Fixes #10600.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/10823)
#include "internal/cryptlib.h"
#include <openssl/asn1.h>
#include "asn1_local.h"
+#include <openssl/asn1t.h>
+
+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)
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)
{
#include "internal/cryptlib.h"
#include <openssl/asn1.h>
#include "asn1_local.h"
+#include <openssl/asn1t.h>
+
+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)
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
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()
B<ASN1_GENERALIZEDTIME>, regardless of year. If either I<out> 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<t> and return the duplicated result
+correspondingly.
+
=head1 NOTES
The B<ASN1_TIME> structure corresponds to the ASN.1 structure B<Time>
ASN1_TIME_to_generalizedtime() returns a pointer to the appropriate time
structure on success or NULL if an error occurred.
+ASN1_TIME_dup(), ASN1_UTCTIME_dup() and ASN1_GENERALIZEDTIME_dup() return a
+pointer to a time structure or NULL if an error occurred.
+
=head1 EXAMPLES
Set a time structure to one hour after the current time and print it out:
DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
+DECLARE_ASN1_DUP_FUNCTION(ASN1_TIME)
+DECLARE_ASN1_DUP_FUNCTION(ASN1_UTCTIME)
+DECLARE_ASN1_DUP_FUNCTION(ASN1_GENERALIZEDTIME)
+
DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
return TEST_int_eq(ASN1_TIME_compare(&td->t1, &td->t2), td->result);
}
+static int test_time_dup(void)
+{
+ int ret = 0;
+ ASN1_TIME *asn1_time = NULL;
+ ASN1_TIME *asn1_time_dup = NULL;
+ ASN1_TIME *asn1_gentime = NULL;
+
+ asn1_time = ASN1_TIME_adj(NULL, time(NULL), 0, 0);
+ if (asn1_time == NULL) {
+ TEST_info("Internal error.");
+ goto err;
+ }
+
+ asn1_gentime = ASN1_TIME_to_generalizedtime(asn1_time, NULL);
+ if (asn1_gentime == NULL) {
+ TEST_info("Internal error.");
+ goto err;
+ }
+
+ asn1_time_dup = ASN1_TIME_dup(asn1_time);
+ if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
+ TEST_info("ASN1_TIME_dup() failed.");
+ goto err;
+ }
+ if (!TEST_int_eq(ASN1_TIME_compare(asn1_time, asn1_time_dup), 0)) {
+ TEST_info("ASN1_TIME_dup() duplicated non-identical value.");
+ goto err;
+ }
+ ASN1_STRING_free(asn1_time_dup);
+
+ asn1_time_dup = ASN1_UTCTIME_dup(asn1_time);
+ if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
+ TEST_info("ASN1_UTCTIME_dup() failed.");
+ goto err;
+ }
+ if (!TEST_int_eq(ASN1_TIME_compare(asn1_time, asn1_time_dup), 0)) {
+ TEST_info("ASN1_UTCTIME_dup() duplicated non-identical UTCTIME value.");
+ goto err;
+ }
+ ASN1_STRING_free(asn1_time_dup);
+
+ asn1_time_dup = ASN1_GENERALIZEDTIME_dup(asn1_gentime);
+ if (!TEST_ptr_ne(asn1_time_dup, NULL)) {
+ TEST_info("ASN1_GENERALIZEDTIME_dup() failed.");
+ goto err;
+ }
+ if (!TEST_int_eq(ASN1_TIME_compare(asn1_gentime, asn1_time_dup), 0)) {
+ TEST_info("ASN1_GENERALIZEDTIME_dup() dup'ed non-identical value.");
+ goto err;
+ }
+
+ ret = 1;
+ err:
+ ASN1_STRING_free(asn1_time);
+ ASN1_STRING_free(asn1_gentime);
+ ASN1_STRING_free(asn1_time_dup);
+ return ret;
+}
+
int setup_tests(void)
{
/*
#endif
}
ADD_ALL_TESTS(test_table_compare, OSSL_NELEM(tbl_compare_testdata));
+ ADD_TEST(test_time_dup);
return 1;
}
EVP_PKEY_CTX_new_from_pkey ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_set_callback ? 3_0_0 EXIST::FUNCTION:
OSSL_SELF_TEST_get_callback ? 3_0_0 EXIST::FUNCTION:
+ASN1_TIME_dup ? 3_0_0 EXIST::FUNCTION:
+ASN1_UTCTIME_dup ? 3_0_0 EXIST::FUNCTION:
+ASN1_GENERALIZEDTIME_dup ? 3_0_0 EXIST::FUNCTION: