1、生成密鑰庫和證書java
一、生成服務器證書庫服務器
keytool -validity 365 -genkey -v -alias uyun -keyalg RSA -keystore /opt/UEM/keyStore/uyun.keystore -dname "CN=192.168.16.163,OU=broada,O=broada,L=Hangzhou,ST=Hangzhou,c=cn" -storepass uyuncollector -keypass uyuncollector
二、生成客戶端證書庫ide
keytool -validity 365 -genkeypair -v -alias client -keyalg RSA -storetype PKCS12 -keystore /opt/UEM/keyStore/client.p12 -dname "CN=client,OU=broada,O=broada,L=hangzhou,ST=hangzhou,c=cn" -storepass uyuncollector -keypass uyuncollector
三、從客戶端證書庫中導出客戶端證書this
keytool -export -v -alias client -keystore /opt/UEM/keyStore/client.p12 -storetype PKCS12 -storepass uyuncollector -rfc -file /opt/UEM/keyStore/client.cer
四、從服務器證書庫中導出服務端證書blog
keytool -export -v -alias uyun -keystore /opt/UEM/keyStore/uyun.keystore -storepass uyuncollector -rfc -file /opt/UEM/keyStore/uyun.cer
五、生成客戶端信任證書庫(由服務端證書生成的證書庫)it
命令:io
keytool -import -v -alias uyun -file /opt/UEM/keyStore/uyun.cer -keystore /opt/UEM/keyStore/client.truststore -storepass uyuncollector
成功結果:class
[root@uem bin]# keytool -import -v -alias uyun -file /opt/UEM/keyStore/uyun.cer -keystore /opt/UEM/keyStore/client.truststore -storepass uyuncollector Owner: CN=192.168.16.163, OU=broada, O=broada, L=Hangzhou, ST=Hangzhou, C=cn Issuer: CN=192.168.16.163, OU=broada, O=broada, L=Hangzhou, ST=Hangzhou, C=cn Serial number: 21210db8 Valid from: Wed Jul 15 11:39:18 CST 2015 until: Thu Jul 14 11:39:18 CST 2016 Certificate fingerprints: MD5: 82:37:F3:44:19:93:94:A5:E7:6A:60:3A:AA:CF:8B:80 SHA1: 17:A6:24:A4:3D:0B:D3:8F:50:5A:8E:91:E8:1D:23:72:6C:D1:3D:38 SHA256: F0:A9:EC:85:06:64:E9:5D:D6:7B:65:9C:40:7D:DF:2C:C1:B5:41:08:CC:86:E1:1B:4A:3A:A3:0C:E2:F1:44:41 Signature algorithm name: SHA256withRSA Version: 3 Extensions: #1: ObjectId: 2.5.29.14 Criticality=false SubjectKeyIdentifier [ KeyIdentifier [ 0000: 02 E6 CD 31 BE F0 54 84 D1 B5 A3 E7 DC 2E 03 5B ...1..T........[ 0010: F2 22 05 0D .".. ] ] Trust this certificate? [no]: y Certificate was added to keystore [Storing /opt/UEM/keyStore/client.truststore]
六、將客戶端證書導入到服務器證書庫(使得服務器信任客戶端證書)import
keytool -import -v -alias client -file /opt/UEM/keyStore/client.cer -keystore /opt/UEM/keyStore/uyun.keystore -storepass uyuncollector
成功結果:cli
[root@uem bin]# keytool -import -v -alias client -file /opt/UEM/keyStore/client.cer -keystore /opt/UEM/keyStore/uyun.keystore -storepass uyuncollector Owner: CN=client, OU=broada, O=broada, L=hangzhou, ST=hangzhou, C=cn Issuer: CN=client, OU=broada, O=broada, L=hangzhou, ST=hangzhou, C=cn Serial number: 2dac5990 Valid from: Wed Jul 15 11:44:12 CST 2015 until: Thu Jul 14 11:44:12 CST 2016 Certificate fingerprints: MD5: 8B:80:CE:DB:5A:1A:B7:91:0F:46:93:1C:82:03:C6:7C SHA1: 7D:6B:1E:68:7D:9E:04:8B:B4:12:51:61:89:46:56:06:C2:50:5C:94 SHA256: 25:FE:36:79:7E:0C:9A:9F:DD:95:DB:92:82:C1:FC:C1:BD:BB:6B:05:D8:84:52:33:FE:5F:8D:25:23:00:E0:86 Signature algorithm name: SHA256withRSA Version: 3 Extensions: #1: ObjectId: 2.5.29.14 Criticality=false SubjectKeyIdentifier [ KeyIdentifier [ 0000: C4 52 CC CC 7A B0 B5 CA B6 CF E1 F9 53 7E 91 69 .R..z.......S..i 0010: 03 1C B2 69 ...i ] ] Trust this certificate? [no]: y Certificate was added to keystore [Storing /opt/UEM/keyStore/uyun.keystore]
七、查看證書庫中的所有證書:
keytool -list -keystore /opt/UEM/keyStore/uyun.keystore -storepass uyuncollector
結果:
[root@uem bin]# keytool -list -keystore /opt/UEM/keyStore/uyun.keystore -storepass uyuncollector
Keystore type: JKS
Keystore provider: SUN
Your keystore contains 2 entries
client, Jul 15, 2015, trustedCertEntry, Certificate fingerprint (SHA1): 7D:6B:1E:68:7D:9E:04:8B:B4:12:51:61:89:46:56:06:C2:50:5C:94uyun, Jul 15, 2015, PrivateKeyEntry, Certificate fingerprint (SHA1): 17:A6:24:A4:3D:0B:D3:8F:50:5A:8E:91:E8:1D:23:72:6C:D1:3D:38