blautenb    2003/09/15 04:53:10

  Modified:    c/src/xenc/impl XENCEncryptedTypeImpl.hpp
                        XENCEncryptedTypeImpl.cpp XENCEncryptedDataImpl.hpp
                        XENCEncryptedDataImpl.cpp XENCCipherValueImpl.hpp
                        XENCCipherValueImpl.cpp XENCCipherImpl.hpp
                        XENCCipherImpl.cpp XENCCipherDataImpl.hpp
                        XENCCipherDataImpl.cpp
  Log:
  Integration of AlgorithmMapper and DSIG KeyInfo loading
  
  Revision  Changes    Path
  1.5       +19 -7     xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp
  
  Index: XENCEncryptedTypeImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XENCEncryptedTypeImpl.hpp 11 Sep 2003 11:43:07 -0000      1.4
  +++ XENCEncryptedTypeImpl.hpp 15 Sep 2003 11:53:09 -0000      1.5
  @@ -74,22 +74,24 @@
   
   #include <xsec/framework/XSECDefs.hpp>
   #include <xsec/xenc/XENCEncryptedType.hpp>
  +#include <xsec/dsig/DSIGKeyInfoList.hpp>
   
   // Forward declarations
   
   XSEC_DECLARE_XERCES_CLASS(DOMNode);
   
  -class XENCCipherImpl;
   class XENCCipherDataImpl;
  +class XENCEncryptionMethodImpl;
   class TXFMChain;
  +class XSECEnv;
   
   class XENCEncryptedTypeImpl : public XENCEncryptedType {
   
   public:
   
  -     XENCEncryptedTypeImpl(XENCCipherImpl * cipher);
  +     XENCEncryptedTypeImpl(const XSECEnv * env);
        XENCEncryptedTypeImpl(
  -             XENCCipherImpl * cipher, 
  +             const XSECEnv * env, 
                XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * node
        );
   
  @@ -103,11 +105,15 @@
        XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * createBlankEncryptedType(
                                                XMLCh * localName,
                                                
XENCCipherData::XENCCipherDataType type, 
  +                                             const XMLCh * algorithm,
                                                const XMLCh * value);
   
        // Interface Methods
        virtual XENCCipherData * getCipherData(void);
        virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * getDOMNode();
  +     virtual DSIGKeyInfoList * getKeyInfoList(void) {return &m_keyInfoList;}
  +     virtual XENCEncryptionMethod * getEncryptionMethod(void);
  +
   
   protected:
   
  @@ -116,10 +122,16 @@
   
        TXFMChain * createCipherTXFMChain(void);
   
  -     XENCCipherImpl                  * mp_cipher;
  +     const XSECEnv                           * mp_env;
        XERCES_CPP_NAMESPACE_QUALIFIER DOMNode                                  
  -                                                     * mp_encryptedTypeNode; 
        // Node at head of structure
  -     XENCCipherDataImpl              * mp_cipherData;
  +                                                             * 
mp_encryptedTypeNode;         // Node at head of structure
  +     XERCES_CPP_NAMESPACE_QUALIFIER DOMNode
  +                                                             * 
mp_keyInfoNode;                       // Any underlying KeyInfo
  +     XENCCipherDataImpl                      * mp_cipherData;
  +     XENCEncryptionMethodImpl        * mp_encryptionMethod;
  +
  +     // Hold the XML Digital Signature KeyInfo list
  +     DSIGKeyInfoList                 m_keyInfoList;
   
        friend class XENCCipherImpl;
   };
  
  
  
  1.4       +47 -15    xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp
  
  Index: XENCEncryptedTypeImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCEncryptedTypeImpl.cpp 11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCEncryptedTypeImpl.cpp 15 Sep 2003 11:53:09 -0000      1.4
  @@ -72,12 +72,14 @@
   #include "XENCCipherImpl.hpp"
   #include "XENCCipherDataImpl.hpp"
   #include "XENCEncryptedTypeImpl.hpp"
  +#include "XENCEncryptionMethodImpl.hpp"
   
   #include <xsec/framework/XSECError.hpp>
   #include <xsec/utils/XSECDOMUtils.hpp>
   #include <xsec/transformers/TXFMBase64.hpp>
   #include <xsec/transformers/TXFMChain.hpp>
   #include <xsec/transformers/TXFMSB.hpp>
  +#include <xsec/framework/XSECEnv.hpp>
   
   #include <xercesc/util/XMLUniDefs.hpp>
   #include <xercesc/util/Janitor.hpp>
  @@ -140,18 +142,22 @@
   //                   Constructors and Destructors
   // 
--------------------------------------------------------------------------------
   
  -XENCEncryptedTypeImpl::XENCEncryptedTypeImpl(XENCCipherImpl * cipher) :
  -mp_cipher(cipher),
  +XENCEncryptedTypeImpl::XENCEncryptedTypeImpl(const XSECEnv * env) :
  +mp_env(env),
   mp_encryptedTypeNode(NULL),
  -mp_cipherData(NULL) {
  +mp_cipherData(NULL),
  +mp_encryptionMethod(NULL),
  +m_keyInfoList(env) {
   
   }
   
   
  -XENCEncryptedTypeImpl::XENCEncryptedTypeImpl(XENCCipherImpl * cipher, 
DOMNode * node) :
  -mp_cipher(cipher),
  +XENCEncryptedTypeImpl::XENCEncryptedTypeImpl(const XSECEnv * env, DOMNode * 
node) :
  +mp_env(env),
   mp_encryptedTypeNode(node),
  -mp_cipherData(NULL) {
  +mp_cipherData(NULL),
  +mp_encryptionMethod(NULL),
  +m_keyInfoList(env) {
   
   }
   
  @@ -160,6 +166,9 @@
        if (mp_cipherData != NULL)
                delete mp_cipherData;
   
  +     if (mp_encryptionMethod != NULL)
  +             delete mp_encryptionMethod;
  +
   }
   
   // 
--------------------------------------------------------------------------------
  @@ -183,7 +192,8 @@
   
        if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt), 
s_EncryptionMethod)) {
   
  -             // For now, ignore
  +             XSECnew(mp_encryptionMethod, XENCEncryptionMethodImpl(mp_env, 
tmpElt));
  +             mp_encryptionMethod->load();
   
                tmpElt = findNextChildOfType(tmpElt, DOMNode::ELEMENT_NODE);
   
  @@ -191,7 +201,11 @@
   
        if (tmpElt != NULL && strEquals(getDSIGLocalName(tmpElt), s_KeyInfo)) {
   
  -             // For now, ignore
  +             // Load
  +             mp_keyInfoNode = tmpElt;
  +             m_keyInfoList.loadListFromXML(tmpElt);
  +
  +             // Find the next node
   
                tmpElt = findNextChildOfType(tmpElt, DOMNode::ELEMENT_NODE);
   
  @@ -199,7 +213,7 @@
   
        if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt), 
s_CipherData)) {
   
  -             XSECnew(mp_cipherData, XENCCipherDataImpl(mp_cipher, tmpElt));
  +             XSECnew(mp_cipherData, XENCCipherDataImpl(mp_env, tmpElt));
                mp_cipherData->load();
                tmpElt = findNextChildOfType(tmpElt, DOMNode::ELEMENT_NODE);
   
  @@ -223,15 +237,17 @@
   DOMElement * XENCEncryptedTypeImpl::createBlankEncryptedType(
                                                XMLCh * localName,
                                                
XENCCipherData::XENCCipherDataType type, 
  +                                             const XMLCh * algorithm,
                                                const XMLCh * value) {
   
        // Reset
        mp_cipherData = NULL;
  +     mp_encryptionMethod = NULL;
   
        // Get some setup values
        safeBuffer str;
  -     DOMDocument *doc = mp_cipher->getDocument();
  -     const XMLCh * prefix = mp_cipher->getXENCNSPrefix();
  +     DOMDocument *doc = mp_env->getParentDocument();
  +     const XMLCh * prefix = mp_env->getXENCNSPrefix();
   
        makeQName(str, prefix, localName);
   
  @@ -251,9 +267,19 @@
                                                        str.rawXMLChBuffer(), 
                                                        
DSIGConstants::s_unicodeStrURIXENC);
   
  +     // Create the EncryptionMethod
  +     if (algorithm != NULL) {
  +
  +             XSECnew(mp_encryptionMethod, XENCEncryptionMethodImpl(mp_env));
  +             DOMNode * encryptionMethodNode = 
  +                     
mp_encryptionMethod->createBlankEncryptedType(algorithm);
  +
  +             ret->appendChild(encryptionMethodNode);
  +
  +     }
   
        // Create the cipher Data
  -     XSECnew(mp_cipherData, XENCCipherDataImpl(mp_cipher));
  +     XSECnew(mp_cipherData, XENCCipherDataImpl(mp_env));
        DOMNode * cipherDataNode = mp_cipherData->createBlankCipherData(type, 
value);
   
        // Add to EncryptedType
  @@ -280,7 +306,7 @@
                ArrayJanitor<char> j_b64(b64);
   
                TXFMSB *sb;
  -             XSECnew(sb, TXFMSB(mp_cipher->getDocument()));
  +             XSECnew(sb, TXFMSB(mp_env->getParentDocument()));
   
                sb->setInput(safeBuffer(b64));
   
  @@ -289,7 +315,7 @@
   
                // Create a base64 decoder
                TXFMBase64 * tb64;
  -             XSECnew(tb64, TXFMBase64(mp_cipher->getDocument()));
  +             XSECnew(tb64, TXFMBase64(mp_env->getParentDocument()));
   
                chain->appendTxfm(tb64);
   
  @@ -323,4 +349,10 @@
                return static_cast<DOMElement*>(mp_encryptedTypeNode);
   
        return NULL;
  +}
  +
  +XENCEncryptionMethod * XENCEncryptedTypeImpl::getEncryptionMethod(void) {
  +     
  +     return mp_encryptionMethod;
  +
   }
  
  
  
  1.4       +10 -5     xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp
  
  Index: XENCEncryptedDataImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCEncryptedDataImpl.hpp 11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCEncryptedDataImpl.hpp 15 Sep 2003 11:53:09 -0000      1.4
  @@ -83,9 +83,9 @@
   
   public:
   
  -     XENCEncryptedDataImpl(XENCCipherImpl * cipher);
  +     XENCEncryptedDataImpl(const XSECEnv * env);
        XENCEncryptedDataImpl(
  -             XENCCipherImpl * cipher, 
  +             const XSECEnv * env, 
                XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * node
        );
        virtual ~XENCEncryptedDataImpl();
  @@ -95,7 +95,9 @@
        // Create a blank EncryptedData DOM structure
   
        XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * 
  -             createBlankEncryptedData(XENCCipherData::XENCCipherDataType 
type, const XMLCh * value);
  +             createBlankEncryptedData(XENCCipherData::XENCCipherDataType 
type, 
  +                                                              const XMLCh * 
algorithm,
  +                                                              const XMLCh * 
value);
   
        // Interface methods
   
  @@ -104,7 +106,10 @@
                {return XENCEncryptedTypeImpl::getCipherData();}
        virtual XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * getDOMNode()
                {return XENCEncryptedTypeImpl::getDOMNode();}
  -
  +     virtual DSIGKeyInfoList * getKeyInfoList(void)
  +             {return XENCEncryptedTypeImpl::getKeyInfoList();}
  +     virtual XENCEncryptionMethod * getEncryptionMethod(void)
  +             {return XENCEncryptedTypeImpl::getEncryptionMethod();}
   
   private:
   
  
  
  
  1.4       +7 -6      xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.cpp
  
  Index: XENCEncryptedDataImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCEncryptedDataImpl.cpp 11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCEncryptedDataImpl.cpp 15 Sep 2003 11:53:09 -0000      1.4
  @@ -106,13 +106,13 @@
   // 
--------------------------------------------------------------------------------
   
   
  -XENCEncryptedDataImpl::XENCEncryptedDataImpl(XENCCipherImpl * cipher) :
  -XENCEncryptedTypeImpl(cipher) {
  +XENCEncryptedDataImpl::XENCEncryptedDataImpl(const XSECEnv * env) :
  +XENCEncryptedTypeImpl(env) {
        
   }
   
  -XENCEncryptedDataImpl::XENCEncryptedDataImpl(XENCCipherImpl * cipher, 
DOMNode * node) :
  -XENCEncryptedTypeImpl(cipher, node) {
  +XENCEncryptedDataImpl::XENCEncryptedDataImpl(const XSECEnv * env, DOMNode * 
node) :
  +XENCEncryptedTypeImpl(env, node) {
   
   }
   
  @@ -152,9 +152,10 @@
   
   DOMElement * XENCEncryptedDataImpl::createBlankEncryptedData(
                                                                        
XENCCipherData::XENCCipherDataType type, 
  +                                                                     const 
XMLCh * algorithm,
                                                                        const 
XMLCh * value) {
   
  -     return createBlankEncryptedType(s_EncryptedData, type, value);
  +     return createBlankEncryptedType(s_EncryptedData, type, algorithm, 
value);
   
   }
   
  
  
  
  1.4       +8 -5      xml-security/c/src/xenc/impl/XENCCipherValueImpl.hpp
  
  Index: XENCCipherValueImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherValueImpl.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCCipherValueImpl.hpp   11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCCipherValueImpl.hpp   15 Sep 2003 11:53:09 -0000      1.4
  @@ -79,13 +79,15 @@
   
   XSEC_DECLARE_XERCES_CLASS(DOMNode);
   
  +class XSECEnv;
  +
   class XENCCipherValueImpl : public XENCCipherValue {
   
   public:
   
  -     XENCCipherValueImpl(XENCCipherImpl * cipher);
  +     XENCCipherValueImpl(const XSECEnv * env);
        XENCCipherValueImpl(
  -             XENCCipherImpl * cipher, 
  +             const XSECEnv * env, 
                XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * node
        );
   
  @@ -99,7 +101,8 @@
   
        // Interface methods
   
  -     const XMLCh * getCipherString(void);
  +     virtual const XMLCh * getCipherString(void);
  +     virtual void setCipherString(const XMLCh * value);
   
   private:
   
  @@ -107,7 +110,7 @@
        XENCCipherValueImpl(const XENCCipherValueImpl &);
        XENCCipherValueImpl & operator = (const XENCCipherValueImpl &);
   
  -     XENCCipher                              * mp_cipher;
  +     const XSECEnv                   * mp_env;
        XERCES_CPP_NAMESPACE_QUALIFIER DOMNode                                  
                                                        * mp_cipherValueNode;
        XMLCh                                   * mp_cipherString;              
// EncryptedData
  
  
  
  1.4       +33 -7     xml-security/c/src/xenc/impl/XENCCipherValueImpl.cpp
  
  Index: XENCCipherValueImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherValueImpl.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCCipherValueImpl.cpp   11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCCipherValueImpl.cpp   15 Sep 2003 11:53:09 -0000      1.4
  @@ -74,6 +74,7 @@
   
   #include <xsec/framework/XSECError.hpp>
   #include <xsec/utils/XSECDOMUtils.hpp>
  +#include <xsec/framework/XSECEnv.hpp>
   
   #include <xercesc/util/XMLUniDefs.hpp>
   
  @@ -103,15 +104,15 @@
   //                   Constructors/Destructors
   // 
--------------------------------------------------------------------------------
   
  -XENCCipherValueImpl::XENCCipherValueImpl(XENCCipherImpl * cipher) :
  -mp_cipher(cipher),
  +XENCCipherValueImpl::XENCCipherValueImpl(const XSECEnv * env) :
  +mp_env(env),
   mp_cipherValueNode(NULL),
   mp_cipherString(NULL) {
   
   }
   
  -XENCCipherValueImpl::XENCCipherValueImpl(XENCCipherImpl * cipher, DOMNode * 
node) :
  -mp_cipher(cipher),
  +XENCCipherValueImpl::XENCCipherValueImpl(const XSECEnv * env, DOMNode * 
node) :
  +mp_env(env),
   mp_cipherValueNode(node),
   mp_cipherString(NULL) {
   
  @@ -171,8 +172,8 @@
   
        // Get some setup values
        safeBuffer str;
  -     DOMDocument *doc = mp_cipher->getDocument();
  -     const XMLCh * prefix = mp_cipher->getXENCNSPrefix();
  +     DOMDocument *doc = mp_env->getParentDocument();
  +     const XMLCh * prefix = mp_env->getXENCNSPrefix();
   
        makeQName(str, prefix, s_CipherValue);
   
  @@ -198,3 +199,28 @@
   
   }
   
  +void XENCCipherValueImpl::setCipherString(const XMLCh * value) {
  +
  +     if (mp_cipherValueNode == NULL) {
  +
  +             throw XSECException(XSECException::CipherValueError,
  +                     "XENCCipherData::setCipherString - called on empty 
DOM");
  +
  +     }
  +
  +     // Find first text child
  +     DOMNode * txt = findFirstChildOfType(mp_cipherValueNode, 
DOMNode::TEXT_NODE);
  +     
  +     if (txt == NULL) {
  +             throw XSECException(XSECException::CipherValueError,
  +                     "XENCCipherData::setCipherString - Error finding text 
node");
  +     }
  +
  +     txt->setNodeValue(value);
  +
  +     if (mp_cipherString != NULL)
  +             delete[] mp_cipherString;
  +
  +     mp_cipherString = XMLString::replicate(value);
  +
  +}
  
  
  
  1.5       +21 -8     xml-security/c/src/xenc/impl/XENCCipherImpl.hpp
  
  Index: XENCCipherImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherImpl.hpp,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- XENCCipherImpl.hpp        11 Sep 2003 11:43:07 -0000      1.4
  +++ XENCCipherImpl.hpp        15 Sep 2003 11:53:09 -0000      1.5
  @@ -78,6 +78,9 @@
   class XSECProvider;
   class XENCEncryptedDataImpl;
   class TXFMChain;
  +class XSECEnv;
  +class XSECKeyInfoResolver;
  +class XSECPlatformUtils;
   
   XSEC_DECLARE_XERCES_CLASS(DOMNode);
   XSEC_DECLARE_XERCES_CLASS(DOMDocumentFragment);
  @@ -95,7 +98,9 @@
   
        // Implementation for encryption Elements
        XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * encryptElement(
  -             XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element);
  +             XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * element,
  +             encryptionMethod em,
  +             const XMLCh * uri = NULL);
   
        // Getter methods
        XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * getDocument(void) 
  @@ -104,20 +109,25 @@
   
        // Setter methods
        void setKey(XSECCryptoKey * key) {mp_key = key;}
  +     void setKeyInfoResolver(const XSECKeyInfoResolver * resolver);
  +
        void setXENCNSPrefix(const XMLCh * prefix);
        
        // Creation methods
  -     XENCEncryptedData * 
createEncryptedData(XENCCipherData::XENCCipherDataType type, 
  -                                                                             
        XMLCh * value);
  +     XENCEncryptedData * 
createEncryptedData(XENCCipherData::XENCCipherDataType type,
  +                                                                             
        const XMLCh * algorithm,
  +                                                                             
        const XMLCh * value);
  +
  +protected:
   
  +     // Initialisation
  +     static void Initialise(void);
   
   protected:
   
        // Protected to prevent direct creation of objects
        XENCCipherImpl(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc);
   
  -     // Creates a transform chain that gives the decrypted data
  -     TXFMChain * createDecryptionTXFMChain(void);
   private:
   
        // Internal functions
  @@ -139,11 +149,14 @@
        // Key
        XSECCryptoKey                   * mp_key;
   
  -     // Prefix
  -     XMLCh                                   * mp_xencPrefixNS;
  +     // Environment
  +     XSECEnv                                 * mp_env;
   
  +     // Resolvers
  +     XSECKeyInfoResolver             * mp_keyInfoResolver;
   
        friend class XSECProvider;
  +     friend class XSECPlatformUtils;
   
   };
   
  
  
  
  1.4       +173 -88   xml-security/c/src/xenc/impl/XENCCipherImpl.cpp
  
  Index: XENCCipherImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherImpl.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCCipherImpl.cpp        11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCCipherImpl.cpp        15 Sep 2003 11:53:09 -0000      1.4
  @@ -73,14 +73,19 @@
   #include <xsec/enc/XSECCryptoKey.hpp>
   #include <xsec/transformers/TXFMChain.hpp>
   #include <xsec/transformers/TXFMBase.hpp>
  -#include <xsec/transformers/TXFMBase64.hpp>
   #include <xsec/transformers/TXFMC14n.hpp>
  -#include <xsec/transformers/TXFMCipher.hpp>
   #include <xsec/transformers/TXFMDocObject.hpp>
   #include <xsec/utils/XSECDOMUtils.hpp>
  +#include <xsec/framework/XSECEnv.hpp>
  +#include <xsec/enc/XSECKeyInfoResolver.hpp>
  +#include <xsec/framework/XSECAlgorithmMapper.hpp>
  +#include <xsec/framework/XSECAlgorithmHandler.hpp>
  +#include <xsec/utils/XSECPlatformUtils.hpp>
   
   #include "XENCCipherImpl.hpp"
   #include "XENCEncryptedDataImpl.hpp"
  +#include "XENCEncryptionMethodImpl.hpp"
  +#include "XENCAlgorithmHandlerDefault.hpp"
   
   #include <xercesc/dom/DOMNode.hpp>
   #include <xercesc/dom/DOMElement.hpp>
  @@ -114,14 +119,14 @@
        chNull
   };
   
  -const XMLCh s_defaultXENCPrefix[] = {
  -
  -     chLatin_x,
  -     chLatin_e,
  +const XMLCh s_noData[] = {
        chLatin_n,
  -     chLatin_c,
  +     chLatin_o,
  +     chLatin_D,
  +     chLatin_a,
  +     chLatin_t,
  +     chLatin_a,
        chNull
  -
   };
   
   // 
--------------------------------------------------------------------------------
  @@ -131,9 +136,10 @@
   XENCCipherImpl::XENCCipherImpl(DOMDocument * doc) :
   mp_doc(doc),
   mp_encryptedData(NULL),
  -mp_key(NULL) {
  +mp_key(NULL),
  +mp_keyInfoResolver(NULL) {
   
  -     mp_xencPrefixNS = XMLString::replicate(s_defaultXENCPrefix);
  +     XSECnew(mp_env, XSECEnv(doc));
   
   }
   
  @@ -145,8 +151,25 @@
        if (mp_key != NULL)
                delete mp_key;
   
  -     if (mp_xencPrefixNS != NULL)
  -             delete mp_xencPrefixNS;
  +     if (mp_env != NULL)
  +             delete mp_env;
  +
  +     if (mp_keyInfoResolver != NULL)
  +             delete mp_keyInfoResolver;
  +
  +}
  +
  +// 
--------------------------------------------------------------------------------
  +//                   Initialiser
  +// 
--------------------------------------------------------------------------------
  +
  +void XENCCipherImpl::Initialise(void) {
  +
  +     XENCAlgorithmHandlerDefault def;
  +     
  +     // Register default encryption algorithm handlers
  +
  +     
XSECPlatformUtils::registerAlgorithmHandler(DSIGConstants::s_unicodeStrURI3DES_CBC,
 def);
   
   }
   
  @@ -156,17 +179,25 @@
   
   void XENCCipherImpl::setXENCNSPrefix(const XMLCh * prefix) {
   
  -     if (mp_xencPrefixNS != NULL)
  -             delete mp_xencPrefixNS;
  -
  -     // Copy in new one
  -     mp_xencPrefixNS = XMLString::replicate(prefix);
  +     mp_env->setXENCNSPrefix(prefix);
   
   }
   
   const XMLCh * XENCCipherImpl::getXENCNSPrefix(void) const {
   
  -     return mp_xencPrefixNS;
  +     return mp_env->getXENCNSPrefix();
  +
  +}
  +// 
--------------------------------------------------------------------------------
  +//                   Key Info resolvers
  +// 
--------------------------------------------------------------------------------
  +
  +void XENCCipherImpl::setKeyInfoResolver(const XSECKeyInfoResolver * 
resolver) {
  +
  +     if (mp_keyInfoResolver != NULL)
  +             delete mp_keyInfoResolver;
  +
  +     mp_keyInfoResolver = resolver->clone();
   
   }
   
  @@ -302,73 +333,76 @@
   }
   
   // 
--------------------------------------------------------------------------------
  -//                   Build a set of decryption transforms
  +//                   Decrypt an Element and replace in original document
   // 
--------------------------------------------------------------------------------
   
  -TXFMChain * XENCCipherImpl::createDecryptionTXFMChain(void) {
  +DOMDocument * XENCCipherImpl::decryptElement(DOMElement * element) {
  +
  +     // First of all load the element
  +     if (mp_encryptedData != NULL)
  +             delete mp_encryptedData;
   
  -     // First obtain the raw encrypted data
  +     XSECnew(mp_encryptedData, 
  +             XENCEncryptedDataImpl(mp_env, dynamic_cast<DOMNode 
*>(element)));
  +
  +     // Load
  +     mp_encryptedData->load();
  +
  +     // Make sure we have a key before we do anything else too drastic
        if (mp_key == NULL) {
  -             throw XSECException(XSECException::CipherError, 
  -                     "XENCCipherImpl::createDecryptionTXFMChain - No key 
set");
  -     }
   
  -     if (mp_encryptedData == NULL) {
  -             throw XSECException(XSECException::CipherError, 
  -                     "XENCCipherImpl::createDecryptionTXFMChain - Encrypted 
Data");
  +             if (mp_keyInfoResolver != NULL)
  +                     mp_key = 
mp_keyInfoResolver->resolveKey(mp_encryptedData->getKeyInfoList());
  +
  +             if (mp_key == NULL) {
  +
  +                     throw XSECException(XSECException::CipherError, 
  +                             "XENCCipherImpl::decryptElement - No key set 
and cannot resolve");
  +             }
        }
   
        // Get the raw encrypted data
        TXFMChain * c = mp_encryptedData->createCipherTXFMChain();
  -
        Janitor<TXFMChain> j_c(c);
   
  -     // Now add the decryption TXFM
  -     TXFMCipher * tcipher;
  -     XSECnew(tcipher, TXFMCipher(mp_doc, mp_key, false));
  +     // Get the Algorithm handler for the algorithm
  +     XENCEncryptionMethod * encryptionMethod = 
mp_encryptedData->getEncryptionMethod();
  +     XSECAlgorithmHandler *handler;
  +
  +     if (encryptionMethod != NULL) {
  +             
  +             handler = 
  +                     XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(
  +                             
mp_encryptedData->getEncryptionMethod()->getAlgorithm());
  +     
  +     }
   
  -     c->appendTxfm(tcipher);
  +     else {
   
  -     j_c.release();
  -     return c;
  +             handler =
  +                     XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(
  +                             
XSECAlgorithmMapper::s_defaultEncryptionMapping);
   
  -}
  +     }
   
  -// 
--------------------------------------------------------------------------------
  -//                   Decrypt an Element and replace in original document
  -// 
--------------------------------------------------------------------------------
  +     safeBuffer sb("");
   
  -DOMDocument * XENCCipherImpl::decryptElement(DOMElement * element) {
  +     if (handler != NULL) {
   
  -     // Make sure we have a key before we do anything too drastic
  -     if (mp_key == NULL) {
  -             throw XSECException(XSECException::CipherError, 
  -                     "XENCCipherImpl::decryptElement - No key set");
  +             handler->decryptToSafeBuffer(c, 
  +                     mp_encryptedData->getEncryptionMethod(), 
  +                     mp_key,
  +                     mp_env->getParentDocument(),
  +                     sb);
        }
  -     
  -     // First of all load the element
  -     if (mp_encryptedData != NULL)
  -             delete mp_encryptedData;
  -
  -     XSECnew(mp_encryptedData, 
  -             XENCEncryptedDataImpl(this, dynamic_cast<DOMNode *>(element)));
  -
  -     // Load
  -     mp_encryptedData->load();
  +     else {
   
  -     // Get the raw encrypted data
  -     TXFMChain * c = createDecryptionTXFMChain();
  -     Janitor<TXFMChain> j_c(c);
  -     TXFMBase * b = c->getLastTxfm();
  +             // Very strange if we get here - any problems should throw an
  +             // exception in the AlgorithmMapper.
   
  -     // Read the result into a safeBuffer
  -     XMLByte buf[2050];
  -     safeBuffer sb("");
  +             throw XSECException(XSECException::CipherError, 
  +                     "XENCCipherImpl::decryptElement - Error retrieving a 
handler for algorithm");
   
  -     int len;
  -     while ((len = b->readBytes(buf, 2048)) > 0) {
  -             buf[len] = '\0';
  -             sb.sbStrcatIn((char *) buf);
        }
   
        // Now de-serialise
  @@ -398,8 +432,9 @@
   // 
--------------------------------------------------------------------------------
   
   XENCEncryptedData * XENCCipherImpl::createEncryptedData(
  -                                             
XENCCipherData::XENCCipherDataType type, 
  -                                             XMLCh * value) {
  +                                             
XENCCipherData::XENCCipherDataType type,
  +                                             const XMLCh * algorithm,
  +                                             const XMLCh * value) {
   
        // Clean out anything currently being used
        if (mp_encryptedData != NULL) {
  @@ -408,8 +443,8 @@
        }
        // Create a new EncryptedData element
   
  -     XSECnew(mp_encryptedData, XENCEncryptedDataImpl(this));
  -     mp_encryptedData->createBlankEncryptedData(type, value);
  +     XSECnew(mp_encryptedData, XENCEncryptedDataImpl(mp_env));
  +     mp_encryptedData->createBlankEncryptedData(type, algorithm, value);
   
        return mp_encryptedData;
   }
  @@ -418,7 +453,9 @@
   //                   Encrypt an element
   // 
--------------------------------------------------------------------------------
   
  -DOMDocument * XENCCipherImpl::encryptElement(DOMElement * element) {
  +DOMDocument * XENCCipherImpl::encryptElement(DOMElement * element, 
  +                                                                             
         encryptionMethod em,
  +                                                                             
         const XMLCh * algorithmURI) {
   
        // Make sure we have a key before we do anything too drastic
        if (mp_key == NULL) {
  @@ -426,6 +463,35 @@
                        "XENCCipherImpl::encryptElement - No key set");
        }
   
  +     // Map the encryption method to a URI
  +     safeBuffer algorithmSB;
  +     const XMLCh * algorithm;
  +
  +     if (em == ENCRYPT_NONE) {
  +             algorithm = algorithmURI;
  +     }
  +     else {
  +             if (encryptionMethod2URI(algorithmSB, em) != true) {
  +                     throw XSECException(XSECException::CipherError, 
  +                             "XENCCipherImpl::encryptElement - Unknown 
encryption method");
  +             }
  +             algorithm = algorithmSB.sbStrToXMLCh();
  +     }
  +
  +     // Create the element with a dummy encrypted value
  +
  +     if (mp_encryptedData != NULL) {
  +             delete mp_encryptedData;
  +             mp_encryptedData = NULL;
  +     }
  +     
  +     XSECnew(mp_encryptedData, XENCEncryptedDataImpl(mp_env));
  +     mp_encryptedData->createBlankEncryptedData(
  +             XENCCipherData::VALUE_TYPE, 
  +             algorithm,
  +             s_noData);
  +
  +
        // Create a transform chain to do the encryption
        TXFMDocObject * tdocObj;
        XSECnew(tdocObj, TXFMDocObject(mp_doc));
  @@ -444,29 +510,48 @@
        tc14n->activateComments();
        tc14n->setExclusive();
   
  -     // Do the encryption
  -     TXFMCipher *tcipher;
  -     XSECnew(tcipher, TXFMCipher(mp_doc, mp_key, true));
  -     c->appendTxfm(tcipher);
  -
  -     // Transform to Base64
  -     TXFMBase64 * tb64;
  -     XSECnew(tb64, TXFMBase64(mp_doc, false));
  -     c->appendTxfm(tb64);
  +     // Perform the encryption
  +     XSECAlgorithmHandler *handler;
  +
  +     if (algorithm != NULL) {
  +             
  +             handler = 
  +                     
XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(algorithm);
  +     
  +     }
  +
  +     else {
  +
  +             handler =
  +                     XSECPlatformUtils::g_algorithmMapper->mapURIToHandler(
  +                             
XSECAlgorithmMapper::s_defaultEncryptionMapping);
  +
  +     }
   
  -     // Read into a safeBuffer
        safeBuffer sb;
  -     sb << c->getLastTxfm();
   
  -     // Create the element!
  +     if (handler != NULL) {
   
  -     if (mp_encryptedData != NULL) {
  -             delete mp_encryptedData;
  -             mp_encryptedData = NULL;
  +             handler->encryptToSafeBuffer(c, 
  +                     mp_encryptedData->getEncryptionMethod(), 
  +                     mp_key,
  +                     mp_env->getParentDocument(),
  +                     sb);
        }
  -     
  -     XSECnew(mp_encryptedData, XENCEncryptedDataImpl(this));
  -     mp_encryptedData->createBlankEncryptedData(XENCCipherData::VALUE_TYPE, 
sb.sbStrToXMLCh());
  +     else {
  +
  +             // Very strange if we get here - any problems should throw an
  +             // exception in the AlgorithmMapper.
  +
  +             throw XSECException(XSECException::CipherError, 
  +                     "XENCCipherImpl::decryptElement - Error retrieving a 
handler for algorithm");
  +
  +     }
  +
  +     // Set the value
  +     XENCCipherValue * val = 
mp_encryptedData->getCipherData()->getCipherValue();
  +
  +     val->setCipherString(sb.sbStrToXMLCh());
   
        // Replace original element
        DOMNode * p = element->getParentNode();
  
  
  
  1.4       +4 -4      xml-security/c/src/xenc/impl/XENCCipherDataImpl.hpp
  
  Index: XENCCipherDataImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherDataImpl.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCCipherDataImpl.hpp    11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCCipherDataImpl.hpp    15 Sep 2003 11:53:09 -0000      1.4
  @@ -84,9 +84,9 @@
   
   public:
   
  -     XENCCipherDataImpl(XENCCipherImpl * cipher);
  +     XENCCipherDataImpl(const XSECEnv * env);
        XENCCipherDataImpl(
  -             XENCCipherImpl * cipher, 
  +             const XSECEnv * env, 
                XERCES_CPP_NAMESPACE_QUALIFIER DOMNode * node
        );
   
  @@ -109,7 +109,7 @@
        // Unimplemented constructor
        XENCCipherDataImpl();
   
  -     XENCCipherImpl                  * mp_cipher;
  +     const XSECEnv                   * mp_env;
        XERCES_CPP_NAMESPACE_QUALIFIER DOMNode                                  
                                                        * mp_cipherDataNode;    
        // Node at head of structure
   
  
  
  
  1.4       +10 -9     xml-security/c/src/xenc/impl/XENCCipherDataImpl.cpp
  
  Index: XENCCipherDataImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-security/c/src/xenc/impl/XENCCipherDataImpl.cpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XENCCipherDataImpl.cpp    11 Sep 2003 11:07:07 -0000      1.3
  +++ XENCCipherDataImpl.cpp    15 Sep 2003 11:53:09 -0000      1.4
  @@ -73,6 +73,7 @@
   
   #include <xsec/framework/XSECError.hpp>
   #include <xsec/utils/XSECDOMUtils.hpp>
  +#include <xsec/framework/XSECEnv.hpp>
   
   #include <xercesc/util/XMLUniDefs.hpp>
   
  @@ -137,16 +138,16 @@
   //                   Constructors and Destructors
   // 
--------------------------------------------------------------------------------
   
  -XENCCipherDataImpl::XENCCipherDataImpl(XENCCipherImpl * cipher) :
  -mp_cipher(cipher),
  +XENCCipherDataImpl::XENCCipherDataImpl(const XSECEnv * env) :
  +mp_env(env),
   mp_cipherDataNode(NULL),
   mp_cipherValue(NULL) {
   
   }
   
   
  -XENCCipherDataImpl::XENCCipherDataImpl(XENCCipherImpl * cipher, DOMNode * 
node) :
  -mp_cipher(cipher),
  +XENCCipherDataImpl::XENCCipherDataImpl(const XSECEnv * env, DOMNode * node) :
  +mp_env(env),
   mp_cipherDataNode(node),
   mp_cipherValue(NULL) {
   
  @@ -187,7 +188,7 @@
        if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt), 
s_CipherValue)) {
   
                m_cipherDataType = VALUE_TYPE;
  -             XSECnew(mp_cipherValue, XENCCipherValueImpl(mp_cipher, tmpElt));
  +             XSECnew(mp_cipherValue, XENCCipherValueImpl(mp_env, tmpElt));
                mp_cipherValue->load();
   
        }
  @@ -225,8 +226,8 @@
   
        // Get some setup values
        safeBuffer str;
  -     DOMDocument *doc = mp_cipher->getDocument();
  -     const XMLCh * prefix = mp_cipher->getXENCNSPrefix();
  +     DOMDocument *doc = mp_env->getParentDocument();
  +     const XMLCh * prefix = mp_env->getXENCNSPrefix();
   
        makeQName(str, prefix, s_CipherData);
   
  @@ -239,7 +240,7 @@
                // Should set the type attribute
   
                // Create the Cipher Value
  -             XSECnew(mp_cipherValue, XENCCipherValueImpl(mp_cipher));
  +             XSECnew(mp_cipherValue, XENCCipherValueImpl(mp_env));
                DOMNode * cipherValueNode = 
mp_cipherValue->createBlankCipherValue(value);
   
                ret->appendChild(cipherValueNode);
  
  
  

Reply via email to