简体   繁体   English

MariaDB SSL 使用自签名客户端证书和letsencrypt签名服务器证书

[英]MariaDB SSL using self signed client cert with letsencrypt signed server cert

How can I use self signed certs for encrypting client communications with MariaDB when the server side certificates are done via letsencrypt?当服务器端证书通过letsencrypt完成时,如何使用自签名证书加密客户端与MariaDB的通信?

Most tutorials I've found, like https://www.cyberciti.biz/faq/how-to-setup-mariadb-ssl-and-secure-connections-from-clients/ , show you how to setup both server and client side certificates as self signed, sharing the same CA (Certificate Authority) certificate.我发现的大多数教程,例如https://www.cyberciti.biz/faq/how-to-setup-mariadb-ssl-and-secure-connections-from-clients/ ,向您展示了如何设置服务器和客户端侧证书作为自签名,共享相同的 CA(证书颁发机构)证书。 This way works as expected, and when I connect to the DB via the command line it works with client side encryption.这种方式按预期工作,当我通过命令行连接到数据库时,它与客户端加密一起工作。

/etc/my.cnf: /etc/my.cnf:

[mariadb]
ssl_cert=/certs/server-cert.pem
ssl_key=/certs/server-key.pem
ssl_ca=/certs/ca-cert.pem

/etc/mysql/mariadb.conf.d/50-mysql-clients.cnf: /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf:

[mysql]
ssl-ca=/certs/ca-cert.pem
ssl-cert=/certs/client-cert.pem
ssl-key=/certs/client-key.pem

With this configuration this command works: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-cert=/certs/client-cert.pem --ssl-key=/certs/client-key.pem --ssl-ca=/certs/ca-cert.pem --ssl-verify-server-cert使用此配置,此命令有效: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-cert=/certs/client-cert.pem --ssl-key=/certs/client-key.pem --ssl-ca=/certs/ca-cert.pem --ssl-verify-server-cert

Note that I generated ca-cert.pem myself and used it to sign both the server and client certs, and that these certs verified correctly and after logging in and checking the servers status it indicates that SSL is being used.请注意,我自己生成了ca-cert.pem并使用它来签署服务器和客户端证书,并且这些证书已正确验证,在登录并检查服务器状态后,它表明正在使用 SSL。

This setup worked fine during development, but now my database is in production and I want to use letsencrypt certificates in my services.此设置在开发过程中运行良好,但现在我的数据库正在生产中,我想在我的服务中使用letsencrypt 证书。 If I replace the server side certificates in my /etc/my.cnf file with the ones that letsencrypt gives me like so:如果我将 /etc/my.cnf 文件中的服务器端证书替换为 letencrypt 给我的证书,如下所示:

/etc/my.cnf: /etc/my.cnf:

[mariadb]
ssl_cert=/certs/cert.pem
ssl_key=/certs/privkey.pem
ssl_ca=/certs/chain.pem

but leave the 50-mysql-clients.cnf file with the self signed client certs as is, it no longer lets me log in using the certs.但是保留带有自签名客户端证书的 50-mysql-clients.cnf 文件,它不再让我使用证书登录。 If i no longer try and use the client certs it still lets me log in using SSL, and a status check indicates that it is still using ssl, but the documentation says that this way the client packets aren't encrypted, only the servers.如果我不再尝试使用客户端证书,它仍然允许我使用 SSL 登录,并且状态检查表明它仍在使用 ssl,但文档说这样客户端数据包不会加密,只有服务器。

Command that works: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-verify-server-cert有效的命令: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-verify-server-cert

Command from before that no longer works: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-cert=/certs/client-cert.pem --ssl-key=/certs/client-key.pem --ssl-ca=/certs/ca-cert.pem --ssl-verify-server-cert之前的命令不再起作用: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-cert=/certs/client-cert.pem --ssl-key=/certs/client-key.pem --ssl-ca=/certs/ca-cert.pem --ssl-verify-server-cert

Error Message: ERROR 2026 (HY000): SSL connection error: unable to get local issuer certificate错误信息: ERROR 2026 (HY000): SSL connection error: unable to get local issuer certificate

Using the server certs letsencrypt generates in the command also doesn't work: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-ca=/certs/chain.pem --ssl-cert=/certs/cert.pem --ssl-key=/certs/privkey.pem --ssl-verify-server-cert在命令中使用letsencrypt生成的服务器证书也不起作用: mysql -u root -p -h mysite.com --port=3310 --protocol=TCP --ssl-ca=/certs/chain.pem --ssl-cert=/certs/cert.pem --ssl-key=/certs/privkey.pem --ssl-verify-server-cert

Error Message: ERROR 2026 (HY000): SSL connection error: unable to get issuer certificate错误信息: ERROR 2026 (HY000): SSL connection error: unable to get issuer certificate

status check:状态检查:

MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 10.5.8-MariaDB, for osx10.15 (x86_64) using readline 5.1

Connection id:      4
Current database:
Current user:       root@myipaddress
SSL:            Cipher in use is TLS_AES_256_GCM_SHA384
Current pager:      less
Using outfile:      ''
Using delimiter:    ;
Server:         MariaDB
Server version:     10.5.4-MariaDB-1:10.5.4+maria~focal mariadb.org binary distribution
Protocol version:   10
Connection:     mysite.com via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8
Conn.  characterset:    utf8
TCP port:       3310
Uptime:         3 min 33 sec

How can I still do 2 way ssl encryption with both client and server when using letsencrypt certificates with MariaDB?将letsencrypt证书与MariaDB一起使用时,我如何仍然使用客户端和服务器进行2路ssl加密?

Too long for a comment..评论太长了。。

  1. One way TLS means, that the server sends his certificate to the client, and the client verifies it. TLS 的一种方式意味着,服务器将其证书发送给客户端,然后客户端对其进行验证。 Two way TLS means, that the client sends also his certificate to the server and the server verifies the client certificate.两种方式的 TLS 意味着,客户端也将他的证书发送到服务器,服务器验证客户端证书。 Latter one happens only, if the REQUIRE X509, REQUIRE SUBJECT, and/or REQUIRE ISSUER clauses are specified for the account.仅当为帐户指定了 REQUIRE X509、REQUIRE SUBJECT 和/或 REQUIRE ISSUER 子句时,才会发生后一种情况。 If no REQUIRE was specified, you don't have to specify a client certificate.如果未指定 REQUIRE,则不必指定客户端证书。

  2. Regardless of one or two way a TLS connection always sends encrypted data in both directions (unless OpenSSL was built with NONE cipher support and client specified NONE cipher).无论采用一种或两种方式,TLS 连接总是在两个方向上发送加密数据(除非 OpenSSL 是使用 NONE 密码支持和客户端指定的 NONE 密码构建的)。

  3. Error message: "unable to get local issuer certificate" means that something in the root certificate chain is missing.错误消息:“无法获取本地颁发者证书”表示根证书链中的某些内容丢失。 If it's not a self signed certificate, you should verify it with system ca (without specifying ssl-ca or ssl-ca-path) or add the server certificate to your ca file.如果它不是自签名证书,您应该使用系统 ca 验证它(不指定 ssl-ca 或 ssl-ca-path)或将服务器证书添加到您的 ca 文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM