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));
  }
    private void loadOpenSSL(String password) throws IOException {

      if (!mStoreFile.exists()) return;

      if (mStoreFile.length() == 0) return;

      FileInputStream fis = null;
      OpenSSLPBEInputStream encIS = null;
      try {

        fis = new FileInputStream(mStoreFile);

        // Decrypt the bytes
        encIS = new OpenSSLPBEInputStream(fis, STORE_ALGORITHM, 1, password.toCharArray());
        mProperties.load(encIS);
      } catch (IllegalArgumentException iae) {
        // might be a unicode character in the password
        encIS =
            new OpenSSLPBEInputStream(
                fis, STORE_ALGORITHM, 1, Base64.encodeBytes(password.getBytes()).toCharArray());
        mProperties.load(encIS);

      } catch (FileNotFoundException fnfe) {
        OtrDebugLogger.log("Properties store file not found: First time?");
        mStoreFile.getParentFile().mkdirs();
      } finally {
        encIS.close();
        fis.close();
      }
    }
Пример #3
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);
  }
Пример #4
0
  /**
   * Computes and returns the hash of the specified <tt>capsString</tt> using the specified
   * <tt>hashAlgorithm</tt>.
   *
   * @param hashAlgorithm the name of the algorithm to be used to generate the hash
   * @param capsString the capabilities string that we'd like to compute a hash for.
   * @return the hash of <tt>capsString</tt> computed by the specified <tt>hashAlgorithm</tt> or
   *     <tt>null</tt> if generating the hash has failed
   */
  private static String capsToHash(String hashAlgorithm, String capsString) {
    try {
      MessageDigest md = MessageDigest.getInstance(hashAlgorithm);
      byte[] digest = md.digest(capsString.getBytes());

      return Base64.encodeBytes(digest);
    } catch (NoSuchAlgorithmException nsae) {
      logger.error("Unsupported XEP-0115: Entity Capabilities hash algorithm: " + hashAlgorithm);
      return null;
    }
  }
  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));
  }
Пример #6
0
  @Override
  protected void authenticate() throws IOException, XMPPException {
    String authText = null;
    try {
      if (sc.hasInitialResponse()) {
        byte[] response = sc.evaluateChallenge(new byte[0]);
        authText = Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
      }
    } catch (SaslException e) {
      throw new XMPPException("SASL authentication failed", e);
    }

    getSASLAuthentication().send(new GoogleOAuth(authText));
  }
Пример #7
0
  protected void authenticate() throws IOException, XMPPException {
    String authenticationText = null;
    try {
      if (sc.hasInitialResponse()) {
        byte[] response = sc.evaluateChallenge(new byte[0]);
        authenticationText = Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
      }
    } catch (SaslException e) {
      throw new XMPPException("SASL authentication failed", e);
    }

    // Send the authentication to the server
    getSASLAuthentication().send(new AuthMechanism(getName(), authenticationText));
  }
    private void saveOpenSSL(String password, File fileStore) throws IOException {
      // Encrypt these bytes
      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      try {
        OpenSSLPBEOutputStream encOS =
            new OpenSSLPBEOutputStream(baos, STORE_ALGORITHM, 1, password.toCharArray());
        mProperties.store(encOS, null);
        encOS.flush();
      } catch (IllegalArgumentException iae) {

        // might be a unicode character in the password
        OpenSSLPBEOutputStream encOS =
            new OpenSSLPBEOutputStream(
                baos, STORE_ALGORITHM, 1, Base64.encodeBytes(password.getBytes()).toCharArray());
        mProperties.store(encOS, null);
        encOS.flush();
      }

      FileOutputStream fos = new FileOutputStream(fileStore);
      fos.write(baos.toByteArray());
      fos.flush();
      fos.close();
    }
    public byte[] getPropertyBytes(String id) {
      String value = mProperties.getProperty(id);

      if (value != null) return Base64.decode(value);
      return null;
    }
 public void setProperty(String id, byte[] value) {
   mProperties.setProperty(id, new String(Base64.encodeBytes(value)));
 }