SSL证书链不同;如何验证?

时间:2015-05-06 01:28:30

标签: ssl ssl-certificate libcurl

简短版:根据我访问https服务器的方式,我看到的SSL证书链有所不同。发生了什么,以及如何在这些情况下验证证书?

版本略长:

我尝试使用libcurl来验证SSL连接的证书。我连接的服务器是Amazon S3。

当我在Firefox中访问Amazon S3时,我得到了这个证书链:

  • VeriSign Class 3公共主要认证机构 - G5
    序列号:18:DA:D1:9E:26:7D:E8:BB:4A:21:58:CD:CC:6B:3B:4A
    • VeriSign Class 3安全服务器CA - G3
      序列号:6E:CC:7A:A5:A7:03:20:09:B8:CE:BC:F4:E9:52:D4:91
      • *。s3.amazonaws.com
        序号:43:FB:BA:C2:66:27:E0:97:1E:1C:11:E0:30:C3:6B:66

当我通过OpenSSL命令行工具访问同一个URL时,我得到了这个证书链:

  1. *。s3.amazonaws.com
    序列号:43fbbac26627e0971e1c11e030c36b66
  2. VeriSign Class 3安全服务器CA - G3
    序列号:6ecc7aa5a7032009b8cebcf4e952d491
  3. VeriSign Class 3公共主要认证机构 - G5
    编号:35973187f3873a07327ece580c9b7eda
  4. " *。s3.amazonaws.com"和" VeriSign Class 3安全服务器CA - G3"证书似乎是相同的,但之后的证书是不同的!它被命名为" VeriSign Class 3公共主要认证机构 - G5"在两个链中,但证书序列号不同。 (其他信息也不同;如果您想要更长的转储,请告诉我。)

    我认为这种差异是我无法通过libcurl验证SSL证书的原因。序列号为#34; 18:DA:D1 ..."在我的CACERT.PEM文件中,但序列号为#34; 35:97:31的证书..."不是。

    显然,简单的解决方法是添加证书" 35:97:31 ......"到我的CACERT.PEM文件,但我想在这里进行正确的更改,而不仅仅是快速修复。

    • 证书链中的这种差异意味着什么?
    • SSL服务器甚至可以根据客户端返回不同的证书链(Firefox与OpenSSL / libcurl)吗?
    • 如何让libcurl验证此SSL证书?

    非常长的版本和背景信息:

    我使用libcurl和OpenSSL从Amazon S3下载。 Libcurl正在返回" SSL证书问题:无法获得本地颁发者证书",我知道这意味着根证书未列在我的CACERT.PEM文件中。 (我使用的是downloaded from curl's website,它是从Mozilla的证书存储区转换而来的。)我能够验证其他SSL连接上的证书,所以我知道我的libcurl设置是正确的。

    要查看正在发生的事情以及证书无法验证的原因,我在Firefox中提取了相同的网址。 Firefox没有显示任何SSL证书警告。这是Firefox显示的认证路径。根证书" VeriSign Class 3公共主要证书颁发机构 - G5",列在我的CACERT.PEM文件中,证书的序列号与屏幕截图中显示的内容相符。

    Firefox screenshot

    这里是链中所有三个证书的序列号:

    • VeriSign Class 3公共主要认证机构 - G5
      序列号:18:DA:D1:9E:26:7D:E8:BB:4A:21:58:CD:CC:6B:3B:4A
      • VeriSign Class 3安全服务器CA - G3
        序列号:6E:CC:7A:A5:A7:03:20:09:B8:CE:BC:F4:E9:52:D4:91
        • *。s3.amazonaws.com
          序号:43:FB:BA:C2:66:27:E0:97:1E:1C:11:E0:30:C3:6B:66

    在不同的平台(不同的操作系统,不同版本的OpenSSL等)上,我尝试使用OpenSSL命令行工具访问相同的URL,并获得了不同的认证路径!

    $ openssl s_client -showcerts -connect stackoverflowtest.s3.amazonaws.com:443
    CONNECTED(00000003)
    depth=3 C = US, O = "VeriSign, Inc.", OU = Class 3 Public Primary Certification Authority
    verify return:1
    depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5
    verify return:1
    depth=1 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = Terms of use at https://www.verisign.com/rpa (c)10, CN = VeriSign Class 3 Secure Server CA - G3
    verify return:1
    depth=0 C = US, ST = Washington, L = Seattle, O = Amazon.com Inc., OU = S3-A, CN = *.s3.amazonaws.com
    verify return:1
    ---
    Certificate chain
     0 s:/C=US/ST=Washington/L=Seattle/O=Amazon.com Inc./OU=S3-A/CN=*.s3.amazonaws.com
       i:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=Terms of use at https://www.verisign.com/rpa (c)10/CN=VeriSign Class 3 Secure Server CA - G3
    -----BEGIN CERTIFICATE-----
    MIIFOTCCBCGgAwIBAgIQQ/u6wmYn4JceHBHgMMNrZjANBgkqhkiG9w0BAQUFADCB
    tTELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
    ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTswOQYDVQQLEzJUZXJtcyBvZiB1c2Ug
    YXQgaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JwYSAoYykxMDEvMC0GA1UEAxMm
    VmVyaVNpZ24gQ2xhc3MgMyBTZWN1cmUgU2VydmVyIENBIC0gRzMwHhcNMTQwNjI1
    MDAwMDAwWhcNMTUwNjA1MjM1OTU5WjB6MQswCQYDVQQGEwJVUzETMBEGA1UECBMK
    V2FzaGluZ3RvbjEQMA4GA1UEBxQHU2VhdHRsZTEYMBYGA1UEChQPQW1hem9uLmNv
    bSBJbmMuMQ0wCwYDVQQLFARTMy1BMRswGQYDVQQDFBIqLnMzLmFtYXpvbmF3cy5j
    b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC+mjGH4PrN0TDNmTsF
    my2fHpHpTuySRwBMe/nuGIkL3cvKIxFKLHvkK9kx1UpO0skdQTdCY55LywhubLNO
    fD19IzJdoRGdlqgkDAYC8vz3LRYj8WWsGnROfS/YFtgj25YaHPnsNp6lWrff4/qi
    ctbojJpMxm+9Q0A4nTzrZymHEUkRbx6AVVUBVKH3uZi/w0aV+i4cp2bs+CYIK3DL
    Qp584DJ9bOImgUhDfz19+Wtv64zIezE0Uz9eOkqgQ1X//XumyZWyD6N6+h/XqTnc
    YTvIer/s83T/IngGMbfPRqjpQCay6ySXCNbJ5izMgo+gwN84t7JhaI+EYcxf1dDN
    w0mXAgMBAAGjggF9MIIBeTAJBgNVHRMEAjAAMA4GA1UdDwEB/wQEAwIFoDAdBgNV
    HSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwZQYDVR0gBF4wXDBaBgpghkgBhvhF
    AQc2MEwwIwYIKwYBBQUHAgEWF2h0dHBzOi8vZC5zeW1jYi5jb20vY3BzMCUGCCsG
    AQUFBwICMBkaF2h0dHBzOi8vZC5zeW1jYi5jb20vcnBhMB8GA1UdIwQYMBaAFA1E
    XBZTRMGCfh0gqyX0AWPYvnmlMCsGA1UdHwQkMCIwIKAeoByGGmh0dHA6Ly9zZC5z
    eW1jYi5jb20vc2QuY3JsMFcGCCsGAQUFBwEBBEswSTAfBggrBgEFBQcwAYYTaHR0
    cDovL3NkLnN5bWNkLmNvbTAmBggrBgEFBQcwAoYaaHR0cDovL3NkLnN5bWNiLmNv
    bS9zZC5jcnQwLwYDVR0RBCgwJoISKi5zMy5hbWF6b25hd3MuY29tghBzMy5hbWF6
    b25hd3MuY29tMA0GCSqGSIb3DQEBBQUAA4IBAQBlXrn1FTPjVIFbcuQNbBesrAMI
    NV4L7jS1mobEwFrb7UrqZ7kHvuvoR/BpDygATyqLvPihs7nUc2TUHsw/41EAHKoq
    QBVfRTOH0yWaTC6SYSx7fiElL+k55Pvrz4+7gLRy5zUlVX3iUw93zr95ka/LPuCL
    7PQOFPeQDOgveDjcSNVtLcTfQfvog/rMSu/4XPFHu7zaZwUEurt9CzLeVbdB6O25
    bHuHTaZLP0wmjCIbwgXu8bFWqOTnAjG70EtYrbIiQhl/ISJU6HioFzLiy5Ibp07r
    RbV4ir5EI2EPKxIy30YDvpCQ0WQvYLWFV0qQOuOXkMC2M2IsBmVn2/9GQ7eP
    -----END CERTIFICATE-----
     1 s:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=Terms of use at https://www.verisign.com/rpa (c)10/CN=VeriSign Class 3 Secure Server CA - G3
       i:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
    -----BEGIN CERTIFICATE-----
    MIIF7DCCBNSgAwIBAgIQbs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MAGGGGh0dHA6Ly9vY3NwLnZlcmlz
    aWduLmNvbTASBgNVHRMBAf8ECDAGAQH/AgEAMHAGA1UdIARpMGcwZQYLYIZIAYb4
    RQEHFwMwVjAoBggrBgEFBQcCARYcaHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL2Nw
    czAqBggrBgEFBQcCAjAeGhxodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhMDQG
    A1UdHwQtMCswKaAnoCWGI2h0dHA6Ly9jcmwudmVyaXNpZ24uY29tL3BjYTMtZzUu
    Y3JsMA4GA1UdDwEB/wQEAwIBBjBtBggrBgEFBQcBDARhMF+hXaBbMFkwVzBVFglp
    bWFnZS9naWYwITAfMAcGBSsOAwIaBBSP5dMahqyNjmvDz4Bq1EgYLHsZLjAlFiNo
    dHRwOi8vbG9nby52ZXJpc2lnbi5jb20vdnNsb2dvLmdpZjAoBgNVHREEITAfpB0w
    GzEZMBcGA1UEAxMQVmVyaVNpZ25NUEtJLTItNjAdBgNVHQ4EFgQUDURcFlNEwYJ+
    HSCrJfQBY9i+eaUwHwYDVR0jBBgwFoAUf9Nlp8Ld7LvwMAnzQzn6Aq8zMTMwDQYJ
    KoZIhvcNAQEFBQADggEBAAyDJO/dwwzZWJz+NrbrioBL0aP3nfPMU++CnqOh5pfB
    WJ11bOAdG0z60cEtBcDqbrIicFXZIDNAMwfCZYP6j0M3m+oOmmxw7vacgDvZN/R6
    bezQGH1JSsqZxxkoor7YdyT3hSaGbYcFQEFn0Sc67dxIHSLNCwuLvPSxe/20majp
    dirhGi2HbnTTiN0eIsbfFrYrghQKlFzyUOyvzv9iNw2tZdMGQVPtAhTItVgooazg
    W+yzf5VK+wPIrSbb5mZ4EkrZn0L74ZjmQoObj49nJOhhGbXdzbULJgWOw27EyHW4
    Rs/iGAZeqa6ogZpHFt4MKGwlJ7net4RYxh84HqTEy2Y=
    -----END CERTIFICATE-----
     2 s:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
       i:/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification Authority
    -----BEGIN CERTIFICATE-----
    MIIExjCCBC+gAwIBAgIQNZcxh/OHOgcyfs5YDJt+2jANBgkqhkiG9w0BAQUFADBf
    MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNzA1BgNVBAsT
    LkNsYXNzIDMgUHVibGljIFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkw
    HhcNMDYxMTA4MDAwMDAwWhcNMjExMTA3MjM1OTU5WjCByjELMAkGA1UEBhMCVVMx
    FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVz
    dCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2lnbiwgSW5jLiAtIEZv
    ciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAz
    IFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0gRzUwggEi
    MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1nmAMqudLO07cfLw8
    RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKzj/i5Vbext0uz/o9+B1fs70Pb
    ZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIzSdhDY2pSS9KP6HBR
    TdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQGBO+QueQA5N06tRn/
    Arr0PO7gi+s3i+z016zy9vA9r911kTMZHRxAy3QkGSGT2RT+rCpSx4/VBEnkjWNH
    iDxpg8v+R70rfk/Fla4OndTRQ8Bnc+MUCH7lP59zuDMKz10/NIeWiu5T6CUVAgMB
    AAGjggGRMIIBjTAPBgNVHRMBAf8EBTADAQH/MDEGA1UdHwQqMCgwJqAkoCKGIGh0
    dHA6Ly9jcmwudmVyaXNpZ24uY29tL3BjYTMuY3JsMA4GA1UdDwEB/wQEAwIBBjA9
    BgNVHSAENjA0MDIGBFUdIAAwKjAoBggrBgEFBQcCARYcaHR0cHM6Ly93d3cudmVy
    aXNpZ24uY29tL2NwczAdBgNVHQ4EFgQUf9Nlp8Ld7LvwMAnzQzn6Aq8zMTMwNAYD
    VR0lBC0wKwYJYIZIAYb4QgQBBgpghkgBhvhFAQgBBggrBgEFBQcDAQYIKwYBBQUH
    AwIwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAHBgUr
    DgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVyaXNp
    Z24uY29tL3ZzbG9nby5naWYwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhho
    dHRwOi8vb2NzcC52ZXJpc2lnbi5jb20wDQYJKoZIhvcNAQEFBQADgYEADyWuSO0b
    M4VMDLXC1/5N1oMoTEFlYAALd0hxgv5/21oOIMzS6ke8ZEJhRDR0MIGBJopK90Rd
    fjSAqLiD4gnXbSPdie0oCL1jWhFXCMSe2uJoKK/dUDzsgiHYAMJVRFBwQa2DF3m6
    CPMr3u00HUSe0gST9MsFFy0JLS1j7/YmC3s=
    -----END CERTIFICATE-----
    ---
    Server certificate
    subject=/C=US/ST=Washington/L=Seattle/O=Amazon.com Inc./OU=S3-A/CN=*.s3.amazonaws.com
    issuer=/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=Terms of use at https://www.verisign.com/rpa (c)10/CN=VeriSign Class 3 Secure Server CA - G3
    ---
    No client certificate CA names sent
    Server Temp Key: ECDH, prime256v1, 256 bits
    ---
    SSL handshake has read 4624 bytes and written 399 bytes
    ---
    New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-SHA
    Server public key is 2048 bit
    Secure Renegotiation IS supported
    Compression: NONE
    Expansion: NONE
    SSL-Session:
        Protocol  : TLSv1.2
        Cipher    : ECDHE-RSA-AES128-SHA
        Session-ID: B642ED1E6FE32F7A374B5A62847DEC63C2F37DCA7A18FD669B8F0FCDC98C49BF
        Session-ID-ctx:
        Master-Key: EE2D31F43D341A0895B36E0BCCE7557B221F1469AC1B7B0BA22D843C75F25F949822B0D0E22E967A1F373F034E9624E4
        Key-Arg   : None
        Krb5 Principal: None
        PSK identity: None
        PSK identity hint: None
        Start Time: 1430871883
        Timeout   : 300 (sec)
        Verify return code: 0 (ok)
    ---
    closed
    

    当我decode列出的证书时,我获得的证书链不同于Firefox给我的。

    1. *。s3.amazonaws.com
      序列号:43fbbac26627e0971e1c11e030c36b66
    2. VeriSign Class 3安全服务器CA - G3
      序列号:6ecc7aa5a7032009b8cebcf4e952d491
    3. VeriSign Class 3公共主要认证机构 - G5
      编号:35973187f3873a07327ece580c9b7eda
    4. 正在使用的证书及其直接父证书是相同的,但下一个证书具有相同的名称,但序列号不同。

      这是我的版本信息:

      > curld --version
      curl 7.40.0 (i386-pc-win32ce) libcurl/7.40.0 OpenSSL/1.0.1e
      Protocols: dict ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps tftp
      Features: NTLM SSL
      
      > curld --version
      curl 7.40.0 (i386-pc-win32) libcurl/7.40.0 OpenSSL/1.0.1c
      Protocols: dict ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps tftp
      Features: AsynchDNS Largefile NTLM SSL
      
      $ cat /etc/redhat-release
      CentOS release 6.6 (Final)
      $ openssl version
      OpenSSL 1.0.1e-fips 11 Feb 2013
      $ yum list openssl
      Installed Packages
      openssl.x86_64               1.0.1e-30.el6.8               @updates
      

      Firefox:37.0.2,在Windows 7 x64上运行。

      我确实回答了这个问题:SSL Certificate - Certification Path in browser different from Certificate Chain File,但我的问题似乎有所不同:在这种情况下,OpenSSL命令行工具中的证书链变为1 - 2 - 3 - 4,在IE中它是1 - 2 - 3.因为IE考虑了#34; 3"作为根证书,链条提前停止。在我的例子中,Firefox报告1 - 2 - 3,OpenSSL报告1 - 2 - 4;链条是不同的。

1 个答案:

答案 0 :(得分:4)

服务器将相同的链证书发送到firefox和s_client:

  1. CN = .s3.amazonaws.com SAN = DNS: .s3.amazonaws.com,DNS:s3.amazonaws.com
  2. CN = VeriSign Class 3安全服务器CA - G3
  3. CN = VeriSign Class 3公共主要证书颁发机构 - G5
  4. 但验证证书的方式因SSL堆栈和客户端的受信任根证书而异。如果是curl,你会遇到一个旧的OpenSSL验证问题。详细说明:

    • Firefox拥有一个受信任的根证书,类似于客户端发送的证书#3。这意味着它是一个不同的证书,但它包含相同的公钥,因此证书#2的签名仍然有效。由于Firefox底层TLS堆栈(NSS)因此找到了可用的信任锚,因此它会将链视为已验证,并忽略服务器发送的证书#3。
    • 但是你使用的curl版本使用OpenSSL作为TLS库。 OpenSSL尝试获得最长匹配,它将尝试查找签署证书#3的受信任根证书。如果失败,它将不会尝试使用较短的信任链,而只是失败。这是一个长期存在的错误,这是导致很多这样的奇怪问题的原因,看起来问题现在只在最新的开发分支中修复(未发布)。

    解决方案可能是使用CA存储进行卷曲which still includes the old deprecated 1024bit CA's,以便它包含信任锚" / C = US / O = VeriSign,Inc. / OU = Class 3 Public Primary Certification Authority& #34;

    有关此问题的更多详细信息,请参阅