Beispiel #1
0
RTDECL(int) RTAsn1Core_CompareEx(PCRTASN1CORE pLeft, PCRTASN1CORE pRight, bool fIgnoreTagAndClass)
{
    int iDiff;
    if (RTASN1CORE_IS_PRESENT(pLeft))
    {
        if (RTASN1CORE_IS_PRESENT(pRight))
        {
            iDiff = memcmp(pLeft->uData.pv, pRight->uData.pv, RT_MIN(pLeft->cb, pRight->cb));
            if (!iDiff)
            {
                if (pLeft->cb != pRight->cb)
                    iDiff = pLeft->cb < pRight->cb ? -1 : 1;
                else if (!fIgnoreTagAndClass)
                {
                    if (pLeft->uTag != pRight->uTag)
                        iDiff = pLeft->uTag < pRight->uTag ? -1 : 1;
                    else if (pLeft->fClass != pRight->fClass)
                        iDiff = pLeft->fClass < pRight->fClass ? -1 : 1;
                }
            }
            else
                iDiff = iDiff < 0 ? -1 : 1;
        }
        else
            iDiff = -1;
    }
    else
        iDiff = 0 - (int)RTASN1CORE_IS_PRESENT(pRight);
    return iDiff;
}
Beispiel #2
0
RTDECL(int) RTAsn1Core_Compare(PCRTASN1CORE pLeft, PCRTASN1CORE pRight)
{
    Assert(pLeft  && (!RTASN1CORE_IS_PRESENT(pLeft)  || pLeft->pOps  == &g_RTAsn1Core_Vtable));
    Assert(pRight && (!RTASN1CORE_IS_PRESENT(pRight) || pRight->pOps == &g_RTAsn1Core_Vtable));

    return RTAsn1Core_CompareEx(pLeft, pRight, false /*fIgnoreTagAndClass*/);
}
Beispiel #3
0
static int rtAsn1Core_CloneEx(PRTASN1CORE pThis, PCRTASN1CORE pSrc, PCRTASN1ALLOCATORVTABLE pAllocator, bool fCopyContent)
{
    Assert(RTASN1CORE_IS_PRESENT(pSrc));
    pThis->uTag         = pSrc->uTag;
    pThis->fClass       = pSrc->fClass;
    pThis->uRealTag     = pSrc->uRealTag;
    pThis->fRealClass   = pSrc->fRealClass;
    pThis->cbHdr        = pSrc->cbHdr;
    pThis->fFlags       = pSrc->fFlags & ~(RTASN1CORE_F_ALLOCATED_CONTENT | RTASN1CORE_F_DECODED_CONTENT);
    pThis->pOps         = pSrc->pOps;
    pThis->cb           = 0;
    pThis->uData.pv     = NULL;
    if (pSrc->cb)
    {
        if (!fCopyContent)
            pThis->cb = pSrc->cb;
        else
        {
            int rc = RTAsn1ContentDup(pThis, pSrc->uData.pv, pSrc->cb, pAllocator);
            if (RT_FAILURE(rc))
            {
                RT_ZERO(*pThis);
                return rc;
            }
            Assert(pThis->cb == pSrc->cb);
            AssertPtr(pThis->uData.pv);
        }
    }
    return VINF_SUCCESS;
}
Beispiel #4
0
RTDECL(int) RTAsn1Core_Enum(PRTASN1CORE pThis, PFNRTASN1ENUMCALLBACK pfnCallback, uint32_t uDepth, void *pvUser)
{
    /* We have no children to enumerate. */
    Assert(pThis && (!RTASN1CORE_IS_PRESENT(pThis) || pThis->pOps == &g_RTAsn1Core_Vtable));
    NOREF(pThis);
    NOREF(pfnCallback);
    NOREF(uDepth);
    NOREF(pvUser);
    return VINF_SUCCESS;
}
Beispiel #5
0
RTDECL(void) RTAsn1Core_Delete(PRTASN1CORE pThis)
{
    if (pThis && RTASN1CORE_IS_PRESENT(pThis))
    {
        Assert(pThis->pOps == &g_RTAsn1Core_Vtable);

        RTAsn1ContentFree(pThis);
        RT_ZERO(*pThis);
    }
}
Beispiel #6
0
RTDECL(int) RTAsn1Core_Clone(PRTASN1CORE pThis, PCRTASN1CORE pSrc, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    int rc;
    RT_ZERO(*pThis);
    if (RTASN1CORE_IS_PRESENT(pSrc))
    {
        Assert(pSrc->pOps == &g_RTAsn1Core_Vtable);

        rc = RTAsn1Core_CloneContent(pThis, pSrc, pAllocator);
    }
    else
        rc = VINF_SUCCESS;
    return rc;
}
RTDECL(int) RTCrPkixSignatureCreate(PRTCRPKIXSIGNATURE phSignature, PCRTCRPKIXSIGNATUREDESC pDesc, void *pvOpaque,
                                    bool fSigning, PCRTASN1BITSTRING pKey, PCRTASN1DYNTYPE pParams)
{
    /*
     * Validate input.
     */
    AssertPtrReturn(phSignature, VERR_INVALID_POINTER);
    AssertPtrReturn(pDesc, VERR_INVALID_POINTER);
    AssertPtrReturn(pKey, VERR_INVALID_POINTER);
    AssertReturn(RTAsn1BitString_IsPresent(pKey), VERR_INVALID_PARAMETER);
    if (pParams)
    {
        AssertPtrReturn(pParams, VERR_INVALID_POINTER);
        if (   pParams->enmType == RTASN1TYPE_NULL
            || !RTASN1CORE_IS_PRESENT(&pParams->u.Core))
            pParams = NULL;
    }

    /*
     * Instantiate the algorithm for the given operation.
     */
    int rc = VINF_SUCCESS;
    PRTCRPKIXSIGNATUREINT pThis = (PRTCRPKIXSIGNATUREINT)RTMemAllocZ(RT_OFFSETOF(RTCRPKIXSIGNATUREINT, abState[pDesc->cbState]));
    if (pThis)
    {
        pThis->u32Magic     = RTCRPKIXSIGNATUREINT_MAGIC;
        pThis->cRefs        = 1;
        pThis->pDesc        = pDesc;
        pThis->fSigning     = fSigning;
        pThis->uState       = RTCRPKIXSIGNATURE_STATE_READY;
        if (pDesc->pfnInit)
            rc = pDesc->pfnInit(pDesc, pThis->abState, pvOpaque, fSigning, pKey, pParams);
        if (RT_SUCCESS(rc))
        {
            *phSignature = pThis;
            return VINF_SUCCESS;
        }
        pThis->u32Magic = 0;
        RTMemFree(pThis);
    }
    else
        rc = VERR_NO_MEMORY;
    return rc;

}
Beispiel #8
0
RTDECL(int) RTCrX509Certificate_VerifySignatureSelfSigned(PCRTCRX509CERTIFICATE pThis, PRTERRINFO pErrInfo)
{
    /*
     * Validate the input a little.
     */
    AssertPtrReturn(pThis, VERR_INVALID_POINTER);
    AssertReturn(RTCrX509Certificate_IsPresent(pThis), VERR_INVALID_PARAMETER);

    /*
     * Assemble parameters for the generic verification call.
     */
    PCRTCRX509TBSCERTIFICATE const pTbsCert    = &pThis->TbsCertificate;
    PCRTASN1DYNTYPE                pParameters = NULL;
    if (   RTASN1CORE_IS_PRESENT(&pTbsCert->SubjectPublicKeyInfo.Algorithm.Parameters.u.Core)
        && pTbsCert->SubjectPublicKeyInfo.Algorithm.Parameters.enmType != RTASN1TYPE_NULL)
        pParameters = &pTbsCert->SubjectPublicKeyInfo.Algorithm.Parameters;
    return RTCrX509Certificate_VerifySignature(pThis, &pTbsCert->SubjectPublicKeyInfo.Algorithm.Algorithm, pParameters,
                                               &pTbsCert->SubjectPublicKeyInfo.SubjectPublicKey, pErrInfo);
}