summaryrefslogtreecommitdiff
path: root/ssh-keygen.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-04-29 04:12:25 +0000
committerDamien Miller <djm@mindrot.org>2017-05-01 09:35:38 +1000
commit249516e428e8461b46340a5df5d5ed1fbad2ccce (patch)
tree6e815007fb5507f1590e0c8835dae904f7b3107a /ssh-keygen.c
parent47a287bb6ac936c26b4f3ae63279c02902ded3b9 (diff)
upstream commit
allow ssh-keygen to include arbitrary string or flag certificate extensions and critical options. ok markus@ dtucker@ Upstream-ID: 2cf28dd6c5489eb9fc136e0b667ac3ea10241646
Diffstat (limited to 'ssh-keygen.c')
-rw-r--r--ssh-keygen.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/ssh-keygen.c b/ssh-keygen.c
index f17af036b..c0d2d5942 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.299 2017/03/10 04:26:06 djm Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.300 2017/04/29 04:12:25 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -149,6 +149,15 @@ u_int32_t certflags_flags = CERTOPT_DEFAULT;
149char *certflags_command = NULL; 149char *certflags_command = NULL;
150char *certflags_src_addr = NULL; 150char *certflags_src_addr = NULL;
151 151
152/* Arbitrary extensions specified by user */
153struct cert_userext {
154 char *key;
155 char *val;
156 int crit;
157};
158struct cert_userext *cert_userext;
159size_t ncert_userext;
160
152/* Conversion to/from various formats */ 161/* Conversion to/from various formats */
153int convert_to = 0; 162int convert_to = 0;
154int convert_from = 0; 163int convert_from = 0;
@@ -1531,6 +1540,8 @@ add_string_option(struct sshbuf *c, const char *name, const char *value)
1531static void 1540static void
1532prepare_options_buf(struct sshbuf *c, int which) 1541prepare_options_buf(struct sshbuf *c, int which)
1533{ 1542{
1543 size_t i;
1544
1534 sshbuf_reset(c); 1545 sshbuf_reset(c);
1535 if ((which & OPTIONS_CRITICAL) != 0 && 1546 if ((which & OPTIONS_CRITICAL) != 0 &&
1536 certflags_command != NULL) 1547 certflags_command != NULL)
@@ -1553,6 +1564,17 @@ prepare_options_buf(struct sshbuf *c, int which)
1553 if ((which & OPTIONS_CRITICAL) != 0 && 1564 if ((which & OPTIONS_CRITICAL) != 0 &&
1554 certflags_src_addr != NULL) 1565 certflags_src_addr != NULL)
1555 add_string_option(c, "source-address", certflags_src_addr); 1566 add_string_option(c, "source-address", certflags_src_addr);
1567 for (i = 0; i < ncert_userext; i++) {
1568 if ((cert_userext[i].crit && (which & OPTIONS_EXTENSIONS)) ||
1569 (!cert_userext[i].crit && (which & OPTIONS_CRITICAL)))
1570 continue;
1571 if (cert_userext[i].val == NULL)
1572 add_flag_option(c, cert_userext[i].key);
1573 else {
1574 add_string_option(c, cert_userext[i].key,
1575 cert_userext[i].val);
1576 }
1577 }
1556} 1578}
1557 1579
1558static struct sshkey * 1580static struct sshkey *
@@ -1789,7 +1811,8 @@ parse_cert_times(char *timespec)
1789static void 1811static void
1790add_cert_option(char *opt) 1812add_cert_option(char *opt)
1791{ 1813{
1792 char *val; 1814 char *val, *cp;
1815 int iscrit = 0;
1793 1816
1794 if (strcasecmp(opt, "clear") == 0) 1817 if (strcasecmp(opt, "clear") == 0)
1795 certflags_flags = 0; 1818 certflags_flags = 0;
@@ -1829,6 +1852,18 @@ add_cert_option(char *opt)
1829 if (addr_match_cidr_list(NULL, val) != 0) 1852 if (addr_match_cidr_list(NULL, val) != 0)
1830 fatal("Invalid source-address list"); 1853 fatal("Invalid source-address list");
1831 certflags_src_addr = xstrdup(val); 1854 certflags_src_addr = xstrdup(val);
1855 } else if (strncasecmp(opt, "extension:", 10) == 0 ||
1856 (iscrit = (strncasecmp(opt, "critical:", 9) == 0))) {
1857 val = xstrdup(strchr(opt, ':') + 1);
1858 if ((cp = strchr(val, '=')) != NULL)
1859 *cp++ = '\0';
1860 cert_userext = xreallocarray(cert_userext, ncert_userext + 1,
1861 sizeof(*cert_userext));
1862 cert_userext[ncert_userext].key = val;
1863 cert_userext[ncert_userext].val = cp == NULL ?
1864 NULL : xstrdup(cp);
1865 cert_userext[ncert_userext].crit = iscrit;
1866 ncert_userext++;
1832 } else 1867 } else
1833 fatal("Unsupported certificate option \"%s\"", opt); 1868 fatal("Unsupported certificate option \"%s\"", opt);
1834} 1869}