Monday 15 July 2013

c - ASN1_TIME_print functionality without BIO? -


As described in this question: A Bio buffer is likely to write ASN1 time and then read it back to a custom Buffer buf :

  Bio * Bio; Int write = 0; Bio = Bio_NU (BIO_s_mem ()); If (Bio) {write (ASN1_TIME_print (Bio, TM)) = BIO_read (bio, buf, len-1); BIO_free (bio); } Buff [write] = '\ 0'; Write a return;   

How can this be achieved without using BIOS? The ASN1_TIME_print function is present only when OPENSSL_NO_BIO is not defined. Is there any way to write time in a given buffer?

You can try the following sample code. It does not use bio, but you should give the same output as an example of OP. If you do not trust the ASN1_TIME string, then you would like to add some error checking:

  • notBefore-gt; The data is & gt;
  • The value for each character is between '0' and '9'
  • Price for year, month, day, hour, minute, second
  • Type <

    You should also check that the date / time is GMT or not on the string If you want to see the output properly, like using BIOs: openssl / crypto / asn1 / t_x509 .c - ASN1_UTCTIME_ print or ASN1_GENERALIZEDTIME_print


      ASN1_TIME * notBefore = NULL; Int lane = 32; Four buff [lane]; Struct tm tm_time; NotBefore = X509_get_notBefore (x509_cert); // format ASN1_TIME type is in a TM straight with UTC if (notBefore-> gt; type == V_ASN1_UTCTIME) {strptime (const char *) notBefore-> data, "% y% m% d% H % M% SZ ", & Amp; tm_time); Stufftime (buff, size) * lane, "% h% d% H:% M:% S% Y", and amp; tm_time); } // format ASN1_TIME format is in a TM structure in "normalized" (not-before-> type == V_ASN1_GENERALIZEDTIME) {// I do not see this format, but it should not be very difficult}    

No comments:

Post a Comment