summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2018-11-30 09:30:15 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2018-11-30 09:33:51 +0100
commit30f427fc9bbb24362062dd083d697ef2cf8fa794 (patch)
tree1520f6423686b21044c067d3bcf1c405cef05f9b
parent51be76ac45bebd34ccf00f0c7b8c694ca5b2264d (diff)
downloadgnutls-tmp-well-defined-exp.tar.gz
gnutls_x509_crt_set_expiration_time: accepts GNUTLS_X509_NO_WELL_DEFINED_EXPIRATIONtmp-well-defined-exp
This modifies this function according to its documentation. Resolves: #609 Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
-rw-r--r--lib/x509/time.c4
-rw-r--r--tests/crt_apis.c31
2 files changed, 31 insertions, 4 deletions
diff --git a/lib/x509/time.c b/lib/x509/time.c
index 4d2b789268..947721d96e 100644
--- a/lib/x509/time.c
+++ b/lib/x509/time.c
@@ -238,7 +238,7 @@ gtime_to_suitable_time(time_t gtime, char *str_time, size_t str_time_size, unsig
size_t ret;
struct tm _tm;
- if (gtime == (time_t)-1
+ if (gtime == GNUTLS_X509_NO_WELL_DEFINED_EXPIRATION || gtime == (time_t)-1
#if SIZEOF_LONG == 8
|| gtime >= 253402210800
#endif
@@ -277,7 +277,7 @@ gtime_to_generalTime(time_t gtime, char *str_time, size_t str_time_size)
size_t ret;
struct tm _tm;
- if (gtime == (time_t)-1
+ if (gtime == GNUTLS_X509_NO_WELL_DEFINED_EXPIRATION || gtime == (time_t)-1
#if SIZEOF_LONG == 8
|| gtime >= 253402210800
#endif
diff --git a/tests/crt_apis.c b/tests/crt_apis.c
index cf0c7fd800..876e0b3b09 100644
--- a/tests/crt_apis.c
+++ b/tests/crt_apis.c
@@ -71,7 +71,12 @@ static time_t mytime(time_t * t)
return then;
}
-void doit(void)
+struct tests_st {
+ const char *name;
+ time_t expiration;
+};
+
+static void try_apis(struct tests_st *test)
{
gnutls_x509_privkey_t pkey;
gnutls_x509_crt_t crt;
@@ -88,6 +93,8 @@ void doit(void)
if (ret < 0)
fail("global_init\n");
+ success("testing: %s\n", test->name);
+
gnutls_global_set_time_function(mytime);
gnutls_global_set_log_function(tls_log_func);
if (debug)
@@ -123,7 +130,7 @@ void doit(void)
if (ret != 0)
fail("gnutls_x509_crt_set_serial\n");
- ret = gnutls_x509_crt_set_expiration_time(crt, -1);
+ ret = gnutls_x509_crt_set_expiration_time(crt, test->expiration);
if (ret != 0)
fail("error\n");
@@ -363,3 +370,23 @@ void doit(void)
gnutls_global_deinit();
}
+
+struct tests_st tests[] = {
+ {
+ .name = "-1 as expiration",
+ .expiration = -1
+ },
+ {
+ .name = "No well defined as expiration",
+ .expiration = GNUTLS_X509_NO_WELL_DEFINED_EXPIRATION
+ }
+};
+
+void doit(void)
+{
+ unsigned i;
+
+ for (i=0;i<sizeof(tests)/sizeof(tests[0]);i++) {
+ try_apis(&tests[i]);
+ }
+} \ No newline at end of file