mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Introduce SmackSaslException
This commit is contained in:
parent
bb759a136e
commit
b51a6c54e8
12 changed files with 161 additions and 100 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014-2017 Florian Schmaus
|
||||
* Copyright 2014-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,7 +20,7 @@ import java.io.UnsupportedEncodingException;
|
|||
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.SmackException.SmackSaslException;
|
||||
import org.jivesoftware.smack.sasl.SASLMechanism;
|
||||
import org.jivesoftware.smack.util.ByteUtils;
|
||||
import org.jivesoftware.smack.util.MD5;
|
||||
|
@ -60,12 +60,12 @@ public class SASLDigestMD5Mechanism extends SASLMechanism {
|
|||
private String hex_hashed_a1;
|
||||
|
||||
@Override
|
||||
protected void authenticateInternal(CallbackHandler cbh) throws SmackException {
|
||||
protected void authenticateInternal(CallbackHandler cbh) {
|
||||
throw new UnsupportedOperationException("CallbackHandler not (yet) supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getAuthenticationText() throws SmackException {
|
||||
protected byte[] getAuthenticationText() {
|
||||
// DIGEST-MD5 has no initial response, return null
|
||||
return null;
|
||||
}
|
||||
|
@ -92,16 +92,16 @@ public class SASLDigestMD5Mechanism extends SASLMechanism {
|
|||
|
||||
|
||||
@Override
|
||||
public void checkIfSuccessfulOrThrow() throws SmackException {
|
||||
public void checkIfSuccessfulOrThrow() throws SmackSaslException {
|
||||
if (verifyServerResponse && state != State.VALID_SERVER_RESPONSE) {
|
||||
throw new SmackException(NAME + " no valid server response");
|
||||
throw new SmackSaslException(NAME + " no valid server response");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] evaluateChallenge(byte[] challenge) throws SmackException {
|
||||
protected byte[] evaluateChallenge(byte[] challenge) throws SmackSaslException {
|
||||
if (challenge.length == 0) {
|
||||
throw new SmackException("Initial challenge has zero length");
|
||||
throw new SmackSaslException("Initial challenge has zero length");
|
||||
}
|
||||
String challengeString;
|
||||
try {
|
||||
|
@ -127,14 +127,14 @@ public class SASLDigestMD5Mechanism extends SASLMechanism {
|
|||
String value = keyValue[1];
|
||||
if ("nonce".equals(key)) {
|
||||
if (nonce != null) {
|
||||
throw new SmackException("Nonce value present multiple times");
|
||||
throw new SmackSaslException("Nonce value present multiple times");
|
||||
}
|
||||
nonce = value.replace("\"", "");
|
||||
}
|
||||
else if ("qop".equals(key)) {
|
||||
value = value.replace("\"", "");
|
||||
if (!value.equals("auth")) {
|
||||
throw new SmackException("Unsupported qop operation: " + value);
|
||||
throw new SmackSaslException("Unsupported qop operation: " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ public class SASLDigestMD5Mechanism extends SASLMechanism {
|
|||
// RFC 2831 2.1.1 about nonce "This directive is required and MUST appear exactly
|
||||
// once; if not present, or if multiple instances are present, the client should
|
||||
// abort the authentication exchange."
|
||||
throw new SmackException("nonce value not present in initial challenge");
|
||||
throw new SmackSaslException("nonce value not present in initial challenge");
|
||||
}
|
||||
// RFC 2831 2.1.2.1 defines A1, A2, KD and response-value
|
||||
byte[] a1FirstPart = MD5.bytes(authenticationId + ':' + serviceName + ':'
|
||||
|
@ -188,12 +188,12 @@ public class SASLDigestMD5Mechanism extends SASLMechanism {
|
|||
}
|
||||
}
|
||||
if (serverResponse == null) {
|
||||
throw new SmackException("No server response received while performing " + NAME
|
||||
throw new SmackSaslException("No server response received while performing " + NAME
|
||||
+ " authentication");
|
||||
}
|
||||
String expectedServerResponse = calcResponse(DigestType.ServerResponse);
|
||||
if (!serverResponse.equals(expectedServerResponse)) {
|
||||
throw new SmackException("Invalid server response while performing " + NAME
|
||||
throw new SmackSaslException("Invalid server response while performing " + NAME
|
||||
+ " authentication");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.jivesoftware.smack.sasl.provided;
|
|||
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.sasl.SASLMechanism;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
|
||||
|
@ -34,13 +33,13 @@ public class SASLExternalMechanism extends SASLMechanism {
|
|||
public static final String NAME = EXTERNAL;
|
||||
|
||||
@Override
|
||||
protected void authenticateInternal(CallbackHandler cbh) throws SmackException {
|
||||
protected void authenticateInternal(CallbackHandler cbh) {
|
||||
// Do nothing. Auth will be done external to Smack and which will receive the localpart
|
||||
// after the resource binding
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getAuthenticationText() throws SmackException {
|
||||
protected byte[] getAuthenticationText() {
|
||||
if (authorizationId != null) {
|
||||
return toBytes(authorizationId.toString());
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ public class SASLExternalMechanism extends SASLMechanism {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void checkIfSuccessfulOrThrow() throws SmackException {
|
||||
public void checkIfSuccessfulOrThrow() {
|
||||
// No check performed
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Florian Schmaus
|
||||
* Copyright 2014-2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,7 +18,6 @@ package org.jivesoftware.smack.sasl.provided;
|
|||
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.sasl.SASLMechanism;
|
||||
import org.jivesoftware.smack.util.ByteUtils;
|
||||
|
||||
|
@ -27,12 +26,12 @@ public class SASLPlainMechanism extends SASLMechanism {
|
|||
public static final String NAME = PLAIN;
|
||||
|
||||
@Override
|
||||
protected void authenticateInternal(CallbackHandler cbh) throws SmackException {
|
||||
protected void authenticateInternal(CallbackHandler cbh) {
|
||||
throw new UnsupportedOperationException("CallbackHandler not (yet) supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected byte[] getAuthenticationText() throws SmackException {
|
||||
protected byte[] getAuthenticationText() {
|
||||
// concatenate and encode username (authcid) and password
|
||||
String authzid;
|
||||
if (authorizationId == null) {
|
||||
|
@ -62,7 +61,7 @@ public class SASLPlainMechanism extends SASLMechanism {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void checkIfSuccessfulOrThrow() throws SmackException {
|
||||
public void checkIfSuccessfulOrThrow() {
|
||||
// No check performed
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue