summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbeck <>2017-05-06 17:12:59 +0000
committerbeck <>2017-05-06 17:12:59 +0000
commit853167f231fa10e61d7747b6f028087e76d0eaa6 (patch)
treedc9c35b12d4ec6d0389f08be9ff6d7183a4f80d4
parentd9dc0bed247af8759a2ecc0116b8f9539291435e (diff)
downloadopenbsd-853167f231fa10e61d7747b6f028087e76d0eaa6.tar.gz
openbsd-853167f231fa10e61d7747b6f028087e76d0eaa6.tar.bz2
openbsd-853167f231fa10e61d7747b6f028087e76d0eaa6.zip
Add ASN1_TIME_set_tm to set an asn1 from a struct tm *
ok jsing@
-rw-r--r--src/lib/libcrypto/asn1/a_time_tm.c12
-rw-r--r--src/lib/libcrypto/asn1/asn1.h3
-rw-r--r--src/lib/libcrypto/man/ASN1_time_parse.334
3 files changed, 44 insertions, 5 deletions
diff --git a/src/lib/libcrypto/asn1/a_time_tm.c b/src/lib/libcrypto/asn1/a_time_tm.c
index b2f65045b5..f0afc00be4 100644
--- a/src/lib/libcrypto/asn1/a_time_tm.c
+++ b/src/lib/libcrypto/asn1/a_time_tm.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_time_tm.c,v 1.11 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: a_time_tm.c,v 1.12 2017/05/06 17:12:59 beck Exp $ */
2/* 2/*
3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2015 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -304,6 +304,16 @@ ASN1_TIME_set(ASN1_TIME *s, time_t t)
304} 304}
305 305
306ASN1_TIME * 306ASN1_TIME *
307ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm)
308{
309 time_t t;
310
311 if ((t = timegm(tm)) == -1)
312 return NULL;
313 return (ASN1_TIME_adj(s, t, 0, 0));
314}
315
316ASN1_TIME *
307ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) 317ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec)
308{ 318{
309 return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec, RFC5280)); 319 return (ASN1_TIME_adj_internal(s, t, offset_day, offset_sec, RFC5280));
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index e35c865e1f..da16d5c529 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1.h,v 1.42 2016/12/30 16:29:45 jsing Exp $ */ 1/* $OpenBSD: asn1.h,v 1.43 2017/05/06 17:12:59 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -939,6 +939,7 @@ extern const ASN1_ITEM ASN1_TIME_it;
939extern const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it; 939extern const ASN1_ITEM ASN1_OCTET_STRING_NDEF_it;
940 940
941ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); 941ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t);
942ASN1_TIME *ASN1_TIME_set_tm(ASN1_TIME *s, struct tm *tm);
942ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, 943ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day,
943 long offset_sec); 944 long offset_sec);
944int ASN1_TIME_check(ASN1_TIME *t); 945int ASN1_TIME_check(ASN1_TIME *t);
diff --git a/src/lib/libcrypto/man/ASN1_time_parse.3 b/src/lib/libcrypto/man/ASN1_time_parse.3
index 77f8b129e2..f14ada5369 100644
--- a/src/lib/libcrypto/man/ASN1_time_parse.3
+++ b/src/lib/libcrypto/man/ASN1_time_parse.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: ASN1_time_parse.3,v 1.3 2016/11/05 09:13:56 jmc Exp $ 1.\" $OpenBSD: ASN1_time_parse.3,v 1.4 2017/05/06 17:12:59 beck Exp $
2.\" 2.\"
3.\" Copyright (c) 2016 Bob Beck <beck@openbsd.org> 3.\" Copyright (c) 2016 Bob Beck <beck@openbsd.org>
4.\" 4.\"
@@ -14,12 +14,13 @@
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\" 16.\"
17.Dd $Mdocdate: November 5 2016 $ 17.Dd $Mdocdate: May 6 2017 $
18.Dt ASN1_TIME_PARSE 3 18.Dt ASN1_TIME_PARSE 3
19.Os 19.Os
20.Sh NAME 20.Sh NAME
21.Nm ASN1_time_parse , 21.Nm ASN1_time_parse ,
22.Nm ASN1_time_tm_cmp 22.Nm ASN1_time_tm_cmp,
23.Nm ASN1_TIME_set_tm
23.Nd LibreSSL utilities for ASN.1 time types 24.Nd LibreSSL utilities for ASN.1 time types
24.Sh SYNOPSIS 25.Sh SYNOPSIS
25.In openssl/asn1.h 26.In openssl/asn1.h
@@ -27,6 +28,8 @@
27.Fn ASN1_time_parse "const char *bytes" "size_t len" "struct tm *tm" "int mode" 28.Fn ASN1_time_parse "const char *bytes" "size_t len" "struct tm *tm" "int mode"
28.Ft int 29.Ft int
29.Fn ASN1_time_tm_cmp "struct tm *tm1" "struct tm *tm2" 30.Fn ASN1_time_tm_cmp "struct tm *tm1" "struct tm *tm2"
31.Ft ASN1_TIME *
32.Fn ASN1_TIME_set_tm "ASN1_TIME *s" "struct tm *tm"
30.Sh DESCRIPTION 33.Sh DESCRIPTION
31The 34The
32.Fn ASN1_time_parse 35.Fn ASN1_time_parse
@@ -62,6 +65,24 @@ function compares two times in
62.Ar tm1 65.Ar tm1
63and 66and
64.Ar tm2 . 67.Ar tm2 .
68.Pp
69The function
70.Fn ASN1_TIME_set_tm
71sets the
72.Vt ASN1_TIME
73structure
74.Fa s
75to the time represented by the
76.Vt strict tm
77value pointed to by
78.Fa tm .
79If
80.Fa s
81is
82.Dv NULL ,
83a new
84.Vt ASN1_TIME
85structure is allocated and returned.
65.Sh RETURN VALUES 86.Sh RETURN VALUES
66.Fn ASN1_parse_time 87.Fn ASN1_parse_time
67returns 88returns
@@ -97,3 +118,10 @@ is greater than
97is the same as 118is the same as
98.Ar tm2 . 119.Ar tm2 .
99.El 120.El
121.Pp
122.Fn ASN1_TIME_set_tm
123returns a pointer to an
124.Vt ASN1_TIME
125structure or
126.Dv NULL
127if an error occurred.