25 EVP_PKEY *pkey =
static_cast<EVP_PKEY *
>(
keyGenerator()->makeRawKeys());
27 ::X509 * x509 =
nullptr;
28 X509_NAME * name =
nullptr;
32 ASN1_INTEGER_set(X509_get_serialNumber(x509), 1);
33 X509_gmtime_adj(X509_get_notBefore(x509), 0);
34 X509_gmtime_adj(X509_get_notAfter(x509), certificateData.
endTime);
35 X509_set_pubkey(x509, pkey);
36 name = X509_get_subject_name(x509);
39 unsigned char *C =
reinterpret_cast<unsigned char *
>(certificateData.
country.toLatin1().data());
40 X509_NAME_add_entry_by_txt(name,
"C", MBSTRING_ASC, C, -1, -1, 0);
42 unsigned char *O =
reinterpret_cast<unsigned char *
>(certificateData.
organization.toLatin1().data());
43 X509_NAME_add_entry_by_txt(name,
"O", MBSTRING_ASC, O, -1, -1, 0);
45 unsigned char *CN =
reinterpret_cast<unsigned char *
>(certificateData.
commonName.toLatin1().data());
46 X509_NAME_add_entry_by_txt(name,
"CN", MBSTRING_ASC, CN, -1, -1, 0);
48 X509_set_issuer_name(x509, name);
49 X509_sign(x509, pkey, EVP_sha256());
52 if(result.
key.isNull()) {
55 qCritical(
"Failed to generate a random private key");
60 BIO * bp_public = BIO_new(BIO_s_mem());
61 q_check_ptr(bp_public);
62 if(PEM_write_bio_X509(bp_public, x509) != 1){
64 BIO_free_all(bp_public);
65 qCritical(
"PEM_write_bio_PrivateKey");
70 if(result.
crt.isNull()) {
72 BIO_free_all(bp_public);
73 qCritical(
"Failed to generate a random client certificate");
78 BIO_free_all(bp_public);