VirtualBox

Changeset 100493 in vbox


Ignore:
Timestamp:
Jul 10, 2023 11:17:15 PM (17 months ago)
Author:
vboxsync
Message:

IPRT/PKCS8: Some corrections and adjustments (bugref:10299):

  • Always put curly brackets around case bodies that declares variables.
  • Removed copy & paste RTCRRSA_MAX_MODULUS_BITS define from pkcs8-internal.h.
  • We don't need to compile the PKCS8 files for ring-0 libraries, since these does not include the key-file.cpp that needs them.
  • Use RTCRX509ALGORITHMIDENTIFIERID_RSA instead of "1.2.840.113549.1.1.1".
  • rTCrPkcs8PrivateKeyInfo should be RTCrPkcs8PrivateKeyInfo in pkcs8-templace.h.
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/crypto/pkcs8.h

    r100425 r100493  
    4848
    4949/** @defgroup grp_rt_crpkcs8 RTCrPkcs8 - PKCS \#8, Private-Key Information Syntax Standard
     50 *
     51 * See RFC-5208 for details.
     52 *
    5053 * @ingroup grp_rt_crypto
    5154 * @{
     
    5457/**
    5558 * PKCS\#8 PrivateKeyInfo.
     59 *
     60 * See RFC-5208 section 5.
    5661 */
    57 /** @todo bird: rename to RTCRPKCS8PRIVATEKEYINFO. Should eventually be moved
    58  *        into a new iprt/crypto/pkcs8.h header file. Ditto for the template
    59  *        and associated code instantiation/whatever. */
    6062typedef struct RTCRPKCS8PRIVATEKEYINFO
    6163{
     
    6668    /** The private key algorithm. */
    6769    RTCRX509ALGORITHMIDENTIFIER PrivateKeyAlgorithm;
    68     /** The private key. */
     70    /** The private key, according to PrivateKeyAlgorithm.
     71     * For RSA there is RSAPrivateKey (in BER encoding) embedded in this string. */
    6972    RTASN1OCTETSTRING           PrivateKey;
    7073    /** Attributes, optional [0].
     
    8285/**
    8386 * PKCS\#8 EncryptedPrivateKeyInfo.
     87 *
     88 * See RFC-5208 section 6.
    8489 */
    8590typedef struct RTCRENCRYPTEDPRIVATEKEY
  • trunk/include/iprt/mangling.h

    r100490 r100493  
    43214321# define g_aRTCrPkcs7Markers                            RT_MANGLER(g_aRTCrPkcs7Markers)
    43224322# define g_cRTCrPkcs7Markers                            RT_MANGLER(g_cRTCrPkcs7Markers)
    4323 # define g_rTCrPkcs8PrivateKeyInfo_Vtable               RT_MANGLER(g_rTCrPkcs8PrivateKeyInfo_Vtable)
     4323# define g_RTCrPkcs8PrivateKeyInfo_Vtable               RT_MANGLER(g_RTCrPkcs8PrivateKeyInfo_Vtable)
    43244324# define g_aRTCrX509CertificateMarkers                  RT_MANGLER(g_aRTCrX509CertificateMarkers)
    43254325# define g_cRTCrX509CertificateMarkers                  RT_MANGLER(g_cRTCrX509CertificateMarkers)
  • trunk/src/VBox/Runtime/Makefile.kmk

    r100442 r100493  
    37193719        common/crypto/pkcs7-sanity.cpp \
    37203720        common/crypto/pkcs7-verify.cpp \
    3721         common/crypto/pkcs8-asn1-decoder.cpp \
    3722         common/crypto/pkcs8-core.cpp \
    3723         common/crypto/pkcs8-init.cpp \
    3724         common/crypto/pkcs8-sanity.cpp \
    37253721        common/crypto/pkix-signature-builtin.cpp \
    37263722        common/crypto/pkix-signature-core.cpp \
     
    38763872        common/crypto/pkcs7-sanity.cpp \
    38773873        common/crypto/pkcs7-verify.cpp \
    3878         common/crypto/pkcs8-asn1-decoder.cpp \
    3879         common/crypto/pkcs8-core.cpp \
    3880         common/crypto/pkcs8-init.cpp \
    3881         common/crypto/pkcs8-sanity.cpp \
    38823874        common/crypto/pkix-signature-builtin.cpp \
    38833875        common/crypto/pkix-signature-core.cpp \
  • trunk/src/VBox/Runtime/common/crypto/key-file.cpp

    r100421 r100493  
    471471
    472472        case kKeyFormat_PrivateKeyInfo:
     473        {
    473474            RTAsn1CursorInitPrimary(&PrimaryCursor, pSection->pbData, (uint32_t)pSection->cbData,
    474475                                    pErrInfo, &g_RTAsn1DefaultAllocator, RTASN1CURSOR_FLAGS_DER, pszErrorTag);
     
    479480            if (RT_SUCCESS(rc))
    480481            {
    481                 /*
    482                  * Check if the algorithm is pkcs1-RsaEncryption
     482                /*
     483                 * Load the private key according to it's algorithm.
     484                 * We currently only support RSA (pkcs1-RsaEncryption).
    483485                 */
    484                 if (strcmp(PrivateKeyInfo.PrivateKeyAlgorithm.Algorithm.szObjId,"1.2.840.113549.1.1.1") == 0)
    485                 {
    486                     uint32_t cbContent = PrivateKeyInfo.PrivateKey.Asn1Core.cb;
    487                     rc = rtCrKeyCreateRsaPrivate(phKey, PrivateKeyInfo.PrivateKey.Asn1Core.uData.pv, cbContent, pErrInfo, pszErrorTag);
    488                 }
     486                if (RTAsn1ObjId_CompareWithString(&PrivateKeyInfo.PrivateKeyAlgorithm.Algorithm,
     487                                                  RTCRX509ALGORITHMIDENTIFIERID_RSA) == 0)
     488                    rc = rtCrKeyCreateRsaPrivate(phKey, PrivateKeyInfo.PrivateKey.Asn1Core.uData.pv,
     489                                                 PrivateKeyInfo.PrivateKey.Asn1Core.cb, pErrInfo, pszErrorTag);
    489490                else
    490                 {
    491491                    rc = RTErrInfoSet(pErrInfo, VERR_CR_KEY_FORMAT_NOT_SUPPORTED,
    492                                     "Support for PKCS#8 PrivateKeyInfo (with no RSA encryption) is not yet implemented");
    493                 }
     492                                      "Support for PKCS#8 PrivateKeyInfo for non-RSA keys is not yet implemented");
    494493            }
    495494            break;
     495        }
    496496
    497497        case kKeyFormat_EncryptedPrivateKeyInfo:
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-internal.h

    r100421 r100493  
    4141#endif
    4242
    43 /** The max number of bits we support in the modulus. */
    44 #define RTCRRSA_MAX_MODULUS_BITS        16384
    45 
    4643#define RTASN1TMPL_TEMPLATE_FILE "../common/crypto/pkcs8-template.h"
    4744#include <iprt/asn1-generator-internal-header.h>
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-template.h

    r100421 r100493  
    4242#define RTASN1TMPL_TYPE         RTCRPKCS8PRIVATEKEYINFO
    4343#define RTASN1TMPL_EXT_NAME     RTCrPkcs8PrivateKeyInfo
    44 #define RTASN1TMPL_INT_NAME     rTCrPkcs8PrivateKeyInfo
     44#define RTASN1TMPL_INT_NAME     RTCrPkcs8PrivateKeyInfo
    4545RTASN1TMPL_BEGIN_SEQCORE();
    4646RTASN1TMPL_MEMBER(              Version,                RTASN1INTEGER,                  RTAsn1Integer);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette