|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/lib/jss.def jss-4.2.6/mozilla/security/jss/lib/jss.def
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/lib/jss.def 2009-06-24 17:08:59.784371000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/lib/jss.def 2009-06-19 17:56:00.000000000 -0700
|
|
|
b93447 |
@@ -175,6 +175,7 @@ Java_org_mozilla_jss_ssl_SSLServerSocket
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_forceHandshake;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_getKeepAlive;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_getLocalAddressNative;
|
|
|
b93447 |
+Java_org_mozilla_jss_ssl_SocketBase_getLocalAddressByteArrayNative;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_getPort;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_getReceiveBufferSize;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_getSendBufferSize;
|
|
|
b93447 |
@@ -199,6 +200,7 @@ Java_org_mozilla_jss_ssl_SSLSocket_socke
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SSLSocket_socketWrite;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_getLocalPortNative;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_getPeerAddressNative;
|
|
|
b93447 |
+Java_org_mozilla_jss_ssl_SocketBase_getPeerAddressByteArrayNative;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_setClientCertNicknameNative;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_requestClientAuthNoExpiryCheckNative;
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_setSSLOption;
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SSLServerSocket.java jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SSLServerSocket.java
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SSLServerSocket.java 2007-03-20 15:39:28.000000000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SSLServerSocket.java 2009-06-24 13:46:49.000000000 -0700
|
|
|
b93447 |
@@ -36,7 +36,8 @@
|
|
|
b93447 |
|
|
|
b93447 |
package org.mozilla.jss.ssl;
|
|
|
b93447 |
|
|
|
b93447 |
-import java.net.InetAddress;
|
|
|
b93447 |
+import java.util.*;
|
|
|
b93447 |
+import java.net.*;
|
|
|
b93447 |
import java.io.IOException;
|
|
|
b93447 |
import java.net.Socket;
|
|
|
b93447 |
import java.net.SocketException;
|
|
|
b93447 |
@@ -138,34 +139,34 @@ public class SSLServerSocket extends jav
|
|
|
b93447 |
super.close();
|
|
|
b93447 |
|
|
|
b93447 |
// create the socket
|
|
|
b93447 |
+
|
|
|
b93447 |
+ int socketFamily = SocketBase.SSL_AF_INET;
|
|
|
b93447 |
+ if(SocketBase.supportsIPV6()) {
|
|
|
b93447 |
+ socketFamily = SocketBase.SSL_AF_INET6;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
sockProxy = new SocketProxy(
|
|
|
b93447 |
- base.socketCreate(this, certApprovalCallback, null) );
|
|
|
b93447 |
+ base.socketCreate(this, certApprovalCallback, null,socketFamily) );
|
|
|
b93447 |
|
|
|
b93447 |
base.setProxy(sockProxy);
|
|
|
b93447 |
|
|
|
b93447 |
setReuseAddress(reuseAddr);
|
|
|
b93447 |
|
|
|
b93447 |
- // bind it to the local address and port
|
|
|
b93447 |
- if( bindAddr == null ) {
|
|
|
b93447 |
- bindAddr = anyLocalAddr;
|
|
|
b93447 |
- }
|
|
|
b93447 |
byte[] bindAddrBA = null;
|
|
|
b93447 |
if( bindAddr != null ) {
|
|
|
b93447 |
bindAddrBA = bindAddr.getAddress();
|
|
|
b93447 |
}
|
|
|
b93447 |
base.socketBind(bindAddrBA, port);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ String hostName = null;
|
|
|
b93447 |
+ if(bindAddr != null) {
|
|
|
b93447 |
+ hostName = bindAddr.getCanonicalHostName();
|
|
|
b93447 |
+ }
|
|
|
b93447 |
socketListen(backlog);
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
private native void socketListen(int backlog) throws SocketException;
|
|
|
b93447 |
|
|
|
b93447 |
- private static InetAddress anyLocalAddr;
|
|
|
b93447 |
- static {
|
|
|
b93447 |
- try {
|
|
|
b93447 |
- anyLocalAddr = InetAddress.getByName("0.0.0.0");
|
|
|
b93447 |
- } catch (java.net.UnknownHostException e) { }
|
|
|
b93447 |
- }
|
|
|
b93447 |
-
|
|
|
b93447 |
/**
|
|
|
b93447 |
* Accepts a connection. This call will block until a connection is made
|
|
|
b93447 |
* or the timeout is reached.
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.c jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.c
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.c 2007-05-08 18:40:14.000000000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.c 2009-06-24 13:27:15.000000000 -0700
|
|
|
b93447 |
@@ -460,10 +460,15 @@ Java_org_mozilla_jss_ssl_SSLSocket_socke
|
|
|
b93447 |
JSSL_SocketData *sock;
|
|
|
b93447 |
PRNetAddr addr;
|
|
|
b93447 |
jbyte *addrBAelems = NULL;
|
|
|
b93447 |
+ int addrBALen = 0;
|
|
|
b93447 |
PRStatus status;
|
|
|
b93447 |
int stat;
|
|
|
b93447 |
const char *hostnameStr=NULL;
|
|
|
b93447 |
|
|
|
b93447 |
+ jmethodID supportsIPV6ID;
|
|
|
b93447 |
+ jclass socketBaseClass;
|
|
|
b93447 |
+ jboolean supportsIPV6 = 0;
|
|
|
b93447 |
+
|
|
|
b93447 |
if( JSSL_getSockData(env, self, &sock) != PR_SUCCESS) {
|
|
|
b93447 |
/* exception was thrown */
|
|
|
b93447 |
goto finish;
|
|
|
b93447 |
@@ -472,16 +477,32 @@ Java_org_mozilla_jss_ssl_SSLSocket_socke
|
|
|
b93447 |
/*
|
|
|
b93447 |
* setup the PRNetAddr structure
|
|
|
b93447 |
*/
|
|
|
b93447 |
- addr.inet.family = AF_INET;
|
|
|
b93447 |
- addr.inet.port = htons(port);
|
|
|
b93447 |
- PR_ASSERT(sizeof(addr.inet.ip) == 4);
|
|
|
b93447 |
- PR_ASSERT( (*env)->GetArrayLength(env, addrBA) == 4);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ socketBaseClass = (*env)->FindClass(env, SOCKET_BASE_NAME);
|
|
|
b93447 |
+ if( socketBaseClass == NULL ) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ supportsIPV6ID = (*env)->GetStaticMethodID(env, socketBaseClass,
|
|
|
b93447 |
+ SUPPORTS_IPV6_NAME, SUPPORTS_IPV6_SIG);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( supportsIPV6ID == NULL ) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ supportsIPV6 = (*env)->CallStaticBooleanMethod(env, socketBaseClass,
|
|
|
b93447 |
+ supportsIPV6ID);
|
|
|
b93447 |
+
|
|
|
b93447 |
addrBAelems = (*env)->GetByteArrayElements(env, addrBA, NULL);
|
|
|
b93447 |
+ addrBALen = (*env)->GetArrayLength(env, addrBA);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ PR_ASSERT(addrBALen != 0);
|
|
|
b93447 |
+
|
|
|
b93447 |
if( addrBAelems == NULL ) {
|
|
|
b93447 |
ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
goto finish;
|
|
|
b93447 |
}
|
|
|
b93447 |
- memcpy(&addr.inet.ip, addrBAelems, 4);
|
|
|
b93447 |
|
|
|
b93447 |
/*
|
|
|
b93447 |
* Tell SSL the URL we think we want to connect to.
|
|
|
b93447 |
@@ -495,6 +516,38 @@ Java_org_mozilla_jss_ssl_SSLSocket_socke
|
|
|
b93447 |
goto finish;
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
+ if( addrBAelems == NULL ) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if(addrBALen != 4 && addrBALen != 16) {
|
|
|
b93447 |
+ JSSL_throwSSLSocketException(env, "Invalid address in connect!");
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( addrBALen == 4) {
|
|
|
b93447 |
+ addr.inet.family = AF_INET;
|
|
|
b93447 |
+ addr.inet.port = PR_htons(port);
|
|
|
b93447 |
+ memcpy(&addr.inet.ip, addrBAelems, 4);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if(supportsIPV6) {
|
|
|
b93447 |
+ addr.ipv6.family = AF_INET6;
|
|
|
b93447 |
+ addr.ipv6.port = PR_htons(port);
|
|
|
b93447 |
+ PR_ConvertIPv4AddrToIPv6(addr.inet.ip,&addr.ipv6.ip);
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ } else { /* Must be 16 and ipv6 */
|
|
|
b93447 |
+ if(supportsIPV6) {
|
|
|
b93447 |
+ addr.ipv6.family = AF_INET6;
|
|
|
b93447 |
+ addr.ipv6.port = PR_htons(port);
|
|
|
b93447 |
+ memcpy(&addr.ipv6.ip,addrBAelems, 16);
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ JSSL_throwSSLSocketException(env, "Invalid address in connect!");
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
/*
|
|
|
b93447 |
* make the connect call
|
|
|
b93447 |
*/
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.java jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.java
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.java 2007-05-08 18:40:14.000000000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SSLSocket.java 2009-06-24 13:45:59.000000000 -0700
|
|
|
b93447 |
@@ -243,11 +243,16 @@ public class SSLSocket extends java.net.
|
|
|
b93447 |
SSLClientCertificateSelectionCallback clientCertSelectionCallback)
|
|
|
b93447 |
throws IOException
|
|
|
b93447 |
{
|
|
|
b93447 |
+
|
|
|
b93447 |
+ int socketFamily = SocketBase.SSL_AF_INET;
|
|
|
b93447 |
+ if(SocketBase.supportsIPV6()) {
|
|
|
b93447 |
+ socketFamily = SocketBase.SSL_AF_INET6;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
// create the socket
|
|
|
b93447 |
sockProxy =
|
|
|
b93447 |
new SocketProxy(
|
|
|
b93447 |
base.socketCreate(
|
|
|
b93447 |
- this, certApprovalCallback, clientCertSelectionCallback) );
|
|
|
b93447 |
+ this, certApprovalCallback, clientCertSelectionCallback,socketFamily) );
|
|
|
b93447 |
|
|
|
b93447 |
base.setProxy(sockProxy);
|
|
|
b93447 |
|
|
|
b93447 |
@@ -288,7 +293,7 @@ public class SSLSocket extends java.net.
|
|
|
b93447 |
new SocketProxy(
|
|
|
b93447 |
base.socketCreate(
|
|
|
b93447 |
this, certApprovalCallback, clientCertSelectionCallback,
|
|
|
b93447 |
- s, host ) );
|
|
|
b93447 |
+ s, host,SocketBase.SSL_AF_INET ) );
|
|
|
b93447 |
|
|
|
b93447 |
base.setProxy(sockProxy);
|
|
|
b93447 |
resetHandshake();
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SocketBase.java jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SocketBase.java
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/SocketBase.java 2007-03-20 15:39:28.000000000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/SocketBase.java 2009-06-24 13:50:32.000000000 -0700
|
|
|
b93447 |
@@ -70,16 +70,16 @@ class SocketBase {
|
|
|
b93447 |
native byte[] socketCreate(Object socketObject,
|
|
|
b93447 |
SSLCertificateApprovalCallback certApprovalCallback,
|
|
|
b93447 |
SSLClientCertificateSelectionCallback clientCertSelectionCallback,
|
|
|
b93447 |
- java.net.Socket javaSock, String host)
|
|
|
b93447 |
+ java.net.Socket javaSock, String host,int family)
|
|
|
b93447 |
throws SocketException;
|
|
|
b93447 |
|
|
|
b93447 |
byte[] socketCreate(Object socketObject,
|
|
|
b93447 |
SSLCertificateApprovalCallback certApprovalCallback,
|
|
|
b93447 |
- SSLClientCertificateSelectionCallback clientCertSelectionCallback)
|
|
|
b93447 |
+ SSLClientCertificateSelectionCallback clientCertSelectionCallback,int family)
|
|
|
b93447 |
throws SocketException
|
|
|
b93447 |
{
|
|
|
b93447 |
return socketCreate(socketObject, certApprovalCallback,
|
|
|
b93447 |
- clientCertSelectionCallback, null, null);
|
|
|
b93447 |
+ clientCertSelectionCallback, null, null,family);
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
native void socketBind(byte[] addrBA, int port) throws SocketException;
|
|
|
b93447 |
@@ -115,6 +115,10 @@ class SocketBase {
|
|
|
b93447 |
static final int SSL_REQUIRE_FIRST_HANDSHAKE = 20;
|
|
|
b93447 |
static final int SSL_REQUIRE_NO_ERROR = 21;
|
|
|
b93447 |
|
|
|
b93447 |
+
|
|
|
b93447 |
+ static final int SSL_AF_INET = 50;
|
|
|
b93447 |
+ static final int SSL_AF_INET6 = 51;
|
|
|
b93447 |
+
|
|
|
b93447 |
void close() throws IOException {
|
|
|
b93447 |
socketClose();
|
|
|
b93447 |
}
|
|
|
b93447 |
@@ -281,13 +285,25 @@ class SocketBase {
|
|
|
b93447 |
return in;
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
+ private native byte[] getLocalAddressByteArrayNative() throws SocketException;
|
|
|
b93447 |
+ private native byte[] getPeerAddressByteArrayNative() throws SocketException;
|
|
|
b93447 |
/**
|
|
|
b93447 |
* @return the InetAddress of the peer end of the socket.
|
|
|
b93447 |
*/
|
|
|
b93447 |
InetAddress getInetAddress()
|
|
|
b93447 |
{
|
|
|
b93447 |
try {
|
|
|
b93447 |
- return convertIntToInetAddress( getPeerAddressNative() );
|
|
|
b93447 |
+ byte[] address = getPeerAddressByteArrayNative();
|
|
|
b93447 |
+
|
|
|
b93447 |
+ InetAddress iAddr = null;
|
|
|
b93447 |
+
|
|
|
b93447 |
+ try {
|
|
|
b93447 |
+
|
|
|
b93447 |
+ iAddr = InetAddress.getByAddress(address);
|
|
|
b93447 |
+ } catch(UnknownHostException e) {
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ return iAddr;
|
|
|
b93447 |
} catch(SocketException e) {
|
|
|
b93447 |
return null;
|
|
|
b93447 |
}
|
|
|
b93447 |
@@ -299,7 +315,17 @@ class SocketBase {
|
|
|
b93447 |
*/
|
|
|
b93447 |
InetAddress getLocalAddress() {
|
|
|
b93447 |
try {
|
|
|
b93447 |
- return convertIntToInetAddress( getLocalAddressNative() );
|
|
|
b93447 |
+ byte[] address = getLocalAddressByteArrayNative();
|
|
|
b93447 |
+
|
|
|
b93447 |
+ InetAddress lAddr = null;
|
|
|
b93447 |
+
|
|
|
b93447 |
+ try {
|
|
|
b93447 |
+
|
|
|
b93447 |
+ lAddr = InetAddress.getByAddress(address);
|
|
|
b93447 |
+ } catch(UnknownHostException e) {
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ return lAddr;
|
|
|
b93447 |
} catch(SocketException e) {
|
|
|
b93447 |
return null;
|
|
|
b93447 |
}
|
|
|
b93447 |
@@ -378,4 +404,45 @@ class SocketBase {
|
|
|
b93447 |
return topException;
|
|
|
b93447 |
}
|
|
|
b93447 |
}
|
|
|
b93447 |
+
|
|
|
b93447 |
+ static private int supportsIPV6 = -1;
|
|
|
b93447 |
+ static boolean supportsIPV6() {
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if(supportsIPV6 >= 0) {
|
|
|
b93447 |
+ if(supportsIPV6 > 0) {
|
|
|
b93447 |
+ return true;
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ return false;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ Enumeration netInter;
|
|
|
b93447 |
+ try {
|
|
|
b93447 |
+ netInter = NetworkInterface.getNetworkInterfaces();
|
|
|
b93447 |
+ } catch (SocketException e) {
|
|
|
b93447 |
+
|
|
|
b93447 |
+ return false;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ while ( netInter.hasMoreElements() )
|
|
|
b93447 |
+ {
|
|
|
b93447 |
+ NetworkInterface ni = (NetworkInterface)netInter.nextElement();
|
|
|
b93447 |
+ Enumeration addrs = ni.getInetAddresses();
|
|
|
b93447 |
+ while ( addrs.hasMoreElements() )
|
|
|
b93447 |
+ {
|
|
|
b93447 |
+ Object o = addrs.nextElement();
|
|
|
b93447 |
+ if ( o.getClass() == InetAddress.class ||
|
|
|
b93447 |
+ o.getClass() == Inet4Address.class ||
|
|
|
b93447 |
+ o.getClass() == Inet6Address.class )
|
|
|
b93447 |
+ {
|
|
|
b93447 |
+ InetAddress iaddr = (InetAddress) o;
|
|
|
b93447 |
+ if(o.getClass() == Inet6Address.class) {
|
|
|
b93447 |
+ supportsIPV6 = 1;
|
|
|
b93447 |
+ return true;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ supportsIPV6 = 0;
|
|
|
b93447 |
+ return false;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
}
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/common.c jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/common.c
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/common.c 2007-04-24 11:34:58.000000000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/common.c 2009-06-24 14:22:02.000000000 -0700
|
|
|
b93447 |
@@ -33,7 +33,6 @@
|
|
|
b93447 |
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
b93447 |
*
|
|
|
b93447 |
* ***** END LICENSE BLOCK ***** */
|
|
|
b93447 |
-
|
|
|
b93447 |
#include <nspr.h>
|
|
|
b93447 |
#include <jni.h>
|
|
|
b93447 |
#include <pk11func.h>
|
|
|
b93447 |
@@ -51,6 +50,9 @@
|
|
|
b93447 |
#include <winsock.h>
|
|
|
b93447 |
#endif
|
|
|
b93447 |
|
|
|
b93447 |
+#define SSL_AF_INET 50
|
|
|
b93447 |
+#define SSL_AF_INET6 51
|
|
|
b93447 |
+
|
|
|
b93447 |
void
|
|
|
b93447 |
JSSL_throwSSLSocketException(JNIEnv *env, char *message)
|
|
|
b93447 |
{
|
|
|
b93447 |
@@ -142,7 +144,7 @@ finish:
|
|
|
b93447 |
JNIEXPORT jbyteArray JNICALL
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_socketCreate(JNIEnv *env, jobject self,
|
|
|
b93447 |
jobject sockObj, jobject certApprovalCallback,
|
|
|
b93447 |
- jobject clientCertSelectionCallback, jobject javaSock, jstring host)
|
|
|
b93447 |
+ jobject clientCertSelectionCallback, jobject javaSock, jstring host,jint family)
|
|
|
b93447 |
{
|
|
|
b93447 |
jbyteArray sdArray = NULL;
|
|
|
b93447 |
JSSL_SocketData *sockdata = NULL;
|
|
|
b93447 |
@@ -150,10 +152,21 @@ Java_org_mozilla_jss_ssl_SocketBase_sock
|
|
|
b93447 |
PRFileDesc *newFD;
|
|
|
b93447 |
PRFileDesc *tmpFD;
|
|
|
b93447 |
PRFilePrivate *priv = NULL;
|
|
|
b93447 |
+ int socketFamily = 0;
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if (family != SSL_AF_INET6 && family != SSL_AF_INET) {
|
|
|
b93447 |
+ JSSL_throwSSLSocketException(env,
|
|
|
b93447 |
+ "socketCreate() Invalid family!");
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ if( family == SSL_AF_INET)
|
|
|
b93447 |
+ socketFamily = PR_AF_INET;
|
|
|
b93447 |
+ else
|
|
|
b93447 |
+ socketFamily = PR_AF_INET6;
|
|
|
b93447 |
|
|
|
b93447 |
if( javaSock == NULL ) {
|
|
|
b93447 |
/* create a TCP socket */
|
|
|
b93447 |
- newFD = PR_NewTCPSocket();
|
|
|
b93447 |
+ newFD = PR_OpenTCPSocket(socketFamily);
|
|
|
b93447 |
if( newFD == NULL ) {
|
|
|
b93447 |
JSSL_throwSSLSocketException(env,
|
|
|
b93447 |
"PR_NewTCPSocket() returned NULL");
|
|
|
b93447 |
@@ -394,10 +407,10 @@ PRInt32 JSSL_enums[] = {
|
|
|
b93447 |
SSL_REQUIRE_ALWAYS, /* 19 */ /* ssl.h */
|
|
|
b93447 |
SSL_REQUIRE_FIRST_HANDSHAKE,/* 20 */ /* ssl.h */
|
|
|
b93447 |
SSL_REQUIRE_NO_ERROR, /* 21 */ /* ssl.h */
|
|
|
b93447 |
-
|
|
|
b93447 |
0
|
|
|
b93447 |
};
|
|
|
b93447 |
|
|
|
b93447 |
+
|
|
|
b93447 |
JNIEXPORT void JNICALL
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_socketBind
|
|
|
b93447 |
(JNIEnv *env, jobject self, jbyteArray addrBA, jint port)
|
|
|
b93447 |
@@ -405,8 +418,13 @@ Java_org_mozilla_jss_ssl_SocketBase_sock
|
|
|
b93447 |
JSSL_SocketData *sock;
|
|
|
b93447 |
PRNetAddr addr;
|
|
|
b93447 |
jbyte *addrBAelems = NULL;
|
|
|
b93447 |
+ int addrBALen = 0;
|
|
|
b93447 |
PRStatus status;
|
|
|
b93447 |
|
|
|
b93447 |
+ jmethodID supportsIPV6ID;
|
|
|
b93447 |
+ jclass socketBaseClass;
|
|
|
b93447 |
+ jboolean supportsIPV6 = 0;
|
|
|
b93447 |
+
|
|
|
b93447 |
if( JSSL_getSockData(env, self, &sock) != PR_SUCCESS) {
|
|
|
b93447 |
/* exception was thrown */
|
|
|
b93447 |
goto finish;
|
|
|
b93447 |
@@ -415,19 +433,72 @@ Java_org_mozilla_jss_ssl_SocketBase_sock
|
|
|
b93447 |
/*
|
|
|
b93447 |
* setup the PRNetAddr structure
|
|
|
b93447 |
*/
|
|
|
b93447 |
- addr.inet.family = AF_INET;
|
|
|
b93447 |
- addr.inet.port = htons(port);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ /*
|
|
|
b93447 |
+ * Do we support IPV6?
|
|
|
b93447 |
+ */
|
|
|
b93447 |
+
|
|
|
b93447 |
+ socketBaseClass = (*env)->FindClass(env, SOCKET_BASE_NAME);
|
|
|
b93447 |
+ if( socketBaseClass == NULL ) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ supportsIPV6ID = (*env)->GetStaticMethodID(env, socketBaseClass,
|
|
|
b93447 |
+ SUPPORTS_IPV6_NAME, SUPPORTS_IPV6_SIG);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( supportsIPV6ID == NULL ) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ supportsIPV6 = (*env)->CallStaticBooleanMethod(env, socketBaseClass,
|
|
|
b93447 |
+ supportsIPV6ID);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ memset( &addr, 0, sizeof( PRNetAddr ));
|
|
|
b93447 |
+
|
|
|
b93447 |
if( addrBA != NULL ) {
|
|
|
b93447 |
- PR_ASSERT(sizeof(addr.inet.ip) == 4);
|
|
|
b93447 |
- PR_ASSERT( (*env)->GetArrayLength(env, addrBA) == 4);
|
|
|
b93447 |
addrBAelems = (*env)->GetByteArrayElements(env, addrBA, NULL);
|
|
|
b93447 |
+ addrBALen = (*env)->GetArrayLength(env, addrBA);
|
|
|
b93447 |
+
|
|
|
b93447 |
if( addrBAelems == NULL ) {
|
|
|
b93447 |
ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
goto finish;
|
|
|
b93447 |
}
|
|
|
b93447 |
- memcpy(&addr.inet.ip, addrBAelems, 4);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if(addrBALen != 4 && addrBALen != 16) {
|
|
|
b93447 |
+ JSS_throwMsgPrErr(env, BIND_EXCEPTION,
|
|
|
b93447 |
+ "Invalid address in bind!");
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( addrBALen == 4) {
|
|
|
b93447 |
+ addr.inet.family = PR_AF_INET;
|
|
|
b93447 |
+ addr.inet.port = PR_htons(port);
|
|
|
b93447 |
+ memcpy(&addr.inet.ip, addrBAelems, 4);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if(supportsIPV6) {
|
|
|
b93447 |
+ addr.inet.family = PR_AF_INET6;
|
|
|
b93447 |
+ addr.ipv6.port = PR_htons(port);
|
|
|
b93447 |
+ PR_ConvertIPv4AddrToIPv6(addr.inet.ip,&addr.ipv6.ip);
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ } else { /* Must be 16 and ipv6 */
|
|
|
b93447 |
+ if(supportsIPV6) {
|
|
|
b93447 |
+ addr.ipv6.family = PR_AF_INET6;
|
|
|
b93447 |
+ addr.ipv6.port = PR_htons(port);
|
|
|
b93447 |
+ memcpy(&addr.ipv6.ip,addrBAelems, 16);
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ JSS_throwMsgPrErr(env, BIND_EXCEPTION,
|
|
|
b93447 |
+ "Invalid address in bind!");
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ }
|
|
|
b93447 |
} else {
|
|
|
b93447 |
- addr.inet.ip = PR_htonl(INADDR_ANY);
|
|
|
b93447 |
+ if(supportsIPV6) {
|
|
|
b93447 |
+ status = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, port, &addr);
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ status = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET, port, &addr);
|
|
|
b93447 |
+ }
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
/* do the bind() call */
|
|
|
b93447 |
@@ -601,6 +672,78 @@ finish:
|
|
|
b93447 |
return status;
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
+JNIEXPORT jbyteArray JNICALL
|
|
|
b93447 |
+Java_org_mozilla_jss_ssl_SocketBase_getPeerAddressByteArrayNative
|
|
|
b93447 |
+ (JNIEnv *env, jobject self)
|
|
|
b93447 |
+{
|
|
|
b93447 |
+ jbyteArray byteArray=NULL;
|
|
|
b93447 |
+ PRNetAddr addr;
|
|
|
b93447 |
+ jbyte *address=NULL;
|
|
|
b93447 |
+ int size=4;
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( JSSL_getSockAddr(env, self, &addr, PEER_SOCK) != PR_SUCCESS) {
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( PR_NetAddrFamily(&addr) == PR_AF_INET6) {
|
|
|
b93447 |
+ size = 16;
|
|
|
b93447 |
+ address = (jbyte *) &addr.ipv6.ip;
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ address = (jbyte *) &addr.inet.ip;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ byteArray = (*env)->NewByteArray(env,size);
|
|
|
b93447 |
+ if(byteArray == NULL) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ (*env)->SetByteArrayRegion(env, byteArray, 0,size ,address);
|
|
|
b93447 |
+ if( (*env)->ExceptionOccurred(env) != NULL) {
|
|
|
b93447 |
+ PR_ASSERT(PR_FALSE);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+finish:
|
|
|
b93447 |
+ return byteArray;
|
|
|
b93447 |
+}
|
|
|
b93447 |
+
|
|
|
b93447 |
+JNIEXPORT jbyteArray JNICALL
|
|
|
b93447 |
+Java_org_mozilla_jss_ssl_SocketBase_getLocalAddressByteArrayNative
|
|
|
b93447 |
+ (JNIEnv *env, jobject self)
|
|
|
b93447 |
+{
|
|
|
b93447 |
+ jbyteArray byteArray=NULL;
|
|
|
b93447 |
+ PRNetAddr addr;
|
|
|
b93447 |
+ jbyte *address=NULL;
|
|
|
b93447 |
+ int size=4;
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( JSSL_getSockAddr(env, self, &addr, LOCAL_SOCK) != PR_SUCCESS) {
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if( PR_NetAddrFamily(&addr) == PR_AF_INET6) {
|
|
|
b93447 |
+ size = 16;
|
|
|
b93447 |
+ address = (jbyte *) &addr.ipv6.ip;
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ address = (jbyte *) &addr.inet.ip;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+ byteArray = (*env)->NewByteArray(env,size);
|
|
|
b93447 |
+ if(byteArray == NULL) {
|
|
|
b93447 |
+ ASSERT_OUTOFMEM(env);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+ (*env)->SetByteArrayRegion(env, byteArray, 0,size,address);
|
|
|
b93447 |
+ if( (*env)->ExceptionOccurred(env) != NULL) {
|
|
|
b93447 |
+ PR_ASSERT(PR_FALSE);
|
|
|
b93447 |
+ goto finish;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
+
|
|
|
b93447 |
+finish:
|
|
|
b93447 |
+ return byteArray;
|
|
|
b93447 |
+}
|
|
|
b93447 |
+
|
|
|
b93447 |
+/* Leave the original versions of these functions for compatibility */
|
|
|
b93447 |
+
|
|
|
b93447 |
JNIEXPORT jint JNICALL
|
|
|
b93447 |
Java_org_mozilla_jss_ssl_SocketBase_getPeerAddressNative
|
|
|
b93447 |
(JNIEnv *env, jobject self)
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/javasock.c jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/javasock.c
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/ssl/javasock.c 2007-04-24 11:34:58.000000000 -0700
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/ssl/javasock.c 2009-06-24 13:43:13.000000000 -0700
|
|
|
b93447 |
@@ -290,6 +290,7 @@ getInetAddress(PRFileDesc *fd, PRNetAddr
|
|
|
b93447 |
jobject inetAddress;
|
|
|
b93447 |
jbyteArray addrByteArray;
|
|
|
b93447 |
jint port;
|
|
|
b93447 |
+ int addrBALen = 0;
|
|
|
b93447 |
|
|
|
b93447 |
if( GET_ENV(fd->secret->javaVM, env) ) goto finish;
|
|
|
b93447 |
|
|
|
b93447 |
@@ -377,8 +378,9 @@ getInetAddress(PRFileDesc *fd, PRNetAddr
|
|
|
b93447 |
|
|
|
b93447 |
memset(addr, 0, sizeof(PRNetAddr));
|
|
|
b93447 |
|
|
|
b93447 |
- /* we only handle IPV4 */
|
|
|
b93447 |
- PR_ASSERT( (*env)->GetArrayLength(env, addrByteArray) == 4 );
|
|
|
b93447 |
+ addrBALen = (*env)->GetArrayLength(env, addrByteArray);
|
|
|
b93447 |
+
|
|
|
b93447 |
+ PR_ASSERT( (addrBALen == 4) || (addrBALen == 16 ) );
|
|
|
b93447 |
|
|
|
b93447 |
/* make sure you release them later */
|
|
|
b93447 |
addrBytes = (*env)->GetByteArrayElements(env, addrByteArray, NULL);
|
|
|
b93447 |
@@ -388,9 +390,16 @@ getInetAddress(PRFileDesc *fd, PRNetAddr
|
|
|
b93447 |
}
|
|
|
b93447 |
|
|
|
b93447 |
/* ip field is in network byte order */
|
|
|
b93447 |
- memcpy( (void*) &addr->inet.ip, addrBytes, 4);
|
|
|
b93447 |
- addr->inet.family = PR_AF_INET;
|
|
|
b93447 |
- addr->inet.port = port;
|
|
|
b93447 |
+
|
|
|
b93447 |
+ if (addrBALen == 4) {
|
|
|
b93447 |
+ memcpy( (void*) &addr->inet.ip, addrBytes, 4);
|
|
|
b93447 |
+ addr->inet.family = PR_AF_INET;
|
|
|
b93447 |
+ addr->inet.port = port;
|
|
|
b93447 |
+ } else {
|
|
|
b93447 |
+ memcpy( (void*) &addr->ipv6.ip,addrBytes, 16);
|
|
|
b93447 |
+ addr->inet.family = PR_AF_INET6;
|
|
|
b93447 |
+ addr->inet.port = port;
|
|
|
b93447 |
+ }
|
|
|
b93447 |
|
|
|
b93447 |
(*env)->ReleaseByteArrayElements(env, addrByteArray, addrBytes,
|
|
|
b93447 |
JNI_ABORT);
|
|
|
b93447 |
diff -rupN jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/util/java_ids.h jss-4.2.6/mozilla/security/jss/org/mozilla/jss/util/java_ids.h
|
|
|
b93447 |
--- jss-4.2.6.pre-IPv6/mozilla/security/jss/org/mozilla/jss/util/java_ids.h 2006-02-22 17:21:52.000000000 -0800
|
|
|
b93447 |
+++ jss-4.2.6/mozilla/security/jss/org/mozilla/jss/util/java_ids.h 2009-06-19 17:56:00.000000000 -0700
|
|
|
b93447 |
@@ -312,6 +312,8 @@ PR_BEGIN_EXTERN_C
|
|
|
b93447 |
#define SOCKET_BASE_NAME "org/mozilla/jss/ssl/SocketBase"
|
|
|
b93447 |
#define PROCESS_EXCEPTIONS_NAME "processExceptions"
|
|
|
b93447 |
#define PROCESS_EXCEPTIONS_SIG "(Ljava/lang/Throwable;Ljava/lang/Throwable;)Ljava/lang/Throwable;"
|
|
|
b93447 |
+#define SUPPORTS_IPV6_NAME "supportsIPV6"
|
|
|
b93447 |
+#define SUPPORTS_IPV6_SIG "()Z"
|
|
|
b93447 |
|
|
|
b93447 |
/*
|
|
|
b93447 |
* SSLCertificateApprovalCallback
|