Coverage Report

Created: 2025-11-16 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl35/crypto/x509/v3_timespec.c
Line
Count
Source
1
/*
2
 * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (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
#include <stdio.h>
11
#include <openssl/asn1t.h>
12
#include <openssl/x509v3.h>
13
#include <crypto/asn1.h>
14
#include "ext_dat.h"
15
16
static const char *WEEKDAY_NAMES[7] = {
17
    "SUN",
18
    "MON",
19
    "TUE",
20
    "WED",
21
    "THU",
22
    "FRI",
23
    "SAT"
24
};
25
26
static const char *WEEK_NAMES[5] = {
27
    "first",
28
    "second",
29
    "third",
30
    "fourth",
31
    "final"
32
};
33
34
static const char *MONTH_NAMES[12] = {
35
    "JAN",
36
    "FEB",
37
    "MAR",
38
    "APR",
39
    "MAY",
40
    "JUN",
41
    "JUL",
42
    "AUG",
43
    "SEPT",
44
    "OCT",
45
    "NOV",
46
    "DEC"
47
};
48
49
ASN1_SEQUENCE(OSSL_TIME_SPEC_ABSOLUTE) = {
50
    ASN1_EXP_OPT(OSSL_TIME_SPEC_ABSOLUTE, startTime, ASN1_GENERALIZEDTIME, 0),
51
    ASN1_EXP_OPT(OSSL_TIME_SPEC_ABSOLUTE, endTime, ASN1_GENERALIZEDTIME, 1),
52
30.1k
} ASN1_SEQUENCE_END(OSSL_TIME_SPEC_ABSOLUTE)
53
30.1k
54
30.1k
ASN1_SEQUENCE(OSSL_DAY_TIME) = {
55
30.1k
    ASN1_EXP_OPT(OSSL_DAY_TIME, hour, ASN1_INTEGER, 0),
56
30.1k
    ASN1_EXP_OPT(OSSL_DAY_TIME, minute, ASN1_INTEGER, 1),
57
30.1k
    ASN1_EXP_OPT(OSSL_DAY_TIME, second, ASN1_INTEGER, 2),
58
30.1k
} ASN1_SEQUENCE_END(OSSL_DAY_TIME)
59
8.02k
60
8.02k
ASN1_SEQUENCE(OSSL_DAY_TIME_BAND) = {
61
8.02k
    ASN1_EXP_OPT(OSSL_DAY_TIME_BAND, startDayTime, OSSL_DAY_TIME, 0),
62
8.02k
    ASN1_EXP_OPT(OSSL_DAY_TIME_BAND, endDayTime, OSSL_DAY_TIME, 1),
63
30.2k
} ASN1_SEQUENCE_END(OSSL_DAY_TIME_BAND)
64
30.2k
65
30.2k
ASN1_CHOICE(OSSL_NAMED_DAY) = {
66
30.2k
    ASN1_SET_OF(OSSL_NAMED_DAY, choice.intNamedDays, ASN1_ENUMERATED),
67
30.2k
    ASN1_SIMPLE(OSSL_NAMED_DAY, choice.bitNamedDays, ASN1_BIT_STRING),
68
30.2k
} ASN1_CHOICE_END(OSSL_NAMED_DAY)
69
6.17k
70
6.17k
ASN1_CHOICE(OSSL_TIME_SPEC_X_DAY_OF) = {
71
6.17k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.first, OSSL_NAMED_DAY, 1),
72
6.17k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.second, OSSL_NAMED_DAY, 2),
73
6.17k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.third, OSSL_NAMED_DAY, 3),
74
6.17k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.fourth, OSSL_NAMED_DAY, 4),
75
6.17k
    ASN1_EXP(OSSL_TIME_SPEC_X_DAY_OF, choice.fifth, OSSL_NAMED_DAY, 5),
76
7.78k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_X_DAY_OF)
77
7.78k
78
7.78k
ASN1_CHOICE(OSSL_TIME_SPEC_DAY) = {
79
7.78k
    ASN1_SET_OF(OSSL_TIME_SPEC_DAY, choice.intDay, ASN1_INTEGER),
80
7.78k
    ASN1_SIMPLE(OSSL_TIME_SPEC_DAY, choice.bitDay, ASN1_BIT_STRING),
81
7.78k
    ASN1_SIMPLE(OSSL_TIME_SPEC_DAY, choice.dayOf, OSSL_TIME_SPEC_X_DAY_OF),
82
223k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_DAY)
83
223k
84
223k
ASN1_CHOICE(OSSL_TIME_SPEC_WEEKS) = {
85
223k
    ASN1_SIMPLE(OSSL_TIME_SPEC_WEEKS, choice.allWeeks, ASN1_NULL),
86
223k
    ASN1_SET_OF(OSSL_TIME_SPEC_WEEKS, choice.intWeek, ASN1_INTEGER),
87
223k
    ASN1_SIMPLE(OSSL_TIME_SPEC_WEEKS, choice.bitWeek, ASN1_BIT_STRING),
88
223k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_WEEKS)
89
220k
90
220k
ASN1_CHOICE(OSSL_TIME_SPEC_MONTH) = {
91
220k
    ASN1_SIMPLE(OSSL_TIME_SPEC_MONTH, choice.allMonths, ASN1_NULL),
92
220k
    ASN1_SET_OF(OSSL_TIME_SPEC_MONTH, choice.intMonth, ASN1_INTEGER),
93
220k
    ASN1_SIMPLE(OSSL_TIME_SPEC_MONTH, choice.bitMonth, ASN1_BIT_STRING),
94
220k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_MONTH)
95
220k
96
220k
ASN1_SEQUENCE(OSSL_TIME_PERIOD) = {
97
220k
    ASN1_EXP_SET_OF_OPT(OSSL_TIME_PERIOD, timesOfDay, OSSL_DAY_TIME_BAND, 0),
98
220k
    ASN1_EXP_OPT(OSSL_TIME_PERIOD, days, OSSL_TIME_SPEC_DAY, 1),
99
220k
    ASN1_EXP_OPT(OSSL_TIME_PERIOD, weeks, OSSL_TIME_SPEC_WEEKS, 2),
100
220k
    ASN1_EXP_OPT(OSSL_TIME_PERIOD, months, OSSL_TIME_SPEC_MONTH, 3),
101
220k
    ASN1_EXP_SET_OF_OPT(OSSL_TIME_PERIOD, years, ASN1_INTEGER, 4),
102
220k
} ASN1_SEQUENCE_END(OSSL_TIME_PERIOD)
103
63.7k
104
63.7k
ASN1_CHOICE(OSSL_TIME_SPEC_TIME) = {
105
63.7k
    ASN1_SIMPLE(OSSL_TIME_SPEC_TIME, choice.absolute, OSSL_TIME_SPEC_ABSOLUTE),
106
63.7k
    ASN1_SET_OF(OSSL_TIME_SPEC_TIME, choice.periodic, OSSL_TIME_PERIOD)
107
183k
} ASN1_CHOICE_END(OSSL_TIME_SPEC_TIME)
108
183k
109
183k
ASN1_SEQUENCE(OSSL_TIME_SPEC) = {
110
183k
    ASN1_SIMPLE(OSSL_TIME_SPEC, time, OSSL_TIME_SPEC_TIME),
111
183k
    ASN1_OPT(OSSL_TIME_SPEC, notThisTime, ASN1_FBOOLEAN),
112
183k
    ASN1_OPT(OSSL_TIME_SPEC, timeZone, ASN1_INTEGER),
113
183k
} ASN1_SEQUENCE_END(OSSL_TIME_SPEC)
114
53.4k
115
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_DAY_TIME)
116
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_DAY_TIME_BAND)
117
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_DAY)
118
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_WEEKS)
119
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_MONTH)
120
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_NAMED_DAY)
121
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_X_DAY_OF)
122
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_ABSOLUTE)
123
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC_TIME)
124
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_SPEC)
125
53.4k
IMPLEMENT_ASN1_FUNCTIONS(OSSL_TIME_PERIOD)
126
53.4k
127
53.4k
static int i2r_OSSL_TIME_SPEC_ABSOLUTE(X509V3_EXT_METHOD *method,
128
53.4k
                                       OSSL_TIME_SPEC_ABSOLUTE *time,
129
53.4k
                                       BIO *out, int indent)
130
53.4k
{
131
3.15k
    if (time->startTime != NULL && time->endTime != NULL) {
132
0
        if (!BIO_puts(out, "Any time between "))
133
0
            return 0;
134
0
        if (!ossl_asn1_time_print_ex(out, time->startTime, 0))
135
0
            return 0;
136
0
        if (!BIO_puts(out, " and "))
137
0
            return 0;
138
0
        if (!ossl_asn1_time_print_ex(out, time->endTime, 0))
139
0
            return 0;
140
3.15k
    } else if (time->startTime != NULL) {
141
0
        if (!BIO_puts(out, "Any time after "))
142
0
            return 0;
143
0
        if (!ossl_asn1_time_print_ex(out, time->startTime, 0))
144
0
            return 0;
145
0
        if (BIO_printf(out, "%.*s", time->startTime->length, time->startTime->data) <= 0)
146
0
            return 0;
147
3.15k
    } else if (time->endTime != NULL) {
148
0
        if (!BIO_puts(out, "Any time until "))
149
0
            return 0;
150
0
        if (!ossl_asn1_time_print_ex(out, time->endTime, 0))
151
0
            return 0;
152
3.15k
    } else { /* Invalid: there must be SOME time specified. */
153
3.15k
        return BIO_puts(out, "INVALID (EMPTY)");
154
3.15k
    }
155
0
    return 1;
156
3.15k
}
157
158
static int i2r_OSSL_DAY_TIME(X509V3_EXT_METHOD *method,
159
                             OSSL_DAY_TIME *dt,
160
                             BIO *out, int indent)
161
36
{
162
36
    int64_t h = 0;
163
36
    int64_t m = 0;
164
36
    int64_t s = 0;
165
166
36
    if (!dt->hour || !ASN1_INTEGER_get_int64(&h, dt->hour))
167
36
        return 0;
168
0
    if (dt->minute && !ASN1_INTEGER_get_int64(&m, dt->minute))
169
0
        return 0;
170
0
    if (dt->minute && !ASN1_INTEGER_get_int64(&s, dt->second))
171
0
        return 0;
172
0
    return BIO_printf(out, "%02lld:%02lld:%02lld",
173
0
                      (long long int)h, (long long int)m, (long long int)s) > 0;
174
0
}
175
176
static int i2r_OSSL_DAY_TIME_BAND(X509V3_EXT_METHOD *method,
177
                                  OSSL_DAY_TIME_BAND *band,
178
                                  BIO *out, int indent)
179
894
{
180
894
    if (band->startDayTime) {
181
18
        if (!i2r_OSSL_DAY_TIME(method, band->startDayTime, out, indent))
182
18
            return 0;
183
876
    } else if (!BIO_puts(out, "00:00:00")) {
184
0
        return 0;
185
0
    }
186
876
    if (!BIO_puts(out, " - "))
187
0
        return 0;
188
876
    if (band->endDayTime) {
189
18
        if (!i2r_OSSL_DAY_TIME(method, band->endDayTime, out, indent))
190
18
            return 0;
191
858
    } else if (!BIO_puts(out, "23:59:59")) {
192
0
        return 0;
193
0
    }
194
858
    return 1;
195
876
}
196
197
static int print_int_month(BIO *out, int64_t month)
198
320
{
199
320
    switch (month) {
200
191
    case (OSSL_TIME_SPEC_INT_MONTH_JAN):
201
191
        return BIO_puts(out, "JAN");
202
0
    case (OSSL_TIME_SPEC_INT_MONTH_FEB):
203
0
        return BIO_puts(out, "FEB");
204
7
    case (OSSL_TIME_SPEC_INT_MONTH_MAR):
205
7
        return BIO_puts(out, "MAR");
206
3
    case (OSSL_TIME_SPEC_INT_MONTH_APR):
207
3
        return BIO_puts(out, "APR");
208
9
    case (OSSL_TIME_SPEC_INT_MONTH_MAY):
209
9
        return BIO_puts(out, "MAY");
210
3
    case (OSSL_TIME_SPEC_INT_MONTH_JUN):
211
3
        return BIO_puts(out, "JUN");
212
7
    case (OSSL_TIME_SPEC_INT_MONTH_JUL):
213
7
        return BIO_puts(out, "JUL");
214
1
    case (OSSL_TIME_SPEC_INT_MONTH_AUG):
215
1
        return BIO_puts(out, "AUG");
216
4
    case (OSSL_TIME_SPEC_INT_MONTH_SEP):
217
4
        return BIO_puts(out, "SEP");
218
9
    case (OSSL_TIME_SPEC_INT_MONTH_OCT):
219
9
        return BIO_puts(out, "OCT");
220
4
    case (OSSL_TIME_SPEC_INT_MONTH_NOV):
221
4
        return BIO_puts(out, "NOV");
222
4
    case (OSSL_TIME_SPEC_INT_MONTH_DEC):
223
4
        return BIO_puts(out, "DEC");
224
78
    default:
225
78
        return 0;
226
320
    }
227
0
    return 0;
228
320
}
229
230
static int print_bit_month(BIO *out, ASN1_BIT_STRING *bs)
231
293
{
232
293
    int i = OSSL_TIME_SPEC_BIT_MONTH_JAN;
233
293
    int j = 0;
234
235
3.80k
    for (; i <= OSSL_TIME_SPEC_BIT_MONTH_DEC; i++) {
236
3.51k
        if (ASN1_BIT_STRING_get_bit(bs, i)) {
237
1.74k
            if (j > 0 && !BIO_puts(out, ", "))
238
0
                return 0;
239
1.74k
            j++;
240
1.74k
            if (!BIO_puts(out, MONTH_NAMES[i]))
241
0
                return 0;
242
1.74k
        }
243
3.51k
    }
244
293
    return 1;
245
293
}
246
247
/*
248
 * It might seem like you could just print the bits of the string numerically,
249
 * but the fifth bit has the special meaning of "the final week" imputed to it
250
 * by the text of ITU-T Recommendation X.520.
251
 */
252
static int print_bit_week(BIO *out, ASN1_BIT_STRING *bs)
253
186
{
254
186
    int i = OSSL_TIME_SPEC_BIT_WEEKS_1;
255
186
    int j = 0;
256
257
1.11k
    for (; i <= OSSL_TIME_SPEC_BIT_WEEKS_5; i++) {
258
930
        if (ASN1_BIT_STRING_get_bit(bs, i)) {
259
739
            if (j > 0 && !BIO_puts(out, ", "))
260
0
                return 0;
261
739
            j++;
262
739
            if (!BIO_puts(out, WEEK_NAMES[i]))
263
0
                return 0;
264
739
        }
265
930
    }
266
186
    return 1;
267
186
}
268
269
static int print_day_of_week(BIO *out, ASN1_BIT_STRING *bs)
270
688
{
271
688
    int i = OSSL_TIME_SPEC_DAY_BIT_SUN;
272
688
    int j = 0;
273
274
5.50k
    for (; i <= OSSL_TIME_SPEC_DAY_BIT_SAT; i++) {
275
4.81k
        if (ASN1_BIT_STRING_get_bit(bs, i)) {
276
3.25k
            if (j > 0 && !BIO_puts(out, ", "))
277
0
                return 0;
278
3.25k
            j++;
279
3.25k
            if (!BIO_puts(out, WEEKDAY_NAMES[i]))
280
0
                return 0;
281
3.25k
        }
282
4.81k
    }
283
688
    return 1;
284
688
}
285
286
static int print_int_day_of_week(BIO *out, int64_t dow)
287
0
{
288
0
    switch (dow) {
289
0
    case (OSSL_TIME_SPEC_DAY_INT_SUN):
290
0
        return BIO_puts(out, "SUN");
291
0
    case (OSSL_TIME_SPEC_DAY_INT_MON):
292
0
        return BIO_puts(out, "MON");
293
0
    case (OSSL_TIME_SPEC_DAY_INT_TUE):
294
0
        return BIO_puts(out, "TUE");
295
0
    case (OSSL_TIME_SPEC_DAY_INT_WED):
296
0
        return BIO_puts(out, "WED");
297
0
    case (OSSL_TIME_SPEC_DAY_INT_THU):
298
0
        return BIO_puts(out, "THU");
299
0
    case (OSSL_TIME_SPEC_DAY_INT_FRI):
300
0
        return BIO_puts(out, "FRI");
301
0
    case (OSSL_TIME_SPEC_DAY_INT_SAT):
302
0
        return BIO_puts(out, "SAT");
303
0
    default:
304
0
        return 0;
305
0
    }
306
0
    return 0;
307
0
}
308
309
static int print_int_named_day(BIO *out, int64_t nd)
310
0
{
311
0
    switch (nd) {
312
0
    case (OSSL_NAMED_DAY_INT_SUN):
313
0
        return BIO_puts(out, "SUN");
314
0
    case (OSSL_NAMED_DAY_INT_MON):
315
0
        return BIO_puts(out, "MON");
316
0
    case (OSSL_NAMED_DAY_INT_TUE):
317
0
        return BIO_puts(out, "TUE");
318
0
    case (OSSL_NAMED_DAY_INT_WED):
319
0
        return BIO_puts(out, "WED");
320
0
    case (OSSL_NAMED_DAY_INT_THU):
321
0
        return BIO_puts(out, "THU");
322
0
    case (OSSL_NAMED_DAY_INT_FRI):
323
0
        return BIO_puts(out, "FRI");
324
0
    case (OSSL_NAMED_DAY_INT_SAT):
325
0
        return BIO_puts(out, "SAT");
326
0
    default:
327
0
        return 0;
328
0
    }
329
0
    return 0;
330
0
}
331
332
static int print_bit_named_day(BIO *out, ASN1_BIT_STRING *bs)
333
598
{
334
598
    return print_day_of_week(out, bs);
335
598
}
336
337
static int i2r_OSSL_PERIOD(X509V3_EXT_METHOD *method,
338
                           OSSL_TIME_PERIOD *p,
339
                           BIO *out, int indent)
340
14.4k
{
341
14.4k
    int i;
342
14.4k
    OSSL_DAY_TIME_BAND *band;
343
14.4k
    ASN1_INTEGER *big_val;
344
14.4k
    int64_t small_val;
345
14.4k
    OSSL_NAMED_DAY *nd;
346
347
14.4k
    if (BIO_printf(out, "%*sPeriod:\n", indent, "") <= 0)
348
0
        return 0;
349
14.4k
    if (p->timesOfDay) {
350
184
        if (BIO_printf(out, "%*sDaytime bands:\n", indent + 4, "") <= 0)
351
0
            return 0;
352
1.04k
        for (i = 0; i < sk_OSSL_DAY_TIME_BAND_num(p->timesOfDay); i++) {
353
894
            band = sk_OSSL_DAY_TIME_BAND_value(p->timesOfDay, i);
354
894
            if (BIO_printf(out, "%*s", indent + 8, "") <= 0)
355
0
                return 0;
356
894
            if (!i2r_OSSL_DAY_TIME_BAND(method, band, out, indent + 8))
357
36
                return 0;
358
858
            if (!BIO_puts(out, "\n"))
359
0
                return 0;
360
858
        }
361
184
    }
362
14.3k
    if (p->days) {
363
827
        if (p->days->type == OSSL_TIME_SPEC_DAY_TYPE_INT) {
364
123
            if (p->weeks != NULL) {
365
1
                if (BIO_printf(out, "%*sDays of the week: ", indent + 4, "") <= 0)
366
0
                    return 0;
367
122
            } else if (p->months != NULL) {
368
10
                if (BIO_printf(out, "%*sDays of the month: ", indent + 4, "") <= 0)
369
0
                    return 0;
370
112
            } else if (p->years != NULL) {
371
0
                if (BIO_printf(out, "%*sDays of the year: ", indent + 4, "") <= 0)
372
0
                    return 0;
373
0
            }
374
704
        } else {
375
704
            if (BIO_printf(out, "%*sDays: ", indent + 4, "") <= 0)
376
0
                return 0;
377
704
        }
378
379
827
        switch (p->days->type) {
380
123
        case (OSSL_TIME_SPEC_DAY_TYPE_INT):
381
229
            for (i = 0; i < sk_ASN1_INTEGER_num(p->days->choice.intDay); i++) {
382
172
                big_val = sk_ASN1_INTEGER_value(p->days->choice.intDay, i);
383
172
                if (!ASN1_INTEGER_get_int64(&small_val, big_val))
384
66
                    return 0;
385
106
                if (i > 0 && !BIO_puts(out, ", "))
386
0
                    return 0;
387
                /* If weeks is defined, then print day of week by name. */
388
106
                if (p->weeks != NULL) {
389
0
                    if (!print_int_day_of_week(out, small_val))
390
0
                        return 0;
391
106
                } else if (BIO_printf(out, "%lld", (long long int)small_val) <= 0) {
392
0
                    return 0;
393
0
                }
394
106
            }
395
57
            break;
396
90
        case (OSSL_TIME_SPEC_DAY_TYPE_BIT):
397
90
            if (!print_day_of_week(out, p->days->choice.bitDay))
398
0
                return 0;
399
90
            break;
400
614
        case (OSSL_TIME_SPEC_DAY_TYPE_DAY_OF):
401
614
            switch (p->days->choice.dayOf->type) {
402
22
            case (OSSL_TIME_SPEC_X_DAY_OF_FIRST):
403
22
                if (!BIO_puts(out, "FIRST "))
404
0
                    return 0;
405
22
                nd = p->days->choice.dayOf->choice.first;
406
22
                break;
407
23
            case (OSSL_TIME_SPEC_X_DAY_OF_SECOND):
408
23
                if (!BIO_puts(out, "SECOND "))
409
0
                    return 0;
410
23
                nd = p->days->choice.dayOf->choice.second;
411
23
                break;
412
509
            case (OSSL_TIME_SPEC_X_DAY_OF_THIRD):
413
509
                if (!BIO_puts(out, "THIRD "))
414
0
                    return 0;
415
509
                nd = p->days->choice.dayOf->choice.third;
416
509
                break;
417
23
            case (OSSL_TIME_SPEC_X_DAY_OF_FOURTH):
418
23
                if (!BIO_puts(out, "FOURTH "))
419
0
                    return 0;
420
23
                nd = p->days->choice.dayOf->choice.fourth;
421
23
                break;
422
37
            case (OSSL_TIME_SPEC_X_DAY_OF_FIFTH):
423
37
                if (!BIO_puts(out, "FIFTH "))
424
0
                    return 0;
425
37
                nd = p->days->choice.dayOf->choice.fifth;
426
37
                break;
427
0
            default:
428
0
                return 0;
429
614
            }
430
614
            switch (nd->type) {
431
16
            case (OSSL_NAMED_DAY_TYPE_INT):
432
16
                if (!ASN1_INTEGER_get_int64(&small_val, nd->choice.intNamedDays))
433
16
                    return 0;
434
0
                if (!print_int_named_day(out, small_val))
435
0
                    return 0;
436
0
                break;
437
598
            case (OSSL_NAMED_DAY_TYPE_BIT):
438
598
                if (!print_bit_named_day(out, nd->choice.bitNamedDays))
439
0
                    return 0;
440
598
                break;
441
598
            default:
442
0
                return 0;
443
614
            }
444
598
            break;
445
598
        default:
446
0
            return 0;
447
827
        }
448
745
        if (!BIO_puts(out, "\n"))
449
0
            return 0;
450
745
    }
451
14.2k
    if (p->weeks) {
452
268
        if (p->weeks->type == OSSL_TIME_SPEC_WEEKS_TYPE_INT) {
453
58
            if (p->months != NULL) {
454
3
                if (BIO_printf(out, "%*sWeeks of the month: ", indent + 4, "") <= 0)
455
0
                    return 0;
456
55
            } else if (p->years != NULL) {
457
0
                if (BIO_printf(out, "%*sWeeks of the year: ", indent + 4, "") <= 0)
458
0
                    return 0;
459
0
            }
460
210
        } else {
461
210
            if (BIO_printf(out, "%*sWeeks: ", indent + 4, "") <= 0)
462
0
                return 0;
463
210
        }
464
465
268
        switch (p->weeks->type) {
466
24
        case (OSSL_TIME_SPEC_WEEKS_TYPE_ALL):
467
24
            if (!BIO_puts(out, "ALL"))
468
0
                return 0;
469
24
            break;
470
58
        case (OSSL_TIME_SPEC_WEEKS_TYPE_INT):
471
116
            for (i = 0; i < sk_ASN1_INTEGER_num(p->weeks->choice.intWeek); i++) {
472
69
                big_val = sk_ASN1_INTEGER_value(p->weeks->choice.intWeek, i);
473
69
                if (!ASN1_INTEGER_get_int64(&small_val, big_val))
474
11
                    return 0;
475
58
                if (i > 0 && !BIO_puts(out, ", "))
476
0
                    return 0;
477
58
                if (!BIO_printf(out, "%lld", (long long int)small_val))
478
0
                    return 0;
479
58
            }
480
47
            break;
481
186
        case (OSSL_TIME_SPEC_WEEKS_TYPE_BIT):
482
186
            if (!print_bit_week(out, p->weeks->choice.bitWeek))
483
0
                return 0;
484
186
            break;
485
186
        default:
486
0
            return 0;
487
268
        }
488
257
        if (!BIO_puts(out, "\n"))
489
0
            return 0;
490
257
    }
491
14.2k
    if (p->months) {
492
484
        if (BIO_printf(out, "%*sMonths: ", indent + 4, "") <= 0)
493
0
            return 0;
494
484
        switch (p->months->type) {
495
34
        case (OSSL_TIME_SPEC_MONTH_TYPE_ALL):
496
34
            if (!BIO_puts(out, "ALL"))
497
0
                return 0;
498
34
            break;
499
157
        case (OSSL_TIME_SPEC_MONTH_TYPE_INT):
500
399
            for (i = 0; i < sk_ASN1_INTEGER_num(p->months->choice.intMonth); i++) {
501
330
                big_val = sk_ASN1_INTEGER_value(p->months->choice.intMonth, i);
502
330
                if (!ASN1_INTEGER_get_int64(&small_val, big_val))
503
10
                    return 0;
504
320
                if (i > 0 && !BIO_puts(out, ", "))
505
0
                    return 0;
506
320
                if (!print_int_month(out, small_val))
507
78
                    return 0;
508
320
            }
509
69
            break;
510
293
        case (OSSL_TIME_SPEC_MONTH_TYPE_BIT):
511
293
            if (!print_bit_month(out, p->months->choice.bitMonth))
512
0
                return 0;
513
293
            break;
514
293
        default:
515
0
            return 0;
516
484
        }
517
396
        if (!BIO_puts(out, "\n"))
518
0
            return 0;
519
396
    }
520
14.1k
    if (p->years) {
521
102
        if (BIO_printf(out, "%*sYears: ", indent + 4, "") <= 0)
522
0
            return 0;
523
259
        for (i = 0; i < sk_ASN1_INTEGER_num(p->years); i++) {
524
160
            big_val = sk_ASN1_INTEGER_value(p->years, i);
525
160
            if (!ASN1_INTEGER_get_int64(&small_val, big_val))
526
3
                return 0;
527
157
            if (i > 0 && !BIO_puts(out, ", "))
528
0
                return 0;
529
157
            if (BIO_printf(out, "%04lld", (long long int)small_val) <= 0)
530
0
                return 0;
531
157
        }
532
102
    }
533
14.1k
    return 1;
534
14.1k
}
535
536
static int i2r_OSSL_TIME_SPEC_TIME(X509V3_EXT_METHOD *method,
537
                                   OSSL_TIME_SPEC_TIME *time,
538
                                   BIO *out, int indent)
539
12.7k
{
540
12.7k
    OSSL_TIME_PERIOD *tp;
541
12.7k
    int i;
542
543
12.7k
    switch (time->type) {
544
3.15k
    case (OSSL_TIME_SPEC_TIME_TYPE_ABSOLUTE):
545
3.15k
        if (BIO_printf(out, "%*sAbsolute: ", indent, "") <= 0)
546
0
            return 0;
547
3.15k
        if (i2r_OSSL_TIME_SPEC_ABSOLUTE(method, time->choice.absolute, out, indent + 4) <= 0)
548
0
            return 0;
549
3.15k
        return BIO_puts(out, "\n");
550
9.56k
    case (OSSL_TIME_SPEC_TIME_TYPE_PERIODIC):
551
9.56k
        if (BIO_printf(out, "%*sPeriodic:\n", indent, "") <= 0)
552
0
            return 0;
553
23.7k
        for (i = 0; i < sk_OSSL_TIME_PERIOD_num(time->choice.periodic); i++) {
554
14.4k
            if (i > 0 && !BIO_puts(out, "\n"))
555
0
                return 0;
556
14.4k
            tp = sk_OSSL_TIME_PERIOD_value(time->choice.periodic, i);
557
14.4k
            if (!i2r_OSSL_PERIOD(method, tp, out, indent + 4))
558
220
                return 0;
559
14.4k
        }
560
9.34k
        return BIO_puts(out, "\n");
561
0
    default:
562
0
        return 0;
563
12.7k
    }
564
0
    return 0;
565
12.7k
}
566
567
static int i2r_OSSL_TIME_SPEC(X509V3_EXT_METHOD *method,
568
                              OSSL_TIME_SPEC *time,
569
                              BIO *out, int indent)
570
12.7k
{
571
12.7k
    int64_t tz;
572
573
12.7k
    if (time->timeZone) {
574
1.78k
        if (ASN1_INTEGER_get_int64(&tz, time->timeZone) != 1)
575
25
            return 0;
576
1.76k
        if (BIO_printf(out, "%*sTimezone: UTC%+03lld:00\n", indent, "", (long long int)tz) <= 0)
577
0
            return 0;
578
1.76k
    }
579
12.7k
    if (time->notThisTime > 0) {
580
366
        if (BIO_printf(out, "%*sNOT this time:\n", indent, "") <= 0)
581
0
            return 0;
582
12.3k
    } else if (BIO_printf(out, "%*sTime:\n", indent, "") <= 0) {
583
0
        return 0;
584
0
    }
585
12.7k
    return i2r_OSSL_TIME_SPEC_TIME(method, time->time, out, indent + 4);
586
12.7k
}
587
588
const X509V3_EXT_METHOD ossl_v3_time_specification = {
589
    NID_time_specification, X509V3_EXT_MULTILINE,
590
    ASN1_ITEM_ref(OSSL_TIME_SPEC),
591
    0, 0, 0, 0,
592
    0, 0,
593
    0,
594
    0,
595
    (X509V3_EXT_I2R)i2r_OSSL_TIME_SPEC,
596
    NULL,
597
    NULL
598
};