Fix time offset calculation.
authorTodd Short <tshort@akamai.com>
Thu, 16 Feb 2017 21:08:02 +0000 (16:08 -0500)
committerRichard Levitte <levitte@openssl.org>
Tue, 2 May 2017 08:41:01 +0000 (10:41 +0200)
ASN1_GENERALIZEDTIME and ASN1_UTCTIME may be specified using offsets,
even though that's not supported within certificates.

To convert the offset time back to GMT, the offsets are supposed to be
subtracted, not added. e.g. 1759-0500 == 2359+0100 == 2259Z.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3335)

crypto/asn1/a_gentm.c
crypto/asn1/a_utctm.c

index c02c8d9acc953b19d93ef5ce21c3e1564465444b..ff1b6954756698e4175ca707c955ba3ac62213ad 100644 (file)
@@ -101,7 +101,7 @@ int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d)
     if (a[o] == 'Z')
         o++;
     else if ((a[o] == '+') || (a[o] == '-')) {
-        int offsign = a[o] == '-' ? -1 : 1, offset = 0;
+        int offsign = a[o] == '-' ? 1 : -1, offset = 0;
         o++;
         if (o + 4 > l)
             goto err;
index 7916e300ef0509a523b7712d2d2382ca5c4c21b0..9797aa8a1eb4b781bf1b99a891a1f53676165040 100644 (file)
@@ -75,7 +75,7 @@ int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d)
     if (a[o] == 'Z')
         o++;
     else if ((a[o] == '+') || (a[o] == '-')) {
-        int offsign = a[o] == '-' ? -1 : 1, offset = 0;
+        int offsign = a[o] == '-' ? 1 : -1, offset = 0;
         o++;
         if (o + 4 > l)
             goto err;