James wrote:
> Hi all
>
<snip>
> // Try to copy public key from X509 Request
>
> EVP_PKEY* newEvpKey = X509_REQ_get_pubkey(x509Request);
>
> EVP_PKEY* evpKey = EVP_PKEY_new();
> evpKey->type = newEvpKey->type;
>
> if(!EVP_PKEY_copy_parameters(newEvpKey, evpKey)) // <-- Segfaults here
> {
> EVP_PKEY_free(evpKey);
> SSLKey::InvalidKeyType ex;
> throw ex;
> }
>
> I get:
> Segmentation fault
> crypto/evp/p_lib.c:151 pkey = 0x8083108, pkey->pkey.dsa = (nil),
> pkey->type = EVP_PKEY_DSA
If I get it right, you're trying to copy from newEvpKey (which points to your
X509_REQ_pubkey) to evpKey.
For this, you should reverse the order of parameters in the call to
EVP_PKEY_copy_parameters, since the first parameter means the target key and
the second the source key structure. That might explain your seg fault -
you're trying to copy from an empty key structure.
> It seems that X509_REQ_set_pubkey() copies the key to an ASN1 format. Do I
> need a d2i_Public_Key() function in there somewhere?
X509_REQ_set_pubkey builds an X509_pubkey struct. Among other things, it
converts the actual value of the key to its DER-coded form and puts it - in
the OpenSSL specific representation of an ASN1_BIT_STRING (containing among
other things the DER byte sequence of the key's value) into the field
'public_key' of that structure. That means if you call set_pubkey with a newly
generated EVP_PKEY, you don't have to convert it at all, the function does
that for you.
Hope this helps you out,
Steve
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [EMAIL PROTECTED]
Automated List Manager [EMAIL PROTECTED]