sipStack.getStackLogger().logDebug(
"inaddr = " + receiverAddress);
sipStack.getStackLogger().logDebug(
"port = " + contactPort);
}
HandshakeCompletedListener listner = new HandshakeCompletedListenerImpl(
(TLSMessageChannel) messageChannel);
((TLSMessageChannel) messageChannel)
.setHandshakeCompletedListener(listner);
sslsock.addHandshakeCompletedListener(listner);
sslsock.setEnabledProtocols(sipStack
.getEnabledProtocols());
sslsock.startHandshake();
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
this.sipStack.getStackLogger().logDebug(
"Handshake passed");
}
// allow application to enforce policy by validating the
// certificate
try {
sipStack
.getTlsSecurityPolicy()
.enforceTlsPolicy(
messageChannel
.getEncapsulatedClientTransaction());
} catch (SecurityException ex) {
throw new IOException(ex.getMessage());
}
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
this.sipStack.getStackLogger().logDebug(
"TLS Security policy passed");
}
OutputStream outputStream = clientSock
.getOutputStream();
writeChunks(outputStream, bytes, length);
putSocket(key, clientSock);
break;
} else {
try {
OutputStream outputStream = clientSock
.getOutputStream();
writeChunks(outputStream, bytes, length);
break;
} catch (IOException ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logException(ex);
// old connection is bad.
// remove from our table.
removeSocket(key);
try {
sipStack.getStackLogger().logDebug(
"Closing socket");
clientSock.close();
} catch (Exception e) {
}
clientSock = null;
retry_count++;
}
}
}
} catch (SSLHandshakeException ex) {
removeSocket(key);
throw ex;
} catch (IOException ex) {
removeSocket(key);
if (!isClient) {
receiverAddress = InetAddress.getByName(messageChannel
.getViaHost());
contactPort = messageChannel.getViaPort();
if (contactPort == -1)
contactPort = 5060;
key = makeKey(receiverAddress, messageChannel
.getViaPort());
clientSock = this.getSocket(key);
if (clientSock == null) {
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG)) {
sipStack.getStackLogger().logDebug(
"inaddr = " + receiverAddress +
" port = " + contactPort);
}
SSLSocket sslsock = sipStack.getNetworkLayer().createSSLSocket(
receiverAddress, contactPort, senderAddress);
OutputStream outputStream = sslsock
.getOutputStream();
HandshakeCompletedListener listner = new HandshakeCompletedListenerImpl(
(TLSMessageChannel) messageChannel);
((TLSMessageChannel) messageChannel)
.setHandshakeCompletedListener(listner);
sslsock.addHandshakeCompletedListener(listner);
sslsock.setEnabledProtocols(sipStack