Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
ac09e22d
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ac09e22d
编写于
3月 24, 2010
作者:
A
asaha
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
69285fcf
d876c863
变更
13
展开全部
隐藏空白更改
内联
并排
Showing
13 changed file
with
4941 addition
and
33 deletion
+4941
-33
src/share/classes/javax/net/SocketFactory.java
src/share/classes/javax/net/SocketFactory.java
+15
-3
src/share/classes/sun/net/NetworkClient.java
src/share/classes/sun/net/NetworkClient.java
+16
-3
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
.../classes/sun/net/www/protocol/http/HttpURLConnection.java
+25
-4
src/share/classes/sun/net/www/protocol/https/HttpsClient.java
...share/classes/sun/net/www/protocol/https/HttpsClient.java
+38
-18
src/share/classes/sun/security/ssl/SSLSocketImpl.java
src/share/classes/sun/security/ssl/SSLSocketImpl.java
+5
-0
src/share/native/sun/management/Flag.c
src/share/native/sun/management/Flag.c
+2
-5
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java
.../www/protocol/https/HttpsURLConnection/DNSIdentities.java
+879
-0
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsCreateSockTest.java
...rotocol/https/HttpsURLConnection/HttpsCreateSockTest.java
+210
-0
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsSocketFacTest.java
...protocol/https/HttpsURLConnection/HttpsSocketFacTest.java
+225
-0
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java
...ocol/https/HttpsURLConnection/IPAddressDNSIdentities.java
+887
-0
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java
...tocol/https/HttpsURLConnection/IPAddressIPIdentities.java
+880
-0
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java
...t/www/protocol/https/HttpsURLConnection/IPIdentities.java
+880
-0
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java
...net/www/protocol/https/HttpsURLConnection/Identities.java
+879
-0
未找到文件。
src/share/classes/javax/net/SocketFactory.java
浏览文件 @
ac09e22d
...
...
@@ -27,8 +27,10 @@
package
javax.net
;
import
java.io.IOException
;
import
java.net.*
;
import
java.net.InetAddress
;
import
java.net.Socket
;
import
java.net.SocketException
;
import
java.net.UnknownHostException
;
/**
* This class creates sockets. It may be subclassed by other factories,
...
...
@@ -113,7 +115,17 @@ public abstract class SocketFactory
* @see java.net.Socket#Socket()
*/
public
Socket
createSocket
()
throws
IOException
{
throw
new
SocketException
(
"Unconnected sockets not implemented"
);
//
// bug 6771432:
// The Exception is used by HttpsClient to signal that
// unconnected sockets have not been implemented.
//
UnsupportedOperationException
uop
=
new
UnsupportedOperationException
();
SocketException
se
=
new
SocketException
(
"Unconnected sockets not implemented"
);
se
.
initCause
(
uop
);
throw
se
;
}
...
...
src/share/classes/sun/net/NetworkClient.java
浏览文件 @
ac09e22d
...
...
@@ -29,7 +29,6 @@ import java.net.Socket;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.UnknownHostException
;
import
java.net.URL
;
import
java.net.Proxy
;
import
java.util.Arrays
;
import
java.security.AccessController
;
...
...
@@ -157,10 +156,15 @@ public class NetworkClient {
public
Socket
run
()
{
return
new
Socket
(
proxy
);
}});
}
else
}
else
if
(
proxy
.
type
()
==
Proxy
.
Type
.
DIRECT
)
{
s
=
createSocket
();
}
else
{
// Still connecting through a proxy
// server & port will be the proxy address and port
s
=
new
Socket
(
Proxy
.
NO_PROXY
);
}
}
else
s
=
new
Socket
();
s
=
create
Socket
();
// Instance specific timeouts do have priority, that means
// connectTimeout & readTimeout (-1 means not set)
// Then global default timeouts
...
...
@@ -182,6 +186,15 @@ public class NetworkClient {
return
s
;
}
/**
* The following method, createSocket, is provided to allow the
* https client to override it so that it may use its socket factory
* to create the socket.
*/
protected
Socket
createSocket
()
throws
IOException
{
return
new
java
.
net
.
Socket
();
}
protected
InetAddress
getLocalAddress
()
throws
IOException
{
if
(
serverSocket
==
null
)
throw
new
IOException
(
"not connected"
);
...
...
src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
浏览文件 @
ac09e22d
/*
* Copyright 1995-20
09
Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1995-20
10
Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -1258,6 +1258,11 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
doingNTLMp2ndStage
=
false
;
continue
;
}
}
else
{
inNegotiateProxy
=
false
;
doingNTLMp2ndStage
=
false
;
if
(!
isUserProxyAuth
)
requests
.
remove
(
"Proxy-Authorization"
);
}
// cache proxy authentication info
...
...
@@ -1303,7 +1308,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
serverAuthentication
.
getAuthScheme
()
!=
NTLM
)
{
if
(
serverAuthentication
.
isAuthorizationStale
(
raw
))
{
/* we can retry with the current credentials */
disconnect
Internal
();
disconnect
Web
();
redirects
++;
requests
.
set
(
serverAuthentication
.
getHeaderName
(),
serverAuthentication
.
getHeaderValue
(
url
,
method
));
...
...
@@ -1318,7 +1323,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
currentServerCredentials
=
serverAuthentication
;
if
(
serverAuthentication
!=
null
)
{
disconnect
Internal
();
disconnect
Web
();
redirects
++;
// don't let things loop ad nauseum
setCookieHeader
();
continue
;
...
...
@@ -1327,7 +1332,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
reset
();
/* header not used for ntlm */
if
(!
serverAuthentication
.
setHeaders
(
this
,
null
,
raw
))
{
disconnect
Internal
();
disconnect
Web
();
throw
new
IOException
(
"Authentication failure"
);
}
doingNTLM2ndStage
=
false
;
...
...
@@ -2319,6 +2324,22 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
connected
=
false
;
}
/**
* Disconnect from the web server at the first 401 error. Do not
* disconnect when using a proxy, a good proxy should have already
* closed the connection to the web server.
*/
private
void
disconnectWeb
()
throws
IOException
{
if
(
usingProxy
())
{
responseCode
=
-
1
;
// clean up, particularly, skip the content part
// of a 401 error response
reset
();
}
else
{
disconnectInternal
();
}
}
/**
* Disconnect from the server (for internal use)
*/
...
...
src/share/classes/sun/net/www/protocol/https/HttpsClient.java
浏览文件 @
ac09e22d
...
...
@@ -28,39 +28,24 @@ package sun.net.www.protocol.https;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.FileInputStream
;
import
java.io.PrintStream
;
import
java.io.BufferedOutputStream
;
import
java.net.Socket
;
import
java.net.SocketException
;
import
java.net.URL
;
import
java.net.UnknownHostException
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.Proxy
;
import
java.net.CookieHandler
;
import
java.net.Authenticator
;
import
java.net.PasswordAuthentication
;
import
java.security.Principal
;
import
java.security.KeyStore
;
import
java.security.PrivateKey
;
import
java.security.cert.*
;
import
java.util.StringTokenizer
;
import
java.util.Vector
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Iterator
;
import
java.security.AccessController
;
import
javax.security.auth.x500.X500Principal
;
import
javax.net.ssl.*
;
import
sun.security.x509.X500Name
;
import
sun.misc.Regexp
;
import
sun.misc.RegexpPool
;
import
sun.net.www.HeaderParser
;
import
sun.net.www.MessageHeader
;
import
sun.net.www.http.HttpClient
;
import
sun.security.action.*
;
...
...
@@ -125,6 +110,7 @@ final class HttpsClient extends HttpClient
private
static
final
int
httpsPortNumber
=
443
;
/** Returns the default HTTPS port (443) */
@Override
protected
int
getDefaultPort
()
{
return
httpsPortNumber
;
}
private
HostnameVerifier
hv
;
...
...
@@ -368,11 +354,39 @@ final class HttpsClient extends HttpClient
return
sslSocketFactory
;
}
/**
* The following method, createSocket, is defined in NetworkClient
* and overridden here so that the socket facroty is used to create
* new sockets.
*/
@Override
protected
Socket
createSocket
()
throws
IOException
{
try
{
return
sslSocketFactory
.
createSocket
();
}
catch
(
SocketException
se
)
{
//
// bug 6771432
// javax.net.SocketFactory throws a SocketException with an
// UnsupportedOperationException as its cause to indicate that
// unconnected sockets have not been implemented.
//
Throwable
t
=
se
.
getCause
();
if
(
t
!=
null
&&
t
instanceof
UnsupportedOperationException
)
{
return
super
.
createSocket
();
}
else
{
throw
se
;
}
}
}
@Override
public
boolean
needsTunneling
()
{
return
(
proxy
!=
null
&&
proxy
.
type
()
!=
Proxy
.
Type
.
DIRECT
&&
proxy
.
type
()
!=
Proxy
.
Type
.
SOCKS
);
}
@Override
public
void
afterConnect
()
throws
IOException
,
UnknownHostException
{
if
(!
isCachedConnection
())
{
SSLSocket
s
=
null
;
...
...
@@ -383,6 +397,9 @@ final class HttpsClient extends HttpClient
host
,
port
,
true
);
}
else
{
s
=
(
SSLSocket
)
serverSocket
;
if
(
s
instanceof
SSLSocketImpl
)
{
((
SSLSocketImpl
)
s
).
setHost
(
host
);
}
}
}
catch
(
IOException
ex
)
{
// If we fail to connect through the tunnel, try it
...
...
@@ -451,7 +468,6 @@ final class HttpsClient extends HttpClient
//
// Get authenticated server name, if any
//
boolean
done
=
false
;
String
host
=
url
.
getHost
();
// if IPv6 strip off the "[]"
...
...
@@ -467,7 +483,7 @@ final class HttpsClient extends HttpClient
// Use ciphersuite to determine whether Kerberos is present.
if
(
cipher
.
startsWith
(
"TLS_KRB5"
))
{
if
(!
c
hecker
.
match
(
host
,
getPeerPrincipal
()))
{
if
(!
HostnameC
hecker
.
match
(
host
,
getPeerPrincipal
()))
{
throw
new
SSLPeerUnverifiedException
(
"Hostname checker"
+
" failed for Kerberos"
);
}
...
...
@@ -514,6 +530,7 @@ final class HttpsClient extends HttpClient
+
url
.
getHost
()
+
">"
);
}
@Override
protected
void
putInKeepAliveCache
()
{
kac
.
put
(
url
,
sslSocketFactory
,
this
);
}
...
...
@@ -521,6 +538,7 @@ final class HttpsClient extends HttpClient
/*
* Close an idle connection to this URL (if it exists in the cache).
*/
@Override
public
void
closeIdleConnection
()
{
HttpClient
http
=
(
HttpClient
)
kac
.
get
(
url
,
sslSocketFactory
);
if
(
http
!=
null
)
{
...
...
@@ -626,6 +644,7 @@ final class HttpsClient extends HttpClient
* @return the proxy host being used for this client, or null
* if we're not going through a proxy
*/
@Override
public
String
getProxyHostUsed
()
{
if
(!
needsTunneling
())
{
return
null
;
...
...
@@ -638,6 +657,7 @@ final class HttpsClient extends HttpClient
* @return the proxy port being used for this client. Meaningless
* if getProxyHostUsed() gives null.
*/
@Override
public
int
getProxyPortUsed
()
{
return
(
proxy
==
null
||
proxy
.
type
()
==
Proxy
.
Type
.
DIRECT
||
proxy
.
type
()
==
Proxy
.
Type
.
SOCKS
)?
-
1
:
...
...
src/share/classes/sun/security/ssl/SSLSocketImpl.java
浏览文件 @
ac09e22d
...
...
@@ -1852,6 +1852,11 @@ final public class SSLSocketImpl extends BaseSSLSocketImpl {
return
host
;
}
// ONLY used by HttpsClient to setup the URI specified hostname
synchronized
public
void
setHost
(
String
host
)
{
this
.
host
=
host
;
}
/**
* Gets an input stream to read from the peer on the other side.
* Data read from this stream was always integrity protected in
...
...
src/share/native/sun/management/Flag.c
浏览文件 @
ac09e22d
...
...
@@ -133,11 +133,8 @@ Java_sun_management_Flag_getFlags
globals
[
i
].
value
.
j
);
break
;
default:
// unsupported type
sprintf
(
errmsg
,
"Unsupported VMGlobal Type %d"
,
globals
[
i
].
type
);
JNU_ThrowInternalError
(
env
,
errmsg
);
free
(
globals
);
return
0
;
// ignore unsupported type
continue
;
}
switch
(
globals
[
i
].
origin
)
{
case
JMM_VMGLOBAL_ORIGIN_DEFAULT
:
...
...
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/DNSIdentities.java
0 → 100644
浏览文件 @
ac09e22d
此差异已折叠。
点击以展开。
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsCreateSockTest.java
0 → 100644
浏览文件 @
ac09e22d
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6771432
* @summary createSocket() - smpatch fails using 1.6.0_10 because of "Unconnected sockets not implemented"
*/
import
javax.net.SocketFactory
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSession
;
import
javax.net.ssl.SSLSocketFactory
;
import
java.security.NoSuchAlgorithmException
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.Socket
;
import
java.net.URL
;
import
java.io.BufferedWriter
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
import
com.sun.net.httpserver.HttpsConfigurator
;
/*
* This class tests that the HTTPS protocol handler is using its socket factory for
* creating new Sockets. It does this by wrapping the default SSLSocketFactory with
* its own socket factory, SimpleSSLSocketFactory, and verifying that when a https
* connection is made one of the socket factories createSocket methods, that
* actually creates a Socket, is being invoked by the protocol handler.
*/
public
class
HttpsCreateSockTest
{
/*
* Where do we find the keystores?
*/
static
String
pathToStores
=
"../../../../../../etc"
;
static
String
keyStoreFile
=
"keystore"
;
static
String
trustStoreFile
=
"truststore"
;
static
String
passwd
=
"passphrase"
;
com
.
sun
.
net
.
httpserver
.
HttpsServer
httpsServer
;
MyHandler
httpHandler
;
public
static
void
main
(
String
[]
args
)
{
String
keyFilename
=
System
.
getProperty
(
"test.src"
,
"./"
)
+
"/"
+
pathToStores
+
"/"
+
keyStoreFile
;
String
trustFilename
=
System
.
getProperty
(
"test.src"
,
"./"
)
+
"/"
+
pathToStores
+
"/"
+
trustStoreFile
;
System
.
setProperty
(
"javax.net.ssl.keyStore"
,
keyFilename
);
System
.
setProperty
(
"javax.net.ssl.keyStorePassword"
,
passwd
);
System
.
setProperty
(
"javax.net.ssl.trustStore"
,
trustFilename
);
System
.
setProperty
(
"javax.net.ssl.trustStorePassword"
,
passwd
);
new
HttpsCreateSockTest
();
}
public
HttpsCreateSockTest
()
{
try
{
startHttpsServer
();
doClient
();
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
finally
{
httpsServer
.
stop
(
1
);
}
}
void
doClient
()
throws
IOException
{
InetSocketAddress
address
=
httpsServer
.
getAddress
();
URL
url
=
new
URL
(
"https://localhost:"
+
address
.
getPort
()
+
"/"
);
System
.
out
.
println
(
"trying to connect to "
+
url
+
"..."
);
HttpsURLConnection
uc
=
(
HttpsURLConnection
)
url
.
openConnection
();
uc
.
setHostnameVerifier
(
new
AllHostnameVerifier
());
if
(
uc
instanceof
javax
.
net
.
ssl
.
HttpsURLConnection
)
{
((
javax
.
net
.
ssl
.
HttpsURLConnection
)
uc
).
setSSLSocketFactory
(
new
SimpleSSLSocketFactory
());
System
.
out
.
println
(
"Using TestSocketFactory"
);
}
uc
.
connect
();
System
.
out
.
println
(
"CONNECTED "
+
uc
);
System
.
out
.
println
(
uc
.
getResponseMessage
());
uc
.
disconnect
();
}
/**
* Https Server
*/
public
void
startHttpsServer
()
throws
IOException
,
NoSuchAlgorithmException
{
httpsServer
=
com
.
sun
.
net
.
httpserver
.
HttpsServer
.
create
(
new
InetSocketAddress
(
0
),
0
);
httpsServer
.
createContext
(
"/"
,
new
MyHandler
());
httpsServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
SSLContext
.
getDefault
()));
httpsServer
.
start
();
}
class
MyHandler
implements
HttpHandler
{
private
String
message
=
"This is a message!"
;
@Override
public
void
handle
(
HttpExchange
t
)
throws
IOException
{
t
.
sendResponseHeaders
(
200
,
message
.
length
());
BufferedWriter
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
t
.
getResponseBody
(),
"ISO8859-1"
));
writer
.
write
(
message
,
0
,
message
.
length
());
writer
.
close
();
t
.
close
();
}
}
/**
* Simple wrapper on default SSLSocketFactory
*/
class
SimpleSSLSocketFactory
extends
SSLSocketFactory
{
/*
* true if this factory has been used to create a new Socket, i.e.
* one of the SocketFactory methods has been called.
*/
boolean
socketCreated
=
false
;
/*
* true if this factory has been used to wrap a Socket, i.e.
* the SSLSocketFactory method,
* createSocket(Socket, String, int, boolean), has been called.
*/
boolean
socketWrapped
=
false
;
@Override
public
Socket
createSocket
(
InetAddress
host
,
int
port
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
host
,
port
);
}
@Override
public
Socket
createSocket
(
InetAddress
address
,
int
port
,
InetAddress
localAddress
,
int
localPort
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
address
,
port
,
localAddress
,
localPort
);
}
@Override
public
Socket
createSocket
(
String
host
,
int
port
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
host
,
port
);
}
@Override
public
Socket
createSocket
(
String
host
,
int
port
,
InetAddress
localHost
,
int
localPort
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
host
,
port
,
localHost
,
localPort
);
}
// methods from SSLSocketFactory
@Override
public
Socket
createSocket
(
Socket
s
,
String
host
,
int
port
,
boolean
autoClose
)
throws
IOException
{
socketWrapped
=
true
;
return
((
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
()).
createSocket
(
s
,
host
,
port
,
autoClose
);
}
@Override
public
String
[]
getDefaultCipherSuites
()
{
return
((
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
()).
getDefaultCipherSuites
();
}
@Override
public
String
[]
getSupportedCipherSuites
()
{
return
((
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
()).
getSupportedCipherSuites
();
}
}
class
AllHostnameVerifier
implements
HostnameVerifier
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
return
true
;
}
}
}
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/HttpsSocketFacTest.java
0 → 100644
浏览文件 @
ac09e22d
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6614957
* @summary HttpsURLConnection not using the set SSLSocketFactory for creating all its Sockets
* @run main/othervm HttpsSocketFacTest
*/
import
javax.net.SocketFactory
;
import
javax.net.ssl.HostnameVerifier
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSession
;
import
javax.net.ssl.SSLSocketFactory
;
import
java.security.NoSuchAlgorithmException
;
import
java.net.InetAddress
;
import
java.net.InetSocketAddress
;
import
java.net.Socket
;
import
java.net.URL
;
import
java.io.BufferedWriter
;
import
java.io.InputStream
;
import
java.io.IOException
;
import
java.io.OutputStreamWriter
;
import
com.sun.net.httpserver.HttpExchange
;
import
com.sun.net.httpserver.HttpHandler
;
import
com.sun.net.httpserver.HttpsConfigurator
;
/*
* This class tests that the HTTPS protocol handler is using its socket factory for
* creating new Sockets. It does this by wrapping the default SSLSocketFactory with
* its own socket factory, SimpleSSLSocketFactory, and verifying that when a https
* connection is made one of the socket factories createSocket methods, that
* actually creates a Socket, is being invoked by the protocol handler.
*/
public
class
HttpsSocketFacTest
{
/*
* Where do we find the keystores?
*/
static
String
pathToStores
=
"../../../../../../etc"
;
static
String
keyStoreFile
=
"keystore"
;
static
String
trustStoreFile
=
"truststore"
;
static
String
passwd
=
"passphrase"
;
com
.
sun
.
net
.
httpserver
.
HttpsServer
httpsServer
;
MyHandler
httpHandler
;
public
static
void
main
(
String
[]
args
)
{
String
keyFilename
=
System
.
getProperty
(
"test.src"
,
"./"
)
+
"/"
+
pathToStores
+
"/"
+
keyStoreFile
;
String
trustFilename
=
System
.
getProperty
(
"test.src"
,
"./"
)
+
"/"
+
pathToStores
+
"/"
+
trustStoreFile
;
System
.
setProperty
(
"javax.net.ssl.keyStore"
,
keyFilename
);
System
.
setProperty
(
"javax.net.ssl.keyStorePassword"
,
passwd
);
System
.
setProperty
(
"javax.net.ssl.trustStore"
,
trustFilename
);
System
.
setProperty
(
"javax.net.ssl.trustStorePassword"
,
passwd
);
new
HttpsSocketFacTest
();
}
public
HttpsSocketFacTest
()
{
try
{
startHttpsServer
();
doClient
();
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
finally
{
httpsServer
.
stop
(
1
);
}
}
void
doClient
()
throws
IOException
{
InetSocketAddress
address
=
httpsServer
.
getAddress
();
URL
url
=
new
URL
(
"https://localhost:"
+
address
.
getPort
()
+
"/test6614957/"
);
System
.
out
.
println
(
"trying to connect to "
+
url
+
"..."
);
HttpsURLConnection
uc
=
(
HttpsURLConnection
)
url
.
openConnection
();
SimpleSSLSocketFactory
sssf
=
new
SimpleSSLSocketFactory
();
uc
.
setSSLSocketFactory
(
sssf
);
uc
.
setHostnameVerifier
(
new
AllHostnameVerifier
());
InputStream
is
=
uc
.
getInputStream
();
byte
[]
ba
=
new
byte
[
1024
];
int
read
=
0
;
while
((
read
=
is
.
read
(
ba
))
!=
-
1
)
{
System
.
out
.
println
(
new
String
(
ba
,
0
,
read
));
}
System
.
out
.
println
(
"SimpleSSLSocketFactory.socketCreated = "
+
sssf
.
socketCreated
);
System
.
out
.
println
(
"SimpleSSLSocketFactory.socketWrapped = "
+
sssf
.
socketWrapped
);
if
(!
sssf
.
socketCreated
)
throw
new
RuntimeException
(
"Failed: Socket Factory not being called to create Socket"
);
}
/**
* Https Server
*/
public
void
startHttpsServer
()
throws
IOException
,
NoSuchAlgorithmException
{
httpsServer
=
com
.
sun
.
net
.
httpserver
.
HttpsServer
.
create
(
new
InetSocketAddress
(
0
),
0
);
httpsServer
.
createContext
(
"/test6614957/"
,
new
MyHandler
());
httpsServer
.
setHttpsConfigurator
(
new
HttpsConfigurator
(
SSLContext
.
getDefault
()));
httpsServer
.
start
();
}
class
MyHandler
implements
HttpHandler
{
private
String
message
=
"This is a message!"
;
@Override
public
void
handle
(
HttpExchange
t
)
throws
IOException
{
t
.
sendResponseHeaders
(
200
,
message
.
length
());
BufferedWriter
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
t
.
getResponseBody
(),
"ISO8859-1"
));
writer
.
write
(
message
,
0
,
message
.
length
());
writer
.
close
();
t
.
close
();
}
}
/**
* Simple wrapper on default SSLSocketFactory
*/
class
SimpleSSLSocketFactory
extends
SSLSocketFactory
{
/*
* true if this factory has been used to create a new Socket, i.e.
* one of the SocketFactory methods has been called.
*/
boolean
socketCreated
=
false
;
/*
* true if this factory has been used to wrap a Socket, i.e.
* the SSLSocketFactory method,
* createSocket(Socket, String, int, boolean), has been called.
*/
boolean
socketWrapped
=
false
;
// methods for SocketFactory
@Override
public
Socket
createSocket
()
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
();
}
@Override
public
Socket
createSocket
(
InetAddress
host
,
int
port
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
host
,
port
);
}
@Override
public
Socket
createSocket
(
InetAddress
address
,
int
port
,
InetAddress
localAddress
,
int
localPort
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
address
,
port
,
localAddress
,
localPort
);
}
@Override
public
Socket
createSocket
(
String
host
,
int
port
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
host
,
port
);
}
@Override
public
Socket
createSocket
(
String
host
,
int
port
,
InetAddress
localHost
,
int
localPort
)
throws
IOException
{
socketCreated
=
true
;
return
SocketFactory
.
getDefault
().
createSocket
(
host
,
port
,
localHost
,
localPort
);
}
// methods from SSLSocketFactory
@Override
public
Socket
createSocket
(
Socket
s
,
String
host
,
int
port
,
boolean
autoClose
)
throws
IOException
{
socketWrapped
=
true
;
return
((
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
()).
createSocket
(
s
,
host
,
port
,
autoClose
);
}
@Override
public
String
[]
getDefaultCipherSuites
()
{
return
((
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
()).
getDefaultCipherSuites
();
}
@Override
public
String
[]
getSupportedCipherSuites
()
{
return
((
SSLSocketFactory
)
SSLSocketFactory
.
getDefault
()).
getSupportedCipherSuites
();
}
}
class
AllHostnameVerifier
implements
HostnameVerifier
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
return
true
;
}
}
}
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressDNSIdentities.java
0 → 100644
浏览文件 @
ac09e22d
此差异已折叠。
点击以展开。
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPAddressIPIdentities.java
0 → 100644
浏览文件 @
ac09e22d
此差异已折叠。
点击以展开。
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/IPIdentities.java
0 → 100644
浏览文件 @
ac09e22d
此差异已折叠。
点击以展开。
test/sun/security/ssl/sun/net/www/protocol/https/HttpsURLConnection/Identities.java
0 → 100644
浏览文件 @
ac09e22d
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录