VirtualBox

Changeset 73662 in vbox


Ignore:
Timestamp:
Aug 14, 2018 4:13:43 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/ASN.1: Added g_RTAsn1EFenceAllocator and RTAsn1CursorIsEnd.

Location:
trunk
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asn1.h

    r69105 r73662  
    158158extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1EFenceAllocator;
    159159
     160/** The safer ASN.1 allocator for sensitive data. */
     161extern RTDATADECL(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocator;
     162
    160163
    161164/**
     
    17561759 * Checks that we've reached the end of the data for the cursor.
    17571760 *
     1761 * This differs from RTAsn1CursorCheckEnd in that it does not consider the end
     1762 * an error and therefore leaves the error buffer alone.
     1763 *
     1764 * @returns True if end, otherwise false.
     1765 * @param   pCursor             The cursor we're decoding from.
     1766 */
     1767RTDECL(bool) RTAsn1CursorIsEnd(PRTASN1CURSOR pCursor);
     1768
     1769/**
     1770 * Checks that we've reached the end of the data for the cursor.
     1771 *
    17581772 * @returns IPRT status code.
    17591773 * @param   pCursor             The cursor we're decoding from.
  • trunk/include/iprt/mangling.h

    r73587 r73662  
    27542754# define RTAsn1CursorInitSubFromCore                    RT_MANGLER(RTAsn1CursorInitSubFromCore)
    27552755# define RTAsn1CursorIsNextEx                           RT_MANGLER(RTAsn1CursorIsNextEx)
     2756# define RTAsn1CursorIsEnd                              RT_MANGLER(RTAsn1CursorIsEnd)
    27562757# define RTAsn1CursorMatchTagClassFlagsEx               RT_MANGLER(RTAsn1CursorMatchTagClassFlagsEx)
    27572758# define RTAsn1CursorPeek                               RT_MANGLER(RTAsn1CursorPeek)
     
    32503251# define RTCrPkixSignatureVerifyOctetString             RT_MANGLER(RTCrPkixSignatureVerifyOctetString)
    32513252# define RTCrPkixGetCiperOidFromSignatureAlgorithm      RT_MANGLER(RTCrPkixGetCiperOidFromSignatureAlgorithm)
     3253# define RTCrPkixPubKeySignDigest                       RT_MANGLER(RTCrPkixPubKeySignDigest)
    32523254# define RTCrPkixPubKeyVerifySignature                  RT_MANGLER(RTCrPkixPubKeyVerifySignature)
    32533255# define RTCrPkixPubKeyVerifySignedDigest               RT_MANGLER(RTCrPkixPubKeyVerifySignedDigest)
     3256# define RTCrPkixPubKeyVerifySignedDigestByCertPubKeyInfo RT_MANGLER(RTCrPkixPubKeyVerifySignedDigestByCertPubKeyInfo)
    32543257# define RTCrSpcAttributeTypeAndOptionalValue_DecodeAsn1 RT_MANGLER(RTCrSpcAttributeTypeAndOptionalValue_DecodeAsn1)
    32553258# define RTCrSpcIndirectDataContent_DecodeAsn1          RT_MANGLER(RTCrSpcIndirectDataContent_DecodeAsn1)
     
    35243527# define RTCrX509PolicyQualifierInfos_Clone             RT_MANGLER(RTCrX509PolicyQualifierInfos_Clone)
    35253528# define RTCrX509PolicyQualifierInfos_Init              RT_MANGLER(RTCrX509PolicyQualifierInfos_Init)
     3529# define RTCrRsaPrivateKey_ReadFromFile                 RT_MANGLER(RTCrRsaPrivateKey_ReadFromFile)
     3530# define RTCrRsaPrivateKey_ReadFromBuffer               RT_MANGLER(RTCrRsaPrivateKey_ReadFromBuffer)
     3531# define RTCrRsaPublicKey_ReadFromFile                  RT_MANGLER(RTCrRsaPublicKey_ReadFromFile)
     3532# define RTCrRsaPublicKey_ReadFromBuffer                RT_MANGLER(RTCrRsaPublicKey_ReadFromBuffer)
    35263533# define RTCrX509SubjectPublicKeyInfo_Clone             RT_MANGLER(RTCrX509SubjectPublicKeyInfo_Clone)
    35273534# define RTCrX509SubjectPublicKeyInfo_Init              RT_MANGLER(RTCrX509SubjectPublicKeyInfo_Init)
     
    37973804# define g_RTAsn1DefaultAllocator                       RT_MANGLER(g_RTAsn1DefaultAllocator)
    37983805# define g_RTAsn1EFenceAllocator                        RT_MANGLER(g_RTAsn1EFenceAllocator)
     3806# define g_RTAsn1SaferAllocator                         RT_MANGLER(g_RTAsn1SaferAllocator)
    37993807# define g_aRTCrX509CertificateMarkers                  RT_MANGLER(g_aRTCrX509CertificateMarkers)
    38003808# define g_cRTCrX509CertificateMarkers                  RT_MANGLER(g_cRTCrX509CertificateMarkers)
     3809# define g_aRTCrRsaPrivateKeyMarkers                    RT_MANGLER(g_aRTCrRsaPrivateKeyMarkers)
     3810# define g_cRTCrRsaPrivateKeyMarkers                    RT_MANGLER(g_cRTCrRsaPrivateKeyMarkers)
     3811# define g_aRTCrRsaPublicKeyMarkers                     RT_MANGLER(g_aRTCrRsaPublicKeyMarkers)
     3812# define g_cRTCrRsaPublicKeyMarkers                     RT_MANGLER(g_cRTCrRsaPublicKeyMarkers)
    38013813
    38023814#if 0 /* Disabled for now as I'm not sure the assmbler supports mangling yet. */
  • trunk/src/VBox/Runtime/common/asn1/asn1-cursor.cpp

    r69111 r73662  
    184184    va_end(va);
    185185    return rc;
     186}
     187
     188
     189RTDECL(bool) RTAsn1CursorIsEnd(PRTASN1CURSOR pCursor)
     190{
     191    return pCursor->cbLeft == 0;
    186192}
    187193
  • trunk/src/VBox/Runtime/common/asn1/asn1-safer-allocator.cpp

    r73643 r73662  
    11/* $Id$ */
    22/** @file
    3  * IPRT - ASN.1, Default Allocator.
     3 * IPRT - ASN.1, Safer Allocator, for sensitive data.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#include <iprt/asn1.h>
    3333
    34 #include <iprt/mem.h>
     34#include <iprt/memsafer.h>
    3535#include <iprt/err.h>
    3636#include <iprt/string.h>
     
    4343 * @param   cb                  Requested size.
    4444 */
    45 static size_t rtAsn1DefaultAllocator_AlignSize(size_t cb)
     45static size_t rtAsn1SaferAllocator_AlignSize(size_t cb)
    4646{
    4747    if (cb >= 64)
     
    5656
    5757/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnFree} */
    58 static DECLCALLBACK(void) rtAsn1DefaultAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv)
    59 {
    60     RT_NOREF_PV(pThis);
    61     RTMemFree(pv);
     58static DECLCALLBACK(void) rtAsn1SaferAllocator_Free(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation, void *pv)
     59{
     60    RT_NOREF_PV(pThis);
     61    RTMemSaferFree(pv, pAllocation->cbAllocated);
    6262    pAllocation->cbAllocated = 0;
    6363}
     
    6565
    6666/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnAlloc} */
    67 static DECLCALLBACK(int)  rtAsn1DefaultAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
    68                                                        void **ppv, size_t cb)
    69 {
    70     size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cb);
    71     void *pv = RTMemAllocZ(cbAlloc);
     67static DECLCALLBACK(int)  rtAsn1SaferAllocator_Alloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
     68                                                     void **ppv, size_t cb)
     69{
     70    size_t cbAlloc = rtAsn1SaferAllocator_AlignSize(cb);
     71    void *pv = RTMemSaferAllocZ(cbAlloc);
    7272    if (pv)
    7373    {
     
    8282
    8383/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnRealloc} */
    84 static DECLCALLBACK(int)  rtAsn1DefaultAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
    85                                                          void *pvOld, void **ppvNew, size_t cbNew)
     84static DECLCALLBACK(int)  rtAsn1SaferAllocator_Realloc(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ALLOCATION pAllocation,
     85                                                       void *pvOld, void **ppvNew, size_t cbNew)
    8686{
    8787    Assert(pvOld);
    8888    Assert(cbNew);
    89     size_t cbAlloc = rtAsn1DefaultAllocator_AlignSize(cbNew);
    90     void *pv = RTMemRealloc(pvOld, cbAlloc);
     89    size_t cbAlloc = rtAsn1SaferAllocator_AlignSize(cbNew);
     90    void *pv = RTMemSaferReallocZ(pAllocation->cbAllocated, pvOld, cbAlloc);
    9191    if (pv)
    9292    {
     
    101101
    102102/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnFreeArray} */
    103 static DECLCALLBACK(void) rtAsn1DefaultAllocator_FreeArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
    104                                                            void **papvArray)
     103static DECLCALLBACK(void) rtAsn1SaferAllocator_FreeArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
     104                                                         void **papvArray)
    105105{
    106106    RT_NOREF_PV(pThis);
     
    110110    uint32_t i = pAllocation->cEntriesAllocated;
    111111    while (i-- > 0)
    112         RTMemFree(papvArray[i]);
     112        RTMemSaferFree(papvArray[i], pAllocation->cbEntry);
    113113    RTMemFree(papvArray);
    114114
     
    119119
    120120/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnGrowArray} */
    121 static DECLCALLBACK(int) rtAsn1DefaultAllocator_GrowArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
     121static DECLCALLBACK(int) rtAsn1SaferAllocator_GrowArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
    122122                                                          void ***ppapvArray, uint32_t cMinEntries)
    123123{
     
    173173    {
    174174        void *pv;
    175         papvArray[pAllocation->cEntriesAllocated] = pv = RTMemAllocZ(pAllocation->cbEntry);
     175        papvArray[pAllocation->cEntriesAllocated] = pv = RTMemSaferAllocZ(pAllocation->cbEntry);
    176176        if (pv)
    177177            pAllocation->cEntriesAllocated++;
     
    187187
    188188/** @interface_method_impl{RTASN1ALLOCATORVTABLE,pfnShrinkArray} */
    189 static DECLCALLBACK(void) rtAsn1DefaultAllocator_ShrinkArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
     189static DECLCALLBACK(void) rtAsn1SaferAllocator_ShrinkArray(PCRTASN1ALLOCATORVTABLE pThis, PRTASN1ARRAYALLOCATION pAllocation,
    190190                                                             void ***ppapvArray, uint32_t cNew, uint32_t cCurrent)
    191191{
     
    198198    while (cNew < cCurrent)
    199199    {
     200        RTMemWipeThoroughly(papvArray[cNew], pAllocation->cbEntry, 3);
    200201        RT_BZERO(papvArray[cNew], pAllocation->cbEntry);
    201202        cNew++;
     
    205206
    206207
    207 /** The default ASN.1 allocator. */
     208/** The Safer ASN.1 allocator. */
    208209#if 1 || !defined(IN_RING3) || defined(DOXYGEN_RUNNING)
    209 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocator =
     210RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocator =
    210211#else
    211 RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1DefaultAllocatorDisabled =
     212RT_DECL_DATA_CONST(RTASN1ALLOCATORVTABLE const) g_RTAsn1SaferAllocatorDisabled =
    212213#endif
    213214{
    214     rtAsn1DefaultAllocator_Free,
    215     rtAsn1DefaultAllocator_Alloc,
    216     rtAsn1DefaultAllocator_Realloc,
    217     rtAsn1DefaultAllocator_FreeArray,
    218     rtAsn1DefaultAllocator_GrowArray,
    219     rtAsn1DefaultAllocator_ShrinkArray
     215    rtAsn1SaferAllocator_Free,
     216    rtAsn1SaferAllocator_Alloc,
     217    rtAsn1SaferAllocator_Realloc,
     218    rtAsn1SaferAllocator_FreeArray,
     219    rtAsn1SaferAllocator_GrowArray,
     220    rtAsn1SaferAllocator_ShrinkArray
    220221};
    221222
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