Search in sources :

Example 1 with AuthMechanism

use of org.jivesoftware.smack.sasl.packet.SaslStreamElements.AuthMechanism 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)

Example 2 with AuthMechanism

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

the class SASLMechanism method authenticate.

private final void authenticate() throws SmackException, NotConnectedException, InterruptedException {
    byte[] authenticationBytes = getAuthenticationText();
    String authenticationText;
    // if there is no authentication text.
    if (authenticationBytes != null && authenticationBytes.length > 0) {
        authenticationText = Base64.encodeToString(authenticationBytes);
    } else {
        // RFC6120 6.4.2 "If the initiating entity needs to send a zero-length initial response,
        // it MUST transmit the response as a single equals sign character ("="), which
        // indicates that the response is present but contains no data."
        authenticationText = "=";
    }
    // Send the authentication to the server
    connection.sendNonza(new AuthMechanism(getName(), authenticationText));
}
Also used : AuthMechanism(org.jivesoftware.smack.sasl.packet.SaslStreamElements.AuthMechanism)

Aggregations

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