diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2017-05-07 22:48:33 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2017-05-07 22:48:33 +0300 |
commit | 321009177486077896680745b2610a47853fbbd1 (patch) | |
tree | 59426ce2de1c9f71440f5c5c13afd7e5e0eb2bc7 /src/murmur/Cert.cpp | |
parent | e7c27873e31557998761af4542623352a6fd4524 (diff) |
selfSignedServerCert_SHA1_RSA_2048: refactor variable declarations.
The control flow is going to change in this function once we add
error handling.
Prepare for that by declaring all variables at the beginning of
the function.
Diffstat (limited to 'src/murmur/Cert.cpp')
-rw-r--r-- | src/murmur/Cert.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/murmur/Cert.cpp b/src/murmur/Cert.cpp index 1e71978e4..71a0a4382 100644 --- a/src/murmur/Cert.cpp +++ b/src/murmur/Cert.cpp @@ -26,23 +26,39 @@ static int add_ext(X509 * crt, int nid, char *value) { static bool selfSignedServerCert_SHA1_RSA_2048(QSslCertificate &qscCert, QSslKey &qskKey) { bool ok = true; + X509 *x509 = NULL; + EVP_PKEY *pkey = NULL; + RSA *rsa = NULL; + X509_NAME *name = NULL; + ASN1_INTEGER *serialNumber = NULL; + ASN1_TIME *notBefore = NULL; + ASN1_TIME *notAfter = NULL; + unsigned char *commonName = NULL; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - X509 *x509 = X509_new(); - EVP_PKEY *pkey = EVP_PKEY_new(); - RSA *rsa = RSA_generate_key(2048,RSA_F4,NULL,NULL); + x509 = X509_new(); + pkey = EVP_PKEY_new(); + rsa = RSA_generate_key(2048,RSA_F4,NULL,NULL); EVP_PKEY_assign_RSA(pkey, rsa); X509_set_version(x509, 2); - ASN1_INTEGER_set(X509_get_serialNumber(x509),1); - X509_gmtime_adj(X509_get_notBefore(x509),0); - X509_gmtime_adj(X509_get_notAfter(x509),60*60*24*365*20); + + serialNumber = X509_get_serialNumber(x509); + ASN1_INTEGER_set(serialNumber, 1); + + notBefore = X509_get_notBefore(x509); + X509_gmtime_adj(notBefore, 0); + + notAfter = X509_get_notAfter(x509); + X509_gmtime_adj(notAfter, 60*60*24*365*20); + X509_set_pubkey(x509, pkey); - X509_NAME *name=X509_get_subject_name(x509); + name = X509_get_subject_name(x509); - X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, reinterpret_cast<unsigned char *>(const_cast<char *>("Murmur Autogenerated Certificate v2")), -1, -1, 0); + commonName = reinterpret_cast<unsigned char *>(const_cast<char *>("Murmur Autogenerated Certificate v2")); + X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, commonName, -1, -1, 0); X509_set_issuer_name(x509, name); add_ext(x509, NID_basic_constraints, SSL_STRING("critical,CA:FALSE")); add_ext(x509, NID_ext_key_usage, SSL_STRING("serverAuth,clientAuth")); |