protected void handshakeChallengeResponse(HelloMessage request,
Channel channel)
throws AuthException {
AuthChallengeResponse cr = request.getAuthChallengeResponse();
if (cr == null) {
throw new AuthException("No authentication data in " +
"handshake message");
}
if (cr.isSetResponse()) {
authenticateResponse(currentChallenge, cr.getResponse());
currentChallenge = null;
channelState = ChannelState.AUTHENTICATED;
handleHello(request, channel);
} else if (cr.isSetChallenge()) {
HelloMessage m = new HelloMessage();
if (getLocalNodeId() != null)
m.setNodeId(getLocalNodeId());
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(getTransactionId());
m.setHeader(header);
SyncMessage bsm = new SyncMessage(MessageType.HELLO);
bsm.setHello(m);
AuthChallengeResponse reply = new AuthChallengeResponse();
reply.setResponse(generateResponse(cr.getChallenge()));
m.setAuthChallengeResponse(reply);
channel.write(bsm);
} else {
throw new AuthException("No authentication data in " +
"handshake message");
}
}