2016-05-18 02:52:22 +08:00
|
|
|
/*
|
2017-07-06 09:39:03 +08:00
|
|
|
* Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 11:40:55 +08:00
|
|
|
*
|
2018-12-06 20:17:34 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-01-17 08:13:14 +08:00
|
|
|
*/
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2016-05-18 02:52:22 +08:00
|
|
|
* GENERALIZEDTIME implementation. Based on UTCTIME
|
2015-01-22 11:40:55 +08:00
|
|
|
*/
|
1999-01-17 08:13:14 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/asn1.h>
|
2012-11-19 23:12:07 +08:00
|
|
|
#include "asn1_locl.h"
|
1999-01-17 08:13:14 +08:00
|
|
|
|
2017-08-04 09:24:03 +08:00
|
|
|
/* This is the primary function used to parse ASN1_GENERALIZEDTIME */
|
2012-11-19 23:12:07 +08:00
|
|
|
int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-07-11 03:01:24 +08:00
|
|
|
/* wrapper around asn1_time_to_tm */
|
2015-01-22 11:40:55 +08:00
|
|
|
if (d->type != V_ASN1_GENERALIZEDTIME)
|
2017-07-11 03:01:24 +08:00
|
|
|
return 0;
|
|
|
|
return asn1_time_to_tm(tm, d);
|
2017-07-27 12:54:27 +08:00
|
|
|
}
|
1999-01-17 08:13:14 +08:00
|
|
|
|
2012-11-19 23:12:07 +08:00
|
|
|
int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *d)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
return asn1_generalizedtime_to_tm(NULL, d);
|
|
|
|
}
|
2012-11-19 23:12:07 +08:00
|
|
|
|
2004-03-16 07:15:26 +08:00
|
|
|
int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ASN1_GENERALIZEDTIME t;
|
1999-01-17 08:13:14 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
t.type = V_ASN1_GENERALIZEDTIME;
|
|
|
|
t.length = strlen(str);
|
|
|
|
t.data = (unsigned char *)str;
|
2017-06-12 04:36:07 +08:00
|
|
|
t.flags = 0;
|
|
|
|
|
2017-08-04 09:24:03 +08:00
|
|
|
if (!ASN1_GENERALIZEDTIME_check(&t))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (s != NULL && !ASN1_STRING_copy(s, &t))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1999-01-17 08:13:14 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
|
2015-01-22 11:40:55 +08:00
|
|
|
time_t t)
|
|
|
|
{
|
|
|
|
return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0);
|
|
|
|
}
|
2008-10-08 06:55:27 +08:00
|
|
|
|
|
|
|
ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
2015-01-22 11:40:55 +08:00
|
|
|
time_t t, int offset_day,
|
|
|
|
long offset_sec)
|
|
|
|
{
|
|
|
|
struct tm *ts;
|
|
|
|
struct tm data;
|
1999-01-17 08:13:14 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
ts = OPENSSL_gmtime(&t, &data);
|
|
|
|
if (ts == NULL)
|
2017-08-04 09:24:03 +08:00
|
|
|
return NULL;
|
2001-05-16 16:44:09 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (offset_day || offset_sec) {
|
|
|
|
if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec))
|
2017-08-04 09:24:03 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1999-01-17 08:13:14 +08:00
|
|
|
|
2017-08-04 09:24:03 +08:00
|
|
|
return asn1_time_from_tm(s, ts, V_ASN1_GENERALIZEDTIME);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2015-09-22 23:05:33 +08:00
|
|
|
|
|
|
|
int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
|
|
|
|
{
|
2017-07-31 08:14:58 +08:00
|
|
|
if (tm->type != V_ASN1_GENERALIZEDTIME)
|
|
|
|
return 0;
|
|
|
|
return ASN1_TIME_print(bp, tm);
|
2015-09-22 23:05:33 +08:00
|
|
|
}
|