]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
openssl: Add missing error checking when encoding ED private key
authorGerardo Ravago <gcr@amazon.com>
Tue, 13 Feb 2024 15:24:33 +0000 (10:24 -0500)
committerTobias Brunner <tobias@strongswan.org>
Wed, 14 Feb 2024 16:57:41 +0000 (17:57 +0100)
This applies the same logic found in other private key implementations
like that for ECDSA.

Closes strongswan/strongswan#2097

src/libstrongswan/plugins/openssl/openssl_ed_private_key.c

index 609e640800f30e7605254113ccad8ff35af7882a..e8d900d94a5de3012c98ef8f821f64182f61dd34 100644 (file)
@@ -19,6 +19,7 @@
 #if OPENSSL_VERSION_NUMBER >= 0x1010100fL && !defined(OPENSSL_NO_EC)
 
 #include "openssl_ed_private_key.h"
+#include "openssl_util.h"
 
 #include <utils/debug.h>
 
@@ -157,8 +158,6 @@ METHOD(private_key_t, get_fingerprint, bool,
 METHOD(private_key_t, get_encoding, bool,
        private_private_key_t *this, cred_encoding_type_t type, chunk_t *encoding)
 {
-       u_char *p;
-
        if (this->engine)
        {
                return FALSE;
@@ -171,9 +170,7 @@ METHOD(private_key_t, get_encoding, bool,
                {
                        bool success = TRUE;
 
-                       *encoding = chunk_alloc(i2d_PrivateKey(this->key, NULL));
-                       p = encoding->ptr;
-                       i2d_PrivateKey(this->key, &p);
+                       *encoding = openssl_i2chunk(PrivateKey, this->key);
 
                        if (type == PRIVKEY_PEM)
                        {