有关SSL的原理和介绍在网上已经有不少,对于Java下使用keytool生成证书,配置SSL通信的教程也非常多。但如果我们不能够亲自动手做一个SSL Sever和SSL Client,可能就永远也不能深入地理解Java环境下,SSL的通信是如何实现的。对SSL中的各种概念的认识也可能会仅限于可以使用的程度。本文通过构造一个简单的SSL Server和SSL Client来讲解Java环境下SSL的通信原理。
首先我们先回顾一下常规的Java Socket编程。在Java下写一个Socket服务器和客户端的例子还是比较简单的。以下是服务端的代码:
- package org.bluedash.tryssl;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- publicclass Server extends Thread {
- private Socket socket;
- public Server(Socket socket) {
- this.socket = socket;
- }
- publicvoid run() {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- PrintWriter writer = new PrintWriter(socket.getOutputStream());
- String data = reader.readLine();
- writer.println(data);
- writer.close();
- socket.close();
- } catch (IOException e) {
- }
- }
- publicstaticvoid main(String[] args) throws Exception {
- while (true) {
- new Server((new ServerSocket(8080)).accept()).start();
- }
- }
- }
package org.bluedash.tryssl; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Server extends Thread { private Socket socket; public Server(Socket socket) { this.socket = socket; } public void run() { try { BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter writer = new PrintWriter(socket.getOutputStream()); String data = reader.readLine(); writer.println(data); writer.close(); socket.close(); } catch (IOException e) { } } public static void main(String[] args) throws Exception { while (true) { new Server((new ServerSocket(8080)).accept()).start(); } } }
服务端很简单:侦听8080端口,并把客户端发来的字符串返回去。下面是客户端的代码:
- package org.bluedash.tryssl;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- publicclass Client {
- publicstaticvoid main(String[] args) throws Exception {
- Socket s = new Socket("localhost", 8080);
- PrintWriter writer = new PrintWriter(s.getOutputStream());
- BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
- writer.println("hello");
- writer.flush();
- System.out.println(reader.readLine());
- s.close();
- }
- }
package org.bluedash.tryssl; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; public class Client { public static void main(String[] args) throws Exception { Socket s = new Socket("localhost", 8080); PrintWriter writer = new PrintWriter(s.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream())); writer.println("hello"); writer.flush(); System.out.println(reader.readLine()); s.close(); } }
客户端也非常简单:向服务端发起请求,发送一个"hello"字串,然后获得服务端的返回。把服务端运行起来后,执行客户端,我们将得到"hello"的返回。
就是这样一套简单的网络通信的代码,我们来把它改造成使用SSL通信。在SSL通信协议中,我们都知道首先服务端必须有一个数字证书,当客户端连接到服务端时,会得到这个证书,然后客户端会判断这个证书是否是可信的,如果是,则交换信道加密密钥,进行通信。如果不信任这个证书,则连接失败。
因此,我们首先要为服务端生成一个数字证书。Java环境下,数字证书是用keytool生成的,这些证书被存储在store的概念中,就是证书仓库。我们来调用keytool命令为服务端生成数字证书和保存它使用的证书仓库:
- keytool -genkey -v -alias bluedash-ssl-demo-server -keyalg RSA -keystore ./server_ks -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,C=cn" -storepass server -keypass 123123
keytool -genkey -v -alias bluedash-ssl-demo-server -keyalg RSA -keystore ./server_ks -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,C=cn" -storepass server -keypass 123123
这样,我们就将服务端证书bluedash-ssl-demo-server保存在了server_ksy这个store文件当中。有关keytool的用法在本文中就不再多赘述。执行上面的命令得到如下结果:
- Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 90 days
- for: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn
- [Storing ./server_ks]
Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 90 days for: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn [Storing ./server_ks]
然后,改造我们的服务端代码,让服务端使用这个证书,并提供SSL通信:
- package org.bluedash.tryssl;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.security.KeyStore;
- import javax.net.ServerSocketFactory;
- import javax.net.ssl.KeyManagerFactory;
- import javax.net.ssl.SSLContext;
- import javax.net.ssl.SSLServerSocket;
- publicclass SSLServer extends Thread {
- private Socket socket;
- public SSLServer(Socket socket) {
- this.socket = socket;
- }
- publicvoid run() {
- try {
- BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- PrintWriter writer = new PrintWriter(socket.getOutputStream());
- String data = reader.readLine();
- writer.println(data);
- writer.close();
- socket.close();
- } catch (IOException e) {
- }
- }
- privatestatic String SERVER_KEY_STORE = "/Users/liweinan/projs/ssl/src/main/resources/META-INF/server_ks";
- privatestatic String SERVER_KEY_STORE_PASSWORD = "123123";
- publicstaticvoid main(String[] args) throws Exception {
- System.setProperty("javax.net.ssl.trustStore", SERVER_KEY_STORE);
- SSLContext context = SSLContext.getInstance("TLS");
- KeyStore ks = KeyStore.getInstance("jceks");
- ks.load(new FileInputStream(SERVER_KEY_STORE), null);
- KeyManagerFactory kf = KeyManagerFactory.getInstance("SunX509");
- kf.init(ks, SERVER_KEY_STORE_PASSWORD.toCharArray());
- context.init(kf.getKeyManagers(), null, null);
- ServerSocketFactory factory = context.getServerSocketFactory();
- ServerSocket _socket = factory.createServerSocket(8443);
- ((SSLServerSocket) _socket).setNeedClientAuth(false);
- while (true) {
- new SSLServer(_socket.accept()).start();
- }
- }
- }
package org.bluedash.tryssl; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.security.KeyStore; import javax.net.ServerSocketFactory; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLServerSocket; public class SSLServer extends Thread { private Socket socket; public SSLServer(Socket socket) { this.socket = socket; } public void run() { try { BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter writer = new PrintWriter(socket.getOutputStream()); String data = reader.readLine(); writer.println(data); writer.close(); socket.close(); } catch (IOException e) { } } private static String SERVER_KEY_STORE = "/Users/liweinan/projs/ssl/src/main/resources/META-INF/server_ks"; private static String SERVER_KEY_STORE_PASSWORD = "123123"; public static void main(String[] args) throws Exception { System.setProperty("javax.net.ssl.trustStore", SERVER_KEY_STORE); SSLContext context = SSLContext.getInstance("TLS"); KeyStore ks = KeyStore.getInstance("jceks"); ks.load(new FileInputStream(SERVER_KEY_STORE), null); KeyManagerFactory kf = KeyManagerFactory.getInstance("SunX509"); kf.init(ks, SERVER_KEY_STORE_PASSWORD.toCharArray()); context.init(kf.getKeyManagers(), null, null); ServerSocketFactory factory = context.getServerSocketFactory(); ServerSocket _socket = factory.createServerSocket(8443); ((SSLServerSocket) _socket).setNeedClientAuth(false); while (true) { new SSLServer(_socket.accept()).start(); } } }
可以看到,服务端的Socket准备设置工作大大增加了,增加的代码的作用主要是将证书导入并进行使用。此外,所使用的Socket变成了SSLServerSocket,另外端口改到了8443(这个不是强制的,仅仅是为了遵守习惯)。另外,最重要的一点,服务端证书里面的CN一定和服务端的域名统一,我们的证书服务的域名是localhost,那么我们的客户端在连接服务端时一定也要用localhost来连接,否则根据SSL协议标准,域名与证书的CN不匹配,说明这个证书是不安全的,通信将无法正常运行。
有了服务端,我们原来的客户端就不能使用了,必须要走SSL协议。由于服务端的证书是我们自己生成的,没有任何受信任机构的签名,所以客户端是无法验证服务端证书的有效性的,通信必然会失败。所以我们需要为客户端创建一个保存所有信任证书的仓库,然后把服务端证书导进这个仓库。这样,当客户端连接服务端时,会发现服务端的证书在自己的信任列表中,就可以正常通信了。
因此现在我们要做的是生成一个客户端的证书仓库,因为keytool不能仅生成一个空白仓库,所以和服务端一样,我们还是生成一个证书加一个仓库(客户端证书加仓库):
- keytool -genkey -v -alias bluedash-ssl-demo-client -keyalg RSA -keystore ./client_ks -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,C=cn" -storepass client -keypass 456456
keytool -genkey -v -alias bluedash-ssl-demo-client -keyalg RSA -keystore ./client_ks -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,C=cn" -storepass client -keypass 456456
结果如下:
- Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 90 days
- for: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn
- [Storing ./client_ks]
Generating 1,024 bit RSA key pair and self-signed certificate (SHA1withRSA) with a validity of 90 days for: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn [Storing ./client_ks]
接下来,我们要把服务端的证书导出来,并导入到客户端的仓库。第一步是导出服务端的证书:
- keytool -export -alias bluedash-ssl-demo-server -keystore ./server_ks -file server_key.cer
keytool -export -alias bluedash-ssl-demo-server -keystore ./server_ks -file server_key.cer
执行结果如下:
- Enter keystore password: server
- Certificate stored in file <server_key.cer>
Enter keystore password: server Certificate stored in file <server_key.cer>
然后是把导出的证书导入到客户端证书仓库:
- keytool -import -trustcacerts -alias bluedash-ssl-demo-server -file ./server_key.cer -keystore ./client_ks
keytool -import -trustcacerts -alias bluedash-ssl-demo-server -file ./server_key.cer -keystore ./client_ks
结果如下:
- Enter keystore password: client
- Owner: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn
- Issuer: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn
- Serial number: 4c57c7de
- Valid from: Tue Aug 0315:40:14 CST 2010 until: Mon Nov 0115:40:14 CST 2010
- Certificate fingerprints:
- MD5: FC:D4:8B:36:3F:1B:30:EA:6D:63:55:4F:C7:68:3B:0C
- SHA1: E1:54:2F:7C:1A:50:F5:74:AA:63:1E:F9:CC:B1:1C:73:AA:34:8A:C4
- Signature algorithm name: SHA1withRSA
- Version: 3
- Trust this certificate? [no]: yes
- Certificate was added to keystore
Enter keystore password: client Owner: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn Issuer: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn Serial number: 4c57c7de Valid from: Tue Aug 03 15:40:14 CST 2010 until: Mon Nov 01 15:40:14 CST 2010 Certificate fingerprints: MD5: FC:D4:8B:36:3F:1B:30:EA:6D:63:55:4F:C7:68:3B:0C SHA1: E1:54:2F:7C:1A:50:F5:74:AA:63:1E:F9:CC:B1:1C:73:AA:34:8A:C4 Signature algorithm name: SHA1withRSA Version: 3 Trust this certificate? [no]: yes Certificate was added to keystore
好,准备工作做完了,我们来撰写客户端的代码:
- package org.bluedash.tryssl;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import javax.net.SocketFactory;
- import javax.net.ssl.SSLSocketFactory;
- publicclass SSLClient {
- privatestatic String CLIENT_KEY_STORE = "/Users/liweinan/projs/ssl/src/main/resources/META-INF/client_ks";
- publicstaticvoid main(String[] args) throws Exception {
- // Set the key store to use for validating the server cert.
- System.setProperty("javax.net.ssl.trustStore", CLIENT_KEY_STORE);
- System.setProperty("javax.net.debug", "ssl,handshake");
- SSLClient client = new SSLClient();
- Socket s = client.clientWithoutCert();
- PrintWriter writer = new PrintWriter(s.getOutputStream());
- BufferedReader reader = new BufferedReader(new InputStreamReader(s
- .getInputStream()));
- writer.println("hello");
- writer.flush();
- System.out.println(reader.readLine());
- s.close();
- }
- private Socket clientWithoutCert() throws Exception {
- SocketFactory sf = SSLSocketFactory.getDefault();
- Socket s = sf.createSocket("localhost", 8443);
- return s;
- }
- }
package org.bluedash.tryssl; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import javax.net.SocketFactory; import javax.net.ssl.SSLSocketFactory; public class SSLClient { private static String CLIENT_KEY_STORE = "/Users/liweinan/projs/ssl/src/main/resources/META-INF/client_ks"; public static void main(String[] args) throws Exception { // Set the key store to use for validating the server cert. System.setProperty("javax.net.ssl.trustStore", CLIENT_KEY_STORE); System.setProperty("javax.net.debug", "ssl,handshake"); SSLClient client = new SSLClient(); Socket s = client.clientWithoutCert(); PrintWriter writer = new PrintWriter(s.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(s .getInputStream())); writer.println("hello"); writer.flush(); System.out.println(reader.readLine()); s.close(); } private Socket clientWithoutCert() throws Exception { SocketFactory sf = SSLSocketFactory.getDefault(); Socket s = sf.createSocket("localhost", 8443); return s; } }
可以看到,除了把一些类变成SSL通信类以外,客户端也多出了使用信任证书仓库的代码。以上,我们便完成了SSL单向握手通信。即:客户端验证服务端的证书,服务端不认证客户端的证书。
以上便是Java环境下SSL单向握手的全过程。因为我们在客户端设置了日志输出级别为DEBUG:
- System.setProperty("javax.net.debug", "ssl,handshake");
System.setProperty("javax.net.debug", "ssl,handshake");
因此我们可以看到SSL通信的全过程,这些日志可以帮助我们更具体地了解通过SSL协议建立网络连接时的全过程。
结合日志,我们来看一下SSL双向认证的全过程:
第一步: 客户端发送ClientHello消息,发起SSL连接请求,告诉服务器自己支持的SSL选项(加密方式等)。
- *** ClientHello, TLSv1
*** ClientHello, TLSv1
第二步: 服务器响应请求,回复ServerHello消息,和客户端确认SSL加密方式:
- *** ServerHello, TLSv1
*** ServerHello, TLSv1
第三步: 服务端向客户端发布自己的公钥。
第四步: 客户端与服务端的协通沟通完毕,服务端发送ServerHelloDone消息:
- *** ServerHelloDone
*** ServerHelloDone
第五步: 客户端使用服务端给予的公钥,创建会话用密钥(SSL证书认证完成后,为了提高性能,所有的信息交互就可能会使用对称加密算法),并通过ClientKeyExchange消息发给服务器:
- *** ClientKeyExchange, RSA PreMasterSecret, TLSv1
*** ClientKeyExchange, RSA PreMasterSecret, TLSv1
第六步: 客户端通知服务器改变加密算法,通过ChangeCipherSpec消息发给服务端:
- main, WRITE: TLSv1 Change Cipher Spec, length = 1
main, WRITE: TLSv1 Change Cipher Spec, length = 1
第七步: 客户端发送Finished消息,告知服务器请检查加密算法的变更请求:
- *** Finished
*** Finished
第八步:服务端确认算法变更,返回ChangeCipherSpec消息
- main, READ: TLSv1 Change Cipher Spec, length = 1
main, READ: TLSv1 Change Cipher Spec, length = 1
第九步:服务端发送Finished消息,加密算法生效:
- *** Finished
*** Finished
那么如何让服务端也认证客户端的身份,即双向握手呢?其实很简单,在服务端代码中,把这一行:
- ((SSLServerSocket) _socket).setNeedClientAuth(false);
((SSLServerSocket) _socket).setNeedClientAuth(false);
改成:
- ((SSLServerSocket) _socket).setNeedClientAuth(true);
((SSLServerSocket) _socket).setNeedClientAuth(true);
就可以了。但是,同样的道理,现在服务端并没有信任客户端的证书,因为客户端的证书也是自己生成的。所以,对于服务端,需要做同样的工作:把客户端的证书导出来,并导入到服务端的证书仓库:
- keytool -export -alias bluedash-ssl-demo-client -keystore ./client_ks -file client_key.cer
- Enter keystore password: client
- Certificate stored in file <client_key.cer>
keytool -export -alias bluedash-ssl-demo-client -keystore ./client_ks -file client_key.cer Enter keystore password: client Certificate stored in file <client_key.cer>
- keytool -import -trustcacerts -alias bluedash-ssl-demo-client -file ./client_key.cer -keystore ./server_ks
- Enter keystore password: server
- Owner: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn
- Issuer: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn
- Serial number: 4c57c80b
- Valid from: Tue Aug 0315:40:59 CST 2010 until: Mon Nov 0115:40:59 CST 2010
- Certificate fingerprints:
- MD5: DB:91:F4:1E:65:D1:81:F2:1E:A6:A3:55:3F:E8:12:79
- SHA1: BF:77:56:61:04:DD:95:FC:E5:84:48:5C:BE:60:AF:02:96:A2:E1:E2
- Signature algorithm name: SHA1withRSA
- Version: 3
- Trust this certificate? [no]: yes
- Certificate was added to keystore
keytool -import -trustcacerts -alias bluedash-ssl-demo-client -file ./client_key.cer -keystore ./server_ks Enter keystore password: server Owner: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn Issuer: CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn Serial number: 4c57c80b Valid from: Tue Aug 03 15:40:59 CST 2010 until: Mon Nov 01 15:40:59 CST 2010 Certificate fingerprints: MD5: DB:91:F4:1E:65:D1:81:F2:1E:A6:A3:55:3F:E8:12:79 SHA1: BF:77:56:61:04:DD:95:FC:E5:84:48:5C:BE:60:AF:02:96:A2:E1:E2 Signature algorithm name: SHA1withRSA Version: 3 Trust this certificate? [no]: yes Certificate was added to keystore
完成了证书的导入,还要在客户端需要加入一段代码,用于在连接时,客户端向服务端出示自己的证书:
- package org.bluedash.tryssl;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.security.KeyStore;
- import javax.net.SocketFactory;
- import javax.net.ssl.KeyManagerFactory;
- import javax.net.ssl.SSLContext;
- import javax.net.ssl.SSLSocketFactory;
- publicclass SSLClient {
- privatestatic String CLIENT_KEY_STORE = "/Users/liweinan/projs/ssl/src/main/resources/META-INF/client_ks";
- privatestatic String CLIENT_KEY_STORE_PASSWORD = "456456";
- publicstaticvoid main(String[] args) throws Exception {
- // Set the key store to use for validating the server cert.
- System.setProperty("javax.net.ssl.trustStore", CLIENT_KEY_STORE);
- System.setProperty("javax.net.debug", "ssl,handshake");
- SSLClient client = new SSLClient();
- Socket s = client.clientWithCert();
- PrintWriter writer = new PrintWriter(s.getOutputStream());
- BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream()));
- writer.println("hello");
- writer.flush();
- System.out.println(reader.readLine());
- s.close();
- }
- private Socket clientWithoutCert() throws Exception {
- SocketFactory sf = SSLSocketFactory.getDefault();
- Socket s = sf.createSocket("localhost", 8443);
- return s;
- }
- private Socket clientWithCert() throws Exception {
- SSLContext context = SSLContext.getInstance("TLS");
- KeyStore ks = KeyStore.getInstance("jceks");
- ks.load(new FileInputStream(CLIENT_KEY_STORE), null);
- KeyManagerFactory kf = KeyManagerFactory.getInstance("SunX509");
- kf.init(ks, CLIENT_KEY_STORE_PASSWORD.toCharArray());
- context.init(kf.getKeyManagers(), null, null);
- SocketFactory factory = context.getSocketFactory();
- Socket s = factory.createSocket("localhost", 8443);
- return s;
- }
- }
package org.bluedash.tryssl; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; import java.security.KeyStore; import javax.net.SocketFactory; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; public class SSLClient { private static String CLIENT_KEY_STORE = "/Users/liweinan/projs/ssl/src/main/resources/META-INF/client_ks"; private static String CLIENT_KEY_STORE_PASSWORD = "456456"; public static void main(String[] args) throws Exception { // Set the key store to use for validating the server cert. System.setProperty("javax.net.ssl.trustStore", CLIENT_KEY_STORE); System.setProperty("javax.net.debug", "ssl,handshake"); SSLClient client = new SSLClient(); Socket s = client.clientWithCert(); PrintWriter writer = new PrintWriter(s.getOutputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(s.getInputStream())); writer.println("hello"); writer.flush(); System.out.println(reader.readLine()); s.close(); } private Socket clientWithoutCert() throws Exception { SocketFactory sf = SSLSocketFactory.getDefault(); Socket s = sf.createSocket("localhost", 8443); return s; } private Socket clientWithCert() throws Exception { SSLContext context = SSLContext.getInstance("TLS"); KeyStore ks = KeyStore.getInstance("jceks"); ks.load(new FileInputStream(CLIENT_KEY_STORE), null); KeyManagerFactory kf = KeyManagerFactory.getInstance("SunX509"); kf.init(ks, CLIENT_KEY_STORE_PASSWORD.toCharArray()); context.init(kf.getKeyManagers(), null, null); SocketFactory factory = context.getSocketFactory(); Socket s = factory.createSocket("localhost", 8443); return s; } }
通过比对单向认证的日志输出,我们可以发现双向认证时,多出了服务端认证客户端证书的步骤:
- *** CertificateRequest
- Cert Types: RSA, DSS
- Cert Authorities:
- <CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn>
- <CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn>
- *** ServerHelloDone
*** CertificateRequest Cert Types: RSA, DSS Cert Authorities: <CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn> <CN=localhost, OU=cn, O=cn, L=cn, ST=cn, C=cn> *** ServerHelloDone
- *** CertificateVerify
- main, WRITE: TLSv1 Handshake, length = 134
- main, WRITE: TLSv1 Change Cipher Spec, length = 1
*** CertificateVerify main, WRITE: TLSv1 Handshake, length = 134 main, WRITE: TLSv1 Change Cipher Spec, length = 1
在 @*** ServerHelloDone@ 之前,服务端向客户端发起了需要证书的请求 @*** CertificateRequest@ 。
在客户端向服务端发出 @Change Cipher Spec@ 请求之前,多了一步客户端证书认证的过程 @*** CertificateVerify@ 。
客户端与服务端互相认证证书的情景,可参考下图:
参考资料:
fn1. Tomcat双向SSL认证的配置 - http://www.javaeedev.com/blog/article.jspx?articleId=ff808081198fb524011993a9bb7a029a
fn2. Understanding SSL - http://developerspoint.wordpress.com/2008/06/21/understanding-ssl/
fn3. Change Cipher Spec Protocol - http://www.pierobon.org/ssl/ch2/ccs.htm
fn4. SSL & TLS Essentials: Securing the Web - http://www.amazon.com/SSL-TLS-Essentials-Securing-Web/dp/0471383546/ref=sr_1_1?ie=UTF8&s=books&qid=1280891641&sr=8-1
相关推荐
在本研究中,作者提出了基于深度学习的SSL/TLS证书验证程序的自动化测试框架,即DRLgencert。该框架旨在减少和消除随机性,并且能够有效发现证书验证过程中的实现缺陷。DRLgencert框架使用深度学习技术来指导证书的...
源码则包含了程序的设计逻辑和功能实现,对于学习和理解SSL代理的工作原理非常有价值。 SSL代理客户端的核心工作流程通常包括以下步骤: 1. **连接建立**:客户端首先会尝试与SSL代理服务器建立TCP连接。这通常...
SSL(Secure Socket Layer)是一种广泛使用的安全协议,用于在互联网上传输敏感数据,如用户名、密码和信用卡...通过实践和研究提供的代码,你将能够熟练地在自己的应用程序中集成SSL功能,为用户提供安全的网络服务。
《易语言SSL代理客户端》是一款基于易语言编程的软件,主要功能是实现通过SSL协议进行安全...通过深入研究源码,开发者可以提升自己的编程技能,掌握SSL通信的核心原理,并能将其应用到实际项目中,提高软件的安全性。
SSL DOS(Denial of Service)攻击...通过对`ssl_dos.c`的深入研究和实践,不仅可以增进对SSL/TLS协议的理解,还能提高对网络安全问题的认识,对于网络安全研究人员和系统管理员来说,这是一个有价值的实验和学习工具。
Wireshark是一款强大的网络协议分析工具,常用于网络调试和分析。它能够捕获和交互式显示网络上的数据包,帮助...通过分析记录中的具体字段,学习者可以进一步学习如何配置和优化SSL/TLS设置,提高网络应用的安全性。
源码是程序员可以直接阅读和修改的文本形式,对于学习和理解SSL代理客户端的工作原理以及易语言编程技巧非常有帮助。以下是对这个主题的一些详细解释: 1. **易语言编程基础**:易语言的核心理念是“易学易用”,它...
了解以上基础知识后,你可以深入研究提供的源代码,学习如何在实际项目中实现SSL通信,同时理解证书和私钥的管理和使用,这对于任何涉及网络安全的开发者来说都是至关重要的。通过调试和修改这些代码,你将更好地...
在"有SSL握手的服务器与客户端"这个压缩包文件中,可能包含了实现SSL服务器和客户端交互的代码示例或工具,供学习和分析SSL握手流程。通过研究这些资源,你可以更好地理解SSL协议的工作原理,以及如何在实际应用中...
《基于OpenSSL的SSL客户端与服务器端编程实例详解》 ...通过深入研究这个项目,开发者不仅可以理解SSL协议的工作原理,还能掌握无阻塞和异步通信的实现技巧,这对于构建安全、高效的网络应用至关重要。
在"IO-Socket-SSL-0.999"这个压缩包中,可能包含的文件有源代码、示例程序、文档、测试脚本等,它们可以帮助开发者学习如何在自己的项目中集成SSL套接字通信。通过阅读和研究这些资源,可以深入了解SSL套接字的工作...
SSO(Single Sign-On)项目和SSL(Secure Socket Layer)技术是网络安全领域中的重要组成部分,它们...通过对这些材料的学习和研究,可以更深入地掌握这两种技术的运用,从而在实际项目中构建出安全可靠的网络环境。
模型压缩SSL(Structured Sparsity Learning)是深度学习领域的一种技术,旨在减少神经网络模型的大小,从而提高其在受限硬件资源环境下的运行效率,同时尽量保持模型的性能。这种技术主要关注于如何在保持精度的...
源码级别的修复对于深入理解 SSL/TLS 协议工作原理和Erlang编程语言都是宝贵的学习资料。通过对这些修改的分析,我们可以学习如何在Erlang环境中编写高并发、高可用性的网络服务,并且如何应对网络安全方面的挑战。...
### SSL攻击实例详解 #### 一、SSL简介 SSL(Secure Socket Layer...然而,需要注意的是,这种行为是非法的,仅供学习和研究目的。了解这些攻击方法可以帮助我们更好地加强网络安全防护措施,保护个人信息免受侵害。
通过构建包含四种典型SSL/TLS攻击流的数据集,并在这些攻击流上验证流谱理论的有效性,本研究不仅为SSL/TLS攻击检测提供了新的思路和技术手段,也为未来网络流检测领域的研究和发展开辟了新的方向。
学习和分析这些源代码可以帮助开发者理解SSL/TLS协议的底层工作原理,同时也能掌握在C语言中实现安全通信的关键步骤。这对于开发自己的安全网络应用程序或者调试现有系统中的SSL问题都是非常有价值的。 在实际应用...
通过对源码的学习和研究,开发者不仅可以提升自己的技能,还能了解如何将理论知识应用于实际项目,这对于提升IT行业的实践能力是非常有益的。 总的来说,"基于SSL协议的FTP文件传输系统设计与开发源码"是一个很好的...
【SSL-RL】自监督强化学习:随机网络蒸馏(RND)方法 随机网络蒸馏(RND)是一种自监督学习方法,旨在提高强化学习中的探索效率。该算法由 Chesney et al. 在论文《Random Network Distillation as a Method for ...