21 #include <ksslcertificatefactory.h>
22 #include <ksslcertificate.h>
28 KSSLCertificateFactory::generateSelfSigned(KSSLKeyType ) {
31 X509_NAME *x509name = X509_NAME_new();
33 ASN1_UTCTIME *beforeafter;
38 if (keytype == KEYTYPE_UNKNOWN || (key=EVP_PKEY_new()) == NULL) {
39 X509_NAME_free(x509name);
45 if (!EVP_PKEY_assign_RSA(key, RSA_generate_key(newkey,0x10001,
51 if (!DSA_generate_key(dsa_params))
goto end;
52 if (!EVP_PKEY_assign_DSA(pkey,dsa_params))
goto end;
54 if (pkey->type == EVP_PKEY_DSA)
64 X509_NAME_add_entry_by_NID(x509name, OBJ_txt2nid(
"CN"), 0x1001,
65 (
unsigned char *) dn, -1, -1, 0);
68 rc = X509_set_issuer_name(x509, x509name);
71 X509_NAME_free(x509name);
74 rc = X509_set_subject_name(x509, x509name);
77 X509_NAME_free(x509name);
80 ASN1_INTEGER_set(X509_get_serialNumber(*x509), 0);
82 X509_NAME_free(x509name);
85 beforeafter = ASN1_UTCTIME_new();
86 if (!X509_gmtime_adj(beforeafter, -60*60*24)) {
90 if (!X509_set_notBefore(x509, beforeafter)) {
94 if (!X509_gmtime_adj(beforeafter, 60*60*24*364)) {
98 if (!X509_set_notAfter(x509, beforeafter)) {
102 ASN1_UTCTIME_free(beforeafter);
104 if (!X509_set_pubkey(x509, key)) {
109 rc = X509_sign(x509, key, EVP_sha1());
bool setCert(TQString &cert)
Re-set the certificate from a base64 string.