if (challengeKey == null && request.password == null) {
// There's going to be no way to log in
throw new IllegalArgumentException();
}
SecretToken userSecret;
if (request.publicKeyChallengeRequest == null) {
userSecret = SecretToken.create(SecretTokenType.USER_SECRET);
} else {
byte[] plaintext = request.publicKeyChallengeRequest.toByteArray();
if (!ChallengeResponses.hasPrefix(plaintext)) {
throw new IllegalArgumentException();
}
byte[] payload = ChallengeResponses.getPayload(plaintext);
payload = ChallengeResponses.getPayload(payload);
AesKey cryptoKey;
try {
cryptoKey = KeyczarUtils.unpack(payload);
} catch (KeyczarException e) {
throw new IllegalArgumentException("Invalid key", e);
}
userSecret = new SecretToken(SecretTokenType.USER_SECRET, cryptoKey, null);
}
if (request.password != null) {
secretService.addPasswordAuth(user, userSecret, request.password);
}