diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2008-06-26 09:19:41 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2008-06-26 09:19:41 +0000 |
commit | 642dd5f0606a6d70841c3fa112840f94b1d66a84 (patch) | |
tree | f1c2baf8a93f8fe1344c2d1bf0ff49b11e5af978 /usr.bin/ssh/dh.c | |
parent | 67c127a282b2cfa5836c066aef10ff424f8bc199 (diff) |
when loading moduli from /etc/moduli in sshd(8), check that they
are of the expected "safe prime" structure and have had
appropriate primality tests performed;
feedback and ok dtucker@
Diffstat (limited to 'usr.bin/ssh/dh.c')
-rw-r--r-- | usr.bin/ssh/dh.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/usr.bin/ssh/dh.c b/usr.bin/ssh/dh.c index db8f0166df2..7bc3171009b 100644 --- a/usr.bin/ssh/dh.c +++ b/usr.bin/ssh/dh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dh.c,v 1.46 2008/04/13 00:22:17 djm Exp $ */ +/* $OpenBSD: dh.c,v 1.47 2008/06/26 09:19:39 djm Exp $ */ /* * Copyright (c) 2000 Niels Provos. All rights reserved. * @@ -43,6 +43,7 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg) char *cp, *arg; char *strsize, *gen, *prime; const char *errstr = NULL; + long long n; cp = line; if ((arg = strdelim(&cp)) == NULL) @@ -59,12 +60,24 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg) arg = strsep(&cp, " "); /* type */ if (cp == NULL || *arg == '\0') goto fail; + /* Ensure this is a safe prime */ + n = strtonum(arg, 0, 5, &errstr); + if (errstr != NULL || n != MODULI_TYPE_SAFE) + goto fail; arg = strsep(&cp, " "); /* tests */ if (cp == NULL || *arg == '\0') goto fail; + /* Ensure prime has been tested and is not composite */ + n = strtonum(arg, 0, 0x1f, &errstr); + if (errstr != NULL || + (n & MODULI_TESTS_COMPOSITE) || !(n & ~MODULI_TESTS_COMPOSITE)) + goto fail; arg = strsep(&cp, " "); /* tries */ if (cp == NULL || *arg == '\0') goto fail; + n = strtonum(arg, 0, 1<<30, &errstr); + if (errstr != NULL || n == 0) + goto fail; strsize = strsep(&cp, " "); /* size */ if (cp == NULL || *strsize == '\0' || (dhg->size = (u_int)strtonum(strsize, 0, 64*1024, &errstr)) == 0 || |