@@ -1216,6 +1216,11 @@ nc_tls_privkey_export_openssh(EVP_PKEY *pkey, char **privkey)
12161216 char * pem = NULL ;
12171217 ssh_key sshkey = NULL ;
12181218
1219+ * privkey = NULL ;
1220+
1221+ /* older versions of libssh (< v0.11.0) do not support exporting to OpenSSH format,
1222+ * signal this to the caller by returning success with NULL privkey */
1223+ #if (LIBSSH_VERSION_MAJOR > 0 ) || (LIBSSH_VERSION_MAJOR == 0 && LIBSSH_VERSION_MINOR >= 11 )
12191224 bio = BIO_new (BIO_s_mem ());
12201225 if (!bio ) {
12211226 ERR (NULL , "Creating new bio failed (%s)." , ERR_reason_error_string (ERR_get_error ()));
@@ -1247,6 +1252,7 @@ nc_tls_privkey_export_openssh(EVP_PKEY *pkey, char **privkey)
12471252 rc = 1 ;
12481253 goto cleanup ;
12491254 }
1255+ #endif
12501256
12511257cleanup :
12521258 BIO_free (bio );
@@ -1261,7 +1267,7 @@ nc_tls_privkey_export_wrap(void *pkey, enum nc_privkey_format format, char **pri
12611267 int rc = 0 ;
12621268 BIO * bio = NULL ;
12631269 OSSL_ENCODER_CTX * ctx = NULL ;
1264- const char * output_structure ;
1270+ const char * output_structure = NULL ;
12651271
12661272 bio = BIO_new (BIO_s_mem ());
12671273 if (!bio ) {
@@ -1280,12 +1286,22 @@ nc_tls_privkey_export_wrap(void *pkey, enum nc_privkey_format format, char **pri
12801286 output_structure = "PrivateKeyInfo" ;
12811287 break ;
12821288 case NC_PRIVKEY_FORMAT_OPENSSH :
1283- /* we need to use libssh for this */
12841289 rc = nc_tls_privkey_export_openssh (pkey , privkey );
1285- goto cleanup ;
1290+ if (rc ) {
1291+ goto cleanup ;
1292+ }
1293+
1294+ if (!* privkey ) {
1295+ /* privkey not converted, just convert it to PrivateKeyInfo format */
1296+ output_structure = "PrivateKeyInfo" ;
1297+ }
1298+ break ;
12861299 default :
12871300 ERRINT ;
12881301 rc = 1 ;
1302+ break ;
1303+ }
1304+ if (!output_structure ) {
12891305 goto cleanup ;
12901306 }
12911307
0 commit comments