赞
踩
例如,我们在访问 https://www.youzan.com
时,浏览器会得到一个 TLS 证书,这个数字证书用于证明我们正在访问的网站和证书的持有者是匹配的,否则因为身份认证无法通过,连接也就无法建立。
浏览器得到的是一个证书的链表,这个链表叫证书链(Certificate Chain)。
HTTPS
协议栈与 HTTP
的唯一区别HTTPS
多了一个安全层(Security Layer),即 TLS/SSL
。SSL
是最早的安全层协议, TLS
由 SSL
发展而来,下面我们统称 TLS
。OkHttp
是android端最火热的一个轻量级框架,用于替代HttpUrlConnection
和Apache HttpClient
。enum
类型来表示 TLS 协议的不同版本。可以看到最早的版本是 SSLv3,诞生于 1996 年,最新的版本是 TLSv1.3。public enum TlsVersion {
TLS_1_3("TLSv1.3"), // 2016. (最新的版本)
TLS_1_2("TLSv1.2"), // 2008.
TLS_1_1("TLSv1.1"), // 2006.
TLS_1_0("TLSv1"), // 1999.
SSL_3_0("SSLv3"), // 1996.(最早的版本)
;
final String javaName;
}
X.509
规范来签发公钥证书(Public Key Certificate),证书内容的语法格式遵守 ASN.1
,证书大致包含如下内容:Certificate Issuer
表示证书的签发者/颁发者。如访问网址 https://www.youzan.com
的[*.youzan.com]
证书,它的签发者是它的父节点[GeoTrust RSA CA 2018]
。Issuer
字段的内容是一组符合X.500
规范的DN(Distinguished Name),其中DN是由逗号连接的相对专有名称(RDN,relative distinguished names)的序列。Issuer
通常表示为:Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=GeoTrust RSA CA 2018
属性名称 | 属性值 |
---|---|
DC | domainComponent |
CN | commonName |
OU | organizationUnitName |
O | organizationName |
STREET | streetAddress |
L | localityName |
ST | stateOrProvinceName |
UID | userid |
https://link.zhihu.com/?target=https%3A//www.youzan.com/
。具体步骤,windows系统可以按照教程 (如何从浏览器导出HTTPS证书)完成,mac系统目前不知道如何导出。pem
。-证书导出包含四种格式。但不知道为什么我导出的cer文件格式openssl解析失败。
证书:Certificate (.cer)
增强保密邮件:Privacy Enhanced Mail (.pem)
证书包Certificate Bundle (.p7b)
个人信息交换:Personal Information Exchange (.p12)
terminal
通过openssl命令
查看证书内容openssl x509 -in /Users/zijikanwa/*.zhihu.com.pem -text
Certificate: Data: Version: 3 (0x2) Serial Number: 0e:3c:c1:49:94:b3:e1:74:a6:34:54:d9:90:64:66:d7 Signature Algorithm: sha256WithRSAEncryption Issuer: C=US, O=DigiCert Inc, OU=www.digicert.com, CN=GeoTrust RSA CA 2018 Validity Not Before: Dec 25 00:00:00 2017 GMT Not After : Dec 24 12:00:00 2020 GMT Subject: C=CN, L=\xE5\x8C\x97\xE4\xBA\xAC\xE5\xB8\x82, O=\xE6\x99\xBA\xE8\x80\x85\xE5\x9B\x9B\xE6\xB5\xB7\xEF\xBC\x88\xE5\x8C\x97\xE4\xBA\xAC\xEF\xBC\x89\xE6\x8A\x80\xE6\x9C\xAF\xE6\x9C\x89\xE9\x99\x90\xE5\x85\xAC\xE5\x8F\xB8, OU=IT, CN=*.zhihu.com Subject Public Key Info: Public Key Algorithm: rsaEncryption Public-Key: (2048 bit) Modulus: 00:a0:a8:71:88:cf:5e:1b:e6:c8:45:ed:60:89:ce: d2:76:a0:af:03:a6:c1:18:bb:8c:8c:c7:cb:b6:93: ce:46:4f:46:74:66:49:1a:80:2c:ae:4f:1b:db:c1: 5c:8d:ad:b6:23:06:dc:97:c0:d0:c4:7d:a9:f8:4e: 79:e4:b4:d1:ed:41:c3:52:87:6c:ac:f3:05:86:5f: 57:52:a0:d2:93:34:7c:6f:d5:4e:21:c4:7c:5b:be: 6f:b0:3e:ef:6c:4c:8f:90:f7:ae:50:c9:a0:b7:dd: 42:eb:c2:c0:58:0e:da:65:01:be:c1:43:6e:2f:f2: 59:fd:b6:c4:59:1f:cd:ee:af:55:44:06:c4:8b:6e: b8:f7:1a:e1:ad:89:4a:0a:a2:9c:a3:a8:bc:65:41: f3:7d:e0:29:03:fb:84:a3:da:7b:fb:c9:ec:87:aa: 87:5c:58:02:0e:02:d8:c1:cf:b1:1c:25:f7:df:ac: 0a:a6:7b:c5:5d:d0:51:e2:97:c6:ff:01:17:21:a6: c0:fd:88:b1:a6:2d:aa:d0:4f:61:3c:35:13:dc:ff: 51:ce:2d:48:18:c3:cd:05:43:60:e2:9a:4c:01:55: 98:31:9d:f3:c4:4b:3b:49:17:d4:bd:0b:34:e1:24: 05:a7:48:87:49:69:77:76:d0:d3:f2:70:f2:e7:c0: 90:b1 Exponent: 65537 (0x10001) X509v3 extensions: X509v3 Authority Key Identifier: keyid:90:58:FF:B0:9C:75:A8:51:54:77:B1:ED:F2:A3:43:16:38:9E:6C:C5 X509v3 Subject Key Identifier: 31:63:1F:A1:0B:43:D7:A5:8C:3D:F6:2E:85:69:D4:E1:E3:56:91:46 X509v3 Subject Alternative Name: DNS:*.zhihu.com, DNS:zhihu.com X509v3 Key Usage: critical Digital Signature, Key Encipherment X509v3 Extended Key Usage: TLS Web Server Authentication, TLS Web Client Authentication X509v3 CRL Distribution Points: Full Name: URI:http://cdp.geotrust.com/GeoTrustRSACA2018.crl X509v3 Certificate Policies: Policy: 2.16.840.1.114412.1.1 CPS: https://www.digicert.com/CPS Policy: 2.23.140.1.2.2 Authority Information Access: OCSP - URI:http://status.geotrust.com CA Issuers - URI:http://cacerts.geotrust.com/GeoTrustRSACA2018.crt X509v3 Basic Constraints: CA:FALSE Signature Algorithm: sha256WithRSAEncryption 54:73:e6:02:db:5d:49:30:4d:61:71:ac:ef:6d:f1:52:af:45: f2:0f:81:94:0b:5c:0e:bd:b6:c2:98:af:08:6c:11:45:25:e9: 8d:7d:80:d8:3e:78:50:5d:f8:4d:bf:ef:6d:fd:8a:74:d9:6c: 90:65:55:b6:d1:59:3a:07:25:42:6a:74:b0:dd:31:e2:a0:50: 04:4a:03:fe:61:24:e7:74:33:c9:69:94:70:79:d9:89:20:c3: 80:b2:e7:73:72:b6:73:00:10:8f:8e:25:0e:1f:41:b6:bc:86: da:d2:b4:ae:c7:b9:1d:80:fa:58:e7:ba:79:2c:ef:63:5a:96: af:03:22:98:78:58:57:9f:70:45:a3:0a:22:87:c3:ef:45:7d: 2a:ed:d8:1b:38:2e:9e:d7:27:7e:53:d1:44:62:3d:cb:d0:e6: 01:e6:3a:5c:86:8c:d5:b8:91:4c:d8:55:07:e6:23:03:71:23: ce:19:f6:4e:a4:ba:69:55:eb:d9:11:49:32:09:ee:b8:58:43: 69:ff:51:6b:c6:17:7f:74:83:50:19:a0:99:79:64:6a:e0:ff: 5b:f5:51:53:fb:22:3a:10:a4:4f:ed:25:b2:ca:cb:8a:1b:1e: bc:db:5d:46:95:31:fe:03:c8:cc:42:dc:b6:e4:29:d9:85:f9: 6a:4e:39:d8 -----BEGIN CERTIFICATE----- MIIFCTCCA/GgAwIBAgIQDjzBSZSz4XSmNFTZkGRm1zANBgkqhkiG9w0BAQsFADBe MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 d3cuZGlnaWNlcnQuY29tMR0wGwYDVQQDExRHZW9UcnVzdCBSU0EgQ0EgMjAxODAe Fw0xNzEyMjUwMDAwMDBaFw0yMDEyMjQxMjAwMDBaMHkxCzAJBgNVBAYTAkNOMRIw EAYDVQQHDAnljJfkuqzluIIxMzAxBgNVBAoMKuaZuuiAheWbm+a1t++8iOWMl+S6 rO+8ieaKgOacr+aciemZkOWFrOWPuDELMAkGA1UECxMCSVQxFDASBgNVBAMMCyou emhpaHUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoKhxiM9e G+bIRe1gic7SdqCvA6bBGLuMjMfLtpPORk9GdGZJGoAsrk8b28Fcja22Iwbcl8DQ xH2p+E555LTR7UHDUodsrPMFhl9XUqDSkzR8b9VOIcR8W75vsD7vbEyPkPeuUMmg t91C68LAWA7aZQG+wUNuL/JZ/bbEWR/N7q9VRAbEi2649xrhrYlKCqKco6i8ZUHz feApA/uEo9p7+8nsh6qHXFgCDgLYwc+xHCX336wKpnvFXdBR4pfG/wEXIabA/Yix pi2q0E9hPDUT3P9Rzi1IGMPNBUNg4ppMAVWYMZ3zxEs7SRfUvQs04SQFp0iHSWl3 dtDT8nDy58CQsQIDAQABo4IBpjCCAaIwHwYDVR0jBBgwFoAUkFj/sJx1qFFUd7Ht 8qNDFjiebMUwHQYDVR0OBBYEFDFjH6ELQ9eljD32LoVp1OHjVpFGMCEGA1UdEQQa MBiCCyouemhpaHUuY29tggl6aGlodS5jb20wDgYDVR0PAQH/BAQDAgWgMB0GA1Ud JQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjA+BgNVHR8ENzA1MDOgMaAvhi1odHRw Oi8vY2RwLmdlb3RydXN0LmNvbS9HZW9UcnVzdFJTQUNBMjAxOC5jcmwwTAYDVR0g BEUwQzA3BglghkgBhv1sAQEwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly93d3cuZGln aWNlcnQuY29tL0NQUzAIBgZngQwBAgIwdQYIKwYBBQUHAQEEaTBnMCYGCCsGAQUF BzABhhpodHRwOi8vc3RhdHVzLmdlb3RydXN0LmNvbTA9BggrBgEFBQcwAoYxaHR0 cDovL2NhY2VydHMuZ2VvdHJ1c3QuY29tL0dlb1RydXN0UlNBQ0EyMDE4LmNydDAJ BgNVHRMEAjAAMA0GCSqGSIb3DQEBCwUAA4IBAQBUc+YC211JME1hcazvbfFSr0Xy D4GUC1wOvbbCmK8IbBFFJemNfYDYPnhQXfhNv+9t/Yp02WyQZVW20Vk6ByVCanSw 3THioFAESgP+YSTndDPJaZRwedmJIMOAsudzcrZzABCPjiUOH0G2vIba0rSux7kd gPpY57p5LO9jWpavAyKYeFhXn3BFowoih8PvRX0q7dgbOC6e1yd+U9FEYj3L0OYB 5jpchozVuJFM2FUH5iMDcSPOGfZOpLppVevZEUkyCe64WENp/1Frxhd/dINQGaCZ eWRq4P9b9VFT+yI6EKRP7SWyysuKGx68211GlTH+A8jMQty25CnZhflqTjnY -----END CERTIFICATE-----
Signature = RSA(sha256(Data), IssuerPrivateKey)
https://www.youzan.com
)时,浏览器并非只拿到一个证书,而是一个证书链:DigiCert Global Root CA
|__ GeoTrust RSA CA 2018
|__ *.zhihu.com
证书「*.zhihu.com」
的 签发者(Issuer)就是它的父节点「GeoTrust RSA CA 2018」
。因为 UA(浏览器或操作系统)中会预先内置一些权威 CA
签发的根证书(Root Certificate)或中间证书(Intermediate Certificate),例如上面的 「GeoTrust RSA CA 2018」
和 「DigiCert Global Root CA」
。
当获得证书链之后,我们就可以很轻松的往上回溯到被 UA 信任的证书,虽然 UA 内置的可能是中间证书(Intermediate Certificate)。
但是如果一个 End-Entity 证书即使回溯到跟证书(Root Certificate)也没有在 UA 的受信列表中找到,那么这个站点就会被标记为不安全。例如 12306 的主页被标记为 “Not Secure",因为它的根证书不被信任。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。