ValidationPolicy.cpp
Go to the documentation of this file.00001
00010 #include "ASN1Helper.h"
00011 #include "AlgorithmIdentifier.h"
00012 #include "Buffer.h"
00013 #include "OID.h"
00014 #include "CVRequest.h"
00015 #include "ValidationPolicy.h"
00016 #include "SCVPException.h"
00017 #include "PKCReference.h"
00018 #include "KeyUsage.h"
00019 #include "PolicyInformation.h"
00020 #include "private/SCVPUtils.h"
00021 #include <iostream>
00022
00023 #include "boost/filesystem/fstream.hpp"
00024 #include "boost/filesystem/operations.hpp"
00025 namespace fs = boost::filesystem;
00026
00027 using namespace std;
00028
00029
00030 #include "SCVP.h"
00031 #include "ToolkitUtils.h"
00032
00034
00035 struct CPKIFValidationPolicyImpl
00036 {
00037 std::bitset<3> m_indicators;
00038 CPKIFValidationPolRefPtr m_validationPolRef;
00039 CPKIFPolicyInformationListPtr m_initPolSet;
00040 CPKIFValidationAlgPtr m_validationAlg;
00041 CPKIFKeyUsageListPtr m_keyUsages;
00042 CPKIFOIDListPtr m_EKUs;
00043 CPKIFOIDListPtr m_SKUs;
00044 CPKIFPKCReferenceListPtr m_TAs;
00045 };
00046
00048
00056 CPKIFValidationPolicy::CPKIFValidationPolicy() :m_impl(new CPKIFValidationPolicyImpl)
00057 {
00058 LOG_STRING_DEBUG("CPKIFValidationPolicy::CPKIFValidationPolicy()", TOOLKIT_SCVP_ASN, 0, this);
00059
00060 }
00071 CPKIFValidationPolicy::CPKIFValidationPolicy(
00073 const CPKIFBufferPtr& valPol)
00074 :m_impl (new CPKIFValidationPolicyImpl)
00075 {
00076 if(valPol == (CPKIFBuffer*)NULL || 0 == valPol->GetLength())
00077 {
00078 throw CPKIFSCVPException(TOOLKIT_SCVP_ASN, COMMON_INVALID_INPUT);
00079 }
00080
00081 CACASNWRAPPER_CREATE(ValidationPolicy, objPDU);
00082 objPDU.Decode(valPol->GetBuffer(), valPol->GetLength());
00083
00084
00085 CPKIFOIDPtr algOID(new CPKIFOID(objPDU->validationPolRef.valPolId.subid, objPDU->validationPolRef.valPolId.numids));
00086
00087 CPKIFBufferPtr algParams;
00088 if(objPDU->validationPolRef.m.valPolParamsPresent == 1)
00089 {
00090 CPKIFBufferPtr tmpAlgParams(new CPKIFBuffer(objPDU->validationPolRef.valPolParams.data,
00091 objPDU->validationPolRef.valPolParams.numocts));
00092
00093 algParams = tmpAlgParams;
00094 }
00095 CPKIFValidationPolRefPtr valPolRef(new CPKIFValidationPolRef(algOID, algParams));
00096
00097 m_impl->m_validationPolRef = valPolRef;
00098
00099 if(0 < objPDU->m.userPolicySetPresent)
00100 {
00101 CPKIFPolicyInformationListPtr tmpuserPolicySet(new CPKIFPolicyInformationList());
00102 DListNode* cur = objPDU->userPolicySet.head;
00103 while(NULL != cur)
00104 {
00105 ASN1OBJID* tmp = (ASN1OBJID*)cur->data;
00106 CPKIFOIDPtr tmpOID(new CPKIFOID(tmp->subid, tmp->numids));
00107
00108 CPKIFPolicyInformationPtr tmpPolInfo(new CPKIFPolicyInformation(tmpOID));
00109 tmpuserPolicySet->push_back(tmpPolInfo);
00110
00111 cur = cur->next;
00112 }
00113 m_impl->m_initPolSet = tmpuserPolicySet;
00114 }
00115
00116 if(0 < objPDU->m.inhibitPolicyMappingPresent)
00117 {
00118 m_impl->m_indicators.set(POLICY_MAPPING);
00119 }
00120 if(0 < objPDU->m.requireExplicitPolicyPresent)
00121 {
00122 m_impl->m_indicators.set(EXPLICIT_POLICY);
00123 }
00124 if(0 < objPDU->m.inhibitAnyPolicyPresent)
00125 {
00126 m_impl->m_indicators.set(ANY_POLICY);
00127 }
00128
00129 if(0 < objPDU->m.trustAnchorsPresent)
00130 {
00131 CPKIFPKCReferenceListPtr tmpTAList(new CPKIFPKCReferenceList());
00132 DListNode* cur = objPDU->trustAnchors.head;
00133 while(NULL != cur)
00134 {
00135 PKCReference* tmp = (PKCReference*)cur->data;
00136 CACASNWRAPPER_CREATE(PKCReference, objPDU2);
00137 ASN1OpenType* data1 = objPDU2.Encode(tmp);
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00150 CPKIFPKCReferencePtr tmpRevInfo(new CPKIFPKCReference(tmpBuf));
00151
00152 if(NULL != data1)
00153 delete data1;
00154
00155 tmpTAList->push_back(tmpRevInfo);
00156
00157 cur = cur->next;
00158 }
00159
00160 m_impl->m_TAs = tmpTAList;
00161 }
00162
00163 if(0 < objPDU->m.validationAlgPresent)
00164 {
00165 CPKIFOIDPtr algOID(new CPKIFOID(objPDU->validationAlg.valAlgId.subid, objPDU->validationAlg.valAlgId.numids));
00166
00167 CPKIFBufferPtr algParams;
00168 if(objPDU->validationAlg.m.parametersPresent == 1)
00169 {
00170 CPKIFBufferPtr tmpAlgParams(new CPKIFBuffer(objPDU->validationAlg.parameters.data,
00171 objPDU->validationAlg.parameters.numocts));
00172
00173 algParams = tmpAlgParams;
00174 }
00175 CPKIFValidationAlgPtr valAlg(new CPKIFValidationAlg(algOID, algParams));
00176
00177 m_impl->m_validationAlg = valAlg;
00178 }
00179 if(0 < objPDU->m.keyUsagesPresent)
00180 {
00181 CPKIFKeyUsageListPtr tmpKeyUsageList(new CPKIFKeyUsageList());
00182 DListNode* cur = objPDU->keyUsages.head;
00183 while(NULL != cur)
00184 {
00185 CACX509V3KeyUsage* tmp = (CACX509V3KeyUsage*)cur->data;
00186 CACASNWRAPPER_CREATE(CACX509V3KeyUsage, objPDU);
00187 ASN1OpenType* data1 = objPDU.Encode(tmp);
00188 CPKIFBufferPtr tmpBuf(new CPKIFBuffer(data1->data, data1->numocts));
00189 CPKIFKeyUsagePtr tmpKeyUsage(new CPKIFKeyUsage(false, tmpBuf));
00190
00191 if(NULL != data1)
00192 delete data1;
00193
00194 tmpKeyUsageList->push_back(tmpKeyUsage);
00195
00196 cur = cur->next;
00197 }
00198 m_impl->m_keyUsages = tmpKeyUsageList;
00199 }
00200 if(0 < objPDU->m.extendedKeyUsagesPresent)
00201 {
00202 m_impl->m_EKUs = PopulatePKIFOIDList(&objPDU->extendedKeyUsages);
00203 }
00204
00205 if(0 < objPDU->m.specifiedKeyUsagesPresent)
00206 {
00207 m_impl->m_SKUs = PopulatePKIFOIDList(&objPDU->specifiedKeyUsages);
00208 }
00209 }
00217 CPKIFValidationPolicy::~CPKIFValidationPolicy()
00218 {
00219 LOG_STRING_DEBUG("CPKIFValidationPolicy::~CPKIFValidationPolicy()", TOOLKIT_SCVP_ASN, 0, this);
00220
00221 if (m_impl) {
00222 delete m_impl;
00223 }
00224 }
00225
00233 void CPKIFValidationPolicy::SetInitialExplicitPolicyIndicator() {m_impl->m_indicators.set(EXPLICIT_POLICY);}
00242 bool CPKIFValidationPolicy::GetInitialExplicitPolicyIndicator() {return m_impl->m_indicators[EXPLICIT_POLICY];}
00250 void CPKIFValidationPolicy::SetInitialPolicyMappingInhibitIndicator() {m_impl->m_indicators.set(POLICY_MAPPING);}
00251
00261 bool CPKIFValidationPolicy::GetInitialPolicyMappingInhibitIndicator() {return m_impl->m_indicators[POLICY_MAPPING];}
00262
00273 void CPKIFValidationPolicy::SetInitialInhibitAnyPolicyIndicator() {m_impl->m_indicators.set(ANY_POLICY);}
00274
00285 bool CPKIFValidationPolicy::GetInitialInhibitAnyPolicyIndicator() {return m_impl->m_indicators[ANY_POLICY];}
00295 void CPKIFValidationPolicy::SetInitialPolicySet(
00298 CPKIFPolicyInformationListPtr& initPolSet)
00299 {
00300 m_impl->m_initPolSet = initPolSet;
00301 }
00302
00312 void CPKIFValidationPolicy::GetInitialPolicySet(
00315 CPKIFPolicyInformationListPtr& initPolSet)const
00316 {
00317 initPolSet = m_impl->m_initPolSet;
00318 }
00326 void CPKIFValidationPolicy::SetValidationPolRef(
00328 CPKIFValidationPolRefPtr& valPolRef)
00329 {
00330 m_impl->m_validationPolRef = valPolRef;
00331 }
00339 CPKIFValidationPolRefPtr CPKIFValidationPolicy::GetValidationPolRef() const
00340 {
00341 return m_impl->m_validationPolRef;
00342 }
00343
00351 void CPKIFValidationPolicy::SetValidationAlg(
00353 CPKIFValidationAlgPtr& valAlg)
00354 {
00355 m_impl->m_validationAlg = valAlg;
00356 }
00364 CPKIFValidationAlgPtr CPKIFValidationPolicy::GetValidationAlg() const
00365 {
00366 return m_impl->m_validationAlg;
00367 }
00375 void CPKIFValidationPolicy::SetKeyUsages(
00377 CPKIFKeyUsageListPtr& keyUsages)
00378 {
00379 m_impl->m_keyUsages = keyUsages;
00380 }
00388 void CPKIFValidationPolicy::GetKeyUsages(
00390 CPKIFKeyUsageListPtr& keyUsages) const
00391 {
00392 keyUsages = m_impl->m_keyUsages;
00393 }
00401 void CPKIFValidationPolicy::SetEKUs(
00403 CPKIFOIDListPtr& ekus)
00404 {
00405 m_impl->m_EKUs = ekus;
00406 }
00414 void CPKIFValidationPolicy::GetEKUs(
00416 CPKIFOIDListPtr& ekus) const
00417 {
00418 ekus = m_impl->m_EKUs;
00419 }
00427 void CPKIFValidationPolicy::SetSKUs(
00429 CPKIFOIDListPtr& skus)
00430 {
00431 m_impl->m_SKUs = skus;
00432 }
00440 void CPKIFValidationPolicy::GetSKUs(
00442 CPKIFOIDListPtr& skus) const
00443 {
00444 skus = m_impl->m_SKUs;
00445 }
00453 void CPKIFValidationPolicy::SetTAs(
00455 CPKIFPKCReferenceListPtr& tas)
00456 {
00457 m_impl->m_TAs = tas;
00458 }
00466 void CPKIFValidationPolicy::GetTAs(
00468 CPKIFPKCReferenceListPtr& tas) const
00469 {
00470 tas = m_impl->m_TAs;
00471 }