From: Mark Wooding Date: Thu, 26 May 2016 08:26:09 +0000 (+0100) Subject: server/keymgmt.c: Detect if a private keys records a wrong public key. X-Git-Tag: 1.0.0pre19~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/f1d5c89163540b40b808527bafa861ca3e5fd371 server/keymgmt.c: Detect if a private keys records a wrong public key. --- diff --git a/server/keymgmt.c b/server/keymgmt.c index 9e4bc5b4..3a20be0f 100644 --- a/server/keymgmt.c +++ b/server/keymgmt.c @@ -203,6 +203,8 @@ static int kh_loadpriv(key_file *kf, key *k, key_data *d, { int rc; const char *err; + dhge *K; + int ok; if ((rc = dh->ldpriv(kf, k, d, kd, t, e)) != 0) goto fail_0; @@ -211,6 +213,13 @@ static int kh_loadpriv(key_file *kf, key *k, key_data *d, a_format(e, "bad-group", "%s", err, A_END); goto fail_1; } + K = kd->grp->ops->mul(kd->grp, kd->k, 0); + ok = kd->grp->ops->eq(kd->grp, kd->K, K); + kd->grp->ops->freege(kd->grp, K); + if (!ok) { + a_format(e, "incorrect-public-key", A_END); + goto fail_1; + } return (0); fail_1: diff --git a/server/tripe-admin.5.in b/server/tripe-admin.5.in index edd56779..de3bfcb1 100644 --- a/server/tripe-admin.5.in +++ b/server/tripe-admin.5.in @@ -1253,6 +1253,9 @@ and the second token is the filename of the keyring. Frequently a key tag may be given next, preceded by the token .BR key . .SP +.BI "KEYMGMT private-keyring " file " key " tag " incorrect-public-key" +The private key doesn't record the correct corresponding public key. +.SP .BI "KEYMGMT public-keyring " file " key " tag " algorithm-mismatch" A peer's public key doesn't request the same algorithms as our private key.