Most of libssh2 already has conditional support for RSA according to
the LIBSSH2_RSA crypto backend #define, but crypto.h and userauth.c
needed a few small fixes.
---
src/crypto.h | 2 ++
src/userauth.c | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/src/crypto.h b/src/crypto.h
index aa997a3..b15a122 100644
--- a/src/crypto.h
+++ b/src/crypto.h
@@ -58,6 +58,7 @@
#include "mbedtls.h"
#endif
+#if LIBSSH2_RSA
int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,
const unsigned char *edata,
unsigned long elen,
@@ -92,6 +93,7 @@ int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa,
LIBSSH2_SESSION * session,
const char *filedata, size_t filedata_len,
unsigned const char *passphrase);
+#endif
#if LIBSSH2_DSA
int _libssh2_dsa_new(libssh2_dsa_ctx ** dsa,
diff --git a/src/userauth.c b/src/userauth.c
index cdfa25e..226eb8b 100644
--- a/src/userauth.c
+++ b/src/userauth.c
@@ -786,6 +786,11 @@ userauth_hostbased_fromfile(LIBSSH2_SESSION *session,
{
int rc;
+#if !LIBSSH2_RSA
+ return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
+ "RSA is not supported by crypto backend");
+#endif
+
if (session->userauth_host_state == libssh2_NB_state_idle) {
const LIBSSH2_HOSTKEY_METHOD *privkeyobj;
unsigned char *pubkeydata, *sig = NULL;
@@ -1378,6 +1383,11 @@ userauth_publickey_frommemory(LIBSSH2_SESSION *session,
void *abstract = &privkey_file;
int rc;
+#if !LIBSSH2_RSA
+ return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
+ "RSA is not supported by crypto backend");
+#endif
+
privkey_file.filename = privatekeydata;
privkey_file.passphrase = passphrase;
@@ -1435,6 +1445,11 @@ userauth_publickey_fromfile(LIBSSH2_SESSION *session,
void *abstract = &privkey_file;
int rc;
+#if !LIBSSH2_RSA
+ return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED,
+ "RSA is not supported by crypto backend");
+#endif
+
privkey_file.filename = privatekey;
privkey_file.passphrase = passphrase;
--
_______________________________________________
libssh2-devel https://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2016-10-27