From fe4309b0de64502398116f648cc7f2068e1a1537 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 13 Jan 2020 14:26:11 +0800 Subject: [PATCH] Add duplication APIs to ASN1_TIME and related types Fixes #10600. Reviewed-by: Richard Levitte Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/10823) --- crypto/asn1/a_gentm.c | 3 ++ crypto/asn1/a_time.c | 1 + crypto/asn1/a_utctm.c | 3 ++ doc/man3/ASN1_TIME_set.pod | 14 ++++++++- include/openssl/asn1.h | 4 +++ test/asn1_time_test.c | 60 ++++++++++++++++++++++++++++++++++++++ util/libcrypto.num | 3 ++ 7 files changed, 87 insertions(+), 1 deletion(-) diff --git a/crypto/asn1/a_gentm.c b/crypto/asn1/a_gentm.c index d82126b0e4..4d31fef8fd 100644 --- a/crypto/asn1/a_gentm.c +++ b/crypto/asn1/a_gentm.c @@ -16,6 +16,9 @@ #include "internal/cryptlib.h" #include #include "asn1_local.h" +#include + +IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME) /* This is the primary function used to parse ASN1_GENERALIZEDTIME */ int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d) diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c index c978248d3e..4c9bf0c430 100644 --- a/crypto/asn1/a_time.c +++ b/crypto/asn1/a_time.c @@ -24,6 +24,7 @@ IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) +IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_TIME) static int is_utc(const int year) { diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c index 47eb93fe84..5965993532 100644 --- a/crypto/asn1/a_utctm.c +++ b/crypto/asn1/a_utctm.c @@ -12,6 +12,9 @@ #include "internal/cryptlib.h" #include #include "asn1_local.h" +#include + +IMPLEMENT_ASN1_DUP_FUNCTION(ASN1_UTCTIME) /* This is the primary function used to parse ASN1_UTCTIME */ int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d) diff --git a/doc/man3/ASN1_TIME_set.pod b/doc/man3/ASN1_TIME_set.pod index ddae0fa326..fc2b9308af 100644 --- a/doc/man3/ASN1_TIME_set.pod +++ b/doc/man3/ASN1_TIME_set.pod @@ -13,7 +13,8 @@ ASN1_TIME_print, ASN1_UTCTIME_print, ASN1_GENERALIZEDTIME_print, ASN1_TIME_diff, ASN1_TIME_cmp_time_t, ASN1_UTCTIME_cmp_time_t, ASN1_TIME_compare, -ASN1_TIME_to_generalizedtime - ASN.1 Time functions +ASN1_TIME_to_generalizedtime, +ASN1_TIME_dup, ASN1_UTCTIME_dup, ASN1_GENERALIZEDTIME_dup - ASN.1 Time functions =head1 SYNOPSIS @@ -58,6 +59,10 @@ ASN1_TIME_to_generalizedtime - ASN.1 Time functions ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); + ASN1_TIME *ASN1_TIME_dup(const ASN1_TIME *t); + ASN1_UTCTIME *ASN1_UTCTIME_dup(const ASN1_UTCTIME *t); + ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_dup(const ASN1_GENERALIZEDTIME *t); + =head1 DESCRIPTION The ASN1_TIME_set(), ASN1_UTCTIME_set() and ASN1_GENERALIZEDTIME_set() @@ -131,6 +136,10 @@ The ASN1_TIME_to_generalizedtime() function converts an B to an B, regardless of year. If either I or I<*out> are NULL, then a new object is allocated and must be freed after use. +The ASN1_TIME_dup(), ASN1_UTCTIME_dup() and ASN1_GENERALIZEDTIME_dup() functions +duplicate the time structure I and return the duplicated result +correspondingly. + =head1 NOTES The B structure corresponds to the ASN.1 structure B