mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
Reload certificate chain during certificate reload
This commit is contained in:
parent
d4063e378e
commit
6b50f5bf10
@ -30,8 +30,22 @@ int CertificateReloader::setCertificate(SSL * ssl)
|
||||
if (!current)
|
||||
return -1;
|
||||
|
||||
SSL_use_certificate(ssl, const_cast<X509 *>(current->cert.certificate()));
|
||||
SSL_use_PrivateKey(ssl, const_cast<EVP_PKEY *>(static_cast<const EVP_PKEY *>(current->key)));
|
||||
if (current->certs_chain.size() < 1)
|
||||
return -1;
|
||||
|
||||
int ret;
|
||||
ret = SSL_clear_chain_certs(ssl);
|
||||
if (!ret)
|
||||
return ret;
|
||||
ret = SSL_use_certificate(ssl, const_cast<X509 *>(current->certs_chain[0].certificate()));
|
||||
if (!ret)
|
||||
return ret;
|
||||
for (auto cert = current->certs_chain.begin() + 1; cert != current->certs_chain.end(); cert++) {
|
||||
ret = SSL_add1_chain_cert(ssl, const_cast<X509 *>(cert->certificate()));
|
||||
if (!ret)
|
||||
return ret;
|
||||
}
|
||||
ret = SSL_use_PrivateKey(ssl, const_cast<EVP_PKEY *>(static_cast<const EVP_PKEY *>(current->key)));
|
||||
|
||||
int err = SSL_check_private_key(ssl);
|
||||
if (err != 1)
|
||||
@ -100,7 +114,7 @@ void CertificateReloader::tryLoad(const Poco::Util::AbstractConfiguration & conf
|
||||
|
||||
|
||||
CertificateReloader::Data::Data(std::string cert_path, std::string key_path, std::string pass_phrase)
|
||||
: cert(cert_path), key(/* public key */ "", /* private key */ key_path, pass_phrase)
|
||||
: certs_chain(Poco::Crypto::X509Certificate::readPEM(cert_path)), key(/* public key */ "", /* private key */ key_path, pass_phrase)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ private:
|
||||
|
||||
struct Data
|
||||
{
|
||||
Poco::Crypto::X509Certificate cert;
|
||||
Poco::Crypto::X509Certificate::List certs_chain;
|
||||
Poco::Crypto::EVPPKey key;
|
||||
|
||||
Data(std::string cert_path, std::string key_path, std::string pass_phrase);
|
||||
|
@ -0,0 +1,43 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDkzCCAnugAwIBAgIUSChEeHqJus9jzKmD/L3Tw0x4OwcwDQYJKoZIhvcNAQEL
|
||||
BQAwQTEaMBgGA1UEAwwRZGVtby5tbG9wc2h1Yi5jb20xCzAJBgNVBAYTAlVTMRYw
|
||||
FAYDVQQHDA1TYW4gRnJhbnNpc2NvMCAXDTI0MDMyMDE5MTE1OVoYDzIxMjQwMjI1
|
||||
MTkxMTU5WjBxMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQG
|
||||
A1UEBwwNU2FuIEZyYW5zaXNjbzEPMA0GA1UECgwGRm9vQmFyMRAwDgYDVQQLDAdG
|
||||
b28gQmFyMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
|
||||
DwAwggEKAoIBAQDM//0s6AX988J86HzxX95irGa9cJIfY24UDBXVkO3gREiwj1Uf
|
||||
bpvpxCcwADMuFdggsJlppWa3q+PNJ/eoVwdl3gG0WXaZp1rcuv6ltxdQAUtgfMAb
|
||||
5p7HwsO7rCTGJBwa62Jg+E79j+V8rZWfaJRfNtY0p7eauWIrqLA0Gyse+lRayPHI
|
||||
hsR9+0qedF+qziFpbNxpW8DHrpIrLb8LEao1BCYQ44koBXjkrXeR6OidXw/gek8+
|
||||
9M2GLxy6ubQ7hrcYwVWpFOKLLZLmyYDgescM6AIU904o1bN0yJ5rM7a1+f150qp6
|
||||
ttZlya0sJH0lm3gzEsqb6Fbh+Dw/9Lsp66sDAgMBAAGjUTBPMB8GA1UdIwQYMBaA
|
||||
FMjyDUyXujACeQa2G+4I8ic5HVBiMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgTwMBQG
|
||||
A1UdEQQNMAuCCWxvY2FsaG9zdDANBgkqhkiG9w0BAQsFAAOCAQEABEWEaVDqv9Za
|
||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RCwBfnyxq
|
||||
sbct/Y2TGXpXmjwt8JcKZkVJcuBPTXOl6cwA7FHAdkR0/hMJUNzS608PZCtAqj4d
|
||||
kANtp3MCgYEA3plv6RYYDZsUdJmIcdIvr/LxWTSqYf37LQM//k+OXo+zWMxgnUNv
|
||||
AEqDlNWP+bw3yJlU1bQS2o1Z+hKzDgqDZtaVVVDgdVsUaDSW0EsJpedWXoGqJdrw
|
||||
yxhB7RYi1tQsXHbR1iyT5hH0ZlV7s0XIKRU4U8MP05av099+++YKhks=
|
||||
-----END RSA PRIVATE KEY-----
|
@ -13,6 +13,8 @@ node = cluster.add_instance(
|
||||
"configs/second.key",
|
||||
"configs/ECcert.crt",
|
||||
"configs/ECcert.key",
|
||||
"configs/WithChain.crt",
|
||||
"configs/WithChain.key",
|
||||
"configs/WithPassPhrase.crt",
|
||||
"configs/WithPassPhrase.key",
|
||||
"configs/cert.xml",
|
||||
@ -158,3 +160,16 @@ def test_cert_with_pass_phrase():
|
||||
check_certificate_switch(
|
||||
"first", "WithPassPhrase", pass_phrase_second=pass_phrase_for_cert
|
||||
)
|
||||
|
||||
|
||||
def test_chain_reload():
|
||||
"""Check cert chain reload"""
|
||||
check_certificate_switch("first", "WithChain")
|
||||
assert (
|
||||
node.exec_in_container([
|
||||
"bash",
|
||||
"-c",
|
||||
"openssl s_client -showcerts -servername localhost -connect localhost:8443 </dev/null 2>/dev/null | grep 'BEGIN CERTIFICATE' | wc -l",
|
||||
])
|
||||
== "2\n"
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user