step2 method
Implementation
SRP6ClientCredentials step2(
final SRP6CryptoParams? config, final BigInt? s, final BigInt? B) {
if (config == null) {
throw IllegalArgumentException(
"The SRP-6a crypto parameters must not be null");
}
this.config = config;
Hash digest = config.getMessageDigestInstance();
if (s == null) {
throw IllegalArgumentException("The salt 's' must not be null");
}
this.s = s;
if (B == null) {
throw IllegalArgumentException(
"The server value 'B' must not be null");
}
this.B = B;
if (state != SrpState.step1) {
throw IllegalStateException(
"State violation: Session must be in STEP_1 state");
}
if (hasTimedOut()) {
throw SRP6Exception("Session timeout", CauseType.timeout);
}
if (!SRP6Routines.isValidPublicValue(config.N, B)) {
throw SRP6Exception("Bad server value 'B'", CauseType.badPublicValue);
}
if (xRoutine != null) {
x = xRoutine?.computeX(
config.getMessageDigestInstance(),
BigIntHelper.toByteArray(s),
utf8.encode(userID!),
utf8.encode(password ?? ""));
} else {
x = SRP6Routines.computeX(
digest, BigIntHelper.toByteArray(s), utf8.encode(password ?? ""));
}
a = SRP6Routines.generatePrivateValue(config.N, random);
A = SRP6Routines.computePublicClientValue(config.N, config.g, a!);
k = SRP6Routines.computeK(digest, config.N, config.g);
if (hashedKeysRoutine != null) {
URoutineContext hashedKeysContext = URoutineContext(A!, B);
u = hashedKeysRoutine!.computeU(config, hashedKeysContext);
} else {
u = SRP6Routines.computeU(digest, config.N, A!, B);
}
S = SRP6Routines.computeClientSessionKey(config.N, config.g, k!, x!, u!, a!, B);
if (clientEvidenceRoutine != null) {
SRP6ClientEvidenceContext ctx =
SRP6ClientEvidenceContext(userID!, s, A!, B, S!);
m1 = clientEvidenceRoutine!.computeClientEvidence(config, ctx);
} else {
m1 = SRP6Routines.computeClientEvidence(digest, A!, B, S!);
}
state = SrpState.step2;
updateLastActivityTime();
return SRP6ClientCredentials(A, m1);
}