Loading ...
Sorry, an error occurred while loading the content.

Autenticacao com JAIN SIP

Expand Messages
  • Ary Junior
    Olá! Estou tentando efetuar um login no asterisk com o JAIN SIP me baseando no fonte do SIP Communicator... debugando o login deste software os valores
    Message 1 of 2 , Aug 4, 2007
    • 0 Attachment
      Olá! Estou tentando efetuar um login no asterisk com o JAIN SIP me baseando no fonte do SIP Communicator... debugando o login deste software os valores utilizados para gerar o response com o MD5 utiliza das seguintes variaveis:

              //algorithm = MD5
              //username_value = aryjunior
              //realm_value = asterisk
              //passwd = mypass
              //nonce_value = 0fceb3ee
              //nc_value = null
              //cnonce_value = null
              //method = REGISTER
              //digest_uri_value = sip:localhost;transport=udp
              //entity_body =
              //qop_value = null

      Ja no meu softfone os mesmos valores:

              //algorithm = MD5
              //username_value = aryjunior
              //realm_value = asterisk
              //passwd = mypass
              //nonce_value = 18e7217e
              //nc_value = null
              //cnonce_value = null
              //method = REGISTER
              //digest_uri_value = sip:localhost;transport=udp
              //entity_body =
              //qop_value = null

      Exceto o nonce_value, q e gerado pelo servidor apos a primeira resposta 401 do servidor... O problema e q com o mesmo algoritmo e os mesmos valores o SIP
      Except by the nonce value... the nonce value for my UAC returned by the server on the first 404 response is no valid for timeout? I get the value from the SipListener.processResponse(ResponseEvent responseEvent), by:

      ...
                      ClientTransaction clientTransaction = responseEvent.getClientTransact
      ion();
                      Response responseClone = (Response)response.clone();
      ...
                      ListIterator authHeaders = responseClone.getHeaders(WWWAuthenticateHeader.NAME);
      ...
                      WWWAuthenticateHeader authHeader = null;
                      while (authHeaders.hasNext ()) {
                          authHeader = (WWWAuthenticateHeader) authHeaders.next();
                          String realm = authHeader.getRealm();
                          System.out.println("Autenticando em "+realm+" !!!");
                      }
      ...
                      authorization.setNonce(authHeader.getNonce());
      ...
                      String responseStr = MessageDigestAlgorithm.calculateResponse(
                              authHeader.getAlgorithm(),
                              user.getUsername(),
                              authHeader.getRealm(),
                              user.getPassword(),
                              authHeader.getNonce(),
                              //TODO we should one day implement those two null-s
                              null, //nc-value
                              null, //cnonce
                              requestClone.getMethod(),
                              "sip:localhost;transport=udp", //requestClone.getRequestURI().toString(),
                              "",
                              authHeader.getQop());
                      authorization.setResponse(responseStr);
      ...

      And I'm sending a lite log file with the messages generated by the client and the asterisk server... Thanks very much!!!


      --
      -----------------------------------------------------------------
      Ary Junior
      Sun Certified Java Programmer - SCJP 1.4
      Site: http://www.powerline.com.br/~aryjr/aryjr/
      -----------------------------------------------------------------
    • Ary Junior
      Olá! Estou tentando efetuar um login no asterisk com o JAIN SIP me baseando no fonte do SIP Communicator... debugando o login deste software os valores
      Message 2 of 2 , Aug 4, 2007
      • 0 Attachment
        Olá! Estou tentando efetuar um login no asterisk com o JAIN SIP me baseando no fonte do SIP Communicator... debugando o login deste software os valores utilizados para gerar o response com o MD5 utiliza das seguintes variaveis:

                //algorithm = MD5
                //username_value = aryjunior
                //realm_value = asterisk
                //passwd = mypass
                //nonce_value = 0fceb3ee
                //nc_value = null
                //cnonce_value = null
                //method = REGISTER
                //digest_uri_value = sip:localhost;transport=udp
                //entity_body =
                //qop_value = null

        Ja no meu softfone os mesmos valores:

                //algorithm = MD5
                //username_value = aryjunior
                //realm_value = asterisk
                //passwd = mypass
                //nonce_value = 18e7217e
                //nc_value = null
                //cnonce_value = null
                //method = REGISTER
                //digest_uri_value = sip:localhost;transport=udp
                //entity_body =
                //qop_value = null

        Exceto o nonce_value, q e gerado pelo servidor apos a primeira resposta 401 do servidor... O problema e q com o mesmo algoritmo e os mesmos valores o SIP Communicator consegue autenticar enquanto o meu cliente nao... abaixo como eu obtenho o nonce_value a partir do metodo SipListener.processResponse(ResponseEvent responseEvent):

        ...
                        ClientTransaction clientTransaction = responseEvent.getClientTransact
        ion();
                        Response responseClone = (Response)response.clone();
        ...
                        ListIterator authHeaders = responseClone.getHeaders(WWWAuthenticateHeader.NAME);
        ...
                        WWWAuthenticateHeader authHeader = null;
                        while (authHeaders.hasNext()) {
                            authHeader = (WWWAuthenticateHeader) authHeaders.next();
                            String realm = authHeader.getRealm();
                            System.out.println("Autenticando em "+realm+" !!!");
                        }
        ...
                        authorization.setNonce(authHeader.getNonce());
        ...
                        String responseStr = MessageDigestAlgorithm.calculateResponse(
                                authHeader.getAlgorithm(),
                                user.getUsername(),
                                authHeader.getRealm(),
                                user.getPassword(),
                                authHeader.getNonce(),
                                //TODO we should one day implement those two null-s
                                null, //nc-value
                                null, //cnonce
                                requestClone.getMethod(),
                                "sip:localhost;transport=udp", //requestClone.getRequestURI().toString(),
                                "",
                                authHeader.getQop());
                        authorization.setResponse(responseStr);
        ...

        A minha duvida e pq o valor nonce q recebo nao vale para a autenticacao e pq o q o SIP Comm. recebe vale? Estou enviando um pequeno arquivo de log da minha aplicacao cliente caso alguem possa me ajudar...

        Valeu!!!

        --
        -----------------------------------------------------------------
        Ary Junior
        Sun Certified Java Programmer - SCJP 1.4
        Site: http://www.powerline.com.br/~aryjr/aryjr/
        -----------------------------------------------------------------
      Your message has been successfully submitted and would be delivered to recipients shortly.