asn1-cursor.cpp revision 4ee2f4fc8e99dc69ba5d63fd7dd3f52a38d0501e
/* $Id$ */
/** @file
* IPRT - ASN.1, Basic Operations.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define RT_STRICT
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** @def RTASN1_MAX_NESTING
* The maximum nesting depth we allow. This limit is enforced to avoid running
* out of stack due to malformed ASN.1 input.
*
* For reference, 'RTSignTool verify-exe RTSignTool.exe', requires a value of 15
* to work without hitting the limit for signatures with simple timestamps, and
*/
#ifdef IN_RING3
# define RTASN1_MAX_NESTING 64
#else
# define RTASN1_MAX_NESTING 32
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
RTDECL(PRTASN1CURSOR) RTAsn1CursorInitPrimary(PRTASN1CURSORPRIMARY pPrimaryCursor, void const *pvFirst, uint32_t cb,
const char *pszErrorTag)
{
return &pPrimaryCursor->Cursor;
}
RTDECL(int) RTAsn1CursorInitSub(PRTASN1CURSOR pParent, uint32_t cb, PRTASN1CURSOR pChild, const char *pszErrorTag)
{
pChild->abReserved[0] = 0;
return VINF_SUCCESS;
}
{
pChild->abReserved[0] = 0;
return VINF_SUCCESS;
}
{
if (pErrInfo)
{
/* Format the message. */
/* Add the prefixes. This isn't the fastest way, but it's the one
which eats the least stack. */
{
/* Make sure there is a ': '. */
bool fFirst = false;
{
{
pszBuf[0] = ':';
cbMove += 2;
fFirst = true;
}
}
/* Add the prefixes from the cursor chain. */
while (pCursor)
{
if (pCursor->pszErrorTag)
{
break;
if (!fFirst)
fFirst = false;
}
}
}
}
return rc;
}
{
return rc;
}
{
return VINF_SUCCESS;
}
RTDECL(PRTASN1ALLOCATION) RTAsn1CursorInitAllocation(PRTASN1CURSOR pCursor, PRTASN1ALLOCATION pAllocation)
{
pAllocation->cbAllocated = 0;
pAllocation->cReallocs = 0;
pAllocation->uReserved0 = 0;
return pAllocation;
}
RTDECL(int) RTAsn1CursorReadHdr(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, const char *pszErrorTag)
{
/*
* Initialize the return structure in case of failure.
*/
pAsn1Core->fRealClass = 0;
/*
* The header has at least two bytes: Type & length.
*/
{
/* Extended length field? */
{
{
/* Definite form. */
"%s: Extended BER length field longer than available data: %#x vs %#x (uTag=%#x)",
switch (cbEnc)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
cb = RT_MAKE_U32_FROM_U8(pCursor->pbCur[3], pCursor->pbCur[2], pCursor->pbCur[1], pCursor->pbCur[0]);
break;
default:
}
/* Check the length encoding efficiency (T-REC-X.690-200811 10.1, 9.1). */
{
if (cb <= 0x7f)
else cbNeeded = 4;
}
}
/* Indefinite form. */
else
}
/* Check if the length makes sense. */
"%s: BER value length out of bounds: %#x (max=%#x uTag=%#x)",
return VINF_SUCCESS;
}
"%s: Too little data left to form a valid BER header", pszErrorTag);
"%s: No more data reading BER header", pszErrorTag);
}
RTDECL(int) RTAsn1CursorMatchTagClassFlagsEx(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, uint32_t uTag, uint32_t fClass,
{
{
return VINF_SUCCESS;
if ( fString
{
return VINF_SUCCESS;
{
return VINF_SUCCESS;
"%s: Constructed %s only allowed for >1000 byte in CER encoding: cb=%#x uTag=%#x fClass=%#x",
}
"%s: DER encoding does not allow constructed %s (cb=%#x uTag=%#x fClass=%#x)",
}
}
{
return VINF_SUCCESS;
}
return RTAsn1CursorSetInfo(pCursor, pAsn1Core->uTag != uTag ? VERR_ASN1_CURSOR_TAG_MISMATCH : VERR_ASN1_CURSOR_TAG_FLAG_CLASS_MISMATCH,
}
static int rtAsn1CursorGetXxxxCursor(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t uTag, uint8_t fClass,
const char *pszErrorTag, const char *pszWhat)
{
if (RT_SUCCESS(rc))
{
rc = VINF_SUCCESS;
else if (fFlags & RTASN1CURSOR_GET_F_IMPLICIT)
{
rc = VINF_SUCCESS;
}
else
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
return rc;
}
{
return rtAsn1CursorGetXxxxCursor(pCursor, fFlags, ASN1_TAG_SEQUENCE, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED,
}
{
return rtAsn1CursorGetXxxxCursor(pCursor, fFlags, ASN1_TAG_SET, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED,
}
RTDECL(int) RTAsn1CursorGetContextTagNCursor(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t uExpectedTag,
{
return rtAsn1CursorGetXxxxCursor(pCursor, fFlags, uExpectedTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED,
}
{
return rc;
}
{
if (RT_SUCCESS(rc))
return false;
}
/** @name Legacy Interfaces.
* @{ */
RTDECL(int) RTAsn1CursorGetCore(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1CORE pAsn1Core, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetNull(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1NULL pNull, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetInteger(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1INTEGER pInteger, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetBoolean(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1BOOLEAN pBoolean, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetObjId(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OBJID pObjId, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetTime(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1TIME pTime, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetBitStringEx(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t cMaxBits, PRTASN1BITSTRING pBitString,
const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetBitString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1BITSTRING pBitString, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetOctetString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OCTETSTRING pOctetString,
const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetIa5String(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetUtf8String(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetBmpString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
{
}
RTDECL(int) RTAsn1CursorGetDynType(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1DYNTYPE pDynType, const char *pszErrorTag)
{
}
/** @} */