Private raw key should be returned as a secret

This commit is contained in:
Kovid Goyal 2022-08-04 20:27:38 +05:30
parent 89854cca8b
commit a1c4ffec20
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -178,11 +178,11 @@ static PyObject*
elliptic_curve_key_get_private(EllipticCurveKey *self, void UNUSED *closure) {
size_t len = 0;
if (1 != EVP_PKEY_get_raw_private_key(self->key, NULL, &len)) return set_error_from_openssl("Could not get public key from EVP_PKEY");
PyObject *ans = PyBytes_FromStringAndSize(NULL, len);
Secret *ans = alloc_secret(len);
if (!ans) return NULL;
if (mlock(PyBytes_AS_STRING(ans), len) != 0) { Py_CLEAR(ans); return PyErr_SetFromErrno(PyExc_OSError); }
if (1 != EVP_PKEY_get_raw_private_key(self->key, (unsigned char*)PyBytes_AS_STRING(ans), &len)) { Py_CLEAR(ans); return set_error_from_openssl("Could not get public key from EVP_PKEY"); }
return ans;
if (1 != EVP_PKEY_get_raw_private_key(self->key, (unsigned char*)ans->secret, &len)) { Py_CLEAR(ans); return set_error_from_openssl("Could not get public key from EVP_PKEY"); }
return (PyObject*)ans;
}