X509_CHECK_PRIVATE_KEY(3SSL)
β¨ X509_CHECK_PRIVATE_KEY β the "is this key actually yours, bestie?" check (3SSL) β¨
okay so real talk, this is the OpenSSL page for X509_check_private_key(3SSL) and X509_REQ_check_private_key, and it's literally just the vibe check that answers: does this private key go with this cert? π¦
π NAME π
X509_check_private_key, X509_REQ_check_private_key β check the consistency of a private key with the public key in an X509 certificate or certificate request
no cap, that's the whole job. consistency check. like making sure your AirPods are actually your AirPods. π
πΈ SYNOPSIS πΈ
#include <openssl/x509.h>
int X509_check_private_key(const X509 *cert, EVP_PKEY *pkey);
int X509_REQ_check_private_key(X509_REQ *req, EVP_PKEY *pkey);
β¨ DESCRIPTION β¨
so X509_check_private_key() checks the consistency of private key pkey with the public key in cert. that's it, that's the function. it's giving "match or not, no drama." π
X509_REQ_check_private_key() is equivalent to X509_check_private_key() β exactly the same energy, same energy, same everything β except that req represents a certificate request of structure X509_REQ. so same check, different container. it's giving siblings. π
π«Ά RETURN VALUES π«Ά
X509_check_private_key()andX509_REQ_check_private_key()return1if the keys match each other β slay, they're a pair π- and they return
0if not β not a match, tragic, moving on π
if the key is invalid or an error occurred, the reason code can be obtained using ERR_get_error(3). so like, when it's not just "no" but "no and something's wrong," go read the reason code. π
π BUGS π
okay bestie this is the important part, do not scroll past:
the X509_check_private_key() and X509_REQ_check_private_key() functions do not check if pkey itself is indeed a private key or not. literally not at all. π
they merely compare the public materials (e.g., exponent and modulus of an RSA key) and/or key parameters (e.g. EC params of an EC key) of a key pair.
so they also return success if pkey is a matching public key. yes, for real. a matching public key gets a 1. that is the bug, and it is documented, and now you know it. iykyk. π
warning: a 1 here does not mean "this is definitely a private key." it means "the public bits and/or params line up." act accordingly, bestie.
π SEE ALSO π
π COPYRIGHT π
Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, periodt. this was page X509_CHECK_PRIVATE_KEY(3SSL) from OpenSSL 4.0.3, dated 2026-09-29 β mwah, go check your keys, ily πβ¨π
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms