|
Jakub Jelen |
5b55d0 |
diff -up openssh/auth-pam.c.openssl openssh/auth-pam.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/auth-pam.c.openssl 2017-09-26 13:19:31.662248869 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/auth-pam.c 2017-09-26 13:19:31.793249672 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -128,6 +128,10 @@ extern u_int utmp_len;
|
|
Jakub Jelen |
aacf0d |
typedef pthread_t sp_pthread_t;
|
|
Jakub Jelen |
aacf0d |
#else
|
|
Jakub Jelen |
aacf0d |
typedef pid_t sp_pthread_t;
|
|
Jakub Jelen |
aacf0d |
+# define pthread_create(a, b, c, d) _ssh_compat_pthread_create(a, b, c, d)
|
|
Jakub Jelen |
aacf0d |
+# define pthread_exit(a) _ssh_compat_pthread_exit(a)
|
|
Jakub Jelen |
aacf0d |
+# define pthread_cancel(a) _ssh_compat_pthread_cancel(a)
|
|
Jakub Jelen |
aacf0d |
+# define pthread_join(a, b) _ssh_compat_pthread_join(a, b)
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
struct pam_ctxt {
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/cipher.c.openssl openssh/cipher.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/cipher.c.openssl 2017-09-26 13:19:31.782249605 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/cipher.c 2017-09-26 13:27:37.424040367 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -283,7 +283,7 @@ cipher_init(struct sshcipher_ctx **ccp,
|
|
Jakub Jelen |
6cf9b8 |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
6cf9b8 |
goto out;
|
|
Jakub Jelen |
6cf9b8 |
}
|
|
Jakub Jelen |
6cf9b8 |
- if (EVP_CipherInit(cc->evp, type, NULL, (u_char *)iv,
|
|
Jakub Jelen |
aacf0d |
+ if (EVP_CipherInit(cc->evp, type, (u_char *)key, (u_char *)iv,
|
|
Jakub Jelen |
aacf0d |
(do_encrypt == CIPHER_ENCRYPT)) == 0) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
6cf9b8 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
@@ -301,10 +301,6 @@ cipher_init(struct sshcipher_ctx **ccp,
|
|
Jakub Jelen |
6cf9b8 |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
6cf9b8 |
- if (EVP_CipherInit(cc->evp, NULL, (u_char *)key, NULL, -1) == 0) {
|
|
Jakub Jelen |
aacf0d |
- ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
6cf9b8 |
- goto out;
|
|
Jakub Jelen |
aacf0d |
- }
|
|
Jakub Jelen |
5b55d0 |
ret = 0;
|
|
Jakub Jelen |
5b55d0 |
#endif /* WITH_OPENSSL */
|
|
Jakub Jelen |
5b55d0 |
out:
|
|
Jakub Jelen |
5b55d0 |
@@ -490,7 +486,7 @@ cipher_get_keyiv(struct sshcipher_ctx *c
|
|
Jakub Jelen |
5b55d0 |
len, iv))
|
|
Jakub Jelen |
5b55d0 |
return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
5b55d0 |
} else
|
|
Jakub Jelen |
5b55d0 |
- memcpy(iv, cc->evp->iv, len);
|
|
Jakub Jelen |
5b55d0 |
+ memcpy(iv, EVP_CIPHER_CTX_iv(cc->evp), len);
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
5b55d0 |
return 0;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -524,14 +520,14 @@ cipher_set_keyiv(struct sshcipher_ctx *c
|
|
Jakub Jelen |
5b55d0 |
EVP_CTRL_GCM_SET_IV_FIXED, -1, (void *)iv))
|
|
Jakub Jelen |
5b55d0 |
return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
5b55d0 |
} else
|
|
Jakub Jelen |
5b55d0 |
- memcpy(cc->evp->iv, iv, evplen);
|
|
Jakub Jelen |
5b55d0 |
+ memcpy(EVP_CIPHER_CTX_iv_noconst(cc->evp), iv, evplen);
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
5b55d0 |
return 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
6cf9b8 |
-#define EVP_X_STATE(evp) (evp)->cipher_data
|
|
Jakub Jelen |
6cf9b8 |
-#define EVP_X_STATE_LEN(evp) (evp)->cipher->ctx_size
|
|
Jakub Jelen |
aacf0d |
+#define EVP_X_STATE(evp) EVP_CIPHER_CTX_get_cipher_data(evp)
|
|
Jakub Jelen |
aacf0d |
+#define EVP_X_STATE_LEN(evp) EVP_CIPHER_impl_ctx_size(EVP_CIPHER_CTX_cipher(evp))
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
int
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ctr-cavstest.c.openssl openssh/ctr-cavstest.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ctr-cavstest.c.openssl 2017-09-26 13:19:31.707249145 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ctr-cavstest.c 2017-09-26 13:19:31.794249679 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -144,7 +144,7 @@ int main (int argc, char *argv[])
|
|
Jakub Jelen |
aacf0d |
usage();
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- SSLeay_add_all_algorithms();
|
|
Jakub Jelen |
aacf0d |
+ OpenSSL_add_all_algorithms();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
c = cipher_by_name(algo);
|
|
Jakub Jelen |
aacf0d |
if (c == NULL) {
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/dh.c.openssl openssh/dh.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/dh.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/dh.c 2017-09-26 13:19:31.794249679 +0200
|
|
Jakub Jelen |
6cf9b8 |
@@ -212,14 +212,15 @@ choose_dh(int min, int wantbits, int max
|
|
Jakub Jelen |
aacf0d |
/* diffie-hellman-groupN-sha1 */
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
int
|
|
Jakub Jelen |
aacf0d |
-dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
|
|
Jakub Jelen |
aacf0d |
+dh_pub_is_valid(const DH *dh, const BIGNUM *dh_pub)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
int i;
|
|
Jakub Jelen |
aacf0d |
int n = BN_num_bits(dh_pub);
|
|
Jakub Jelen |
aacf0d |
int bits_set = 0;
|
|
Jakub Jelen |
aacf0d |
BIGNUM *tmp;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- if (dh_pub->neg) {
|
|
Jakub Jelen |
aacf0d |
+ if (BN_is_negative(dh_pub)) {
|
|
Jakub Jelen |
aacf0d |
logit("invalid public DH value: negative");
|
|
Jakub Jelen |
aacf0d |
return 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
6cf9b8 |
@@ -232,7 +233,8 @@ dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
|
|
Jakub Jelen |
aacf0d |
error("%s: BN_new failed", __func__);
|
|
Jakub Jelen |
aacf0d |
return 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if (!BN_sub(tmp, dh->p, BN_value_one()) ||
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(dh, &p, NULL, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if (!BN_sub(tmp, p, BN_value_one()) ||
|
|
Jakub Jelen |
aacf0d |
BN_cmp(dh_pub, tmp) != -1) { /* pub_exp > p-2 */
|
|
Jakub Jelen |
aacf0d |
BN_clear_free(tmp);
|
|
Jakub Jelen |
aacf0d |
logit("invalid public DH value: >= p-1");
|
|
Jakub Jelen |
6cf9b8 |
@@ -243,14 +245,14 @@ dh_pub_is_valid(DH *dh, BIGNUM *dh_pub)
|
|
Jakub Jelen |
aacf0d |
for (i = 0; i <= n; i++)
|
|
Jakub Jelen |
aacf0d |
if (BN_is_bit_set(dh_pub, i))
|
|
Jakub Jelen |
aacf0d |
bits_set++;
|
|
Jakub Jelen |
aacf0d |
- debug2("bits set: %d/%d", bits_set, BN_num_bits(dh->p));
|
|
Jakub Jelen |
aacf0d |
+ debug2("bits set: %d/%d", bits_set, BN_num_bits(p));
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/*
|
|
Jakub Jelen |
aacf0d |
* if g==2 and bits_set==1 then computing log_g(dh_pub) is trivial
|
|
Jakub Jelen |
aacf0d |
*/
|
|
Jakub Jelen |
aacf0d |
if (bits_set < 4) {
|
|
Jakub Jelen |
aacf0d |
logit("invalid public DH value (%d/%d)",
|
|
Jakub Jelen |
aacf0d |
- bits_set, BN_num_bits(dh->p));
|
|
Jakub Jelen |
aacf0d |
+ bits_set, BN_num_bits(p));
|
|
Jakub Jelen |
aacf0d |
return 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
return 1;
|
|
Jakub Jelen |
6cf9b8 |
@@ -260,9 +262,11 @@ int
|
|
Jakub Jelen |
aacf0d |
dh_gen_key(DH *dh, int need)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
int pbits;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- if (need < 0 || dh->p == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pbits = BN_num_bits(dh->p)) <= 0 ||
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(dh, &p, NULL, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if (need < 0 || p == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pbits = BN_num_bits(p)) <= 0 ||
|
|
Jakub Jelen |
aacf0d |
need > INT_MAX / 2 || 2 * need > pbits)
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
if (need < 256)
|
|
Jakub Jelen |
6cf9b8 |
@@ -271,10 +275,11 @@ dh_gen_key(DH *dh, int need)
|
|
Jakub Jelen |
aacf0d |
* Pollard Rho, Big step/Little Step attacks are O(sqrt(n)),
|
|
Jakub Jelen |
aacf0d |
* so double requested need here.
|
|
Jakub Jelen |
aacf0d |
*/
|
|
Jakub Jelen |
6cf9b8 |
- dh->length = MINIMUM(need * 2, pbits - 1);
|
|
Jakub Jelen |
aacf0d |
- if (DH_generate_key(dh) == 0 ||
|
|
Jakub Jelen |
aacf0d |
- !dh_pub_is_valid(dh, dh->pub_key)) {
|
|
Jakub Jelen |
aacf0d |
- BN_clear_free(dh->priv_key);
|
|
Jakub Jelen |
aacf0d |
+ DH_set_length(dh, MINIMUM(need * 2, pbits - 1));
|
|
Jakub Jelen |
aacf0d |
+ if (DH_generate_key(dh) == 0)
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(dh, &pub_key, NULL);
|
|
Jakub Jelen |
6cf9b8 |
+ if (!dh_pub_is_valid(dh, pub_key)) {
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
6cf9b8 |
}
|
|
Jakub Jelen |
aacf0d |
return 0;
|
|
Jakub Jelen |
5b55d0 |
@@ -284,15 +289,22 @@ DH *
|
|
Jakub Jelen |
aacf0d |
dh_new_group_asc(const char *gen, const char *modulus)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
DH *dh;
|
|
Jakub Jelen |
e0e7ed |
+ BIGNUM *p = NULL, *g = NULL;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- if ((dh = DH_new()) == NULL)
|
|
Jakub Jelen |
aacf0d |
- return NULL;
|
|
Jakub Jelen |
aacf0d |
- if (BN_hex2bn(&dh->p, modulus) == 0 ||
|
|
Jakub Jelen |
aacf0d |
- BN_hex2bn(&dh->g, gen) == 0) {
|
|
Jakub Jelen |
aacf0d |
- DH_free(dh);
|
|
Jakub Jelen |
aacf0d |
- return NULL;
|
|
Jakub Jelen |
aacf0d |
- }
|
|
Jakub Jelen |
aacf0d |
+ if ((dh = DH_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (p = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (g = BN_new()) == NULL)
|
|
Jakub Jelen |
aacf0d |
+ goto err;
|
|
Jakub Jelen |
aacf0d |
+ if (BN_hex2bn(&p, modulus) == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ BN_hex2bn(&g, gen) == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ DH_set0_pqg(dh, p, NULL, g) == 0)
|
|
Jakub Jelen |
aacf0d |
+ goto err;
|
|
Jakub Jelen |
aacf0d |
return (dh);
|
|
Jakub Jelen |
aacf0d |
+err:
|
|
Jakub Jelen |
aacf0d |
+ DH_free(dh);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(g);
|
|
Jakub Jelen |
aacf0d |
+ return NULL;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/*
|
|
Jakub Jelen |
5b55d0 |
@@ -307,8 +319,7 @@ dh_new_group(BIGNUM *gen, BIGNUM *modulu
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if ((dh = DH_new()) == NULL)
|
|
Jakub Jelen |
aacf0d |
return NULL;
|
|
Jakub Jelen |
aacf0d |
- dh->p = modulus;
|
|
Jakub Jelen |
aacf0d |
- dh->g = gen;
|
|
Jakub Jelen |
aacf0d |
+ DH_set0_pqg(dh, modulus, NULL, gen);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
return (dh);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/dh.h.openssl openssh/dh.h
|
|
Jakub Jelen |
5b55d0 |
--- openssh/dh.h.openssl 2017-09-26 13:19:31.783249611 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/dh.h 2017-09-26 13:19:31.794249679 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -42,7 +42,7 @@ DH *dh_new_group18(void);
|
|
Jakub Jelen |
aacf0d |
DH *dh_new_group_fallback(int);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
int dh_gen_key(DH *, int);
|
|
Jakub Jelen |
aacf0d |
-int dh_pub_is_valid(DH *, BIGNUM *);
|
|
Jakub Jelen |
aacf0d |
+int dh_pub_is_valid(const DH *, const BIGNUM *);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
u_int dh_estimate(int);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/digest-openssl.c.openssl openssh/digest-openssl.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/digest-openssl.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/digest-openssl.c 2017-09-26 13:19:31.795249685 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -43,7 +43,7 @@
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
struct ssh_digest_ctx {
|
|
Jakub Jelen |
aacf0d |
int alg;
|
|
Jakub Jelen |
aacf0d |
- EVP_MD_CTX mdctx;
|
|
Jakub Jelen |
aacf0d |
+ EVP_MD_CTX *mdctx;
|
|
Jakub Jelen |
aacf0d |
};
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
struct ssh_digest {
|
|
Jakub Jelen |
5b55d0 |
@@ -106,7 +106,7 @@ ssh_digest_bytes(int alg)
|
|
Jakub Jelen |
aacf0d |
size_t
|
|
Jakub Jelen |
aacf0d |
ssh_digest_blocksize(struct ssh_digest_ctx *ctx)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
- return EVP_MD_CTX_block_size(&ctx->mdctx);
|
|
Jakub Jelen |
aacf0d |
+ return EVP_MD_CTX_block_size(ctx->mdctx);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
struct ssh_digest_ctx *
|
|
Jakub Jelen |
e0e7ed |
@@ -118,8 +118,10 @@ ssh_digest_start(int alg)
|
|
Jakub Jelen |
aacf0d |
if (digest == NULL || ((ret = calloc(1, sizeof(*ret))) == NULL))
|
|
Jakub Jelen |
aacf0d |
return NULL;
|
|
Jakub Jelen |
aacf0d |
ret->alg = alg;
|
|
Jakub Jelen |
aacf0d |
- EVP_MD_CTX_init(&ret->mdctx);
|
|
Jakub Jelen |
aacf0d |
- if (EVP_DigestInit_ex(&ret->mdctx, digest->mdfunc(), NULL) != 1) {
|
|
Jakub Jelen |
aacf0d |
+ ret->mdctx = EVP_MD_CTX_new();
|
|
Jakub Jelen |
aacf0d |
+ if (ret->mdctx == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ EVP_DigestInit_ex(ret->mdctx, digest->mdfunc(), NULL) != 1) {
|
|
Jakub Jelen |
e0e7ed |
+ EVP_MD_CTX_free(ret->mdctx);
|
|
Jakub Jelen |
aacf0d |
free(ret);
|
|
Jakub Jelen |
aacf0d |
return NULL;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -132,7 +133,7 @@ ssh_digest_copy_state(struct ssh_digest_
|
|
Jakub Jelen |
aacf0d |
if (from->alg != to->alg)
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
/* we have bcopy-style order while openssl has memcpy-style */
|
|
Jakub Jelen |
aacf0d |
- if (!EVP_MD_CTX_copy_ex(&to->mdctx, &from->mdctx))
|
|
Jakub Jelen |
aacf0d |
+ if (!EVP_MD_CTX_copy_ex(to->mdctx, from->mdctx))
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
return 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -140,7 +141,7 @@ ssh_digest_copy_state(struct ssh_digest_
|
|
Jakub Jelen |
aacf0d |
int
|
|
Jakub Jelen |
aacf0d |
ssh_digest_update(struct ssh_digest_ctx *ctx, const void *m, size_t mlen)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
- if (EVP_DigestUpdate(&ctx->mdctx, m, mlen) != 1)
|
|
Jakub Jelen |
aacf0d |
+ if (EVP_DigestUpdate(ctx->mdctx, m, mlen) != 1)
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
return 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -161,7 +162,7 @@ ssh_digest_final(struct ssh_digest_ctx *
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
if (dlen < digest->digest_len) /* No truncation allowed */
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
- if (EVP_DigestFinal_ex(&ctx->mdctx, d, &l) != 1)
|
|
Jakub Jelen |
aacf0d |
+ if (EVP_DigestFinal_ex(ctx->mdctx, d, &l) != 1)
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
if (l != digest->digest_len) /* sanity */
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INTERNAL_ERROR;
|
|
Jakub Jelen |
5b55d0 |
@@ -172,7 +173,7 @@ void
|
|
Jakub Jelen |
aacf0d |
ssh_digest_free(struct ssh_digest_ctx *ctx)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
if (ctx != NULL) {
|
|
Jakub Jelen |
aacf0d |
- EVP_MD_CTX_cleanup(&ctx->mdctx);
|
|
Jakub Jelen |
aacf0d |
+ EVP_MD_CTX_free(ctx->mdctx);
|
|
Jakub Jelen |
aacf0d |
explicit_bzero(ctx, sizeof(*ctx));
|
|
Jakub Jelen |
aacf0d |
free(ctx);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/entropy.c.openssl openssh/entropy.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/entropy.c.openssl 2017-09-26 13:19:31.783249611 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/entropy.c 2017-09-26 13:19:31.795249685 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -218,7 +218,9 @@ seed_rng(void)
|
|
Jakub Jelen |
aacf0d |
"have %lx", (u_long)OPENSSL_VERSION_NUMBER, SSLeay());
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* clean the PRNG status when exiting the program */
|
|
Jakub Jelen |
aacf0d |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Jakub Jelen |
aacf0d |
atexit(RAND_cleanup);
|
|
Jakub Jelen |
aacf0d |
+#endif
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
#ifndef OPENSSL_PRNG_ONLY
|
|
Jakub Jelen |
aacf0d |
if (RAND_status() == 1) {
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/gss-genr.c.openssl openssh/gss-genr.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/gss-genr.c.openssl 2017-09-26 13:19:31.773249550 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/gss-genr.c 2017-09-26 13:19:31.796249691 +0200
|
|
Jakub Jelen |
6cf9b8 |
@@ -99,7 +99,7 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
|
|
Jakub Jelen |
aacf0d |
u_char digest[EVP_MAX_MD_SIZE];
|
|
Jakub Jelen |
aacf0d |
char deroid[2];
|
|
Jakub Jelen |
aacf0d |
const EVP_MD *evp_md = EVP_md5();
|
|
Jakub Jelen |
aacf0d |
- EVP_MD_CTX md;
|
|
Jakub Jelen |
aacf0d |
+ EVP_MD_CTX *md;
|
|
Jakub Jelen |
aacf0d |
char *s, *cp, *p;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (gss_enc2oid != NULL) {
|
|
Jakub Jelen |
6cf9b8 |
@@ -113,6 +113,7 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
buffer_init(&buf;;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
+ md = EVP_MD_CTX_new();
|
|
Jakub Jelen |
aacf0d |
oidpos = 0;
|
|
Jakub Jelen |
aacf0d |
s = cp = xstrdup(kex);
|
|
Jakub Jelen |
aacf0d |
for (i = 0; i < gss_supported->count; i++) {
|
|
Jakub Jelen |
6cf9b8 |
@@ -122,12 +123,13 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
|
|
Jakub Jelen |
aacf0d |
deroid[0] = SSH_GSS_OIDTYPE;
|
|
Jakub Jelen |
aacf0d |
deroid[1] = gss_supported->elements[i].length;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- EVP_DigestInit(&md, evp_md);
|
|
Jakub Jelen |
aacf0d |
- EVP_DigestUpdate(&md, deroid, 2);
|
|
Jakub Jelen |
aacf0d |
- EVP_DigestUpdate(&md,
|
|
Jakub Jelen |
aacf0d |
+ EVP_MD_CTX_reset(md);
|
|
Jakub Jelen |
aacf0d |
+ EVP_DigestInit(md, evp_md);
|
|
Jakub Jelen |
aacf0d |
+ EVP_DigestUpdate(md, deroid, 2);
|
|
Jakub Jelen |
aacf0d |
+ EVP_DigestUpdate(md,
|
|
Jakub Jelen |
aacf0d |
gss_supported->elements[i].elements,
|
|
Jakub Jelen |
aacf0d |
gss_supported->elements[i].length);
|
|
Jakub Jelen |
aacf0d |
- EVP_DigestFinal(&md, digest, NULL);
|
|
Jakub Jelen |
aacf0d |
+ EVP_DigestFinal(md, digest, NULL);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
encoded = xmalloc(EVP_MD_size(evp_md) * 2);
|
|
Jakub Jelen |
aacf0d |
enclen = __b64_ntop(digest, EVP_MD_size(evp_md),
|
|
Jakub Jelen |
6cf9b8 |
@@ -149,6 +151,7 @@ ssh_gssapi_kex_mechs(gss_OID_set gss_sup
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
free(s);
|
|
Jakub Jelen |
aacf0d |
+ EVP_MD_CTX_free(md);
|
|
Jakub Jelen |
aacf0d |
gss_enc2oid[oidpos].oid = NULL;
|
|
Jakub Jelen |
aacf0d |
gss_enc2oid[oidpos].encoded = NULL;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/includes.h.openssl openssh/includes.h
|
|
Jakub Jelen |
5b55d0 |
--- openssh/includes.h.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/includes.h 2017-09-26 13:19:31.796249691 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -166,6 +166,7 @@
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
#include <openssl/opensslv.h> /* For OPENSSL_VERSION_NUMBER */
|
|
Jakub Jelen |
aacf0d |
+#include "libcrypto-compat.h"
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
#include "defines.h"
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/kexdhc.c.openssl openssh/kexdhc.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/kexdhc.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/kexdhc.c 2017-09-26 13:19:31.797249697 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -56,6 +56,7 @@ kexdh_client(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
struct kex *kex = ssh->kex;
|
|
Jakub Jelen |
aacf0d |
int r;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* generate and send 'e', client DH public key */
|
|
Jakub Jelen |
aacf0d |
switch (kex->kex_type) {
|
|
Jakub Jelen |
aacf0d |
@@ -81,21 +82,27 @@ kexdh_client(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
debug("sending SSH2_MSG_KEXDH_INIT");
|
|
Jakub Jelen |
aacf0d |
- if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(kex->dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_INIT)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_send(ssh)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
#ifdef DEBUG_KEXDH
|
|
Jakub Jelen |
aacf0d |
DHparams_print_fp(stderr, kex->dh);
|
|
Jakub Jelen |
aacf0d |
fprintf(stderr, "pub= ");
|
|
Jakub Jelen |
aacf0d |
- BN_print_fp(stderr, kex->dh->pub_key);
|
|
Jakub Jelen |
aacf0d |
+ BN_print_fp(stderr, pub_key);
|
|
Jakub Jelen |
aacf0d |
fprintf(stderr, "\n");
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
debug("expecting SSH2_MSG_KEXDH_REPLY");
|
|
Jakub Jelen |
aacf0d |
ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_REPLY, &input_kex_dh);
|
|
Jakub Jelen |
aacf0d |
r = 0;
|
|
Jakub Jelen |
aacf0d |
out:
|
|
Jakub Jelen |
aacf0d |
+ if (r != 0) {
|
|
Jakub Jelen |
aacf0d |
+ DH_free(kex->dh);
|
|
Jakub Jelen |
aacf0d |
+ kex->dh = NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
return r;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -109,6 +116,7 @@ input_kex_dh(int type, u_int32_t seq, st
|
|
Jakub Jelen |
aacf0d |
u_char hash[SSH_DIGEST_MAX_LENGTH];
|
|
Jakub Jelen |
aacf0d |
size_t klen = 0, slen, sbloblen, hashlen;
|
|
Jakub Jelen |
aacf0d |
int kout, r;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (kex->verify_host_key == NULL) {
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
5b55d0 |
@@ -168,6 +176,7 @@ input_kex_dh(int type, u_int32_t seq, st
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* calc and verify H */
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(kex->dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
hashlen = sizeof(hash);
|
|
Jakub Jelen |
aacf0d |
if ((r = kex_dh_hash(
|
|
Jakub Jelen |
aacf0d |
kex->hash_alg,
|
|
Jakub Jelen |
5b55d0 |
@@ -176,7 +185,7 @@ input_kex_dh(int type, u_int32_t seq, st
|
|
Jakub Jelen |
aacf0d |
sshbuf_ptr(kex->my), sshbuf_len(kex->my),
|
|
Jakub Jelen |
aacf0d |
sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
|
|
Jakub Jelen |
aacf0d |
server_host_key_blob, sbloblen,
|
|
Jakub Jelen |
aacf0d |
- kex->dh->pub_key,
|
|
Jakub Jelen |
aacf0d |
+ pub_key,
|
|
Jakub Jelen |
aacf0d |
dh_server_pub,
|
|
Jakub Jelen |
aacf0d |
shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen)) != 0)
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/kexdhs.c.openssl openssh/kexdhs.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/kexdhs.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/kexdhs.c 2017-09-26 13:19:31.797249697 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -87,6 +87,10 @@ kexdh_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
ssh_dispatch_set(ssh, SSH2_MSG_KEXDH_INIT, &input_kex_dh_init);
|
|
Jakub Jelen |
aacf0d |
r = 0;
|
|
Jakub Jelen |
aacf0d |
out:
|
|
Jakub Jelen |
aacf0d |
+ if (r != 0) {
|
|
Jakub Jelen |
aacf0d |
+ DH_free(kex->dh);
|
|
Jakub Jelen |
aacf0d |
+ kex->dh = NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
return r;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -101,6 +105,7 @@ input_kex_dh_init(int type, u_int32_t se
|
|
Jakub Jelen |
aacf0d |
size_t sbloblen, slen;
|
|
Jakub Jelen |
aacf0d |
size_t klen = 0, hashlen;
|
|
Jakub Jelen |
aacf0d |
int kout, r;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (kex->load_host_public_key == NULL ||
|
|
Jakub Jelen |
aacf0d |
kex->load_host_private_key == NULL) {
|
|
Jakub Jelen |
5b55d0 |
@@ -163,6 +168,7 @@ input_kex_dh_init(int type, u_int32_t se
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
/* calc H */
|
|
Jakub Jelen |
aacf0d |
hashlen = sizeof(hash);
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(kex->dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
if ((r = kex_dh_hash(
|
|
Jakub Jelen |
aacf0d |
kex->hash_alg,
|
|
Jakub Jelen |
aacf0d |
kex->client_version_string,
|
|
Jakub Jelen |
5b55d0 |
@@ -171,7 +177,7 @@ input_kex_dh_init(int type, u_int32_t se
|
|
Jakub Jelen |
aacf0d |
sshbuf_ptr(kex->my), sshbuf_len(kex->my),
|
|
Jakub Jelen |
aacf0d |
server_host_key_blob, sbloblen,
|
|
Jakub Jelen |
aacf0d |
dh_client_pub,
|
|
Jakub Jelen |
aacf0d |
- kex->dh->pub_key,
|
|
Jakub Jelen |
aacf0d |
+ pub_key,
|
|
Jakub Jelen |
aacf0d |
shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
5b55d0 |
@@ -197,7 +203,7 @@ input_kex_dh_init(int type, u_int32_t se
|
|
Jakub Jelen |
aacf0d |
/* send server hostkey, DH pubkey 'f' and singed H */
|
|
Jakub Jelen |
aacf0d |
if ((r = sshpkt_start(ssh, SSH2_MSG_KEXDH_REPLY)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 || /* f */
|
|
Jakub Jelen |
aacf0d |
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_send(ssh)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/kexgexc.c.openssl openssh/kexgexc.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/kexgexc.c.openssl 2017-09-26 13:19:31.783249611 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/kexgexc.c 2017-09-26 13:19:31.797249697 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -95,6 +95,7 @@ input_kex_dh_gex_group(int type, u_int32
|
|
Jakub Jelen |
aacf0d |
struct kex *kex = ssh->kex;
|
|
Jakub Jelen |
aacf0d |
BIGNUM *p = NULL, *g = NULL;
|
|
Jakub Jelen |
aacf0d |
int r, bits;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
debug("got SSH2_MSG_KEX_DH_GEX_GROUP");
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
3cd489 |
@@ -119,24 +120,30 @@ input_kex_dh_gex_group(int type, u_int32
|
|
Jakub Jelen |
aacf0d |
p = g = NULL; /* belong to kex->dh now */
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* generate and send 'e', client DH public key */
|
|
Jakub Jelen |
aacf0d |
- if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_INIT)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ if ((r = dh_gen_key(kex->dh, kex->we_need * 8)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(kex->dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_INIT)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_send(ssh)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
debug("SSH2_MSG_KEX_DH_GEX_INIT sent");
|
|
Jakub Jelen |
aacf0d |
#ifdef DEBUG_KEXDH
|
|
Jakub Jelen |
aacf0d |
DHparams_print_fp(stderr, kex->dh);
|
|
Jakub Jelen |
aacf0d |
fprintf(stderr, "pub= ");
|
|
Jakub Jelen |
aacf0d |
- BN_print_fp(stderr, kex->dh->pub_key);
|
|
Jakub Jelen |
aacf0d |
+ BN_print_fp(stderr, pub_key);
|
|
Jakub Jelen |
aacf0d |
fprintf(stderr, "\n");
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_GROUP, NULL);
|
|
Jakub Jelen |
aacf0d |
ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_REPLY, &input_kex_dh_gex_reply);
|
|
Jakub Jelen |
aacf0d |
r = 0;
|
|
Jakub Jelen |
aacf0d |
out:
|
|
Jakub Jelen |
3cd489 |
BN_clear_free(p);
|
|
Jakub Jelen |
3cd489 |
BN_clear_free(g);
|
|
Jakub Jelen |
aacf0d |
+ if (r != 0) {
|
|
Jakub Jelen |
aacf0d |
+ DH_free(kex->dh);
|
|
Jakub Jelen |
aacf0d |
+ kex->dh = NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
return r;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -152,6 +157,7 @@ input_kex_dh_gex_reply(int type, u_int32
|
|
Jakub Jelen |
aacf0d |
u_char hash[SSH_DIGEST_MAX_LENGTH];
|
|
Jakub Jelen |
aacf0d |
size_t klen = 0, slen, sbloblen, hashlen;
|
|
Jakub Jelen |
aacf0d |
int kout, r;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *g, *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
debug("got SSH2_MSG_KEX_DH_GEX_REPLY");
|
|
Jakub Jelen |
aacf0d |
if (kex->verify_host_key == NULL) {
|
|
Jakub Jelen |
5b55d0 |
@@ -214,6 +220,8 @@ input_kex_dh_gex_reply(int type, u_int32
|
|
Jakub Jelen |
aacf0d |
kex->min = kex->max = -1;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* calc and verify H */
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(kex->dh, &p, NULL, &g);
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(kex->dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
hashlen = sizeof(hash);
|
|
Jakub Jelen |
aacf0d |
if ((r = kexgex_hash(
|
|
Jakub Jelen |
aacf0d |
kex->hash_alg,
|
|
Jakub Jelen |
5b55d0 |
@@ -223,8 +231,8 @@ input_kex_dh_gex_reply(int type, u_int32
|
|
Jakub Jelen |
aacf0d |
sshbuf_ptr(kex->peer), sshbuf_len(kex->peer),
|
|
Jakub Jelen |
aacf0d |
server_host_key_blob, sbloblen,
|
|
Jakub Jelen |
aacf0d |
kex->min, kex->nbits, kex->max,
|
|
Jakub Jelen |
aacf0d |
- kex->dh->p, kex->dh->g,
|
|
Jakub Jelen |
aacf0d |
- kex->dh->pub_key,
|
|
Jakub Jelen |
aacf0d |
+ p, g,
|
|
Jakub Jelen |
aacf0d |
+ pub_key,
|
|
Jakub Jelen |
aacf0d |
dh_server_pub,
|
|
Jakub Jelen |
aacf0d |
shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen)) != 0)
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/kexgexs.c.openssl openssh/kexgexs.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/kexgexs.c.openssl 2017-09-26 13:19:31.783249611 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/kexgexs.c 2017-09-26 13:19:31.797249697 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -72,6 +72,7 @@ input_kex_dh_gex_request(int type, u_int
|
|
Jakub Jelen |
aacf0d |
struct kex *kex = ssh->kex;
|
|
Jakub Jelen |
aacf0d |
int r;
|
|
Jakub Jelen |
aacf0d |
u_int min = 0, max = 0, nbits = 0;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *g;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
debug("SSH2_MSG_KEX_DH_GEX_REQUEST received");
|
|
Jakub Jelen |
aacf0d |
if ((r = sshpkt_get_u32(ssh, &min)) != 0 ||
|
|
Jakub Jelen |
5b55d0 |
@@ -101,9 +102,10 @@ input_kex_dh_gex_request(int type, u_int
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
debug("SSH2_MSG_KEX_DH_GEX_GROUP sent");
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(kex->dh, &p, NULL, &g);
|
|
Jakub Jelen |
aacf0d |
if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_GROUP)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_put_bignum2(ssh, kex->dh->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_put_bignum2(ssh, kex->dh->g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshpkt_put_bignum2(ssh, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshpkt_put_bignum2(ssh, g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_send(ssh)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -115,6 +117,10 @@ input_kex_dh_gex_request(int type, u_int
|
|
Jakub Jelen |
aacf0d |
ssh_dispatch_set(ssh, SSH2_MSG_KEX_DH_GEX_INIT, &input_kex_dh_gex_init);
|
|
Jakub Jelen |
aacf0d |
r = 0;
|
|
Jakub Jelen |
aacf0d |
out:
|
|
Jakub Jelen |
aacf0d |
+ if (r != 0) {
|
|
Jakub Jelen |
aacf0d |
+ DH_free(kex->dh);
|
|
Jakub Jelen |
aacf0d |
+ kex->dh = NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
return r;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -129,6 +135,7 @@ input_kex_dh_gex_init(int type, u_int32_
|
|
Jakub Jelen |
aacf0d |
size_t sbloblen, slen;
|
|
Jakub Jelen |
aacf0d |
size_t klen = 0, hashlen;
|
|
Jakub Jelen |
aacf0d |
int kout, r;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *g, *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (kex->load_host_public_key == NULL ||
|
|
Jakub Jelen |
aacf0d |
kex->load_host_private_key == NULL) {
|
|
Jakub Jelen |
5b55d0 |
@@ -191,6 +198,8 @@ input_kex_dh_gex_init(int type, u_int32_
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
/* calc H */
|
|
Jakub Jelen |
aacf0d |
hashlen = sizeof(hash);
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(kex->dh, &p, NULL, &g);
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(kex->dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
if ((r = kexgex_hash(
|
|
Jakub Jelen |
aacf0d |
kex->hash_alg,
|
|
Jakub Jelen |
aacf0d |
kex->client_version_string,
|
|
Jakub Jelen |
5b55d0 |
@@ -199,9 +208,9 @@ input_kex_dh_gex_init(int type, u_int32_
|
|
Jakub Jelen |
aacf0d |
sshbuf_ptr(kex->my), sshbuf_len(kex->my),
|
|
Jakub Jelen |
aacf0d |
server_host_key_blob, sbloblen,
|
|
Jakub Jelen |
aacf0d |
kex->min, kex->nbits, kex->max,
|
|
Jakub Jelen |
aacf0d |
- kex->dh->p, kex->dh->g,
|
|
Jakub Jelen |
aacf0d |
+ p, g,
|
|
Jakub Jelen |
aacf0d |
dh_client_pub,
|
|
Jakub Jelen |
aacf0d |
- kex->dh->pub_key,
|
|
Jakub Jelen |
aacf0d |
+ pub_key,
|
|
Jakub Jelen |
aacf0d |
shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
5b55d0 |
@@ -227,7 +236,7 @@ input_kex_dh_gex_init(int type, u_int32_
|
|
Jakub Jelen |
aacf0d |
/* send server hostkey, DH pubkey 'f' and singed H */
|
|
Jakub Jelen |
aacf0d |
if ((r = sshpkt_start(ssh, SSH2_MSG_KEX_DH_GEX_REPLY)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_put_string(ssh, server_host_key_blob, sbloblen)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshpkt_put_bignum2(ssh, kex->dh->pub_key)) != 0 || /* f */
|
|
Jakub Jelen |
aacf0d |
+ (r = sshpkt_put_bignum2(ssh, pub_key)) != 0 || /* f */
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_put_string(ssh, signature, slen)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(r = sshpkt_send(ssh)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/kexgssc.c.openssl openssh/kexgssc.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/kexgssc.c.openssl 2017-09-26 13:19:31.771249537 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/kexgssc.c 2017-09-26 13:19:31.797249697 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -59,6 +59,7 @@ kexgss_client(struct ssh *ssh) {
|
|
Jakub Jelen |
aacf0d |
BIGNUM *shared_secret = NULL;
|
|
Jakub Jelen |
aacf0d |
BIGNUM *p = NULL;
|
|
Jakub Jelen |
aacf0d |
BIGNUM *g = NULL;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *pub_key, *p1, *g1;
|
|
Jakub Jelen |
aacf0d |
u_char *kbuf;
|
|
Jakub Jelen |
aacf0d |
u_char *serverhostkey = NULL;
|
|
Jakub Jelen |
aacf0d |
u_char *empty = "";
|
|
Jakub Jelen |
5b55d0 |
@@ -126,6 +127,7 @@ kexgss_client(struct ssh *ssh) {
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* Step 1 - e is dh->pub_key */
|
|
Jakub Jelen |
aacf0d |
dh_gen_key(dh, ssh->kex->we_need * 8);
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* This is f, we initialise it now to make life easier */
|
|
Jakub Jelen |
aacf0d |
dh_server_pub = BN_new();
|
|
Jakub Jelen |
5b55d0 |
@@ -173,7 +175,7 @@ kexgss_client(struct ssh *ssh) {
|
|
Jakub Jelen |
aacf0d |
packet_start(SSH2_MSG_KEXGSS_INIT);
|
|
Jakub Jelen |
aacf0d |
packet_put_string(send_tok.value,
|
|
Jakub Jelen |
aacf0d |
send_tok.length);
|
|
Jakub Jelen |
aacf0d |
- packet_put_bignum2(dh->pub_key);
|
|
Jakub Jelen |
aacf0d |
+ packet_put_bignum2((BIGNUM *)pub_key);
|
|
Jakub Jelen |
aacf0d |
first = 0;
|
|
Jakub Jelen |
aacf0d |
} else {
|
|
Jakub Jelen |
aacf0d |
packet_start(SSH2_MSG_KEXGSS_CONTINUE);
|
|
Jakub Jelen |
5b55d0 |
@@ -282,13 +284,14 @@ kexgss_client(struct ssh *ssh) {
|
|
Jakub Jelen |
aacf0d |
buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
|
|
Jakub Jelen |
aacf0d |
buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
|
|
Jakub Jelen |
aacf0d |
(serverhostkey ? serverhostkey : empty), slen,
|
|
Jakub Jelen |
aacf0d |
- dh->pub_key, /* e */
|
|
Jakub Jelen |
aacf0d |
+ pub_key, /* e */
|
|
Jakub Jelen |
aacf0d |
dh_server_pub, /* f */
|
|
Jakub Jelen |
aacf0d |
shared_secret, /* K */
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen
|
|
Jakub Jelen |
aacf0d |
);
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEX_GSS_GEX_SHA1:
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(dh, &p1, NULL, &g1;;
|
|
Jakub Jelen |
aacf0d |
kexgex_hash(
|
|
Jakub Jelen |
aacf0d |
ssh->kex->hash_alg,
|
|
Jakub Jelen |
aacf0d |
ssh->kex->client_version_string,
|
|
Jakub Jelen |
5b55d0 |
@@ -297,8 +300,8 @@ kexgss_client(struct ssh *ssh) {
|
|
Jakub Jelen |
aacf0d |
buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
|
|
Jakub Jelen |
aacf0d |
(serverhostkey ? serverhostkey : empty), slen,
|
|
Jakub Jelen |
aacf0d |
min, nbits, max,
|
|
Jakub Jelen |
aacf0d |
- dh->p, dh->g,
|
|
Jakub Jelen |
aacf0d |
- dh->pub_key,
|
|
Jakub Jelen |
aacf0d |
+ p1, g1,
|
|
Jakub Jelen |
aacf0d |
+ pub_key,
|
|
Jakub Jelen |
aacf0d |
dh_server_pub,
|
|
Jakub Jelen |
aacf0d |
shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/kexgsss.c.openssl openssh/kexgsss.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/kexgsss.c.openssl 2017-09-26 13:19:31.771249537 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/kexgsss.c 2017-09-26 13:19:31.798249703 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -78,6 +78,7 @@ kexgss_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
char *mechs;
|
|
Jakub Jelen |
aacf0d |
u_char hash[SSH_DIGEST_MAX_LENGTH];
|
|
Jakub Jelen |
aacf0d |
size_t hashlen;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *g, *pub_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* Initialise GSSAPI */
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -127,9 +128,10 @@ kexgss_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
if (dh == NULL)
|
|
Jakub Jelen |
aacf0d |
packet_disconnect("Protocol error: no matching group found");
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(dh, &p, NULL, &g);
|
|
Jakub Jelen |
aacf0d |
packet_start(SSH2_MSG_KEXGSS_GROUP);
|
|
Jakub Jelen |
aacf0d |
- packet_put_bignum2(dh->p);
|
|
Jakub Jelen |
aacf0d |
- packet_put_bignum2(dh->g);
|
|
Jakub Jelen |
aacf0d |
+ packet_put_bignum2((BIGNUM *)p);
|
|
Jakub Jelen |
aacf0d |
+ packet_put_bignum2((BIGNUM *)g);
|
|
Jakub Jelen |
aacf0d |
packet_send();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
packet_write_wait();
|
|
Jakub Jelen |
5b55d0 |
@@ -221,6 +223,7 @@ kexgss_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
memset(kbuf, 0, klen);
|
|
Jakub Jelen |
aacf0d |
free(kbuf);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_key(dh, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
hashlen = sizeof(hash);
|
|
Jakub Jelen |
aacf0d |
switch (ssh->kex->kex_type) {
|
|
Jakub Jelen |
aacf0d |
case KEX_GSS_GRP1_SHA1:
|
|
Jakub Jelen |
5b55d0 |
@@ -232,7 +235,7 @@ kexgss_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
buffer_ptr(ssh->kex->peer), buffer_len(ssh->kex->peer),
|
|
Jakub Jelen |
aacf0d |
buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
|
|
Jakub Jelen |
aacf0d |
NULL, 0, /* Change this if we start sending host keys */
|
|
Jakub Jelen |
aacf0d |
- dh_client_pub, dh->pub_key, shared_secret,
|
|
Jakub Jelen |
aacf0d |
+ dh_client_pub, pub_key, shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen
|
|
Jakub Jelen |
aacf0d |
);
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
5b55d0 |
@@ -244,9 +247,9 @@ kexgss_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
buffer_ptr(ssh->kex->my), buffer_len(ssh->kex->my),
|
|
Jakub Jelen |
aacf0d |
NULL, 0,
|
|
Jakub Jelen |
aacf0d |
cmin, nbits, cmax,
|
|
Jakub Jelen |
aacf0d |
- dh->p, dh->g,
|
|
Jakub Jelen |
aacf0d |
+ p, g,
|
|
Jakub Jelen |
aacf0d |
dh_client_pub,
|
|
Jakub Jelen |
aacf0d |
- dh->pub_key,
|
|
Jakub Jelen |
aacf0d |
+ pub_key,
|
|
Jakub Jelen |
aacf0d |
shared_secret,
|
|
Jakub Jelen |
aacf0d |
hash, &hashlen
|
|
Jakub Jelen |
aacf0d |
);
|
|
Jakub Jelen |
5b55d0 |
@@ -270,7 +273,7 @@ kexgss_server(struct ssh *ssh)
|
|
Jakub Jelen |
aacf0d |
fatal("Couldn't get MIC");
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
packet_start(SSH2_MSG_KEXGSS_COMPLETE);
|
|
Jakub Jelen |
aacf0d |
- packet_put_bignum2(dh->pub_key);
|
|
Jakub Jelen |
aacf0d |
+ packet_put_bignum2((BIGNUM *)pub_key);
|
|
Jakub Jelen |
aacf0d |
packet_put_string(msg_tok.value,msg_tok.length);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (send_tok.length != 0) {
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/libcrypto-compat.c.openssl openssh/libcrypto-compat.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/libcrypto-compat.c.openssl 2017-09-26 13:19:31.798249703 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/libcrypto-compat.c 2017-09-26 13:19:31.798249703 +0200
|
|
Jakub Jelen |
e0e7ed |
@@ -0,0 +1,428 @@
|
|
Jakub Jelen |
aacf0d |
+/*
|
|
Jakub Jelen |
aacf0d |
+ * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
Jakub Jelen |
aacf0d |
+ *
|
|
Jakub Jelen |
aacf0d |
+ * Licensed under the OpenSSL license (the "License"). You may not use
|
|
Jakub Jelen |
aacf0d |
+ * this file except in compliance with the License. You can obtain a copy
|
|
Jakub Jelen |
aacf0d |
+ * in the file LICENSE in the source distribution or at
|
|
Jakub Jelen |
aacf0d |
+ * https://www.openssl.org/source/license.html
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#include "includes.h"
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#include <string.h>
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/engine.h>
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+static void *OPENSSL_zalloc(size_t num)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ void *ret = OPENSSL_malloc(num);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (ret != NULL)
|
|
Jakub Jelen |
aacf0d |
+ memset(ret, 0, num);
|
|
Jakub Jelen |
aacf0d |
+ return ret;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ /* If the fields n and e in r are NULL, the corresponding input
|
|
Jakub Jelen |
aacf0d |
+ * parameters MUST be non-NULL for n and e. d may be
|
|
Jakub Jelen |
aacf0d |
+ * left NULL (in case only the public key is used).
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if ((r->n == NULL && n == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (r->e == NULL && e == NULL))
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (n != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->n);
|
|
Jakub Jelen |
aacf0d |
+ r->n = n;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (e != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->e);
|
|
Jakub Jelen |
aacf0d |
+ r->e = e;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (d != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->d);
|
|
Jakub Jelen |
aacf0d |
+ r->d = d;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ /* If the fields p and q in r are NULL, the corresponding input
|
|
Jakub Jelen |
aacf0d |
+ * parameters MUST be non-NULL.
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if ((r->p == NULL && p == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (r->q == NULL && q == NULL))
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (p != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->p);
|
|
Jakub Jelen |
aacf0d |
+ r->p = p;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->q);
|
|
Jakub Jelen |
aacf0d |
+ r->q = q;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
|
|
Jakub Jelen |
aacf0d |
+ * parameters MUST be non-NULL.
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if ((r->dmp1 == NULL && dmp1 == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (r->dmq1 == NULL && dmq1 == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (r->iqmp == NULL && iqmp == NULL))
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (dmp1 != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->dmp1);
|
|
Jakub Jelen |
aacf0d |
+ r->dmp1 = dmp1;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (dmq1 != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->dmq1);
|
|
Jakub Jelen |
aacf0d |
+ r->dmq1 = dmq1;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (iqmp != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r->iqmp);
|
|
Jakub Jelen |
aacf0d |
+ r->iqmp = iqmp;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void RSA_get0_key(const RSA *r,
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (n != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *n = r->n;
|
|
Jakub Jelen |
aacf0d |
+ if (e != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *e = r->e;
|
|
Jakub Jelen |
aacf0d |
+ if (d != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *d = r->d;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (p != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *p = r->p;
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *q = r->q;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void RSA_get0_crt_params(const RSA *r,
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM **dmp1, const BIGNUM **dmq1,
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM **iqmp)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (dmp1 != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *dmp1 = r->dmp1;
|
|
Jakub Jelen |
aacf0d |
+ if (dmq1 != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *dmq1 = r->dmq1;
|
|
Jakub Jelen |
aacf0d |
+ if (iqmp != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *iqmp = r->iqmp;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DSA_get0_pqg(const DSA *d,
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (p != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *p = d->p;
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *q = d->q;
|
|
Jakub Jelen |
aacf0d |
+ if (g != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *g = d->g;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ /* If the fields p, q and g in d are NULL, the corresponding input
|
|
Jakub Jelen |
aacf0d |
+ * parameters MUST be non-NULL.
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if ((d->p == NULL && p == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (d->q == NULL && q == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (d->g == NULL && g == NULL))
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (p != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(d->p);
|
|
Jakub Jelen |
aacf0d |
+ d->p = p;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(d->q);
|
|
Jakub Jelen |
aacf0d |
+ d->q = q;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (g != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(d->g);
|
|
Jakub Jelen |
aacf0d |
+ d->g = g;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DSA_get0_key(const DSA *d,
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM **pub_key, const BIGNUM **priv_key)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (pub_key != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *pub_key = d->pub_key;
|
|
Jakub Jelen |
aacf0d |
+ if (priv_key != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *priv_key = d->priv_key;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ /* If the field pub_key in d is NULL, the corresponding input
|
|
Jakub Jelen |
aacf0d |
+ * parameters MUST be non-NULL. The priv_key field may
|
|
Jakub Jelen |
aacf0d |
+ * be left NULL.
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if (d->pub_key == NULL && pub_key == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (pub_key != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(d->pub_key);
|
|
Jakub Jelen |
aacf0d |
+ d->pub_key = pub_key;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (priv_key != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(d->priv_key);
|
|
Jakub Jelen |
aacf0d |
+ d->priv_key = priv_key;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (pr != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *pr = sig->r;
|
|
Jakub Jelen |
aacf0d |
+ if (ps != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *ps = sig->s;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (r == NULL || s == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+ BN_clear_free(sig->r);
|
|
Jakub Jelen |
aacf0d |
+ BN_clear_free(sig->s);
|
|
Jakub Jelen |
aacf0d |
+ sig->r = r;
|
|
Jakub Jelen |
aacf0d |
+ sig->s = s;
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (pr != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *pr = sig->r;
|
|
Jakub Jelen |
aacf0d |
+ if (ps != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *ps = sig->s;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (r == NULL || s == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+ BN_clear_free(sig->r);
|
|
Jakub Jelen |
aacf0d |
+ BN_clear_free(sig->s);
|
|
Jakub Jelen |
aacf0d |
+ sig->r = r;
|
|
Jakub Jelen |
aacf0d |
+ sig->s = s;
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DH_get0_pqg(const DH *dh,
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (p != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *p = dh->p;
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *q = dh->q;
|
|
Jakub Jelen |
aacf0d |
+ if (g != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *g = dh->g;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ /* If the fields p and g in d are NULL, the corresponding input
|
|
Jakub Jelen |
aacf0d |
+ * parameters MUST be non-NULL. q may remain NULL.
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if ((dh->p == NULL && p == NULL)
|
|
Jakub Jelen |
aacf0d |
+ || (dh->g == NULL && g == NULL))
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (p != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(dh->p);
|
|
Jakub Jelen |
aacf0d |
+ dh->p = p;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(dh->q);
|
|
Jakub Jelen |
aacf0d |
+ dh->q = q;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (g != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(dh->g);
|
|
Jakub Jelen |
aacf0d |
+ dh->g = g;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (q != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ dh->length = BN_num_bits(q);
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (pub_key != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *pub_key = dh->pub_key;
|
|
Jakub Jelen |
aacf0d |
+ if (priv_key != NULL)
|
|
Jakub Jelen |
aacf0d |
+ *priv_key = dh->priv_key;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int DH_set_length(DH *dh, long length)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ dh->length = length;
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ return ctx->iv;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ return ctx->iv;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+EVP_MD_CTX *EVP_MD_CTX_new(void)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ return OPENSSL_zalloc(sizeof(EVP_MD_CTX));
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+static void OPENSSL_clear_free(void *str, size_t num)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (str == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return;
|
|
Jakub Jelen |
aacf0d |
+ if (num)
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_cleanse(str, num);
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_free(str);
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+/* This call frees resources associated with the context */
|
|
Jakub Jelen |
aacf0d |
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (ctx == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ /*
|
|
Jakub Jelen |
aacf0d |
+ * Don't assume ctx->md_data was cleaned in EVP_Digest_Final, because
|
|
Jakub Jelen |
aacf0d |
+ * sometimes only copies of the context are ever finalised.
|
|
Jakub Jelen |
aacf0d |
+ */
|
|
Jakub Jelen |
aacf0d |
+ if (ctx->digest && ctx->digest->cleanup
|
|
Jakub Jelen |
aacf0d |
+ && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_CLEANED))
|
|
Jakub Jelen |
aacf0d |
+ ctx->digest->cleanup(ctx);
|
|
Jakub Jelen |
aacf0d |
+ if (ctx->digest && ctx->digest->ctx_size && ctx->md_data
|
|
Jakub Jelen |
aacf0d |
+ && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ EVP_PKEY_CTX_free(ctx->pctx);
|
|
Jakub Jelen |
aacf0d |
+#ifndef OPENSSL_NO_ENGINE
|
|
Jakub Jelen |
aacf0d |
+ ENGINE_finish(ctx->engine);
|
|
Jakub Jelen |
aacf0d |
+#endif
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_cleanse(ctx, sizeof(*ctx));
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ EVP_MD_CTX_reset(ctx);
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_free(ctx);
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ RSA_METHOD *ret;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ ret = OPENSSL_malloc(sizeof(RSA_METHOD));
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (ret != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ memcpy(ret, meth, sizeof(*meth));
|
|
Jakub Jelen |
aacf0d |
+ ret->name = OPENSSL_strdup(meth->name);
|
|
Jakub Jelen |
aacf0d |
+ if (ret->name == NULL) {
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_free(ret);
|
|
Jakub Jelen |
aacf0d |
+ return NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return ret;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_meth_set1_name(RSA_METHOD *meth, const char *name)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ char *tmpname;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ tmpname = OPENSSL_strdup(name);
|
|
Jakub Jelen |
aacf0d |
+ if (tmpname == NULL) {
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_free((char *)meth->name);
|
|
Jakub Jelen |
aacf0d |
+ meth->name = tmpname;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_meth_set_priv_enc(RSA_METHOD *meth,
|
|
Jakub Jelen |
aacf0d |
+ int (*priv_enc) (int flen, const unsigned char *from,
|
|
Jakub Jelen |
aacf0d |
+ unsigned char *to, RSA *rsa,
|
|
Jakub Jelen |
aacf0d |
+ int padding))
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ meth->rsa_priv_enc = priv_enc;
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_meth_set_priv_dec(RSA_METHOD *meth,
|
|
Jakub Jelen |
aacf0d |
+ int (*priv_dec) (int flen, const unsigned char *from,
|
|
Jakub Jelen |
aacf0d |
+ unsigned char *to, RSA *rsa,
|
|
Jakub Jelen |
aacf0d |
+ int padding))
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ meth->rsa_priv_dec = priv_dec;
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa))
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ meth->finish = finish;
|
|
Jakub Jelen |
aacf0d |
+ return 1;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void RSA_meth_free(RSA_METHOD *meth)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (meth != NULL) {
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_free((char *)meth->name);
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_free(meth);
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_bits(const RSA *r)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ return (BN_num_bits(r->n));
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int DSA_bits(const DSA *dsa)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ return BN_num_bits(dsa->p);
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
|
|
Jakub Jelen |
aacf0d |
+{
|
|
Jakub Jelen |
aacf0d |
+ if (pkey->type != EVP_PKEY_RSA) {
|
|
Jakub Jelen |
aacf0d |
+ return NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ return pkey->pkey.rsa;
|
|
Jakub Jelen |
aacf0d |
+}
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#endif /* OPENSSL_VERSION_NUMBER */
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/libcrypto-compat.h.openssl openssh/libcrypto-compat.h
|
|
Jakub Jelen |
5b55d0 |
--- openssh/libcrypto-compat.h.openssl 2017-09-26 13:19:31.798249703 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/libcrypto-compat.h 2017-09-26 13:19:31.798249703 +0200
|
|
Jakub Jelen |
e0e7ed |
@@ -0,0 +1,59 @@
|
|
Jakub Jelen |
aacf0d |
+#ifndef LIBCRYPTO_COMPAT_H
|
|
Jakub Jelen |
aacf0d |
+#define LIBCRYPTO_COMPAT_H
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/rsa.h>
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/dsa.h>
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/ecdsa.h>
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/dh.h>
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/evp.h>
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
|
|
Jakub Jelen |
aacf0d |
+int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
|
|
Jakub Jelen |
aacf0d |
+int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
|
|
Jakub Jelen |
aacf0d |
+void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
|
|
Jakub Jelen |
aacf0d |
+void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
|
|
Jakub Jelen |
aacf0d |
+void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
|
|
Jakub Jelen |
aacf0d |
+int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
|
|
Jakub Jelen |
aacf0d |
+void DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key);
|
|
Jakub Jelen |
aacf0d |
+int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
|
|
Jakub Jelen |
aacf0d |
+int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
|
|
Jakub Jelen |
aacf0d |
+int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+void DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
|
|
Jakub Jelen |
aacf0d |
+int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
|
|
Jakub Jelen |
aacf0d |
+void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
|
|
Jakub Jelen |
aacf0d |
+int DH_set_length(DH *dh, long length);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx);
|
|
Jakub Jelen |
aacf0d |
+unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx);
|
|
Jakub Jelen |
aacf0d |
+int EVP_MD_CTX_reset(EVP_MD_CTX *ctx);
|
|
Jakub Jelen |
aacf0d |
+EVP_MD_CTX *EVP_MD_CTX_new(void);
|
|
Jakub Jelen |
aacf0d |
+void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
|
|
Jakub Jelen |
aacf0d |
+#define EVP_CIPHER_impl_ctx_size(e) e->ctx_size
|
|
Jakub Jelen |
aacf0d |
+#define EVP_CIPHER_CTX_get_cipher_data(ctx) ctx->cipher_data
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+RSA_METHOD *RSA_meth_dup(const RSA_METHOD *meth);
|
|
Jakub Jelen |
aacf0d |
+int RSA_meth_set1_name(RSA_METHOD *meth, const char *name);
|
|
Jakub Jelen |
aacf0d |
+#define RSA_meth_get_finish(meth) meth->finish
|
|
Jakub Jelen |
aacf0d |
+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));
|
|
Jakub Jelen |
aacf0d |
+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));
|
|
Jakub Jelen |
aacf0d |
+int RSA_meth_set_finish(RSA_METHOD *meth, int (*finish) (RSA *rsa));
|
|
Jakub Jelen |
aacf0d |
+void RSA_meth_free(RSA_METHOD *meth);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+int RSA_bits(const RSA *r);
|
|
Jakub Jelen |
aacf0d |
+int DSA_bits(const DSA *d);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#endif /* OPENSSL_VERSION_NUMBER */
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+#endif /* LIBCRYPTO_COMPAT_H */
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/Makefile.in.openssl openssh/Makefile.in
|
|
Jakub Jelen |
5b55d0 |
--- openssh/Makefile.in.openssl 2017-09-26 13:19:31.784249617 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/Makefile.in 2017-09-26 13:19:31.798249703 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -101,7 +101,7 @@ LIBSSH_OBJS=${LIBOPENSSH_OBJS} \
|
|
Jakub Jelen |
aacf0d |
kexdhc.o kexgexc.o kexecdhc.o kexc25519c.o \
|
|
Jakub Jelen |
aacf0d |
kexdhs.o kexgexs.o kexecdhs.o kexc25519s.o \
|
|
Jakub Jelen |
5b55d0 |
platform-pledge.o platform-tracing.o platform-misc.o \
|
|
Jakub Jelen |
5b55d0 |
- auditstub.o
|
|
Jakub Jelen |
5b55d0 |
+ auditstub.o libcrypto-compat.o
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
SSHOBJS= ssh.o readconf.o clientloop.o sshtty.o \
|
|
Jakub Jelen |
5b55d0 |
sshconnect.o sshconnect2.o mux.o
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/monitor.c.openssl openssh/monitor.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/monitor.c.openssl 2017-09-26 13:19:31.789249648 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/monitor.c 2017-09-26 13:19:31.799249709 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -631,9 +631,12 @@ mm_answer_moduli(int sock, Buffer *m)
|
|
Jakub Jelen |
aacf0d |
return (0);
|
|
Jakub Jelen |
aacf0d |
} else {
|
|
Jakub Jelen |
aacf0d |
/* Send first bignum */
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *g;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DH_get0_pqg(dh, &p, NULL, &g);
|
|
Jakub Jelen |
aacf0d |
buffer_put_char(m, 1);
|
|
Jakub Jelen |
aacf0d |
- buffer_put_bignum2(m, dh->p);
|
|
Jakub Jelen |
aacf0d |
- buffer_put_bignum2(m, dh->g);
|
|
Jakub Jelen |
aacf0d |
+ buffer_put_bignum2(m, p);
|
|
Jakub Jelen |
aacf0d |
+ buffer_put_bignum2(m, g);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
DH_free(dh);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/openbsd-compat/openssl-compat.c.openssl openssh/openbsd-compat/openssl-compat.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/openbsd-compat/openssl-compat.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/openbsd-compat/openssl-compat.c 2017-09-26 13:19:31.799249709 +0200
|
|
Jakub Jelen |
6cf9b8 |
@@ -70,12 +70,19 @@ ssh_compatible_openssl(long headerver, l
|
|
Jakub Jelen |
aacf0d |
void
|
|
Jakub Jelen |
aacf0d |
ssh_OpenSSL_add_all_algorithms(void)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Jakub Jelen |
aacf0d |
OpenSSL_add_all_algorithms();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* Enable use of crypto hardware */
|
|
Jakub Jelen |
aacf0d |
ENGINE_load_builtin_engines();
|
|
Jakub Jelen |
aacf0d |
+#if OPENSSL_VERSION_NUMBER < 0x10001000L
|
|
Jakub Jelen |
aacf0d |
ENGINE_register_all_complete();
|
|
Jakub Jelen |
aacf0d |
+#endif
|
|
Jakub Jelen |
aacf0d |
OPENSSL_config(NULL);
|
|
Jakub Jelen |
aacf0d |
+#else
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_DIGESTS |
|
|
Jakub Jelen |
aacf0d |
+ OPENSSL_INIT_ADD_ALL_DIGESTS | OPENSSL_INIT_LOAD_CONFIG, NULL);
|
|
Jakub Jelen |
aacf0d |
+#endif
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/pam_ssh_agent_auth-0.10.3/configure.ac.openssl openssh/pam_ssh_agent_auth-0.10.3/configure.ac
|
|
Jakub Jelen |
5b55d0 |
--- openssh/pam_ssh_agent_auth-0.10.3/configure.ac.openssl 2016-11-13 04:24:32.000000000 +0100
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/pam_ssh_agent_auth-0.10.3/configure.ac 2017-09-26 13:19:31.799249709 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -1829,6 +1829,7 @@ AC_RUN_IFELSE(
|
|
Jakub Jelen |
aacf0d |
[AC_LANG_SOURCE([[
|
|
Jakub Jelen |
aacf0d |
#include <string.h>
|
|
Jakub Jelen |
aacf0d |
#include <openssl/opensslv.h>
|
|
Jakub Jelen |
aacf0d |
+#include <openssl/crypto.h>
|
|
Jakub Jelen |
aacf0d |
int main(void) { exit(SSLeay() == OPENSSL_VERSION_NUMBER ? 0 : 1); }
|
|
Jakub Jelen |
aacf0d |
]])],
|
|
Jakub Jelen |
aacf0d |
[
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/regress/unittests/sshkey/test_file.c.openssl openssh/regress/unittests/sshkey/test_file.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/regress/unittests/sshkey/test_file.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/regress/unittests/sshkey/test_file.c 2017-09-26 13:19:31.799249709 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -46,6 +46,7 @@ sshkey_file_tests(void)
|
|
Jakub Jelen |
aacf0d |
struct sshbuf *buf, *pw;
|
|
Jakub Jelen |
aacf0d |
BIGNUM *a, *b, *c;
|
|
Jakub Jelen |
aacf0d |
char *cp;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *n, *p, *q, *g, *pub_key, *priv_key;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
TEST_START("load passphrase");
|
|
Jakub Jelen |
aacf0d |
pw = load_text_file("pw");
|
|
Jakub Jelen |
5b55d0 |
@@ -60,9 +61,11 @@ sshkey_file_tests(void)
|
|
Jakub Jelen |
aacf0d |
a = load_bignum("rsa_1.param.n");
|
|
Jakub Jelen |
aacf0d |
b = load_bignum("rsa_1.param.p");
|
|
Jakub Jelen |
aacf0d |
c = load_bignum("rsa_1.param.q");
|
|
Jakub Jelen |
aacf0d |
- ASSERT_BIGNUM_EQ(k1->rsa->n, a);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_BIGNUM_EQ(k1->rsa->p, b);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_BIGNUM_EQ(k1->rsa->q, c);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(k1->rsa, &n, NULL, NULL);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_factors(k1->rsa, &p, &q);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_BIGNUM_EQ(n, a);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_BIGNUM_EQ(p, b);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_BIGNUM_EQ(q, c);
|
|
Jakub Jelen |
aacf0d |
BN_free(a);
|
|
Jakub Jelen |
aacf0d |
BN_free(b);
|
|
Jakub Jelen |
aacf0d |
BN_free(c);
|
|
Jakub Jelen |
5b55d0 |
@@ -151,9 +154,11 @@ sshkey_file_tests(void)
|
|
Jakub Jelen |
aacf0d |
a = load_bignum("dsa_1.param.g");
|
|
Jakub Jelen |
aacf0d |
b = load_bignum("dsa_1.param.priv");
|
|
Jakub Jelen |
aacf0d |
c = load_bignum("dsa_1.param.pub");
|
|
Jakub Jelen |
aacf0d |
- ASSERT_BIGNUM_EQ(k1->dsa->g, a);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_BIGNUM_EQ(k1->dsa->priv_key, b);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_BIGNUM_EQ(k1->dsa->pub_key, c);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(k1->dsa, NULL, NULL, &g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(k1->dsa, &pub_key, &priv_key);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_BIGNUM_EQ(g, a);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_BIGNUM_EQ(priv_key, b);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_BIGNUM_EQ(pub_key, c);
|
|
Jakub Jelen |
aacf0d |
BN_free(a);
|
|
Jakub Jelen |
aacf0d |
BN_free(b);
|
|
Jakub Jelen |
aacf0d |
BN_free(c);
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/regress/unittests/sshkey/test_sshkey.c.openssl openssh/regress/unittests/sshkey/test_sshkey.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/regress/unittests/sshkey/test_sshkey.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/regress/unittests/sshkey/test_sshkey.c 2017-09-26 13:19:31.800249715 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -197,9 +197,6 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
k1 = sshkey_new(KEY_RSA);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1->rsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->n, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->e, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_EQ(k1->rsa->p, NULL);
|
|
Jakub Jelen |
aacf0d |
sshkey_free(k1);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -207,8 +204,6 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
k1 = sshkey_new(KEY_DSA);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1->dsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->dsa->g, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
|
|
Jakub Jelen |
aacf0d |
sshkey_free(k1);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
@@ -234,9 +229,6 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
k1 = sshkey_new_private(KEY_RSA);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1->rsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->n, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->e, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->p, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_INT_EQ(sshkey_add_private(k1), 0);
|
|
Jakub Jelen |
aacf0d |
sshkey_free(k1);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
5b55d0 |
@@ -245,8 +237,6 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
k1 = sshkey_new_private(KEY_DSA);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1->dsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->dsa->g, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->dsa->priv_key, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_INT_EQ(sshkey_add_private(k1), 0);
|
|
Jakub Jelen |
aacf0d |
sshkey_free(k1);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
5b55d0 |
@@ -285,18 +275,13 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
ASSERT_INT_EQ(sshkey_generate(KEY_RSA, 1024, &kr), 0);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(kr, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(kr->rsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(kr->rsa->n, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(kr->rsa->e, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(kr->rsa->p, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_INT_EQ(BN_num_bits(kr->rsa->n), 1024);
|
|
Jakub Jelen |
aacf0d |
+ ASSERT_INT_EQ(RSA_bits(kr->rsa), 1024);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
TEST_START("generate KEY_DSA");
|
|
Jakub Jelen |
aacf0d |
ASSERT_INT_EQ(sshkey_generate(KEY_DSA, 1024, &kd), 0);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(kd, NULL);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(kd->dsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(kd->dsa->g, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(kd->dsa->priv_key, NULL);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
#ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
5b55d0 |
@@ -323,9 +308,6 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(kr, k1);
|
|
Jakub Jelen |
aacf0d |
ASSERT_INT_EQ(k1->type, KEY_RSA);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1->rsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->n, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->rsa->e, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_EQ(k1->rsa->p, NULL);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
TEST_START("equal KEY_RSA/demoted KEY_RSA");
|
|
Jakub Jelen |
5b55d0 |
@@ -339,8 +321,6 @@ sshkey_tests(void)
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(kd, k1);
|
|
Jakub Jelen |
aacf0d |
ASSERT_INT_EQ(k1->type, KEY_DSA);
|
|
Jakub Jelen |
aacf0d |
ASSERT_PTR_NE(k1->dsa, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_NE(k1->dsa->g, NULL);
|
|
Jakub Jelen |
aacf0d |
- ASSERT_PTR_EQ(k1->dsa->priv_key, NULL);
|
|
Jakub Jelen |
aacf0d |
TEST_DONE();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
TEST_START("equal KEY_DSA/demoted KEY_DSA");
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/sshconnect2.c.openssl openssh/sshconnect2.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/sshconnect2.c.openssl 2017-09-26 13:19:31.786249629 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/sshconnect2.c 2017-09-26 13:19:31.800249715 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -306,6 +306,7 @@ ssh_kex2(char *host, struct sockaddr *ho
|
|
Jakub Jelen |
aacf0d |
packet_send();
|
|
Jakub Jelen |
aacf0d |
packet_write_wait();
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
+ /* XXX free myproposal ?? */
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/*
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh.c.openssl openssh/ssh.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh.c.openssl 2017-09-26 13:19:31.786249629 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh.c 2017-09-26 13:19:31.800249715 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -530,7 +530,9 @@ main(int ac, char **av)
|
|
Jakub Jelen |
aacf0d |
sanitise_stdfd();
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
__progname = ssh_get_progname(av[0]);
|
|
Jakub Jelen |
aacf0d |
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
|
Jakub Jelen |
aacf0d |
SSLeay_add_all_algorithms();
|
|
Jakub Jelen |
aacf0d |
+#endif
|
|
Jakub Jelen |
aacf0d |
if (access("/etc/system-fips", F_OK) == 0)
|
|
Jakub Jelen |
aacf0d |
if (! FIPSCHECK_verify(NULL, NULL)){
|
|
Jakub Jelen |
aacf0d |
if (FIPS_mode())
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/sshd.c.openssl openssh/sshd.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/sshd.c.openssl 2017-09-26 13:19:31.792249666 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/sshd.c 2017-09-26 13:19:31.801249721 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -1485,7 +1485,7 @@ main(int ac, char **av)
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
__progname = ssh_get_progname(av[0]);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- SSLeay_add_all_algorithms();
|
|
Jakub Jelen |
aacf0d |
+ OpenSSL_add_all_algorithms();
|
|
Jakub Jelen |
aacf0d |
if (access("/etc/system-fips", F_OK) == 0)
|
|
Jakub Jelen |
aacf0d |
if (! FIPSCHECK_verify(NULL, NULL)) {
|
|
Jakub Jelen |
aacf0d |
openlog(__progname, LOG_PID, LOG_AUTHPRIV);
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh-dss.c.openssl openssh/ssh-dss.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh-dss.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh-dss.c 2017-09-26 13:19:31.801249721 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -55,6 +55,7 @@ ssh_dss_sign(const struct sshkey *key, u
|
|
Jakub Jelen |
aacf0d |
size_t rlen, slen, len, dlen = ssh_digest_bytes(SSH_DIGEST_SHA1);
|
|
Jakub Jelen |
aacf0d |
struct sshbuf *b = NULL;
|
|
Jakub Jelen |
aacf0d |
int ret = SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *r, *s;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (lenp != NULL)
|
|
Jakub Jelen |
aacf0d |
*lenp = 0;
|
|
Jakub Jelen |
aacf0d |
@@ -76,15 +77,16 @@ ssh_dss_sign(const struct sshkey *key, u
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- rlen = BN_num_bytes(sig->r);
|
|
Jakub Jelen |
aacf0d |
- slen = BN_num_bytes(sig->s);
|
|
Jakub Jelen |
aacf0d |
+ DSA_SIG_get0(sig, &r, &s);
|
|
Jakub Jelen |
aacf0d |
+ rlen = BN_num_bytes(r);
|
|
Jakub Jelen |
aacf0d |
+ slen = BN_num_bytes(s);
|
|
Jakub Jelen |
aacf0d |
if (rlen > INTBLOB_LEN || slen > INTBLOB_LEN) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_INTERNAL_ERROR;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
explicit_bzero(sigblob, SIGBLOB_LEN);
|
|
Jakub Jelen |
aacf0d |
- BN_bn2bin(sig->r, sigblob + SIGBLOB_LEN - INTBLOB_LEN - rlen);
|
|
Jakub Jelen |
aacf0d |
- BN_bn2bin(sig->s, sigblob + SIGBLOB_LEN - slen);
|
|
Jakub Jelen |
aacf0d |
+ BN_bn2bin(r, sigblob + SIGBLOB_LEN - INTBLOB_LEN - rlen);
|
|
Jakub Jelen |
aacf0d |
+ BN_bn2bin(s, sigblob + SIGBLOB_LEN - slen);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
3cd489 |
if ((b = sshbuf_new()) == NULL) {
|
|
Jakub Jelen |
3cd489 |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
@@ -137,6 +139,7 @@ ssh_dss_verify(const struct sshkey *key,
|
|
Jakub Jelen |
aacf0d |
int ret = SSH_ERR_INTERNAL_ERROR;
|
|
Jakub Jelen |
aacf0d |
struct sshbuf *b = NULL;
|
|
Jakub Jelen |
aacf0d |
char *ktype = NULL;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *r = NULL, *s = NULL;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (key == NULL || key->dsa == NULL ||
|
|
Jakub Jelen |
aacf0d |
sshkey_type_plain(key->type) != KEY_DSA ||
|
|
Jakub Jelen |
aacf0d |
@@ -177,16 +180,19 @@ ssh_dss_verify(const struct sshkey *key,
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* parse signature */
|
|
Jakub Jelen |
aacf0d |
if ((sig = DSA_SIG_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (sig->r = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (sig->s = BN_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
+ (r = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (s = BN_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if ((BN_bin2bn(sigblob, INTBLOB_LEN, sig->r) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
- (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s) == NULL)) {
|
|
Jakub Jelen |
aacf0d |
+ if ((BN_bin2bn(sigblob, INTBLOB_LEN, r) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, s) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ (DSA_SIG_set0(sig, r, s) == 0)) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
+ r = NULL;
|
|
Jakub Jelen |
aacf0d |
+ s = NULL;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* sha1 the data */
|
|
Jakub Jelen |
aacf0d |
if ((ret = ssh_digest_memory(SSH_DIGEST_SHA1, data, datalen,
|
|
Jakub Jelen |
3cd489 |
@@ -207,7 +213,9 @@ ssh_dss_verify(const struct sshkey *key,
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
out:
|
|
Jakub Jelen |
aacf0d |
explicit_bzero(digest, sizeof(digest));
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(s);
|
|
Jakub Jelen |
3cd489 |
DSA_SIG_free(sig);
|
|
Jakub Jelen |
aacf0d |
sshbuf_free(b);
|
|
Jakub Jelen |
aacf0d |
free(ktype);
|
|
Jakub Jelen |
aacf0d |
if (sigblob != NULL) {
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh-ecdsa.c.openssl openssh/ssh-ecdsa.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh-ecdsa.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh-ecdsa.c 2017-09-26 13:19:31.801249721 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -54,6 +54,7 @@ ssh_ecdsa_sign(const struct sshkey *key,
|
|
Jakub Jelen |
aacf0d |
size_t len, dlen;
|
|
Jakub Jelen |
aacf0d |
struct sshbuf *b = NULL, *bb = NULL;
|
|
Jakub Jelen |
aacf0d |
int ret = SSH_ERR_INTERNAL_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *r, *s;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (lenp != NULL)
|
|
Jakub Jelen |
aacf0d |
*lenp = 0;
|
|
Jakub Jelen |
aacf0d |
@@ -80,8 +81,9 @@ ssh_ecdsa_sign(const struct sshkey *key,
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if ((ret = sshbuf_put_bignum2(bb, sig->r)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(bb, sig->s)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ ECDSA_SIG_get0(sig, &r, &s);
|
|
Jakub Jelen |
aacf0d |
+ if ((ret = sshbuf_put_bignum2(bb, r)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(bb, s)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
if ((ret = sshbuf_put_cstring(b, sshkey_ssh_name_plain(key))) != 0 ||
|
|
Jakub Jelen |
aacf0d |
(ret = sshbuf_put_stringb(b, bb)) != 0)
|
|
Jakub Jelen |
aacf0d |
@@ -119,6 +121,7 @@ ssh_ecdsa_verify(const struct sshkey *ke
|
|
Jakub Jelen |
aacf0d |
int ret = SSH_ERR_INTERNAL_ERROR;
|
|
Jakub Jelen |
aacf0d |
struct sshbuf *b = NULL, *sigbuf = NULL;
|
|
Jakub Jelen |
aacf0d |
char *ktype = NULL;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *r = NULL, *s = NULL;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
if (key == NULL || key->ecdsa == NULL ||
|
|
Jakub Jelen |
aacf0d |
sshkey_type_plain(key->type) != KEY_ECDSA ||
|
|
Jakub Jelen |
aacf0d |
@@ -147,15 +150,23 @@ ssh_ecdsa_verify(const struct sshkey *ke
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
/* parse signature */
|
|
Jakub Jelen |
aacf0d |
- if ((sig = ECDSA_SIG_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
+ if ((sig = ECDSA_SIG_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (r = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (s = BN_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if (sshbuf_get_bignum2(sigbuf, sig->r) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- sshbuf_get_bignum2(sigbuf, sig->s) != 0) {
|
|
Jakub Jelen |
aacf0d |
+ if (sshbuf_get_bignum2(sigbuf, r) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(sigbuf, s) != 0) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_INVALID_FORMAT;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
+ if (ECDSA_SIG_set0(sig, r, s) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ r = NULL;
|
|
Jakub Jelen |
aacf0d |
+ s = NULL;
|
|
Jakub Jelen |
aacf0d |
if (sshbuf_len(sigbuf) != 0) {
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_UNEXPECTED_TRAILING_DATA;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
3cd489 |
@@ -180,7 +191,9 @@ ssh_ecdsa_verify(const struct sshkey *ke
|
|
Jakub Jelen |
aacf0d |
explicit_bzero(digest, sizeof(digest));
|
|
Jakub Jelen |
aacf0d |
sshbuf_free(sigbuf);
|
|
Jakub Jelen |
aacf0d |
sshbuf_free(b);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(r);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(s);
|
|
Jakub Jelen |
3cd489 |
ECDSA_SIG_free(sig);
|
|
Jakub Jelen |
aacf0d |
free(ktype);
|
|
Jakub Jelen |
aacf0d |
return ret;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/sshkey.c.openssl openssh/sshkey.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/sshkey.c.openssl 2017-09-26 13:19:31.786249629 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/sshkey.c 2017-09-26 13:19:31.802249728 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -267,10 +267,10 @@ sshkey_size(const struct sshkey *k)
|
|
Jakub Jelen |
5b55d0 |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- return BN_num_bits(k->rsa->n);
|
|
Jakub Jelen |
aacf0d |
+ return RSA_bits(k->rsa);
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- return BN_num_bits(k->dsa->p);
|
|
Jakub Jelen |
aacf0d |
+ return DSA_bits(k->dsa);
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA_CERT:
|
|
Jakub Jelen |
aacf0d |
return sshkey_curve_nid_to_bits(k->ecdsa_nid);
|
|
Jakub Jelen |
5b55d0 |
@@ -302,11 +302,17 @@ sshkey_is_private(const struct sshkey *k
|
|
Jakub Jelen |
5b55d0 |
switch (k->type) {
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- return k->rsa->d != NULL;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *d;
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(k->rsa, NULL, NULL, &d);
|
|
Jakub Jelen |
aacf0d |
+ return d != NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- return k->dsa->priv_key != NULL;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *priv_key;
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(k->dsa, NULL, &priv_key);
|
|
Jakub Jelen |
aacf0d |
+ return priv_key != NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
#ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA_CERT:
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
3cd489 |
@@ -496,10 +501,7 @@ sshkey_new(int type)
|
|
Jakub Jelen |
5b55d0 |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((rsa = RSA_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (rsa->n = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (rsa->e = BN_new()) == NULL) {
|
|
Jakub Jelen |
3cd489 |
- RSA_free(rsa);
|
|
Jakub Jelen |
aacf0d |
+ if ((rsa = RSA_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
free(k);
|
|
Jakub Jelen |
aacf0d |
return NULL;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
3cd489 |
@@ -508,12 +509,7 @@ sshkey_new(int type)
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((dsa = DSA_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (dsa->p = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (dsa->q = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (dsa->g = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (dsa->pub_key = BN_new()) == NULL) {
|
|
Jakub Jelen |
3cd489 |
- DSA_free(dsa);
|
|
Jakub Jelen |
aacf0d |
+ if ((dsa = DSA_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
free(k);
|
|
Jakub Jelen |
aacf0d |
return NULL;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -553,21 +548,10 @@ sshkey_add_private(struct sshkey *k)
|
|
Jakub Jelen |
5b55d0 |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
-#define bn_maybe_alloc_failed(p) (p == NULL && (p = BN_new()) == NULL)
|
|
Jakub Jelen |
aacf0d |
- if (bn_maybe_alloc_failed(k->rsa->d) ||
|
|
Jakub Jelen |
aacf0d |
- bn_maybe_alloc_failed(k->rsa->iqmp) ||
|
|
Jakub Jelen |
aacf0d |
- bn_maybe_alloc_failed(k->rsa->q) ||
|
|
Jakub Jelen |
aacf0d |
- bn_maybe_alloc_failed(k->rsa->p) ||
|
|
Jakub Jelen |
aacf0d |
- bn_maybe_alloc_failed(k->rsa->dmq1) ||
|
|
Jakub Jelen |
aacf0d |
- bn_maybe_alloc_failed(k->rsa->dmp1))
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if (bn_maybe_alloc_failed(k->dsa->priv_key))
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
-#undef bn_maybe_alloc_failed
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA_CERT:
|
|
Jakub Jelen |
aacf0d |
/* Cannot do anything until we know the group */
|
|
Jakub Jelen |
5b55d0 |
@@ -684,17 +668,31 @@ sshkey_equal_public(const struct sshkey
|
|
Jakub Jelen |
5b55d0 |
switch (a->type) {
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- return a->rsa != NULL && b->rsa != NULL &&
|
|
Jakub Jelen |
aacf0d |
- BN_cmp(a->rsa->e, b->rsa->e) == 0 &&
|
|
Jakub Jelen |
aacf0d |
- BN_cmp(a->rsa->n, b->rsa->n) == 0;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *a_e, *a_n, *b_e, *b_n;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (a->rsa == NULL || b->rsa == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(a->rsa, &a_n, &a_e, NULL);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(b->rsa, &b_n, &b_e, NULL);
|
|
Jakub Jelen |
aacf0d |
+ return BN_cmp(a_e, b_e) == 0 && BN_cmp(a_n, b_n) == 0;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- return a->dsa != NULL && b->dsa != NULL &&
|
|
Jakub Jelen |
aacf0d |
- BN_cmp(a->dsa->p, b->dsa->p) == 0 &&
|
|
Jakub Jelen |
aacf0d |
- BN_cmp(a->dsa->q, b->dsa->q) == 0 &&
|
|
Jakub Jelen |
aacf0d |
- BN_cmp(a->dsa->g, b->dsa->g) == 0 &&
|
|
Jakub Jelen |
aacf0d |
- BN_cmp(a->dsa->pub_key, b->dsa->pub_key) == 0;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *a_p, *a_q, *a_g, *a_pub_key;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *b_p, *b_q, *b_g, *b_pub_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (a->dsa == NULL || b->dsa == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return 0;
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(a->dsa, &a_p, &a_q, &a_g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(a->dsa, &a_pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(b->dsa, &b_p, &b_q, &b_g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(b->dsa, &b_pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+ return BN_cmp(a_p, b_p) == 0 &&
|
|
Jakub Jelen |
aacf0d |
+ BN_cmp(a_q, b_q) == 0 &&
|
|
Jakub Jelen |
aacf0d |
+ BN_cmp(a_g, b_g) == 0 &&
|
|
Jakub Jelen |
aacf0d |
+ BN_cmp(a_pub_key, b_pub_key) == 0;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
# ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA_CERT:
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
5b55d0 |
@@ -769,15 +767,21 @@ to_blob_buf(const struct sshkey *key, st
|
|
Jakub Jelen |
aacf0d |
return ret;
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- if (key->dsa == NULL)
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
- if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(b, key->dsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(b, key->dsa->q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(b, key->dsa->g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(b, key->dsa->pub_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- return ret;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *q, *g, *pub_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (key->dsa == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(key->dsa, &p, &q, &g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(key->dsa, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(b, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(b, q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(b, g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(b, pub_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ return ret;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
5b55d0 |
@@ -790,13 +794,18 @@ to_blob_buf(const struct sshkey *key, st
|
|
Jakub Jelen |
aacf0d |
return ret;
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# endif
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- if (key->rsa == NULL)
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
- if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(b, key->rsa->e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(b, key->rsa->n)) != 0)
|
|
Jakub Jelen |
aacf0d |
- return ret;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *e, *n;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (key->rsa == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(key->rsa, &n, &e, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if ((ret = sshbuf_put_cstring(b, typename)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(b, e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(b, n)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ return ret;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
#endif /* WITH_OPENSSL */
|
|
Jakub Jelen |
aacf0d |
case KEY_ED25519:
|
|
Jakub Jelen |
5b55d0 |
@@ -1672,15 +1681,32 @@ sshkey_from_private(const struct sshkey
|
|
Jakub Jelen |
aacf0d |
switch (k->type) {
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((n = sshkey_new(k->type)) == NULL)
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
- if ((BN_copy(n->dsa->p, k->dsa->p) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
- (BN_copy(n->dsa->q, k->dsa->q) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
- (BN_copy(n->dsa->g, k->dsa->g) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
- (BN_copy(n->dsa->pub_key, k->dsa->pub_key) == NULL)) {
|
|
Jakub Jelen |
aacf0d |
- sshkey_free(n);
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA_CERT: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *k_p, *k_q, *k_g, *k_pub_key;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *n_p = NULL, *n_q = NULL, *n_g = NULL, *n_pub_key = NULL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if ((n = sshkey_new(k->type)) == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(k->dsa, &k_p, &k_q, &k_g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(k->dsa, &k_pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (((n_p = BN_dup(k_p)) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ ((n_q = BN_dup(k_q)) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ ((n_g = BN_dup(k_g)) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ (DSA_set0_pqg(n->dsa, n_p, n_q, n_g) == 0)) {
|
|
Jakub Jelen |
aacf0d |
+ sshkey_free(n);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n_p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n_q);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n_g);
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (((n_pub_key = BN_dup(k_pub_key)) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ (DSA_set0_key(n->dsa, n_pub_key, NULL) == 0)) {
|
|
Jakub Jelen |
aacf0d |
+ sshkey_free(n);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n_pub_key);
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
5b55d0 |
@@ -1702,13 +1728,22 @@ sshkey_from_private(const struct sshkey
|
|
Jakub Jelen |
5b55d0 |
break;
|
|
Jakub Jelen |
aacf0d |
# endif /* OPENSSL_HAS_ECC */
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((n = sshkey_new(k->type)) == NULL)
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
- if ((BN_copy(n->rsa->n, k->rsa->n) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
- (BN_copy(n->rsa->e, k->rsa->e) == NULL)) {
|
|
Jakub Jelen |
aacf0d |
- sshkey_free(n);
|
|
Jakub Jelen |
aacf0d |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA_CERT: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *k_n, *k_e;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *n_n = NULL, *n_e = NULL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if ((n = sshkey_new(k->type)) == NULL)
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(k->rsa, &k_n, &k_e, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if (((n_n = BN_dup(k_n)) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ ((n_e = BN_dup(k_e)) == NULL) ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_set0_key(n->rsa, n_n, n_e, NULL) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ sshkey_free(n);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n_n);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n_e);
|
|
Jakub Jelen |
aacf0d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
#endif /* WITH_OPENSSL */
|
|
Jakub Jelen |
5b55d0 |
@@ -1907,12 +1942,22 @@ sshkey_from_blob_internal(struct sshbuf
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if (sshbuf_get_bignum2(b, key->rsa->e) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- sshbuf_get_bignum2(b, key->rsa->n) != 0) {
|
|
Jakub Jelen |
aacf0d |
- ret = SSH_ERR_INVALID_FORMAT;
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *e, *n;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ e = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ n = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ if (e == NULL || n == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(b, e) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(b, n) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_set0_key(key->rsa, n, e, NULL) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(e);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n);
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
- if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
5b55d0 |
+ if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
5b55d0 |
ret = SSH_ERR_KEY_LENGTH;
|
|
Jakub Jelen |
5b55d0 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -1932,12 +1977,34 @@ sshkey_from_blob_internal(struct sshbuf
|
|
Jakub Jelen |
aacf0d |
ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if (sshbuf_get_bignum2(b, key->dsa->p) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- sshbuf_get_bignum2(b, key->dsa->q) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- sshbuf_get_bignum2(b, key->dsa->g) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- sshbuf_get_bignum2(b, key->dsa->pub_key) != 0) {
|
|
Jakub Jelen |
aacf0d |
- ret = SSH_ERR_INVALID_FORMAT;
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *p, *q, *g, *pub_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ p = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ q = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ g = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ pub_key = BN_new();
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (p == NULL || q == NULL || g == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ pub_key == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(b, p) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(b, q) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(b, g) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_get_bignum2(b, pub_key) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ DSA_set0_pqg(key->dsa, p, q, g) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(q);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(g);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pub_key);
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (DSA_set0_key(key->dsa, pub_key, NULL) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pub_key);
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
#ifdef DEBUG_PK
|
|
Jakub Jelen |
aacf0d |
DSA_print_fp(stderr, key->dsa, 8);
|
|
Jakub Jelen |
5b55d0 |
@@ -2171,26 +2238,53 @@ sshkey_demote(const struct sshkey *k, st
|
|
Jakub Jelen |
5b55d0 |
if ((ret = sshkey_cert_copy(k, pk)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto fail;
|
|
Jakub Jelen |
aacf0d |
/* FALLTHROUGH */
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- if ((pk->rsa = RSA_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pk->rsa->e = BN_dup(k->rsa->e)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pk->rsa->n = BN_dup(k->rsa->n)) == NULL) {
|
|
Jakub Jelen |
aacf0d |
- ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
- goto fail;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *k_e, *k_n;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *pk_e = NULL, *pk_n = NULL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(k->rsa, &k_n, &k_e, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if ((pk->rsa = RSA_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pk_e = BN_dup(k_e)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pk_n = BN_dup(k_n)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_set0_key(pk->rsa, pk_n, pk_e, NULL) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_e);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_n);
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ goto fail;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
if ((ret = sshkey_cert_copy(k, pk)) != 0)
|
|
Jakub Jelen |
aacf0d |
goto fail;
|
|
Jakub Jelen |
aacf0d |
/* FALLTHROUGH */
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- if ((pk->dsa = DSA_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pk->dsa->p = BN_dup(k->dsa->p)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pk->dsa->q = BN_dup(k->dsa->q)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pk->dsa->g = BN_dup(k->dsa->g)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
- (pk->dsa->pub_key = BN_dup(k->dsa->pub_key)) == NULL) {
|
|
Jakub Jelen |
aacf0d |
- ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
- goto fail;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *k_p, *k_q, *k_g, *k_pub_key;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *pk_p = NULL, *pk_q = NULL, *pk_g = NULL;
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *pk_pub_key = NULL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(k->dsa, &k_p, &k_q, &k_g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(k->dsa, &k_pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if ((pk->dsa = DSA_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pk_p = BN_dup(k_p)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pk_q = BN_dup(k_q)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pk_g = BN_dup(k_g)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pk_pub_key = BN_dup(k_pub_key)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ DSA_set0_pqg(pk->dsa, pk_p, pk_q, pk_g) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_q);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_g);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_pub_key);
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
+ goto fail;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (DSA_set0_key(pk->dsa, pk_pub_key, NULL) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pk_pub_key);
|
|
Jakub Jelen |
aacf0d |
+ ret = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ goto fail;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA_CERT:
|
|
Jakub Jelen |
5b55d0 |
@@ -2312,12 +2406,17 @@ sshkey_certify_custom(struct sshkey *k,
|
|
Jakub Jelen |
aacf0d |
/* XXX this substantially duplicates to_blob(); refactor */
|
|
Jakub Jelen |
aacf0d |
switch (k->type) {
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((ret = sshbuf_put_bignum2(cert, k->dsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(cert, k->dsa->q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(cert, k->dsa->g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(cert, k->dsa->pub_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA_CERT: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *q, *g, *pub_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(k->dsa, &p, &q, &g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(k->dsa, &pub_key, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if ((ret = sshbuf_put_bignum2(cert, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(cert, q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(cert, g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(cert, pub_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA_CERT:
|
|
Jakub Jelen |
5b55d0 |
@@ -2329,10 +2428,15 @@ sshkey_certify_custom(struct sshkey *k,
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# endif /* OPENSSL_HAS_ECC */
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((ret = sshbuf_put_bignum2(cert, k->rsa->e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (ret = sshbuf_put_bignum2(cert, k->rsa->n)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA_CERT: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *e, *n;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(k->rsa, &n, &e, NULL);
|
|
Jakub Jelen |
aacf0d |
+ if (e == NULL || n == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(cert, e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (ret = sshbuf_put_bignum2(cert, n)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
#endif /* WITH_OPENSSL */
|
|
Jakub Jelen |
aacf0d |
case KEY_ED25519_CERT:
|
|
Jakub Jelen |
5b55d0 |
@@ -2505,43 +2609,65 @@ sshkey_private_serialize(const struct ss
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
switch (key->type) {
|
|
Jakub Jelen |
aacf0d |
#ifdef WITH_OPENSSL
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_put_bignum2(b, key->rsa->n)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->q)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *n, *e, *d, *iqmp, *p, *q;
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(key->rsa, &n, &e, &d);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_crt_params(key->rsa, NULL, NULL, &iqmp);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_factors(key->rsa, &p, &q);
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshbuf_put_bignum2(b, n)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, q)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
if (key->cert == NULL || sshbuf_len(key->cert->certblob) == 0) {
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->rsa->q)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *d, *iqmp, *p, *q;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_key(key->rsa, NULL, NULL, &d);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_factors(key->rsa, &p, &q);
|
|
Jakub Jelen |
aacf0d |
+ RSA_get0_crt_params(key->rsa, NULL, NULL, &iqmp);
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, q)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_put_bignum2(b, key->dsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->dsa->q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->dsa->g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->dsa->pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->dsa->priv_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA: {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *p, *q, *g, *pub_key, *priv_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_pqg(key->dsa, &p, &q, &g);
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(key->dsa, &pub_key, &priv_key);
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshbuf_put_bignum2(b, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, priv_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
if (key->cert == NULL || sshbuf_len(key->cert->certblob) == 0) {
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_put_bignum2(b, key->dsa->priv_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ {
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *priv_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ DSA_get0_key(key->dsa, NULL, &priv_key);
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshbuf_put_stringb(b, key->cert->certblob)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_put_bignum2(b, priv_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
5b55d0 |
@@ -2617,18 +2743,51 @@ sshkey_private_deserialize(struct sshbuf
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_get_bignum2(buf, k->dsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->dsa->q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->dsa->g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->dsa->pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->dsa->priv_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *p, *q, *g, *pub_key, *priv_key;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ p = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ q = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ g = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ pub_key = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ priv_key = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ if (p == NULL || q == NULL || g == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ pub_key == NULL || priv_key == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, g)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, pub_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, priv_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = ((DSA_set0_pqg(k->dsa, p, q, g) == 0)
|
|
Jakub Jelen |
aacf0d |
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(q);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(g);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pub_key);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(priv_key);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (DSA_set0_key(k->dsa, pub_key, priv_key) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ BN_free(pub_key);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(priv_key);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshkey_froms(buf, &k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshkey_add_private(k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->dsa->priv_key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA_CERT: {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *priv_key = BN_new();
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (priv_key == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshkey_froms(buf, &k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshkey_add_private(k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, priv_key)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = ((DSA_set0_key(k->dsa, NULL, priv_key) == 0)
|
|
Jakub Jelen |
aacf0d |
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(priv_key);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
# ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
case KEY_ECDSA:
|
|
Jakub Jelen |
5b55d0 |
@@ -2687,29 +2846,89 @@ sshkey_private_deserialize(struct sshbuf
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_get_bignum2(buf, k->rsa->n)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->q)) != 0 ||
|
|
Jakub Jelen |
5b55d0 |
- (r = ssh_rsa_generate_additional_parameters(k)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
5b55d0 |
- if (BN_num_bits(k->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
aacf0d |
+ {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *n, *e, *d, *iqmp, *p, *q;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ n = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ e = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ d = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ iqmp = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ p = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ q = BN_new();
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if (n == NULL || e == NULL || d == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ iqmp == NULL || p == NULL || q == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, n)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, e)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, q)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = ((RSA_set0_key(k->rsa, n, e, d) == 0)
|
|
Jakub Jelen |
aacf0d |
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(n);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(e);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(d);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(iqmp);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(q);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (RSA_set0_factors(k->rsa, p, q) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
+ BN_free(iqmp);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(p);
|
|
Jakub Jelen |
aacf0d |
+ BN_free(q);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
5b55d0 |
+ if ((r = ssh_rsa_generate_additional_parameters(k, iqmp)) != 0) {
|
|
Jakub Jelen |
aacf0d |
+ BN_free(iqmp);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
5b55d0 |
+ if (RSA_bits(k->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
5b55d0 |
r = SSH_ERR_KEY_LENGTH;
|
|
Jakub Jelen |
5b55d0 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA_CERT:
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshkey_froms(buf, &k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshkey_add_private(k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (r = sshbuf_get_bignum2(buf, k->rsa->q)) != 0 ||
|
|
Jakub Jelen |
5b55d0 |
- (r = ssh_rsa_generate_additional_parameters(k)) != 0)
|
|
Jakub Jelen |
aacf0d |
- goto out;
|
|
Jakub Jelen |
5b55d0 |
- if (BN_num_bits(k->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA_CERT: {
|
|
Jakub Jelen |
4a6ef4 |
+ BIGNUM *d, *iqmp, *p, *q;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
4a6ef4 |
+ /* N and E are already set so make sure we will not overwrite them */
|
|
Jakub Jelen |
aacf0d |
+ d = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ iqmp = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ p = BN_new();
|
|
Jakub Jelen |
aacf0d |
+ q = BN_new();
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
4a6ef4 |
+ if (d == NULL || iqmp == NULL || p == NULL ||
|
|
Jakub Jelen |
4a6ef4 |
+ q == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshkey_froms(buf, &k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshkey_add_private(k)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, d)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, iqmp)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, p)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (r = sshbuf_get_bignum2(buf, q)) != 0 ||
|
|
Jakub Jelen |
4a6ef4 |
+ (r = ((RSA_set0_key(k->rsa, NULL, NULL, d) == 0)
|
|
Jakub Jelen |
f07a08 |
+ ? SSH_ERR_LIBCRYPTO_ERROR : 0)) != 0) {
|
|
Jakub Jelen |
f07a08 |
+ BN_free(d);
|
|
Jakub Jelen |
f07a08 |
+ BN_free(iqmp);
|
|
Jakub Jelen |
f07a08 |
+ BN_free(p);
|
|
Jakub Jelen |
f07a08 |
+ BN_free(q);
|
|
Jakub Jelen |
f07a08 |
+ goto out;
|
|
Jakub Jelen |
f07a08 |
+ }
|
|
Jakub Jelen |
f07a08 |
+ if (RSA_set0_factors(k->rsa, p, q) == 0) {
|
|
Jakub Jelen |
f07a08 |
+ r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
f07a08 |
+ BN_free(p);
|
|
Jakub Jelen |
f07a08 |
+ BN_free(q);
|
|
Jakub Jelen |
aacf0d |
+ goto out;
|
|
Jakub Jelen |
f07a08 |
+ }
|
|
Jakub Jelen |
5b55d0 |
+ if (ssh_rsa_generate_additional_parameters(k, iqmp) != 0) {
|
|
Jakub Jelen |
f07a08 |
+ r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
f07a08 |
+ free(iqmp);
|
|
Jakub Jelen |
f07a08 |
+ goto out;
|
|
Jakub Jelen |
f07a08 |
+ }
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
5b55d0 |
+ if (RSA_bits(k->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
5b55d0 |
r = SSH_ERR_KEY_LENGTH;
|
|
Jakub Jelen |
5b55d0 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -3427,7 +3646,9 @@ translate_libcrypto_error(unsigned long
|
|
Jakub Jelen |
5b55d0 |
switch (pem_reason) {
|
|
Jakub Jelen |
5b55d0 |
case EVP_R_BAD_DECRYPT:
|
|
Jakub Jelen |
5b55d0 |
return SSH_ERR_KEY_WRONG_PASSPHRASE;
|
|
Jakub Jelen |
f07a08 |
+#ifdef EVP_R_BN_DECODE_ERROR
|
|
Jakub Jelen |
5b55d0 |
case EVP_R_BN_DECODE_ERROR:
|
|
Jakub Jelen |
f07a08 |
+#endif
|
|
Jakub Jelen |
5b55d0 |
case EVP_R_DECODE_ERROR:
|
|
Jakub Jelen |
f07a08 |
#ifdef EVP_R_PRIVATE_KEY_DECODE_ERROR
|
|
Jakub Jelen |
5b55d0 |
case EVP_R_PRIVATE_KEY_DECODE_ERROR:
|
|
Jakub Jelen |
5b55d0 |
@@ -3492,7 +3713,7 @@ sshkey_parse_private_pem_fileblob(struct
|
|
Jakub Jelen |
5b55d0 |
r = convert_libcrypto_error();
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if (pk->type == EVP_PKEY_RSA &&
|
|
Jakub Jelen |
aacf0d |
+ if (EVP_PKEY_id(pk) == EVP_PKEY_RSA &&
|
|
Jakub Jelen |
aacf0d |
(type == KEY_UNSPEC || type == KEY_RSA)) {
|
|
Jakub Jelen |
aacf0d |
if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
5b55d0 |
@@ -3507,11 +3728,11 @@ sshkey_parse_private_pem_fileblob(struct
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
aacf0d |
goto out;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
5b55d0 |
- if (BN_num_bits(prv->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
5b55d0 |
+ if (RSA_bits(prv->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE) {
|
|
Jakub Jelen |
5b55d0 |
r = SSH_ERR_KEY_LENGTH;
|
|
Jakub Jelen |
5b55d0 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
aacf0d |
- } else if (pk->type == EVP_PKEY_DSA &&
|
|
Jakub Jelen |
aacf0d |
+ } else if (EVP_PKEY_id(pk) == EVP_PKEY_DSA &&
|
|
Jakub Jelen |
aacf0d |
(type == KEY_UNSPEC || type == KEY_DSA)) {
|
|
Jakub Jelen |
aacf0d |
if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
5b55d0 |
@@ -3523,7 +3744,7 @@ sshkey_parse_private_pem_fileblob(struct
|
|
Jakub Jelen |
aacf0d |
DSA_print_fp(stderr, prv->dsa, 8);
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
#ifdef OPENSSL_HAS_ECC
|
|
Jakub Jelen |
aacf0d |
- } else if (pk->type == EVP_PKEY_EC &&
|
|
Jakub Jelen |
aacf0d |
+ } else if (EVP_PKEY_id(pk) == EVP_PKEY_EC &&
|
|
Jakub Jelen |
aacf0d |
(type == KEY_UNSPEC || type == KEY_ECDSA)) {
|
|
Jakub Jelen |
aacf0d |
if ((prv = sshkey_new(KEY_UNSPEC)) == NULL) {
|
|
Jakub Jelen |
aacf0d |
r = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh-keygen.c.openssl openssh/ssh-keygen.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh-keygen.c.openssl 2017-09-26 13:19:31.787249636 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh-keygen.c 2017-09-26 13:19:31.802249728 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -501,40 +501,67 @@ do_convert_private_ssh2_from_blob(u_char
|
|
Jakub Jelen |
aacf0d |
free(type);
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
switch (key->type) {
|
|
Jakub Jelen |
aacf0d |
- case KEY_DSA:
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->dsa->p);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->dsa->g);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->dsa->q);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->dsa->pub_key);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->dsa->priv_key);
|
|
Jakub Jelen |
aacf0d |
+ case KEY_DSA: {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *p = NULL, *g = NULL, *q = NULL, *pub_key = NULL, *priv_key = NULL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if ((p = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (g = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (q = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (pub_key = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (priv_key = BN_new()) == NULL)
|
|
Jakub Jelen |
aacf0d |
+ fatal("BN_new() failed");
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, p);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, g);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, q);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, pub_key);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, priv_key);
|
|
Jakub Jelen |
aacf0d |
+ if (DSA_set0_pqg(key->dsa, p, q, g) == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ DSA_set0_key(key->dsa, pub_key, priv_key) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ fatal("failed to set DSA key");
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
- case KEY_RSA:
|
|
Jakub Jelen |
aacf0d |
- if ((r = sshbuf_get_u8(b, &e1)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
- (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) ||
|
|
Jakub Jelen |
aacf0d |
- (e1 < 30 && (r = sshbuf_get_u8(b, &e3)) != 0))
|
|
Jakub Jelen |
aacf0d |
- fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
Jakub Jelen |
aacf0d |
- e = e1;
|
|
Jakub Jelen |
aacf0d |
- debug("e %lx", e);
|
|
Jakub Jelen |
aacf0d |
- if (e < 30) {
|
|
Jakub Jelen |
aacf0d |
- e <<= 8;
|
|
Jakub Jelen |
aacf0d |
- e += e2;
|
|
Jakub Jelen |
aacf0d |
- debug("e %lx", e);
|
|
Jakub Jelen |
aacf0d |
- e <<= 8;
|
|
Jakub Jelen |
aacf0d |
- e += e3;
|
|
Jakub Jelen |
aacf0d |
+ case KEY_RSA: {
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *bn_e = NULL, *bn_d = NULL, *bn_n = NULL, *bn_iqmp = NULL, *bn_p = NULL, *bn_q = NULL;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if ((bn_e = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (bn_d = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (bn_n = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (bn_iqmp = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (bn_p = BN_new()) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ (bn_q = BN_new()) == NULL)
|
|
Jakub Jelen |
aacf0d |
+ fatal("BN_new() failed");
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ if ((r = sshbuf_get_u8(b, &e1)) != 0 ||
|
|
Jakub Jelen |
aacf0d |
+ (e1 < 30 && (r = sshbuf_get_u8(b, &e2)) != 0) ||
|
|
Jakub Jelen |
aacf0d |
+ (e1 < 30 && (r = sshbuf_get_u8(b, &e3)) != 0))
|
|
Jakub Jelen |
aacf0d |
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
Jakub Jelen |
aacf0d |
+ e = e1;
|
|
Jakub Jelen |
aacf0d |
debug("e %lx", e);
|
|
Jakub Jelen |
aacf0d |
+ if (e < 30) {
|
|
Jakub Jelen |
aacf0d |
+ e <<= 8;
|
|
Jakub Jelen |
aacf0d |
+ e += e2;
|
|
Jakub Jelen |
aacf0d |
+ debug("e %lx", e);
|
|
Jakub Jelen |
aacf0d |
+ e <<= 8;
|
|
Jakub Jelen |
aacf0d |
+ e += e3;
|
|
Jakub Jelen |
aacf0d |
+ debug("e %lx", e);
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ if (!BN_set_word(bn_e, e)) {
|
|
Jakub Jelen |
aacf0d |
+ sshbuf_free(b);
|
|
Jakub Jelen |
aacf0d |
+ sshkey_free(key);
|
|
Jakub Jelen |
aacf0d |
+ return NULL;
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, bn_d);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, bn_n);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, bn_iqmp);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, bn_q);
|
|
Jakub Jelen |
aacf0d |
+ buffer_get_bignum_bits(b, bn_p);
|
|
Jakub Jelen |
aacf0d |
+ if (RSA_set0_key(key->rsa, bn_n, bn_e, bn_d) == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_set0_factors(key->rsa, bn_p, bn_q) == 0)
|
|
Jakub Jelen |
aacf0d |
+ fatal("Failed to set RSA parameters");
|
|
Jakub Jelen |
5b55d0 |
+ if ((r = ssh_rsa_generate_additional_parameters(key, bn_iqmp)) != 0)
|
|
Jakub Jelen |
aacf0d |
+ fatal("generate RSA parameters failed: %s", ssh_err(r));
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- if (!BN_set_word(key->rsa->e, e)) {
|
|
Jakub Jelen |
aacf0d |
- sshbuf_free(b);
|
|
Jakub Jelen |
aacf0d |
- sshkey_free(key);
|
|
Jakub Jelen |
aacf0d |
- return NULL;
|
|
Jakub Jelen |
aacf0d |
- }
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->rsa->d);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->rsa->n);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->rsa->iqmp);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->rsa->q);
|
|
Jakub Jelen |
aacf0d |
- buffer_get_bignum_bits(b, key->rsa->p);
|
|
Jakub Jelen |
5b55d0 |
- if ((r = ssh_rsa_generate_additional_parameters(key)) != 0)
|
|
Jakub Jelen |
aacf0d |
- fatal("generate RSA parameters failed: %s", ssh_err(r));
|
|
Jakub Jelen |
aacf0d |
break;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
rlen = sshbuf_len(b);
|
|
Jakub Jelen |
5b55d0 |
@@ -642,7 +669,7 @@ do_convert_from_pkcs8(struct sshkey **k,
|
|
Jakub Jelen |
aacf0d |
identity_file);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
fclose(fp);
|
|
Jakub Jelen |
aacf0d |
- switch (EVP_PKEY_type(pubkey->type)) {
|
|
Jakub Jelen |
aacf0d |
+ switch (EVP_PKEY_base_id(pubkey)) {
|
|
Jakub Jelen |
aacf0d |
case EVP_PKEY_RSA:
|
|
Jakub Jelen |
aacf0d |
if ((*k = sshkey_new(KEY_UNSPEC)) == NULL)
|
|
Jakub Jelen |
aacf0d |
fatal("sshkey_new failed");
|
|
Jakub Jelen |
5b55d0 |
@@ -666,7 +693,7 @@ do_convert_from_pkcs8(struct sshkey **k,
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
default:
|
|
Jakub Jelen |
aacf0d |
fatal("%s: unsupported pubkey type %d", __func__,
|
|
Jakub Jelen |
aacf0d |
- EVP_PKEY_type(pubkey->type));
|
|
Jakub Jelen |
aacf0d |
+ EVP_PKEY_base_id(pubkey));
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
EVP_PKEY_free(pubkey);
|
|
Jakub Jelen |
aacf0d |
return;
|
|
Jakub Jelen |
5b55d0 |
@@ -1798,6 +1825,7 @@ do_ca_sign(struct passwd *pw, int argc,
|
|
Jakub Jelen |
aacf0d |
#ifdef ENABLE_PKCS11
|
|
Jakub Jelen |
aacf0d |
pkcs11_terminate();
|
|
Jakub Jelen |
aacf0d |
#endif
|
|
Jakub Jelen |
aacf0d |
+ free(ca);
|
|
Jakub Jelen |
aacf0d |
exit(0);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/sshkey.h.openssl openssh/sshkey.h
|
|
Jakub Jelen |
5b55d0 |
--- openssh/sshkey.h.openssl 2017-09-26 13:19:31.780249593 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/sshkey.h 2017-09-26 13:19:31.803249734 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -199,7 +199,7 @@ int sshkey_parse_private_fileblob_type(s
|
|
Jakub Jelen |
5b55d0 |
const char *passphrase, struct sshkey **keyp, char **commentp);
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
5b55d0 |
/* XXX should be internal, but used by ssh-keygen */
|
|
Jakub Jelen |
5b55d0 |
-int ssh_rsa_generate_additional_parameters(struct sshkey *);
|
|
Jakub Jelen |
5b55d0 |
+int ssh_rsa_generate_additional_parameters(struct sshkey *, BIGNUM *iqmp);
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
3cd489 |
/* stateful keys (e.g. XMSS) */
|
|
Jakub Jelen |
3cd489 |
#ifdef NO_ATTRIBUTE_ON_PROTOTYPE_ARGS
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh-pkcs11-client.c.openssl openssh/ssh-pkcs11-client.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh-pkcs11-client.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh-pkcs11-client.c 2017-09-26 13:19:31.803249734 +0200
|
|
Jakub Jelen |
e0e7ed |
@@ -143,12 +143,16 @@ pkcs11_rsa_private_encrypt(int flen, con
|
|
Jakub Jelen |
aacf0d |
static int
|
|
Jakub Jelen |
7e9748 |
wrap_rsa_key(RSA *rsa)
|
|
Jakub Jelen |
aacf0d |
{
|
|
Jakub Jelen |
aacf0d |
- static RSA_METHOD helper_rsa;
|
|
Jakub Jelen |
aacf0d |
+ static RSA_METHOD *helper_rsa;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
- memcpy(&helper_rsa, RSA_get_default_method(), sizeof(helper_rsa));
|
|
Jakub Jelen |
aacf0d |
- helper_rsa.name = "ssh-pkcs11-helper";
|
|
Jakub Jelen |
aacf0d |
- helper_rsa.rsa_priv_enc = pkcs11_rsa_private_encrypt;
|
|
Jakub Jelen |
aacf0d |
- RSA_set_method(rsa, &helper_rsa);
|
|
Jakub Jelen |
aacf0d |
+ if (helper_rsa == NULL) {
|
|
Jakub Jelen |
aacf0d |
+ helper_rsa = RSA_meth_dup(RSA_get_default_method());
|
|
Jakub Jelen |
e0e7ed |
+ if (helper_rsa == NULL)
|
|
Jakub Jelen |
e0e7ed |
+ error("RSA_meth_dup failed");
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_set1_name(helper_rsa, "ssh-pkcs11-helper");
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_set_priv_enc(helper_rsa, pkcs11_rsa_private_encrypt);
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+ RSA_set_method(rsa, helper_rsa);
|
|
Jakub Jelen |
aacf0d |
return (0);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh-pkcs11.c.openssl openssh/ssh-pkcs11.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh-pkcs11.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh-pkcs11.c 2017-09-26 13:19:31.803249734 +0200
|
|
Jakub Jelen |
aacf0d |
@@ -67,7 +67,7 @@ struct pkcs11_key {
|
|
Jakub Jelen |
aacf0d |
CK_ULONG slotidx;
|
|
Jakub Jelen |
7e9748 |
CK_ULONG key_type;
|
|
Jakub Jelen |
aacf0d |
int (*orig_finish)(RSA *rsa);
|
|
Jakub Jelen |
aacf0d |
- RSA_METHOD rsa_method;
|
|
Jakub Jelen |
aacf0d |
+ RSA_METHOD *rsa_method;
|
|
Jakub Jelen |
7e9748 |
char *label;
|
|
Jakub Jelen |
aacf0d |
char *keyid;
|
|
Jakub Jelen |
aacf0d |
int keyid_len;
|
|
Jakub Jelen |
e0e7ed |
@@ -183,6 +183,7 @@ pkcs11_rsa_finish(RSA *rsa)
|
|
Jakub Jelen |
e0e7ed |
pkcs11_provider_unref(k11->provider);
|
|
Jakub Jelen |
e0e7ed |
free(k11->keyid);
|
|
Jakub Jelen |
7e9748 |
free(k11->label);
|
|
Jakub Jelen |
e0e7ed |
+ RSA_meth_free(k11->rsa_method);
|
|
Jakub Jelen |
e0e7ed |
free(k11);
|
|
Jakub Jelen |
e0e7ed |
}
|
|
Jakub Jelen |
e0e7ed |
return (rv);
|
|
Jakub Jelen |
aacf0d |
@@ -326,13 +326,21 @@ pkcs11_rsa_wrap(struct pkcs11_provider *
|
|
Jakub Jelen |
7e9748 |
memcpy(k11->label, label_attrib->pValue, label_attrib->ulValueLen);
|
|
Jakub Jelen |
7e9748 |
k11->label[label_attrib->ulValueLen] = 0;
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
- k11->orig_finish = def->finish;
|
|
Jakub Jelen |
aacf0d |
- memcpy(&k11->rsa_method, def, sizeof(k11->rsa_method));
|
|
Jakub Jelen |
aacf0d |
- k11->rsa_method.name = "pkcs11";
|
|
Jakub Jelen |
aacf0d |
- k11->rsa_method.rsa_priv_enc = pkcs11_rsa_private_encrypt;
|
|
Jakub Jelen |
aacf0d |
- k11->rsa_method.rsa_priv_dec = pkcs11_rsa_private_decrypt;
|
|
Jakub Jelen |
aacf0d |
- k11->rsa_method.finish = pkcs11_rsa_finish;
|
|
Jakub Jelen |
aacf0d |
- RSA_set_method(rsa, &k11->rsa_method);
|
|
Jakub Jelen |
aacf0d |
+ k11->orig_finish = RSA_meth_get_finish(def);
|
|
Jakub Jelen |
aacf0d |
+ if ((k11->rsa_method = RSA_meth_dup(def)) == NULL ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_set1_name(k11->rsa_method, "pkcs11") == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_set_priv_enc(k11->rsa_method, pkcs11_rsa_private_encrypt) == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_set_priv_dec(k11->rsa_method, pkcs11_rsa_private_decrypt) == 0 ||
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_set_finish(k11->rsa_method, pkcs11_rsa_finish) == 0) {
|
|
Jakub Jelen |
aacf0d |
+ RSA_meth_free(k11->rsa_method);
|
|
Jakub Jelen |
aacf0d |
+ k11->rsa_method = NULL;
|
|
Jakub Jelen |
aacf0d |
+ pkcs11_provider_unref(k11->provider);
|
|
Jakub Jelen |
aacf0d |
+ free(k11->keyid);
|
|
Jakub Jelen |
aacf0d |
+ free(k11);
|
|
Jakub Jelen |
aacf0d |
+ return (-1);
|
|
Jakub Jelen |
aacf0d |
+ }
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
aacf0d |
+ RSA_set_method(rsa, k11->rsa_method);
|
|
Jakub Jelen |
aacf0d |
RSA_set_app_data(rsa, k11);
|
|
Jakub Jelen |
aacf0d |
return (0);
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
aacf0d |
@@ -460,6 +468,7 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
|
|
Jakub Jelen |
aacf0d |
CK_ULONG nfound;
|
|
Jakub Jelen |
aacf0d |
CK_SESSION_HANDLE session;
|
|
Jakub Jelen |
aacf0d |
CK_FUNCTION_LIST *f;
|
|
Jakub Jelen |
aacf0d |
+ const BIGNUM *n, *e;
|
|
Jakub Jelen |
aacf0d |
|
|
Jakub Jelen |
aacf0d |
f = p->function_list;
|
|
Jakub Jelen |
aacf0d |
session = p->slotinfo[slotidx].session;
|
|
Jakub Jelen |
e0e7ed |
@@ -512,10 +521,16 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
|
|
Jakub Jelen |
aacf0d |
if ((rsa = RSA_new()) == NULL) {
|
|
Jakub Jelen |
aacf0d |
error("RSA_new failed");
|
|
Jakub Jelen |
aacf0d |
} else {
|
|
Jakub Jelen |
7e9748 |
- rsa->n = BN_bin2bn(attribs[2].pValue,
|
|
Jakub Jelen |
aacf0d |
+ BIGNUM *rsa_n, *rsa_e;
|
|
Jakub Jelen |
aacf0d |
+
|
|
Jakub Jelen |
7e9748 |
+ rsa_n = BN_bin2bn(attribs[2].pValue,
|
|
Jakub Jelen |
aacf0d |
attribs[2].ulValueLen, NULL);
|
|
Jakub Jelen |
7e9748 |
- rsa->e = BN_bin2bn(attribs[3].pValue,
|
|
Jakub Jelen |
7e9748 |
+ rsa_e = BN_bin2bn(attribs[3].pValue,
|
|
Jakub Jelen |
7e9748 |
attribs[3].ulValueLen, NULL);
|
|
Jakub Jelen |
e0e7ed |
+ if (rsa_n == NULL || rsa_e == NULL)
|
|
Jakub Jelen |
e0e7ed |
+ error("BN_bin2bn failed");
|
|
Jakub Jelen |
aacf0d |
+ if (RSA_set0_key(rsa, rsa_n, rsa_e, NULL) == 0)
|
|
Jakub Jelen |
aacf0d |
+ error("RSA_set0_key failed");
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
077597 |
#ifdef ENABLE_PKCS11_ECDSA
|
|
Jakub Jelen |
077597 |
} else if (attribs[2].type == CKA_EC_PARAMS ) {
|
|
Jakub Jelen |
077597 |
@@ -920,19 +936,19 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
|
|
Jakub Jelen |
077597 |
} else if ((evp = X509_get_pubkey(x509)) == NULL) {
|
|
Jakub Jelen |
077597 |
debug("X509_get_pubkey failed");
|
|
Jakub Jelen |
077597 |
} else {
|
|
Jakub Jelen |
077597 |
- switch (evp->type) {
|
|
Jakub Jelen |
077597 |
+ switch (EVP_PKEY_id(evp)) {
|
|
Jakub Jelen |
077597 |
case EVP_PKEY_RSA:
|
|
Jakub Jelen |
077597 |
- if (evp->pkey.rsa == NULL)
|
|
Jakub Jelen |
077597 |
+ if (EVP_PKEY_get0_RSA(evp) == NULL)
|
|
Jakub Jelen |
077597 |
debug("Missing RSA key");
|
|
Jakub Jelen |
077597 |
- else if ((rsa = RSAPublicKey_dup(
|
|
Jakub Jelen |
077597 |
- evp->pkey.rsa)) == NULL)
|
|
Jakub Jelen |
077597 |
+ else if ((rsa = RSAPublicKey_dup(
|
|
Jakub Jelen |
077597 |
+ EVP_PKEY_get0_RSA(evp))) == NULL)
|
|
Jakub Jelen |
077597 |
error("RSAPublicKey_dup failed");
|
|
Jakub Jelen |
077597 |
break;
|
|
Jakub Jelen |
077597 |
case EVP_PKEY_EC:
|
|
Jakub Jelen |
077597 |
- if (evp->pkey.ecdsa == NULL)
|
|
Jakub Jelen |
077597 |
+ if (EVP_PKEY_get0_EC_KEY(evp) == NULL)
|
|
Jakub Jelen |
077597 |
debug("Missing ECDSA key");
|
|
Jakub Jelen |
077597 |
- else if ((ecdsa = EC_KEY_dup(
|
|
Jakub Jelen |
077597 |
- evp->pkey.ecdsa)) == NULL)
|
|
Jakub Jelen |
077597 |
+ else if ((ecdsa = EC_KEY_dup(
|
|
Jakub Jelen |
077597 |
+ EVP_PKEY_get0_EC_KEY(evp))) == NULL)
|
|
Jakub Jelen |
077597 |
error("EC_KEY_dup failed");
|
|
Jakub Jelen |
077597 |
break;
|
|
Jakub Jelen |
077597 |
default:
|
|
Jakub Jelen |
077597 |
@@ -538,7 +551,9 @@ pkcs11_fetch_keys_filter(struct pkcs11_p
|
|
Jakub Jelen |
aacf0d |
}
|
|
Jakub Jelen |
7e9748 |
key = NULL;
|
|
Jakub Jelen |
7e9748 |
if (rsa || ecdsa) {
|
|
Jakub Jelen |
7e9748 |
- if (rsa && rsa->n && rsa->e &&
|
|
Jakub Jelen |
7e9748 |
+ if (rsa)
|
|
Jakub Jelen |
7e9748 |
+ RSA_get0_key(rsa, &n, &e, NULL);
|
|
Jakub Jelen |
7e9748 |
+ if (rsa && n && e &&
|
|
Jakub Jelen |
7e9748 |
pkcs11_rsa_wrap(p, slotidx, &attribs[0], &attribs[1], rsa) == 0) {
|
|
Jakub Jelen |
7e9748 |
if ((key = sshkey_new(KEY_UNSPEC)) == NULL)
|
|
Jakub Jelen |
7e9748 |
fatal("sshkey_new failed");
|
|
Jakub Jelen |
5b55d0 |
diff -up openssh/ssh-rsa.c.openssl openssh/ssh-rsa.c
|
|
Jakub Jelen |
5b55d0 |
--- openssh/ssh-rsa.c.openssl 2017-09-19 06:26:43.000000000 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh/ssh-rsa.c 2017-09-26 13:19:31.803249734 +0200
|
|
Jakub Jelen |
3cd489 |
@@ -78,38 +78,50 @@ rsa_hash_alg_nid(int type)
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
5b55d0 |
int
|
|
Jakub Jelen |
5b55d0 |
-ssh_rsa_generate_additional_parameters(struct sshkey *key)
|
|
Jakub Jelen |
5b55d0 |
+ssh_rsa_generate_additional_parameters(struct sshkey *key, BIGNUM *iqmp)
|
|
Jakub Jelen |
5b55d0 |
{
|
|
Jakub Jelen |
5b55d0 |
BIGNUM *aux = NULL;
|
|
Jakub Jelen |
5b55d0 |
BN_CTX *ctx = NULL;
|
|
Jakub Jelen |
3cd489 |
- BIGNUM d;
|
|
Jakub Jelen |
3cd489 |
+ BIGNUM *d = NULL;
|
|
Jakub Jelen |
5b55d0 |
int r;
|
|
Jakub Jelen |
3cd489 |
+ const BIGNUM *p, *q, *rsa_d;
|
|
Jakub Jelen |
5b55d0 |
+ BIGNUM *dmp1 = NULL, *dmq1 = NULL;
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
5b55d0 |
if (key == NULL || key->rsa == NULL ||
|
|
Jakub Jelen |
5b55d0 |
sshkey_type_plain(key->type) != KEY_RSA)
|
|
Jakub Jelen |
5b55d0 |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
5b55d0 |
- if ((ctx = BN_CTX_new()) == NULL)
|
|
Jakub Jelen |
5b55d0 |
- return SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
5b55d0 |
- if ((aux = BN_new()) == NULL) {
|
|
Jakub Jelen |
5b55d0 |
+ RSA_get0_factors(key->rsa, &p, &q);
|
|
Jakub Jelen |
3cd489 |
+ RSA_get0_key(key->rsa, NULL, NULL, &rsa_d);
|
|
Jakub Jelen |
5b55d0 |
+
|
|
Jakub Jelen |
5b55d0 |
+ if ((ctx = BN_CTX_new()) == NULL ||
|
|
Jakub Jelen |
5b55d0 |
+ (aux = BN_new()) == NULL ||
|
|
Jakub Jelen |
3cd489 |
+ (d = BN_new()) == NULL ||
|
|
Jakub Jelen |
5b55d0 |
+ (dmp1 = BN_new()) == NULL ||
|
|
Jakub Jelen |
5b55d0 |
+ (dmq1 = BN_new()) == NULL) {
|
|
Jakub Jelen |
5b55d0 |
r = SSH_ERR_ALLOC_FAIL;
|
|
Jakub Jelen |
5b55d0 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
3cd489 |
BN_set_flags(aux, BN_FLG_CONSTTIME);
|
|
Jakub Jelen |
3cd489 |
|
|
Jakub Jelen |
3cd489 |
- BN_init(&d);
|
|
Jakub Jelen |
3cd489 |
- BN_with_flags(&d, key->rsa->d, BN_FLG_CONSTTIME);
|
|
Jakub Jelen |
3cd489 |
+ BN_with_flags(d, rsa_d, BN_FLG_CONSTTIME);
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
3cd489 |
- if ((BN_sub(aux, key->rsa->q, BN_value_one()) == 0) ||
|
|
Jakub Jelen |
3cd489 |
- (BN_mod(key->rsa->dmq1, &d, aux, ctx) == 0) ||
|
|
Jakub Jelen |
3cd489 |
- (BN_sub(aux, key->rsa->p, BN_value_one()) == 0) ||
|
|
Jakub Jelen |
3cd489 |
- (BN_mod(key->rsa->dmp1, &d, aux, ctx) == 0)) {
|
|
Jakub Jelen |
5b55d0 |
+ if ((BN_sub(aux, q, BN_value_one()) == 0) ||
|
|
Jakub Jelen |
5b55d0 |
+ (BN_mod(dmq1, d, aux, ctx) == 0) ||
|
|
Jakub Jelen |
5b55d0 |
+ (BN_sub(aux, p, BN_value_one()) == 0) ||
|
|
Jakub Jelen |
5b55d0 |
+ (BN_mod(dmp1, d, aux, ctx) == 0) ||
|
|
Jakub Jelen |
5b55d0 |
+ (RSA_set0_crt_params(key->rsa, dmp1, dmq1, iqmp) == 0)) {
|
|
Jakub Jelen |
5b55d0 |
r = SSH_ERR_LIBCRYPTO_ERROR;
|
|
Jakub Jelen |
5b55d0 |
goto out;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
5b55d0 |
+ dmp1 = NULL;
|
|
Jakub Jelen |
5b55d0 |
+ dmq1 = NULL;
|
|
Jakub Jelen |
5b55d0 |
r = 0;
|
|
Jakub Jelen |
5b55d0 |
out:
|
|
Jakub Jelen |
3cd489 |
+ BN_free(d);
|
|
Jakub Jelen |
5b55d0 |
BN_clear_free(aux);
|
|
Jakub Jelen |
5b55d0 |
+ BN_clear_free(dmp1);
|
|
Jakub Jelen |
5b55d0 |
+ BN_clear_free(dmq1);
|
|
Jakub Jelen |
5b55d0 |
BN_CTX_free(ctx);
|
|
Jakub Jelen |
5b55d0 |
return r;
|
|
Jakub Jelen |
5b55d0 |
}
|
|
Jakub Jelen |
5b55d0 |
@@ -136,7 +145,7 @@ ssh_rsa_sign(const struct sshkey *key, u
|
|
Jakub Jelen |
aacf0d |
if (key == NULL || key->rsa == NULL || hash_alg == -1 ||
|
|
Jakub Jelen |
5b55d0 |
sshkey_type_plain(key->type) != KEY_RSA)
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
5b55d0 |
- if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE)
|
|
Jakub Jelen |
5b55d0 |
+ if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
|
|
Jakub Jelen |
5b55d0 |
return SSH_ERR_KEY_LENGTH;
|
|
Jakub Jelen |
aacf0d |
slen = RSA_size(key->rsa);
|
|
Jakub Jelen |
aacf0d |
if (slen <= 0 || slen > SSHBUF_MAX_BIGNUM)
|
|
Jakub Jelen |
5b55d0 |
@@ -210,7 +219,7 @@ ssh_rsa_verify(const struct sshkey *key,
|
|
Jakub Jelen |
aacf0d |
sshkey_type_plain(key->type) != KEY_RSA ||
|
|
Jakub Jelen |
aacf0d |
sig == NULL || siglen == 0)
|
|
Jakub Jelen |
aacf0d |
return SSH_ERR_INVALID_ARGUMENT;
|
|
Jakub Jelen |
5b55d0 |
- if (BN_num_bits(key->rsa->n) < SSH_RSA_MINIMUM_MODULUS_SIZE)
|
|
Jakub Jelen |
5b55d0 |
+ if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
|
|
Jakub Jelen |
5b55d0 |
return SSH_ERR_KEY_LENGTH;
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
5b55d0 |
if ((b = sshbuf_from(sig, siglen)) == NULL)
|
|
Jakub Jelen |
5b55d0 |
--- openssh-7.6p1/configure.ac.openssl 2017-10-04 15:47:48.440672023 +0200
|
|
Jakub Jelen |
5b55d0 |
+++ openssh-7.6p1/configure.ac 2017-10-04 15:47:23.327531495 +0200
|
|
Jakub Jelen |
5b55d0 |
@@ -2730,6 +2730,7 @@
|
|
Jakub Jelen |
5b55d0 |
AC_MSG_ERROR([OpenSSL >= 1.0.1 required (have "$ssl_library_ver")])
|
|
Jakub Jelen |
5b55d0 |
;;
|
|
Jakub Jelen |
5b55d0 |
100*) ;; # 1.0.x
|
|
Jakub Jelen |
5b55d0 |
+ 101*) ;; # 1.1.x is supported by this patch too
|
|
Jakub Jelen |
5b55d0 |
200*) ;; # LibreSSL
|
|
Jakub Jelen |
5b55d0 |
*)
|
|
Jakub Jelen |
5b55d0 |
AC_MSG_ERROR([OpenSSL >= 1.1.0 is not yet supported (have "$ssl_library_ver")])
|