OpenSSL client not sending client certificate

后端 未结 3 1818
孤城傲影
孤城傲影 2021-01-04 22:31

I am struggling with a client certificate problem and hope somebody here can help me. I\'m developing a client/server pair using boost asio but I\'ll try to be unspecific. I

相关标签:
3条回答
  • 2021-01-04 22:45

    All right, after much suffering, the answer has been found by Dave Thompson of OpenSSL.

    The reason was that my ssl code called all those functions on the OpenSSL context after the socket object (SSL*) was created from it. Which means all those functions did practically nothing or the wrong thing.

    All I had to do was either:

    1. Call SSL_use_certificate_file

    res = SSL_use_certificate_file(ssl, "testclient.crt", SSL_FILETYPE_PEM);
    if (res <= 0) {
        // handle error
    }
    res = SSL_use_PrivateKey_file(ssl, "testclient.key", SSL_FILETYPE_PEM);
    if (res <= 0) {
        // handle error
    }
    

    (notice the missing CTX)

    2. Call the CTX functions

    Call the CTX functions upon the context before the socket was created. As asio seemingly encourages to create the context and socket right afterwards (as I did in the initializer list) the calls were all but useless.

    The SSL context (in lib OpenSSL or asio alike) encapsulates the SSL usage and each socket created from it will share it's properties.

    Thank you guys for your suggestions.

    0 讨论(0)
  • 2021-01-04 22:45

    I think you need to call SSL_CTX_set_client_CA_list on the server side. This sets a list of certificate authorities to be sent together with the client certificate request.

    The client will not send its certificate, even if one was requested, if the certificate does not match that CA list sent by the server.

    0 讨论(0)
  • 2021-01-04 23:05

    You should not use both SSL_CTX_use_certificate_chain_file() and SSL_CTX_use_certificate_file(), as SSL_CTX_use_certificate_chain_file() tries to load a chain including the client certificate, not just the CA chain. From SSL_CTX_use_certificate(3):

    SSL_CTX_use_certificate_chain_file() loads a certificate chain from file into ctx. The certificates must be in PEM format and must be sorted starting with the subject's certificate (actual client or server certificate), followed by intermediate CA certificates if applicable, and ending at the highest level (root) CA.

    I think you should be fine using only SSL_CTX_use_certificate_file() and SSL_CTX_use_PrivateKey_file(), as the client does not care much for the CA chain anyway.

    0 讨论(0)
提交回复
热议问题