Conversation
src/base/net/tls/TlsGen.cpp: In member function 'bool
xmrig::TlsGen::generate_x509(const char*)':
src/base/net/tls/TlsGen.cpp:118:32: error: invalid conversion from
'const X509_name_st*' to 'X509_NAME*' {aka 'X509_name_st*'}
[-fpermissive]
118 | X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0);
| ^~~~
| |
| const X509_name_st*
openssl/openssl#29117
Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
|
@bkuhls instead of casting away the const have you considered using |
|
The better fix (compared to what znc did) would be |
SChernykh
left a comment
There was a problem hiding this comment.
The better fix:
auto name = X509_NAME_dup(X509_get_subject_name(cert));
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0);
X509_set_issuer_name(m_x509, name);
X509_NAME_free(name);
--- a/src/base/net/tls/TlsGen.cpp
+++ b/src/base/net/tls/TlsGen.cpp
@@ -114,10 +114,11 @@ bool xmrig::TlsGen::generate_x509(const char *commonName)
X509_gmtime_adj(X509_get_notBefore(m_x509), 0);
X509_gmtime_adj(X509_get_notAfter(m_x509), 315360000L);
- auto name = X509_get_subject_name(m_x509);
+ auto name = X509_NAME_dup(X509_get_subject_name(cert));
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0);
X509_set_issuer_name(m_x509, name);
+ X509_NAME_free(name);
return X509_sign(m_x509, m_pkey, EVP_sha256());
}Produces: |
|
Did you mean: --- a/src/base/net/tls/TlsGen.cpp
+++ b/src/base/net/tls/TlsGen.cpp
@@ -114,10 +114,11 @@ bool xmrig::TlsGen::generate_x509(const char *commonName)
X509_gmtime_adj(X509_get_notBefore(m_x509), 0);
X509_gmtime_adj(X509_get_notAfter(m_x509), 315360000L);
- auto name = X509_get_subject_name(m_x509);
+ auto name = X509_NAME_dup(X509_get_subject_name(m_x509));
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0);
X509_set_issuer_name(m_x509, name);
+ X509_NAME_free(name);
return X509_sign(m_x509, m_pkey, EVP_sha256());
} |
|
Yes, it's |
| auto name = X509_get_subject_name(m_x509); | ||
| X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0); | ||
| X509_NAME_add_entry_by_txt((X509_NAME *) name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0); | ||
|
|
||
| X509_set_issuer_name(m_x509, name); | ||
|
|
There was a problem hiding this comment.
The recommended fix is to allocate a new X509_NAME then to assign it to both the subject and issuer of the certificate (since duplication does not use the original subject name):
auto name = X509_NAME_new();
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<const uint8_t *>(commonName), -1, -1, 0);
X509_set_subject_name(m_x509, name);
X509_set_issuer_name(m_x509, name);
X509_NAME_free(name);
openssl/openssl#29117