Fields Summary |
---|
public static final int | NEED_UNWRAPHandshake status NEED_UNWRAP - HandshakeProtocol needs to receive data |
public static final int | NOT_HANDSHAKINGHandshake status NOT_HANDSHAKING - is not currently handshaking |
public static final int | FINISHEDHandshake status FINISHED - HandshakeProtocol has just finished |
public static final int | NEED_TASKHandshake status NEED_TASK - HandshakeProtocol needs the results of delegated task |
protected int | statusCurrent handshake status |
protected HandshakeIODataStream | io_streamIO stream for income/outcome handshake data |
protected SSLRecordProtocol | recordProtocolSSL Record Protocol implementation. |
protected SSLParameters | parametersSSLParameters suplied by SSLSocket or SSLEngine |
protected Vector | delegatedTasksDelegated tasks for this handshake implementation |
protected boolean | nonBlockingIndicates non-blocking handshake |
protected SSLSessionImpl | sessionPending session |
protected ClientHello | clientHelloSended and received handshake messages |
protected ServerHello | serverHello |
protected CertificateMessage | serverCert |
protected ServerKeyExchange | serverKeyExchange |
protected CertificateRequest | certificateRequest |
protected ServerHelloDone | serverHelloDone |
protected CertificateMessage | clientCert |
protected ClientKeyExchange | clientKeyExchange |
protected CertificateVerify | certificateVerify |
protected Finished | clientFinished |
protected Finished | serverFinished |
protected boolean | changeCipherSpecReceivedIndicates that change cipher spec message has been received |
protected boolean | isResumingIndicates previous session resuming |
protected byte[] | preMasterSecretPremaster secret |
protected Exception | delegatedTaskErrException occured in delegated task |
private byte[] | verify_data |
private byte[] | master_secret_bytes |
private boolean | needSendCCSpec |
protected boolean | needSendHelloRequest |
public SSLEngineImpl | engineOwnerSSLEngine owning this HandshakeProtocol |
Methods Summary |
---|
protected void | clearMessages()Clears previously sended and received handshake messages
io_stream.clearBuffer();
clientHello = null;
serverHello = null;
serverCert = null;
serverKeyExchange = null;
certificateRequest = null;
serverHelloDone = null;
clientCert = null;
clientKeyExchange = null;
certificateVerify = null;
clientFinished = null;
serverFinished = null;
|
public void | computerMasterSecret()Computers master secret
byte[] seed = new byte[64];
System.arraycopy(clientHello.getRandom(), 0, seed, 0, 32);
System.arraycopy(serverHello.getRandom(), 0, seed, 32, 32);
session.master_secret = new byte[48];
if (serverHello.server_version[1] == 1) { // TLSv1
try {
PRF.computePRF(session.master_secret, preMasterSecret,
master_secret_bytes, seed);
} catch (GeneralSecurityException e) {
fatalAlert(AlertProtocol.INTERNAL_ERROR, "PRF error", e);
}
} else { // SSL3.0
PRF.computePRF_SSLv3(session.master_secret, preMasterSecret, seed);
}
//delete preMasterSecret from memory
Arrays.fill(preMasterSecret, (byte)0);
preMasterSecret = null;
|
protected void | computerReferenceVerifyDataSSLv3(byte[] sender)Computer reference SSLv3 verify_data that is used to verify finished message
verify_data = new byte[36];
computerVerifyDataSSLv3(sender, verify_data);
|
protected void | computerReferenceVerifyDataTLS(java.lang.String label)Computers reference TLS verify_data that is used to verify finished message
computerVerifyDataTLS(label, verify_data);
|
protected void | computerVerifyDataSSLv3(byte[] sender, byte[] buf)Computer SSLv3 verify_data
MessageDigest md5;
MessageDigest sha;
try {
md5 = MessageDigest.getInstance("MD5");
sha = MessageDigest.getInstance("SHA-1");
} catch (Exception e) {
fatalAlert(AlertProtocol.INTERNAL_ERROR, "Could not initialize the Digest Algorithms.", e);
return;
}
try {
byte[] hanshake_messages = io_stream.getMessages();
md5.update(hanshake_messages);
md5.update(sender);
md5.update(session.master_secret);
byte[] b = md5.digest(SSLv3Constants.MD5pad1);
md5.update(session.master_secret);
md5.update(SSLv3Constants.MD5pad2);
System.arraycopy(md5.digest(b), 0, buf, 0, 16);
sha.update(hanshake_messages);
sha.update(sender);
sha.update(session.master_secret);
b = sha.digest(SSLv3Constants.SHApad1);
sha.update(session.master_secret);
sha.update(SSLv3Constants.SHApad2);
System.arraycopy(sha.digest(b), 0, buf, 16, 20);
} catch (Exception e) {
fatalAlert(AlertProtocol.INTERNAL_ERROR, "INTERNAL ERROR", e);
}
|
protected void | computerVerifyDataTLS(java.lang.String label, byte[] buf)Computer TLS verify_data
byte[] md5_digest = io_stream.getDigestMD5();
byte[] sha_digest = io_stream.getDigestSHA();
byte[] digest = new byte[md5_digest.length + sha_digest.length];
System.arraycopy(md5_digest, 0, digest, 0, md5_digest.length);
System.arraycopy(sha_digest, 0, digest, md5_digest.length,
sha_digest.length);
try {
PRF.computePRF(buf, session.master_secret,
label.getBytes(), digest);
} catch (GeneralSecurityException e) {
fatalAlert(AlertProtocol.INTERNAL_ERROR, "PRF error", e);
}
|
protected void | fatalAlert(byte description, java.lang.String reason)Sends fatal alert, breaks execution
throw new AlertException(description, new SSLHandshakeException(reason));
|
protected void | fatalAlert(byte description, java.lang.String reason, java.lang.Exception cause)Sends fatal alert, breaks execution
throw new AlertException(description, new SSLException(reason, cause));
|
protected void | fatalAlert(byte description, javax.net.ssl.SSLException cause)Sends fatal alert, breaks execution
throw new AlertException(description, cause);
|
protected static int | getRSAKeyLength(java.security.PublicKey pk)Returns RSA key length
BigInteger mod;
if (pk instanceof RSAKey) {
mod = ((RSAKey) pk).getModulus();
} else {
KeyFactory kf = KeyFactory.getInstance("RSA");
mod = ((RSAPublicKeySpec) kf.getKeySpec(pk, RSAPublicKeySpec.class))
.getModulus();
}
return mod.bitLength();
|
public SSLSessionImpl | getSession()Returns pending session
return session;
|
public javax.net.ssl.SSLEngineResult$HandshakeStatus | getStatus()Returns handshake status
if (io_stream.hasData() || needSendCCSpec ||
needSendHelloRequest || delegatedTaskErr != null) {
return SSLEngineResult.HandshakeStatus.NEED_WRAP;
}
if (!delegatedTasks.isEmpty()) {
return SSLEngineResult.HandshakeStatus.NEED_TASK;
}
switch (status) {
case HandshakeProtocol.NEED_UNWRAP:
return SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
case HandshakeProtocol.FINISHED:
status = NOT_HANDSHAKING;
clearMessages();
return SSLEngineResult.HandshakeStatus.FINISHED;
default: // HandshakeProtocol.NOT_HANDSHAKING:
return SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING;
}
|
public java.lang.Runnable | getTask()Returns a delegated task.
if (delegatedTasks.isEmpty()) {
return null;
} else {
Runnable task = (Runnable)delegatedTasks.firstElement();
delegatedTasks.remove(0);
return task;
}
|
abstract void | makeFinished()Creates and sends finished message
|
abstract void | receiveChangeCipherSpec()Proceses inbound ChangeCipherSpec message
|
public void | send(Message message)Writes message to HandshakeIODataStream
io_stream.writeUint8(message.getType());
io_stream.writeUint24(message.length());
message.send(io_stream);
|
protected void | sendChangeCipherSpec()
needSendCCSpec = true;
|
protected void | sendHelloRequest()
needSendHelloRequest = true;
|
protected void | sendWarningAlert(byte description)Sends fatal alert, breaks execution
recordProtocol.alert(AlertProtocol.WARNING, description);
|
public void | setRecordProtocol(SSLRecordProtocol recordProtocol)Sets SSL Record Protocol
this.recordProtocol = recordProtocol;
|
protected void | shutdown()Shutdownes the protocol. It will be impossiblke to use the instance
after the calling of this method.
clearMessages();
session = null;
preMasterSecret = null;
delegatedTasks.clear();
|
public abstract void | start()Start session negotiation
|
protected void | stop()Stops the current session renegotiation process.
Such functionality is needed when it is session renegotiation
process and no_renegotiation alert message is received
from another peer.
clearMessages();
status = NOT_HANDSHAKING;
|
protected void | unexpectedMessage()Sends fatal alert "UNEXPECTED MESSAGE"
fatalAlert(AlertProtocol.UNEXPECTED_MESSAGE, "UNEXPECTED MESSAGE");
|
public abstract void | unwrap(byte[] bytes)Proceses inbound handshake messages
|
public abstract void | unwrapSSLv2(byte[] bytes)Processes SSLv2 Hello message
|
protected void | verifyFinished(byte[] data)Verifies finished data
if (!Arrays.equals(verify_data, data)) {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, "Incorrect FINISED");
}
|
public byte[] | wrap()Proceses outbound handshake messages
if (delegatedTaskErr != null) {
// process error occured in delegated task
Exception e = delegatedTaskErr;
delegatedTaskErr = null;
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
"Error occured in delegated task:" + e.getMessage(), e);
}
if (io_stream.hasData()) {
return recordProtocol.wrap(ContentType.HANDSHAKE, io_stream);
} else if (needSendCCSpec) {
makeFinished();
needSendCCSpec = false;
return recordProtocol.getChangeCipherSpecMesage(getSession());
} else if (needSendHelloRequest) {
needSendHelloRequest = false;
return recordProtocol.wrap(ContentType.HANDSHAKE,
// hello request message
// (see TLS v 1 specification:
// http://www.ietf.org/rfc/rfc2246.txt)
new byte[] {0, 0, 0, 0}, 0, 4);
} else {
return null; // nothing to send;
}
|