Sebastiano Di Paola wrote:
> 
> Dr S N Henson wrote:
> 
> > Sebastiano Di Paola wrote:
> > >
> > > Hi all,
> > > well this could seem a stupid question,
> > > I would like to know if there is a function provided with openssl to
> > > generate the x.509v3 extension
> > > Authority Key Identifier.
> > > I read rfc2459 to know how to calculate it:
> > > it says:
> > >
> > > 1) The keyIdentifier is composed of the 160-bit SHA-1 hash of the
> > >       value of the BIT STRING subjectPublicKey (excluding the tag,
> > >       length, and number of unused bits).
> > >
> > > Or
> > >
> > > (2) The keyIdentifier is composed of a four bit type field with
> > >       the value 0100 followed by the least significant 60 bits of the
> > >       SHA-1 hash of the value of the BIT STRING subjectPublicKey.
> > >
> >
> > I think that quote refers to subject key identifier.
> >
> 
> [..]
> 
> Well, I re-read rfc2459. The quotes is written in the paragraph related to
> 
> Subject key Identifier ,but refers alsto to Authority Key Identifier.
> Besides this issue
> 
> If Openssl copy Authority key info from subject key info of the issuer's
> certificate How does openssl generate Subject Key Identifier for the new
> certificate signed?
> 
> I would like to know if there is some high level function which can
> generate the
> Subject Key Identifier from a public key (as X509_digest for the whole
> certificate)
> If yes what is it?
> if no how to generate by hand the Subject key id?
> I have a PKCS12 bag with private key and certificate.
> 1) Extract certficate from pkcs12 with PKCS12_parse
> 2) Extract Public Key with X509_get_pubKey
> 3) Extract DER encoding of Pub Pkey with i2d_PublicKey
> 4) Create a sha1 digest of the buffer filled with i2d_PublicKey.
> 
> Is there something wrong because the value calculated in tha way differs
> from the
> value of the Subject Key Identifier already present in the certificate!!
> 

OK let me explain a bit about what subject key id is for. Its
basically a way of identifying the public key in a certificate using
a unique set of bytes. RFC2459 makes recommendations but many ignore
them
and use their own techniques based on hashes of various things as well
as the public key.

Now authority key identifier is used as a way to recognise the issuing
authority of a certificate. As such its key identifier (if present)
*must* 
match the value in the subject key identifier field of the issuing
authorities certificate. If it doesn't then the issuer wont be
recognised
and certificate chains wont verify with certain software. OpenSSL 0.9.6
for
example will use these fields for chain verification but earlier
versions
didn't.

Finally how to calculate it. Well there is a way using the extension
code
to automatically calculate it. Check out the documentation in
doc/openssl.txt
for details. These however take a certificate not a public key.

If your code is correct then i2d_PublicKey() should work and should
agree
with the values calculated by OpenSSL. You can use the function
ASN1_digest()
to automatically do the calculation. If you check what X509_digest()
does:

#define X509_digest(data,type,md,len) \
        ASN1_digest((int (*)())i2d_X509,type,(char *)data,md,len)

Something like:

#define PublicKey_digest(pkey,type,md,len) \
        ASN1_digest((int (*)())i2d_PublicKey,type,(char *)pkey,md,len)

then calling:

PublicKey_digest(pkey, EVP_sha1(), ...);

might work.

Steve.
-- 
Dr Stephen N. Henson.   http://www.drh-consultancy.demon.co.uk/
Personal Email: [EMAIL PROTECTED] 
Senior crypto engineer, Celo Communications: http://www.celocom.com/
Core developer of the   OpenSSL project: http://www.openssl.org/
Business Email: [EMAIL PROTECTED] PGP key: via homepage.


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to