blautenb 2003/08/31 05:47:19
Added: c/src/xenc XENCCipher.hpp XENCCipherData.hpp
XENCCipherValue.hpp XENCEncryptedData.hpp
XENCEncryptedType.hpp XENCEncryptionMethod.hpp
c/src/xenc/impl XENCCipherDataImpl.cpp
XENCCipherDataImpl.hpp XENCCipherImpl.cpp
XENCCipherImpl.hpp XENCCipherValueImpl.cpp
XENCCipherValueImpl.hpp XENCEncryptedDataImpl.cpp
XENCEncryptedDataImpl.hpp XENCEncryptedTypeImpl.cpp
XENCEncryptedTypeImpl.hpp
Log:
Skeleton for XML Encryption
Revision Changes Path
1.1 xml-security/c/src/xenc/XENCCipher.hpp
Index: XENCCipher.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipher := Interface definition for main encryption worker class
*
* $Id: XENCCipher.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCCIPHER_INCLUDE
#define XENCCIPHER_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
// Xerces
XSEC_DECLARE_XERCES_CLASS(DOMElement);
XSEC_DECLARE_XERCES_CLASS(DOMDocument);
class XSECCryptoKey;
/**
* @defgroup xenc XML Encryption Implementation
*
* <p>The classes in this group implement the XML Encryption
* standard. In most cases, users should interact with these
* functions via the XENCCipher class</p>
*
[EMAIL PROTECTED]/
/**
* @brief Main worker class for the XSEC implementation of XML
* Encryption.
*
* The XENCCipher class not something that is directly defined in
* the XML Encryption standard. It is a control class used by the
* library to generate encrypted XML information and to decrypt
* information held in XML Encryption structures.
*
*/
class XENCCipher {
public:
/** @name Constructors and Destructors */
//@{
virtual ~XENCCipher() {};
//@}
/** @name Decryption Functions */
//@{
/**
* \brief Decrypt the nominated element.
*
* Decrypts the passed in element, which must be the root
* node of a \<EncryptedData\> method with a type of "#Element".
* If not, the library will throw an XSECException exception.
*
* This is an "all in one method". The library will replace
* the passed in Element (i.e. the encrypted XML data) with
* the resultant plain text, after it has been parsed back into
* DOM nodes
*
* @param element Root of EncryptedData DOM structyre to decrypt
* @returns The owning document with the element replaced, or NULL
* if the decryption fails for some reason (normally an exception).
* @throws XSECException if the decryption fails, or if this is
* not a valid EncryptedData DOM structure.
*/
virtual DOMDocument * decryptElement(DOMElement * element) = 0;
//@}
/** @name Getter Functions */
//@{
/**
* \brief Get owning document
*
* Every Cipher object is associated with an owning document (for
generation of
* nodes etc.) This allows callers to retrieve this value.
*
* @returns The DOMDocument that is used by this object
*/
virtual DOMDocument * getDocument(void) = 0;
//@}
/** @name Setter Functions */
//@{
/**
* \brief Set decryption key for next operation
*
* Set the passed in key for the next decryption/encryption
* operation.
*
* @param key Key to use
* @note Unlike the EncryptedType element and its derivatives, this
* function will take ownership of the key and delete it when done.
*/
virtual void setKey(XSECCryptoKey * key) = 0;
};
/[EMAIL PROTECTED]/
#endif /* XENCCIPHER_INCLUDE */
1.1 xml-security/c/src/xenc/XENCCipherData.hpp
Index: XENCCipherData.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherData := Interface for CipherData elements
*
* $Id: XENCCipherData.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XSECCIPHERDATA_INCLUDE
#define XSECCIPHERDATA_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCCipherValue.hpp>
/**
* @ingroup xenc
* @{
*/
/**
* @brief Interface definition for the CipherData object
*
* The \<CipherData\> element either holds the encrypted data (via
* a CipherValue element) or a reference to the encrypted data.
*
* Within the library, the CipherData element can only be used to
* hold and read the encrypted data. To actually decrypt/encrypt
* data, an XENCEncryptedType derivative object of XENCCipher object
* should be used.
*
*/
class XENCCipherData {
public:
/**
* CipherDataType
*/
enum XENCCipherDataType {
CipherNone = 0, /** Not Set */
CipherValue = 1,
CipherReference = 2,
};
/** @name Constructors and Destructors */
//@{
protected:
XENCCipherData() {};
public:
virtual ~XENCCipherData() {};
/** @name Get Interface Methods */
//@{
/**
* \brief Find the type of Cipher Data held
*
* CipherData elements can hold either a CipherValue element (whose
* text is the encrypted data) or a CipherReference element, where the
* contents tell the library how to retrieve the encrypted data from
* elsewhere.
*
* @returns The type of CipherData
*/
virtual XENCCipherDataType getCipherDataType(void) = 0;
/**
* \brief Get the CipherValue element
*
* @returns the CipherValue element, or NULL if one is not held
*/
virtual XENCCipherValue * getCipherValue(void) = 0;
//@}
private:
// Unimplemented
XENCCipherData(const XENCCipherData &);
XENCCipherData & operator = (const XENCCipherData &);
};
#endif /* XENCCIPHERDATA_INCLUDE */
1.1 xml-security/c/src/xenc/XENCCipherValue.hpp
Index: XENCCipherValue.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherValue := Interface definition for CipherValue element
*
* $Id: XENCCipherValue.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCCIPHERVALUE_INCLUDE
#define XENCCIPHERVALUE_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
/**
* @ingroup xenc
* @{
*/
/**
* @brief Interface definition for the CipherValue object
*
* The \<CipherValue\> element holds the base64 encoded, encrypted data.
* This is a very simple class that acts purely as a holder of data.
*
*/
class XENCCipherValue {
/** @name Constructors and Destructors */
//@{
protected:
XENCCipherValue() {};
public:
virtual ~XENCCipherValue() {};
/** @name Get Interface Methods */
//@{
/**
* \brief Get the encrypted information
*
* CipherValue nodes contain a text child that holds the base64 encoded
* cipher text that needs to be decrypted. This call will return the
* base64 encoded string.
*
* @returns The Encrypted information in a base64 encoded string
*/
virtual const XMLCh * getCipherString(void) = 0;
//@}
private:
// Unimplemented
XENCCipherValue(const XENCCipherValue &);
XENCCipherValue & operator = (const XENCCipherValue &);
};
#endif /* XENCCIPHERVALUE_INCLUDE */
1.1 xml-security/c/src/xenc/XENCEncryptedData.hpp
Index: XENCEncryptedData.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptedData := Definition for holder object for EncryptedData
* element
*
* $Id: XENCEncryptedData.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCENCRYPTEDDATA_INCLUDE
#define XENCENCRYPTEDDATA_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCEncryptedType.hpp>
#include <xsec/xenc/XENCCipherData.hpp>
/**
* @ingroup xenc
* @{
*/
/**
* @brief Interface definition for the EncryptedData object
*
* The \<EncryptedData\> element is an abstract type which builds
* on the EncryptedType element for encrypted data (as opposed to
* encrypted keys).
*
* In general, this class should not be used directly. For most
* applications, callers will want to use the XENCCipher class
* instead.
*/
class XENCEncryptedData : public XENCEncryptedType {
/** @name Constructors and Destructors */
//@{
protected:
XENCEncryptedData() {};
public:
virtual ~XENCEncryptedData() {};
/** @name Get Interface Methods */
//@{
/**
* \brief Retrieve the CipherData element
*
* CipherData elements are the sub part of the EncryptedData
* that hold the actual enciphered information.
*
* @returns The CipherData object
*/
virtual XENCCipherData * getCipherData(void) = 0;
//@}
private:
// Unimplemented
XENCEncryptedData(const XENCEncryptedData &);
XENCEncryptedData & operator = (const XENCEncryptedData &);
};
#endif /* XENCENCRYPTEDDATA_INCLUDE */
1.1 xml-security/c/src/xenc/XENCEncryptedType.hpp
Index: XENCEncryptedType.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptedType := Definition for holder object for EncryptedType
* element
*
* Author(s): Berin Lautenbach
*
* $Id: XENCEncryptedType.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCENCRYPTEDTYPE_INCLUDE
#define XENCENCRYPTEDTYPE_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
class XSECCryptoKey;
/**
* @ingroup xenc
* @{
*/
/**
* @brief Interface definition for the EncryptedType object
*
* The \<EncryptedType\> element is an abstract type on which
* EncryptedData and EncryptedKey objects are built.
*
* This is the base class on which most of the XML Encryption
* standard is built. Using classes derived from this,
* calling programs can decrypt the content, determine KeyInfo
* references etc.
*
* In general derived objects should not be used directly.
* The XENCCipher class should be used to operate on them.
*/
class XENCEncryptedType {
/** @name Constructors and Destructors */
//@{
protected:
XENCEncryptedType() {};
public:
virtual ~XENCEncryptedType() {};
/** @name Interface Methods */
//@{
/**
* \brief Set the encryption key to be used to decrypt
*
* The decrypt functions use this key to decrypt the cipher data.
*
* @param key The key to use for encryption/decryption
* @note The object will take a copy of the key (using
XSECCryptoKey::clone()).
*/
virtual void setKey(XSECCryptoKey * key) = 0;
//@}
private:
// Unimplemented
XENCEncryptedType(const XENCEncryptedType &);
XENCEncryptedType & operator = (const XENCEncryptedType &);
};
#endif /* XENCENCRYPTEDTYPE_INCLUDE */
1.1 xml-security/c/src/xenc/XENCEncryptionMethod.hpp
Index: XENCEncryptionMethod.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptionMethod := Interface definition for EncryptionMethod element
*
* $Id: XENCEncryptionMethod.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCENCRYPTIONMETHOD_INCLUDE
#define XENCENCRYPTIONMETHOD_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
/**
* @ingroup xenc
* @{
*/
/**
* @brief Interface definition for the EncryptionMethod object
*
* The \<EncryptionMethod\> element holds information about the
* encryption algorithm being used.
*
* This element is optional within an EncryptedType derivative,
* but applications not making use of this need to know the
* this information, otherwise the library will not be able to
* decrypt the data.
*
*/
class XENCEncryptionMethod {
};
#endif /* XENCENCRYPTIONMETHOD_INCLUDE */
1.1 xml-security/c/src/xenc/impl/XENCCipherDataImpl.cpp
Index: XENCCipherDataImpl.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherDataImpl := Implementation of CipherData elements
*
* $Id: XENCCipherDataImpl.cpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#include <xsec/framework/XSECDefs.hpp>
#include "XENCCipherDataImpl.hpp"
#include "XENCCipherValueImpl.hpp"
#include <xsec/framework/XSECError.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
//
--------------------------------------------------------------------------------
// String Constants
//
--------------------------------------------------------------------------------
static XMLCh s_CipherData[] = {
XERCES_CPP_NAMESPACE :: chLatin_C,
XERCES_CPP_NAMESPACE :: chLatin_i,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_h,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_D,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chNull,
};
static XMLCh s_CipherValue[] = {
XERCES_CPP_NAMESPACE :: chLatin_C,
XERCES_CPP_NAMESPACE :: chLatin_i,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_h,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_V,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chLatin_l,
XERCES_CPP_NAMESPACE :: chLatin_u,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chNull,
};
static XMLCh s_CipherReference[] = {
XERCES_CPP_NAMESPACE :: chLatin_C,
XERCES_CPP_NAMESPACE :: chLatin_i,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_h,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_R,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_f,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_n,
XERCES_CPP_NAMESPACE :: chLatin_c,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chNull,
};
//
--------------------------------------------------------------------------------
// Constructors and Destructors
//
--------------------------------------------------------------------------------
XENCCipherDataImpl::XENCCipherDataImpl(XENCCipherImpl * cipher) :
mp_cipher(cipher),
mp_cipherDataNode(NULL),
mp_cipherValue(NULL) {
}
XENCCipherDataImpl::XENCCipherDataImpl(XENCCipherImpl * cipher, DOMNode *
node) :
mp_cipher(cipher),
mp_cipherDataNode(node),
mp_cipherValue(NULL) {
}
XENCCipherDataImpl::~XENCCipherDataImpl() {
if (mp_cipherValue != NULL)
delete mp_cipherValue;
}
//
--------------------------------------------------------------------------------
// Load DOM
//
--------------------------------------------------------------------------------
void XENCCipherDataImpl::load() {
if (mp_cipherDataNode == NULL) {
// Attempt to load an empty encryptedType element
throw XSECException(XSECException::CipherDataError,
"XENCCipherData::load - called on empty DOM");
}
if (!strEquals(getXENCLocalName(mp_cipherDataNode), s_CipherData)) {
throw XSECException(XSECException::CipherDataError,
"XENCCipherData::load - called incorrect node");
}
// Find out whether this is a CipherValue or CipherReference and load
// appropriately
DOMNode *tmpElt = findFirstChildOfType(mp_cipherDataNode,
DOMNode::ELEMENT_NODE);
if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt),
s_CipherValue)) {
m_cipherDataType = CipherValue;
XSECnew(mp_cipherValue, XENCCipherValueImpl(mp_cipher, tmpElt));
mp_cipherValue->load();
}
else if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt),
s_CipherReference)) {
m_cipherDataType = CipherNone;
}
else {
throw XSECException(XSECException::ExpectedXENCChildNotFound,
"XENCCipherData::load - expected <CipherValue> or
<CipherReference>");
}
}
//
--------------------------------------------------------------------------------
// Constructors and Destructors
//
--------------------------------------------------------------------------------
// Interface methods
XENCCipherDataImpl::XENCCipherDataType
XENCCipherDataImpl::getCipherDataType(void) {
return m_cipherDataType;
}
XENCCipherValue * XENCCipherDataImpl::getCipherValue(void) {
return mp_cipherValue;
}
1.1 xml-security/c/src/xenc/impl/XENCCipherDataImpl.hpp
Index: XENCCipherDataImpl.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherDataImpl := Implementation of CipherData elements
*
* $Id: XENCCipherDataImpl.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XSECCIPHERDATAIMPL_INCLUDE
#define XSECCIPHERDATAIMPL_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCCipherData.hpp>
#include "XENCCipherImpl.hpp"
class XENCCipherValueImpl;
XSEC_DECLARE_XERCES_CLASS(DOMNode);
class XENCCipherDataImpl : public XENCCipherData {
public:
XENCCipherDataImpl(XENCCipherImpl * cipher);
XENCCipherDataImpl(XENCCipherImpl * cipher, DOMNode * node);
virtual ~XENCCipherDataImpl();
// Load elements
void load();
// Interface methods
virtual XENCCipherDataType getCipherDataType(void);
virtual XENCCipherValue * getCipherValue(void);
private:
// Unimplemented constructor
XENCCipherDataImpl();
XENCCipherImpl * mp_cipher;
DOMNode * mp_cipherDataNode;
// Node at head of structure
XENCCipherDataType m_cipherDataType;
// Is this a value or a reference?
XENCCipherValueImpl * mp_cipherValue;
// Cipher value node
};
#endif /* XENCCIPHERDATAIMPL_INCLUDE */
1.1 xml-security/c/src/xenc/impl/XENCCipherImpl.cpp
Index: XENCCipherImpl.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherImpl := Implementation of the main encryption worker class
*
* $Id: XENCCipherImpl.cpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/framework/XSECError.hpp>
#include <xsec/enc/XSECCryptoKey.hpp>
#include <xsec/transformers/TXFMChain.hpp>
#include <xsec/transformers/TXFMBase.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include "XENCCipherImpl.hpp"
#include "XENCEncryptedDataImpl.hpp"
#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/util/Janitor.hpp>
// With all the characters - just uplift entire thing
XERCES_CPP_NAMESPACE_USE
#include <iostream>
using std::cout;
//
--------------------------------------------------------------------------------
// Constant Strings
//
--------------------------------------------------------------------------------
const XMLCh s_tagname[] = {
XERCES_CPP_NAMESPACE :: chLatin_f,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chLatin_g,
XERCES_CPP_NAMESPACE :: chLatin_m,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_n,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chNull
};
//
--------------------------------------------------------------------------------
// Constructors
//
--------------------------------------------------------------------------------
XENCCipherImpl::XENCCipherImpl(DOMDocument * doc) :
mp_doc(doc),
mp_encryptedData(NULL),
mp_key(NULL) {
}
XENCCipherImpl::~XENCCipherImpl() {
if (mp_encryptedData != NULL)
delete mp_encryptedData;
if (mp_key != NULL)
delete mp_key;
}
//
--------------------------------------------------------------------------------
// Serialise/Deserialise an element
//
--------------------------------------------------------------------------------
DOMDocumentFragment * XENCCipherImpl::deSerialise(safeBuffer &content,
DOMNode * ctx) {
DOMDocumentFragment * result;
// Create the context to parse the document against
safeBuffer sb;
sb.sbXMLChIn(DSIGConstants::s_unicodeStrEmpty);
sb.sbXMLChAppendCh(chUnicodeMarker);
//sb.sbXMLChCat8("<?xml version=\"1.0\" encoding=\"UTF-16\"?><");
sb.sbXMLChAppendCh(chOpenAngle);
sb.sbXMLChCat(s_tagname);
// Run through each node up to the document node and find any
// xmlns: nodes that may be needed during the parse of the decrypted
content
DOMNode * ctxParent = ctx->getParentNode();
DOMNode * wk = ctxParent;
while (wk != NULL) {
DOMNamedNodeMap * atts = wk->getAttributes();
int length;
if (atts != NULL)
length = atts->getLength();
else
length = 0;
for (int i = 0 ; i < length ; ++i) {
DOMNode * att = atts->item(i);
if (strEquals(att->getNodeName(),
DSIGConstants::s_unicodeStrXmlns) ||
(XMLString::compareNString(att->getNodeName(),
DSIGConstants::s_unicodeStrXmlns, 5) &&
att->getNodeName()[5] == chColon)) {
// Check to see if this node has already been
found
DOMNode * p = ctxParent;
bool found = false;
while (p != wk) {
DOMNamedNodeMap * tstAtts =
p->getAttributes();
if (tstAtts != NULL &&
tstAtts->getNamedItem(att->getNodeName()) != NULL) {
found = true;
break;
}
p = p->getParentNode();
}
if (found == false) {
// This is an attribute node that needs
to be added
sb.sbXMLChAppendCh(chSpace);
sb.sbXMLChCat(att->getNodeName());
sb.sbXMLChAppendCh(chEqual);
sb.sbXMLChAppendCh(chDoubleQuote);
sb.sbXMLChCat(att->getNodeValue());
sb.sbXMLChAppendCh(chDoubleQuote);
}
}
}
wk = wk->getParentNode();
}
sb.sbXMLChAppendCh(chCloseAngle);
// Now transform the content to UTF-8
sb.sbXMLChCat8(content.rawCharBuffer());
// Terminate the string
sb.sbXMLChAppendCh(chOpenAngle);
sb.sbXMLChAppendCh(chForwardSlash);
sb.sbXMLChCat(s_tagname);
sb.sbXMLChAppendCh(chCloseAngle);
// Now we need to parse the document
XercesDOMParser * parser = new XercesDOMParser;
Janitor<XercesDOMParser> j_parser(parser);
parser->setDoNamespaces(true);
parser->setCreateEntityReferenceNodes(true);
parser->setDoSchema(false);
// Create an input source
unsigned int bytes = XMLString::stringLen(sb.rawXMLChBuffer()) *
sizeof(XMLCh);
char * utf = XMLString::transcode(sb.rawXMLChBuffer());
MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*)
sb.rawBuffer(), bytes, "XSECMem");
//MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*)
utf, strlen(utf), "XSECMem");
Janitor<MemBufInputSource> j_memIS(memIS);
int errorCount = 0;
parser->parse(*memIS);
errorCount = parser->getErrorCount();
if (errorCount > 0)
throw XSECException(XSECException::CipherError, "Errors occured
during de-serialisation of decrypted element content");
DOMDocument * doc = parser->getDocument();
// Create a DocumentFragment to hold the children of the parsed doc
element
DOMDocument *ctxDocument = ctx->getOwnerDocument();
result = ctxDocument->createDocumentFragment();
Janitor<DOMDocumentFragment> j_result(result);
// Now get the children of the document into a DOC fragment
DOMNode * fragElt = doc->getDocumentElement();
DOMNode * child;
if (fragElt != NULL) {
child = fragElt->getFirstChild();
}
else {
throw XSECException(XSECException::CipherError,
"XENCCipher::deSerialse - re-parsed document
unexpectedly empty");
}
while (child != NULL) {
result->appendChild(ctxDocument->importNode(child, true));
child = child->getNextSibling();
}
// Done!
j_result.release();
return result;
}
//
--------------------------------------------------------------------------------
// Decrypt an Element and replace in original document
//
--------------------------------------------------------------------------------
DOMDocument * XENCCipherImpl::decryptElement(DOMElement * element) {
// 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");
}
// 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();
// Do the decrypt
mp_encryptedData->setKey(mp_key);
TXFMChain * c = mp_encryptedData->createDecryptionTXFMChain();
Janitor<TXFMChain> j_c(c);
TXFMBase * b = c->getLastTxfm();
// Read the result into a safeBuffer
XMLByte buf[2050];
safeBuffer sb("");
int len;
while ((len = b->readBytes(buf, 2048)) > 0) {
buf[len] = '\0';
sb.sbStrcatIn((char *) buf);
}
// Now de-serialise
DOMDocumentFragment * frag = deSerialise(sb, element);
if (frag != NULL) {
// Have something to replace current element with
DOMNode * p = element->getParentNode();
DOMNode * c = frag->getFirstChild();
// By inserting the DocumentFragment, we effectively insert the
children
p->replaceChild(frag, element);
// Delete the frag and the old element
frag->release();
element->release();
}
return NULL;
}
1.1 xml-security/c/src/xenc/impl/XENCCipherImpl.hpp
Index: XENCCipherImpl.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherImpl := Implementation of the main encryption worker class
*
* $Id: XENCCipherImpl.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCCIPHERIMPL_INCLUDE
#define XENCCIPHERIMPL_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCCipher.hpp>
class safeBuffer;
class XSECProvider;
class XENCEncryptedDataImpl;
XSEC_DECLARE_XERCES_CLASS(DOMNode);
XSEC_DECLARE_XERCES_CLASS(DOMDocumentFragment);
class XENCCipherImpl : public XENCCipher {
public:
virtual ~XENCCipherImpl();
// Implementation for decrypting elements
DOMDocument * decryptElement(DOMElement * element);
// Getter methods
DOMDocument * getDocument(void) {return mp_doc;}
// Setter methods
void setKey(XSECCryptoKey * key) {mp_key = key;}
protected:
// Protected to prevent direct creation of objects
XENCCipherImpl(DOMDocument * doc);
private:
// Internal functions
DOMDocumentFragment * deSerialise(safeBuffer &content, DOMNode * ctx);
// Unimplemented constructor
XENCCipherImpl();
DOMDocument * mp_doc;
// Document against which this will operate
// Current working object
XENCEncryptedDataImpl * mp_encryptedData;
// Key
XSECCryptoKey * mp_key;
friend XSECProvider;
};
#endif /* XENCCIPHERIMPL_INCLUDE */
1.1 xml-security/c/src/xenc/impl/XENCCipherValueImpl.cpp
Index: XENCCipherValueImpl.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherValueImpl := Implementation for CipherValue elements
*
* $Id: XENCCipherValueImpl.cpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include "XENCCipherValueImpl.hpp"
#include <xsec/framework/XSECError.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
//
--------------------------------------------------------------------------------
// String Constants
//
--------------------------------------------------------------------------------
static XMLCh s_CipherValue[] = {
XERCES_CPP_NAMESPACE :: chLatin_C,
XERCES_CPP_NAMESPACE :: chLatin_i,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_h,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_V,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chLatin_l,
XERCES_CPP_NAMESPACE :: chLatin_u,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chNull,
};
//
--------------------------------------------------------------------------------
// Constructors/Destructors
//
--------------------------------------------------------------------------------
XENCCipherValueImpl::XENCCipherValueImpl(XENCCipherImpl * cipher) :
mp_cipher(cipher),
mp_cipherValueNode(NULL) {
}
XENCCipherValueImpl::XENCCipherValueImpl(XENCCipherImpl * cipher, DOMNode *
node) :
mp_cipher(cipher),
mp_cipherValueNode(node) {
}
XENCCipherValueImpl::~XENCCipherValueImpl() {
if (mp_cipherString != NULL)
delete[] mp_cipherString;
}
//
--------------------------------------------------------------------------------
// Load
//
--------------------------------------------------------------------------------
void XENCCipherValueImpl::load(void) {
if (mp_cipherValueNode == NULL) {
// Attempt to load an empty encryptedType element
throw XSECException(XSECException::CipherValueError,
"XENCCipherData::load - called on empty DOM");
}
if (!strEquals(getXENCLocalName(mp_cipherValueNode), s_CipherValue)) {
throw XSECException(XSECException::CipherValueError,
"XENCCipherData::load - called incorrect node");
}
// JUst gather the text children and continue
safeBuffer txt;
gatherChildrenText(mp_cipherValueNode, txt);
// Get a copy
mp_cipherString = XMLString::replicate(txt.rawXMLChBuffer());
}
//
--------------------------------------------------------------------------------
// Interface Methods
//
--------------------------------------------------------------------------------
const XMLCh * XENCCipherValueImpl::getCipherString(void) {
return mp_cipherString;
}
1.1 xml-security/c/src/xenc/impl/XENCCipherValueImpl.hpp
Index: XENCCipherValueImpl.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCCipherValueImpl := Implementation for CipherValue elements
*
* $Id: XENCCipherValueImpl.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCCIPHERVALUEIMPL_INCLUDE
#define XENCCIPHERVALUEIMPL_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCCipherValue.hpp>
#include "XENCCipherImpl.hpp"
XSEC_DECLARE_XERCES_CLASS(DOMNode);
class XENCCipherValueImpl : public XENCCipherValue {
public:
XENCCipherValueImpl(XENCCipherImpl * cipher);
XENCCipherValueImpl(XENCCipherImpl * cipher, DOMNode * node);
virtual ~XENCCipherValueImpl();
// Load
void load(void);
// Interface methods
const XMLCh * getCipherString(void);
private:
// Unimplemented constructors
XENCCipherValueImpl(const XENCCipherValueImpl &);
XENCCipherValueImpl & operator = (const XENCCipherValueImpl &);
XENCCipher * mp_cipher;
DOMNode * mp_cipherValueNode;
XMLCh * mp_cipherString;
// EncryptedData
};
#endif /* XENCCIPHERVALUEIMPL_INCLUDE */
1.1 xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.cpp
Index: XENCEncryptedDataImpl.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptedDataImpl := Implementation for holder object for
EncryptedData
*
* $Id: XENCEncryptedDataImpl.cpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#include <xsec/framework/XSECDefs.hpp>
#include "XENCCipherImpl.hpp"
#include "XENCEncryptedDataImpl.hpp"
#include "XENCCipherDataImpl.hpp"
#include <xsec/framework/XSECError.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
//
--------------------------------------------------------------------------------
// UNICODE Strings
//
--------------------------------------------------------------------------------
static XMLCh s_EncryptedData[] = {
XERCES_CPP_NAMESPACE :: chLatin_E,
XERCES_CPP_NAMESPACE :: chLatin_n,
XERCES_CPP_NAMESPACE :: chLatin_c,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_y,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_d,
XERCES_CPP_NAMESPACE :: chLatin_D,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chNull,
};
//
--------------------------------------------------------------------------------
// Construct/Destruct
//
--------------------------------------------------------------------------------
XENCEncryptedDataImpl::XENCEncryptedDataImpl(XENCCipherImpl * cipher) :
XENCEncryptedTypeImpl(cipher) {
}
XENCEncryptedDataImpl::XENCEncryptedDataImpl(XENCCipherImpl * cipher, DOMNode
* node) :
XENCEncryptedTypeImpl(cipher, node) {
}
XENCEncryptedDataImpl::~XENCEncryptedDataImpl() {
}
//
--------------------------------------------------------------------------------
// Load
//
--------------------------------------------------------------------------------
void XENCEncryptedDataImpl::load(void) {
if (mp_encryptedTypeNode == NULL) {
// Attempt to load an empty encryptedData element
throw XSECException(XSECException::EncryptedTypeError,
"XENCEncryptedData::load - called on empty DOM");
}
if (!strEquals(getXENCLocalName(mp_encryptedTypeNode),
s_EncryptedData)) {
// Attempt to load an empty encryptedData element
throw XSECException(XSECException::EncryptedTypeError,
"XENCEncryptedData::load - called on non EncryptedData
node");
}
// Now call the virtual function we overloaded to get here.
XENCEncryptedTypeImpl::load();
}
//
--------------------------------------------------------------------------------
// Interface Methods
//
--------------------------------------------------------------------------------
XENCCipherData * XENCEncryptedDataImpl::getCipherData(void) {
return mp_cipherData;
}
1.1 xml-security/c/src/xenc/impl/XENCEncryptedDataImpl.hpp
Index: XENCEncryptedDataImpl.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptedDataImpl := Implementation for holder object for
EncryptedData
*
* $Id: XENCEncryptedDataImpl.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCENCRYPTEDDATAIMPL_INCLUDE
#define XENCENCRYPTEDDATAIMPL_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCEncryptedData.hpp>
#include "XENCCipherImpl.hpp"
#include "XENCEncryptedTypeImpl.hpp"
XSEC_DECLARE_XERCES_CLASS(DOMNode);
class XENCEncryptedDataImpl : public XENCEncryptedTypeImpl, XENCEncryptedData
{
public:
XENCEncryptedDataImpl(XENCCipherImpl * cipher);
XENCEncryptedDataImpl(XENCCipherImpl * cipher, DOMNode * node);
virtual ~XENCEncryptedDataImpl();
void load(void);
// Interface methods
virtual XENCCipherData * getCipherData(void);
virtual void setKey(XSECCryptoKey * key)
{XENCEncryptedTypeImpl::setKey(key);}
private:
// Unimplemented
XENCEncryptedDataImpl(void);
XENCEncryptedDataImpl(const XENCEncryptedDataImpl &);
XENCEncryptedDataImpl & operator = (const XENCEncryptedDataImpl &);
};
#endif /* XENCENCRYPTEDDATAIMPL_INCLUDE */
1.1 xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.cpp
Index: XENCEncryptedTypeImpl.cpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptedTypeImpl := Implementation of the EncryptedType interface
* element
*
* $Id: XENCEncryptedTypeImpl.cpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#include <xsec/framework/XSECDefs.hpp>
#include "XENCCipherImpl.hpp"
#include "XENCCipherDataImpl.hpp"
#include "XENCEncryptedTypeImpl.hpp"
#include <xsec/framework/XSECError.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include <xsec/transformers/TXFMBase64.hpp>
#include <xsec/transformers/TXFMCipher.hpp>
#include <xsec/transformers/TXFMChain.hpp>
#include <xsec/transformers/TXFMSB.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/util/Janitor.hpp>
XSEC_USING_XERCES(Janitor);
XSEC_USING_XERCES(ArrayJanitor);
//
--------------------------------------------------------------------------------
// UNICODE Strings
//
--------------------------------------------------------------------------------
static XMLCh s_EncryptionMethod[] = {
XERCES_CPP_NAMESPACE :: chLatin_E,
XERCES_CPP_NAMESPACE :: chLatin_n,
XERCES_CPP_NAMESPACE :: chLatin_c,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_y,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chLatin_i,
XERCES_CPP_NAMESPACE :: chLatin_o,
XERCES_CPP_NAMESPACE :: chLatin_n,
XERCES_CPP_NAMESPACE :: chLatin_M,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chLatin_h,
XERCES_CPP_NAMESPACE :: chLatin_o,
XERCES_CPP_NAMESPACE :: chLatin_d,
XERCES_CPP_NAMESPACE :: chNull,
};
static XMLCh s_KeyInfo[] = {
XERCES_CPP_NAMESPACE :: chLatin_K,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_y,
XERCES_CPP_NAMESPACE :: chLatin_I,
XERCES_CPP_NAMESPACE :: chLatin_n,
XERCES_CPP_NAMESPACE :: chLatin_f,
XERCES_CPP_NAMESPACE :: chLatin_o,
XERCES_CPP_NAMESPACE :: chNull,
};
static XMLCh s_CipherData[] = {
XERCES_CPP_NAMESPACE :: chLatin_C,
XERCES_CPP_NAMESPACE :: chLatin_i,
XERCES_CPP_NAMESPACE :: chLatin_p,
XERCES_CPP_NAMESPACE :: chLatin_h,
XERCES_CPP_NAMESPACE :: chLatin_e,
XERCES_CPP_NAMESPACE :: chLatin_r,
XERCES_CPP_NAMESPACE :: chLatin_D,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chLatin_t,
XERCES_CPP_NAMESPACE :: chLatin_a,
XERCES_CPP_NAMESPACE :: chNull,
};
//
--------------------------------------------------------------------------------
// Constructors and Destructors
//
--------------------------------------------------------------------------------
XENCEncryptedTypeImpl::XENCEncryptedTypeImpl(XENCCipherImpl * cipher) :
mp_cipher(cipher),
mp_encryptedTypeNode(NULL),
mp_cipherData(NULL),
mp_key(NULL) {
}
XENCEncryptedTypeImpl::XENCEncryptedTypeImpl(XENCCipherImpl * cipher, DOMNode
* node) :
mp_cipher(cipher),
mp_encryptedTypeNode(node),
mp_cipherData(NULL),
mp_key(NULL) {
}
XENCEncryptedTypeImpl::~XENCEncryptedTypeImpl() {
if (mp_cipherData != NULL)
delete mp_cipherData;
if (mp_key != NULL)
delete mp_key;
}
//
--------------------------------------------------------------------------------
// Load DOM Structures
//
--------------------------------------------------------------------------------
void XENCEncryptedTypeImpl::load() {
if (mp_encryptedTypeNode == NULL) {
// Attempt to load an empty encryptedType element
throw XSECException(XSECException::EncryptedTypeError,
"XENCEncryptedType::load - called on empty DOM");
}
// Don't know what the node name should be (held by super class),
// so go straight to the children
DOMNode *tmpElt = findFirstChildOfType(mp_encryptedTypeNode,
DOMNode::ELEMENT_NODE);
if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt),
s_EncryptionMethod)) {
// For now, ignore
tmpElt = findNextChildOfType(tmpElt, DOMNode::ELEMENT_NODE);
}
if (tmpElt != NULL && strEquals(getDSIGLocalName(tmpElt), s_KeyInfo)) {
// For now, ignore
tmpElt = findNextChildOfType(tmpElt, DOMNode::ELEMENT_NODE);
}
if (tmpElt != NULL && strEquals(getXENCLocalName(tmpElt),
s_CipherData)) {
XSECnew(mp_cipherData, XENCCipherDataImpl(mp_cipher, tmpElt));
mp_cipherData->load();
tmpElt = findNextChildOfType(tmpElt, DOMNode::ELEMENT_NODE);
}
else {
throw XSECException(XSECException::ExpectedXENCChildNotFound,
"Expected <CipherData> child of <EncryptedType>");
}
// Should check for EncryptionProperties
}
//
--------------------------------------------------------------------------------
// Create a txfm chain for this transform list
//
--------------------------------------------------------------------------------
void XENCEncryptedTypeImpl::setKey(XSECCryptoKey * key) {
if (key == NULL)
return;
if (mp_key != NULL)
delete mp_key;
mp_key = key->clone();
}
//
--------------------------------------------------------------------------------
// Create a txfm chain for this transform list
//
--------------------------------------------------------------------------------
TXFMChain * XENCEncryptedTypeImpl::createDecryptionTXFMChain(void) {
TXFMChain * chain;
if (mp_cipherData->getCipherDataType() == XENCCipherData::CipherValue) {
// Given we already have this in memory, we transcode to
// local code page and then transform
char * b64 =
XMLString::transcode(mp_cipherData->getCipherValue()->getCipherString());
ArrayJanitor<char> j_b64(b64);
TXFMSB *sb;
XSECnew(sb, TXFMSB(mp_cipher->getDocument()));
sb->setInput(safeBuffer(b64));
// Create a chain
XSECnew(chain, TXFMChain(sb));
// Create a base64 decoder
TXFMBase64 * tb64;
XSECnew(tb64, TXFMBase64(mp_cipher->getDocument()));
chain->appendTxfm(tb64);
}
else {
throw XSECException(XSECException::EncryptedTypeError,
"XENCEncryptedType::createDecryptionTXFMChain - cannot
process non CipherValue elements");
}
Janitor<TXFMChain> j_chain(chain);
// Now add the decryption TXFM
TXFMCipher * tcipher;
XSECnew(tcipher, TXFMCipher(mp_cipher->getDocument(), mp_key, false));
chain->appendTxfm(tcipher);
j_chain.release();
return chain;
}
1.1 xml-security/c/src/xenc/impl/XENCEncryptedTypeImpl.hpp
Index: XENCEncryptedTypeImpl.hpp
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "<WebSig>" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Institute for
* Data Communications Systems, <http://www.nue.et-inf.uni-siegen.de/>.
* The development of this software was partly funded by the European
* Commission in the <WebSig> project in the ISIS Programme.
* For more information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
/*
* XSEC
*
* XENCEncryptedTypeImpl := Implementation of the EncryptedType interface
* element
*
* $Id: XENCEncryptedTypeImpl.hpp,v 1.1 2003/08/31 12:47:19 blautenb Exp $
*
*/
#ifndef XENCENCRYPTEDTYPEIMPL_INCLUDE
#define XENCENCRYPTEDTYPEIMPL_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/xenc/XENCEncryptedType.hpp>
// Forward declarations
XSEC_DECLARE_XERCES_CLASS(DOMNode);
class XENCCipherImpl;
class XENCCipherDataImpl;
class TXFMChain;
class XENCEncryptedTypeImpl : public XENCEncryptedType {
public:
XENCEncryptedTypeImpl(XENCCipherImpl * cipher);
XENCEncryptedTypeImpl(XENCCipherImpl * cipher, DOMNode * node);
virtual ~XENCEncryptedTypeImpl();
// Load elements
void load();
virtual void setKey(XSECCryptoKey * key);
protected:
// Create the txfm list - gives as output a TXFM chain with
// the output being the decrypted data
TXFMChain * createDecryptionTXFMChain(void);
XENCCipherImpl * mp_cipher;
DOMNode * mp_encryptedTypeNode;
// Node at head of structure
XENCCipherDataImpl * mp_cipherData;
XSECCryptoKey * mp_key;
friend XENCCipherImpl;
};
#endif /* XENCENCRYPTEDTYPEIMPL_INCLUDE */