Program: 154357
Project: 154357
Buggy source:
private void clientHandshake() throws AlertException {
switch (type) {
case HELLO_REQUEST:
    clientRandom=new byte[RANDOM_SIZE];
  genRandom(clientRandom);
state.setClientRandom(clientRandom);
State tmpState=TLSEngine.findState(state.getPeerHost());
if (tmpState != null) sessionId=tmpState.getSessionId();
clientHello=new ClientHello(clientRandom,sessionId,TLSEngine.allCipherSuites);
responseQueue.add(clientHello);
break;
case SERVER_HELLO:
if (lastMessage != CLIENT_HELLO) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverHello=new ServerHello(content);
if (!Tools.isEmptyByteArray(sessionId) && Tools.compareByteArray(sessionId,serverHello.getSessionId())) {
state.setServerRandom(serverHello.getServerRandom());
state.resumeSession(TLSEngine.findState(sessionId));
state.addHandshakeLog("String_Node_Str");
}
 else {
sessionId=serverHello.getSessionId();
state.setSessionId(sessionId);
}
state.addHandshakeLog(new LogEvent("String_Node_Str",serverHello.getStringValue()));
break;
case CERTIFICATE:
if (lastMessage != SERVER_HELLO) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverCertificate=new ServerCertificate(content);
state.addHandshakeLog(new LogEvent("String_Node_Str",serverCertificate.getStringValue()));
break;
case SERVER_KEY_EXCHANGE:
if (lastMessage != CERTIFICATE) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverKeyExchange=new ServerKeyExchange(content);
state.addHandshakeLog(new LogEvent("String_Node_Str",serverKeyExchange.getStringValue()));
break;
case CERTIFICATE_REQUEST:
state.addHandshakeLog(new LogEvent("String_Node_Str","String_Node_Str"));
throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str");
case SERVER_HELLO_DONE:
if (lastMessage != SERVER_KEY_EXCHANGE && lastMessage != CERTIFICATE) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverHelloDone=new ServerHelloDone();
state.addHandshakeLog(new LogEvent("String_Node_Str",serverHelloDone.getStringValue()));
if (serverHello.getChosenCipherSuite().getKeyExchange().requireServerKeyExchange()) clientKeyExchange=new ClientKeyExchange(serverHello.getChosenCipherSuite().getKeyExchange());
 else {
preMasterSecret=new byte[RANDOM_SIZE];
genRandom(preMasterSecret);
clientKeyExchange=new ClientKeyExchange(preMasterSecret);
}
responseQueue.add(clientKeyExchange);
responseQueue.add(new ChangeCipherSpec());
state.setChangeCipherSpecClient();
state.setCipherSuite(serverHello.getChosenCipherSuite());
clientFinished=new Finished();
responseQueue.add(clientFinished);
break;
case CHANGE_CIPHER_SPEC:
state.addHandshakeLog(new LogEvent("String_Node_Str",Tools.byteArrayToString(content)));
state.setChangeCipherSpecServer();
break;
case FINISHED:
if (lastMessage != CHANGE_CIPHER_SPEC) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
if (!state.getChangeCipherSpecServer()) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str");
serverFinished=new Finished(content);
isFinished=true;
state.addHandshakeLog(new LogEvent("String_Node_Str",serverFinished.getStringValue()));
state.addHandshakeLog("String_Node_Str" + serverHello.getChosenCipherSuite().getName());
break;
default :
throw new AlertException(AlertException.alert_warning,AlertException.unexpected_message,"String_Node_Str" + type);
}
}

Fixed version (ground truth):
private void clientHandshake() throws AlertException {
switch (type) {
case HELLO_REQUEST:
    clientRandom=new byte[RANDOM_SIZE];
  genRandom(clientRandom);
state.setClientRandom(clientRandom);
State tmpState=TLSEngine.findState(state.getPeerHost());
if (tmpState != null) sessionId=tmpState.getSessionId();
clientHello=new ClientHello(clientRandom,sessionId,TLSEngine.allCipherSuites);
responseQueue.add(clientHello);
break;
case SERVER_HELLO:
if (lastMessage != CLIENT_HELLO) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverHello=new ServerHello(content);
state.setServerRandom(serverHello.getServerRandom());
if (!Tools.isEmptyByteArray(sessionId) && Tools.compareByteArray(sessionId,serverHello.getSessionId())) {
state.setServerRandom(serverHello.getServerRandom());
state.resumeSession(TLSEngine.findState(sessionId));
state.addHandshakeLog("String_Node_Str");
}
 else {
sessionId=serverHello.getSessionId();
state.setSessionId(sessionId);
}
state.addHandshakeLog(new LogEvent("String_Node_Str",serverHello.getStringValue()));
break;
case CERTIFICATE:
if (lastMessage != SERVER_HELLO) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverCertificate=new ServerCertificate(content);
state.addHandshakeLog(new LogEvent("String_Node_Str",serverCertificate.getStringValue()));
break;
case SERVER_KEY_EXCHANGE:
if (lastMessage != CERTIFICATE) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverKeyExchange=new ServerKeyExchange(content);
state.addHandshakeLog(new LogEvent("String_Node_Str",serverKeyExchange.getStringValue()));
break;
case CERTIFICATE_REQUEST:
state.addHandshakeLog(new LogEvent("String_Node_Str","String_Node_Str"));
throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str");
case SERVER_HELLO_DONE:
if (lastMessage != SERVER_KEY_EXCHANGE && lastMessage != CERTIFICATE) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
serverHelloDone=new ServerHelloDone();
state.addHandshakeLog(new LogEvent("String_Node_Str",serverHelloDone.getStringValue()));
if (serverHello.getChosenCipherSuite().getKeyExchange().requireServerKeyExchange()) clientKeyExchange=new ClientKeyExchange(serverHello.getChosenCipherSuite().getKeyExchange());
 else {
preMasterSecret=new byte[RANDOM_SIZE];
genRandom(preMasterSecret);
clientKeyExchange=new ClientKeyExchange(preMasterSecret);
}
state.setPreMasterSecret(clientKeyExchange.getByte());
responseQueue.add(clientKeyExchange);
responseQueue.add(new ChangeCipherSpec());
state.setChangeCipherSpecClient();
state.setCipherSuite(serverHello.getChosenCipherSuite());
clientFinished=new Finished();
responseQueue.add(clientFinished);
break;
case CHANGE_CIPHER_SPEC:
state.addHandshakeLog(new LogEvent("String_Node_Str",Tools.byteArrayToString(content)));
state.setChangeCipherSpecServer();
break;
case FINISHED:
if (lastMessage != CHANGE_CIPHER_SPEC) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str" + lastMessage);
if (!state.getChangeCipherSpecServer()) throw new AlertException(AlertException.alert_fatal,AlertException.handshake_failure,"String_Node_Str");
serverFinished=new Finished(content);
isFinished=true;
state.addHandshakeLog(new LogEvent("String_Node_Str",serverFinished.getStringValue()));
state.addHandshakeLog("String_Node_Str" + serverHello.getChosenCipherSuite().getName());
break;
default :
throw new AlertException(AlertException.alert_warning,AlertException.unexpected_message,"String_Node_Str" + type);
}
}