3131# define SERIAL_RAND_BITS 159
3232
3333BIO * bio_err ;
34- #if OPENSSL_API_COMPAT >= 30101
34+ #if OPENSSL_API_COMPAT >= 30000
3535OSSL_LIB_CTX * libctx = NULL ;
3636static const char * propq = NULL ;
3737#endif
@@ -55,7 +55,11 @@ int rand_serial(BIGNUM *b, ASN1_INTEGER *ai)
5555 if (btmp == NULL )
5656 return 0 ;
5757
58+ #if OPENSSL_API_COMPAT < 10100
59+ if (!BN_rand (btmp , SERIAL_RAND_BITS , 0 , 0 ))
60+ #else
5861 if (!BN_rand (btmp , SERIAL_RAND_BITS , BN_RAND_TOP_ANY , BN_RAND_BOTTOM_ANY ))
62+ #endif
5963 goto error ;
6064 if (ai && !BN_to_ASN1_INTEGER (btmp , ai ))
6165 goto error ;
@@ -74,24 +78,32 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate,
7478 int days )
7579{
7680 if (startdate == NULL || strcmp (startdate , "today" ) == 0 ) {
81+ #if OPENSSL_API_COMPAT < 10100
82+ if (X509_gmtime_adj (X509_get_notBefore (x ), 0 ) == NULL )
83+ #else
7784 if (X509_gmtime_adj (X509_getm_notBefore (x ), 0 ) == NULL )
85+ #endif
7886 return 0 ;
7987 } else {
80- #if OPENSSL_API_COMPAT >= 10101
81- if (!ASN1_TIME_set_string_X509 ( X509_getm_notBefore (x ), startdate ))
88+ #if OPENSSL_API_COMPAT < 10101
89+ if (!ASN1_TIME_set_string ( X509_get_notBefore (x ), startdate ))
8290#else
83- if (!ASN1_TIME_set_string (X509_getm_notBefore (x ), startdate ))
91+ if (!ASN1_TIME_set_string_X509 (X509_getm_notBefore (x ), startdate ))
8492#endif
8593 return 0 ;
8694 }
8795 if (enddate == NULL ) {
96+ #if OPENSSL_API_COMPAT < 10100
97+ if (X509_time_adj_ex (X509_get_notAfter (x ), days , 0 , NULL )
98+ #else
8899 if (X509_time_adj_ex (X509_getm_notAfter (x ), days , 0 , NULL )
100+ #endif
89101 == NULL )
90102 return 0 ;
91- #if OPENSSL_API_COMPAT >= 10101
92- } else if (!ASN1_TIME_set_string_X509 ( X509_getm_notAfter (x ), enddate )) {
103+ #if OPENSSL_API_COMPAT < 10101
104+ } else if (!ASN1_TIME_set_string ( X509_get_notAfter (x ), enddate )) {
93105#else
94- } else if (!ASN1_TIME_set_string (X509_getm_notAfter (x ), enddate )) {
106+ } else if (!ASN1_TIME_set_string_X509 (X509_getm_notAfter (x ), enddate )) {
95107#endif
96108 return 0 ;
97109 }
@@ -140,7 +152,7 @@ int cert_matches_key(const X509 *cert, const EVP_PKEY *pkey)
140152 int match ;
141153
142154 ERR_set_mark ();
143- match = X509_check_private_key (cert , pkey );
155+ match = X509_check_private_key (( X509 * ) cert , ( EVP_PKEY * ) pkey );
144156 ERR_pop_to_mark ();
145157 return match ;
146158}
@@ -175,7 +187,7 @@ int do_X509_REQ_verify(X509_REQ *x, EVP_PKEY *pkey, STACK_OF(OPENSSL_STRING) *vf
175187 int rv = 0 ;
176188
177189 if (do_x509_req_init (x , vfyopts ) > 0 ){
178- #if OPENSSL_API_COMPAT >= 30101
190+ #if OPENSSL_API_COMPAT >= 30000
179191 rv = X509_REQ_verify_ex (x , pkey , libctx , propq );
180192#else
181193 rv = X509_REQ_verify (x , pkey );
@@ -449,7 +461,7 @@ IV set_digest(self, SV* digest)
449461#endif
450462 if (digest != NULL ) {
451463 digestname = (const char * ) SvPV (digest , digestname_length );
452- //printf("Digest Name: %s\n", digestname);
464+ // printf("Digest Name: %s\n", digestname);
453465 md = (EVP_MD * )EVP_get_digestbyname (digestname );
454466 }
455467
@@ -458,7 +470,9 @@ IV set_digest(self, SV* digest)
458470 RETVAL = 0 ;
459471 else
460472 RETVAL = 1 ;
461- }
473+ } else {
474+ //printf("Can't change digets to %s\n", digestname);
475+ }
462476
463477 OUTPUT :
464478
@@ -617,13 +631,19 @@ SV * sign(self, request_SV, sigopts)
617631 // Verify the CSR is properly signed
618632 EVP_PKEY * pkey ;
619633 if (csr != NULL ) {
634+ #if OPENSSL_API_COMPAT < 10100
635+ pkey = X509_REQ_get_pubkey (csr );
636+ #else
620637 pkey = X509_REQ_get0_pubkey (csr );
638+ #endif
639+ if (pkey == NULL )
640+ croak ("Warning: unable to get public key from CSR\n" );
621641
622642 int ret = do_X509_REQ_verify (csr , pkey , NULL );
623- if (pkey == NULL || ret < 0 )
624- croak ("Warning: error while verifying CSR self-signature\n" );
625643 if (ret == 0 )
626644 croak ("Verification of CSR failed\n" );
645+ if ( ret < 0 )
646+ croak ("Warning: error while verifying CSR self-signature\n" );
627647 }
628648 else
629649 croak ("Unable to properly parse the Certificate Signing Request\n" );
@@ -647,7 +667,11 @@ SV * sign(self, request_SV, sigopts)
647667 croak ("X509_set_subject_name cannot set subject name\n" );
648668
649669 // Update the certificate with the CSR's public key
670+ #if OPENSSL_API_COMPAT < 10100
671+ if (!X509_set_pubkey (x , X509_REQ_get_pubkey (csr )))
672+ #else
650673 if (!X509_set_pubkey (x , X509_REQ_get0_pubkey (csr )))
674+ #endif
651675 croak ("X509_set_pubkey cannot set public key\n" );
652676
653677 // FIXME need to look at this
@@ -688,8 +712,10 @@ SV * sign(self, request_SV, sigopts)
688712 X509V3_set_ctx (& ext_ctx , issuer_cert , x , NULL , NULL , X509V3_CTX_REPLACE );
689713 if (!X509V3_set_issuer_pkey (& ext_ctx , private_key ))
690714 croak ("X509V3_set_issuer_pkey cannot set issuer private key\n" );
691- #else
715+ #elseif OPENSSL_API_COMPAT >=10010
692716 X509V3_set_ctx (& ext_ctx , issuer_cert , x , csr , NULL , X509V3_CTX_REPLACE );
717+ #else
718+ X509V3_set_ctx (& ext_ctx , issuer_cert , x , csr , NULL , 0 );
693719#endif
694720
695721 // Set the X509 version of the certificate
@@ -712,12 +738,17 @@ SV * sign(self, request_SV, sigopts)
712738 }
713739 if (md != NULL )
714740 digestname = (const char * ) digestname ;
715- else
716- digestname = NULL ;
717-
741+ else {
742+ digestname = NULL ;
743+ printf ("Failed to set the digest md = Null\n" );
744+ }
718745 //printf ("DIGEST NAME = %s\n", digestname);
719746 // Allocate and a new digest context for certificate signing
747+ #if OPENSSL_API_COMPAT >= 10100
720748 mctx = EVP_MD_CTX_new ();
749+ #else
750+ mctx = EVP_MD_CTX_create ();
751+ #endif
721752
722753 // Sign the new certificate
723754#if OPENSSL_API_COMPAT >= 30101
0 commit comments