转载自:http://www.iteye.com/topic/1125183
有关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
相关推荐
BoringSSL是一个由Google维护的SSL/TLS实现,它是OpenSSL的一个分支,旨在提供更简洁的代码库,更严格的审核,以及对现代硬件优化的支持。这个win-x86_64包显然为Windows 64位平台设计,包含了三个关键组件:`bssl....
在IT行业中,尤其是在Web服务器和应用服务器领域,SSL(Secure Sockets Layer)和其后续版本TLS(Transport Layer Security)是确保数据传输安全的关键技术。Tomcat作为一款流行的Java应用服务器,支持SSL配置以实现...
MySQL 使用SSL连接配置详解 在现代数据库管理中,安全性是至关重要的,SSL(Secure Sockets Layer)连接为MySQL提供了一种加密数据传输的方式,确保了客户端和服务器之间的通信不被窃听或篡改。本文将详细介绍如何...
在Kubernetes(K8S)集群环境中,安全套接字层(SSL)证书的监控是确保服务安全和稳定的重要环节。SSL证书用于加密网络通信,确保数据传输的安全性。`ssl-exporter`是一款专为监控SSL/TLS证书状态设计的Prometheus ...
在当今的网络安全领域,加密通讯协议SSL(Secure Sockets Layer,安全套接层)扮演着至关重要的角色。SSL协议能够为基于IP层的网络通讯提供加密和认证服务,保障数据传输的安全性,防止被窃听或篡改。在Linux环境下...
在Python编程过程中,有时会遇到导入模块时遇到错误,例如"ImportError: No module named _ssl"。这个错误通常表示Python无法找到SSL模块,该模块是Python标准库的一部分,用于处理安全套接层(SSL)和传输层安全...
**Apache SSL 插件:mod_ssl** Apache HTTP Server 是世界上最流行的Web服务器软件,而mod_ssl是Apache的一个核心模块,专门用于实现安全套接层(SSL)协议,为网站提供安全的HTTPS服务。SSL(Secure Sockets Layer...
SSL/TLS(安全套接层/传输层安全)协议是互联网上广泛使用的安全通信协议,用于在客户端(如浏览器)和服务器之间建立安全、私密的连接,保护数据免受窃听和篡改。RFC5246文档是SSL/TLS协议的最新版本,正式名为...
SSL(Secure Sockets Layer)证书是互联网安全领域的重要组成部分,用于加密用户与服务器之间的通信,确保数据在传输过程中不被窃取或篡改。在本地生成SSL证书,可以帮助开发者在测试环境中模拟真实环境的安全设置,...
### 信安SSL配置知识点详解 #### 一、实施步骤和操作过程 1. **登录管理界面**: - **管理口**: 设备的Port1口,地址为192.168.1.99。 - **登录方式**: - 直接连接笔记本电脑至设备的Port1口并通过浏览器访问`...
### ApacheFtpServer之ssl配置详解 #### 一、FTPS概述 FTPS(File Transfer Protocol Secure),即安全文件传输协议,是一种通过SSL/TLS(Secure Sockets Layer/Transport Layer Security)来保护传统FTP(File ...
### STM32 实现SSL通讯 #### 一、引言 随着网络安全日益受到重视,确保数据传输的安全性成为了一个不容忽视的问题。对于嵌入式系统而言,如何在资源受限的条件下实现安全通信变得尤为重要。本篇文章将基于STM32F...
本文将详细介绍如何在Nginx服务器上配置SSL自签名证书。 首先,我们需要生成自签名SSL证书。这通常包括以下步骤: 1. **生成RSA密钥**:使用`openssl genrsa`命令创建一个带有密码保护的RSA私钥。例如,`openssl ...
ssl_session_cache shared:SSL:10m; # 管理 SSL 会话缓存 ssl_session_timeout 10m; # 设置 SSL 会话超时时间 ``` 6. **处理静态资源**: - 通过 `location` 块配置,Nginx 可以高效地处理各种静态文件请求,...
SSL证书在线生成系统源码是实现网站安全的重要工具,它基于公钥基础设施(PKI)原理,用于在互联网上建立安全的数据传输通道。本系统允许用户通过在线方式申请并生成SSL证书,简化了传统SSL证书获取流程,提升了用户...
在本文中,我们将深入探讨如何使用Visual C++(VC)进行SSL通信,主要基于OpenSSL库来实现Socket服务器和客户端的交互。SSL(Secure Sockets Layer)是一种安全协议,用于在互联网上提供加密通信和身份验证,而...
本报告就如何配置SSL/TLS以提供最先进的身份验证和加密技术提出了一般性建议。ssl引擎提供的选项是从 自从Netscape开发SSL2.0以来的早期。TLS的引入使问题变得更具有挑战性,因为服务器和客户端根据各个ssl引擎提供...
### 超微H12SSL-C用户手册关键知识点解析 #### 一、产品概述与文档准确性声明 根据所提供的文件信息,“超微H12SSL-C用户手册”是一份关于超微H12SSL-C系列服务器主板(包括H12SSL-i/C/CT/NT型号)的操作指南。该...
在Linux环境下,使用C语言编写基于SSL(Secure Socket Layer)的TCP程序是一项常见的任务,尤其在开发安全通信软件时。SSL是一种网络安全协议,用于在Internet上提供加密通信和身份验证。下面将详细介绍如何在Linux...
SSL(Secure Socket Layer)是一种广泛使用的网络安全协议,其主要任务是提供加密通信和身份认证,确保数据在网络传输过程中的安全性和完整性。SSL的工作原理涉及到多个关键概念和技术。 首先,SSL的核心在于加密,...