Skip to content

Commit cc2efb4

Browse files
committed
session mbedtls UPDATE add libssh version check
1 parent ad242b8 commit cc2efb4

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/session_mbedtls.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,8 @@ nc_tls_import_cert_file_wrap(const char *cert_path)
14131413
return c;
14141414
}
14151415

1416+
#if (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
1417+
14161418
/**
14171419
* @brief Convert a PKCS#1/SEC1 private key to OpenSSH format.
14181420
*
@@ -1445,6 +1447,8 @@ nc_tls_privkey_export_openssh(const char *pk, char **privkey)
14451447
return rc;
14461448
}
14471449

1450+
#endif // (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
1451+
14481452
int
14491453
nc_tls_privkey_export_wrap(void *pkey, enum nc_privkey_format format, char **privkey)
14501454
{
@@ -1475,8 +1479,15 @@ nc_tls_privkey_export_wrap(void *pkey, enum nc_privkey_format format, char **pri
14751479
}
14761480

14771481
if (format == NC_PRIVKEY_FORMAT_OPENSSH) {
1478-
/* convert it to OpenSSH format */
1482+
#if (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
1483+
/* convert it to OpenSSH format, API added in libssh 0.11.0 */
14791484
rc = nc_tls_privkey_export_openssh(pk, privkey);
1485+
#else
1486+
/* older versions of libssh do not support exporting to OpenSSH format,
1487+
* so just use the original PEM instead */
1488+
*privkey = pk;
1489+
pk = NULL;
1490+
#endif // (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
14801491
} else {
14811492
/* return the PEM as is (PKCS#1 or SEC1), mbedtls can not do NC_PRIVKEY_FORMAT_X509 */
14821493
*privkey = pk;

src/session_openssl.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,8 @@ nc_tls_import_cert_file_wrap(const char *cert_path)
12011201
return cert;
12021202
}
12031203

1204+
#if (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
1205+
12041206
/**
12051207
* @brief Export OpenSSL's EVP_PKEY to OpenSSH private key format.
12061208
*
@@ -1255,6 +1257,8 @@ nc_tls_privkey_export_openssh(EVP_PKEY *pkey, char **privkey)
12551257
return rc;
12561258
}
12571259

1260+
#endif // (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
1261+
12581262
int
12591263
nc_tls_privkey_export_wrap(void *pkey, enum nc_privkey_format format, char **privkey)
12601264
{
@@ -1280,9 +1284,16 @@ nc_tls_privkey_export_wrap(void *pkey, enum nc_privkey_format format, char **pri
12801284
output_structure = "PrivateKeyInfo";
12811285
break;
12821286
case NC_PRIVKEY_FORMAT_OPENSSH:
1283-
/* we need to use libssh for this */
1287+
#if (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
1288+
/* we need to use libssh for this, API for this added in libssh 0.11.0 */
12841289
rc = nc_tls_privkey_export_openssh(pkey, privkey);
12851290
goto cleanup;
1291+
#else
1292+
/* older versions of libssh do not support exporting to OpenSSH format,
1293+
* so just convert to PrivateKeyInfo instead */
1294+
output_structure = "PrivateKeyInfo";
1295+
break;
1296+
#endif // (LIBSSH_VERSION_MAJOR > 0) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11)
12861297
default:
12871298
ERRINT;
12881299
rc = 1;

0 commit comments

Comments
 (0)