| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/asn1/a_time.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||||||||||||||||||||
| 2 | * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||||||||||||||
| 3 | * | - | ||||||||||||||||||||||||||||||
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||||||||||||||
| 5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||||||||||||||
| 6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||||||||||||||
| 7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||||||||||||||
| 8 | */ | - | ||||||||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||||||||
| 10 | /*- | - | ||||||||||||||||||||||||||||||
| 11 | * This is an implementation of the ASN1 Time structure which is: | - | ||||||||||||||||||||||||||||||
| 12 | * Time ::= CHOICE { | - | ||||||||||||||||||||||||||||||
| 13 | * utcTime UTCTime, | - | ||||||||||||||||||||||||||||||
| 14 | * generalTime GeneralizedTime } | - | ||||||||||||||||||||||||||||||
| 15 | */ | - | ||||||||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||||||||
| 17 | #include <stdio.h> | - | ||||||||||||||||||||||||||||||
| 18 | #include <time.h> | - | ||||||||||||||||||||||||||||||
| 19 | #include "internal/ctype.h" | - | ||||||||||||||||||||||||||||||
| 20 | #include "internal/cryptlib.h" | - | ||||||||||||||||||||||||||||||
| 21 | #include <openssl/asn1t.h> | - | ||||||||||||||||||||||||||||||
| 22 | #include "asn1_locl.h" | - | ||||||||||||||||||||||||||||||
| 23 | - | |||||||||||||||||||||||||||||||
| 24 | IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) | - | ||||||||||||||||||||||||||||||
| 25 | - | |||||||||||||||||||||||||||||||
| 26 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) executed 8321 times by 1 test: end of blockExecuted by:
never executed: return (ASN1_TIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, (&(ASN1_TIME_it)));never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, (&(ASN1_TIME_it)));executed 117 times by 1 test: return (ASN1_TIME *)ASN1_item_new((&(ASN1_TIME_it)));Executed by:
| 0-8321 | ||||||||||||||||||||||||||||||
| 27 | - | |||||||||||||||||||||||||||||||
| 28 | static int is_utc(const int year) | - | ||||||||||||||||||||||||||||||
| 29 | { | - | ||||||||||||||||||||||||||||||
| 30 | if (50 <= year && year <= 149)
| 3-8344 | ||||||||||||||||||||||||||||||
| 31 | return 1; executed 8341 times by 1 test: return 1;Executed by:
| 8341 | ||||||||||||||||||||||||||||||
| 32 | return 0; executed 10 times by 1 test: return 0;Executed by:
| 10 | ||||||||||||||||||||||||||||||
| 33 | } | - | ||||||||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||||||||
| 35 | static int leap_year(const int year) | - | ||||||||||||||||||||||||||||||
| 36 | { | - | ||||||||||||||||||||||||||||||
| 37 | if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
| 390-22368 | ||||||||||||||||||||||||||||||
| 38 | return 1; executed 3349 times by 1 test: return 1;Executed by:
| 3349 | ||||||||||||||||||||||||||||||
| 39 | return 0; executed 20491 times by 1 test: return 0;Executed by:
| 20491 | ||||||||||||||||||||||||||||||
| 40 | } | - | ||||||||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||||||||
| 42 | /* | - | ||||||||||||||||||||||||||||||
| 43 | * Compute the day of the week and the day of the year from the year, month | - | ||||||||||||||||||||||||||||||
| 44 | * and day. The day of the year is straightforward, the day of the week uses | - | ||||||||||||||||||||||||||||||
| 45 | * a form of Zeller's congruence. For this months start with March and are | - | ||||||||||||||||||||||||||||||
| 46 | * numbered 4 through 15. | - | ||||||||||||||||||||||||||||||
| 47 | */ | - | ||||||||||||||||||||||||||||||
| 48 | static void determine_days(struct tm *tm) | - | ||||||||||||||||||||||||||||||
| 49 | { | - | ||||||||||||||||||||||||||||||
| 50 | static const int ydays[12] = { | - | ||||||||||||||||||||||||||||||
| 51 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 | - | ||||||||||||||||||||||||||||||
| 52 | }; | - | ||||||||||||||||||||||||||||||
| 53 | int y = tm->tm_year + 1900; | - | ||||||||||||||||||||||||||||||
| 54 | int m = tm->tm_mon; | - | ||||||||||||||||||||||||||||||
| 55 | int d = tm->tm_mday; | - | ||||||||||||||||||||||||||||||
| 56 | int c; | - | ||||||||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||||||||
| 58 | tm->tm_yday = ydays[m] + d - 1; | - | ||||||||||||||||||||||||||||||
| 59 | if (m >= 2) {
| 13300-21900 | ||||||||||||||||||||||||||||||
| 60 | /* March and onwards can be one day further into the year */ | - | ||||||||||||||||||||||||||||||
| 61 | tm->tm_yday += leap_year(y); | - | ||||||||||||||||||||||||||||||
| 62 | m += 2; | - | ||||||||||||||||||||||||||||||
| 63 | } else { executed 13300 times by 1 test: end of blockExecuted by:
| 13300 | ||||||||||||||||||||||||||||||
| 64 | /* Treat January and February as part of the previous year */ | - | ||||||||||||||||||||||||||||||
| 65 | m += 14; | - | ||||||||||||||||||||||||||||||
| 66 | y--; | - | ||||||||||||||||||||||||||||||
| 67 | } executed 21900 times by 1 test: end of blockExecuted by:
| 21900 | ||||||||||||||||||||||||||||||
| 68 | c = y / 100; | - | ||||||||||||||||||||||||||||||
| 69 | y %= 100; | - | ||||||||||||||||||||||||||||||
| 70 | /* Zeller's congruance */ | - | ||||||||||||||||||||||||||||||
| 71 | tm->tm_wday = (d + (13 * m) / 5 + y + y / 4 + c / 4 + 5 * c + 6) % 7; | - | ||||||||||||||||||||||||||||||
| 72 | } executed 35200 times by 1 test: end of blockExecuted by:
| 35200 | ||||||||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||||||||
| 74 | int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *d) | - | ||||||||||||||||||||||||||||||
| 75 | { | - | ||||||||||||||||||||||||||||||
| 76 | static const int min[9] = { 0, 0, 1, 1, 0, 0, 0, 0, 0 }; | - | ||||||||||||||||||||||||||||||
| 77 | static const int max[9] = { 99, 99, 12, 31, 23, 59, 59, 12, 59 }; | - | ||||||||||||||||||||||||||||||
| 78 | static const int mdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; | - | ||||||||||||||||||||||||||||||
| 79 | char *a; | - | ||||||||||||||||||||||||||||||
| 80 | int n, i, i2, l, o, min_l = 11, strict = 0, end = 6, btz = 5, md; | - | ||||||||||||||||||||||||||||||
| 81 | struct tm tmp; | - | ||||||||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||||||||
| 83 | /* | - | ||||||||||||||||||||||||||||||
| 84 | * ASN1_STRING_FLAG_X509_TIME is used to enforce RFC 5280 | - | ||||||||||||||||||||||||||||||
| 85 | * time string format, in which: | - | ||||||||||||||||||||||||||||||
| 86 | * | - | ||||||||||||||||||||||||||||||
| 87 | * 1. "seconds" is a 'MUST' | - | ||||||||||||||||||||||||||||||
| 88 | * 2. "Zulu" timezone is a 'MUST' | - | ||||||||||||||||||||||||||||||
| 89 | * 3. "+|-" is not allowed to indicate a time zone | - | ||||||||||||||||||||||||||||||
| 90 | */ | - | ||||||||||||||||||||||||||||||
| 91 | if (d->type == V_ASN1_UTCTIME) {
| 18809-25351 | ||||||||||||||||||||||||||||||
| 92 | if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
| 20-25331 | ||||||||||||||||||||||||||||||
| 93 | min_l = 13; | - | ||||||||||||||||||||||||||||||
| 94 | strict = 1; | - | ||||||||||||||||||||||||||||||
| 95 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||||||||||||||
| 96 | } else if (d->type == V_ASN1_GENERALIZEDTIME) { executed 25351 times by 1 test: end of blockExecuted by:
| 0-25351 | ||||||||||||||||||||||||||||||
| 97 | end = 7; | - | ||||||||||||||||||||||||||||||
| 98 | btz = 6; | - | ||||||||||||||||||||||||||||||
| 99 | if (d->flags & ASN1_STRING_FLAG_X509_TIME) {
| 20-18789 | ||||||||||||||||||||||||||||||
| 100 | min_l = 15; | - | ||||||||||||||||||||||||||||||
| 101 | strict = 1; | - | ||||||||||||||||||||||||||||||
| 102 | } else { executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||||||||||||||
| 103 | min_l = 13; | - | ||||||||||||||||||||||||||||||
| 104 | } executed 18789 times by 1 test: end of blockExecuted by:
| 18789 | ||||||||||||||||||||||||||||||
| 105 | } else { | - | ||||||||||||||||||||||||||||||
| 106 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
| 107 | } | - | ||||||||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||||||||
| 109 | l = d->length; | - | ||||||||||||||||||||||||||||||
| 110 | a = (char *)d->data; | - | ||||||||||||||||||||||||||||||
| 111 | o = 0; | - | ||||||||||||||||||||||||||||||
| 112 | memset(&tmp, 0, sizeof(tmp)); | - | ||||||||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||||||||
| 114 | /* | - | ||||||||||||||||||||||||||||||
| 115 | * GENERALIZEDTIME is similar to UTCTIME except the year is represented | - | ||||||||||||||||||||||||||||||
| 116 | * as YYYY. This stuff treats everything as a two digit field so make | - | ||||||||||||||||||||||||||||||
| 117 | * first two fields 00 to 99 | - | ||||||||||||||||||||||||||||||
| 118 | */ | - | ||||||||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||||||||
| 120 | if (l < min_l)
| 6457-37703 | ||||||||||||||||||||||||||||||
| 121 | goto err; executed 6457 times by 1 test: goto err;Executed by:
| 6457 | ||||||||||||||||||||||||||||||
| 122 | for (i = 0; i < end; i++) {
| 27854-229866 | ||||||||||||||||||||||||||||||
| 123 | if (!strict && (i == btz) && ((a[o] == 'Z') || (a[o] == '+') || (a[o] == '-'))) {
| 151-229715 | ||||||||||||||||||||||||||||||
| 124 | i++; | - | ||||||||||||||||||||||||||||||
| 125 | break; executed 5428 times by 1 test: break;Executed by:
| 5428 | ||||||||||||||||||||||||||||||
| 126 | } | - | ||||||||||||||||||||||||||||||
| 127 | if (!ossl_isdigit(a[o]))
| 977-223461 | ||||||||||||||||||||||||||||||
| 128 | goto err; executed 977 times by 1 test: goto err;Executed by:
| 977 | ||||||||||||||||||||||||||||||
| 129 | n = a[o] - '0'; | - | ||||||||||||||||||||||||||||||
| 130 | /* incomplete 2-digital number */ | - | ||||||||||||||||||||||||||||||
| 131 | if (++o == l)
| 486-222975 | ||||||||||||||||||||||||||||||
| 132 | goto err; executed 486 times by 1 test: goto err;Executed by:
| 486 | ||||||||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||||||||
| 134 | if (!ossl_isdigit(a[o]))
| 848-222127 | ||||||||||||||||||||||||||||||
| 135 | goto err; executed 848 times by 1 test: goto err;Executed by:
| 848 | ||||||||||||||||||||||||||||||
| 136 | n = (n * 10) + a[o] - '0'; | - | ||||||||||||||||||||||||||||||
| 137 | /* no more bytes to read, but we haven't seen time-zone yet */ | - | ||||||||||||||||||||||||||||||
| 138 | if (++o == l)
| 106-222021 | ||||||||||||||||||||||||||||||
| 139 | goto err; executed 106 times by 1 test: goto err;Executed by:
| 106 | ||||||||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||||||||
| 141 | i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
| 95699-126322 | ||||||||||||||||||||||||||||||
| 142 | - | |||||||||||||||||||||||||||||||
| 143 | if ((n < min[i2]) || (n > max[i2]))
| 531-221490 | ||||||||||||||||||||||||||||||
| 144 | goto err; executed 1207 times by 1 test: goto err;Executed by:
| 1207 | ||||||||||||||||||||||||||||||
| 145 | switch (i2) { | - | ||||||||||||||||||||||||||||||
| 146 | case 0: executed 15100 times by 1 test: case 0:Executed by:
| 15100 | ||||||||||||||||||||||||||||||
| 147 | /* UTC will never be here */ | - | ||||||||||||||||||||||||||||||
| 148 | tmp.tm_year = n * 100 - 1900; | - | ||||||||||||||||||||||||||||||
| 149 | break; executed 15100 times by 1 test: break;Executed by:
| 15100 | ||||||||||||||||||||||||||||||
| 150 | case 1: executed 37083 times by 1 test: case 1:Executed by:
| 37083 | ||||||||||||||||||||||||||||||
| 151 | if (d->type == V_ASN1_UTCTIME)
| 14812-22271 | ||||||||||||||||||||||||||||||
| 152 | tmp.tm_year = n < 50 ? n + 100 : n; executed 22271 times by 1 test: tmp.tm_year = n < 50 ? n + 100 : n;Executed by:
| 2878-22271 | ||||||||||||||||||||||||||||||
| 153 | else | - | ||||||||||||||||||||||||||||||
| 154 | tmp.tm_year += n; executed 14812 times by 1 test: tmp.tm_year += n;Executed by:
| 14812 | ||||||||||||||||||||||||||||||
| 155 | break; executed 37083 times by 1 test: break;Executed by:
| 37083 | ||||||||||||||||||||||||||||||
| 156 | case 2: executed 36351 times by 1 test: case 2:Executed by:
| 36351 | ||||||||||||||||||||||||||||||
| 157 | tmp.tm_mon = n - 1; | - | ||||||||||||||||||||||||||||||
| 158 | break; executed 36351 times by 1 test: break;Executed by:
| 36351 | ||||||||||||||||||||||||||||||
| 159 | case 3: executed 35997 times by 1 test: case 3:Executed by:
| 35997 | ||||||||||||||||||||||||||||||
| 160 | /* check if tm_mday is valid in tm_mon */ | - | ||||||||||||||||||||||||||||||
| 161 | if (tmp.tm_mon == 1) {
| 10540-25457 | ||||||||||||||||||||||||||||||
| 162 | /* it's February */ | - | ||||||||||||||||||||||||||||||
| 163 | md = mdays[1] + leap_year(tmp.tm_year + 1900); | - | ||||||||||||||||||||||||||||||
| 164 | } else { executed 10540 times by 1 test: end of blockExecuted by:
| 10540 | ||||||||||||||||||||||||||||||
| 165 | md = mdays[tmp.tm_mon]; | - | ||||||||||||||||||||||||||||||
| 166 | } executed 25457 times by 1 test: end of blockExecuted by:
| 25457 | ||||||||||||||||||||||||||||||
| 167 | if (n > md)
| 797-35200 | ||||||||||||||||||||||||||||||
| 168 | goto err; executed 797 times by 1 test: goto err;Executed by:
| 797 | ||||||||||||||||||||||||||||||
| 169 | tmp.tm_mday = n; | - | ||||||||||||||||||||||||||||||
| 170 | determine_days(&tmp); | - | ||||||||||||||||||||||||||||||
| 171 | break; executed 35200 times by 1 test: break;Executed by:
| 35200 | ||||||||||||||||||||||||||||||
| 172 | case 4: executed 34371 times by 1 test: case 4:Executed by:
| 34371 | ||||||||||||||||||||||||||||||
| 173 | tmp.tm_hour = n; | - | ||||||||||||||||||||||||||||||
| 174 | break; executed 34371 times by 1 test: break;Executed by:
| 34371 | ||||||||||||||||||||||||||||||
| 175 | case 5: executed 34058 times by 1 test: case 5:Executed by:
| 34058 | ||||||||||||||||||||||||||||||
| 176 | tmp.tm_min = n; | - | ||||||||||||||||||||||||||||||
| 177 | break; executed 34058 times by 1 test: break;Executed by:
| 34058 | ||||||||||||||||||||||||||||||
| 178 | case 6: executed 27854 times by 1 test: case 6:Executed by:
| 27854 | ||||||||||||||||||||||||||||||
| 179 | tmp.tm_sec = n; | - | ||||||||||||||||||||||||||||||
| 180 | break; executed 27854 times by 1 test: break;Executed by:
| 27854 | ||||||||||||||||||||||||||||||
| 181 | } | - | ||||||||||||||||||||||||||||||
| 182 | } executed 220017 times by 1 test: end of blockExecuted by:
| 220017 | ||||||||||||||||||||||||||||||
| 183 | - | |||||||||||||||||||||||||||||||
| 184 | /* | - | ||||||||||||||||||||||||||||||
| 185 | * Optional fractional seconds: decimal point followed by one or more | - | ||||||||||||||||||||||||||||||
| 186 | * digits. | - | ||||||||||||||||||||||||||||||
| 187 | */ | - | ||||||||||||||||||||||||||||||
| 188 | if (d->type == V_ASN1_GENERALIZEDTIME && a[o] == '.') {
| 5084-20348 | ||||||||||||||||||||||||||||||
| 189 | if (strict)
| 2-5082 | ||||||||||||||||||||||||||||||
| 190 | /* RFC 5280 forbids fractional seconds */ | - | ||||||||||||||||||||||||||||||
| 191 | goto err; executed 2 times by 1 test: goto err;Executed by:
| 2 | ||||||||||||||||||||||||||||||
| 192 | if (++o == l)
| 215-4867 | ||||||||||||||||||||||||||||||
| 193 | goto err; executed 215 times by 1 test: goto err;Executed by:
| 215 | ||||||||||||||||||||||||||||||
| 194 | i = o; | - | ||||||||||||||||||||||||||||||
| 195 | while ((o < l) && ossl_isdigit(a[o]))
| 208-22748 | ||||||||||||||||||||||||||||||
| 196 | o++; executed 18089 times by 1 test: o++;Executed by:
| 18089 | ||||||||||||||||||||||||||||||
| 197 | /* Must have at least one digit after decimal point */ | - | ||||||||||||||||||||||||||||||
| 198 | if (i == o)
| 400-4467 | ||||||||||||||||||||||||||||||
| 199 | goto err; executed 400 times by 1 test: goto err;Executed by:
| 400 | ||||||||||||||||||||||||||||||
| 200 | /* no more bytes to read, but we haven't seen time-zone yet */ | - | ||||||||||||||||||||||||||||||
| 201 | if (o == l)
| 208-4259 | ||||||||||||||||||||||||||||||
| 202 | goto err; executed 208 times by 1 test: goto err;Executed by:
| 208 | ||||||||||||||||||||||||||||||
| 203 | } executed 4259 times by 1 test: end of blockExecuted by:
| 4259 | ||||||||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||||||||
| 205 | /* | - | ||||||||||||||||||||||||||||||
| 206 | * 'o' will never point to '\0' at this point, the only chance | - | ||||||||||||||||||||||||||||||
| 207 | * 'o' can point to '\0' is either the subsequent if or the first | - | ||||||||||||||||||||||||||||||
| 208 | * else if is true. | - | ||||||||||||||||||||||||||||||
| 209 | */ | - | ||||||||||||||||||||||||||||||
| 210 | if (a[o] == 'Z') {
| 5109-27348 | ||||||||||||||||||||||||||||||
| 211 | o++; | - | ||||||||||||||||||||||||||||||
| 212 | } else if (!strict && ((a[o] == '+') || (a[o] == '-'))) { executed 27348 times by 1 test: end of blockExecuted by:
| 4-27348 | ||||||||||||||||||||||||||||||
| 213 | int offsign = a[o] == '-' ? 1 : -1;
| 1286-3382 | ||||||||||||||||||||||||||||||
| 214 | int offset = 0; | - | ||||||||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||||||||
| 216 | o++; | - | ||||||||||||||||||||||||||||||
| 217 | /* | - | ||||||||||||||||||||||||||||||
| 218 | * if not equal, no need to do subsequent checks | - | ||||||||||||||||||||||||||||||
| 219 | * since the following for-loop will add 'o' by 4 | - | ||||||||||||||||||||||||||||||
| 220 | * and the final return statement will check if 'l' | - | ||||||||||||||||||||||||||||||
| 221 | * and 'o' are equal. | - | ||||||||||||||||||||||||||||||
| 222 | */ | - | ||||||||||||||||||||||||||||||
| 223 | if (o + 4 != l)
| 439-4229 | ||||||||||||||||||||||||||||||
| 224 | goto err; executed 439 times by 1 test: goto err;Executed by:
| 439 | ||||||||||||||||||||||||||||||
| 225 | for (i = end; i < end + 2; i++) {
| 3259-7716 | ||||||||||||||||||||||||||||||
| 226 | if (!ossl_isdigit(a[o]))
| 329-7387 | ||||||||||||||||||||||||||||||
| 227 | goto err; executed 329 times by 1 test: goto err;Executed by:
| 329 | ||||||||||||||||||||||||||||||
| 228 | n = a[o] - '0'; | - | ||||||||||||||||||||||||||||||
| 229 | o++; | - | ||||||||||||||||||||||||||||||
| 230 | if (!ossl_isdigit(a[o]))
| 315-7072 | ||||||||||||||||||||||||||||||
| 231 | goto err; executed 315 times by 1 test: goto err;Executed by:
| 315 | ||||||||||||||||||||||||||||||
| 232 | n = (n * 10) + a[o] - '0'; | - | ||||||||||||||||||||||||||||||
| 233 | i2 = (d->type == V_ASN1_UTCTIME) ? i + 1 : i;
| 2848-4224 | ||||||||||||||||||||||||||||||
| 234 | if ((n < min[i2]) || (n > max[i2]))
| 0-7072 | ||||||||||||||||||||||||||||||
| 235 | goto err; executed 326 times by 1 test: goto err;Executed by:
| 326 | ||||||||||||||||||||||||||||||
| 236 | /* if tm is NULL, no need to adjust */ | - | ||||||||||||||||||||||||||||||
| 237 | if (tm != NULL) {
| 48-6698 | ||||||||||||||||||||||||||||||
| 238 | if (i == end)
| 3235-3463 | ||||||||||||||||||||||||||||||
| 239 | offset = n * 3600; executed 3463 times by 1 test: offset = n * 3600;Executed by:
| 3463 | ||||||||||||||||||||||||||||||
| 240 | else if (i == end + 1)
| 0-3235 | ||||||||||||||||||||||||||||||
| 241 | offset += n * 60; executed 3235 times by 1 test: offset += n * 60;Executed by:
| 3235 | ||||||||||||||||||||||||||||||
| 242 | } executed 6698 times by 1 test: end of blockExecuted by:
| 6698 | ||||||||||||||||||||||||||||||
| 243 | o++; | - | ||||||||||||||||||||||||||||||
| 244 | } executed 6746 times by 1 test: end of blockExecuted by:
| 6746 | ||||||||||||||||||||||||||||||
| 245 | if (offset && !OPENSSL_gmtime_adj(&tmp, 0, offset * offsign))
| 217-2602 | ||||||||||||||||||||||||||||||
| 246 | goto err; executed 217 times by 1 test: goto err;Executed by:
| 217 | ||||||||||||||||||||||||||||||
| 247 | } else { executed 3042 times by 1 test: end of blockExecuted by:
| 3042 | ||||||||||||||||||||||||||||||
| 248 | /* not Z, or not +/- in non-strict mode */ | - | ||||||||||||||||||||||||||||||
| 249 | goto err; executed 441 times by 1 test: goto err;Executed by:
| 441 | ||||||||||||||||||||||||||||||
| 250 | } | - | ||||||||||||||||||||||||||||||
| 251 | if (o == l) {
| 1011-29379 | ||||||||||||||||||||||||||||||
| 252 | /* success, check if tm should be filled */ | - | ||||||||||||||||||||||||||||||
| 253 | if (tm != NULL)
| 1949-27430 | ||||||||||||||||||||||||||||||
| 254 | *tm = tmp; executed 27430 times by 1 test: *tm = tmp;Executed by:
| 27430 | ||||||||||||||||||||||||||||||
| 255 | return 1; executed 29379 times by 1 test: return 1;Executed by:
| 29379 | ||||||||||||||||||||||||||||||
| 256 | } | - | ||||||||||||||||||||||||||||||
| 257 | err: code before this statement executed 1011 times by 1 test: err:Executed by:
| 1011 | ||||||||||||||||||||||||||||||
| 258 | return 0; executed 14781 times by 1 test: return 0;Executed by:
| 14781 | ||||||||||||||||||||||||||||||
| 259 | } | - | ||||||||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||||||||
| 261 | ASN1_TIME *asn1_time_from_tm(ASN1_TIME *s, struct tm *ts, int type) | - | ||||||||||||||||||||||||||||||
| 262 | { | - | ||||||||||||||||||||||||||||||
| 263 | char* p; | - | ||||||||||||||||||||||||||||||
| 264 | ASN1_TIME *tmps = NULL; | - | ||||||||||||||||||||||||||||||
| 265 | const size_t len = 20; | - | ||||||||||||||||||||||||||||||
| 266 | - | |||||||||||||||||||||||||||||||
| 267 | if (type == V_ASN1_UNDEF) {
| 1822-8348 | ||||||||||||||||||||||||||||||
| 268 | if (is_utc(ts->tm_year))
| 8-8340 | ||||||||||||||||||||||||||||||
| 269 | type = V_ASN1_UTCTIME; executed 8340 times by 1 test: type = 23;Executed by:
| 8340 | ||||||||||||||||||||||||||||||
| 270 | else | - | ||||||||||||||||||||||||||||||
| 271 | type = V_ASN1_GENERALIZEDTIME; executed 8 times by 1 test: type = 24;Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 272 | } else if (type == V_ASN1_UTCTIME) {
| 0-1822 | ||||||||||||||||||||||||||||||
| 273 | if (!is_utc(ts->tm_year))
| 0 | ||||||||||||||||||||||||||||||
| 274 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
| 275 | } else if (type != V_ASN1_GENERALIZEDTIME) { never executed: end of block
| 0-1822 | ||||||||||||||||||||||||||||||
| 276 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
| 277 | } | - | ||||||||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||||||||
| 279 | if (s == NULL)
| 1867-8303 | ||||||||||||||||||||||||||||||
| 280 | tmps = ASN1_STRING_new(); executed 8303 times by 1 test: tmps = ASN1_STRING_new();Executed by:
| 8303 | ||||||||||||||||||||||||||||||
| 281 | else | - | ||||||||||||||||||||||||||||||
| 282 | tmps = s; executed 1867 times by 1 test: tmps = s;Executed by:
| 1867 | ||||||||||||||||||||||||||||||
| 283 | if (tmps == NULL)
| 0-10170 | ||||||||||||||||||||||||||||||
| 284 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||||||||
| 286 | if (!ASN1_STRING_set(tmps, NULL, len))
| 0-10170 | ||||||||||||||||||||||||||||||
| 287 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||||||||
| 289 | tmps->type = type; | - | ||||||||||||||||||||||||||||||
| 290 | p = (char*)tmps->data; | - | ||||||||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||||||||
| 292 | if (type == V_ASN1_GENERALIZEDTIME)
| 1830-8340 | ||||||||||||||||||||||||||||||
| 293 | tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", executed 1830 times by 1 test: tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 1830 | ||||||||||||||||||||||||||||||
| 294 | ts->tm_year + 1900, ts->tm_mon + 1, executed 1830 times by 1 test: tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 1830 | ||||||||||||||||||||||||||||||
| 295 | ts->tm_mday, ts->tm_hour, ts->tm_min, executed 1830 times by 1 test: tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 1830 | ||||||||||||||||||||||||||||||
| 296 | ts->tm_sec); executed 1830 times by 1 test: tmps->length = BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 1830 | ||||||||||||||||||||||||||||||
| 297 | else | - | ||||||||||||||||||||||||||||||
| 298 | tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", executed 8340 times by 1 test: tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 8340 | ||||||||||||||||||||||||||||||
| 299 | ts->tm_year % 100, ts->tm_mon + 1, executed 8340 times by 1 test: tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 8340 | ||||||||||||||||||||||||||||||
| 300 | ts->tm_mday, ts->tm_hour, ts->tm_min, executed 8340 times by 1 test: tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 8340 | ||||||||||||||||||||||||||||||
| 301 | ts->tm_sec); executed 8340 times by 1 test: tmps->length = BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec);Executed by:
| 8340 | ||||||||||||||||||||||||||||||
| 302 | - | |||||||||||||||||||||||||||||||
| 303 | #ifdef CHARSET_EBCDIC_not | - | ||||||||||||||||||||||||||||||
| 304 | ebcdic2ascii(tmps->data, tmps->data, tmps->length); | - | ||||||||||||||||||||||||||||||
| 305 | #endif | - | ||||||||||||||||||||||||||||||
| 306 | return tmps; executed 10170 times by 1 test: return tmps;Executed by:
| 10170 | ||||||||||||||||||||||||||||||
| 307 | err: | - | ||||||||||||||||||||||||||||||
| 308 | if (tmps != s)
| 0 | ||||||||||||||||||||||||||||||
| 309 | ASN1_STRING_free(tmps); never executed: ASN1_STRING_free(tmps); | 0 | ||||||||||||||||||||||||||||||
| 310 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
| 311 | } | - | ||||||||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||||||||
| 313 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | - | ||||||||||||||||||||||||||||||
| 314 | { | - | ||||||||||||||||||||||||||||||
| 315 | return ASN1_TIME_adj(s, t, 0, 0); executed 111 times by 1 test: return ASN1_TIME_adj(s, t, 0, 0);Executed by:
| 111 | ||||||||||||||||||||||||||||||
| 316 | } | - | ||||||||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||||||||
| 318 | ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, | - | ||||||||||||||||||||||||||||||
| 319 | int offset_day, long offset_sec) | - | ||||||||||||||||||||||||||||||
| 320 | { | - | ||||||||||||||||||||||||||||||
| 321 | struct tm *ts; | - | ||||||||||||||||||||||||||||||
| 322 | struct tm data; | - | ||||||||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||||||||
| 324 | ts = OPENSSL_gmtime(&t, &data); | - | ||||||||||||||||||||||||||||||
| 325 | if (ts == NULL) {
| 0-8319 | ||||||||||||||||||||||||||||||
| 326 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | - | ||||||||||||||||||||||||||||||
| 327 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
| 328 | } | - | ||||||||||||||||||||||||||||||
| 329 | if (offset_day || offset_sec) {
| 0-8302 | ||||||||||||||||||||||||||||||
| 330 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
| 0-17 | ||||||||||||||||||||||||||||||
| 331 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
| 332 | } executed 17 times by 1 test: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||||||||
| 333 | return asn1_time_from_tm(s, ts, V_ASN1_UNDEF); executed 8319 times by 1 test: return asn1_time_from_tm(s, ts, -1);Executed by:
| 8319 | ||||||||||||||||||||||||||||||
| 334 | } | - | ||||||||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||||||||
| 336 | int ASN1_TIME_check(const ASN1_TIME *t) | - | ||||||||||||||||||||||||||||||
| 337 | { | - | ||||||||||||||||||||||||||||||
| 338 | if (t->type == V_ASN1_GENERALIZEDTIME)
| 36-56 | ||||||||||||||||||||||||||||||
| 339 | return ASN1_GENERALIZEDTIME_check(t); executed 56 times by 1 test: return ASN1_GENERALIZEDTIME_check(t);Executed by:
| 56 | ||||||||||||||||||||||||||||||
| 340 | else if (t->type == V_ASN1_UTCTIME)
| 0-36 | ||||||||||||||||||||||||||||||
| 341 | return ASN1_UTCTIME_check(t); executed 36 times by 1 test: return ASN1_UTCTIME_check(t);Executed by:
| 36 | ||||||||||||||||||||||||||||||
| 342 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
| 343 | } | - | ||||||||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||||||||
| 345 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | - | ||||||||||||||||||||||||||||||
| 346 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(const ASN1_TIME *t, | - | ||||||||||||||||||||||||||||||
| 347 | ASN1_GENERALIZEDTIME **out) | - | ||||||||||||||||||||||||||||||
| 348 | { | - | ||||||||||||||||||||||||||||||
| 349 | ASN1_GENERALIZEDTIME *ret = NULL; | - | ||||||||||||||||||||||||||||||
| 350 | struct tm tm; | - | ||||||||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||||||||
| 352 | if (!ASN1_TIME_to_tm(t, &tm))
| 0-16 | ||||||||||||||||||||||||||||||
| 353 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||||||||
| 355 | if (out != NULL)
| 4-12 | ||||||||||||||||||||||||||||||
| 356 | ret = *out; executed 4 times by 1 test: ret = *out;Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||||||||
| 358 | ret = asn1_time_from_tm(ret, &tm, V_ASN1_GENERALIZEDTIME); | - | ||||||||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||||||||
| 360 | if (out != NULL && ret != NULL)
| 0-12 | ||||||||||||||||||||||||||||||
| 361 | *out = ret; executed 4 times by 1 test: *out = ret;Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 362 | - | |||||||||||||||||||||||||||||||
| 363 | return ret; executed 16 times by 1 test: return ret;Executed by:
| 16 | ||||||||||||||||||||||||||||||
| 364 | } | - | ||||||||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||||||||
| 366 | int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | - | ||||||||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||||||||
| 368 | /* Try UTC, if that fails, try GENERALIZED */ | - | ||||||||||||||||||||||||||||||
| 369 | if (ASN1_UTCTIME_set_string(s, str))
| 25-83 | ||||||||||||||||||||||||||||||
| 370 | return 1; executed 25 times by 1 test: return 1;Executed by:
| 25 | ||||||||||||||||||||||||||||||
| 371 | return ASN1_GENERALIZEDTIME_set_string(s, str); executed 83 times by 1 test: return ASN1_GENERALIZEDTIME_set_string(s, str);Executed by:
| 83 | ||||||||||||||||||||||||||||||
| 372 | } | - | ||||||||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||||||||
| 374 | int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str) | - | ||||||||||||||||||||||||||||||
| 375 | { | - | ||||||||||||||||||||||||||||||
| 376 | ASN1_TIME t; | - | ||||||||||||||||||||||||||||||
| 377 | struct tm tm; | - | ||||||||||||||||||||||||||||||
| 378 | int rv = 0; | - | ||||||||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||||||||
| 380 | t.length = strlen(str); | - | ||||||||||||||||||||||||||||||
| 381 | t.data = (unsigned char *)str; | - | ||||||||||||||||||||||||||||||
| 382 | t.flags = ASN1_STRING_FLAG_X509_TIME; | - | ||||||||||||||||||||||||||||||
| 383 | - | |||||||||||||||||||||||||||||||
| 384 | t.type = V_ASN1_UTCTIME; | - | ||||||||||||||||||||||||||||||
| 385 | - | |||||||||||||||||||||||||||||||
| 386 | if (!ASN1_TIME_check(&t)) {
| 3-17 | ||||||||||||||||||||||||||||||
| 387 | t.type = V_ASN1_GENERALIZEDTIME; | - | ||||||||||||||||||||||||||||||
| 388 | if (!ASN1_TIME_check(&t))
| 5-12 | ||||||||||||||||||||||||||||||
| 389 | goto out; executed 12 times by 1 test: goto out;Executed by:
| 12 | ||||||||||||||||||||||||||||||
| 390 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||||||||
| 392 | /* | - | ||||||||||||||||||||||||||||||
| 393 | * Per RFC 5280 (section 4.1.2.5.), the valid input time | - | ||||||||||||||||||||||||||||||
| 394 | * strings should be encoded with the following rules: | - | ||||||||||||||||||||||||||||||
| 395 | * | - | ||||||||||||||||||||||||||||||
| 396 | * 1. UTC: YYMMDDHHMMSSZ, if YY < 50 (20YY) --> UTC: YYMMDDHHMMSSZ | - | ||||||||||||||||||||||||||||||
| 397 | * 2. UTC: YYMMDDHHMMSSZ, if YY >= 50 (19YY) --> UTC: YYMMDDHHMMSSZ | - | ||||||||||||||||||||||||||||||
| 398 | * 3. G'd: YYYYMMDDHHMMSSZ, if YYYY >= 2050 --> G'd: YYYYMMDDHHMMSSZ | - | ||||||||||||||||||||||||||||||
| 399 | * 4. G'd: YYYYMMDDHHMMSSZ, if YYYY < 2050 --> UTC: YYMMDDHHMMSSZ | - | ||||||||||||||||||||||||||||||
| 400 | * | - | ||||||||||||||||||||||||||||||
| 401 | * Only strings of the 4th rule should be reformatted, but since a | - | ||||||||||||||||||||||||||||||
| 402 | * UTC can only present [1950, 2050), so if the given time string | - | ||||||||||||||||||||||||||||||
| 403 | * is less than 1950 (e.g. 19230419000000Z), we do nothing... | - | ||||||||||||||||||||||||||||||
| 404 | */ | - | ||||||||||||||||||||||||||||||
| 405 | - | |||||||||||||||||||||||||||||||
| 406 | if (s != NULL && t.type == V_ASN1_GENERALIZEDTIME) {
| 2-5 | ||||||||||||||||||||||||||||||
| 407 | if (!asn1_time_to_tm(&tm, &t))
| 0-3 | ||||||||||||||||||||||||||||||
| 408 | goto out; never executed: goto out; | 0 | ||||||||||||||||||||||||||||||
| 409 | if (is_utc(tm.tm_year)) {
| 1-2 | ||||||||||||||||||||||||||||||
| 410 | t.length -= 2; | - | ||||||||||||||||||||||||||||||
| 411 | /* | - | ||||||||||||||||||||||||||||||
| 412 | * it's OK to let original t.data go since that's assigned | - | ||||||||||||||||||||||||||||||
| 413 | * to a piece of memory allocated outside of this function. | - | ||||||||||||||||||||||||||||||
| 414 | * new t.data would be freed after ASN1_STRING_copy is done. | - | ||||||||||||||||||||||||||||||
| 415 | */ | - | ||||||||||||||||||||||||||||||
| 416 | t.data = OPENSSL_zalloc(t.length + 1); | - | ||||||||||||||||||||||||||||||
| 417 | if (t.data == NULL)
| 0-1 | ||||||||||||||||||||||||||||||
| 418 | goto out; never executed: goto out; | 0 | ||||||||||||||||||||||||||||||
| 419 | memcpy(t.data, str + 2, t.length); | - | ||||||||||||||||||||||||||||||
| 420 | t.type = V_ASN1_UTCTIME; | - | ||||||||||||||||||||||||||||||
| 421 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||
| 422 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||
| 423 | - | |||||||||||||||||||||||||||||||
| 424 | if (s == NULL || ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t))
| 0-5 | ||||||||||||||||||||||||||||||
| 425 | rv = 1; executed 8 times by 1 test: rv = 1;Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 426 | - | |||||||||||||||||||||||||||||||
| 427 | if (t.data != (unsigned char *)str)
| 1-7 | ||||||||||||||||||||||||||||||
| 428 | OPENSSL_free(t.data); executed 1 time by 1 test: CRYPTO_free(t.data, __FILE__, 428);Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 429 | out: code before this statement executed 8 times by 1 test: out:Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 430 | return rv; executed 20 times by 1 test: return rv;Executed by:
| 20 | ||||||||||||||||||||||||||||||
| 431 | } | - | ||||||||||||||||||||||||||||||
| 432 | - | |||||||||||||||||||||||||||||||
| 433 | int ASN1_TIME_to_tm(const ASN1_TIME *s, struct tm *tm) | - | ||||||||||||||||||||||||||||||
| 434 | { | - | ||||||||||||||||||||||||||||||
| 435 | if (s == NULL) {
| 0-16818 | ||||||||||||||||||||||||||||||
| 436 | time_t now_t; | - | ||||||||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||||||||
| 438 | time(&now_t); | - | ||||||||||||||||||||||||||||||
| 439 | memset(tm, 0, sizeof(*tm)); | - | ||||||||||||||||||||||||||||||
| 440 | if (OPENSSL_gmtime(&now_t, tm) != NULL)
| 0 | ||||||||||||||||||||||||||||||
| 441 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||||||||
| 442 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
| 443 | } | - | ||||||||||||||||||||||||||||||
| 444 | - | |||||||||||||||||||||||||||||||
| 445 | return asn1_time_to_tm(tm, s); executed 16818 times by 1 test: return asn1_time_to_tm(tm, s);Executed by:
| 16818 | ||||||||||||||||||||||||||||||
| 446 | } | - | ||||||||||||||||||||||||||||||
| 447 | - | |||||||||||||||||||||||||||||||
| 448 | int ASN1_TIME_diff(int *pday, int *psec, | - | ||||||||||||||||||||||||||||||
| 449 | const ASN1_TIME *from, const ASN1_TIME *to) | - | ||||||||||||||||||||||||||||||
| 450 | { | - | ||||||||||||||||||||||||||||||
| 451 | struct tm tm_from, tm_to; | - | ||||||||||||||||||||||||||||||
| 452 | - | |||||||||||||||||||||||||||||||
| 453 | if (!ASN1_TIME_to_tm(from, &tm_from))
| 53-8246 | ||||||||||||||||||||||||||||||
| 454 | return 0; executed 53 times by 1 test: return 0;Executed by:
| 53 | ||||||||||||||||||||||||||||||
| 455 | if (!ASN1_TIME_to_tm(to, &tm_to))
| 0-8246 | ||||||||||||||||||||||||||||||
| 456 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
| 457 | return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to); executed 8246 times by 1 test: return OPENSSL_gmtime_diff(pday, psec, &tm_from, &tm_to);Executed by:
| 8246 | ||||||||||||||||||||||||||||||
| 458 | } | - | ||||||||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||||||||
| 460 | static const char _asn1_mon[12][4] = { | - | ||||||||||||||||||||||||||||||
| 461 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | - | ||||||||||||||||||||||||||||||
| 462 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | - | ||||||||||||||||||||||||||||||
| 463 | }; | - | ||||||||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||||||||
| 465 | int ASN1_TIME_print(BIO *bp, const ASN1_TIME *tm) | - | ||||||||||||||||||||||||||||||
| 466 | { | - | ||||||||||||||||||||||||||||||
| 467 | char *v; | - | ||||||||||||||||||||||||||||||
| 468 | int gmt = 0, l; | - | ||||||||||||||||||||||||||||||
| 469 | struct tm stm; | - | ||||||||||||||||||||||||||||||
| 470 | - | |||||||||||||||||||||||||||||||
| 471 | if (!asn1_time_to_tm(&stm, tm)) {
| 10662-14056 | ||||||||||||||||||||||||||||||
| 472 | /* asn1_time_to_tm will check the time type */ | - | ||||||||||||||||||||||||||||||
| 473 | goto err; executed 14056 times by 1 test: goto err;Executed by:
| 14056 | ||||||||||||||||||||||||||||||
| 474 | } | - | ||||||||||||||||||||||||||||||
| 475 | - | |||||||||||||||||||||||||||||||
| 476 | l = tm->length; | - | ||||||||||||||||||||||||||||||
| 477 | v = (char *)tm->data; | - | ||||||||||||||||||||||||||||||
| 478 | if (v[l - 1] == 'Z')
| 2894-7768 | ||||||||||||||||||||||||||||||
| 479 | gmt = 1; executed 7768 times by 1 test: gmt = 1;Executed by:
| 7768 | ||||||||||||||||||||||||||||||
| 480 | - | |||||||||||||||||||||||||||||||
| 481 | if (tm->type == V_ASN1_GENERALIZEDTIME) {
| 4479-6183 | ||||||||||||||||||||||||||||||
| 482 | char *f = NULL; | - | ||||||||||||||||||||||||||||||
| 483 | int f_len = 0; | - | ||||||||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||||||||
| 485 | /* | - | ||||||||||||||||||||||||||||||
| 486 | * Try to parse fractional seconds. '14' is the place of | - | ||||||||||||||||||||||||||||||
| 487 | * 'fraction point' in a GeneralizedTime string. | - | ||||||||||||||||||||||||||||||
| 488 | */ | - | ||||||||||||||||||||||||||||||
| 489 | if (tm->length > 15 && v[14] == '.') {
| 910-3569 | ||||||||||||||||||||||||||||||
| 490 | f = &v[14]; | - | ||||||||||||||||||||||||||||||
| 491 | f_len = 1; | - | ||||||||||||||||||||||||||||||
| 492 | while (14 + f_len < l && ossl_isdigit(f[f_len]))
| 0-14487 | ||||||||||||||||||||||||||||||
| 493 | ++f_len; executed 12114 times by 1 test: ++f_len;Executed by:
| 12114 | ||||||||||||||||||||||||||||||
| 494 | } executed 2373 times by 1 test: end of blockExecuted by:
| 2373 | ||||||||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||||||||
| 496 | return BIO_printf(bp, "%s %2d %02d:%02d:%02d%.*s %d%s", executed 4479 times by 1 test: 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;Executed by:
| 4479 | ||||||||||||||||||||||||||||||
| 497 | _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, executed 4479 times by 1 test: 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;Executed by:
| 4479 | ||||||||||||||||||||||||||||||
| 498 | stm.tm_min, stm.tm_sec, f_len, f, stm.tm_year + 1900, executed 4479 times by 1 test: 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;Executed by:
| 4479 | ||||||||||||||||||||||||||||||
| 499 | (gmt ? " GMT" : "")) > 0; executed 4479 times by 1 test: 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;Executed by:
| 4479 | ||||||||||||||||||||||||||||||
| 500 | } else { | - | ||||||||||||||||||||||||||||||
| 501 | return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", executed 6183 times by 1 test: return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, stm.tm_min, stm.tm_sec, stm.tm_year + 1900, (gmt ? " GMT" : "")) > 0;Executed by:
| 6183 | ||||||||||||||||||||||||||||||
| 502 | _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, executed 6183 times by 1 test: return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, stm.tm_min, stm.tm_sec, stm.tm_year + 1900, (gmt ? " GMT" : "")) > 0;Executed by:
| 6183 | ||||||||||||||||||||||||||||||
| 503 | stm.tm_min, stm.tm_sec, stm.tm_year + 1900, executed 6183 times by 1 test: return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, stm.tm_min, stm.tm_sec, stm.tm_year + 1900, (gmt ? " GMT" : "")) > 0;Executed by:
| 6183 | ||||||||||||||||||||||||||||||
| 504 | (gmt ? " GMT" : "")) > 0; executed 6183 times by 1 test: return BIO_printf(bp, "%s %2d %02d:%02d:%02d %d%s", _asn1_mon[stm.tm_mon], stm.tm_mday, stm.tm_hour, stm.tm_min, stm.tm_sec, stm.tm_year + 1900, (gmt ? " GMT" : "")) > 0;Executed by:
| 6183 | ||||||||||||||||||||||||||||||
| 505 | } | - | ||||||||||||||||||||||||||||||
| 506 | err: | - | ||||||||||||||||||||||||||||||
| 507 | BIO_write(bp, "Bad time value", 14); | - | ||||||||||||||||||||||||||||||
| 508 | return 0; executed 14056 times by 1 test: return 0;Executed by:
| 14056 | ||||||||||||||||||||||||||||||
| 509 | } | - | ||||||||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||||||||
| 511 | int ASN1_TIME_cmp_time_t(const ASN1_TIME *s, time_t t) | - | ||||||||||||||||||||||||||||||
| 512 | { | - | ||||||||||||||||||||||||||||||
| 513 | struct tm stm, ttm; | - | ||||||||||||||||||||||||||||||
| 514 | int day, sec; | - | ||||||||||||||||||||||||||||||
| 515 | - | |||||||||||||||||||||||||||||||
| 516 | if (!ASN1_TIME_to_tm(s, &stm))
| 0-179 | ||||||||||||||||||||||||||||||
| 517 | return -2; never executed: return -2; | 0 | ||||||||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||||||||
| 519 | if (!OPENSSL_gmtime(&t, &ttm))
| 0-179 | ||||||||||||||||||||||||||||||
| 520 | return -2; never executed: return -2; | 0 | ||||||||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||||||||
| 522 | if (!OPENSSL_gmtime_diff(&day, &sec, &ttm, &stm))
| 0-179 | ||||||||||||||||||||||||||||||
| 523 | return -2; never executed: return -2; | 0 | ||||||||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||||||||
| 525 | if (day > 0 || sec > 0)
| 4-155 | ||||||||||||||||||||||||||||||
| 526 | return 1; executed 28 times by 1 test: return 1;Executed by:
| 28 | ||||||||||||||||||||||||||||||
| 527 | if (day < 0 || sec < 0)
| 4-124 | ||||||||||||||||||||||||||||||
| 528 | return -1; executed 31 times by 1 test: return -1;Executed by:
| 31 | ||||||||||||||||||||||||||||||
| 529 | return 0; executed 120 times by 1 test: return 0;Executed by:
| 120 | ||||||||||||||||||||||||||||||
| 530 | } | - | ||||||||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||||||||
| 532 | int ASN1_TIME_normalize(ASN1_TIME *t) | - | ||||||||||||||||||||||||||||||
| 533 | { | - | ||||||||||||||||||||||||||||||
| 534 | struct tm tm; | - | ||||||||||||||||||||||||||||||
| 535 | - | |||||||||||||||||||||||||||||||
| 536 | if (!ASN1_TIME_to_tm(t, &tm))
| 0-29 | ||||||||||||||||||||||||||||||
| 537 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||
| 538 | - | |||||||||||||||||||||||||||||||
| 539 | return asn1_time_from_tm(t, &tm, V_ASN1_UNDEF) != NULL; executed 29 times by 1 test: return asn1_time_from_tm(t, &tm, -1) != ((void *)0) ;Executed by:
| 29 | ||||||||||||||||||||||||||||||
| 540 | } | - | ||||||||||||||||||||||||||||||
| 541 | - | |||||||||||||||||||||||||||||||
| 542 | int ASN1_TIME_compare(const ASN1_TIME *a, const ASN1_TIME *b) | - | ||||||||||||||||||||||||||||||
| 543 | { | - | ||||||||||||||||||||||||||||||
| 544 | int day, sec; | - | ||||||||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||||||||
| 546 | if (!ASN1_TIME_diff(&day, &sec, b, a))
| 0-55 | ||||||||||||||||||||||||||||||
| 547 | return -2; never executed: return -2; | 0 | ||||||||||||||||||||||||||||||
| 548 | if (day > 0 || sec > 0)
| 4-51 | ||||||||||||||||||||||||||||||
| 549 | return 1; executed 8 times by 1 test: return 1;Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 550 | if (day < 0 || sec < 0)
| 7-39 | ||||||||||||||||||||||||||||||
| 551 | return -1; executed 15 times by 1 test: return -1;Executed by:
| 15 | ||||||||||||||||||||||||||||||
| 552 | return 0; executed 32 times by 1 test: return 0;Executed by:
| 32 | ||||||||||||||||||||||||||||||
| 553 | } | - | ||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |