OpenSSL s_client 在一台机器上返回不支持的证书用途,但在另一台具有相同证书的机器上正常工作

OpenSSL s_client 在一台机器上返回不支持的证书用途,但在另一台具有相同证书的机器上正常工作

我正在调试主机和 Docker 容器之间的 TLS 连接问题。我的 Docker 容器有一个服务器证书:

-----BEGIN CERTIFICATE-----
MIICWjCCAgGgAwIBAgIRANvW2Yf383GwxnIkjgkYSkYwCgYIKoZIzj0EAwIwcDEL
MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
cmFuY2lzY28xFjAUBgNVBAoTDWluc3VyYW5jZS1vcmcxHDAaBgNVBAMTE3Rsc2Nh
Lmluc3VyYW5jZS1vcmcwHhcNMTkxMDIzMDYyNjQyWhcNMjkxMDIwMDYyNjQyWjBT
MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2Fu
IEZyYW5jaXNjbzEXMBUGA1UEAxMOaW5zdXJhbmNlLXBlZXIwWTATBgcqhkjOPQIB
BggqhkjOPQMBBwNCAAR9Weg8lFSG6SdLYm78Vght0zHeGD3HkxkQ0lFkpL7cqNMF
Zjj9W+9iHI40Ww45Cj12EE5lts95s2fXtIRw5k/bo4GYMIGVMA4GA1UdDwEB/wQE
AwIFoDAdBgNVHSUEFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwDAYDVR0TAQH/BAIw
ADArBgNVHSMEJDAigCD+YRoM4vL2vWIlIp0YNf3HmJL5NxHyB2Cmv5GrEJ9VWTAp
BgNVHREEIjAggg5pbnN1cmFuY2UtcGVlcoIOaW5zdXJhbmNlLXBlZXIwCgYIKoZI
zj0EAwIDRwAwRAIgQBSXuMpnKYfxiSoH6KWtLEZYF6bGjju1vSE3O2BLWswCICUq
9A08+Aj+u1Kv+BpNpTsYMZ8FMQvv4ACoKKBD6PJ0
-----END CERTIFICATE-----

该证书由CA颁发,证书内容如下:

-----BEGIN CERTIFICATE-----
MIICPDCCAeOgAwIBAgIQYAbsZD8nQXqvSyVkNMYg/jAKBggqhkjOPQQDAjBwMQsw
CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
YW5jaXNjbzEWMBQGA1UEChMNaW5zdXJhbmNlLW9yZzEcMBoGA1UEAxMTdGxzY2Eu
aW5zdXJhbmNlLW9yZzAeFw0xOTEwMjMwNjI2NDJaFw0yOTEwMjAwNjI2NDJaMHAx
CzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4g
RnJhbmNpc2NvMRYwFAYDVQQKEw1pbnN1cmFuY2Utb3JnMRwwGgYDVQQDExN0bHNj
YS5pbnN1cmFuY2Utb3JnMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEKkTdw/ia
IeHM/f4dzB0uGmhUCjo5uZxd7fpPHILRaWMwXh5BcxeNxNrwdBuvAJcrepiV+Pc+
eqv3RGF8u94j4aNfMF0wDgYDVR0PAQH/BAQDAgGmMA8GA1UdJQQIMAYGBFUdJQAw
DwYDVR0TAQH/BAUwAwEB/zApBgNVHQ4EIgQg/mEaDOLy9r1iJSKdGDX9x5iS+TcR
8gdgpr+RqxCfVVkwCgYIKoZIzj0EAwIDRwAwRAIgHR4M8sO20GazpTz9/MXDap4h
OVBMLCrP3M5fxLaykb0CIG8Vp1QszEvT1O5euZhsZoS5CcNLoFwbXT+ZuOlhUoV6
-----END CERTIFICATE-----

当我s_client跑上主持人机器:

$ openssl s_client -CAfile ./ca.crt -connect localhost:7051 -servername insurance-peer

它返回

 SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-ECDSA-AES256-GCM-SHA384
    Session-ID:
    Session-ID-ctx:
    Master-Key: 94B93D75B297584B53E87ADA0968F2B3B9121F1CAA048212642195E299F6BEA24E482E19E35F5FF18D596E138955EEBF
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1571897582
    Timeout   : 7200 (sec)
    Verify return code: 26 (unsupported certificate purpose)
    Extended master secret: no

请注意返回代码是26 (unsupported certificate purpose)

当我s_client跑上码头工人容器

$ openssl s_client -connect insurance-peer:7051 -CAfile ./ca.crt

它返回:

SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-ECDSA-AES256-GCM-SHA384
    Session-ID:
    Session-ID-ctx:
    Master-Key:85B6CAD935415FFDCC76623E9A1B5FC1749D3B7B450B41316F581A181D29039CA092B55F25170ED8D125B7ACFBE33289
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1571897694
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)

注意这里的返回代码是0 (ok)

因此,如果是s_client主机和容器之间的连接,则会出现错误,unsupported certificate purpose而如果是容器内的连接,则正常工作。

$ openssl verify在两种环境下均可正常工作。

主持人:

$ openssl verify -CAfile ./ca.crt server.crt
server.crt: OK

码头工人:

# openssl verify -CAfile ./ca.crt server.crt
server.crt: OK

OpenSSL 版本主持人机器:OpenSSL 1.1.1d 10 Sep 2019

OpenSSL 版本码头工人OpenSSL 1.0.2g 1 Mar 2016

你能帮助我这里可能存在什么问题吗?

答案1

看起来类似于此错误报告:Nginx #1760

您的 CA 密钥报告“任何扩展密钥使用情况”。自 OpenSSL 1.1.0 起,它受支持。这就是不同版本行为不同的原因。要修复此问题,我认为您需要更新 OpenSSL。

相关内容