blautenb 2003/09/15 04:48:11
Added: c/src/framework XSECAlgorithmMapper.hpp
XSECAlgorithmMapper.cpp XSECAlgorithmHandler.hpp
Log:
Implementation of AlgorithmMapper - run time handling of algorithm
implementations
Revision Changes Path
1.1 xml-security/c/src/framework/XSECAlgorithmMapper.hpp
Index: XSECAlgorithmMapper.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
*
* XSECAlgorithmMapper := Provides a table of AlgorithmHandlers
* Mapped by Type URI
*
* $Id: XSECAlgorithmMapper.hpp,v 1.1 2003/09/15 11:48:11 blautenb Exp $
*
*/
#ifndef XSECALGMAPPER_INCLUDE
#define XSECALGMAPPER_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <vector>
class XSECAlgorithmHandler;
/**
* @ingroup internal
[EMAIL PROTECTED]/
/**
* @brief Holder class for mapping Algorithms to Handlers
*
*/
class XSECAlgorithmMapper {
public:
/** @name Constructors and Destructors */
//@{
XSECAlgorithmMapper(void);
~XSECAlgorithmMapper();
//@}
/** @name Default mapping strings */
//@{
static const XMLCh s_defaultEncryptionMapping[];
/** @name Map Methods */
//@{
/**
* \brief Map a URI to a handler
*/
XSECAlgorithmHandler * mapURIToHandler(const XMLCh * URI) const;
//@}
/** @name Registration Methods */
//@{
/**
* \brief Register a new handler
*/
void registerHandler(const XMLCh * URI, const XSECAlgorithmHandler &
handler);
//@}
private:
struct MapperEntry {
XMLCh * mp_uri;
XSECAlgorithmHandler * mp_handler;
};
MapperEntry * findEntry(const XMLCh * URI) const;
#if defined(XSEC_NO_NAMESPACES)
typedef vector<MapperEntry *> MapperEntryVectorType;
#else
typedef std::vector<MapperEntry *> MapperEntryVectorType;
#endif
mutable MapperEntryVectorType m_mapping;
};
/[EMAIL PROTECTED]/
#endif /* XSECALGMAPPER_INCLUDE */
1.1 xml-security/c/src/framework/XSECAlgorithmMapper.cpp
Index: XSECAlgorithmMapper.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
*
* XSECAlgorithmMapper := Provides a table of AlgorithmHandlers
* Mapped by Type URI
*
* $Id: XSECAlgorithmMapper.cpp,v 1.1 2003/09/15 11:48:11 blautenb Exp $
*
*/
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
#include <xsec/framework/XSECAlgorithmMapper.hpp>
#include <xsec/framework/XSECError.hpp>
#include <xsec/utils/XSECDOMUtils.hpp>
#include "XSECAlgorithmMapper.hpp"
#include "XSECAlgorithmHandler.hpp"
// Xerces
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
XERCES_CPP_NAMESPACE_USE
// Default strings
const XMLCh XSECAlgorithmMapper::s_defaultEncryptionMapping [] = {
chLatin_D,
chLatin_e,
chLatin_f,
chLatin_a,
chLatin_u,
chLatin_l,
chLatin_t,
chLatin_E,
chLatin_n,
chLatin_c,
chLatin_r,
chLatin_y,
chLatin_p,
chLatin_t,
chLatin_i,
chLatin_o,
chLatin_n,
chNull
};
XSECAlgorithmMapper::XSECAlgorithmMapper(void) {
}
XSECAlgorithmMapper::~XSECAlgorithmMapper() {
MapperEntryVectorType::iterator it = m_mapping.begin();
while (it != m_mapping.end()) {
delete[] (*it)->mp_uri;
delete (*it)->mp_handler;
delete (*it);
it++;
}
m_mapping.clear();
}
XSECAlgorithmMapper::MapperEntry * XSECAlgorithmMapper::findEntry(const XMLCh
* URI) const {
MapperEntryVectorType::iterator it = m_mapping.begin();
while (it != m_mapping.end()) {
if (strEquals((*it)->mp_uri, URI)) {
return (*it);
}
it++;
}
return NULL;
}
XSECAlgorithmHandler * XSECAlgorithmMapper::mapURIToHandler(const XMLCh *
URI) const {
MapperEntry * entry = findEntry(URI);
if (entry == NULL) {
throw XSECException(XSECException::AlgorithmMapperError,
"XSECAlgorithmMapper::mapURIToHandler - URI not found");
}
return entry->mp_handler;
}
void XSECAlgorithmMapper::registerHandler(const XMLCh * URI, const
XSECAlgorithmHandler & handler) {
MapperEntry * entry = findEntry(URI);
if (entry != NULL) {
delete entry->mp_handler;
}
else {
XSECnew(entry, MapperEntry);
entry->mp_uri = XMLString::replicate(URI);
m_mapping.push_back(entry);
}
entry->mp_handler = handler.clone();
}
1.1 xml-security/c/src/framework/XSECAlgorithmHandler.hpp
Index: XSECAlgorithmHandler.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
*
* XSECAlgorithmHandler := Interface class to define handling of
* encryption and signature
algorithms
*
* $Id: XSECAlgorithmHandler.hpp,v 1.1 2003/09/15 11:48:11 blautenb Exp $
*
*/
#ifndef XSECALGHANDLER_INCLUDE
#define XSECALGHANDLER_INCLUDE
// XSEC Includes
#include <xsec/framework/XSECDefs.hpp>
class TXFMChain;
class XENCEncryptionMethod;
class XSECCryptoKey;
class safeBuffer;
XSEC_DECLARE_XERCES_CLASS(DOMDocument);
// Xerces
/**
* @ingroup xenc
[EMAIL PROTECTED]/
/**
* @brief Interface class to provide handlers for processing different
* encryption types.
*
* The XENCCipher class allows users and callers to register algorithm
* handlers for different Type URIs, as defined in the EncryptionMethod
* element within XML Encryption.
*
* A default handler (XENCAlgorithmHandlerDefault) is provided by the
* library, and is used to process all algorithms defined as mandatory
* (and many optional) within the standard.
*
* Users can extend this class to provide custom algorithm handlers
* for their own classes.
*
* @note The library will use a single clone of any provided object for
* a given algorithm. So all implementation classes <b>must</b> be
* thread safe!
*/
class XSECAlgorithmHandler {
public:
/** @name Constructors and Destructors */
//@{
virtual ~XSECAlgorithmHandler() {};
//@}
/** @name Encryption Methods */
//@{
/**
* \brief Encrypt an input Transform chain to a safeBuffer.
*
* This method takes a TXFMChain that will provide the plain
* text data, and places the encrypted and base64 encoded output
* in a safeBuffer.
*
* The EncryptionMethod object is provided so that any algorithm
* specific parameters can be embedded by the processor. Default
* parameters can be set directly (OAEParams and KeySize). Anything
* additional will need to be set within the DOM directly.
*
* @param plainText Chain that will provide the plain bytes. Ownership
* remains with the caller - do not delete.
* @param encryptionMethod Information about the algorithm to use.
* Can also be used to set the required encryption parameters
* @param key The key that has been provided by the calling
* application to perform the encryption.
*
* @note This is not quite the symmetric opposite of decryptToSafeBuffer
* because of the way the library uses transformers. It is expected
* that this method will create a safeBuffer with <b>base64</b> encoded
* data. (It's easier to throw a TXFMBase64 txfmer on the end of the
* chain than to do the encryption and then separately base64 encode.)
*/
virtual bool encryptToSafeBuffer(
TXFMChain * plainText,
XENCEncryptionMethod * encryptionMethod,
XSECCryptoKey * key,
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc,
safeBuffer & result
) = 0;
//@}
/** @name Decryption Methods */
//@{
/**
* \brief Decrypt an input Transform chain to a safeBuffer.
*
* This method takes a TXFMChain that will provide the cipher
* text data, and places the output in a safeBuffer.
*
* The EncryptionMethod object is provided so that any algorithm
* specific parameters can be found by the processor. It also
* allows applications to embed multiple algorithms in a single
* processing object. The Type value can then be read from the
* EncryptionMethod object to determine what to do.
*
* @param cipherText Chain that will provide the cipherText.
* Ownership remains with the caller - do not delete.
* @param encryptionMethod Information about the algorithm to use
* @param key The key that has been determined via a resolver or
* that has been provided by the calling application.
*/
virtual bool decryptToSafeBuffer(
TXFMChain * cipherText,
XENCEncryptionMethod * encryptionMethod,
XSECCryptoKey * key,
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument * doc,
safeBuffer & result
) = 0;
//@}
/** @name Miscellaneous Functions */
//@{
/**
* \brief Create a new instance of the handler
*
* Provides a means for the library to create a new instance
* of the object without knowing its type
*/
virtual XSECAlgorithmHandler * clone(void) const = 0;
//@}
};
/[EMAIL PROTECTED]/
#endif /* XSECALGHANDLER_INCLUDE*/