VirtualBox

Changeset 100421 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Jul 6, 2023 7:24:56 PM (20 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158161
Message:

IPRT/PKCS8: add key format for PKCS #8 bugref:10299

Location:
trunk/src/VBox/Runtime/common/crypto
Files:
1 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/crypto/key-file.cpp

    r98103 r100421  
    5252#include <iprt/string.h>
    5353#include <iprt/crypto/rsa.h>
     54#include <iprt/crypto/pkcs8.h>
    5455#include <iprt/crypto/pkix.h>
    5556#include <iprt/crypto/x509.h>
     
    470471
    471472        case kKeyFormat_PrivateKeyInfo:
    472             rc = RTErrInfoSet(pErrInfo, VERR_CR_KEY_FORMAT_NOT_SUPPORTED,
    473                               "Support for PKCS#8 PrivateKeyInfo is not yet implemented");
     473            RTAsn1CursorInitPrimary(&PrimaryCursor, pSection->pbData, (uint32_t)pSection->cbData,
     474                                    pErrInfo, &g_RTAsn1DefaultAllocator, RTASN1CURSOR_FLAGS_DER, pszErrorTag);
     475            RTCRPKCS8PRIVATEKEYINFO PrivateKeyInfo;
     476            RT_ZERO(PrivateKeyInfo);
     477            rc = RTCrPkcs8PrivateKeyInfo_DecodeAsn1(&PrimaryCursor.Cursor, 0, &PrivateKeyInfo,
     478                                                    pszErrorTag ? pszErrorTag : "PrivateKeyInfo");
     479            if (RT_SUCCESS(rc))
     480            {
     481                /*
     482                 * Check if the algorithm is pkcs1-RsaEncryption
     483                 */
     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                }
     489                else
     490                {
     491                    rc = RTErrInfoSet(pErrInfo, VERR_CR_KEY_FORMAT_NOT_SUPPORTED,
     492                                    "Support for PKCS#8 PrivateKeyInfo (with no RSA encryption) is not yet implemented");
     493                }
     494            }
    474495            break;
    475496
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-asn1-decoder.cpp

    r99258 r100421  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Crypto - RSA, Decoder for ASN.1.
     3 * IPRT - Crypto - PKCS \#8, Decoder for ASN.1.
    44 */
    55
     
    4040*********************************************************************************************************************************/
    4141#include "internal/iprt.h"
    42 #include <iprt/crypto/rsa.h>
     42#include <iprt/crypto/pkcs8.h>
    4343
    4444#include <iprt/errcore.h>
    4545#include <iprt/string.h>
    4646
    47 #include "rsa-internal.h"
     47#include "pkcs8-internal.h"
    4848
    4949/*
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-core.cpp

    r99258 r100421  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Crypto - RSA, Core APIs.
     3 * IPRT - Crypto - PKCS \#8, Core APIs.
    44 */
    55
     
    4040*********************************************************************************************************************************/
    4141#include "internal/iprt.h"
    42 #include <iprt/crypto/rsa.h>
     42#include <iprt/crypto/pkcs8.h>
    4343
    4444#include <iprt/errcore.h>
     
    4646#include <iprt/string.h>
    4747
    48 #include "rsa-internal.h"
     48#include "pkcs8-internal.h"
    4949
    5050/*
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-init.cpp

    r99258 r100421  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Crypto - RSA, Initialization API.
     3 * IPRT - Crypto - PKCS \#8, Initialization API.
    44 */
    55
     
    4040*********************************************************************************************************************************/
    4141#include "internal/iprt.h"
    42 #include <iprt/crypto/rsa.h>
     42#include <iprt/crypto/pkcs8.h>
    4343
    4444#include <iprt/errcore.h>
    4545#include <iprt/string.h>
    4646
    47 #include "rsa-internal.h"
     47#include "pkcs8-internal.h"
    4848
    4949/*
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-internal.h

    r99258 r100421  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Crypto - RSA, Internal Header.
     3 * IPRT - Crypto - PKCS \#8, Internal Header.
    44 */
    55
     
    3535 */
    3636
    37 #ifndef IPRT_INCLUDED_SRC_common_crypto_rsa_internal_h
    38 #define IPRT_INCLUDED_SRC_common_crypto_rsa_internal_h
     37#ifndef IPRT_INCLUDED_SRC_common_crypto_pkcs8_internal_h
     38#define IPRT_INCLUDED_SRC_common_crypto_pkcs8_internal_h
    3939#ifndef RT_WITHOUT_PRAGMA_ONCE
    4040# pragma once
     
    4444#define RTCRRSA_MAX_MODULUS_BITS        16384
    4545
    46 #define RTASN1TMPL_TEMPLATE_FILE "../common/crypto/rsa-template.h"
     46#define RTASN1TMPL_TEMPLATE_FILE "../common/crypto/pkcs8-template.h"
    4747#include <iprt/asn1-generator-internal-header.h>
    4848
    49 #endif /* !IPRT_INCLUDED_SRC_common_crypto_rsa_internal_h */
    50 
     49#endif /* !IPRT_INCLUDED_SRC_common_crypto_pkcs8_internal_h */
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-sanity.cpp

    r99258 r100421  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Crypto - RSA, Sanity Checkers.
     3 * IPRT - Crypto - PKCS \#8, Sanity Checkers.
    44 */
    55
     
    4040*********************************************************************************************************************************/
    4141#include "internal/iprt.h"
    42 #include <iprt/crypto/rsa.h>
     42#include <iprt/crypto/pkcs8.h>
    4343
    4444#include <iprt/errcore.h>
    4545#include <iprt/string.h>
    4646
    47 #include "rsa-internal.h"
     47#include "pkcs8-internal.h"
    4848
    4949/*
  • trunk/src/VBox/Runtime/common/crypto/pkcs8-template.h

    r99258 r100421  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Crypto - RSA, Code Generator Template.
     3 * IPRT - Crypto - PKCS \#8, Code Generator Template.
    44 */
    55
     
    3838
    3939/*
    40  * RSA public key.
     40 * PKCS\#8 Private key info
    4141 */
    42 #define RTASN1TMPL_TYPE         RTCRRSAPUBLICKEY
    43 #define RTASN1TMPL_EXT_NAME     RTCrRsaPublicKey
    44 #define RTASN1TMPL_INT_NAME     rtCrRsaPublicKey
     42#define RTASN1TMPL_TYPE         RTCRPKCS8PRIVATEKEYINFO
     43#define RTASN1TMPL_EXT_NAME     RTCrPkcs8PrivateKeyInfo
     44#define RTASN1TMPL_INT_NAME     rTCrPkcs8PrivateKeyInfo
    4545RTASN1TMPL_BEGIN_SEQCORE();
    46 RTASN1TMPL_MEMBER(              Modulus,            RTASN1INTEGER,                  RTAsn1Integer);
    47 RTASN1TMPL_MEMBER(              PublicExponent,     RTASN1INTEGER,                  RTAsn1Integer);
     46RTASN1TMPL_MEMBER(              Version,                RTASN1INTEGER,                  RTAsn1Integer);
     47RTASN1TMPL_MEMBER(              PrivateKeyAlgorithm,    RTCRX509ALGORITHMIDENTIFIER,    RTCrX509AlgorithmIdentifier);
     48RTASN1TMPL_MEMBER(              PrivateKey,             RTASN1OCTETSTRING,              RTAsn1OctetString);
     49RTASN1TMPL_MEMBER_OPT_ITAG(     Attributes,             RTCRPKCS7ATTRIBUTES,            RTCrPkcs7Attributes,     0);
    4850RTASN1TMPL_END_SEQCORE();
    4951#undef RTASN1TMPL_TYPE
     
    5153#undef RTASN1TMPL_INT_NAME
    5254
     55#if 0
    5356
    5457/*
    55  * One RSA other prime info.
     58 * Encrypted private key info
    5659 */
    57 #define RTASN1TMPL_TYPE         RTCRRSAOTHERPRIMEINFO
    58 #define RTASN1TMPL_EXT_NAME     RTCrRsaOtherPrimeInfo
    59 #define RTASN1TMPL_INT_NAME     rtCrRsaOtherPrimeInfo
     60#define RTASN1TMPL_TYPE         RTCRENCRYPTEDPRIVATEKEY
     61#define RTASN1TMPL_EXT_NAME     RTCrEncryptedPrivateKey
     62#define RTASN1TMPL_INT_NAME     rtCrEncryptedPrivateKey
    6063RTASN1TMPL_BEGIN_SEQCORE();
    61 RTASN1TMPL_MEMBER(              Prime,              RTASN1INTEGER,                  RTAsn1Integer);
    62 RTASN1TMPL_MEMBER(              Exponent,           RTASN1INTEGER,                  RTAsn1Integer);
    63 RTASN1TMPL_MEMBER(              Coefficient,        RTASN1INTEGER,                  RTAsn1Integer);
     64RTASN1TMPL_MEMBER(              EncryptionAlgorithm,    RTCRX509ALGORITHMIDENTIFIER,    RTCrX509AlgorithmIdentifier);
     65RTASN1TMPL_MEMBER(              EncryptedData,          RTASN1OCTETSTRING,              RTAsn1OctetString);
    6466RTASN1TMPL_END_SEQCORE();
    6567#undef RTASN1TMPL_TYPE
     
    6769#undef RTASN1TMPL_INT_NAME
    6870
    69 
    70 /*
    71  * Sequence of RSA other prime infos.
    72  */
    73 #define RTASN1TMPL_TYPE         RTCRRSAOTHERPRIMEINFOS
    74 #define RTASN1TMPL_EXT_NAME     RTCrRsaOtherPrimeInfos
    75 #define RTASN1TMPL_INT_NAME     rtCrRsaOtherPrimeInfos
    76 RTASN1TMPL_SEQ_OF(RTCRRSAOTHERPRIMEINFO, RTCrRsaOtherPrimeInfo);
    77 #undef RTASN1TMPL_TYPE
    78 #undef RTASN1TMPL_EXT_NAME
    79 #undef RTASN1TMPL_INT_NAME
    80 
    81 
    82 /*
    83  * RSA private key.
    84  */
    85 #define RTASN1TMPL_TYPE         RTCRRSAPRIVATEKEY
    86 #define RTASN1TMPL_EXT_NAME     RTCrRsaPrivateKey
    87 #define RTASN1TMPL_INT_NAME     rtCrRsaPrivateKey
    88 RTASN1TMPL_BEGIN_SEQCORE();
    89 RTASN1TMPL_MEMBER(              Version,            RTASN1INTEGER,                  RTAsn1Integer);
    90 RTASN1TMPL_MEMBER(              Modulus,            RTASN1INTEGER,                  RTAsn1Integer);
    91 RTASN1TMPL_MEMBER(              PublicExponent,     RTASN1INTEGER,                  RTAsn1Integer);
    92 RTASN1TMPL_MEMBER(              PrivateExponent,    RTASN1INTEGER,                  RTAsn1Integer);
    93 RTASN1TMPL_MEMBER(              Prime1,             RTASN1INTEGER,                  RTAsn1Integer);
    94 RTASN1TMPL_MEMBER(              Prime2,             RTASN1INTEGER,                  RTAsn1Integer);
    95 RTASN1TMPL_MEMBER(              Exponent1,          RTASN1INTEGER,                  RTAsn1Integer);
    96 RTASN1TMPL_MEMBER(              Exponent2,          RTASN1INTEGER,                  RTAsn1Integer);
    97 RTASN1TMPL_MEMBER(              Coefficient,        RTASN1INTEGER,                  RTAsn1Integer);
    98 RTASN1TMPL_MEMBER_OPT_ITAG_EX(  OtherPrimeInfos,    RTCRRSAOTHERPRIMEINFOS,         RTCrRsaOtherPrimeInfos, ASN1_TAG_SEQUENCE, RTASN1TMPL_ITAG_F_UC,  RT_NOTHING);
    99 RTASN1TMPL_END_SEQCORE();
    100 #undef RTASN1TMPL_TYPE
    101 #undef RTASN1TMPL_EXT_NAME
    102 #undef RTASN1TMPL_INT_NAME
    103 
    104 
    105 /*
    106  * RSA Digest Info.
    107  */
    108 #define RTASN1TMPL_TYPE         RTCRRSADIGESTINFO
    109 #define RTASN1TMPL_EXT_NAME     RTCrRsaDigestInfo
    110 #define RTASN1TMPL_INT_NAME     rtCrRsaDigestInfo
    111 RTASN1TMPL_BEGIN_SEQCORE();
    112 RTASN1TMPL_MEMBER(              DigestAlgorithm,    RTCRX509ALGORITHMIDENTIFIER,    RTCrX509AlgorithmIdentifier);
    113 RTASN1TMPL_MEMBER(              Digest,             RTASN1OCTETSTRING,              RTAsn1OctetString);
    114 RTASN1TMPL_END_SEQCORE();
    115 #undef RTASN1TMPL_TYPE
    116 #undef RTASN1TMPL_EXT_NAME
    117 #undef RTASN1TMPL_INT_NAME
    118 
     71#endif
Note: See TracChangeset for help on using the changeset viewer.

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