step2 method

BigInt step2(
  1. BigInt A,
  2. BigInt m1
)

Implementation

BigInt step2(final BigInt A, final BigInt m1) {
// Check arguments

  this.A = A;
  this.m1 = m1;

  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, A)) {
    throw SRP6Exception(
        "Bad client public value 'A'", CauseType.badPublicValue);
  }

  if (noSuchUserIdentity) {
    throw SRP6Exception("Bad client credentials", CauseType.badCredentials);
  }

  Hash digest = config!.getMessageDigestInstance();

  if (hashedKeysRoutine != null) {
    URoutineContext hashedKeysContext = URoutineContext(A, B!);
    u = hashedKeysRoutine!.computeU(config!, hashedKeysContext);
  } else {
    u = SRP6Routines.computeU(digest, config!.N, A, B!);
  }

  S = SRP6Routines.computeServerSessionKey(config!.N, v!, u!, A, b!);
  BigInt computedM1;

  if (clientEvidenceRoutine != null) {
    SRP6ClientEvidenceContext ctx =
        SRP6ClientEvidenceContext(userID!, s!, A, B!, S!);
    computedM1 = clientEvidenceRoutine!.computeClientEvidence(config!, ctx);
  } else {
    computedM1 = SRP6Routines.computeClientEvidence(digest, A, B!, S!);
  }

  if (computedM1 != m1) {
    throw SRP6Exception("Bad client credentials", CauseType.badCredentials);
  }

  state = SrpState.step2;

  if (serverEvidenceRoutine != null) {
    SRP6ServerEvidenceContext ctx = SRP6ServerEvidenceContext(A, m1, S!);

    m2 = serverEvidenceRoutine!.computeServerEvidence(config!, ctx);
  } else {
    m2 = SRP6Routines.computeServerEvidence(digest, A, m1, S!);
  }

  updateLastActivityTime();

  return m2!;
}