VirtualBox

Changeset 100421 in vbox


Ignore:
Timestamp:
Jul 6, 2023 7:24:56 PM (19 months ago)
Author:
vboxsync
Message:

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

Location:
trunk
Files:
1 added
3 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r100314 r100421  
    455455        common/crypto/pkcs7-sign.cpp \
    456456        common/crypto/pkcs7-verify.cpp \
     457        common/crypto/pkcs8-asn1-decoder.cpp \
     458        common/crypto/pkcs8-core.cpp \
     459        common/crypto/pkcs8-init.cpp \
     460        common/crypto/pkcs8-sanity.cpp \
    457461        common/crypto/pkix-sign.cpp \
    458462        common/crypto/pkix-signature-builtin.cpp \
     
    22982302        common/crypto/pkcs7-sanity.cpp \
    22992303        common/crypto/pkcs7-verify.cpp \
     2304        common/crypto/pkcs8-asn1-decoder.cpp \
     2305        common/crypto/pkcs8-core.cpp \
     2306        common/crypto/pkcs8-init.cpp \
     2307        common/crypto/pkcs8-sanity.cpp \
    23002308        common/crypto/pkix-signature-builtin.cpp \
    23012309        common/crypto/pkix-signature-core.cpp \
     
    37093717        common/crypto/pkcs7-sanity.cpp \
    37103718        common/crypto/pkcs7-verify.cpp \
     3719        common/crypto/pkcs8-asn1-decoder.cpp \
     3720        common/crypto/pkcs8-core.cpp \
     3721        common/crypto/pkcs8-init.cpp \
     3722        common/crypto/pkcs8-sanity.cpp \
    37113723        common/crypto/pkix-signature-builtin.cpp \
    37123724        common/crypto/pkix-signature-core.cpp \
     
    38623874        common/crypto/pkcs7-sanity.cpp \
    38633875        common/crypto/pkcs7-verify.cpp \
     3876        common/crypto/pkcs8-asn1-decoder.cpp \
     3877        common/crypto/pkcs8-core.cpp \
     3878        common/crypto/pkcs8-init.cpp \
     3879        common/crypto/pkcs8-sanity.cpp \
    38643880        common/crypto/pkix-signature-builtin.cpp \
    38653881        common/crypto/pkix-signature-core.cpp \
     
    49144930x509-template.o x509-template.obj: x509-core.o x509-asn1-decoder.o x509-sanity.o x509-init.o
    49154931pkcs7-template.o pkcs7-template.obj: pkcs7-core.o pkcs7-asn1-decoder.o pkcs7-sanity.o pkcs7-init.o
     4932pkcs8-template.o pkcs8-template.obj: pkcs8-core.o pkcs8-asn1-decoder.o pkcs8-sanity.o pkcs8-init.o
  • 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
  • trunk/src/VBox/Runtime/testcase/tstRTCrPkix-1.cpp

    r98103 r100421  
    255255        "-----END PUBLIC KEY-----\n",
    256256        "password"
     257    },
     258
     259    /*
     260     * PKCS8 Test Keys
     261     */
     262    {
     263        1024,
     264        "-----BEGIN PRIVATE KEY-----\n"
     265        "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAK4uHX+XRbLQ7dGm\n"
     266        "sE1IqNDi4Obf7WS2TwfklmterJvCMrN3DxDAFq9et5j8kFRtI0Lgbc6sVAxlSkaw\n"
     267        "+0LltbkC8JX0cjPSIlozzcZn+9dQ+m5rVLDl3AaV3kBLrYpnNggdTRiHuVbNPqZq\n"
     268        "0CNDMxCqHpqRjtIOuoKukcOZasD5AgMBAAECgYA4IlKNaTIkM+NBGshcz9rgHw4+\n"
     269        "OdKnD34e3BOCHOvh8s8mOWuYiV+GOy9OVa8qFlYz2mJpJe6cZBRw/d6sK53Jrzc1\n"
     270        "ULULW9YNqgkhdhTm0z8QolYjBU+qp9pAXhh29tCdMxgCWAsiVR9jsnFtPQX4QEmM\n"
     271        "9t+65ghTFQWtQXMqpQJBANly600i4GYoxvzvp67RvUkmnG47LvwuVRMwUAmAX6QP\n"
     272        "Ww5q6aJd9HnHttLsNHxgX49aVxgpFu2uJI2SwSV3qwMCQQDND2kty83UXW5RahIt\n"
     273        "BXAY8W60Itw6+bPLg3P4IixDCoHphnLqkz5ZT2NxxPsAPGeaFZDVyNs3Hgasnd8V\n"
     274        "V8VTAkEAi4KWgrvQmtqoqFkeDSRVvBwAmxxvja4wOQpzH1V0hy6u7fYcBWcgVg2T\n"
     275        "N4oCNpYiWTfNzxt1sXJb01UHhIFdfwJAO8ZiQpdGSMFzhwgEhFsxchPu0VPYHtjr\n"
     276        "MEgBZjOP83r8o7YtiXOimSYrNt7UzBzPlnry3V7PiCGYkHj0rqQHQQJBANi5N5X4\n"
     277        "g7dNDsE5i1B0JsQ4ru8qE60ZtoOOCwNjwiI/IIsMVW2KqhTBynEYLnWolkRRogEF\n"
     278        "ACoRRxUBhj9EefI=\n"
     279        "-----END PRIVATE KEY-----\n",
     280        "-----BEGIN PUBLIC KEY-----\n"
     281        "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuLh1/l0Wy0O3RprBNSKjQ4uDm\n"
     282        "3+1ktk8H5JZrXqybwjKzdw8QwBavXreY/JBUbSNC4G3OrFQMZUpGsPtC5bW5AvCV\n"
     283        "9HIz0iJaM83GZ/vXUPpua1Sw5dwGld5AS62KZzYIHU0Yh7lWzT6matAjQzMQqh6a\n"
     284        "kY7SDrqCrpHDmWrA+QIDAQAB\n"
     285        "-----END PUBLIC KEY-----\n",
     286        NULL
    257287    }
    258288};
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