summaryrefslogtreecommitdiff
path: root/sshkey.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-11-19 01:08:55 +0000
committerDamien Miller <djm@mindrot.org>2015-11-19 12:11:37 +1100
commit499cf36fecd6040e30e2912dd25655bc574739a7 (patch)
tree26ff48a460c48b89f3e53cbc88345e663ae25e0b /sshkey.c
parentbcb7bc77bbb1535d1008c7714085556f3065d99d (diff)
upstream commit
move the certificate validity formatting code to sshkey.[ch] Upstream-ID: f05f7c78fab20d02ff1d5ceeda533ef52e8fe523
Diffstat (limited to 'sshkey.c')
-rw-r--r--sshkey.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/sshkey.c b/sshkey.c
index b60f325f7..dc16fe92c 100644
--- a/sshkey.c
+++ b/sshkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshkey.c,v 1.26 2015/11/16 23:47:52 millert Exp $ */ 1/* $OpenBSD: sshkey.c,v 1.27 2015/11/19 01:08:55 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Alexander von Gernler. All rights reserved. 4 * Copyright (c) 2008 Alexander von Gernler. All rights reserved.
@@ -2536,6 +2536,43 @@ sshkey_cert_check_authority(const struct sshkey *k,
2536 return 0; 2536 return 0;
2537} 2537}
2538 2538
2539size_t
2540sshkey_format_cert_validity(const struct sshkey_cert *cert, char *s, size_t l)
2541{
2542 char from[32], to[32], ret[64];
2543 time_t tt;
2544 struct tm *tm;
2545
2546 *from = *to = '\0';
2547 if (cert->valid_after == 0 &&
2548 cert->valid_before == 0xffffffffffffffffULL)
2549 return strlcpy(s, "forever", l);
2550
2551 if (cert->valid_after != 0) {
2552 /* XXX revisit INT_MAX in 2038 :) */
2553 tt = cert->valid_after > INT_MAX ?
2554 INT_MAX : cert->valid_after;
2555 tm = localtime(&tt);
2556 strftime(from, sizeof(from), "%Y-%m-%dT%H:%M:%S", tm);
2557 }
2558 if (cert->valid_before != 0xffffffffffffffffULL) {
2559 /* XXX revisit INT_MAX in 2038 :) */
2560 tt = cert->valid_before > INT_MAX ?
2561 INT_MAX : cert->valid_before;
2562 tm = localtime(&tt);
2563 strftime(to, sizeof(to), "%Y-%m-%dT%H:%M:%S", tm);
2564 }
2565
2566 if (cert->valid_after == 0)
2567 snprintf(ret, sizeof(ret), "before %s", to);
2568 else if (cert->valid_before == 0xffffffffffffffffULL)
2569 snprintf(ret, sizeof(ret), "after %s", from);
2570 else
2571 snprintf(ret, sizeof(ret), "from %s to %s", from, to);
2572
2573 return strlcpy(s, ret, l);
2574}
2575
2539int 2576int
2540sshkey_private_serialize(const struct sshkey *key, struct sshbuf *b) 2577sshkey_private_serialize(const struct sshkey *key, struct sshbuf *b)
2541{ 2578{