CACCAPIRaw.cpp File Reference


Detailed Description

Subsystem: Cryptography (PKIFCRYPTO)

Module: CPKIFCAPIRaw

Id
CACCAPIRaw.cpp 11101 2010-01-06 15:03:00Z cwallace

Definition in file CACCAPIRaw.cpp.

#include "PKIFCAPIRaw.h"
#include "PKIFCAPICryptContext2.h"
#include "PKIFCAPIHashContext.h"
#include "CAPIUtils.h"
#include "PKIFCryptoException.h"
#include "PKIFKeyMaterial.h"
#include "PKIFCryptoErrors.h"
#include "PKIFCAPIErrors.h"
#include "CAPIRawCryptContext.h"
#include "PKIFAlgorithm.h"
#include "AlgorithmIdentifier.h"
#include "Buffer.h"
#include "Certificate.h"
#include "ToolkitUtils.h"
#include "components.h"
#include "PKIFException.h"
#include "SubjectPublicKeyInfo.h"
#include "ASN1Helper.h"
#include "PKIX1Algorithms88.h"
#include <iostream>
#include <sstream>

Include dependency graph for CACCAPIRaw.cpp:

Go to the source code of this file.

Defines

#define ALG_SID_SHA_256   12
#define ALG_SID_SHA_384   13
#define ALG_SID_SHA_512   14
#define CALG_SHA_256   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)
#define CALG_SHA_384   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)
#define CALG_SHA_512   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)
#define CLEANUP
#define CLEANUP
#define CLEANUP

Functions

ALG_ID GetSymAlgorithm (const CPKIFKeyMaterial &key)
DWORD GetProvType (PCCERT_CONTEXT cert)
DWORD GetProvType (const char *oidString)
HCRYPTHASH CreateHashObjectFromData (HCRYPTPROV hProv, unsigned char *pHashData, int nHashDataLen)
bool _Verify (const CPKIFKeyMaterial &key, unsigned char *pHashData, int nHashDataLen, unsigned char *pSignature, int nSignatureLen)

Variables

CAC_API char g_defCACCAPITrustStore [] = "Root"
 defined(ALG_SID_SHA_256)


Define Documentation

#define ALG_SID_SHA_256   12

Definition at line 38 of file CACCAPIRaw.cpp.

#define ALG_SID_SHA_384   13

Definition at line 39 of file CACCAPIRaw.cpp.

#define ALG_SID_SHA_512   14

Definition at line 40 of file CACCAPIRaw.cpp.

#define CALG_SHA_256   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256)

Definition at line 42 of file CACCAPIRaw.cpp.

Referenced by CPKIFCAPIRaw::HashInit().

#define CALG_SHA_384   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384)

Definition at line 43 of file CACCAPIRaw.cpp.

Referenced by CPKIFCAPIRaw::HashInit().

#define CALG_SHA_512   (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512)

Definition at line 44 of file CACCAPIRaw.cpp.

Referenced by CPKIFCAPIRaw::HashInit().

#define CLEANUP

Value:

{ \
    if (capiSpki.Algorithm.Parameters.cbData)  \
    {   delete[] capiSpki.Algorithm.Parameters.pbData; capiSpki.Algorithm.Parameters.pbData = NULL; capiSpki.Algorithm.Parameters.cbData = 0;}  \
    if (clearParams)  \
    {   delete[] cert->pCertInfo->SubjectPublicKeyInfo.Algorithm.Parameters.pbData; cert->pCertInfo->SubjectPublicKeyInfo.Algorithm.Parameters.pbData = NULL; cert->pCertInfo->SubjectPublicKeyInfo.Algorithm.Parameters.cbData = 0;}  \
    if (NULL != cert)  \
    {   CertFreeCertificateContext(cert); cert = NULL; }  \
    if (NULL != hHash)  \
    {   CryptDestroyHash(hHash); hHash = NULL; }  \
    if (NULL != hKey)  \
    {   CryptDestroyKey(hKey); hKey = NULL; }  \
    if (NULL != hProv)  \
    {   CryptReleaseContext(hProv, 0); hProv = NULL; }  \
}

#define CLEANUP

Value:

{ \
    if (NULL != hHash)  \
    {   CryptDestroyHash(hHash); hHash = NULL; }  \
}

#define CLEANUP

Value:

{ \
    if (NULL != hSessionKey)  \
    {   BOOL succ = CryptDestroyKey(hSessionKey); hSessionKey = NULL;}  \
    if (NULL != hTmpProv)  \
    {   CryptReleaseContext(hTmpProv, 0); hTmpProv = NULL; }  \
    if (NULL != cert)  \
    {   CertFreeCertificateContext(cert); cert = NULL; }  \
}

Referenced by _Verify(), CreateHashObjectFromData(), CPKIFCAPI2::Decrypt(), GetCertfromLDAPURL(), CPKIFLDAPRepository::GetCertificates(), GetCRLfromLDAPURL(), CPKIFLDAPRepository::GetCRLs(), CPKIFCAPI2::MakeKeyID(), CPKIFCAPI2::Sign(), and CPKIFNSSRaw::VerifyCertificate().


Function Documentation

bool _Verify ( const CPKIFKeyMaterial key,
unsigned char *  pHashData,
int  nHashDataLen,
unsigned char *  pSignature,
int  nSignatureLen 
)

Interface: Module

This is a helper function called in Verify

Returns:
This function returns true if the signature verifies and false otherwise. Some errors can result in exceptions
Exceptions:
CPKIFCryptoException(PKIFCAPI_CREATE_CERT_FAILED) 
CPKIFCryptoException(PKIFCAPI_ACQUIRE_CONTEXT_FAILED) 
CPKIFCryptoException(PKIFCAPI_KEY_IMPORT_FAILED) 
CPKIFCryptoException(PKIFCAPI_KEY_MATERIAL_NOT_SUPPORTED) 
Parameters:
key  [in] Reference to a CPKIFKeyMaterial object containing key material to use when verifying the signature
pHashData  [in] Pointer to a buffer containing the message digest that was signed to produce the signature conveyed via the pSignature parameter
nHashDataLen  [in] Integer indicating the length of the value passed via the pHashData parameter
pSignature  [in] Pointer to a buffer containing the signature to verify
nSignatureLen  [in] Integer indicating the size of the value passed via the pSignature parameter

Definition at line 734 of file CACCAPIRaw.cpp.

References atob(), CACASNWRAPPER_CREATE, CLEANUP, CPKIFKeyMaterial::ContainsCertificate(), CPKIFKeyMaterial::ContainsPublicKeyMaterial(), CreateHashObjectFromData(), CPKIFKeyMaterial::GetCertificate(), CPKIFKeyMaterial::GetCertificateLength(), GetProvType(), CPKIFKeyMaterial::GetSubjectPublicKeyInfo(), CPKIFKeyMaterial::GetWorkingParameters(), LOG_STRING_DEBUG, MAXHASH, PKIFCAPI_ACQUIRE_CONTEXT_FAILED, PKIFCAPI_CREATE_CERT_FAILED, PKIFCAPI_KEY_IMPORT_FAILED, PKIFCAPI_KEY_MATERIAL_NOT_SUPPORTED, RAISE_CRYPTO_EXCEPTION, ReverseBytes(), TOOLKIT_CRYPTO, and TOOLKIT_CRYPTO_CAPIRAW.

Referenced by CPKIFNSSRaw::Verify(), CPKIFCryptoPPRaw::Verify(), CPKIFCAPIRaw::Verify(), CPKIFCryptoPPRaw::VerifyCertificate(), and VerifyCertificateWithCryptoPP().

HCRYPTHASH CreateHashObjectFromData ( HCRYPTPROV  hProv,
unsigned char *  pHashData,
int  nHashDataLen 
)

Interface: Module

This function creates a hash object from data

Returns:
This function returns HCRYPTHASH
Exceptions:
CPKIFCryptoException(PKIFCAPI_CREATE_HASH_FAILED) 
CPKIFCryptoException(PKIFCAPI_MISC_HASH_CALL_FAILED) 
Parameters:
hProv  CAPI Cryptographic privider
pHashData  [in] Pointer to a buffer containing the message digest that was signed to produce the signature conveyed via the pSignature parameter
nHashDataLen  [in] Integer indicating the length of the value passed via the pHashData parameter

Definition at line 660 of file CACCAPIRaw.cpp.

References CLEANUP, GetHashAlg(), LOG_STRING_DEBUG, PKIFCAPI_CREATE_HASH_FAILED, PKIFCAPI_MISC_HASH_CALL_FAILED, RAISE_CRYPTO_EXCEPTION, TOOLKIT_CRYPTO, and TOOLKIT_CRYPTO_CAPIRAW.

Referenced by _Verify().

DWORD GetProvType ( const char *  oidString  ) 

Interface: Module

This function is used to retrive provider type

Returns:
This function returns DWORD containing the provider type
Exceptions:
CPKIFCryptoException(CRYPTO_ALG_NOT_SUPPORTED) 
Parameters:
oidString  [in]Pointer to string representation of algorithm OID

Definition at line 249 of file CACCAPIRaw.cpp.

References CRYPTO_ALG_NOT_SUPPORTED, RAISE_CRYPTO_EXCEPTION, and TOOLKIT_CRYPTO_CAPIRAW.

DWORD GetProvType ( PCCERT_CONTEXT  cert  ) 

Interface: Module

This function is used to retrive provider type

Returns:
This function returns DWORD
Exceptions:
CPKIFCryptoException(CRYPTO_ALG_NOT_SUPPORTED) 
Parameters:
cert  [in]Certificate in PCCERT_CONTEXT format

Definition at line 225 of file CACCAPIRaw.cpp.

References CRYPTO_ALG_NOT_SUPPORTED, RAISE_CRYPTO_EXCEPTION, and TOOLKIT_CRYPTO_CAPIRAW.

Referenced by _Verify(), and CPKIFCAPIRaw::SupportsAlgorithm().

ALG_ID GetSymAlgorithm ( const CPKIFKeyMaterial key  ) 

Interface: Module

This function is used to retrive symmetric algorithm

Returns:
This function returns ALG_ID
Exceptions:
CPKIFCryptoException(CRYPTO_ALG_NOT_SUPPORTED) 
Parameters:
key  [in]CPKIFKeyMaterial object

Definition at line 194 of file CACCAPIRaw.cpp.

References CRYPTO_ALG_NOT_SUPPORTED, PKIFCRYPTO::DES, CPKIFKeyMaterial::GetSymmetricKeyAlgorithm(), RAISE_CRYPTO_EXCEPTION, PKIFCRYPTO::TDES, and TOOLKIT_CRYPTO.

Referenced by CPKIFCAPIRaw::CryptInit(), and CPKIFCAPIRaw::SupportsAlgorithm().


Variable Documentation

CAC_API char g_defCACCAPITrustStore[] = "Root"

defined(ALG_SID_SHA_256)

Definition at line 47 of file CACCAPIRaw.cpp.

Referenced by LoadStorageAndRetrievalComponents(), MakeDefaultMediator(), and SaveStorageAndRetrievalComponents().


Generated on Mon Nov 15 11:16:11 2010 for PublicKeyInfrastructureFramework(PKIF) by  doxygen 1.5.6