Skip Menu |

This queue is for tickets about the Net-SSLeay CPAN distribution.

Report information
The Basics
Id: 74556
Status: resolved
Priority: 0/
Queue: Net-SSLeay

People
Owner: MIKEM [...] cpan.org
Requestors: kmx [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: P_ASN1_UTCTIME_put2string fails to print dates out of 1950-2049
The reason is that Net::SSLeay::P_ASN1_UTCTIME_put2string() uses openssl function ASN1_UTCTIME_print which is able to operate only on ASN1_UTCTIME type limited to 1959-2049

My proposal is to introduce a new function based on ASN1_TIME_print (which handles both ASN1_UTCTIME + ASN1_GENERALIZEDTIME):

void
P_ASN1_TIME_put2string(tm)
     ASN1_TIME * tm
     PREINIT:
     BIO *bp;
     int i;
     char buffer[256];
     CODE:
     bp = BIO_new(BIO_s_mem());
     ASN1_TIME_print(bp,tm);
     i = BIO_read(bp,buffer,255);
     buffer[i] = '\0';
     ST(0) = sv_newmortal();   /* Undefined to start with */
     if ( i > 0 )
         sv_setpvn( ST(0), buffer, i );
     BIO_free(bp);

--
kmx
Subject: get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
I propose to add 2 new functions:
1/ P_ASN1_TIME_set_isotime(tm,str)
2/ P_ASN1_TIME_get_isotime(tm)

These function support getting and storing datetime info in ISO8601 format. It supports only "full" format like "2012-03-22T23:55:33" or "2012-03-22T23:55:33Z" or "2012-03-22T23:55:33<timezone>" - short forms like "2012-03-22T23:55" are not supported (to keep implementation simple).

The format is parsable by DateTime::Format::RFC3339

Here is the code:

void
P_ASN1_TIME_get_isotime(tm)
     ASN1_TIME *tm
     PREINIT:
     ASN1_GENERALIZEDTIME *tmp = NULL;
     char buf[256];
     CODE:
     buf[0] = '\0';
     ASN1_TIME_to_generalizedtime(tm,&tmp);
     if (tmp) {
       if (ASN1_GENERALIZEDTIME_check(tmp)) {
         if (strlen(tmp->data)>=14 && strlen(tmp->data)<200) {
           strcpy (buf,"yyyy-mm-ddThh:mm:ss");
           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);
     }
     ST(0) = sv_newmortal();
     sv_setpv(ST(0), buf);

void
P_ASN1_TIME_set_isotime(tm,str)
     ASN1_TIME *tm
     const char *str
     PREINIT:
     ASN1_TIME t;
     char buf[256];
     int y=0,M=0,d=0,h=0,m=0,s=0;
     int i,rv;
     CODE:
     if (!tm) XSRETURN_UNDEF;
     /* we support only "2012-03-22T23:55:33" or "2012-03-22T23:55:33Z" or "2012-03-22T23:55:33<timezone>" */
     if (strlen(str) < 19) XSRETURN_UNDEF;
     for (i=0;  i<4;  i++) if ((str[i] > '9') || (str[i] < '0')) XSRETURN_UNDEF;
     for (i=5;  i<7;  i++) if ((str[i] > '9') || (str[i] < '0')) XSRETURN_UNDEF;
     for (i=8;  i<10; i++) if ((str[i] > '9') || (str[i] < '0')) XSRETURN_UNDEF;
     for (i=11; i<13; i++) if ((str[i] > '9') || (str[i] < '0')) XSRETURN_UNDEF;
     for (i=14; i<16; i++) if ((str[i] > '9') || (str[i] < '0')) XSRETURN_UNDEF;    
     for (i=17; i<19; i++) if ((str[i] > '9') || (str[i] < '0')) XSRETURN_UNDEF;
     strncpy(buf,    str,    4);
     strncpy(buf+4,  str+5,  2);
     strncpy(buf+6,  str+8,  2);
     strncpy(buf+8,  str+11, 2);
     strncpy(buf+10, str+14, 2);
     strncpy(buf+12, str+17, 2);
     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;
     }
     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 */

     ST(0) = sv_newmortal();
     sv_setiv(ST(0), rv); /* 1 = success, undef = failure */

--
kmx


Subject: Re: [rt.cpan.org #74555] AutoReply: P_ASN1_UTCTIME_put2string fails to print dates out of 1950-2049
Date: Tue, 31 Jan 2012 12:21:18 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
in the end we can make P_ASN1_UTCTIME_put2string() just an alias for the newly implemented P_ASN1_TIME_put2string() -- kmx
Subject: Re: [rt.cpan.org #74555] AutoReply: P_ASN1_UTCTIME_put2string fails to print dates out of 1950-2049
Date: Wed, 01 Feb 2012 08:57:48 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
Hello, On Tuesday, January 31, 2012 06:21:33 AM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74555 > > > in the end we can make P_ASN1_UTCTIME_put2string() just an alias for the > newly implemented P_ASN1_TIME_put2string()
That seems reasonable. Cheers. Show quoted text
> > -- > kmx
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
I have merged these 2 RTs as I plan to prepare a patch + tests covering both

--
kmx

Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Sat, 04 Feb 2012 08:06:44 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
On Friday, February 03, 2012 11:52:16 AM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74556 > > > I have merged these 2 RTs as I plan to prepare a patch + tests covering both
OK, send when available for testing and merging into the mainline. Show quoted text
> > -- > kmx
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Mon, 06 Feb 2012 22:00:53 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Show quoted text
> OK, send when available for testing and merging into the mainline. >
see asn1time-enhancement_r291.diff -- kmx

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 08:07:03 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
Hi, Hmmm, Fine on Linux with 1.0.0 but I get test errors on all perl versions on Windows Server 2003 32 bit with openssl 0.9.8 R:\net-ssleay\trunk>c:\perl-5.12\bin\perl -w -I blib/lib -I blib/arch t/local/37 _asn1_time.t 1..9 ok 1 - ASN1_TIME_new [1] not ok 2 - P_ASN1_TIME_put2string # Failed test 'P_ASN1_TIME_put2string' # at t/local/37_asn1_time.t line 12. # got: 'May 16 20:39:00 2033 GMT' # expected: 'May 16 20:39:37 2033 GMT' not ok 3 - P_ASN1_UTCTIME_put2string # Failed test 'P_ASN1_UTCTIME_put2string' # at t/local/37_asn1_time.t line 13. # got: 'May 16 20:39:00 2033 GMT' # expected: 'May 16 20:39:37 2033 GMT' ok 4 - P_ASN1_TIME_get_isotime ok 5 - ASN1_TIME_new [2] not ok 6 - P_ASN1_TIME_put2string y=2075 # Failed test 'P_ASN1_TIME_put2string y=2075' # at t/local/37_asn1_time.t line 25. # got: 'Jun 19 13:08:00 2075 GMT' # expected: 'Jun 19 13:08:52 2075 GMT' ok 7 - P_ASN1_TIME_get_isotime y=2075 ok 8 - ASN1_TIME_new [3] ok 9 - X509_gmtime_adj # Looks like you failed 3 tests of 9. Note that the times are all correct _except_ for the seconds! Cheers. On Monday, February 06, 2012 04:01:13 PM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74556 > >
> > OK, send when available for testing and merging into the mainline.
> > see asn1time-enhancement_r291.diff > > -- > kmx
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 07:56:52 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Well, it is just calling ASN1_TIME_print there no additional magic implemented on Net::SSLeay side. On my Win7 + 32bit perl pass all tests with all perls and 0.9.7, 0.9.8, 0.9.8e, 0.9.8t I'll try to debug it more (first I need to make it fail like on your W2k3 box). -- kmx
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 09:49:38 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Could you please try to build & run the enclosed asn1time_print_test1.c The expected output is something like this: [0] version = 'OpenSSL 0.9.8t 18 Jan 2012' [1] timestamp = 1999888777 [2] sizeof(time_t) = 4 [3] tm->data = '330516203937Z' [4] tm->length = 13 [5] tm->type = 23 [6] tm->flags = 0 [7] out_time = 'May 16 20:39:37 2033 GMT' [8] out_utctime = 'May 16 20:39:37 2033 GMT' -- kmx

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 19:01 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
Hi, On Tuesday, February 07, 2012 03:49:51 AM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74556 > > > Could you please try to build & run the enclosed asn1time_print_test1.c > > The expected output is something like this: > > [0] version = 'OpenSSL 0.9.8t 18 Jan 2012' > [1] timestamp = 1999888777 > [2] sizeof(time_t) = 4 > [3] tm->data = '330516203937Z' > [4] tm->length = 13 > [5] tm->type = 23 > [6] tm->flags = 0 > [7] out_time = 'May 16 20:39:37 2033 GMT' > [8] out_utctime = 'May 16 20:39:37 2033 GMT'
R:\net-ssleay\trunk\tmp>asn1time_print_test1.exe [0] version = 'OpenSSL 0.9.8e 23 Feb 2007' [1] timestamp = 1999888777 [2] sizeof(time_t) = 4 [3] tm->data = '330516203937Z' [4] tm->length = 13 [5] tm->type = 23 [6] tm->flags = 0 [7] out_time = 'May 16 20:39:37 2033 GMT' [8] out_utctime = 'May 16 20:39:37 2033 GMT' Cheers. Show quoted text
> > -- > kmx
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 10:22:42 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Show quoted text
> [7] out_time = 'May 16 20:39:37 2033 GMT' >
Do you see ":37" part? (I know you see) Why the hell it gets zeroed? The thing is that the whole string 'May 16 20:39:37 2033 GMT' is completely created by ASN1_TIME_print() function. I would understand if it got cut somehow but it is "corrupted" in the middle. -- kmx
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 10:35:30 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Maybe a bug in openssl? http://rt.openssl.org/Ticket/Display.html?id=1768&user=guest&pass=guest According to my openssl source code scan it was introduced in 0.9.8i and fixed in 0.9.8j What exactly reports this command on your computer (run this in the same prompt as you run nmake test): perl -Mblib -MNet::SSLeay -e "print Net::SSLeay::SSLeay_version" If it turns out that the failure was on 0.9.8i we have solved the mystery (and I will just add a test skip for this buggy version). -- kmx
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Tue, 07 Feb 2012 11:02:16 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
I have build 0.9.8i and show exactly the same failure, so I have added test skip for this version. I am not saying that it will fix also your failure but we have to fix 0.9.8i anyway. Please apply this diff and rerun 'nmake test' on your machine. -- kmx

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Wed, 08 Feb 2012 09:37:16 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
Hi, Yes, that was OK, all your changes are now committed in 293. Thanks for all your contributions. Cheers. On Tuesday, February 07, 2012 05:02:30 AM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74556 > > > I have build 0.9.8i and show exactly the same failure, so I have added > test skip for this version. > > I am not saying that it will fix also your failure but we have to fix > 0.9.8i anyway. > > Please apply this diff and rerun 'nmake test' on your machine. > > -- > kmx
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Wed, 08 Feb 2012 03:24:16 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
please do not forget 37_asn1_time.t
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Wed, 08 Feb 2012 16:57:14 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
Ooops, sorry, added. Cheers. On Tuesday, February 07, 2012 09:24:30 PM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74556 > > > please do not forget 37_asn1_time.t
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.
Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Thu, 09 Feb 2012 08:55:32 +0100
To: bug-Net-SSLeay [...] rt.cpan.org
From: kmx <kmx [...] volny.cz>
Please apply also attached asn1time_remove_debug_stuff_r296.diff - I left there some debug stuff. -- kmx

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #74556] get/set ASN1_TIME in ISO8601-like format (proposal for 2 new functions)
Date: Thu, 09 Feb 2012 19:51:21 +1000
To: bug-Net-SSLeay [...] rt.cpan.org
From: Mike McCauley <mikem [...] open.com.au>
HI, Thanks. Now in 297 On Thursday, February 09, 2012 02:55:53 AM you wrote: Show quoted text
> Queue: Net-SSLeay > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=74556 > > > Please apply also attached asn1time_remove_debug_stuff_r296.diff - I > left there some debug stuff. > > -- > kmx
-- Mike McCauley mikem@open.com.au Open System Consultants Pty. Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia http://www.open.com.au Phone +61 7 5598-7474 Fax +61 7 5598-7070 Radiator: the most portable, flexible and configurable RADIUS server anywhere. SQL, proxy, DBM, files, LDAP, NIS+, password, NT, Emerald, Platypus, Freeside, TACACS+, PAM, external, Active Directory, EAP, TLS, TTLS, PEAP, TNC, WiMAX, RSA, Vasco, Yubikey, MOTP, HOTP, TOTP, DIAMETER etc. Full source on Unix, Windows, MacOSX, Solaris, VMS, NetWare etc.