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_PASS (1 << 2 ) /* Can use CERTIDENT (verify private key password) */
67+ #define UPSCLI_SSL_CAPS_CERTIDENT_NAME (1 << 3 ) /* Can use CERTIDENT (verify cert name) */
68+ #define UPSCLI_SSL_CAPS_CERTIDENT (UPSCLI_SSL_CAPS_CERTIDENT_PASS | UPSCLI_SSL_CAPS_CERTIDENT_NAME)
6669
6770
6871namespace nut
@@ -109,22 +112,25 @@ class SSLConfig_OpenSSL : public SSLConfig
109112 SSLConfig_OpenSSL (bool force_ssl = false , int certverify = -1 ,
110113 const std::string& ca_path = " " , const std::string& ca_file = " " ,
111114 const std::string& cert_file = " " , const std::string& key_file = " " ,
112- const std::string& key_pass = " " )
115+ const std::string& key_pass = " " , const std::string& certident_name = " " )
113116 : 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) {}
117+ _cert_file (cert_file), _key_file(key_file), _key_pass(key_pass),
118+ _certident_name(certident_name) {}
115119
116120 SSLConfig_OpenSSL (bool force_ssl, int certverify,
117121 const char *ca_path, const char *ca_file,
118122 const char *cert_file, const char *key_file,
119- const char *key_pass)
123+ const char *key_pass, const char *certident_name = nullptr )
120124 : 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) {}
125+ _cert_file(cert_file), _key_file(key_file), _key_pass(key_pass),
126+ _certident_name(certident_name) {}
122127
123128 const std::string& getCAPath () const { return _ca_path; }
124129 const std::string& getCAFile () const { return _ca_file; }
125130 const std::string& getCertFile () const { return _cert_file; }
126131 const std::string& getKeyFile () const { return _key_file; }
127132 const std::string& getKeyPass () const { return _key_pass; }
133+ const std::string& getCertIdentName () const { return _certident_name; }
128134
129135 virtual void apply (TcpClient& client) const override ;
130136
@@ -134,6 +140,7 @@ class SSLConfig_OpenSSL : public SSLConfig
134140 std::string _cert_file;
135141 std::string _key_file;
136142 std::string _key_pass;
143+ std::string _certident_name;
137144};
138145
139146/* *
@@ -826,8 +833,9 @@ class TcpClient : public Client
826833 * \param cert_file Path to a client certificate file (PEM format for OpenSSL) or nickname (NSS).
827834 * \param key_file Path to a client private key file (PEM format for OpenSSL).
828835 * \param key_pass Optional passphrase to decrypt the private key.
836+ * \param certident_name Expected name in the client certificate (CN or SAN).
829837 */
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);
838+ 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 );
831839
832840 /* *
833841 * Set SSL configuration for OpenSSL.
@@ -838,8 +846,9 @@ class TcpClient : public Client
838846 * \param cert_file Path to a client certificate file (PEM format for OpenSSL) or nickname (NSS).
839847 * \param key_file Path to a client private key file (PEM format for OpenSSL).
840848 * \param key_pass Optional passphrase to decrypt the private key.
849+ * \param certident_name Expected name in the client certificate (CN or SAN).
841850 */
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);
851+ 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 = " " );
843852
844853 /* *
845854 * Set SSL configuration for Mozilla NSS
@@ -1486,11 +1495,13 @@ NUTCLIENT_TCP_t nutclient_tcp_create_client_ssl_OpenSSL(
14861495 const char * host, uint16_t port, int try_ssl,
14871496 int force_ssl, int certverify,
14881497 const char *ca_path, const char *ca_file,
1489- const char *cert_file, const char *key_file, const char *key_pass);
1498+ const char *cert_file, const char *key_file,
1499+ const char *key_pass, const char *certident_name);
14901500void nutclient_tcp_set_ssl_config_OpenSSL (NUTCLIENT_TCP_t client,
14911501 int force_ssl, int certverify,
14921502 const char *ca_path, const char *ca_file,
1493- const char *cert_file, const char *key_file, const char *key_pass);
1503+ const char *cert_file, const char *key_file,
1504+ const char *key_pass, const char *certident_name);
14941505
14951506NUTCLIENT_TCP_t nutclient_tcp_create_client_ssl_NSS (
14961507 const char * host, uint16_t port, int try_ssl,
0 commit comments