From 929e8eb5ae2953fdb5231588a9d916ae6cffa939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Josef=20=C5=A0pa=C4=8Dek?= Date: Tue, 14 Apr 2026 14:32:27 +0200 Subject: [PATCH 3/7] Fix Net::SSLeay to support opaque ASN1_STRING --- SSLeay.xs | 95 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/SSLeay.xs b/SSLeay.xs index ad996d5c1aa9..2567d81abef0 100644 --- a/SSLeay.xs +++ b/SSLeay.xs @@ -2194,35 +2194,41 @@ int ssl_ctx_set_cert_cb_invoke(SSL *ssl, void *arg) time_t ASN1_TIME_timet(ASN1_TIME *asn1t, time_t *gmtoff) { struct tm t; - const char *p = (const char*) asn1t->data; +#if (OPENSSL_VERSION_NUMBER >= 0x1010000f && !defined(LIBRESSL_VERSION_NUMBER)) || (LIBRESSL_VERSION_NUMBER >= 0x2070000fL) + const char *p = (const char*) ASN1_STRING_get0_data(asn1t); +#else + const char *p = (const char*) ASN1_STRING_data(asn1t); +#endif + int asn1t_length = ASN1_STRING_length(asn1t); + int asn1t_type = ASN1_STRING_type(asn1t); size_t msec = 0, tz = 0, i, l; time_t result; int adj = 0; - if (asn1t->type == V_ASN1_UTCTIME) { - if (asn1t->length<12 || asn1t->length>17) return 0; - if (asn1t->length>12) tz = 12; + if (asn1t_type == V_ASN1_UTCTIME) { + if (asn1t_length<12 || asn1t_length>17) return 0; + if (asn1t_length>12) tz = 12; } else { - if (asn1t->length<14) return 0; - if (asn1t->length>14) { + if (asn1t_length<14) return 0; + if (asn1t_length>14) { if (p[14] == '.') { msec = 14; - for(i=msec+1;ilength && p[i]>='0' && p[i]<='9';i++) ; - if (ilength) tz = i; + for(i=msec+1;i<(size_t)asn1t_length && p[i]>='0' && p[i]<='9';i++) ; + if (i<(size_t)asn1t_length) tz = i; } else { tz = 14; } } } - l = msec ? msec : tz ? tz : asn1t->length; + l = msec ? msec : tz ? tz : (size_t)asn1t_length; for(i=0;i'9') return 0; } /* extract data and time */ OPENSSL_cleanse(&t, sizeof(t)); - if (asn1t->type == V_ASN1_UTCTIME) { /* YY - two digit year */ + if (asn1t_type == V_ASN1_UTCTIME) { /* YY - two digit year */ t.tm_year = (p[0]-'0')*10 + (p[1]-'0'); if (t.tm_year < 70) t.tm_year += 100; i=2; @@ -2242,11 +2248,11 @@ time_t ASN1_TIME_timet(ASN1_TIME *asn1t, time_t *gmtoff) { if (tz) { /* TZ is 'Z' or [+-]DDDD and after TZ the string must stop*/ if (p[tz] == 'Z') { - if (asn1t->length>tz+1 ) return 0; - } else if (asn1t->lengthtz+1 ) return 0; + } else if ((size_t)asn1t_lengthlength>tz+5 ) return 0; + if ((size_t)asn1t_length>tz+5 ) return 0; for(i=tz+1;i'9') return 0; } @@ -4690,7 +4696,11 @@ X509_get_subjectAltNames(cert) EXTEND(SP, 2); count++; PUSHs(sv_2mortal(newSViv(subjAltNameDN->type))); - PUSHs(sv_2mortal(newSVpv((const char*)subjAltNameDN->d.ip->data, subjAltNameDN->d.ip->length))); +#if (OPENSSL_VERSION_NUMBER >= 0x1010000f && !defined(LIBRESSL_VERSION_NUMBER)) || (LIBRESSL_VERSION_NUMBER >= 0x2070000fL) + PUSHs(sv_2mortal(newSVpv((const char*)ASN1_STRING_get0_data(subjAltNameDN->d.ip), ASN1_STRING_length(subjAltNameDN->d.ip)))); +#else + PUSHs(sv_2mortal(newSVpv((const char*)ASN1_STRING_data(subjAltNameDN->d.ip), ASN1_STRING_length(subjAltNameDN->d.ip)))); +#endif break; } @@ -5229,15 +5239,20 @@ P_ASN1_TIME_get_isotime(tm) ASN1_TIME_to_generalizedtime(tm,&tmp); if (tmp) { if (ASN1_GENERALIZEDTIME_check(tmp)) { - if (strlen((char*)tmp->data)>=14 && strlen((char*)tmp->data)<200) { +#if (OPENSSL_VERSION_NUMBER >= 0x1010000f && !defined(LIBRESSL_VERSION_NUMBER)) || (LIBRESSL_VERSION_NUMBER >= 0x2070000fL) + const char *tmp_data = (const char*)ASN1_STRING_get0_data(tmp); +#else + const char *tmp_data = (const char*)ASN1_STRING_data(tmp); +#endif + if (strlen(tmp_data)>=14 && strlen(tmp_data)<200) { strcpy (buf,"yyyy-mm-ddThh:mm:ss"); - strncpy(buf, (char*)tmp->data, 4); - strncpy(buf+5, (char*)tmp->data+4, 2); - strncpy(buf+8, (char*)tmp->data+6, 2); - strncpy(buf+11,(char*)tmp->data+8, 2); - strncpy(buf+14,(char*)tmp->data+10,2); - strncpy(buf+17,(char*)tmp->data+12,2); - if (strlen((char*)tmp->data)>14) strcat(buf+19,(char*)tmp->data+14); + strncpy(buf, tmp_data, 4); + strncpy(buf+5, tmp_data+4, 2); + strncpy(buf+8, tmp_data+6, 2); + strncpy(buf+11,tmp_data+8, 2); + strncpy(buf+14,tmp_data+10,2); + strncpy(buf+17,tmp_data+12,2); + if (strlen(tmp_data)>14) strcat(buf+19,tmp_data+14); } } ASN1_GENERALIZEDTIME_free(tmp); @@ -5250,7 +5265,6 @@ P_ASN1_TIME_set_isotime(tm,str) ASN1_TIME *tm const char *str PREINIT: - ASN1_TIME t; char buf[256]; int i,rv; CODE: @@ -5272,22 +5286,27 @@ P_ASN1_TIME_set_isotime(tm,str) buf[14] = '\0'; if (strlen(str)>19 && strlen(str)<200) strcat(buf,str+19); - /* WORKAROUND: ASN1_TIME_set_string() not available in 0.9.8 !!!*/ - /* in 1.0.0 we would simply: rv = ASN1_TIME_set_string(tm,buf); */ - t.length = strlen(buf); - t.data = (unsigned char *)buf; - t.flags = 0; - t.type = V_ASN1_UTCTIME; - if (!ASN1_TIME_check(&t)) { - t.type = V_ASN1_GENERALIZEDTIME; - if (!ASN1_TIME_check(&t)) XSRETURN_UNDEF; + /* ASN1_TIME_set_string() not available in 0.9.8 */ +#if OPENSSL_VERSION_NUMBER >= 0x10000000L + rv = ASN1_TIME_set_string(tm, buf); + if (!rv) XSRETURN_UNDEF; +#else + { + ASN1_TIME t; + t.length = strlen(buf); + t.data = (unsigned char *)buf; + t.flags = 0; + t.type = V_ASN1_UTCTIME; + if (!ASN1_TIME_check(&t)) { + t.type = V_ASN1_GENERALIZEDTIME; + if (!ASN1_TIME_check(&t)) XSRETURN_UNDEF; + } + tm->type = t.type; + tm->flags = t.flags; + if (!ASN1_STRING_set(tm,t.data,t.length)) XSRETURN_UNDEF; + rv = 1; } - tm->type = t.type; - tm->flags = t.flags; - if (!ASN1_STRING_set(tm,t.data,t.length)) XSRETURN_UNDEF; - rv = 1; - - /* end of ASN1_TIME_set_string() reimplementation */ +#endif ST(0) = sv_newmortal(); sv_setiv(ST(0), rv); /* 1 = success, undef = failure */ -- 2.55.0