/** * Create the client challenge. * * @return A challenge to be sent the remote side. */ ClientChallenge challenge() throws GeneralSecurityException, IOException { this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce, conf.encryptionKeyLength()); initializeForAuth(conf.cipherTransformation(), authNonce, authKey); this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce, challenge(appId, authNonce, challenge)); }
/** * Create the client challenge. * * @return A challenge to be sent the remote side. */ ClientChallenge challenge() throws GeneralSecurityException { this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce, conf.encryptionKeyLength()); initializeForAuth(conf.cipherTransformation(), authNonce, authKey); this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce, challenge(appId, authNonce, challenge)); }
/** * Create the client challenge. * * @return A challenge to be sent the remote side. */ ClientChallenge challenge() throws GeneralSecurityException { this.authNonce = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); SecretKeySpec authKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), authNonce, conf.encryptionKeyLength()); initializeForAuth(conf.cipherTransformation(), authNonce, authKey); this.challenge = randomBytes(conf.encryptionKeyLength() / Byte.SIZE); return new ClientChallenge(new String(appId, UTF_8), conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), conf.cipherTransformation(), conf.encryptionKeyLength(), authNonce, challenge(appId, authNonce, challenge)); }
/** * Validates the server response and initializes the cipher to use for the session. * * @param serverResponse The response from the server. */ void validate(ServerResponse serverResponse) throws GeneralSecurityException { byte[] response = validateChallenge(authNonce, serverResponse.response); byte[] expected = rawResponse(challenge); Preconditions.checkArgument(Arrays.equals(expected, response)); byte[] nonce = decrypt(serverResponse.nonce); byte[] inputIv = decrypt(serverResponse.inputIv); byte[] outputIv = decrypt(serverResponse.outputIv); SecretKeySpec sessionKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), nonce, conf.encryptionKeyLength()); this.sessionCipher = new TransportCipher(cryptoConf, conf.cipherTransformation(), sessionKey, inputIv, outputIv); }
/** * Validates the server response and initializes the cipher to use for the session. * * @param serverResponse The response from the server. */ void validate(ServerResponse serverResponse) throws GeneralSecurityException { byte[] response = validateChallenge(authNonce, serverResponse.response); byte[] expected = rawResponse(challenge); Preconditions.checkArgument(Arrays.equals(expected, response)); byte[] nonce = decrypt(serverResponse.nonce); byte[] inputIv = decrypt(serverResponse.inputIv); byte[] outputIv = decrypt(serverResponse.outputIv); SecretKeySpec sessionKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), nonce, conf.encryptionKeyLength()); this.sessionCipher = new TransportCipher(cryptoConf, conf.cipherTransformation(), sessionKey, inputIv, outputIv); }
/** * Validates the server response and initializes the cipher to use for the session. * * @param serverResponse The response from the server. */ void validate(ServerResponse serverResponse) throws GeneralSecurityException { byte[] response = validateChallenge(authNonce, serverResponse.response); byte[] expected = rawResponse(challenge); Preconditions.checkArgument(Arrays.equals(expected, response)); byte[] nonce = decrypt(serverResponse.nonce); byte[] inputIv = decrypt(serverResponse.inputIv); byte[] outputIv = decrypt(serverResponse.outputIv); SecretKeySpec sessionKey = generateKey(conf.keyFactoryAlgorithm(), conf.keyFactoryIterations(), nonce, conf.encryptionKeyLength()); this.sessionCipher = new TransportCipher(cryptoConf, conf.cipherTransformation(), sessionKey, inputIv, outputIv); }