Search in sources :

Example 1 with Response

use of org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response in project Smack by igniterealtime.

the class SASLMechanism method challengeReceived.

/**
     * The server is challenging the SASL mechanism for the stanza he just sent. Send a
     * response to the server's challenge.
     *
     * @param challengeString a base64 encoded string representing the challenge.
     * @param finalChallenge true if this is the last challenge send by the server within the success stanza
     * @throws NotConnectedException
     * @throws SmackException
     * @throws InterruptedException 
     */
public final void challengeReceived(String challengeString, boolean finalChallenge) throws SmackException, NotConnectedException, InterruptedException {
    byte[] challenge = Base64.decode((challengeString != null && challengeString.equals("=")) ? "" : challengeString);
    byte[] response = evaluateChallenge(challenge);
    if (finalChallenge) {
        return;
    }
    Response responseStanza;
    if (response == null) {
        responseStanza = new Response();
    } else {
        responseStanza = new Response(Base64.encodeToString(response));
    }
    // Send the authentication to the server
    connection.sendNonza(responseStanza);
}
Also used : Response(org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response)

Example 2 with Response

use of org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response in project Smack by igniterealtime.

the class SCRAMSHA1MechanismTest method testScramSha1Mechanism.

@Test
public void testScramSha1Mechanism() throws NotConnectedException, SmackException, InterruptedException {
    final DummyConnection con = new DummyConnection();
    SCRAMSHA1Mechanism mech = new SCRAMSHA1Mechanism() {

        @Override
        public String getRandomAscii() {
            this.connection = con;
            return "fyko+d2lbbFgONRv9qkxdawL";
        }
    };
    mech.authenticate(USERNAME, "unusedFoo", JidTestUtil.DOMAIN_BARE_JID_1, PASSWORD, null, null);
    AuthMechanism authMechanism = con.getSentPacket();
    assertEquals(SCRAMSHA1Mechanism.NAME, authMechanism.getMechanism());
    assertEquals(CLIENT_FIRST_MESSAGE, saslLayerString(authMechanism.getAuthenticationText()));
    mech.challengeReceived(Base64.encode(SERVER_FIRST_MESSAGE), false);
    Response response = con.getSentPacket();
    assertEquals(CLIENT_FINAL_MESSAGE, saslLayerString(response.getAuthenticationText()));
    mech.challengeReceived(Base64.encode(SERVER_FINAL_MESSAGE), true);
    mech.checkIfSuccessfulOrThrow();
}
Also used : Response(org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response) AuthMechanism(org.jivesoftware.smack.sasl.packet.SaslStreamElements.AuthMechanism) DummyConnection(org.jivesoftware.smack.DummyConnection) Test(org.junit.Test)

Aggregations

Response (org.jivesoftware.smack.sasl.packet.SaslStreamElements.Response)2 DummyConnection (org.jivesoftware.smack.DummyConnection)1 AuthMechanism (org.jivesoftware.smack.sasl.packet.SaslStreamElements.AuthMechanism)1 Test (org.junit.Test)1