Revision: 15839
Author: [email protected]
Date: Fri Dec 17 01:29:30 2010
Log: Fixes Issue 2206
http://code.google.com/p/mobicents/source/detail?r=15839
Added:
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/ClientAuthType.java
Modified:
/tags/jain-sip/1.2-build161/.classpath
/tags/jain-sip/1.2-build161/.project
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/SipStackImpl.java
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/SIPTransactionStack.java
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/TLSMessageChannel.java
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java
=======================================
--- /dev/null
+++
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/ClientAuthType.java
Fri Dec 17 01:29:30 2010
@@ -0,0 +1,34 @@
+/*
+ * Conditions Of Use
+ *
+ * This software was developed by employees of the National Institute of
+ * Standards and Technology (NIST), an agency of the Federal Government.
+ * Pursuant to title 15 Untied States Code Section 105, works of NIST
+ * employees are not subject to copyright protection in the United States
+ * and are considered to be in the public domain. As a result, a formal
+ * license is not needed to use the software.
+ *
+ * This software is provided by NIST as a service and is expressly
+ * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
+ * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
+ * AND DATA ACCURACY. NIST does not warrant or make any representations
+ * regarding the use of the software or the results thereof, including but
+ * not limited to the correctness, accuracy, reliability or usefulness of
+ * the software.
+ *
+ * Permission to use this software is contingent upon your acceptance
+ * of the terms of this agreement
+ *
+ * .
+ *
+ */
+package gov.nist.javax.sip.stack;
+
+/**
+ * @author [email protected]
+ *
+ */
+public enum ClientAuthType {
+ Enabled, Disabled, Want, Default;
+}
=======================================
--- /tags/jain-sip/1.2-build161/.classpath Thu Dec 16 01:28:26 2010
+++ /tags/jain-sip/1.2-build161/.classpath Fri Dec 17 01:29:30 2010
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="ant-tasks/src"/>
- <classpathentry kind="src" path="src"/>
+ <classpathentry excluding="gov/nist/javax/sip/stack/sctp/" kind="src"
path="src"/>
<classpathentry exported="true" kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/junit-3.8.1.jar"/>
<classpathentry kind="lib" path="ant-tasks/lib/jdom.jar"/>
=======================================
--- /tags/jain-sip/1.2-build161/.project Thu Dec 16 01:28:26 2010
+++ /tags/jain-sip/1.2-build161/.project Fri Dec 17 01:29:30 2010
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>jain-sip</name>
+ <name>jain-sip-1.2.161</name>
<comment></comment>
<projects>
</projects>
=======================================
--- /tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/SipStackImpl.java
Thu Dec 16 01:28:26 2010
+++ /tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/SipStackImpl.java
Fri Dec 17 01:29:30 2010
@@ -40,6 +40,7 @@
import gov.nist.javax.sip.parser.PipelinedMsgParser;
import gov.nist.javax.sip.parser.StringMsgParser;
import gov.nist.javax.sip.parser.StringMsgParserFactory;
+import gov.nist.javax.sip.stack.ClientAuthType;
import gov.nist.javax.sip.stack.DefaultMessageLogFactory;
import gov.nist.javax.sip.stack.DefaultRouter;
import gov.nist.javax.sip.stack.MessageProcessor;
@@ -516,6 +517,13 @@
* of outbund TLS connections.
* </li>
*
+ * <li><b>gov.nist.javax.sip.TLS_CLIENT_AUTH_TYPE = String </b> Valid
values are Default (backward compatible with previous versions)
+ * , Enabled, Want or Disabled. Set to Enabled if you want the SSL stack
to require a valid certificate chain from the client before
+ * accepting a connection. Set to Want if you want the SSL stack to
request a client Certificate, but not fail if one isn't presented.
+ * A Disabled value will not require a certificate chain.
+ *
+ * </li>
+ *
* <li><b>javax.net.ssl.keyStore = fileName </b> <br/>
* Default is <it>NULL</it>. If left undefined the keyStore and trustStore
will
* be left to the java runtime defaults. If defined, any TLS sockets
created
@@ -894,7 +902,14 @@
+ "- check that it is present on the classpath and that there is a
no-args constructor defined",
ex);
}
-
+
+ // Allow application to choose the tls client auth policy on
the socket
+ String clientAuthType =
configurationProperties.getProperty("gov.nist.javax.sip.TLS_CLIENT_AUTH_TYPE");
+ if (clientAuthType != null) {
+ super.clientAuth = ClientAuthType.valueOf(clientAuthType);
+ logger.logInfo("using " + clientAuthType + " tls auth policy");
+ }
+
// The following features are unique to the NIST implementation.
/*
=======================================
---
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/SIPTransactionStack.java
Thu Dec 16 01:28:26 2010
+++
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/SIPTransactionStack.java
Fri Dec 17 01:29:30 2010
@@ -385,6 +385,8 @@
private boolean deliverUnsolicitedNotify = false;
private boolean deliverTerminatedEventForAck = false;
+
+ protected ClientAuthType clientAuth = ClientAuthType.Default;
// ThreadPool when parsed SIP messages are processed. Affects the case
when many TCP calls use single socket.
private int tcpPostParsingThreadPoolSize = 0;
@@ -3025,4 +3027,18 @@
public int getEarlyDialogTimeout() {
return this.earlyDialogTimeout;
}
-}
+
+ /**
+ * @param clientAuth the clientAuth to set
+ */
+ public void setClientAuth(ClientAuthType clientAuth) {
+ this.clientAuth = clientAuth;
+ }
+
+ /**
+ * @return the clientAuth
+ */
+ public ClientAuthType getClientAuth() {
+ return clientAuth;
+ }
+}
=======================================
---
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/TLSMessageChannel.java
Thu Dec 16 01:28:26 2010
+++
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/TLSMessageChannel.java
Fri Dec 17 01:29:30 2010
@@ -42,19 +42,37 @@
******************************************************************************/
package gov.nist.javax.sip.stack;
-import gov.nist.javax.sip.header.*;
-import gov.nist.javax.sip.message.*;
-import gov.nist.javax.sip.parser.*;
-import gov.nist.core.*;
-
-import java.net.*;
-import java.io.*;
+import gov.nist.core.CommonLogger;
+import gov.nist.core.InternalErrorHandler;
+import gov.nist.core.LogWriter;
+import gov.nist.core.ServerLogger;
+import gov.nist.core.StackLogger;
+import gov.nist.javax.sip.header.CSeq;
+import gov.nist.javax.sip.header.CallID;
+import gov.nist.javax.sip.header.ContentLength;
+import gov.nist.javax.sip.header.From;
+import gov.nist.javax.sip.header.RequestLine;
+import gov.nist.javax.sip.header.RetryAfter;
+import gov.nist.javax.sip.header.StatusLine;
+import gov.nist.javax.sip.header.To;
+import gov.nist.javax.sip.header.Via;
+import gov.nist.javax.sip.header.ViaList;
+import gov.nist.javax.sip.message.SIPMessage;
+import gov.nist.javax.sip.message.SIPRequest;
+import gov.nist.javax.sip.message.SIPResponse;
+import gov.nist.javax.sip.parser.Pipeline;
+import gov.nist.javax.sip.parser.PipelinedMsgParser;
+import gov.nist.javax.sip.parser.SIPMessageListener;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.Socket;
import java.text.ParseException;
import javax.net.ssl.HandshakeCompletedListener;
-import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLHandshakeException;
-
+import javax.net.ssl.SSLSocket;
import javax.sip.address.Hop;
import javax.sip.message.Response;
@@ -142,7 +160,12 @@
if (sock instanceof SSLSocket) {
try {
SSLSocket sslSock = (SSLSocket) sock;
- sslSock.setNeedClientAuth(true);
+ if(sipStack.getClientAuth() != ClientAuthType.Want &&
sipStack.getClientAuth() != ClientAuthType.Disabled) {
+ sslSock.setNeedClientAuth(true);
+ }
+ if(logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
+ logger.logDebug("SSLServerSocket need client auth " +
sslSock.getNeedClientAuth());
+ }
this.handshakeCompletedListener = new
HandshakeCompletedListenerImpl(
this);
sslSock
=======================================
---
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java
Thu Dec 16 01:28:26 2010
+++
/tags/jain-sip/1.2-build161/src/gov/nist/javax/sip/stack/TLSMessageProcessor.java
Fri Dec 17 01:29:30 2010
@@ -47,17 +47,20 @@
import gov.nist.core.StackLogger;
import gov.nist.javax.sip.SipStackImpl;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLServerSocket;
-import javax.net.ssl.SSLSocket;
-
import java.io.IOException;
-import java.net.*;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLServerSocket;
+
/**
* Sit in a loop waiting for incoming tls connections and start a new
thread to handle each new
* connection. This is the active object that creates new TLS
MessageChannels (one for each new
@@ -109,14 +112,32 @@
this.sock =
sipStack.getNetworkLayer().createSSLServerSocket(this.getPort(), 0,
this.getIpAddress());
- ((SSLServerSocket) this.sock).setNeedClientAuth(false);
+ if(sipStack.getClientAuth() == ClientAuthType.Want ||
sipStack.getClientAuth() == ClientAuthType.Default) {
+ // we set it to true in Default case as well to keep backward
compatibility and default behavior
+ ((SSLServerSocket) this.sock).setWantClientAuth(true);
+ } else {
+ ((SSLServerSocket) this.sock).setWantClientAuth(false);
+ }
+ if(sipStack.getClientAuth() == ClientAuthType.Enabled) {
+ ((SSLServerSocket) this.sock).setNeedClientAuth(true);
+ } else {
+ ((SSLServerSocket) this.sock).setNeedClientAuth(false);
+ }
((SSLServerSocket) this.sock).setUseClientMode(false);
- ((SSLServerSocket) this.sock).setWantClientAuth(true);
String []enabledCiphers =
((SipStackImpl)sipStack).getEnabledCipherSuites();
- ((SSLServerSocket)
this.sock).setEnabledCipherSuites(enabledCiphers);
- ((SSLServerSocket)this.sock).setWantClientAuth(true);
-
-
+ ((SSLServerSocket)
this.sock).setEnabledCipherSuites(enabledCiphers);
+ if(sipStack.getClientAuth() == ClientAuthType.Want ||
sipStack.getClientAuth() == ClientAuthType.Default) {
+ // we set it to true in Default case as well to keep backward
compatibility and default behavior
+ ((SSLServerSocket) this.sock).setWantClientAuth(true);
+ } else {
+ ((SSLServerSocket) this.sock).setWantClientAuth(false);
+ }
+
+ if(logger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
+ logger.logDebug("SSLServerSocket want client auth " +
((SSLServerSocket) this.sock).getWantClientAuth());
+ logger.logDebug("SSLServerSocket need client auth " +
((SSLServerSocket) this.sock).getNeedClientAuth());
+ }
+
this.isRunning = true;
thread.start();