2014-11-12 15:15:38 +00:00
|
|
|
package eu.siacs.conversations.crypto.sasl;
|
|
|
|
|
|
|
|
import java.security.SecureRandom;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.xml.TagWriter;
|
|
|
|
|
|
|
|
public abstract class SaslMechanism {
|
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
final protected TagWriter tagWriter;
|
|
|
|
final protected Account account;
|
|
|
|
final protected SecureRandom rng;
|
2014-11-12 15:15:38 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
protected enum State {
|
|
|
|
INITIAL,
|
|
|
|
AUTH_TEXT_SENT,
|
|
|
|
RESPONSE_SENT,
|
|
|
|
VALID_SERVER_RESPONSE,
|
|
|
|
}
|
2014-11-15 13:48:40 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public static class AuthenticationException extends Exception {
|
|
|
|
public AuthenticationException(final String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
2014-11-15 13:48:40 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public AuthenticationException(final Exception inner) {
|
|
|
|
super(inner);
|
|
|
|
}
|
2017-07-30 09:39:47 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public AuthenticationException(final String message, final Exception exception) {
|
|
|
|
super(message, exception);
|
|
|
|
}
|
|
|
|
}
|
2014-11-15 13:48:40 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public static class InvalidStateException extends AuthenticationException {
|
|
|
|
public InvalidStateException(final String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
2014-11-15 13:48:40 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public InvalidStateException(final State state) {
|
|
|
|
this("Invalid state: " + state.toString());
|
|
|
|
}
|
|
|
|
}
|
2014-11-15 13:48:40 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public SaslMechanism(final TagWriter tagWriter, final Account account, final SecureRandom rng) {
|
|
|
|
this.tagWriter = tagWriter;
|
|
|
|
this.account = account;
|
|
|
|
this.rng = rng;
|
|
|
|
}
|
2014-11-12 15:15:38 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
/**
|
|
|
|
* The priority is used to pin the authentication mechanism. If authentication fails, it MAY be retried with another
|
|
|
|
* mechanism of the same priority, but MUST NOT be tried with a mechanism of lower priority (to prevent downgrade
|
|
|
|
* attacks).
|
|
|
|
*
|
|
|
|
* @return An arbitrary int representing the priority
|
|
|
|
*/
|
|
|
|
public abstract int getPriority();
|
2014-11-15 14:42:40 +00:00
|
|
|
|
2020-12-31 08:32:05 +00:00
|
|
|
public abstract String getMechanism();
|
|
|
|
|
|
|
|
public String getClientFirstMessage() {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getResponse(final String challenge) throws AuthenticationException {
|
|
|
|
return "";
|
|
|
|
}
|
2014-11-12 15:15:38 +00:00
|
|
|
}
|