summaryrefslogtreecommitdiff
path: root/pkg/bearssl/patch/0002-Add-functions-to-retrieve-certificate-validity-perio.patch
blob: c025866e69e1f43afc4ff0f8e35928cb9db13cfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From 89dfcdd084486a728c347e14ec619cd46c430ffd Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Thu, 26 Mar 2020 14:17:19 -0700
Subject: [PATCH] Add functions to retrieve certificate validity period from
 br_x509_decoder.

---
 inc/bearssl_x509.h | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/inc/bearssl_x509.h b/inc/bearssl_x509.h
index 7668e1d..a50b8fe 100644
--- a/inc/bearssl_x509.h
+++ b/inc/bearssl_x509.h
@@ -1122,6 +1122,42 @@ br_x509_decoder_last_error(br_x509_decoder_context *ctx)
 	return 0;
 }
 
+/**
+ * \brief Get the time when the certificate becomes valid.
+ *
+ * The time is represented the same as in `br_x509_minimal_set_time()`.
+ * These values should not be read before decoding completed successfully.
+ *
+ * \param ctx      X.509 decoder context.
+ * \param days     receives the days since January 1st, 0 AD.
+ * \param seconds  receives the seconds since midnight (0 to 86400).
+ */
+static inline void
+br_x509_decoder_get_notbefore(br_x509_decoder_context *ctx,
+	uint32_t *days, uint32_t *seconds)
+{
+	*days = ctx->notbefore_days;
+	*seconds = ctx->notbefore_seconds;
+}
+
+/**
+ * \brief Get the time when the certificate is no longer valid.
+ *
+ * The time is represented the same as in `br_x509_minimal_set_time()`.
+ * These values should not be read before decoding completed successfully.
+ *
+ * \param ctx      X.509 decoder context.
+ * \param days     receives the days since January 1st, 0 AD.
+ * \param seconds  receives the seconds since midnight (0 to 86400).
+ */
+static inline void
+br_x509_decoder_get_notafter(br_x509_decoder_context *ctx,
+	uint32_t *days, uint32_t *seconds)
+{
+	*days = ctx->notafter_days;
+	*seconds = ctx->notafter_seconds;
+}
+
 /**
  * \brief Get the "isCA" flag from an X.509 decoder context.
  *
-- 
2.35.1