000023750 - How to resolve differences in format of BER-encoded private keys used by RSA BSAFE Crypto-C  Cert-C  and SSL-C

Document created by RSA Customer Support Employee on Jun 16, 2016Last modified by RSA Customer Support Employee on Apr 21, 2017
Version 2Show Document
  • View in full screen mode

Article Content

Article Number000023750
Applies ToRSA BSAFE Crypto-C
RSA BSAFE Cert-C
RSA BSAFE SSL-C
IssueHow to resolve differences in format of BER-encoded private keys used by RSA BSAFE Crypto-C, Cert-C, and SSL-C
SSL-C shows error such as

SSL3_GET_CLIENT_HELLO:no shared cipher
CauseIn RSA BSAFE Crypto-C and Cert-C, when you call B_GetKeyInfo() with KI_PKCS_RSAPrivateBER, KI_DSAPrivateBER, or KI_DSAPrivateX957BER, the private key is given to the application as a BER-encoded PKCS #8 PrivateKeyInfo.

PrivateKeyInfo ::= SEQUENCE {
 version Version,
 privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
 privateKey PrivateKey,
 attributes [0] IMPLICIT Attributes OPTIONAL
}

The privateKey field of the PrivateKeyInfo will then contain the BER-encoded PKCS #1 RSAPrivateKey or the BER-encoded DSA private key.  When SSL-C takes a BER-encoded private key, it will fail if given an encoding of a PrivateKeyInfo.  It either needs the raw RSA or DSA private key.
ResolutionIn RSA BSAFE Crypto-C 6.0 and in later versions, refer to the Library Reference Manual for a description for AI_SSLC_KeyWrap.  The Crypto-C sample in samples/keywrap/keywrap.c demonstrates this feature.

There is a sample that ships with Cert-C, demonstrating the use of the ASN.1 APIs to convert between the two formats.  The sample source can be found in the samples/asn1/sslcpvt.c.

/*
** Crypto-C and Cert-C use RSA private keys contained in PKCS #8
** PrivateKeyInfo containers, while SSL-C uses data in the raw PKCS #1
** RSAPrivateKey format. (The advantage of the PKCS #8 format, like the
** X.509 SubjectPublicKeyInfo for public keys, is that it contains an
** algorithm identifier specifying the type of key, so that an application
** receiving the key knows what type of key it is) This sample demonstrates
** the ASN.1 decoding APIs in Cert-C by taking a PKCS #8 binary, verifying
** that it is a PKCS #8 containing an RSAPrivateKey, extracting the
** RSAPrivateKey, and saving it to a file. Note that this is a binary,
** unencrypted RSA private key.
**
** Here is the ASN.1 definition of a PrivateKeyInfo:
**
** PrivateKeyInfo ::= SEQUENCE {
** version Version,
** privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
** privateKey PrivateKey,
** attributes [0] IMPLICIT Attributes OPTIONAL
** }
**
** PrivateKey ::= OCTET STRING
**
** Basically, we need to get the third item in the sequence and extract the
** value of that octet string.
Legacy Article IDa8496

Attachments

    Outcomes