Question

In the PKey class documentation of the M2Crypto python package (an OpenSSL wrapper for Python) it is said that PKey is a reference to a Public key.

My opinion is instead that it's a reference to a Private Key because the init method of the PKey class calls the evp_pkey_new openssl function that, from this link: http://linux.die.net/man/3/evp_pkey_new , should allocate a new reference to a private key structure!

There are two only possible explaination: The M2Crypto documentation is wrong or the link I've reported has wrong informations.

Can someone help me to find the truth?

Was it helpful?

Solution

The OpenSSL documentation is incomplete - the EVP_PKEY structure allocated by EVP_PKEY_new() is used to store either private or public keys. The type of key is determined by what you later load into the structure.

(Eg. both EVP_SealInit() and EVP_OpenInit take EVP_PKEY parameters).

OTHER TIPS

The documentation for EVP_PKEY_new directly states its used to store private keys. And I'm lost as the original poster is since x509foo.get_pubkey() just returns a EVP.PKey instance and that storeing the instance as pem shows PRIVATE KEY. I can't pretend to know the intention of the M2Crypto team since many functions that use PKey are not documented. For example an x509 request object has a verify(self,pkey) yet tells me nothing about what kind of object pkey is. Likewise there or any documentation. I'm just as confused as the original auther since I think of RSA at the very least nn terms of (e,n)#Public key (d,n)#Private key

and at best I think of Privatekeys (d,n,p,q,dp,dq,qinv,t) where p and q are the large primes dp and dq and qinv are extra coeficiants to make decrypting faster and t as the totient function.

The reason the distinction should have been made clearer in the documentation is sometimes you want to encrypt with the private keys(In the case of a signature) so that every one else can verify by decrupting using the public key. h = hash(m) sig = h^d (mod n) only some one that knows d (The private key) could create the signature. Verification is done by

h = sig^e (mod n)

if the two hashes match you know the message is authentic.

The issue I'm having is EVP.Pkey claimes to be representing a public key yet its assign_rsa() method declares it takes in an RSA key pair ("I'm assuming this means private key at this point". Any examples I've found so far are only for creating a self cigned cert (Including M2Crypto's own unit tests. I don't see any tests that take a third party x509 request and sign it with its own ca cert and key like we would normally see in reality. The unit tests doesn't help me in terms of figuring out how to sign general CSRs since X509 Requests won't contain the private key. Yet the unit tests examples work fine since its self signed and the signer already had access to the private keys. Infact the test_mkcert test does exactly that it takes the private key handed back by the mkreq method which generates the x509 request.

The M2Crypto docs are confuseing since they use the terms pk,pkey and even pubkey interchangably.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top