EnvelopedData.h

Go to the documentation of this file.
00001 
00009 #ifndef __ENVELOPEDDATA_H__
00010 #define __ENVELOPEDDATA_H__
00011 
00012 #include "PKIFCMSDLL.h"
00013 #include "PKIFMediators.h"
00014 #include "IPKIFHasAttributes.h"
00015 #include "PKIFCMSUtils.h" // for enumerated constants
00016 #include "components.h"
00017 #include "OID.h"
00018 #include "ContentType.h"
00019 
00020 FD_LIST_PTR(CPKIFCertificate);
00021 FD_LIST_PTR(CPKIFCRL);
00022 FD_LIST_PTR(CPKIFRecipientInfo);
00023 FD_SMART_PTR(CPKIFCertificatePath);
00024 FD_SMART_PTR(CPKIFKEKRecipInfoDetails);
00025 FD_SMART_PTR(CPKIFPathValidationResults);
00026 FD_SMART_PTR(CPKIFEncryptedContentInfo);
00027 FD_SMART_PTR(CPKIFPathSettings);
00028 FD_SMART_PTR(CPKIFCredential);
00029 FD_SMART_PTR(CPKIFKARIDetails);
00030 template<class T> class CPKIFASNWrapper;
00031 
00056 class PKIFCMS_API CPKIFEnvelopedData  : public IPKIFHasAttributes,  public CPKIFContentType
00057 {
00058     friend struct CPKIFEnvelopedDataImpl;
00059 public:
00060     //this enum matches the contents of the underlying 
00061     //objective enum and must continue to do so
00062     typedef enum {
00063         CMSv0 = 0,
00064         CMSv1 = 1,
00065         CMSv2 = 2,
00066         CMSv3 = 3,
00067         CMSv4 = 4
00068     } CMSVersion;
00069 
00070     //*****************************************************************************
00071     //  constructors and destructors
00072     //*****************************************************************************
00073     CPKIFEnvelopedData();
00074     virtual ~CPKIFEnvelopedData();
00075 
00076     //*****************************************************************************
00077     //  field manipulation functions
00078     //  EnvelopedData ::= SEQUENCE 
00079     //  {
00080     //      version CMSVersion,
00081     //      originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
00082     //      recipientInfos RecipientInfos,
00083     //      encryptedContentInfo EncryptedContentInfo,
00084     //      unprotectedAttrs [1] IMPLICIT UnprotectedAttributes OPTIONAL 
00085     //  }
00086     //  OriginatorInfo ::= SEQUENCE 
00087     //  {
00088     //      certs [0] IMPLICIT CertificateSet OPTIONAL,
00089     //      crls [1] IMPLICIT CertificateRevocationLists OPTIONAL 
00090     //  }
00091     //  RecipientInfos ::= SET SIZE (1..MAX) OF RecipientInfo
00092     //  EncryptedContentInfo ::= SEQUENCE 
00093     //  {
00094     //      contentType ContentType,
00095     //      contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
00096     //      encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL 
00097     //  }
00098     //  EncryptedContent ::= OCTET STRING
00099     //  UnprotectedAttributes ::= SET SIZE (1..MAX) OF Attribute
00100     //  RecipientInfo ::= CHOICE 
00101     //  {
00102     //      ktri KeyTransRecipientInfo,
00103     //      kari [1] KeyAgreeRecipientInfo,
00104     //      kekri [2] KEKRecipientInfo,
00105     //      pwri [3] PasswordRecipientinfo,
00106     //      ori [4] OtherRecipientInfo 
00107     //  }
00108     //  EncryptedKey ::= OCTET STRING
00109 
00110     //*****************************************************************************
00111     //version (required) - automatically set based on message contents
00112     //                      (see private CalculateAndSetVersion function)
00113     CMSVersion GetVersion() const;
00114 
00115     //originatorInfo (optional)
00116     void AddOriginatorCertificate(CPKIFCertificatePtr& cert);
00117     void AddOriginatorCRL(CPKIFCRLPtr& crl);
00118 
00119     void SetOriginatorCredential(CPKIFCredentialPtr & cred);
00120 
00121     void GetOriginatorCertificates(CPKIFCertificateList& certs);
00122     void GetOriginatorCRLs(CPKIFCRLList& crls);             
00123 
00124     void GetRecipientInfos(CPKIFRecipientInfoList& recipInfos) const;
00125 
00126     //recipientInfos (required)
00127     void AddRecipient(CPKIFCertificatePtr& cert, CMSPathValidationStatus minStatus = PVS_REV_STATUS_VERIFIED);
00128     void AddRecipient(CPKIFCertificatePtr& cert, CPKIFCertificatePathPtr& path, CPKIFPathValidationResultsPtr& valResults, CMSPathValidationStatus minStatus = PVS_REV_STATUS_VERIFIED);
00129     void AddRecipient(CPKIFKEKRecipInfoDetailsPtr& kek);
00130     //void AddRecipient(CPKIFKARIDetailsPtr& kari);
00131 
00132     //encryptedContentInfo (required)
00133     void SetDataToEncrypt(CPKIFEncryptedContentInfoPtr& buf);
00134     CPKIFEncryptedContentInfoPtr GetEncryptedData() const;
00135 
00136     //unprotectedAttrs (optional)
00137     void AddUnprotectedAttribute(CPKIFAttributePtr& attr);
00138 
00139     void GetUnprotectedAttributes(CPKIFAttributeList& ual);
00140 
00141     // Implementation of virtual IPKIFHasAttributes::GetEncodedUnprotectedAttributes
00142     void GetEncodedUnprotectedAttributes (CPKIFBufferPtr& buf);
00143 
00144     // The following function is a workaround bc it's not wise to use
00145     // static members inside of template functions.  This should be revisited
00146     // after a more "correct" approach has been decided.
00147     void _GetUnprotectedAttributes(std::vector<CPKIFAttributePtr> attrVector);
00148 
00149     template <class T> boost::shared_ptr<T> GetUnprotectedAttribute();
00150 
00151     void ClearContent();
00152 
00153     void SetAlgorithmAndMode(PKIFCRYPTO::SYMKEY_ALG alg, PKIFCRYPTO::SYMKEY_MODE mode);
00154     PKIFCRYPTO::SYMKEY_ALG GetAlgorithm() const;
00155     PKIFCRYPTO::SYMKEY_MODE GetMode() const;
00156 
00157     //*****************************************************************************
00158     //  encode and decode functions
00159     //*****************************************************************************
00160     CPKIFBufferPtr Encode();                                //also performs encryption
00161     void Decode(CPKIFBufferPtr& buf);                   //does not perform decryption
00162 
00163     //*****************************************************************************
00164     //  miscellaneous functions
00165     //*****************************************************************************
00166     void SetPathSettings(CPKIFPathSettingsPtr& settings);
00167     CPKIFBufferPtr Decrypt(CPKIFCredentialPtr& cred);
00168     CPKIFBufferPtr Decrypt(CPKIFKEKRecipInfoDetailsPtr& kek);
00169     void GetAddedUnprotectedAttributes(std::vector<CPKIFAttributePtr>& attr);
00170 
00171     void SetMediator(IPKIFMediatorPtr& m);
00172     IPKIFMediatorPtr GetMediator();
00173 private:
00175     CPKIFEnvelopedData(const CPKIFEnvelopedData& copy);
00177     CPKIFEnvelopedData& operator=(const CPKIFEnvelopedData& rhs); //added 4/6/2004
00178 
00179     enum {thisComponent=TOOLKIT_MESSAGE_ENVELOPED_DATA};
00180 
00181     struct CPKIFEnvelopedDataImpl *m_impl;
00182 
00183 
00184 };
00185 DECLARE_SMART_POINTERS(CPKIFEnvelopedData)
00186 
00187 //added smart pointer declaration 6/29/2004 AG
00196 template <class T> boost::shared_ptr<T> CPKIFEnvelopedData::GetUnprotectedAttribute()
00197 
00198 {
00199   //XXX*** Read the comments below and fix this please 
00200   
00201   std::vector<CPKIFAttributePtr> attrVector;
00202   // The following function is a workaround bc it's not wise to use
00203   // static members inside of template functions.  This should be revisited
00204   // after a more "correct" approach has been decided.
00205   _GetUnprotectedAttributes(attrVector);
00206   
00207   //GetUnprotectedAttributes (IPKIFParseAttributes* m, attrVector);
00208  
00209   CPKIFStringPtr oidStr(new std::string(T::extOID));
00210   CPKIFOID oid(oidStr);
00211 
00212   CPKIFAttribute* p = NULL;
00213   CPKIFAttributeList::iterator pos;
00214   CPKIFAttributeList::iterator end = attrVector.end();
00215   for(pos = attrVector.begin(); pos != end; ++pos)
00216   {
00217     p = &(*(*pos));
00218     if(oid == (*pos)->GetOID() && NULL != dynamic_cast<T*>(p))
00219     {
00220       return *((boost::shared_ptr<T>*)&(*pos));
00221     }
00222   }     
00223 
00224   boost::shared_ptr<T> nullExt;
00225   return nullExt;
00226 }
00227 
00228 #endif

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