6161#endif
6262
6363#define UPSCLI_SSL_CAPS_NONE 0 /* No ability to use SSL */
64- #define UPSCLI_SSL_CAPS_OPENSSL 1 /* Can use OpenSSL-specific setup */
65- #define UPSCLI_SSL_CAPS_NSS 2 /* Can use Mozilla NSS-specific setup */
64+ #define UPSCLI_SSL_CAPS_OPENSSL (1 << 0 ) /* Can use OpenSSL-specific setup */
65+ #define UPSCLI_SSL_CAPS_NSS (1 << 1 ) /* Can use Mozilla NSS-specific setup */
66+ #define UPSCLI_SSL_CAPS_CERTIDENT (1 << 2 ) /* Can use CERTIDENT (verify cert */
67+ /* name, private key password) */
6668
6769
6870namespace nut
@@ -109,22 +111,25 @@ class SSLConfig_OpenSSL : public SSLConfig
109111 SSLConfig_OpenSSL (bool force_ssl = false , int certverify = -1 ,
110112 const std::string& ca_path = " " , const std::string& ca_file = " " ,
111113 const std::string& cert_file = " " , const std::string& key_file = " " ,
112- const std::string& key_pass = " " )
114+ const std::string& key_pass = " " , const std::string& certident_name = " " )
113115 : SSLConfig(force_ssl, certverify), _ca_path(ca_path), _ca_file(ca_file),
114- _cert_file (cert_file), _key_file(key_file), _key_pass(key_pass) {}
116+ _cert_file (cert_file), _key_file(key_file), _key_pass(key_pass),
117+ _certident_name(certident_name) {}
115118
116119 SSLConfig_OpenSSL (bool force_ssl, int certverify,
117120 const char *ca_path, const char *ca_file,
118121 const char *cert_file, const char *key_file,
119- const char *key_pass)
122+ const char *key_pass, const char *certident_name = nullptr )
120123 : SSLConfig(force_ssl, certverify), _ca_path(ca_path), _ca_file(ca_file),
121- _cert_file(cert_file), _key_file(key_file), _key_pass(key_pass) {}
124+ _cert_file(cert_file), _key_file(key_file), _key_pass(key_pass),
125+ _certident_name(certident_name) {}
122126
123127 const std::string& getCAPath () const { return _ca_path; }
124128 const std::string& getCAFile () const { return _ca_file; }
125129 const std::string& getCertFile () const { return _cert_file; }
126130 const std::string& getKeyFile () const { return _key_file; }
127131 const std::string& getKeyPass () const { return _key_pass; }
132+ const std::string& getCertIdentName () const { return _certident_name; }
128133
129134 virtual void apply (TcpClient& client) const override ;
130135
@@ -134,6 +139,7 @@ class SSLConfig_OpenSSL : public SSLConfig
134139 std::string _cert_file;
135140 std::string _key_file;
136141 std::string _key_pass;
142+ std::string _certident_name;
137143};
138144
139145/* *
@@ -826,8 +832,9 @@ class TcpClient : public Client
826832 * \param cert_file Path to a client certificate file (PEM format for OpenSSL) or nickname (NSS).
827833 * \param key_file Path to a client private key file (PEM format for OpenSSL).
828834 * \param key_pass Optional passphrase to decrypt the private key.
835+ * \param certident_name Expected name in the client certificate (CN or SAN).
829836 */
830- void setSSLConfig_OpenSSL (bool force_ssl, int certverify, const char *ca_path, const char *ca_file, const char *cert_file, const char *key_file, const char *key_pass);
837+ void setSSLConfig_OpenSSL (bool force_ssl, int certverify, const char *ca_path, const char *ca_file, const char *cert_file, const char *key_file, const char *key_pass, const char *certident_name = nullptr );
831838
832839 /* *
833840 * Set SSL configuration for OpenSSL.
@@ -838,8 +845,9 @@ class TcpClient : public Client
838845 * \param cert_file Path to a client certificate file (PEM format for OpenSSL) or nickname (NSS).
839846 * \param key_file Path to a client private key file (PEM format for OpenSSL).
840847 * \param key_pass Optional passphrase to decrypt the private key.
848+ * \param certident_name Expected name in the client certificate (CN or SAN).
841849 */
842- void setSSLConfig_OpenSSL (bool force_ssl, int certverify, const std::string& ca_path, const std::string& ca_file, const std::string& cert_file, const std::string& key_file, const std::string& key_pass);
850+ void setSSLConfig_OpenSSL (bool force_ssl, int certverify, const std::string& ca_path, const std::string& ca_file, const std::string& cert_file, const std::string& key_file, const std::string& key_pass, const std::string& certident_name = " " );
843851
844852 /* *
845853 * Set SSL configuration for Mozilla NSS
@@ -1486,11 +1494,13 @@ NUTCLIENT_TCP_t nutclient_tcp_create_client_ssl_OpenSSL(
14861494 const char * host, uint16_t port, int try_ssl,
14871495 int force_ssl, int certverify,
14881496 const char *ca_path, const char *ca_file,
1489- const char *cert_file, const char *key_file, const char *key_pass);
1497+ const char *cert_file, const char *key_file,
1498+ const char *key_pass, const char *certident_name);
14901499void nutclient_tcp_set_ssl_config_OpenSSL (NUTCLIENT_TCP_t client,
14911500 int force_ssl, int certverify,
14921501 const char *ca_path, const char *ca_file,
1493- const char *cert_file, const char *key_file, const char *key_pass);
1502+ const char *cert_file, const char *key_file,
1503+ const char *key_pass, const char *certident_name);
14941504
14951505NUTCLIENT_TCP_t nutclient_tcp_create_client_ssl_NSS (
14961506 const char * host, uint16_t port, int try_ssl,
0 commit comments