|
Norbert Pocs |
e8e01d |
diff --color -ru -x regress -x autom4te.cache -x '*.o' -x '*.lo' -x Makefile -x config.status -x configure~ -x configure.ac openssh-9.0p1/ssh-ecdsa.c openssh-9.0p1-patched/ssh-ecdsa.c
|
|
Norbert Pocs |
e8e01d |
--- openssh-9.0p1/ssh-ecdsa.c 2023-05-24 08:54:03.926443958 +0200
|
|
Norbert Pocs |
e8e01d |
+++ openssh-9.0p1-patched/ssh-ecdsa.c 2023-05-24 09:46:19.082925921 +0200
|
|
Norbert Pocs |
e8e01d |
@@ -74,8 +74,18 @@
|
|
Norbert Pocs |
e8e01d |
if ((hash_alg = sshkey_ec_nid_to_hash_alg(key->ecdsa_nid)) == -1)
|
|
Norbert Pocs |
e8e01d |
return SSH_ERR_INTERNAL_ERROR;
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
- if ((ret = ssh_create_evp_ec(key->ecdsa, key->ecdsa_nid, &pkey)) != 0)
|
|
Norbert Pocs |
e8e01d |
- return ret;
|
|
Norbert Pocs |
e8e01d |
+#ifdef ENABLE_PKCS11
|
|
Norbert Pocs |
e8e01d |
+ if (is_ecdsa_pkcs11(key->ecdsa)) {
|
|
Norbert Pocs |
e8e01d |
+ if ((pkey = EVP_PKEY_new()) == NULL ||
|
|
Norbert Pocs |
e8e01d |
+ EVP_PKEY_set1_EC_KEY(pkey, key->ecdsa) != 1)
|
|
Norbert Pocs |
e8e01d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Norbert Pocs |
e8e01d |
+ } else {
|
|
Norbert Pocs |
e8e01d |
+#endif
|
|
Norbert Pocs |
e8e01d |
+ if ((ret = ssh_create_evp_ec(key->ecdsa, key->ecdsa_nid, &pkey)) != 0)
|
|
Norbert Pocs |
e8e01d |
+ return ret;
|
|
Norbert Pocs |
e8e01d |
+#ifdef ENABLE_PKCS11
|
|
Norbert Pocs |
e8e01d |
+ }
|
|
Norbert Pocs |
e8e01d |
+#endif
|
|
Norbert Pocs |
e8e01d |
ret = sshkey_calculate_signature(pkey, hash_alg, &sigb, &len, data,
|
|
Dmitry Belyavskiy |
f561c6 |
dlen);
|
|
Norbert Pocs |
e8e01d |
EVP_PKEY_free(pkey);
|
|
Norbert Pocs |
e8e01d |
diff --color -ru -x regress -x autom4te.cache -x '*.o' -x '*.lo' -x Makefile -x config.status -x configure~ -x configure.ac openssh-9.0p1/sshkey.h openssh-9.0p1-patched/sshkey.h
|
|
Norbert Pocs |
e8e01d |
--- openssh-9.0p1/sshkey.h 2023-05-24 08:54:03.926443958 +0200
|
|
Norbert Pocs |
e8e01d |
+++ openssh-9.0p1-patched/sshkey.h 2023-05-24 08:57:22.930642788 +0200
|
|
Norbert Pocs |
e8e01d |
@@ -340,6 +340,10 @@
|
|
Dmitry Belyavskiy |
f561c6 |
#endif
|
|
Norbert Pocs |
e8e01d |
#endif
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
+#ifdef ENABLE_PKCS11
|
|
Norbert Pocs |
e8e01d |
+int pkcs11_get_ecdsa_idx(void);
|
|
Norbert Pocs |
e8e01d |
+#endif
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
#if !defined(WITH_OPENSSL)
|
|
Norbert Pocs |
e8e01d |
# undef RSA
|
|
Norbert Pocs |
e8e01d |
# undef DSA
|
|
Norbert Pocs |
e8e01d |
diff --color -ru -x regress -x autom4te.cache -x '*.o' -x '*.lo' -x Makefile -x config.status -x configure~ -x configure.ac openssh-9.0p1/ssh-pkcs11.c openssh-9.0p1-patched/ssh-pkcs11.c
|
|
Norbert Pocs |
e8e01d |
--- openssh-9.0p1/ssh-pkcs11.c 2023-05-24 08:54:03.888443542 +0200
|
|
Norbert Pocs |
e8e01d |
+++ openssh-9.0p1-patched/ssh-pkcs11.c 2023-05-24 09:48:13.101168512 +0200
|
|
Norbert Pocs |
e8e01d |
@@ -776,8 +776,24 @@
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
return (0);
|
|
Norbert Pocs |
e8e01d |
}
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
+int
|
|
Norbert Pocs |
e8e01d |
+is_ecdsa_pkcs11(EC_KEY *ecdsa)
|
|
Norbert Pocs |
e8e01d |
+{
|
|
Norbert Pocs |
e8e01d |
+ if (EC_KEY_get_ex_data(ecdsa, ec_key_idx) != NULL)
|
|
Norbert Pocs |
e8e01d |
+ return 1;
|
|
Norbert Pocs |
e8e01d |
+ return 0;
|
|
Norbert Pocs |
e8e01d |
+}
|
|
Norbert Pocs |
e8e01d |
#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
+int
|
|
Norbert Pocs |
e8e01d |
+is_rsa_pkcs11(RSA *rsa)
|
|
Norbert Pocs |
e8e01d |
+{
|
|
Norbert Pocs |
e8e01d |
+ if (RSA_get_ex_data(rsa, rsa_idx) != NULL)
|
|
Norbert Pocs |
e8e01d |
+ return 1;
|
|
Norbert Pocs |
e8e01d |
+ return 0;
|
|
Norbert Pocs |
e8e01d |
+}
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
/* remove trailing spaces */
|
|
Norbert Pocs |
e8e01d |
static void
|
|
Norbert Pocs |
e8e01d |
rmspace(u_char *buf, size_t len)
|
|
Norbert Pocs |
e8e01d |
diff --color -ru -x regress -x autom4te.cache -x '*.o' -x '*.lo' -x Makefile -x config.status -x configure~ -x configure.ac openssh-9.0p1/ssh-pkcs11-client.c openssh-9.0p1-patched/ssh-pkcs11-client.c
|
|
Norbert Pocs |
e8e01d |
--- openssh-9.0p1/ssh-pkcs11-client.c 2023-05-24 08:54:03.887443531 +0200
|
|
Norbert Pocs |
e8e01d |
+++ openssh-9.0p1-patched/ssh-pkcs11-client.c 2023-05-24 09:49:41.741134514 +0200
|
|
Norbert Pocs |
e8e01d |
@@ -225,8 +225,36 @@
|
|
Norbert Pocs |
e8e01d |
static RSA_METHOD *helper_rsa;
|
|
Norbert Pocs |
e8e01d |
#if defined(OPENSSL_HAS_ECC) && defined(HAVE_EC_KEY_METHOD_NEW)
|
|
Norbert Pocs |
e8e01d |
static EC_KEY_METHOD *helper_ecdsa;
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
+int
|
|
Norbert Pocs |
e8e01d |
+is_ecdsa_pkcs11(EC_KEY *ecdsa)
|
|
Norbert Pocs |
e8e01d |
+{
|
|
Norbert Pocs |
e8e01d |
+ const EC_KEY_METHOD *meth;
|
|
Norbert Pocs |
e8e01d |
+ ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, int dgstlen,
|
|
Norbert Pocs |
e8e01d |
+ const BIGNUM *kinv, const BIGNUM *rp, EC_KEY *eckey) = NULL;
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
+ meth = EC_KEY_get_method(ecdsa);
|
|
Norbert Pocs |
e8e01d |
+ EC_KEY_METHOD_get_sign(meth, NULL, NULL, &sign_sig);
|
|
Norbert Pocs |
e8e01d |
+ if (sign_sig == ecdsa_do_sign)
|
|
Norbert Pocs |
e8e01d |
+ return 1;
|
|
Norbert Pocs |
e8e01d |
+ return 0;
|
|
Norbert Pocs |
e8e01d |
+}
|
|
Norbert Pocs |
e8e01d |
#endif /* OPENSSL_HAS_ECC && HAVE_EC_KEY_METHOD_NEW */
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
+int
|
|
Norbert Pocs |
e8e01d |
+is_rsa_pkcs11(RSA *rsa)
|
|
Norbert Pocs |
e8e01d |
+{
|
|
Norbert Pocs |
e8e01d |
+ const RSA_METHOD *meth;
|
|
Norbert Pocs |
e8e01d |
+ int (*priv_enc)(int flen, const unsigned char *from,
|
|
Norbert Pocs |
e8e01d |
+ unsigned char *to, RSA *rsa, int padding) = NULL;
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
+ meth = RSA_get_method(rsa);
|
|
Norbert Pocs |
e8e01d |
+ priv_enc = RSA_meth_get_priv_enc(meth);
|
|
Norbert Pocs |
e8e01d |
+ if (priv_enc == rsa_encrypt)
|
|
Norbert Pocs |
e8e01d |
+ return 1;
|
|
Norbert Pocs |
e8e01d |
+ return 0;
|
|
Norbert Pocs |
e8e01d |
+}
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
/* redirect private key crypto operations to the ssh-pkcs11-helper */
|
|
Norbert Pocs |
e8e01d |
static void
|
|
Norbert Pocs |
e8e01d |
wrap_key(struct sshkey *k)
|
|
Norbert Pocs |
e8e01d |
diff --color -ru -x regress -x autom4te.cache -x '*.o' -x '*.lo' -x Makefile -x config.status -x configure~ -x configure.ac openssh-9.0p1/ssh-pkcs11.h openssh-9.0p1-patched/ssh-pkcs11.h
|
|
Norbert Pocs |
e8e01d |
--- openssh-9.0p1/ssh-pkcs11.h 2023-05-24 08:54:03.888443542 +0200
|
|
Norbert Pocs |
e8e01d |
+++ openssh-9.0p1-patched/ssh-pkcs11.h 2023-05-24 09:50:03.981376886 +0200
|
|
Norbert Pocs |
e8e01d |
@@ -39,6 +39,11 @@
|
|
Norbert Pocs |
e8e01d |
u_int32_t *);
|
|
Norbert Pocs |
e8e01d |
#endif
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
+#ifdef HAVE_EC_KEY_METHOD_NEW
|
|
Norbert Pocs |
e8e01d |
+int is_ecdsa_pkcs11(EC_KEY *ecdsa);
|
|
Norbert Pocs |
e8e01d |
+#endif
|
|
Norbert Pocs |
e8e01d |
+int is_rsa_pkcs11(RSA *rsa);
|
|
Norbert Pocs |
e8e01d |
+
|
|
Norbert Pocs |
e8e01d |
#if !defined(WITH_OPENSSL) && defined(ENABLE_PKCS11)
|
|
Norbert Pocs |
e8e01d |
#undef ENABLE_PKCS11
|
|
Norbert Pocs |
e8e01d |
#endif
|
|
Norbert Pocs |
e8e01d |
diff --color -ru -x regress -x autom4te.cache -x '*.o' -x '*.lo' -x Makefile -x config.status -x configure~ -x configure.ac openssh-9.0p1/ssh-rsa.c openssh-9.0p1-patched/ssh-rsa.c
|
|
Norbert Pocs |
e8e01d |
--- openssh-9.0p1/ssh-rsa.c 2023-05-24 08:54:03.927443969 +0200
|
|
Norbert Pocs |
e8e01d |
+++ openssh-9.0p1-patched/ssh-rsa.c 2023-05-24 09:51:50.358536178 +0200
|
|
Norbert Pocs |
e8e01d |
@@ -174,8 +174,18 @@
|
|
Norbert Pocs |
e8e01d |
if (RSA_bits(key->rsa) < SSH_RSA_MINIMUM_MODULUS_SIZE)
|
|
Norbert Pocs |
e8e01d |
return SSH_ERR_KEY_LENGTH;
|
|
Norbert Pocs |
e8e01d |
|
|
Norbert Pocs |
e8e01d |
- if ((ret = ssh_create_evp_rsa(key, &pkey)) != 0)
|
|
Norbert Pocs |
e8e01d |
- return ret;
|
|
Norbert Pocs |
e8e01d |
+#ifdef ENABLE_PKCS11
|
|
Norbert Pocs |
e8e01d |
+ if (is_rsa_pkcs11(key->rsa)) {
|
|
Norbert Pocs |
e8e01d |
+ if ((pkey = EVP_PKEY_new()) == NULL ||
|
|
Norbert Pocs |
e8e01d |
+ EVP_PKEY_set1_RSA(pkey, key->rsa) != 1)
|
|
Norbert Pocs |
e8e01d |
+ return SSH_ERR_ALLOC_FAIL;
|
|
Norbert Pocs |
e8e01d |
+ } else {
|
|
Norbert Pocs |
e8e01d |
+#endif
|
|
Norbert Pocs |
e8e01d |
+ if ((ret = ssh_create_evp_rsa(key, &pkey)) != 0)
|
|
Norbert Pocs |
e8e01d |
+ return ret;
|
|
Norbert Pocs |
e8e01d |
+#ifdef ENABLE_PKCS11
|
|
Norbert Pocs |
e8e01d |
+ }
|
|
Norbert Pocs |
e8e01d |
+#endif
|
|
Norbert Pocs |
e8e01d |
ret = sshkey_calculate_signature(pkey, hash_alg, &sig, &len, data,
|
|
Norbert Pocs |
e8e01d |
datalen);
|
|
Norbert Pocs |
e8e01d |
EVP_PKEY_free(pkey);
|