openssh/openssh-7.7p1-openssl_1.1.0.patch

3103 lines
95 KiB
Diff
Raw Normal View History

# HG changeset patch
# Parent 6e5e3cb13cb379ca302c54a1f21156364781f8b6
OpenSSL 1.1.0 API shims and crutches
modified from RH patch
Index: openssh-7.8p1/Makefile.in
===================================================================
--- openssh-7.8p1.orig/Makefile.in
+++ openssh-7.8p1/Makefile.in
@@ -112,6 +112,8 @@ LIBSSH_OBJS += kexgssc.o kexgsss.o
LIBSSH_OBJS += auditstub.o
+LIBSSH_OBJS += libcrypto-compat.o
+
SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
sshconnect.o sshconnect2.o mux.o
Index: openssh-7.8p1/auth-pam.c
===================================================================
--- openssh-7.8p1.orig/auth-pam.c
+++ openssh-7.8p1/auth-pam.c
@@ -128,6 +128,10 @@ extern u_int utmp_len;
typedef pthread_t sp_pthread_t;
#else
typedef pid_t sp_pthread_t;
+# define pthread_create(a, b, c, d) _ssh_compat_pthread_create(a, b, c, d)
+# define pthread_exit(a) _ssh_compat_pthread_exit(a)
+# define pthread_cancel(a) _ssh_compat_pthread_cancel(a)
+# define pthread_join(a, b) _ssh_compat_pthread_join(a, b)
#endif
struct pam_ctxt {
Index: openssh-7.8p1/cavstest-ctr.c
===================================================================
--- openssh-7.8p1.orig/cavstest-ctr.c
+++ openssh-7.8p1/cavstest-ctr.c
@@ -150,7 +150,7 @@ main(int argc, char *argv[])
usage();
}
- SSLeay_add_all_algorithms();
+ OpenSSL_add_all_algorithms();
c = cipher_by_name(algo);
if (c == NULL) {
Index: openssh-7.8p1/cipher.c
===================================================================
--- openssh-7.8p1.orig/cipher.c
+++ openssh-7.8p1/cipher.c
@@ -299,7 +299,7 @@ cipher_init(struct sshcipher_ctx **ccp,
ret = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if (EVP_CipherInit(cc->evp, type, NULL, (u_char *)iv,
+ if (EVP_CipherInit(cc->evp, type, (u_char *)key, (u_char *)iv,
(do_encrypt == CIPHER_ENCRYPT)) == 0) {
ret = SSH_ERR_LIBCRYPTO_ERROR;
goto out;
@@ -317,10 +317,6 @@ cipher_init(struct sshcipher_ctx **ccp,
goto out;
}
}
- if (EVP_CipherInit(cc->evp, NULL, (u_char *)key, NULL, -1) == 0) {
- ret = SSH_ERR_LIBCRYPTO_ERROR;
- goto out;
- }
ret = 0;
#endif /* WITH_OPENSSL */
out:
@@ -503,7 +499,7 @@ cipher_get_keyiv(struct sshcipher_ctx *c
len, iv))
return SSH_ERR_LIBCRYPTO_ERROR;
} else
- memcpy(iv, cc->evp->iv, len);
+ memcpy(iv, EVP_CIPHER_CTX_iv(cc->evp), len);
#endif
return 0;
}
@@ -537,14 +533,14 @@ cipher_set_keyiv(struct sshcipher_ctx *c
EVP_CTRL_GCM_SET_IV_FIXED, -1, (void *)iv))
return SSH_ERR_LIBCRYPTO_ERROR;
} else
- memcpy(cc->evp->iv, iv, evplen);
+ memcpy(EVP_CIPHER_CTX_iv_noconst(cc->evp), iv, evplen);
#endif
return 0;
}
#ifdef WITH_OPENSSL
-#define EVP_X_STATE(evp) (evp)->cipher_data
-#define EVP_X_STATE_LEN(evp) (evp)->cipher->ctx_size
+#define EVP_X_STATE(evp) EVP_CIPHER_CTX_get_cipher_data(evp)
+#define EVP_X_STATE_LEN(evp) EVP_CIPHER_impl_ctx_size(EVP_CIPHER_CTX_cipher(evp))
#endif
int
Index: openssh-7.8p1/configure.ac
===================================================================
--- openssh-7.8p1.orig/configure.ac
+++ openssh-7.8p1/configure.ac
@@ -2626,6 +2626,7 @@ if test "x$openssl" = "xyes" ; then
AC_MSG_ERROR([OpenSSL >= 1.0.1 required (have "$ssl_library_ver")])
;;
100*) ;; # 1.0.x
+ 101*) ;; # 1.1.x is supported by this patch too
200*) ;; # LibreSSL
*)
AC_MSG_ERROR([OpenSSL >= 1.1.0 is not yet supported (have "$ssl_library_ver")])
Index: openssh-7.8p1/dh.c
===================================================================
--- openssh-7.8p1.orig/dh.c
+++ openssh-7.8p1/dh.c
@@ -218,14 +218,15 @@ choose_dh(int min, int wantbits, int max
/* diffie-hellman-groupN-sha1 */
int
-dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
+dh_pub_is_valid(const DH *dh, const BIGNUM *dh_pub)
{
int i;
int n = BN_num_bits(dh_pub);
int bits_set = 0;
BIGNUM *tmp;
+ const BIGNUM *p;
- if (dh_pub->neg) {
+ if (BN_is_negative(dh_pub)) {
logit("invalid public DH value: negative");
return 0;
}
@@ -238,7 +239,8 @@ dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
error("%s: BN_new failed", __func__);
return 0;
}
- if (!BN_sub(tmp, dh->p, BN_value_one()) ||
+ DH_get0_pqg(dh, &p, NULL, NULL);
+ if (!BN_sub(tmp, p, BN_value_one()) ||
BN_cmp(dh_pub, tmp) != -1) { /* pub_exp > p-2 */
BN_clear_free(tmp);
logit("invalid public DH value: >= p-1");
@@ -249,14 +251,14 @@ dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
for (i = 0; i <= n; i++)
if (BN_is_bit_set(dh_pub, i))
bits_set++;
- debug2("bits set: %d/%d", bits_set, BN_num_bits(dh->p));
+ debug2("bits set: %d/%d", bits_set, BN_num_bits(p));
/*
* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial
*/
if (bits_set < 4) {
logit("invalid public DH value (%d/%d)",
- bits_set, BN_num_bits(dh->p));
+ bits_set, BN_num_bits(p));
return 0;
}
return 1;
@@ -266,9 +268,11 @@ int
dh_gen_key(DH *dh, int need)
{
int pbits;
+ const BIGNUM *p, *pub_key;
- if (need < 0 || dh->p == NULL ||
- (pbits = BN_num_bits(dh->p)) <= 0 ||
+ DH_get0_pqg(dh, &p, NULL, NULL);
+ if (need < 0 || p == NULL ||
+ (pbits = BN_num_bits(p)) <= 0 ||
need > INT_MAX / 2 || 2 * need > pbits)
return SSH_ERR_INVALID_ARGUMENT;
if (need < 256)
@@ -277,11 +281,11 @@ dh_gen_key(DH *dh, int need)
* Pollard Rho, Big step/Little Step attacks are O(sqrt(n)),
* so double requested need here.
*/
- dh->length = MINIMUM(need * 2, pbits - 1);
- if (DH_generate_key(dh) == 0 ||
- !dh_pub_is_valid(dh, dh->pub_key)) {
- BN_clear_free(dh->priv_key);
- dh->priv_key = NULL;
+ DH_set_length(dh, MINIMUM(need * 2, pbits - 1));
+ if (DH_generate_key(dh) == 0)
+ return SSH_ERR_LIBCRYPTO_ERROR;
+ DH_get0_key(dh, &pub_key, NULL);
+ if (!dh_pub_is_valid(dh, pub_key)) {
return SSH_ERR_LIBCRYPTO_ERROR;
}
return 0;
@@ -291,15 +295,22 @@ DH *
dh_new_group_asc(const char *gen, const char *modulus)
{
DH *dh;
+ BIGNUM *p = NULL, *g = NULL;
- if ((dh = DH_new()) == NULL)
- return NULL;
- if (BN_hex2bn(&dh->p, modulus) == 0 ||
- BN_hex2bn(&dh->g, gen) == 0) {
- DH_free(dh);
- return NULL;
- }
+ if ((dh = DH_new()) == NULL ||
+ (p = BN_new()) == NULL ||
+ (g = BN_new()) == NULL)
+ goto err;
+ if (BN_hex2bn(&p, modulus) == 0 ||
+ BN_hex2bn(&g, gen) == 0 ||
+ DH_set0_pqg(dh, p, NULL, g) == 0)
+ goto err;
return (dh);
+err:
+ DH_free(dh);
+ BN_free(p);
+ BN_free(g);
+ return NULL;
}
/*
@@ -314,8 +325,7 @@ dh_new_group(BIGNUM *gen, BIGNUM *modulu
if ((dh = DH_new()) == NULL)
return NULL;
- dh->p = modulus;
- dh->g = gen;
+ DH_set0_pqg(dh, modulus, NULL, gen);
return (dh);
}
Index: openssh-7.8p1/dh.h
===================================================================
--- openssh-7.8p1.orig/dh.h
+++ openssh-7.8p1/dh.h
@@ -42,7 +42,7 @@ DH *dh_new_group18(void);
DH *dh_new_group_fallback(int);
int dh_gen_key(DH *, int);
-int dh_pub_is_valid(DH *, BIGNUM *);
+int dh_pub_is_valid(const DH *, const BIGNUM *);
u_int dh_estimate(int);
Index: openssh-7.8p1/digest-openssl.c
===================================================================
--- openssh-7.8p1.orig/digest-openssl.c
+++ openssh-7.8p1/digest-openssl.c
@@ -43,7 +43,7 @@
struct ssh_digest_ctx {
int alg;
- EVP_MD_CTX mdctx;
+ EVP_MD_CTX *mdctx;
};
struct ssh_digest {
@@ -106,7 +106,7 @@ ssh_digest_bytes(int alg)
size_t
ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
{
- return EVP_MD_CTX_block_size(&ctx->mdctx);
+ return EVP_MD_CTX_block_size(ctx->mdctx);
}
struct ssh_digest_ctx *
@@ -118,8 +118,10 @@ ssh_digest_start(int alg)
if (digest == NULL || ((ret = calloc(1, sizeof(*ret))) == NULL))
return NULL;
ret->alg = alg;
- EVP_MD_CTX_init(&ret->mdctx);
- if (EVP_DigestInit_ex(&ret->mdctx, digest->mdfunc(), NULL) != 1) {
+ ret->mdctx = EVP_MD_CTX_new();
+ if (ret->mdctx == NULL ||
+ EVP_DigestInit_ex(ret->mdctx, digest->mdfunc(), NULL) != 1) {
+ EVP_MD_CTX_free(ret->mdctx);
free(ret);
return NULL;
}
@@ -132,7 +134,7 @@ ssh_digest_copy_state(struct ssh_digest_
if (from->alg != to->alg)
return SSH_ERR_INVALID_ARGUMENT;
/* we have bcopy-style order while openssl has memcpy-style */
- if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
+ if (!EVP_MD_CTX_copy_ex(to->mdctx, from->mdctx))
return SSH_ERR_LIBCRYPTO_ERROR;
return 0;
}
@@ -140,7 +142,7 @@ ssh_digest_copy_state(struct ssh_digest_
int
ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
{
- if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
+ if (EVP_DigestUpdate(ctx->mdctx, m, mlen) != 1)
return SSH_ERR_LIBCRYPTO_ERROR;
return 0;
}
@@ -161,7 +163,7 @@ ssh_digest_final(struct ssh_digest_ctx *
return SSH_ERR_INVALID_ARGUMENT;
if (dlen < digest->digest_len) /* No truncation allowed */
return SSH_ERR_INVALID_ARGUMENT;
- if (EVP_DigestFinal_ex(&ctx->mdctx, d, &l) != 1)
+ if (EVP_DigestFinal_ex(ctx->mdctx, d, &l) != 1)
return SSH_ERR_LIBCRYPTO_ERROR;
if (l != digest->digest_len) /* sanity */
return SSH_ERR_INTERNAL_ERROR;
@@ -172,7 +174,7 @@ void
ssh_digest_free(struct ssh_digest_ctx *ctx)
{
if (ctx != NULL) {
- EVP_MD_CTX_cleanup(&ctx->mdctx);
+ EVP_MD_CTX_free(ctx->mdctx);
explicit_bzero(ctx, sizeof(*ctx));
free(ctx);
}
Index: openssh-7.8p1/gss-genr.c
===================================================================
--- openssh-7.8p1.orig/gss-genr.c
+++ openssh-7.8p1/gss-genr.c
@@ -87,12 +87,12 @@ ssh_gssapi_client_mechanisms(const char
return NULL;
return(ssh_gssapi_kex_mechs(gss_supported, ssh_gssapi_check_mechanism,
- host, client));
+ host, client, kex));
}
char *
ssh_gssapi_kex_mechs(gss_OID_set gss_supported, ssh_gssapi_check_fn *check,
- const char *host, const char *client) {
+ const char *host, const char *client, const char *kex) {
struct sshbuf *buf;
size_t i;
int oidpos, enclen, r;
@@ -100,7 +100,8 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
u_char digest[EVP_MAX_MD_SIZE];
char deroid[2];
const EVP_MD *evp_md = EVP_md5();
- EVP_MD_CTX md;
+ EVP_MD_CTX *md;
+ char *s, *cp, *p;
if (gss_enc2oid != NULL) {
for (i = 0; gss_enc2oid[i].encoded != NULL; i++)
@@ -114,7 +115,9 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
if ((buf = sshbuf_new()) == NULL)
fatal("%s: sshbuf_new failed", __func__);
+ md = EVP_MD_CTX_new();
oidpos = 0;
+ s = cp = xstrdup(kex);
for (i = 0; i < gss_supported->count; i++) {
if (gss_supported->elements[i].length < 128 &&
(*check)(NULL, &(gss_supported->elements[i]), host, client)) {
@@ -122,26 +125,27 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
deroid[0] = SSH_GSS_OIDTYPE;
deroid[1] = gss_supported->elements[i].length;
- EVP_DigestInit(&md, evp_md);
- EVP_DigestUpdate(&md, deroid, 2);
- EVP_DigestUpdate(&md,
+ EVP_MD_CTX_reset(md);
+ EVP_DigestInit(md, evp_md);
+ EVP_DigestUpdate(md, deroid, 2);
+ EVP_DigestUpdate(md,
gss_supported->elements[i].elements,
gss_supported->elements[i].length);
- EVP_DigestFinal(&md, digest, NULL);
+ EVP_DigestFinal(md, digest, NULL);
encoded = xmalloc(EVP_MD_size(evp_md) * 2);
enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
encoded, EVP_MD_size(evp_md) * 2);
cp = strncpy(s, kex, strlen(kex));
- for ((p = strsep(&cp, ",")); p && *p != '\0';
+ for ((p = strsep(&cp, ",")); p && *p != '\0';
(p = strsep(&cp, ","))) {
if (sshbuf_len(buf) != 0)
if ((r = sshbuf_put_u8(buf, ',')) !=0)
fatal("%s: buffer error: %s",
__func__, ssh_err(r));
if ((r = sshbuf_put(buf, p, strlen(p))) != 0 ||
- (r = sshbuf_put(buf, encoded, enclen)) != 0)
+ (r = sshbuf_put(buf, encoded, enclen)) != 0)
fatal("%s: buffer error: %s",
__func__, ssh_err(r));
}
@@ -151,7 +155,8 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
oidpos++;
}
}
- free(s);
+ free(s);
+ EVP_MD_CTX_free(md);
gss_enc2oid[oidpos].oid = NULL;
gss_enc2oid[oidpos].encoded = NULL;
Index: openssh-7.8p1/includes.h
===================================================================
--- openssh-7.8p1.orig/includes.h
+++ openssh-7.8p1/includes.h
@@ -166,6 +166,7 @@
#ifdef WITH_OPENSSL
#include <openssl/opensslv.h> /* For OPENSSL_VERSION_NUMBER */
+#include "libcrypto-compat.h"
#endif
#include "defines.h"
Index: openssh-7.8p1/kexdhc.c
===================================================================
--- openssh-7.8p1.orig/kexdhc.c
+++ openssh-7.8p1/kexdhc.c
@@ -56,6 +56,7 @@ kexdh_client(struct ssh *ssh)
{
struct kex *kex = ssh->kex;
int r;
+ const BIGNUM *pub_key;
/* generate and send 'e', client DH public key */
switch (kex->kex_type) {
@@ -81,21 +82,27 @@ kexdh_client(struct ssh *ssh)
goto out;
}
debug("sending SSH2_MSG_KEXDH_INIT");
- if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0 ||
- (r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||
+ if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
+ goto out;
+ DH_get0_key(kex->dh, &pub_key, NULL);
+ if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
(r = sshpkt_send(ssh)) != 0)
goto out;
#ifdef DEBUG_KEXDH
DHparams_print_fp(stderr, kex->dh);
fprintf(stderr, "pub= ");
- BN_print_fp(stderr, kex->dh->pub_key);
+ BN_print_fp(stderr, pub_key);
fprintf(stderr, "\n");
#endif
debug("expecting SSH2_MSG_KEXDH_REPLY");
ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_REPLY, &input_kex_dh);
r = 0;
out:
+ if (r != 0) {
+ DH_free(kex->dh);
+ kex->dh = NULL;
+ }
return r;
}
@@ -109,6 +116,7 @@ input_kex_dh(int type, u_int32_t seq, st
u_char hash[SSH_DIGEST_MAX_LENGTH];
size_t klen = 0, slen, sbloblen, hashlen;
int kout, r;
+ const BIGNUM *pub_key;
if (kex->verify_host_key == NULL) {
r = SSH_ERR_INVALID_ARGUMENT;
@@ -168,6 +176,7 @@ input_kex_dh(int type, u_int32_t seq, st
#endif
/* calc and verify H */
+ DH_get0_key(kex->dh, &pub_key, NULL);
hashlen = sizeof(hash);
if ((r = kex_dh_hash(
kex->hash_alg,
@@ -176,7 +185,7 @@ input_kex_dh(int type, u_int32_t seq, st
sshbuf_ptr(kex->my), sshbuf_len(kex->my),
sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
server_host_key_blob, sbloblen,
- kex->dh->pub_key,
+ pub_key,
dh_server_pub,
shared_secret,
hash, &hashlen)) != 0)
Index: openssh-7.8p1/kexdhs.c
===================================================================
--- openssh-7.8p1.orig/kexdhs.c
+++ openssh-7.8p1/kexdhs.c
@@ -87,6 +87,10 @@ kexdh_server(struct ssh *ssh)
ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_INIT, &input_kex_dh_init);
r = 0;
out:
+ if (r != 0) {
+ DH_free(kex->dh);
+ kex->dh = NULL;
+ }
return r;
}
@@ -101,6 +105,7 @@ input_kex_dh_init(int type, u_int32_t se
size_t sbloblen, slen;
size_t klen = 0, hashlen;
int kout, r;
+ const BIGNUM *pub_key;
if (kex->load_host_public_key == NULL ||
kex->load_host_private_key == NULL) {
@@ -163,6 +168,7 @@ input_kex_dh_init(int type, u_int32_t se
goto out;
/* calc H */
hashlen = sizeof(hash);
+ DH_get0_key(kex->dh, &pub_key, NULL);
if ((r = kex_dh_hash(
kex->hash_alg,
kex->client_version_string,
@@ -171,7 +177,7 @@ input_kex_dh_init(int type, u_int32_t se
sshbuf_ptr(kex->my), sshbuf_len(kex->my),
server_host_key_blob, sbloblen,
dh_client_pub,
- kex->dh->pub_key,
+ pub_key,
shared_secret,
hash, &hashlen)) != 0)
goto out;
@@ -197,7 +203,7 @@ input_kex_dh_init(int type, u_int32_t se
/* send server hostkey, DH pubkey 'f' and signed H */
if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_REPLY)) != 0 ||
(r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 || /* f */
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */
(r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
(r = sshpkt_send(ssh)) != 0)
goto out;
Index: openssh-7.8p1/kexgexc.c
===================================================================
--- openssh-7.8p1.orig/kexgexc.c
+++ openssh-7.8p1/kexgexc.c
@@ -96,6 +96,7 @@ input_kex_dh_gex_group(int type, u_int32
struct kex *kex = ssh->kex;
BIGNUM *p = NULL, *g = NULL;
int r, bits;
+ const BIGNUM *pub_key;
debug("got SSH2_MSG_KEX_DH_GEX_GROUP");
@@ -126,16 +127,18 @@ input_kex_dh_gex_group(int type, u_int32
p = g = NULL; /* belong to kex->dh now */
/* generate and send 'e', client DH public key */
- if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0 ||
- (r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_INIT)) != 0 ||
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||
+ if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
+ goto out;
+ DH_get0_key(kex->dh, &pub_key, NULL);
+ if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_INIT)) != 0 ||
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
(r = sshpkt_send(ssh)) != 0)
goto out;
debug("SSH2_MSG_KEX_DH_GEX_INIT sent");
#ifdef DEBUG_KEXDH
DHparams_print_fp(stderr, kex->dh);
fprintf(stderr, "pub= ");
- BN_print_fp(stderr, kex->dh->pub_key);
+ BN_print_fp(stderr, pub_key);
fprintf(stderr, "\n");
#endif
ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_GROUP, NULL);
@@ -144,6 +147,10 @@ input_kex_dh_gex_group(int type, u_int32
out:
BN_clear_free(p);
BN_clear_free(g);
+ if (r != 0) {
+ DH_free(kex->dh);
+ kex->dh = NULL;
+ }
return r;
}
@@ -157,6 +164,7 @@ input_kex_dh_gex_reply(int type, u_int32
u_char hash[SSH_DIGEST_MAX_LENGTH];
size_t klen = 0, slen, sbloblen, hashlen;
int kout, r;
+ const BIGNUM *p, *g, *pub_key;
debug("got SSH2_MSG_KEX_DH_GEX_REPLY");
if (kex->verify_host_key == NULL) {
@@ -219,6 +227,8 @@ input_kex_dh_gex_reply(int type, u_int32
kex->min = kex->max = -1;
/* calc and verify H */
+ DH_get0_pqg(kex->dh, &p, NULL, &g);
+ DH_get0_key(kex->dh, &pub_key, NULL);
hashlen = sizeof(hash);
if ((r = kexgex_hash(
kex->hash_alg,
@@ -228,8 +238,8 @@ input_kex_dh_gex_reply(int type, u_int32
sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
server_host_key_blob, sbloblen,
kex->min, kex->nbits, kex->max,
- kex->dh->p, kex->dh->g,
- kex->dh->pub_key,
+ p, g,
+ pub_key,
dh_server_pub,
shared_secret,
hash, &hashlen)) != 0)
Index: openssh-7.8p1/kexgexs.c
===================================================================
--- openssh-7.8p1.orig/kexgexs.c
+++ openssh-7.8p1/kexgexs.c
@@ -74,6 +74,7 @@ input_kex_dh_gex_request(int type, u_int
struct kex *kex = ssh->kex;
int r;
u_int min = 0, max = 0, nbits = 0;
+ const BIGNUM *p, *g;
debug("SSH2_MSG_KEX_DH_GEX_REQUEST received");
if ((r = sshpkt_get_u32(ssh, &min)) != 0 ||
@@ -109,9 +110,10 @@ input_kex_dh_gex_request(int type, u_int
goto out;
}
debug("SSH2_MSG_KEX_DH_GEX_GROUP sent");
+ DH_get0_pqg(kex->dh, &p, NULL, &g);
if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_GROUP)) != 0 ||
- (r = sshpkt_put_bignum2(ssh, kex->dh->p)) != 0 ||
- (r = sshpkt_put_bignum2(ssh, kex->dh->g)) != 0 ||
+ (r = sshpkt_put_bignum2(ssh, p)) != 0 ||
+ (r = sshpkt_put_bignum2(ssh, g)) != 0 ||
(r = sshpkt_send(ssh)) != 0)
goto out;
@@ -123,6 +125,10 @@ input_kex_dh_gex_request(int type, u_int
ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_INIT, &input_kex_dh_gex_init);
r = 0;
out:
+ if (r != 0) {
+ DH_free(kex->dh);
+ kex->dh = NULL;
+ }
return r;
}
@@ -137,6 +143,7 @@ input_kex_dh_gex_init(int type, u_int32_
size_t sbloblen, slen;
size_t klen = 0, hashlen;
int kout, r;
+ const BIGNUM *p, *g, *pub_key;
if (kex->load_host_public_key == NULL ||
kex->load_host_private_key == NULL) {
@@ -199,6 +206,8 @@ input_kex_dh_gex_init(int type, u_int32_
goto out;
/* calc H */
hashlen = sizeof(hash);
+ DH_get0_pqg(kex->dh, &p, NULL, &g);
+ DH_get0_key(kex->dh, &pub_key, NULL);
if ((r = kexgex_hash(
kex->hash_alg,
kex->client_version_string,
@@ -207,9 +216,9 @@ input_kex_dh_gex_init(int type, u_int32_
sshbuf_ptr(kex->my), sshbuf_len(kex->my),
server_host_key_blob, sbloblen,
kex->min, kex->nbits, kex->max,
- kex->dh->p, kex->dh->g,
+ p, g,
dh_client_pub,
- kex->dh->pub_key,
+ pub_key,
shared_secret,
hash, &hashlen)) != 0)
goto out;
@@ -235,7 +244,7 @@ input_kex_dh_gex_init(int type, u_int32_
/* send server hostkey, DH pubkey 'f' and signed H */
if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REPLY)) != 0 ||
(r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 || /* f */
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */
(r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
(r = sshpkt_send(ssh)) != 0)
goto out;
Index: openssh-7.8p1/kexgssc.c
===================================================================
--- openssh-7.8p1.orig/kexgssc.c
+++ openssh-7.8p1/kexgssc.c
@@ -61,6 +61,7 @@ kexgss_client(struct ssh *ssh)
BIGNUM *shared_secret = NULL;
BIGNUM *p = NULL;
BIGNUM *g = NULL;
+ const BIGNUM *pub_key, *p1, *g1;
u_char *kbuf;
u_char *serverhostkey = NULL;
u_char *empty = "";
@@ -126,6 +127,7 @@ kexgss_client(struct ssh *ssh)
/* Step 1 - e is dh->pub_key */
dh_gen_key(dh, ssh->kex->we_need * 8);
+ DH_get0_key(dh, &pub_key, NULL);
/* This is f, we initialise it now to make life easier */
dh_server_pub = BN_new();
@@ -173,7 +175,7 @@ kexgss_client(struct ssh *ssh)
packet_start(SSH2_MSG_KEXGSS_INIT);
packet_put_string(send_tok.value,
send_tok.length);
- packet_put_bignum2(dh->pub_key);
+ packet_put_bignum2((BIGNUM *)pub_key);
first = 0;
} else {
packet_start(SSH2_MSG_KEXGSS_CONTINUE);
@@ -284,13 +286,14 @@ kexgss_client(struct ssh *ssh)
sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
(serverhostkey ? serverhostkey : empty), slen,
- dh->pub_key, /* e */
+ pub_key, /* e */
dh_server_pub, /* f */
shared_secret, /* K */
hash, &hashlen
);
break;
case KEX_GSS_GEX_SHA1:
+ DH_get0_pqg(dh, &p1, NULL, &g1);
kexgex_hash(
ssh->kex->hash_alg,
ssh->kex->client_version_string,
@@ -299,8 +302,8 @@ kexgss_client(struct ssh *ssh)
sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
(serverhostkey ? serverhostkey : empty), slen,
min, nbits, max,
- dh->p, dh->g,
- dh->pub_key,
+ p1, g1,
+ pub_key,
dh_server_pub,
shared_secret,
hash, &hashlen
Index: openssh-7.8p1/kexgsss.c
===================================================================
--- openssh-7.8p1.orig/kexgsss.c
+++ openssh-7.8p1/kexgsss.c
@@ -78,6 +78,7 @@ kexgss_server(struct ssh *ssh)
char *mechs;
u_char hash[SSH_DIGEST_MAX_LENGTH];
size_t hashlen;
+ const BIGNUM *p, *g, *pub_key;
/* Initialise GSSAPI */
@@ -130,9 +131,10 @@ kexgss_server(struct ssh *ssh)
if (dh == NULL)
packet_disconnect("Protocol error: no matching group found");
+ DH_get0_pqg(dh, &p, NULL, &g);
packet_start(SSH2_MSG_KEXGSS_GROUP);
- packet_put_bignum2(dh->p);
- packet_put_bignum2(dh->g);
+ packet_put_bignum2((BIGNUM *)p);
+ packet_put_bignum2((BIGNUM *)g);
packet_send();
packet_write_wait();
@@ -224,6 +226,7 @@ kexgss_server(struct ssh *ssh)
memset(kbuf, 0, klen);
free(kbuf);
+ DH_get0_key(dh, &pub_key, NULL);
hashlen = sizeof(hash);
switch (ssh->kex->kex_type) {
case KEX_GSS_GRP1_SHA1:
@@ -234,7 +237,7 @@ kexgss_server(struct ssh *ssh)
sshbuf_ptr(ssh->kex->peer), sshbuf_len(ssh->kex->peer),
sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
NULL, 0, /* Change this if we start sending host keys */
- dh_client_pub, dh->pub_key, shared_secret,
+ dh_client_pub, pub_key, shared_secret,
hash, &hashlen
);
break;
@@ -246,9 +249,9 @@ kexgss_server(struct ssh *ssh)
sshbuf_ptr(ssh->kex->my), sshbuf_len(ssh->kex->my),
NULL, 0,
cmin, nbits, cmax,
- dh->p, dh->g,
+ p, g,
dh_client_pub,
- dh->pub_key,
+ pub_key,
shared_secret,
hash, &hashlen
);
@@ -272,7 +275,7 @@ kexgss_server(struct ssh *ssh)
fatal("Couldn't get MIC");
packet_start(SSH2_MSG_KEXGSS_COMPLETE);
- packet_put_bignum2(dh->pub_key);
+ packet_put_bignum2((BIGNUM *)pub_key);
packet_put_string(msg_tok.value,msg_tok.length);
if (send_tok.length != 0) {
Index: openssh-7.8p1/libcrypto-compat.c
===================================================================
--- /dev/null
+++ openssh-7.8p1/libcrypto-compat.c
@@ -0,0 +1,428 @@
+/*
+ * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include "includes.h"
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+
+#include <string.h>
+#include <openssl/engine.h>
+
+static void *OPENSSL_zalloc(size_t num)
+{
+ void *ret = OPENSSL_malloc(num);
+
+ if (ret != NULL)
+ memset(ret, 0, num);
+ return ret;
+}
+
+int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
+{
+ /* If the fields n and e in r are NULL, the corresponding input
+ * parameters MUST be non-NULL for n and e. d may be
+ * left NULL (in case only the public key is used).
+ */
+ if ((r->n == NULL && n == NULL)
+ || (r->e == NULL && e == NULL))
+ return 0;
+
+ if (n != NULL) {
+ BN_clear_free(r->n);
+ r->n = n;
+ }
+ if (e != NULL) {
+ BN_clear_free(r->e);
+ r->e = e;
+ }
+ if (d != NULL) {
+ BN_clear_free(r->d);
+ r->d = d;
+ }
+
+ return 1;
+}
+
+int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
+{
+ /* If the fields p and q in r are NULL, the corresponding input
+ * parameters MUST be non-NULL.
+ */
+ if ((r->p == NULL && p == NULL)
+ || (r->q == NULL && q == NULL))
+ return 0;
+
+ if (p != NULL) {
+ BN_clear_free(r->p);
+ r->p = p;
+ }
+ if (q != NULL) {
+ BN_clear_free(r->q);
+ r->q = q;
+ }
+
+ return 1;
+}
+
+int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
+{
+ /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
+ * parameters MUST be non-NULL.
+ */
+ if ((r->dmp1 == NULL && dmp1 == NULL)
+ || (r->dmq1 == NULL && dmq1 == NULL)
+ || (r->iqmp == NULL && iqmp == NULL))
+ return 0;
+
+ if (dmp1 != NULL) {
+ BN_clear_free(r->dmp1);
+ r->dmp1 = dmp1;
+ }
+ if (dmq1 != NULL) {
+ BN_clear_free(r->dmq1);
+ r->dmq1 = dmq1;
+ }
+ if (iqmp != NULL) {
+ BN_clear_free(r->iqmp);
+ r->iqmp = iqmp;
+ }
+
+ return 1;
+}
+
+void RSA_get0_key(const RSA *r,
+ const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
+{
+ if (n != NULL)
+ *n = r->n;
+ if (e != NULL)
+ *e = r->e;
+ if (d != NULL)
+ *d = r->d;
+}
+
+void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
+{
+ if (p != NULL)
+ *p = r->p;
+ if (q != NULL)
+ *q = r->q;
+}
+
+void RSA_get0_crt_params(const RSA *r,
+ const BIGNUM **dmp1, const BIGNUM **dmq1,
+ const BIGNUM **iqmp)
+{
+ if (dmp1 != NULL)
+ *dmp1 = r->dmp1;
+ if (dmq1 != NULL)
+ *dmq1 = r->dmq1;
+ if (iqmp != NULL)
+ *iqmp = r->iqmp;
+}
+
+void DSA_get0_pqg(const DSA *d,
+ const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
+{
+ if (p != NULL)
+ *p = d->p;
+ if (q != NULL)
+ *q = d->q;
+ if (g != NULL)
+ *g = d->g;
+}
+
+int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
+{
+ /* If the fields p, q and g in d are NULL, the corresponding input
+ * parameters MUST be non-NULL.
+ */
+ if ((d->p == NULL && p == NULL)
+ || (d->q == NULL && q == NULL)
+ || (d->g == NULL && g == NULL))
+ return 0;
+
+ if (p != NULL) {
+ BN_clear_free(d->p);
+ d->p = p;
+ }
+ if (q != NULL) {
+ BN_clear_free(d->q);
+ d->q = q;
+ }
+ if (g != NULL) {
+ BN_clear_free(d->g);
+ d->g = g;
+ }
+
+ return 1;
+}
+
+void DSA_get0_key(const DSA *d,
+ const BIGNUM **pub_key, const BIGNUM **priv_key)
+{
+ if (pub_key != NULL)
+ *pub_key = d->pub_key;
+ if (priv_key != NULL)
+ *priv_key = d->priv_key;
+}
+
+int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
+{
+ /* If the field pub_key in d is NULL, the corresponding input
+ * parameters MUST be non-NULL. The priv_key field may
+ * be left NULL.
+ */
+ if (d->pub_key == NULL && pub_key == NULL)
+ return 0;
+
+ if (pub_key != NULL) {
+ BN_clear_free(d->pub_key);
+ d->pub_key = pub_key;
+ }
+ if (priv_key != NULL) {
+ BN_clear_free(d->priv_key);
+ d->priv_key = priv_key;
+ }
+
+ return 1;
+}
+
+void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
+{
+ if (pr != NULL)
+ *pr = sig->r;
+ if (ps != NULL)
+ *ps = sig->s;
+}
+
+int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s)
+{
+ if (r == NULL || s == NULL)
+ return 0;
+ BN_clear_free(sig->r);
+ BN_clear_free(sig->s);
+ sig->r = r;
+ sig->s = s;
+ return 1;
+}
+
+void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
+{
+ if (pr != NULL)
+ *pr = sig->r;
+ if (ps != NULL)
+ *ps = sig->s;
+}
+
+int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
+{
+ if (r == NULL || s == NULL)
+ return 0;
+ BN_clear_free(sig->r);
+ BN_clear_free(sig->s);
+ sig->r = r;
+ sig->s = s;
+ return 1;
+}
+
+void DH_get0_pqg(const DH *dh,
+ const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
+{
+ if (p != NULL)
+ *p = dh->p;
+ if (q != NULL)
+ *q = dh->q;
+ if (g != NULL)
+ *g = dh->g;
+}
+
+int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
+{
+ /* If the fields p and g in d are NULL, the corresponding input
+ * parameters MUST be non-NULL. q may remain NULL.
+ */
+ if ((dh->p == NULL && p == NULL)
+ || (dh->g == NULL && g == NULL))
+ return 0;
+
+ if (p != NULL) {
+ BN_clear_free(dh->p);
+ dh->p = p;
+ }
+ if (q != NULL) {
+ BN_clear_free(dh->q);
+ dh->q = q;
+ }
+ if (g != NULL) {
+ BN_clear_free(dh->g);
+ dh->g = g;
+ }
+
+ if (q != NULL) {
+ dh->length = BN_num_bits(q);
+ }
+
+ return 1;
+}
+
+void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
+{
+ if (pub_key != NULL)
+ *pub_key = dh->pub_key;
+ if (priv_key != NULL)
+ *priv_key = dh->priv_key;
+}
+
+int DH_set_length(DH *dh, long length)
+{
+ dh->length = length;
+ return 1;
+}
+
+const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx)
+{
+ return ctx->iv;
+}
+
+unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx)
+{
+ return ctx->iv;
+}
+
+EVP_MD_CTX *EVP_MD_CTX_new(void)
+{
+ return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
+}
+
+static void OPENSSL_clear_free(void *str, size_t num)
+{
+ if (str == NULL)
+ return;
+ if (num)
+ OPENSSL_cleanse(str, num);
+ OPENSSL_free(str);
+}
+
+/* This call frees resources associated with the context */
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
+{
+ if (ctx == NULL)
+ return 1;
+
+ /*
+ * Don't assume ctx->md_data was cleaned in EVP_Digest_Final, because
+ * sometimes only copies of the context are ever finalised.
+ */
+ if (ctx->digest && ctx->digest->cleanup
+ && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))
+ ctx->digest->cleanup(ctx);
+ if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
+ && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {
+ OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
+ }
+ EVP_PKEY_CTX_free(ctx->pctx);
+#ifndef OPENSSL_NO_ENGINE
+ ENGINE_finish(ctx->engine);
+#endif
+ OPENSSL_cleanse(ctx, sizeof(*ctx));
+
+ return 1;
+}
+
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
+{
+ EVP_MD_CTX_reset(ctx);
+ OPENSSL_free(ctx);
+}
+
+RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
+{
+ RSA_METHOD *ret;
+
+ ret = OPENSSL_malloc(sizeof(RSA_METHOD));
+
+ if (ret != NULL) {
+ memcpy(ret, meth, sizeof(*meth));
+ ret->name = OPENSSL_strdup(meth->name);
+ if (ret->name == NULL) {
+ OPENSSL_free(ret);
+ return NULL;
+ }
+ }
+
+ return ret;
+}
+
+int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
+{
+ char *tmpname;
+
+ tmpname = OPENSSL_strdup(name);
+ if (tmpname == NULL) {
+ return 0;
+ }
+
+ OPENSSL_free((char *)meth->name);
+ meth->name = tmpname;
+
+ return 1;
+}
+
+int RSA_meth_set_priv_enc(RSA_METHOD *meth,
+ int (*priv_enc) (int flen, const unsigned char *from,
+ unsigned char *to, RSA *rsa,
+ int padding))
+{
+ meth->rsa_priv_enc = priv_enc;
+ return 1;
+}
+
+int RSA_meth_set_priv_dec(RSA_METHOD *meth,
+ int (*priv_dec) (int flen, const unsigned char *from,
+ unsigned char *to, RSA *rsa,
+ int padding))
+{
+ meth->rsa_priv_dec = priv_dec;
+ return 1;
+}
+
+int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
+{
+ meth->finish = finish;
+ return 1;
+}
+
+void RSA_meth_free(RSA_METHOD *meth)
+{
+ if (meth != NULL) {
+ OPENSSL_free((char *)meth->name);
+ OPENSSL_free(meth);
+ }
+}
+
+int RSA_bits(const RSA *r)
+{
+ return (BN_num_bits(r->n));
+}
+
+int DSA_bits(const DSA *dsa)
+{
+ return BN_num_bits(dsa->p);
+}
+
+RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
+{
+ if (pkey->type != EVP_PKEY_RSA) {
+ return NULL;
+ }
+ return pkey->pkey.rsa;
+}
+
+#endif /* OPENSSL_VERSION_NUMBER */
Index: openssh-7.8p1/libcrypto-compat.h
===================================================================
--- /dev/null
+++ openssh-7.8p1/libcrypto-compat.h
@@ -0,0 +1,59 @@
+#ifndef LIBCRYPTO_COMPAT_H
+#define LIBCRYPTO_COMPAT_H
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+
+#include <openssl/rsa.h>
+#include <openssl/dsa.h>
+#include <openssl/ecdsa.h>
+#include <openssl/dh.h>
+#include <openssl/evp.h>
+
+int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
+int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
+int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
+void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
+void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
+void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp);
+
+void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
+int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
+void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key);
+int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
+
+void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
+int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
+
+void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
+int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
+
+void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
+int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
+void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
+int DH_set_length(DH *dh, long length);
+
+const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx);
+unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx);
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
+EVP_MD_CTX *EVP_MD_CTX_new(void);
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
+#define EVP_CIPHER_impl_ctx_size(e) e->ctx_size
+#define EVP_CIPHER_CTX_get_cipher_data(ctx) ctx->cipher_data
+
+RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
+int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
+#define RSA_meth_get_finish(meth) meth->finish
+int RSA_meth_set_priv_enc(RSA_METHOD *meth, int (*priv_enc) (int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding));
+int RSA_meth_set_priv_dec(RSA_METHOD *meth, int (*priv_dec) (int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding));
+int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa));
+void RSA_meth_free(RSA_METHOD *meth);
+
+int RSA_bits(const RSA *r);
+int DSA_bits(const DSA *d);
+
+RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
+
+#endif /* OPENSSL_VERSION_NUMBER */
+
+#endif /* LIBCRYPTO_COMPAT_H */
+
Index: openssh-7.8p1/monitor.c
===================================================================
--- openssh-7.8p1.orig/monitor.c
+++ openssh-7.8p1/monitor.c
@@ -624,9 +624,12 @@ mm_answer_moduli(int sock, struct sshbuf
return (0);
} else {
/* Send first bignum */
+ const BIGNUM *p, *g;
+
+ DH_get0_pqg(dh, &p, NULL, &g);
if ((r = sshbuf_put_u8(m, 1)) != 0 ||
- (r = sshbuf_put_bignum2(m, dh->p)) != 0 ||
- (r = sshbuf_put_bignum2(m, dh->g)) != 0)
+ (r = sshbuf_put_bignum2(m, p)) != 0 ||
+ (r = sshbuf_put_bignum2(m, g)) != 0)
fatal("%s: buffer error: %s", __func__, ssh_err(r));
DH_free(dh);
Index: openssh-7.8p1/openbsd-compat/openssl-compat.c
===================================================================
--- openssh-7.8p1.orig/openbsd-compat/openssl-compat.c
+++ openssh-7.8p1/openbsd-compat/openssl-compat.c
@@ -70,12 +70,19 @@ ssh_compatible_openssl(long headerver, l
void
ssh_OpenSSL_add_all_algorithms(void)
{
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
OpenSSL_add_all_algorithms();
/* Enable use of crypto hardware */
ENGINE_load_builtin_engines();
+#if OPENSSL_VERSION_NUMBER < 0x10001000L
ENGINE_register_all_complete();
+#endif
OPENSSL_config(NULL);
+#else
+ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS |
+ OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL);
+#endif
}
#endif
Index: openssh-7.8p1/regress/unittests/sshkey/test_file.c
===================================================================
--- openssh-7.8p1.orig/regress/unittests/sshkey/test_file.c
+++ openssh-7.8p1/regress/unittests/sshkey/test_file.c
@@ -46,6 +46,7 @@ sshkey_file_tests(void)
struct sshbuf *buf, *pw;
BIGNUM *a, *b, *c;
char *cp;
+ const BIGNUM *n, *p, *q, *g, *pub_key, *priv_key;
TEST_START("load passphrase");
pw = load_text_file("pw");
@@ -60,9 +61,11 @@ sshkey_file_tests(void)
a = load_bignum("rsa_1.param.n");
b = load_bignum("rsa_1.param.p");
c = load_bignum("rsa_1.param.q");
- ASSERT_BIGNUM_EQ(k1->rsa->n, a);
- ASSERT_BIGNUM_EQ(k1->rsa->p, b);
- ASSERT_BIGNUM_EQ(k1->rsa->q, c);
+ RSA_get0_key(k1->rsa, &n, NULL, NULL);
+ RSA_get0_factors(k1->rsa, &p, &q);
+ ASSERT_BIGNUM_EQ(n, a);
+ ASSERT_BIGNUM_EQ(p, b);
+ ASSERT_BIGNUM_EQ(q, c);
BN_free(a);
BN_free(b);
BN_free(c);
@@ -151,9 +154,11 @@ sshkey_file_tests(void)
a = load_bignum("dsa_1.param.g");
b = load_bignum("dsa_1.param.priv");
c = load_bignum("dsa_1.param.pub");
- ASSERT_BIGNUM_EQ(k1->dsa->g, a);
- ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b);
- ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c);
+ DSA_get0_pqg(k1->dsa, NULL, NULL, &g);
+ DSA_get0_key(k1->dsa, &pub_key, &priv_key);
+ ASSERT_BIGNUM_EQ(g, a);
+ ASSERT_BIGNUM_EQ(priv_key, b);
+ ASSERT_BIGNUM_EQ(pub_key, c);
BN_free(a);
BN_free(b);
BN_free(c);
Index: openssh-7.8p1/regress/unittests/sshkey/test_sshkey.c
===================================================================
--- openssh-7.8p1.orig/regress/unittests/sshkey/test_sshkey.c
+++ openssh-7.8p1/regress/unittests/sshkey/test_sshkey.c
@@ -197,9 +197,6 @@ sshkey_tests(void)
k1 = sshkey_new(KEY_RSA);
ASSERT_PTR_NE(k1, NULL);
ASSERT_PTR_NE(k1->rsa, NULL);
- ASSERT_PTR_NE(k1->rsa->n, NULL);
- ASSERT_PTR_NE(k1->rsa->e, NULL);
- ASSERT_PTR_EQ(k1->rsa->p, NULL);
sshkey_free(k1);
TEST_DONE();
@@ -207,8 +204,6 @@ sshkey_tests(void)
k1 = sshkey_new(KEY_DSA);
ASSERT_PTR_NE(k1, NULL);
ASSERT_PTR_NE(k1->dsa, NULL);
- ASSERT_PTR_NE(k1->dsa->g, NULL);
- ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
sshkey_free(k1);
TEST_DONE();
@@ -234,9 +229,6 @@ sshkey_tests(void)
k1 = sshkey_new_private(KEY_RSA);
ASSERT_PTR_NE(k1, NULL);
ASSERT_PTR_NE(k1->rsa, NULL);
- ASSERT_PTR_NE(k1->rsa->n, NULL);
- ASSERT_PTR_NE(k1->rsa->e, NULL);
- ASSERT_PTR_NE(k1->rsa->p, NULL);
ASSERT_INT_EQ(sshkey_add_private(k1), 0);
sshkey_free(k1);
TEST_DONE();
@@ -245,8 +237,6 @@ sshkey_tests(void)
k1 = sshkey_new_private(KEY_DSA);
ASSERT_PTR_NE(k1, NULL);
ASSERT_PTR_NE(k1->dsa, NULL);
- ASSERT_PTR_NE(k1->dsa->g, NULL);
- ASSERT_PTR_NE(k1->dsa->priv_key, NULL);
ASSERT_INT_EQ(sshkey_add_private(k1), 0);
sshkey_free(k1);
TEST_DONE();
@@ -285,18 +275,13 @@ sshkey_tests(void)
ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &kr), 0);
ASSERT_PTR_NE(kr, NULL);
ASSERT_PTR_NE(kr->rsa, NULL);
- ASSERT_PTR_NE(kr->rsa->n, NULL);
- ASSERT_PTR_NE(kr->rsa->e, NULL);
- ASSERT_PTR_NE(kr->rsa->p, NULL);
- ASSERT_INT_EQ(BN_num_bits(kr->rsa->n), 1024);
+ ASSERT_INT_EQ(RSA_bits(kr->rsa), 1024);
TEST_DONE();
TEST_START("generate KEY_DSA");
ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0);
ASSERT_PTR_NE(kd, NULL);
ASSERT_PTR_NE(kd->dsa, NULL);
- ASSERT_PTR_NE(kd->dsa->g, NULL);
- ASSERT_PTR_NE(kd->dsa->priv_key, NULL);
TEST_DONE();
#ifdef OPENSSL_HAS_ECC
@@ -323,9 +308,6 @@ sshkey_tests(void)
ASSERT_PTR_NE(kr, k1);
ASSERT_INT_EQ(k1->type, KEY_RSA);
ASSERT_PTR_NE(k1->rsa, NULL);
- ASSERT_PTR_NE(k1->rsa->n, NULL);
- ASSERT_PTR_NE(k1->rsa->e, NULL);
- ASSERT_PTR_EQ(k1->rsa->p, NULL);
TEST_DONE();
TEST_START("equal KEY_RSA/demoted KEY_RSA");
@@ -339,8 +321,6 @@ sshkey_tests(void)
ASSERT_PTR_NE(kd, k1);
ASSERT_INT_EQ(k1->type, KEY_DSA);
ASSERT_PTR_NE(k1->dsa, NULL);
- ASSERT_PTR_NE(k1->dsa->g, NULL);
- ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
TEST_DONE();
TEST_START("equal KEY_DSA/demoted KEY_DSA");
Index: openssh-7.8p1/ssh-dss.c
===================================================================
--- openssh-7.8p1.orig/ssh-dss.c
+++ openssh-7.8p1/ssh-dss.c
@@ -55,6 +55,7 @@ ssh_dss_sign(const struct sshkey *key, u
size_t rlen, slen, len, dlen = ssh_digest_bytes(SSH_DIGEST_SHA1);
struct sshbuf *b = NULL;
int ret = SSH_ERR_INVALID_ARGUMENT;
+ const BIGNUM *r, *s;
if (lenp != NULL)
*lenp = 0;
@@ -76,15 +77,16 @@ ssh_dss_sign(const struct sshkey *key, u
goto out;
}
- rlen = BN_num_bytes(sig->r);
- slen = BN_num_bytes(sig->s);
+ DSA_SIG_get0(sig, &r, &s);
+ rlen = BN_num_bytes(r);
+ slen = BN_num_bytes(s);
if (rlen > INTBLOB_LEN || slen > INTBLOB_LEN) {
ret = SSH_ERR_INTERNAL_ERROR;
goto out;
}
explicit_bzero(sigblob, SIGBLOB_LEN);
- BN_bn2bin(sig->r, sigblob + SIGBLOB_LEN - INTBLOB_LEN - rlen);
- BN_bn2bin(sig->s, sigblob + SIGBLOB_LEN - slen);
+ BN_bn2bin(r, sigblob + SIGBLOB_LEN - INTBLOB_LEN - rlen);
+ BN_bn2bin(s, sigblob + SIGBLOB_LEN - slen);
if ((b = sshbuf_new()) == NULL) {
ret = SSH_ERR_ALLOC_FAIL;
@@ -123,6 +125,7 @@ ssh_dss_verify(const struct sshkey *key,
int ret = SSH_ERR_INTERNAL_ERROR;
struct sshbuf *b = NULL;
char *ktype = NULL;
+ BIGNUM *r = NULL, *s = NULL;
if (key == NULL || key->dsa == NULL ||
sshkey_type_plain(key->type) != KEY_DSA ||
@@ -155,16 +158,19 @@ ssh_dss_verify(const struct sshkey *key,
/* parse signature */
if ((sig = DSA_SIG_new()) == NULL ||
- (sig->r = BN_new()) == NULL ||
- (sig->s = BN_new()) == NULL) {
+ (r = BN_new()) == NULL ||
+ (s = BN_new()) == NULL) {
ret = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if ((BN_bin2bn(sigblob, INTBLOB_LEN, sig->r) == NULL) ||
- (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s) == NULL)) {
+ if ((BN_bin2bn(sigblob, INTBLOB_LEN, r) == NULL) ||
+ (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, s) == NULL) ||
+ (DSA_SIG_set0(sig, r, s) == 0)) {
ret = SSH_ERR_LIBCRYPTO_ERROR;
goto out;
}
+ r = NULL;
+ s = NULL;
/* sha1 the data */
if ((ret = ssh_digest_memory(SSH_DIGEST_SHA1, data, datalen,
@@ -185,6 +191,8 @@ ssh_dss_verify(const struct sshkey *key,
out:
explicit_bzero(digest, sizeof(digest));
+ BN_free(r);
+ BN_free(s);
DSA_SIG_free(sig);
sshbuf_free(b);
free(ktype);
Index: openssh-7.8p1/ssh-ecdsa.c
===================================================================
--- openssh-7.8p1.orig/ssh-ecdsa.c
+++ openssh-7.8p1/ssh-ecdsa.c
@@ -54,6 +54,7 @@ ssh_ecdsa_sign(const struct sshkey *key,
size_t len, dlen;
struct sshbuf *b = NULL, *bb = NULL;
int ret = SSH_ERR_INTERNAL_ERROR;
+ const BIGNUM *r, *s;
if (lenp != NULL)
*lenp = 0;
@@ -80,8 +81,9 @@ ssh_ecdsa_sign(const struct sshkey *key,
ret = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if ((ret = sshbuf_put_bignum2(bb, sig->r)) != 0 ||
- (ret = sshbuf_put_bignum2(bb, sig->s)) != 0)
+ ECDSA_SIG_get0(sig, &r, &s);
+ if ((ret = sshbuf_put_bignum2(bb, r)) != 0 ||
+ (ret = sshbuf_put_bignum2(bb, s)) != 0)
goto out;
if ((ret = sshbuf_put_cstring(b, sshkey_ssh_name_plain(key))) != 0 ||
(ret = sshbuf_put_stringb(b, bb)) != 0)
@@ -118,6 +120,7 @@ ssh_ecdsa_verify(const struct sshkey *ke
int ret = SSH_ERR_INTERNAL_ERROR;
struct sshbuf *b = NULL, *sigbuf = NULL;
char *ktype = NULL;
+ BIGNUM *r = NULL, *s = NULL;
if (key == NULL || key->ecdsa == NULL ||
sshkey_type_plain(key->type) != KEY_ECDSA ||
@@ -146,15 +149,23 @@ ssh_ecdsa_verify(const struct sshkey *ke
}
/* parse signature */
- if ((sig = ECDSA_SIG_new()) == NULL) {
+ if ((sig = ECDSA_SIG_new()) == NULL ||
+ (r = BN_new()) == NULL ||
+ (s = BN_new()) == NULL) {
ret = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if (sshbuf_get_bignum2(sigbuf, sig->r) != 0 ||
- sshbuf_get_bignum2(sigbuf, sig->s) != 0) {
+ if (sshbuf_get_bignum2(sigbuf, r) != 0 ||
+ sshbuf_get_bignum2(sigbuf, s) != 0) {
ret = SSH_ERR_INVALID_FORMAT;
goto out;
}
+ if (ECDSA_SIG_set0(sig, r, s) == 0) {
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
+ goto out;
+ }
+ r = NULL;
+ s = NULL;
if (sshbuf_len(sigbuf) != 0) {
ret = SSH_ERR_UNEXPECTED_TRAILING_DATA;
goto out;
@@ -179,6 +190,8 @@ ssh_ecdsa_verify(const struct sshkey *ke
explicit_bzero(digest, sizeof(digest));
sshbuf_free(sigbuf);
sshbuf_free(b);
+ BN_free(r);
+ BN_free(s);
ECDSA_SIG_free(sig);
free(ktype);
return ret;
Index: openssh-7.8p1/ssh-keygen.c
===================================================================
--- openssh-7.8p1.orig/ssh-keygen.c
+++ openssh-7.8p1/ssh-keygen.c
@@ -495,40 +495,67 @@ do_convert_private_ssh2_from_blob(u_char
free(type);
switch (key->type) {
- case KEY_DSA:
- buffer_get_bignum_bits(b, key->dsa->p);
- buffer_get_bignum_bits(b, key->dsa->g);
- buffer_get_bignum_bits(b, key->dsa->q);
- buffer_get_bignum_bits(b, key->dsa->pub_key);
- buffer_get_bignum_bits(b, key->dsa->priv_key);
+ case KEY_DSA: {
+ BIGNUM *p = NULL, *g = NULL, *q = NULL, *pub_key = NULL, *priv_key = NULL;
+
+ if ((p = BN_new()) == NULL ||
+ (g = BN_new()) == NULL ||
+ (q = BN_new()) == NULL ||
+ (pub_key = BN_new()) == NULL ||
+ (priv_key = BN_new()) == NULL)
+ fatal("BN_new() failed");
+ buffer_get_bignum_bits(b, p);
+ buffer_get_bignum_bits(b, g);
+ buffer_get_bignum_bits(b, q);
+ buffer_get_bignum_bits(b, pub_key);
+ buffer_get_bignum_bits(b, priv_key);
+ if (DSA_set0_pqg(key->dsa, p, q, g) == 0 ||
+ DSA_set0_key(key->dsa, pub_key, priv_key) == 0) {
+ fatal("failed to set DSA key");
+ }
+ }
break;
- case KEY_RSA:
- if ((r = sshbuf_get_u8(b, &e1)) != 0 ||
- (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) ||
- (e1 < 30 && (r = sshbuf_get_u8(b, &e3)) != 0))
- fatal("%s: buffer error: %s", __func__, ssh_err(r));
- e = e1;
- debug("e %lx", e);
- if (e < 30) {
- e <<= 8;
- e += e2;
- debug("e %lx", e);
- e <<= 8;
- e += e3;
+ case KEY_RSA: {
+ BIGNUM *bn_e = NULL, *bn_d = NULL, *bn_n = NULL, *bn_iqmp = NULL, *bn_p = NULL, *bn_q = NULL;
+
+ if ((bn_e = BN_new()) == NULL ||
+ (bn_d = BN_new()) == NULL ||
+ (bn_n = BN_new()) == NULL ||
+ (bn_iqmp = BN_new()) == NULL ||
+ (bn_p = BN_new()) == NULL ||
+ (bn_q = BN_new()) == NULL)
+ fatal("BN_new() failed");
+
+ if ((r = sshbuf_get_u8(b, &e1)) != 0 ||
+ (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) ||
+ (e1 < 30 && (r = sshbuf_get_u8(b, &e3)) != 0))
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
+ e = e1;
debug("e %lx", e);
+ if (e < 30) {
+ e <<= 8;
+ e += e2;
+ debug("e %lx", e);
+ e <<= 8;
+ e += e3;
+ debug("e %lx", e);
+ }
+ if (!BN_set_word(bn_e, e)) {
+ sshbuf_free(b);
+ sshkey_free(key);
+ return NULL;
+ }
+ buffer_get_bignum_bits(b, bn_d);
+ buffer_get_bignum_bits(b, bn_n);
+ buffer_get_bignum_bits(b, bn_iqmp);
+ buffer_get_bignum_bits(b, bn_q);
+ buffer_get_bignum_bits(b, bn_p);
+ if (RSA_set0_key(key->rsa, bn_n, bn_e, bn_d) == 0 ||
+ RSA_set0_factors(key->rsa, bn_p, bn_q) == 0)
+ fatal("Failed to set RSA parameters");
+ if ((r = ssh_rsa_generate_additional_parameters(key, bn_iqmp)) != 0)
+ fatal("generate RSA parameters failed: %s", ssh_err(r));
}
- if (!BN_set_word(key->rsa->e, e)) {
- sshbuf_free(b);
- sshkey_free(key);
- return NULL;
- }
- buffer_get_bignum_bits(b, key->rsa->d);
- buffer_get_bignum_bits(b, key->rsa->n);
- buffer_get_bignum_bits(b, key->rsa->iqmp);
- buffer_get_bignum_bits(b, key->rsa->q);
- buffer_get_bignum_bits(b, key->rsa->p);
- if ((r = ssh_rsa_generate_additional_parameters(key)) != 0)
- fatal("generate RSA parameters failed: %s", ssh_err(r));
break;
}
rlen = sshbuf_len(b);
@@ -636,7 +663,7 @@ do_convert_from_pkcs8(struct sshkey **k,
identity_file);
}
fclose(fp);
- switch (EVP_PKEY_type(pubkey->type)) {
+ switch (EVP_PKEY_base_id(pubkey)) {
case EVP_PKEY_RSA:
if ((*k = sshkey_new(KEY_UNSPEC)) == NULL)
fatal("sshkey_new failed");
@@ -660,7 +687,7 @@ do_convert_from_pkcs8(struct sshkey **k,
#endif
default:
fatal("%s: unsupported pubkey type %d", __func__,
- EVP_PKEY_type(pubkey->type));
+ EVP_PKEY_base_id(pubkey));
}
EVP_PKEY_free(pubkey);
return;
@@ -1806,6 +1833,7 @@ do_ca_sign(struct passwd *pw, int argc,
#ifdef ENABLE_PKCS11
pkcs11_terminate();
#endif
+ free(ca);
exit(0);
}
Index: openssh-7.8p1/ssh-pkcs11-client.c
===================================================================
--- openssh-7.8p1.orig/ssh-pkcs11-client.c
+++ openssh-7.8p1/ssh-pkcs11-client.c
@@ -156,12 +156,16 @@ pkcs11_rsa_private_encrypt(int flen, con
static int
wrap_key(RSA *rsa)
{
- static RSA_METHOD helper_rsa;
+ static RSA_METHOD *helper_rsa;
- memcpy(&helper_rsa, RSA_get_default_method(), sizeof(helper_rsa));
- helper_rsa.name = "ssh-pkcs11-helper";
- helper_rsa.rsa_priv_enc = pkcs11_rsa_private_encrypt;
- RSA_set_method(rsa, &helper_rsa);
+ if (helper_rsa == NULL) {
+ helper_rsa = RSA_meth_dup(RSA_get_default_method());
+ if (helper_rsa == NULL)
+ error("RSA_meth_dup failed");
+ RSA_meth_set1_name(helper_rsa, "ssh-pkcs11-helper");
+ RSA_meth_set_priv_enc(helper_rsa, pkcs11_rsa_private_encrypt);
+ }
+ RSA_set_method(rsa, helper_rsa);
return (0);
}
Index: openssh-7.8p1/ssh-pkcs11.c
===================================================================
--- openssh-7.8p1.orig/ssh-pkcs11.c
+++ openssh-7.8p1/ssh-pkcs11.c
@@ -67,7 +67,7 @@ struct pkcs11_key {
struct pkcs11_provider *provider;
CK_ULONG slotidx;
int (*orig_finish)(RSA *rsa);
- RSA_METHOD rsa_method;
+ RSA_METHOD *rsa_method;
char *keyid;
int keyid_len;
};
@@ -183,6 +183,7 @@ pkcs11_rsa_finish(RSA *rsa)
if (k11->provider)
pkcs11_provider_unref(k11->provider);
free(k11->keyid);
+ RSA_meth_free(k11->rsa_method);
free(k11);
}
return (rv);
@@ -326,13 +327,21 @@ pkcs11_rsa_wrap(struct pkcs11_provider *
k11->keyid = xmalloc(k11->keyid_len);
memcpy(k11->keyid, keyid_attrib->pValue, k11->keyid_len);
}
- k11->orig_finish = def->finish;
- memcpy(&k11->rsa_method, def, sizeof(k11->rsa_method));
- k11->rsa_method.name = "pkcs11";
- k11->rsa_method.rsa_priv_enc = pkcs11_rsa_private_encrypt;
- k11->rsa_method.rsa_priv_dec = pkcs11_rsa_private_decrypt;
- k11->rsa_method.finish = pkcs11_rsa_finish;
- RSA_set_method(rsa, &k11->rsa_method);
+ k11->orig_finish = RSA_meth_get_finish(def);
+ if ((k11->rsa_method = RSA_meth_dup(def)) == NULL ||
+ RSA_meth_set1_name(k11->rsa_method, "pkcs11") == 0 ||
+ RSA_meth_set_priv_enc(k11->rsa_method, pkcs11_rsa_private_encrypt) == 0 ||
+ RSA_meth_set_priv_dec(k11->rsa_method, pkcs11_rsa_private_decrypt) == 0 ||
+ RSA_meth_set_finish(k11->rsa_method, pkcs11_rsa_finish) == 0) {
+ RSA_meth_free(k11->rsa_method);
+ k11->rsa_method = NULL;
+ pkcs11_provider_unref(k11->provider);
+ free(k11->keyid);
+ free(k11);
+ return (-1);
+ }
+
+ RSA_set_method(rsa, k11->rsa_method);
RSA_set_app_data(rsa, k11);
return (0);
}
@@ -460,6 +469,7 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
CK_ULONG nfound;
CK_SESSION_HANDLE session;
CK_FUNCTION_LIST *f;
+ const BIGNUM *n, *e;
f = p->function_list;
session = p->slotinfo[slotidx].session;
@@ -512,10 +522,16 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
if ((rsa = RSA_new()) == NULL) {
error("RSA_new failed");
} else {
- rsa->n = BN_bin2bn(attribs[1].pValue,
+ BIGNUM *rsa_n, *rsa_e;
+
+ rsa_n = BN_bin2bn(attribs[1].pValue,
attribs[1].ulValueLen, NULL);
- rsa->e = BN_bin2bn(attribs[2].pValue,
+ rsa_e = BN_bin2bn(attribs[2].pValue,
attribs[2].ulValueLen, NULL);
+ if (rsa_n == NULL || rsa_e == NULL)
+ error("BN_bin2bn failed");
+ if (RSA_set0_key(rsa, rsa_n, rsa_e, NULL) == 0)
+ error("RSA_set0_key failed");
}
} else {
cp = attribs[2].pValue;
@@ -525,16 +541,18 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
== NULL) {
error("d2i_X509 failed");
} else if ((evp = X509_get_pubkey(x509)) == NULL ||
- evp->type != EVP_PKEY_RSA ||
- evp->pkey.rsa == NULL) {
+ EVP_PKEY_id(evp) != EVP_PKEY_RSA ||
+ EVP_PKEY_get0_RSA(evp) == NULL) {
debug("X509_get_pubkey failed or no rsa");
- } else if ((rsa = RSAPublicKey_dup(evp->pkey.rsa))
+ } else if ((rsa = RSAPublicKey_dup(EVP_PKEY_get0_RSA(evp)))
== NULL) {
error("RSAPublicKey_dup");
}
X509_free(x509);
}
- if (rsa && rsa->n && rsa->e &&
+ if (rsa)
+ RSA_get0_key(rsa, &n, &e, NULL);
+ if (rsa && n && e &&
pkcs11_rsa_wrap(p, slotidx, &attribs[0], rsa) == 0) {
if ((key = sshkey_new(KEY_UNSPEC)) == NULL)
fatal("sshkey_new failed");
Index: openssh-7.8p1/ssh-rsa.c
===================================================================
--- openssh-7.8p1.orig/ssh-rsa.c
+++ openssh-7.8p1/ssh-rsa.c
@@ -104,38 +104,50 @@ rsa_hash_alg_nid(int type)
}
int
-ssh_rsa_generate_additional_parameters(struct sshkey *key)
+ssh_rsa_generate_additional_parameters(struct sshkey *key, BIGNUM *iqmp)
{
BIGNUM *aux = NULL;
BN_CTX *ctx = NULL;
- BIGNUM d;
+ BIGNUM *d = NULL;
int r;
+ const BIGNUM *p, *q, *rsa_d;
+ BIGNUM *dmp1 = NULL, *dmq1 = NULL;
if (key == NULL || key->rsa == NULL ||
sshkey_type_plain(key->type) != KEY_RSA)
return SSH_ERR_INVALID_ARGUMENT;
- if ((ctx = BN_CTX_new()) == NULL)
- return SSH_ERR_ALLOC_FAIL;
- if ((aux = BN_new()) == NULL) {
+ RSA_get0_factors(key->rsa, &p, &q);
+ RSA_get0_key(key->rsa, NULL, NULL, &rsa_d);
+
+ if ((ctx = BN_CTX_new()) == NULL ||
+ (aux = BN_new()) == NULL ||
+ (d = BN_new()) == NULL ||
+ (dmp1 = BN_new()) == NULL ||
+ (dmq1 = BN_new()) == NULL) {
r = SSH_ERR_ALLOC_FAIL;
goto out;
}
BN_set_flags(aux, BN_FLG_CONSTTIME);
- BN_init(&d);
- BN_with_flags(&d, key->rsa->d, BN_FLG_CONSTTIME);
+ BN_with_flags(d, rsa_d, BN_FLG_CONSTTIME);
- if ((BN_sub(aux, key->rsa->q, BN_value_one()) == 0) ||
- (BN_mod(key->rsa->dmq1, &d, aux, ctx) == 0) ||
- (BN_sub(aux, key->rsa->p, BN_value_one()) == 0) ||
- (BN_mod(key->rsa->dmp1, &d, aux, ctx) == 0)) {
+ if ((BN_sub(aux, q, BN_value_one()) == 0) ||
+ (BN_mod(dmq1, d, aux, ctx) == 0) ||
+ (BN_sub(aux, p, BN_value_one()) == 0) ||
+ (BN_mod(dmp1, d, aux, ctx) == 0) ||
+ (RSA_set0_crt_params(key->rsa, dmp1, dmq1, iqmp) == 0)) {
r = SSH_ERR_LIBCRYPTO_ERROR;
goto out;
}
+ dmp1 = NULL;
+ dmq1 = NULL;
r = 0;
out:
+ BN_free(d);
BN_clear_free(aux);
+ BN_clear_free(dmp1);
+ BN_clear_free(dmq1);
BN_CTX_free(ctx);
return r;
}
@@ -163,7 +175,7 @@ ssh_rsa_sign(const struct sshkey *key, u
if (key == NULL || key->rsa == NULL || hash_alg == -1 ||
sshkey_type_plain(key->type) != KEY_RSA)
return SSH_ERR_INVALID_ARGUMENT;
- if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE)
+ if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
return SSH_ERR_KEY_LENGTH;
slen = RSA_size(key->rsa);
if (slen <= 0 || slen > SSHBUF_MAX_BIGNUM)
@@ -235,7 +247,7 @@ ssh_rsa_verify(const struct sshkey *key,
sshkey_type_plain(key->type) != KEY_RSA ||
sig == NULL || siglen == 0)
return SSH_ERR_INVALID_ARGUMENT;
- if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE)
+ if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
return SSH_ERR_KEY_LENGTH;
if ((b = sshbuf_from(sig, siglen)) == NULL)
Index: openssh-7.8p1/sshconnect.c
===================================================================
--- openssh-7.8p1.orig/sshconnect.c
+++ openssh-7.8p1/sshconnect.c
@@ -1399,6 +1399,7 @@ ssh_login(Sensitive *sensitive, const ch
char *server_user, *local_user;
local_user = xstrdup(pw->pw_name);
+ free(pw);
server_user = options.user ? options.user : local_user;
/* Convert the user-supplied hostname into all lowercase. */
Index: openssh-7.8p1/sshkey.c
===================================================================
--- openssh-7.8p1.orig/sshkey.c
+++ openssh-7.8p1/sshkey.c
@@ -293,10 +293,10 @@ sshkey_size(const struct sshkey *k)
#ifdef WITH_OPENSSL
case KEY_RSA:
case KEY_RSA_CERT:
- return BN_num_bits(k->rsa->n);
+ return RSA_bits(k->rsa);
case KEY_DSA:
case KEY_DSA_CERT:
- return BN_num_bits(k->dsa->p);
+ return DSA_bits(k->dsa);
case KEY_ECDSA:
case KEY_ECDSA_CERT:
return sshkey_curve_nid_to_bits(k->ecdsa_nid);
@@ -325,6 +325,31 @@ sshkey_type_is_valid_ca(int type)
}
}
+
+static int
+sshkey_is_private_rsa(const RSA *r)
+{
+ const BIGNUM *d;
+ int rv;
+
+ RSA_get0_key(r, NULL, NULL, &d);
+ rv = (d != NULL);
+ d = NULL;
+ return rv;
+}
+
+static int
+sshkey_is_private_dsa(const DSA *d)
+{
+ const BIGNUM *priv_key;
+ int rv;
+
+ DSA_get0_key(d, NULL, &priv_key);
+ rv = (priv_key != NULL);
+ priv_key = NULL;
+ return rv;
+}
+
int
sshkey_is_private(const struct sshkey *k)
{
@@ -332,10 +357,10 @@ sshkey_is_private(const struct sshkey *k
#ifdef WITH_OPENSSL
case KEY_RSA_CERT:
case KEY_RSA:
- return k->rsa->d != NULL;
+ return sshkey_is_private_rsa(k->rsa);
case KEY_DSA_CERT:
case KEY_DSA:
- return k->dsa->priv_key != NULL;
+ return sshkey_is_private_dsa(k->dsa);
#ifdef OPENSSL_HAS_ECC
case KEY_ECDSA_CERT:
case KEY_ECDSA:
@@ -527,10 +552,7 @@ sshkey_new(int type)
#ifdef WITH_OPENSSL
case KEY_RSA:
case KEY_RSA_CERT:
- if ((rsa = RSA_new()) == NULL ||
- (rsa->n = BN_new()) == NULL ||
- (rsa->e = BN_new()) == NULL) {
- RSA_free(rsa);
+ if ((rsa = RSA_new()) == NULL) {
free(k);
return NULL;
}
@@ -538,12 +560,7 @@ sshkey_new(int type)
break;
case KEY_DSA:
case KEY_DSA_CERT:
- if ((dsa = DSA_new()) == NULL ||
- (dsa->p = BN_new()) == NULL ||
- (dsa->q = BN_new()) == NULL ||
- (dsa->g = BN_new()) == NULL ||
- (dsa->pub_key = BN_new()) == NULL) {
- DSA_free(dsa);
+ if ((dsa = DSA_new()) == NULL) {
free(k);
return NULL;
}
@@ -584,21 +601,10 @@ sshkey_add_private(struct sshkey *k)
#ifdef WITH_OPENSSL
case KEY_RSA:
case KEY_RSA_CERT:
-#define bn_maybe_alloc_failed(p) (p == NULL && (p = BN_new()) == NULL)
- if (bn_maybe_alloc_failed(k->rsa->d) ||
- bn_maybe_alloc_failed(k->rsa->iqmp) ||
- bn_maybe_alloc_failed(k->rsa->q) ||
- bn_maybe_alloc_failed(k->rsa->p) ||
- bn_maybe_alloc_failed(k->rsa->dmq1) ||
- bn_maybe_alloc_failed(k->rsa->dmp1))
- return SSH_ERR_ALLOC_FAIL;
break;
case KEY_DSA:
case KEY_DSA_CERT:
- if (bn_maybe_alloc_failed(k->dsa->priv_key))
- return SSH_ERR_ALLOC_FAIL;
break;
-#undef bn_maybe_alloc_failed
case KEY_ECDSA:
case KEY_ECDSA_CERT:
/* Cannot do anything until we know the group */
@@ -721,17 +727,31 @@ sshkey_equal_public(const struct sshkey
switch (a->type) {
#ifdef WITH_OPENSSL
case KEY_RSA_CERT:
- case KEY_RSA:
- return a->rsa != NULL && b->rsa != NULL &&
- BN_cmp(a->rsa->e, b->rsa->e) == 0 &&
- BN_cmp(a->rsa->n, b->rsa->n) == 0;
+ case KEY_RSA: {
+ const BIGNUM *a_e, *a_n, *b_e, *b_n;
+
+ if (a->rsa == NULL || b->rsa == NULL)
+ return 0;
+ RSA_get0_key(a->rsa, &a_n, &a_e, NULL);
+ RSA_get0_key(b->rsa, &b_n, &b_e, NULL);
+ return BN_cmp(a_e, b_e) == 0 && BN_cmp(a_n, b_n) == 0;
+ }
case KEY_DSA_CERT:
- case KEY_DSA:
- return a->dsa != NULL && b->dsa != NULL &&
- BN_cmp(a->dsa->p, b->dsa->p) == 0 &&
- BN_cmp(a->dsa->q, b->dsa->q) == 0 &&
- BN_cmp(a->dsa->g, b->dsa->g) == 0 &&
- BN_cmp(a->dsa->pub_key, b->dsa->pub_key) == 0;
+ case KEY_DSA: {
+ const BIGNUM *a_p, *a_q, *a_g, *a_pub_key;
+ const BIGNUM *b_p, *b_q, *b_g, *b_pub_key;
+
+ if (a->dsa == NULL || b->dsa == NULL)
+ return 0;
+ DSA_get0_pqg(a->dsa, &a_p, &a_q, &a_g);
+ DSA_get0_key(a->dsa, &a_pub_key, NULL);
+ DSA_get0_pqg(b->dsa, &b_p, &b_q, &b_g);
+ DSA_get0_key(b->dsa, &b_pub_key, NULL);
+ return BN_cmp(a_p, b_p) == 0 &&
+ BN_cmp(a_q, b_q) == 0 &&
+ BN_cmp(a_g, b_g) == 0 &&
+ BN_cmp(a_pub_key, b_pub_key) == 0;
+ }
# ifdef OPENSSL_HAS_ECC
case KEY_ECDSA_CERT:
case KEY_ECDSA:
@@ -817,15 +837,21 @@ to_blob_buf(const struct sshkey *key, st
return ret;
break;
#ifdef WITH_OPENSSL
- case KEY_DSA:
- if (key->dsa == NULL)
- return SSH_ERR_INVALID_ARGUMENT;
- if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
- (ret = sshbuf_put_bignum2(b, key->dsa->p)) != 0 ||
- (ret = sshbuf_put_bignum2(b, key->dsa->q)) != 0 ||
- (ret = sshbuf_put_bignum2(b, key->dsa->g)) != 0 ||
- (ret = sshbuf_put_bignum2(b, key->dsa->pub_key)) != 0)
- return ret;
+ case KEY_DSA: {
+ const BIGNUM *p, *q, *g, *pub_key;
+
+ if (key->dsa == NULL)
+ return SSH_ERR_INVALID_ARGUMENT;
+
+ DSA_get0_pqg(key->dsa, &p, &q, &g);
+ DSA_get0_key(key->dsa, &pub_key, NULL);
+ if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
+ (ret = sshbuf_put_bignum2(b, p)) != 0 ||
+ (ret = sshbuf_put_bignum2(b, q)) != 0 ||
+ (ret = sshbuf_put_bignum2(b, g)) != 0 ||
+ (ret = sshbuf_put_bignum2(b, pub_key)) != 0)
+ return ret;
+ }
break;
# ifdef OPENSSL_HAS_ECC
case KEY_ECDSA:
@@ -838,13 +864,18 @@ to_blob_buf(const struct sshkey *key, st
return ret;
break;
# endif
- case KEY_RSA:
- if (key->rsa == NULL)
- return SSH_ERR_INVALID_ARGUMENT;
- if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
- (ret = sshbuf_put_bignum2(b, key->rsa->e)) != 0 ||
- (ret = sshbuf_put_bignum2(b, key->rsa->n)) != 0)
- return ret;
+ case KEY_RSA: {
+ const BIGNUM *e, *n;
+
+ if (key->rsa == NULL)
+ return SSH_ERR_INVALID_ARGUMENT;
+
+ RSA_get0_key(key->rsa, &n, &e, NULL);
+ if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
+ (ret = sshbuf_put_bignum2(b, e)) != 0 ||
+ (ret = sshbuf_put_bignum2(b, n)) != 0)
+ return ret;
+ }
break;
#endif /* WITH_OPENSSL */
case KEY_ED25519:
@@ -1782,15 +1813,32 @@ sshkey_from_private(const struct sshkey
switch (k->type) {
#ifdef WITH_OPENSSL
case KEY_DSA:
- case KEY_DSA_CERT:
- if ((n = sshkey_new(k->type)) == NULL)
- return SSH_ERR_ALLOC_FAIL;
- if ((BN_copy(n->dsa->p, k->dsa->p) == NULL) ||
- (BN_copy(n->dsa->q, k->dsa->q) == NULL) ||
- (BN_copy(n->dsa->g, k->dsa->g) == NULL) ||
- (BN_copy(n->dsa->pub_key, k->dsa->pub_key) == NULL)) {
- sshkey_free(n);
- return SSH_ERR_ALLOC_FAIL;
+ case KEY_DSA_CERT: {
+ const BIGNUM *k_p, *k_q, *k_g, *k_pub_key;
+ BIGNUM *n_p = NULL, *n_q = NULL, *n_g = NULL, *n_pub_key = NULL;
+
+ if ((n = sshkey_new(k->type)) == NULL)
+ return SSH_ERR_ALLOC_FAIL;
+
+ DSA_get0_pqg(k->dsa, &k_p, &k_q, &k_g);
+ DSA_get0_key(k->dsa, &k_pub_key, NULL);
+
+ if (((n_p = BN_dup(k_p)) == NULL) ||
+ ((n_q = BN_dup(k_q)) == NULL) ||
+ ((n_g = BN_dup(k_g)) == NULL) ||
+ (DSA_set0_pqg(n->dsa, n_p, n_q, n_g) == 0)) {
+ sshkey_free(n);
+ BN_free(n_p);
+ BN_free(n_q);
+ BN_free(n_g);
+ return SSH_ERR_ALLOC_FAIL;
+ }
+ if (((n_pub_key = BN_dup(k_pub_key)) == NULL) ||
+ (DSA_set0_key(n->dsa, n_pub_key, NULL) == 0)) {
+ sshkey_free(n);
+ BN_free(n_pub_key);
+ return SSH_ERR_ALLOC_FAIL;
+ }
}
break;
# ifdef OPENSSL_HAS_ECC
@@ -1812,13 +1860,22 @@ sshkey_from_private(const struct sshkey
break;
# endif /* OPENSSL_HAS_ECC */
case KEY_RSA:
- case KEY_RSA_CERT:
- if ((n = sshkey_new(k->type)) == NULL)
- return SSH_ERR_ALLOC_FAIL;
- if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
- (BN_copy(n->rsa->e, k->rsa->e) == NULL)) {
- sshkey_free(n);
- return SSH_ERR_ALLOC_FAIL;
+ case KEY_RSA_CERT: {
+ const BIGNUM *k_n, *k_e;
+ BIGNUM *n_n = NULL, *n_e = NULL;
+
+ if ((n = sshkey_new(k->type)) == NULL)
+ return SSH_ERR_ALLOC_FAIL;
+
+ RSA_get0_key(k->rsa, &k_n, &k_e, NULL);
+ if (((n_n = BN_dup(k_n)) == NULL) ||
+ ((n_e = BN_dup(k_e)) == NULL) ||
+ RSA_set0_key(n->rsa, n_n, n_e, NULL) == 0) {
+ sshkey_free(n);
+ BN_free(n_n);
+ BN_free(n_e);
+ return SSH_ERR_ALLOC_FAIL;
+ }
}
break;
#endif /* WITH_OPENSSL */
@@ -2040,12 +2097,22 @@ sshkey_from_blob_internal(struct sshbuf
ret = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if (sshbuf_get_bignum2(b, key->rsa->e) != 0 ||
- sshbuf_get_bignum2(b, key->rsa->n) != 0) {
- ret = SSH_ERR_INVALID_FORMAT;
- goto out;
+ {
+ BIGNUM *e, *n;
+
+ e = BN_new();
+ n = BN_new();
+ if (e == NULL || n == NULL ||
+ sshbuf_get_bignum2(b, e) != 0 ||
+ sshbuf_get_bignum2(b, n) != 0 ||
+ RSA_set0_key(key->rsa, n, e, NULL) == 0) {
+ BN_free(e);
+ BN_free(n);
+ ret = SSH_ERR_ALLOC_FAIL;
+ goto out;
+ }
}
- if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
+ if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
ret = SSH_ERR_KEY_LENGTH;
goto out;
}
@@ -2065,12 +2132,34 @@ sshkey_from_blob_internal(struct sshbuf
ret = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if (sshbuf_get_bignum2(b, key->dsa->p) != 0 ||
- sshbuf_get_bignum2(b, key->dsa->q) != 0 ||
- sshbuf_get_bignum2(b, key->dsa->g) != 0 ||
- sshbuf_get_bignum2(b, key->dsa->pub_key) != 0) {
- ret = SSH_ERR_INVALID_FORMAT;
- goto out;
+ {
+ BIGNUM *p, *q, *g, *pub_key;
+
+ p = BN_new();
+ q = BN_new();
+ g = BN_new();
+ pub_key = BN_new();
+
+ if (p == NULL || q == NULL || g == NULL ||
+ pub_key == NULL ||
+ sshbuf_get_bignum2(b, p) != 0 ||
+ sshbuf_get_bignum2(b, q) != 0 ||
+ sshbuf_get_bignum2(b, g) != 0 ||
+ sshbuf_get_bignum2(b, pub_key) != 0 ||
+ DSA_set0_pqg(key->dsa, p, q, g) == 0) {
+ BN_free(p);
+ BN_free(q);
+ BN_free(g);
+ BN_free(pub_key);
+ ret = SSH_ERR_ALLOC_FAIL;
+ goto out;
+ }
+
+ if (DSA_set0_key(key->dsa, pub_key, NULL) == 0) {
+ BN_free(pub_key);
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
+ goto out;
+ }
}
#ifdef DEBUG_PK
DSA_print_fp(stderr, key->dsa, 8);
@@ -2415,26 +2504,53 @@ sshkey_demote(const struct sshkey *k, st
if ((ret = sshkey_cert_copy(k, pk)) != 0)
goto fail;
/* FALLTHROUGH */
- case KEY_RSA:
- if ((pk->rsa = RSA_new()) == NULL ||
- (pk->rsa->e = BN_dup(k->rsa->e)) == NULL ||
- (pk->rsa->n = BN_dup(k->rsa->n)) == NULL) {
- ret = SSH_ERR_ALLOC_FAIL;
- goto fail;
+ case KEY_RSA: {
+ const BIGNUM *k_e, *k_n;
+ BIGNUM *pk_e = NULL, *pk_n = NULL;
+
+ RSA_get0_key(k->rsa, &k_n, &k_e, NULL);
+ if ((pk->rsa = RSA_new()) == NULL ||
+ (pk_e = BN_dup(k_e)) == NULL ||
+ (pk_n = BN_dup(k_n)) == NULL ||
+ RSA_set0_key(pk->rsa, pk_n, pk_e, NULL) == 0) {
+ BN_free(pk_e);
+ BN_free(pk_n);
+ ret = SSH_ERR_ALLOC_FAIL;
+ goto fail;
}
+ }
break;
case KEY_DSA_CERT:
if ((ret = sshkey_cert_copy(k, pk)) != 0)
goto fail;
/* FALLTHROUGH */
- case KEY_DSA:
- if ((pk->dsa = DSA_new()) == NULL ||
- (pk->dsa->p = BN_dup(k->dsa->p)) == NULL ||
- (pk->dsa->q = BN_dup(k->dsa->q)) == NULL ||
- (pk->dsa->g = BN_dup(k->dsa->g)) == NULL ||
- (pk->dsa->pub_key = BN_dup(k->dsa->pub_key)) == NULL) {
- ret = SSH_ERR_ALLOC_FAIL;
- goto fail;
+ case KEY_DSA: {
+ const BIGNUM *k_p, *k_q, *k_g, *k_pub_key;
+ BIGNUM *pk_p = NULL, *pk_q = NULL, *pk_g = NULL;
+ BIGNUM *pk_pub_key = NULL;
+
+ DSA_get0_pqg(k->dsa, &k_p, &k_q, &k_g);
+ DSA_get0_key(k->dsa, &k_pub_key, NULL);
+
+ if ((pk->dsa = DSA_new()) == NULL ||
+ (pk_p = BN_dup(k_p)) == NULL ||
+ (pk_q = BN_dup(k_q)) == NULL ||
+ (pk_g = BN_dup(k_g)) == NULL ||
+ (pk_pub_key = BN_dup(k_pub_key)) == NULL ||
+ DSA_set0_pqg(pk->dsa, pk_p, pk_q, pk_g) == 0) {
+ BN_free(pk_p);
+ BN_free(pk_q);
+ BN_free(pk_g);
+ BN_free(pk_pub_key);
+ ret = SSH_ERR_ALLOC_FAIL;
+ goto fail;
+ }
+
+ if (DSA_set0_key(pk->dsa, pk_pub_key, NULL) == 0) {
+ BN_free(pk_pub_key);
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
+ goto fail;
+ }
}
break;
case KEY_ECDSA_CERT:
@@ -2584,12 +2700,17 @@ sshkey_certify_custom(struct sshkey *k,
/* XXX this substantially duplicates to_blob(); refactor */
switch (k->type) {
#ifdef WITH_OPENSSL
- case KEY_DSA_CERT:
- if ((ret = sshbuf_put_bignum2(cert, k->dsa->p)) != 0 ||
- (ret = sshbuf_put_bignum2(cert, k->dsa->q)) != 0 ||
- (ret = sshbuf_put_bignum2(cert, k->dsa->g)) != 0 ||
- (ret = sshbuf_put_bignum2(cert, k->dsa->pub_key)) != 0)
- goto out;
+ case KEY_DSA_CERT: {
+ const BIGNUM *p, *q, *g, *pub_key;
+
+ DSA_get0_pqg(k->dsa, &p, &q, &g);
+ DSA_get0_key(k->dsa, &pub_key, NULL);
+ if ((ret = sshbuf_put_bignum2(cert, p)) != 0 ||
+ (ret = sshbuf_put_bignum2(cert, q)) != 0 ||
+ (ret = sshbuf_put_bignum2(cert, g)) != 0 ||
+ (ret = sshbuf_put_bignum2(cert, pub_key)) != 0)
+ goto out;
+ }
break;
# ifdef OPENSSL_HAS_ECC
case KEY_ECDSA_CERT:
@@ -2601,10 +2722,15 @@ sshkey_certify_custom(struct sshkey *k,
goto out;
break;
# endif /* OPENSSL_HAS_ECC */
- case KEY_RSA_CERT:
- if ((ret = sshbuf_put_bignum2(cert, k->rsa->e)) != 0 ||
- (ret = sshbuf_put_bignum2(cert, k->rsa->n)) != 0)
- goto out;
+ case KEY_RSA_CERT: {
+ const BIGNUM *e, *n;
+
+ RSA_get0_key(k->rsa, &n, &e, NULL);
+ if (e == NULL || n == NULL ||
+ (ret = sshbuf_put_bignum2(cert, e)) != 0 ||
+ (ret = sshbuf_put_bignum2(cert, n)) != 0)
+ goto out;
+ }
break;
#endif /* WITH_OPENSSL */
case KEY_ED25519_CERT:
@@ -2790,43 +2916,65 @@ sshkey_private_serialize_opt(const struc
goto out;
switch (key->type) {
#ifdef WITH_OPENSSL
- case KEY_RSA:
- if ((r = sshbuf_put_bignum2(b, key->rsa->n)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->e)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->d)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->iqmp)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->p)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->q)) != 0)
- goto out;
+ case KEY_RSA: {
+ const BIGNUM *n, *e, *d, *iqmp, *p, *q;
+ RSA_get0_key(key->rsa, &n, &e, &d);
+ RSA_get0_crt_params(key->rsa, NULL, NULL, &iqmp);
+ RSA_get0_factors(key->rsa, &p, &q);
+ if ((r = sshbuf_put_bignum2(b, n)) != 0 ||
+ (r = sshbuf_put_bignum2(b, e)) != 0 ||
+ (r = sshbuf_put_bignum2(b, d)) != 0 ||
+ (r = sshbuf_put_bignum2(b, iqmp)) != 0 ||
+ (r = sshbuf_put_bignum2(b, p)) != 0 ||
+ (r = sshbuf_put_bignum2(b, q)) != 0)
+ goto out;
+ }
break;
case KEY_RSA_CERT:
if (key->cert == NULL || sshbuf_len(key->cert->certblob) == 0) {
r = SSH_ERR_INVALID_ARGUMENT;
goto out;
}
- if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->d)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->iqmp)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->p)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->rsa->q)) != 0)
- goto out;
+ {
+ const BIGNUM *d, *iqmp, *p, *q;
+
+ RSA_get0_key(key->rsa, NULL, NULL, &d);
+ RSA_get0_factors(key->rsa, &p, &q);
+ RSA_get0_crt_params(key->rsa, NULL, NULL, &iqmp);
+ if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
+ (r = sshbuf_put_bignum2(b, d)) != 0 ||
+ (r = sshbuf_put_bignum2(b, iqmp)) != 0 ||
+ (r = sshbuf_put_bignum2(b, p)) != 0 ||
+ (r = sshbuf_put_bignum2(b, q)) != 0)
+ goto out;
+ }
break;
- case KEY_DSA:
- if ((r = sshbuf_put_bignum2(b, key->dsa->p)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->dsa->q)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->dsa->g)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->dsa->pub_key)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->dsa->priv_key)) != 0)
- goto out;
+ case KEY_DSA: {
+ const BIGNUM *p, *q, *g, *pub_key, *priv_key;
+
+ DSA_get0_pqg(key->dsa, &p, &q, &g);
+ DSA_get0_key(key->dsa, &pub_key, &priv_key);
+ if ((r = sshbuf_put_bignum2(b, p)) != 0 ||
+ (r = sshbuf_put_bignum2(b, q)) != 0 ||
+ (r = sshbuf_put_bignum2(b, g)) != 0 ||
+ (r = sshbuf_put_bignum2(b, pub_key)) != 0 ||
+ (r = sshbuf_put_bignum2(b, priv_key)) != 0)
+ goto out;
+ }
break;
case KEY_DSA_CERT:
if (key->cert == NULL || sshbuf_len(key->cert->certblob) == 0) {
r = SSH_ERR_INVALID_ARGUMENT;
goto out;
}
- if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
- (r = sshbuf_put_bignum2(b, key->dsa->priv_key)) != 0)
- goto out;
+ {
+ const BIGNUM *priv_key;
+
+ DSA_get0_key(key->dsa, NULL, &priv_key);
+ if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
+ (r = sshbuf_put_bignum2(b, priv_key)) != 0)
+ goto out;
+ }
break;
# ifdef OPENSSL_HAS_ECC
case KEY_ECDSA:
@@ -2940,18 +3088,51 @@ sshkey_private_deserialize(struct sshbuf
r = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if ((r = sshbuf_get_bignum2(buf, k->dsa->p)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->dsa->q)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->dsa->g)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->dsa->pub_key)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->dsa->priv_key)) != 0)
- goto out;
+ {
+ BIGNUM *p, *q, *g, *pub_key, *priv_key;
+
+ p = BN_new();
+ q = BN_new();
+ g = BN_new();
+ pub_key = BN_new();
+ priv_key = BN_new();
+ if (p == NULL || q == NULL || g == NULL ||
+ pub_key == NULL || priv_key == NULL ||
+ (r = sshbuf_get_bignum2(buf, p)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, q)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, g)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, pub_key)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, priv_key)) != 0 ||
+ (r = ((DSA_set0_pqg(k->dsa, p, q, g) == 0)
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
+ BN_free(p);
+ BN_free(q);
+ BN_free(g);
+ BN_free(pub_key);
+ BN_free(priv_key);
+ goto out;
+ }
+ if (DSA_set0_key(k->dsa, pub_key, priv_key) == 0) {
+ r = SSH_ERR_LIBCRYPTO_ERROR;
+ BN_free(pub_key);
+ BN_free(priv_key);
+ goto out;
+ }
+ }
break;
- case KEY_DSA_CERT:
- if ((r = sshkey_froms(buf, &k)) != 0 ||
- (r = sshkey_add_private(k)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->dsa->priv_key)) != 0)
- goto out;
+ case KEY_DSA_CERT: {
+ BIGNUM *priv_key = BN_new();
+
+ if (priv_key == NULL ||
+ (r = sshkey_froms(buf, &k)) != 0 ||
+ (r = sshkey_add_private(k)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, priv_key)) != 0 ||
+ (r = ((DSA_set0_key(k->dsa, NULL, priv_key) == 0)
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
+ BN_free(priv_key);
+ goto out;
+ }
+ }
break;
# ifdef OPENSSL_HAS_ECC
case KEY_ECDSA:
@@ -3010,29 +3191,89 @@ sshkey_private_deserialize(struct sshbuf
r = SSH_ERR_ALLOC_FAIL;
goto out;
}
- if ((r = sshbuf_get_bignum2(buf, k->rsa->n)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->e)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->d)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->iqmp)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->p)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->q)) != 0 ||
- (r = ssh_rsa_generate_additional_parameters(k)) != 0)
- goto out;
- if (BN_num_bits(k->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
+ {
+ BIGNUM *n, *e, *d, *iqmp, *p, *q;
+
+ n = BN_new();
+ e = BN_new();
+ d = BN_new();
+ iqmp = BN_new();
+ p = BN_new();
+ q = BN_new();
+
+ if (n == NULL || e == NULL || d == NULL ||
+ iqmp == NULL || p == NULL || q == NULL ||
+ (r = sshbuf_get_bignum2(buf, n)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, e)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, d)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, iqmp)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, p)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, q)) != 0 ||
+ (r = ((RSA_set0_key(k->rsa, n, e, d) == 0)
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
+ BN_free(n);
+ BN_free(e);
+ BN_free(d);
+ BN_free(iqmp);
+ BN_free(p);
+ BN_free(q);
+ goto out;
+ }
+ if (RSA_set0_factors(k->rsa, p, q) == 0) {
+ r = SSH_ERR_LIBCRYPTO_ERROR;
+ BN_free(iqmp);
+ BN_free(p);
+ BN_free(q);
+ goto out;
+ }
+ if ((r = ssh_rsa_generate_additional_parameters(k, iqmp)) != 0) {
+ BN_free(iqmp);
+ goto out;
+ }
+ }
+ if (RSA_bits(k->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
r = SSH_ERR_KEY_LENGTH;
goto out;
}
break;
- case KEY_RSA_CERT:
- if ((r = sshkey_froms(buf, &k)) != 0 ||
- (r = sshkey_add_private(k)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->d)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->iqmp)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->p)) != 0 ||
- (r = sshbuf_get_bignum2(buf, k->rsa->q)) != 0 ||
- (r = ssh_rsa_generate_additional_parameters(k)) != 0)
- goto out;
- if (BN_num_bits(k->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
+ case KEY_RSA_CERT: {
+ BIGNUM *d, *iqmp, *p, *q;
+
+ /* N and E are already set so make sure we will not overwrite them */
+ d = BN_new();
+ iqmp = BN_new();
+ p = BN_new();
+ q = BN_new();
+
+ if (d == NULL || iqmp == NULL || p == NULL ||
+ q == NULL ||
+ (r = sshkey_froms(buf, &k)) != 0 ||
+ (r = sshkey_add_private(k)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, d)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, iqmp)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, p)) != 0 ||
+ (r = sshbuf_get_bignum2(buf, q)) != 0 ||
+ (r = ((RSA_set0_key(k->rsa, NULL, NULL, d) == 0)
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
+ BN_free(d);
+ BN_free(iqmp);
+ BN_free(p);
+ BN_free(q);
+ goto out;
+ }
+ if (RSA_set0_factors(k->rsa, p, q) == 0) {
+ r = SSH_ERR_LIBCRYPTO_ERROR;
+ BN_free(p);
+ BN_free(q);
+ goto out;
+ }
+ if (ssh_rsa_generate_additional_parameters(k, iqmp) != 0) {
+ r = SSH_ERR_LIBCRYPTO_ERROR;
+ free(iqmp);
+ goto out;
+ }
+ }
+ if (RSA_bits(k->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
r = SSH_ERR_KEY_LENGTH;
goto out;
}
@@ -3796,7 +4037,9 @@ translate_libcrypto_error(unsigned long
switch (pem_reason) {
case EVP_R_BAD_DECRYPT:
return SSH_ERR_KEY_WRONG_PASSPHRASE;
+#ifdef EVP_R_BN_DECODE_ERROR
case EVP_R_BN_DECODE_ERROR:
+#endif
case EVP_R_DECODE_ERROR:
#ifdef EVP_R_PRIVATE_KEY_DECODE_ERROR
case EVP_R_PRIVATE_KEY_DECODE_ERROR:
@@ -3861,7 +4104,7 @@ sshkey_parse_private_pem_fileblob(struct
r = convert_libcrypto_error();
goto out;
}
- if (pk->type == EVP_PKEY_RSA &&
+ if (EVP_PKEY_id(pk) == EVP_PKEY_RSA &&
(type == KEY_UNSPEC || type == KEY_RSA)) {
if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
r = SSH_ERR_ALLOC_FAIL;
@@ -3876,11 +4119,11 @@ sshkey_parse_private_pem_fileblob(struct
r = SSH_ERR_LIBCRYPTO_ERROR;
goto out;
}
- if (BN_num_bits(prv->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
+ if (RSA_bits(prv->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
r = SSH_ERR_KEY_LENGTH;
goto out;
}
- } else if (pk->type == EVP_PKEY_DSA &&
+ } else if (EVP_PKEY_id(pk) == EVP_PKEY_DSA &&
(type == KEY_UNSPEC || type == KEY_DSA)) {
if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
r = SSH_ERR_ALLOC_FAIL;
@@ -3892,7 +4135,7 @@ sshkey_parse_private_pem_fileblob(struct
DSA_print_fp(stderr, prv->dsa, 8);
#endif
#ifdef OPENSSL_HAS_ECC
- } else if (pk->type == EVP_PKEY_EC &&
+ } else if (EVP_PKEY_id(pk) == EVP_PKEY_EC &&
(type == KEY_UNSPEC || type == KEY_ECDSA)) {
if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
r = SSH_ERR_ALLOC_FAIL;
Index: openssh-7.8p1/sshkey.h
===================================================================
--- openssh-7.8p1.orig/sshkey.h
+++ openssh-7.8p1/sshkey.h
@@ -220,7 +220,7 @@ int sshkey_parse_private_fileblob_type(s
const char *passphrase, struct sshkey **keyp, char **commentp);
/* XXX should be internal, but used by ssh-keygen */
-int ssh_rsa_generate_additional_parameters(struct sshkey *);
+int ssh_rsa_generate_additional_parameters(struct sshkey *, BIGNUM *iqmp);
/* stateful keys (e.g. XMSS) */
#ifdef NO_ATTRIBUTE_ON_PROTOTYPE_ARGS
Index: openssh-7.8p1/ssh.c
===================================================================
--- openssh-7.8p1.orig/ssh.c
+++ openssh-7.8p1/ssh.c
@@ -1332,6 +1332,7 @@ main(int ac, char **av)
(char *)NULL);
free(cp);
}
+ free(host_arg);
if (config_test) {
dump_client_config(&options, host);
Index: openssh-7.8p1/gss-serv.c
===================================================================
--- openssh-7.8p1.orig/gss-serv.c
+++ openssh-7.8p1/gss-serv.c
@@ -148,7 +148,8 @@ ssh_gssapi_server_mechanisms() {
if (supported_oids == NULL)
ssh_gssapi_prepare_supported_oids();
return (ssh_gssapi_kex_mechs(supported_oids,
- &ssh_gssapi_server_check_mech, NULL, NULL));
+ ssh_gssapi_server_check_mech, NULL, NULL,
+ options.gss_kex_algorithms));
}
/* Unprivileged */
Index: openssh-7.8p1/kex.c
===================================================================
--- openssh-7.8p1.orig/kex.c
+++ openssh-7.8p1/kex.c
@@ -49,6 +49,7 @@
#include "misc.h"
#include "dispatch.h"
#include "monitor.h"
+#include "xmalloc.h"
#include "ssherr.h"
#include "sshbuf.h"
@@ -359,6 +360,28 @@ kex_assemble_names(char **listp, const c
return r;
}
+/* Validate GSS KEX method name list */
+int
+gss_kex_names_valid(const char *names)
+{
+ char *s, *cp, *p;
+ if (names == NULL || *names == '\0')
+ return 0;
+ s = cp = xstrdup(names);
+ for ((p = strsep(&cp, ",")); p && *p != '\0';
+ (p = strsep(&cp, ","))) {
+ if (strncmp(p, "gss-", 4) != 0
+ || kex_alg_by_name(p) == NULL) {
+ error("Unsupported KEX algorithm \"%.100s\"", p);
+ free(s);
+ return 0;
+ }
+ }
+ debug3("gss kex names ok: [%s]", names);
+ free(s);
+ return 1;
+}
+
/* put algorithm proposal into buffer */
int
kex_prop2buf(struct sshbuf *b, char *proposal[PROPOSAL_MAX])
@@ -795,7 +818,7 @@ choose_mac(struct ssh *ssh, struct sshma
#ifdef SSH_AUDIT_EVENTS
audit_unsupported(SSH_AUDIT_UNSUPPORTED_MAC);
#endif
- return SSH_ERR_NO_MAC_ALG_MATCH;
+ return SSH_ERR_NO_MAC_ALG_MATCH;
}
if (mac_setup(mac, name) < 0) {
free(name);
Index: openssh-7.8p1/kex.h
===================================================================
--- openssh-7.8p1.orig/kex.h
+++ openssh-7.8p1/kex.h
@@ -182,6 +182,7 @@ int kex_names_valid(const char *);
char *kex_alg_list(char);
char *kex_names_cat(const char *, const char *);
int kex_assemble_names(char **, const char *, const char *);
+int gss_kex_names_valid(const char *);
int kex_new(struct ssh *, char *[PROPOSAL_MAX], struct kex **);
int kex_setup(struct ssh *, char *[PROPOSAL_MAX]);
Index: openssh-7.8p1/readconf.c
===================================================================
--- openssh-7.8p1.orig/readconf.c
+++ openssh-7.8p1/readconf.c
@@ -69,6 +69,7 @@
#include "digest.h"
#include "dh.h"
#include "fips.h"
+#include "ssh-gss.h"
/* Format of the configuration file:
@@ -164,7 +165,7 @@ typedef enum {
oEnableSSHKeysign, oRekeyLimit, oVerifyHostKeyDNS, oConnectTimeout,
oAddressFamily, oGssAuthentication, oGssDelegateCreds,
oGssTrustDns, oGssKeyEx, oGssClientIdentity, oGssRenewalRekey,
- oGssServerIdentity,
+ oGssServerIdentity, oGssKexAlgorithms,
oServerAliveInterval, oServerAliveCountMax, oIdentitiesOnly,
oSendEnv, oSetEnv, oControlPath, oControlMaster, oControlPersist,
oHashKnownHosts,
@@ -211,6 +212,7 @@ static struct {
{ "gssapiclientidentity", oGssClientIdentity },
{ "gssapiserveridentity", oGssServerIdentity },
{ "gssapirenewalforcesrekey", oGssRenewalRekey },
+ { "gssapikexalgorithms", oGssKexAlgorithms },
# else
{ "gssapiauthentication", oUnsupported },
{ "gssapikeyexchange", oUnsupported },
@@ -219,6 +221,7 @@ static struct {
{ "gssapiclientidentity", oUnsupported },
{ "gssapiserveridentity", oUnsupported },
{ "gssapirenewalforcesrekey", oUnsupported },
+ { "gssapikexalgorithms", oUnsupported },
#endif
#ifdef ENABLE_PKCS11
{ "smartcarddevice", oPKCS11Provider },
@@ -1015,6 +1018,18 @@ parse_time:
intptr = &options->gss_renewal_rekey;
goto parse_flag;
+ case oGssKexAlgorithms:
+ arg = strdelim(&s);
+ if (!arg || *arg == '\0')
+ fatal("%.200s line %d: Missing argument.",
+ filename, linenum);
+ if (!gss_kex_names_valid(arg))
+ fatal("%.200s line %d: Bad GSSAPI KexAlgorithms '%s'.",
+ filename, linenum, arg ? arg : "<NONE>");
+ if (*activep && options->gss_kex_algorithms == NULL)
+ options->gss_kex_algorithms = xstrdup(arg);
+ break;
+
case oBatchMode:
intptr = &options->batch_mode;
goto parse_flag;
@@ -1879,9 +1894,10 @@ initialize_options(Options * options)
options->gss_keyex = -1;
options->gss_deleg_creds = -1;
options->gss_trust_dns = -1;
- options->gss_renewal_rekey = -1;
- options->gss_client_identity = NULL;
- options->gss_server_identity = NULL;
+ options->gss_renewal_rekey = -1;
+ options->gss_client_identity = NULL;
+ options->gss_server_identity = NULL;
+ options->gss_kex_algorithms = NULL;
options->password_authentication = -1;
options->kbd_interactive_authentication = -1;
options->kbd_interactive_devices = NULL;
@@ -2035,6 +2051,10 @@ fill_default_options(Options * options)
options->gss_trust_dns = 0;
if (options->gss_renewal_rekey == -1)
options->gss_renewal_rekey = 0;
+#ifdef GSSAPI
+ if (options->gss_kex_algorithms == NULL)
+ options->gss_kex_algorithms = strdup(GSS_KEX_DEFAULT_KEX);
+#endif
if (options->password_authentication == -1)
options->password_authentication = 1;
if (options->kbd_interactive_authentication == -1)
Index: openssh-7.8p1/readconf.h
===================================================================
--- openssh-7.8p1.orig/readconf.h
+++ openssh-7.8p1/readconf.h
@@ -46,6 +46,7 @@ typedef struct {
int gss_renewal_rekey; /* Credential renewal forces rekey */
char *gss_client_identity; /* Principal to initiate GSSAPI with */
char *gss_server_identity; /* GSSAPI target principal */
+ char *gss_kex_algorithms; /* GSSAPI kex methods to be offered by client. */
int password_authentication; /* Try password
* authentication. */
int kbd_interactive_authentication; /* Try keyboard-interactive auth. */
Index: openssh-7.8p1/servconf.c
===================================================================
--- openssh-7.8p1.orig/servconf.c
+++ openssh-7.8p1/servconf.c
@@ -64,6 +64,7 @@
#include "auth.h"
#include "myproposal.h"
#include "digest.h"
+#include "ssh-gss.h"
#include "dh.h"
#include "fips.h"
@@ -134,6 +135,7 @@ initialize_server_options(ServerOptions
options->gss_cleanup_creds = -1;
options->gss_strict_acceptor = -1;
options->gss_store_rekey = -1;
+ options->gss_kex_algorithms = NULL;
options->password_authentication = -1;
options->kbd_interactive_authentication = -1;
options->challenge_response_authentication = -1;
@@ -379,6 +381,10 @@ fill_default_server_options(ServerOption
options->gss_strict_acceptor = 1;
if (options->gss_store_rekey == -1)
options->gss_store_rekey = 0;
+#ifdef GSSAPI
+ if (options->gss_kex_algorithms == NULL)
+ options->gss_kex_algorithms = strdup(GSS_KEX_DEFAULT_KEX);
+#endif
if (options->password_authentication == -1)
options->password_authentication = 1;
if (options->kbd_interactive_authentication == -1)
@@ -525,8 +531,7 @@ typedef enum {
sHostKeyAlgorithms,
sClientAliveInterval, sClientAliveCountMax, sAuthorizedKeysFile,
sGssAuthentication, sGssCleanupCreds, sGssStrictAcceptor,
- sGssKeyEx, sGssStoreRekey,
- sAcceptEnv, sSetEnv, sPermitTunnel,
+ sGssKeyEx, sGssStoreRekey, sGssKexAlgorithms, sAcceptEnv, sSetEnv, sPermitTunnel,
sMatch, sPermitOpen, sPermitListen, sForceCommand, sChrootDirectory,
sUsePrivilegeSeparation, sAllowAgentForwarding,
sHostCertificate,
@@ -605,12 +610,14 @@ static struct {
{ "gssapistrictacceptorcheck", sGssStrictAcceptor, SSHCFG_GLOBAL },
{ "gssapikeyexchange", sGssKeyEx, SSHCFG_GLOBAL },
{ "gssapistorecredentialsonrekey", sGssStoreRekey, SSHCFG_GLOBAL },
+ { "gssapikexalgorithms", sGssKexAlgorithms, SSHCFG_GLOBAL },
#else
{ "gssapiauthentication", sUnsupported, SSHCFG_ALL },
{ "gssapicleanupcredentials", sUnsupported, SSHCFG_GLOBAL },
{ "gssapistrictacceptorcheck", sUnsupported, SSHCFG_GLOBAL },
{ "gssapikeyexchange", sUnsupported, SSHCFG_GLOBAL },
{ "gssapistorecredentialsonrekey", sUnsupported, SSHCFG_GLOBAL },
+ { "gssapikexalgorithms", sUnsupported, SSHCFG_GLOBAL },
#endif
{ "gssusesessionccache", sUnsupported, SSHCFG_GLOBAL },
{ "gssapiusesessioncredcache", sUnsupported, SSHCFG_GLOBAL },
@@ -1532,6 +1539,18 @@ process_server_config_line(ServerOptions
intptr = &options->gss_store_rekey;
goto parse_flag;
+ case sGssKexAlgorithms:
+ arg = strdelim(&cp);
+ if (!arg || *arg == '\0')
+ fatal("%.200s line %d: Missing argument.",
+ filename, linenum);
+ if (!gss_kex_names_valid(arg))
+ fatal("%.200s line %d: Bad GSSAPI KexAlgorithms '%s'.",
+ filename, linenum, arg ? arg : "<NONE>");
+ if (*activep && options->gss_kex_algorithms == NULL)
+ options->gss_kex_algorithms = xstrdup(arg);
+ break;
+
case sPasswordAuthentication:
intptr = &options->password_authentication;
goto parse_flag;
@@ -2629,6 +2648,7 @@ dump_config(ServerOptions *o)
dump_cfg_fmtint(sGssCleanupCreds, o->gss_cleanup_creds);
dump_cfg_fmtint(sGssStrictAcceptor, o->gss_strict_acceptor);
dump_cfg_fmtint(sGssStoreRekey, o->gss_store_rekey);
+ dump_cfg_string(sGssKexAlgorithms, o->gss_kex_algorithms);
#endif
dump_cfg_fmtint(sPasswordAuthentication, o->password_authentication);
dump_cfg_fmtint(sKbdInteractiveAuthentication,
Index: openssh-7.8p1/servconf.h
===================================================================
--- openssh-7.8p1.orig/servconf.h
+++ openssh-7.8p1/servconf.h
@@ -131,6 +131,7 @@ typedef struct {
int gss_cleanup_creds; /* If true, destroy cred cache on logout */
int gss_strict_acceptor; /* If true, restrict the GSSAPI acceptor name */
int gss_store_rekey;
+ char *gss_kex_algorithms; /* GSSAPI kex methods to be offered by client. */
int password_authentication; /* If true, permit password
* authentication. */
int kbd_interactive_authentication; /* If true, permit */
Index: openssh-7.8p1/ssh-gss.h
===================================================================
--- openssh-7.8p1.orig/ssh-gss.h
+++ openssh-7.8p1/ssh-gss.h
@@ -72,6 +72,10 @@
#define KEX_GSS_GRP14_SHA1_ID "gss-group14-sha1-"
#define KEX_GSS_GEX_SHA1_ID "gss-gex-sha1-"
+#define GSS_KEX_DEFAULT_KEX \
+ KEX_GSS_GEX_SHA1_ID "," \
+ KEX_GSS_GRP14_SHA1_ID
+
typedef struct {
char *filename;
char *envvar;
@@ -148,7 +152,7 @@ int ssh_gssapi_credentials_updated(Gssct
typedef int ssh_gssapi_check_fn(Gssctxt **, gss_OID, const char *, const char *);
char *ssh_gssapi_client_mechanisms(const char *, const char *, const char *);
char *ssh_gssapi_kex_mechs(gss_OID_set, ssh_gssapi_check_fn *, const char *,
- const char *);
+ const char *, const char *);
gss_OID ssh_gssapi_id_kex(Gssctxt *, char *, int);
int ssh_gssapi_server_check_mech(Gssctxt **, gss_OID, const char *, const char *);
OM_uint32 ssh_gssapi_server_ctx(Gssctxt **, gss_OID);
Index: openssh-7.8p1/ssh.1
===================================================================
--- openssh-7.8p1.orig/ssh.1
+++ openssh-7.8p1/ssh.1
@@ -489,6 +489,7 @@ For full details of the options listed b
.It GlobalKnownHostsFile
.It GSSAPIAuthentication
.It GSSAPIDelegateCredentials
+.It GSSAPIKexAlgorithms
.It HashKnownHosts
.It Host
.It HostbasedAuthentication
Index: openssh-7.8p1/ssh_config.5
===================================================================
--- openssh-7.8p1.orig/ssh_config.5
+++ openssh-7.8p1/ssh_config.5
@@ -754,6 +754,18 @@ the name of the host being connected to.
command line will be passed untouched to the GSSAPI library.
The default is
.Dq no .
+.It Cm GSSAPIKexAlgorithms
+The list of key exchange algorithms that are offered for GSSAPI
+key exchange. Possible values are
+.Bd -literal -offset 3n
+gss-gex-sha1-,
+gss-group1-sha1-,
+gss-group14-sha1-
+.Ed
+.Pp
+The default is
+.Dq gss-gex-sha1-,gss-group14-sha1- .
+This option only applies to protocol version 2 connections using GSSAPI.
.It Cm HashKnownHosts
Indicates that
.Xr ssh 1
Index: openssh-7.8p1/sshconnect2.c
===================================================================
--- openssh-7.8p1.orig/sshconnect2.c
+++ openssh-7.8p1/sshconnect2.c
@@ -301,8 +301,9 @@ ssh_kex2(char *host, struct sockaddr *ho
else
gss_host = host;
- gss = ssh_gssapi_client_mechanisms(gss_host, options.gss_client_identity,
- options.kex_algorithms);
+ gss = ssh_gssapi_client_mechanisms(gss_host,
+ options.gss_client_identity,
+ options.kex_algorithms);
if (gss) {
debug("Offering GSSAPI proposal: %s", gss);
xasprintf(&options.kex_algorithms,
Index: openssh-7.8p1/sshd_config.5
===================================================================
--- openssh-7.8p1.orig/sshd_config.5
+++ openssh-7.8p1/sshd_config.5
@@ -668,6 +668,18 @@ Controls whether the user's GSSAPI crede
successful connection rekeying. This option can be used to accepted renewed
or updated credentials from a compatible client. The default is
.Dq no .
+.It Cm GSSAPIKexAlgorithms
+The list of key exchange algorithms that are accepted by GSSAPI
+key exchange. Possible values are
+.Bd -literal -offset 3n
+gss-gex-sha1-,
+gss-group1-sha1-,
+gss-group14-sha1-
+.Ed
+.Pp
+The default is
+.Dq gss-gex-sha1-,gss-group14-sha1- .
+This option only applies to protocol version 2 connections using GSSAPI.
.It Cm HostbasedAcceptedKeyTypes
Specifies the key types that will be accepted for hostbased authentication
as a list of comma-separated patterns.