public void challengeReceived(String challenge) throws IOException {
    // Build the challenge response stanza encoding the response text
    StringBuilder stanza = new StringBuilder();

    byte response[];
    if (challenge != null) {
      response = sc.evaluateChallenge(Base64.decode(challenge));
    } else {
      response = sc.evaluateChallenge(null);
    }

    String authenticationText = "";

    if (response != null) { // fix from 3.1.1
      authenticationText = Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
      if (authenticationText.equals("")) {
        authenticationText = "=";
      }
    }

    stanza.append("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">");
    stanza.append(authenticationText);
    stanza.append("</response>");

    // Send the authentication to the server
    getSASLAuthentication().send(new Response(authenticationText));
  }
예제 #2
0
  /**
   * The server is challenging the SASL mechanism for the stanza he just sent. Send a response to
   * the server's challenge.
   *
   * @param challenge a base64 encoded string representing the challenge.
   * @throws IOException if an exception sending the response occurs.
   */
  public void challengeReceived(String challenge) throws IOException {
    byte response[];
    if (challenge != null) {
      response = sc.evaluateChallenge(Base64.decode(challenge));
    } else {
      response = sc.evaluateChallenge(new byte[0]);
    }

    Packet responseStanza;
    if (response == null) {
      responseStanza = new Response();
    } else {
      responseStanza = new Response(Base64.encodeBytes(response, Base64.DONT_BREAK_LINES));
    }

    // Send the authentication to the server
    getSASLAuthentication().send(responseStanza);
  }
  public void challengeReceived(String challenge) throws IOException {
    byte response[] = null;
    if (challenge != null) {
      String decodedResponse = new String(Base64.decode(challenge));
      Map<String, String> parameters = getQueryMap(decodedResponse);
      Long callId = new GregorianCalendar().getTimeInMillis() / 1000;

      SortedMap<String, String> params = new TreeMap<String, String>();
      params.put("api_key", apiKey);
      params.put("call_id", callId.toString());
      params.put("method", parameters.get("method"));
      params.put("nonce", parameters.get("nonce"));
      params.put("session_key", sessionKey);
      params.put("v", "1.0");

      StringBuilder sigB = new StringBuilder();
      for (Map.Entry<String, String> entry : params.entrySet()) {
        sigB.append(String.format("%s=%s", entry.getKey(), entry.getValue()));
      }
      sigB.append(sessionSecret);

      String sig;
      try {
        sig = MD5(sigB.toString());
      } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException(e);
      }

      StringBuilder composedResp = new StringBuilder();
      for (Map.Entry<String, String> entry : params.entrySet()) {
        composedResp.append(String.format("%s=%s&", entry.getKey(), entry.getValue()));
      }
      composedResp.append("sig=" + sig);

      response = composedResp.toString().getBytes();
    }
    String authenticationText =
        response == null ? "" : Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
    // getSASLAuthentication().send(authenticationText);
    getSASLAuthentication().send(new Response(authenticationText));
  }
    public byte[] getPropertyBytes(String id) {
      String value = mProperties.getProperty(id);

      if (value != null) return Base64.decode(value);
      return null;
    }