Visualizzazione dei risultati da 1 a 8 su 8

Discussione: Wsse listener aiuto

  1. #1

    Wsse listener aiuto

    Buongiorno,

    non riesco a creare un WSSE Listener.

    Questa è la chiamata che ricevo.

    <?php
    class TokenGenerator {
    public static function generateToken($username, $password) {
    $nonce = self::generateNonce ();


    $created = date ( 'Y-m-d\TH:i:sP' );
    $digest = base64_encode ( sha1 ( $nonce . $created . $password, TRUE ) );
    $token = sprintf ( 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"', $username, $digest, $nonce, $created );
    return $token;
    }


    private static function generateNonce($bits = 256) {
    $bytes = ceil ( $bits / 8 ) * microtime ();
    $return = '';


    for($i = 0; $i < $bytes; $i ++)
    $return .= chr ( mt_rand ( 0, 255 ) );


    return md5 ( $return );
    }
    }


    $xwsse = TokenGenerator::generateToken ( 'username', 'RC&EWoiQ7#!!' ); // ### GENERO IL TOKEN
    $httpRequest = new \HttpRequest (
    'http://XXXX/',
    \HttpRequest::METH_POST, [
    'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8',
    'Accept-Charset' => 'UTF-8',
    'X-Wsse' => $xwsse
    ],
    'protocol' => HTTP_VERSION_1_2
    ]
    );


    $httpRequest->setPostFields ( [
    'userName' => 'testAgentnip',
    'phoneNumber' => '368456123',
    'customer' => '112233'
    ] ) or die ( 'Errore' );


    try {
    $result = $httpRequest->send()->getBody ();
    echo $result;
    } catch ( \HttpException $ex ) {
    error_log ( 'ERRORE CHIAMATA HTTP => ' . $ex->getMessage () );
    }
    Ultima modifica di chinoknot; 22-12-2015 a 11:15

  2. #2
    e come fai l'handling della richiesta lato server?
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  3. #3
    Lato server c'è un webservice che accetta i campi in post, ma prima di tutto mi deve verificare l'autenticazione di tipo digest. Ho trovato diversi esempi sul web, anche sul manuale PHP, ma non sono riuscito adattarlo al tipo di chiamata che ricevo, negli altri casi mettono in mezzo anche il $realm che a me non serve.

  4. #4
    un esempio di token generato?
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  5. #5
    UsernameToken Username="chinoknot", PasswordDigest="6c63L9thaxq90+N1UrPPjJTlw+s=", Nonce="f83b40bb60d2f0f8ad002c56327fa7dd", Created="2015-12-24T14:59:00+01:00"

  6. #6
    ma l'errore quale sarebbe? Hai controllato che tipo di richiesta http fai? puoi fartela stampare? hai provato ad usare sistemi tipo https://www.google.it/webhp?sourceid...0rest%20client per testare a mano la richiesta? ora non so il token così ad occhio mi pare corretto, magari è la richiesta che è fatta male. riportaci l'errore ottenuto
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  7. #7
    Dunque. La richiesta purtroppo è fatta in modo corretto e il metodo WSSE non l'ho scelto io, me lo hanno imposto. Mi sono creato un file di log per vedere se appunto la chiamata fosse fatta in modo corretto, e infatti è ok.
    Il mio unico problema è proprio creare una pagina, un listener appunto che mi accetti nell'header questo tipo di token, utilizzando la funzione getallheaders di PHP ad esempio.

    L'unica indicazione che ho ricevuto per creare il listener è stata:

    public static function wsseIsValid(){

    $time = time();
    $wsseRegex = '/UsernameToken Username="([^"]+)", PasswordDigest="([^"]+)", Nonce="([^"]+)", Created="([^"]+)"/';
    $token = "L'HEADER WSSE PRESO DALLA RICHIESTA"

    if( $token == NULL || 1 !== preg_match( $wsseRegex, $token, $matches ) ) {
    return FALSE;
    }

    $userName = $matches[ 1 ];
    $digest = $matches[ 2 ];
    $nonce = $matches[ 3 ];
    $created = $matches[ 4 ];

    if( strtotime( $created ) > $time ) {
    throw new Exception( 'DESCRIZIONE ERRORE', 'CODICE CHE VUOI USARE PER QUESTO ERRORE' );
    }
    if( $time - strtotime( $created ) > 300 ) {
    throw new Exception( 'DESCRIZIONE ERRORE', 'CODICE CHE VUOI USARE PER QUESTO ERRORE' );
    }


    // CARICA L'UTENTE $userName (preso sopra) DA DB O DA CONFIGURAZIONE, COME VUOI TU, PER RECUPERARE LA PASSWORD
    $passwordUser = "PRENDO LA PASSWORD DELL'UTENTE $userName CARICATO"; //
    // SE LA TUA $passwordUser è salvata nel db in chiaro è ok, altrimenti la dovresti decodificarla

    // RICREI IL DIGEST COSÌ, SE IL DIGEST CHE TI E' ARRIVATO E' UGUALE A QUELLO CHE HAI GENERATO ALLORA E' OK
    $expected = base64_encode( sha1( $nonce . $created . $passwordUser, TRUE ) );
    return $digest === $expected;

    Ho provato ad usarla, ma con scarso esito, mi ritorna sempre internal server error e non credo per quel ";" che manca, ma credo per la versione di PHP che utilizzo (5.2.5) che forse non supporta questo tipo di funzione, per questo avevo optato per una più "semplice" getallheaders.

  8. #8
    allora, http://php.net/manual/en/function.ap...st-headers.php dovrebbe essere disponibile anche alla tua versione. Il gioco è semplice, una volta che trovi l'header X-Wsse fai il check che hai postato sopra (non so se quel codice sia corretto, fai dei test). Se non usi Apache come web server, negli esempi c'è un codice generico. Altrimenti vai a cercarti l'header in $_SERVER.

    il fatto che ti ritorni "internal server error" lo devi debuggare te che cosìì ad occhio non saprei dirti
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.