mirror of https://github.com/openssl/openssl.git
				
				
				
			Improve ASN1_TIME_print documentation and output
This adds missing GMT indication when printing the local time as
it is converted to the UTC timezone before printing.
Also fixing the fractional seconds printing on EBCDIC platforms.
Fixes #26313
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26344)
(cherry picked from commit c81ff97866)
			
			
This commit is contained in:
		
							parent
							
								
									71f8af87f2
								
							
						
					
					
						commit
						73c85a7342
					
				|  | @ -492,9 +492,9 @@ int ASN1_TIME_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags) | ||||||
| int ossl_asn1_time_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags) | int ossl_asn1_time_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags) | ||||||
| { | { | ||||||
|     char *v; |     char *v; | ||||||
|     int gmt = 0, l; |     int l; | ||||||
|     struct tm stm; |     struct tm stm; | ||||||
|     const char upper_z = 0x5A, period = 0x2E; |     const char period = 0x2E; | ||||||
| 
 | 
 | ||||||
|     /* ossl_asn1_time_to_tm will check the time type */ |     /* ossl_asn1_time_to_tm will check the time type */ | ||||||
|     if (!ossl_asn1_time_to_tm(&stm, tm)) |     if (!ossl_asn1_time_to_tm(&stm, tm)) | ||||||
|  | @ -502,8 +502,6 @@ int ossl_asn1_time_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags) | ||||||
| 
 | 
 | ||||||
|     l = tm->length; |     l = tm->length; | ||||||
|     v = (char *)tm->data; |     v = (char *)tm->data; | ||||||
|     if (v[l - 1] == upper_z) |  | ||||||
|         gmt = 1; |  | ||||||
| 
 | 
 | ||||||
|     if (tm->type == V_ASN1_GENERALIZEDTIME) { |     if (tm->type == V_ASN1_GENERALIZEDTIME) { | ||||||
|         char *f = NULL; |         char *f = NULL; | ||||||
|  | @ -514,39 +512,36 @@ int ossl_asn1_time_print_ex(BIO *bp, const ASN1_TIME *tm, unsigned long flags) | ||||||
|          * 'fraction point' in a GeneralizedTime string. |          * 'fraction point' in a GeneralizedTime string. | ||||||
|          */ |          */ | ||||||
|         if (tm->length > 15 && v[14] == period) { |         if (tm->length > 15 && v[14] == period) { | ||||||
|             f = &v[14]; |             /* exclude the . itself */ | ||||||
|             f_len = 1; |             f = &v[15]; | ||||||
|             while (14 + f_len < l && ossl_ascii_isdigit(f[f_len])) |             f_len = 0; | ||||||
|  |             while (15 + f_len < l && ossl_ascii_isdigit(f[f_len])) | ||||||
|                 ++f_len; |                 ++f_len; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         if (f_len > 0) { | ||||||
|             if ((flags & ASN1_DTFLGS_TYPE_MASK) == ASN1_DTFLGS_ISO8601) { |             if ((flags & ASN1_DTFLGS_TYPE_MASK) == ASN1_DTFLGS_ISO8601) { | ||||||
|             return BIO_printf(bp, "%4d-%02d-%02d %02d:%02d:%02d%.*s%s", |                 return BIO_printf(bp, "%4d-%02d-%02d %02d:%02d:%02d.%.*sZ", | ||||||
|                                   stm.tm_year + 1900, stm.tm_mon + 1, |                                   stm.tm_year + 1900, stm.tm_mon + 1, | ||||||
|                                   stm.tm_mday, stm.tm_hour, |                                   stm.tm_mday, stm.tm_hour, | ||||||
|                           stm.tm_min, stm.tm_sec, f_len, f, |                                   stm.tm_min, stm.tm_sec, f_len, f) > 0; | ||||||
|                           (gmt ? "Z" : "")) > 0; |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|             return BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s", |  | ||||||
|                           _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, |  | ||||||
|                           stm.tm_min, stm.tm_sec, f_len, f, stm.tm_year + 1900, |  | ||||||
|                           (gmt ? " GMT" : "")) > 0; |  | ||||||
|         } |  | ||||||
|             } else { |             } else { | ||||||
|  |                 return BIO_printf(bp, "%s %2d %02d:%02d:%02d.%.*s %d GMT", | ||||||
|  |                                   _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, | ||||||
|  |                                   stm.tm_min, stm.tm_sec, f_len, f, | ||||||
|  |                                   stm.tm_year + 1900) > 0; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|     if ((flags & ASN1_DTFLGS_TYPE_MASK) == ASN1_DTFLGS_ISO8601) { |     if ((flags & ASN1_DTFLGS_TYPE_MASK) == ASN1_DTFLGS_ISO8601) { | ||||||
|             return BIO_printf(bp, "%4d-%02d-%02d %02d:%02d:%02d%s", |         return BIO_printf(bp, "%4d-%02d-%02d %02d:%02d:%02dZ", | ||||||
|                           stm.tm_year + 1900, stm.tm_mon + 1, |                           stm.tm_year + 1900, stm.tm_mon + 1, | ||||||
|                           stm.tm_mday, stm.tm_hour, |                           stm.tm_mday, stm.tm_hour, | ||||||
|                           stm.tm_min, stm.tm_sec, |                           stm.tm_min, stm.tm_sec) > 0; | ||||||
|                           (gmt ? "Z" : "")) > 0; |     } else { | ||||||
|         } |         return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d GMT", | ||||||
|         else { |  | ||||||
|             return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", |  | ||||||
|                           _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, |                           _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, | ||||||
|                           stm.tm_min, stm.tm_sec, stm.tm_year + 1900, |                           stm.tm_min, stm.tm_sec, stm.tm_year + 1900) > 0; | ||||||
|                           (gmt ? " GMT" : "")) > 0; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -102,8 +102,8 @@ functions check the syntax of the time structure I<s>. | ||||||
| 
 | 
 | ||||||
| The ASN1_TIME_print(), ASN1_UTCTIME_print() and ASN1_GENERALIZEDTIME_print() | The ASN1_TIME_print(), ASN1_UTCTIME_print() and ASN1_GENERALIZEDTIME_print() | ||||||
| functions print the time structure I<s> to BIO I<b> in human readable | functions print the time structure I<s> to BIO I<b> in human readable | ||||||
| format. It will be of the format MMM DD HH:MM:SS YYYY [GMT], for example | format. It will be of the format MMM DD HH:MM:SS[.s*] YYYY GMT, for example | ||||||
| "Feb  3 00:55:52 2015 GMT", which does not include a newline. | "Feb E<32>3 00:55:52 2015 GMT", which does not include a newline. | ||||||
| If the time structure has invalid format it prints out "Bad time value" and | If the time structure has invalid format it prints out "Bad time value" and | ||||||
| returns an error. The output for generalized time may include a fractional part | returns an error. The output for generalized time may include a fractional part | ||||||
| following the second. | following the second. | ||||||
|  | @ -179,6 +179,10 @@ starting with B<ASN1_UTCTIME> and B<ASN1_GENERALIZEDTIME> act only on that | ||||||
| specific time format. The functions starting with B<ASN1_TIME> will operate on | specific time format. The functions starting with B<ASN1_TIME> will operate on | ||||||
| either format. | either format. | ||||||
| 
 | 
 | ||||||
|  | Users familiar with RFC822 should note that when specifying the flag | ||||||
|  | B<ASN1_DTFLGS_RFC822> the year will be formatted as documented above, | ||||||
|  | i.e., using 4 digits, not 2 as specified in RFC822. | ||||||
|  | 
 | ||||||
| =head1 BUGS | =head1 BUGS | ||||||
| 
 | 
 | ||||||
| ASN1_TIME_print(), ASN1_UTCTIME_print() and ASN1_GENERALIZEDTIME_print() do | ASN1_TIME_print(), ASN1_UTCTIME_print() and ASN1_GENERALIZEDTIME_print() do | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue