2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * ChainingTrustEngine.cpp
20 * TrustEngine that uses multiple engines in sequence.
24 #include "exceptions.h"
26 #include "security/ChainingTrustEngine.h"
27 #include "util/XMLHelper.h"
29 #include <xercesc/util/XMLUniDefs.hpp>
31 using namespace xmlsignature;
32 using namespace xmltooling::logging;
33 using namespace xmltooling;
36 namespace xmltooling {
37 TrustEngine* XMLTOOL_DLLLOCAL ChainingTrustEngineFactory(const DOMElement* const & e)
39 return new ChainingTrustEngine(e);
43 static const XMLCh _TrustEngine[] = UNICODE_LITERAL_11(T,r,u,s,t,E,n,g,i,n,e);
44 static const XMLCh type[] = UNICODE_LITERAL_4(t,y,p,e);
46 ChainingTrustEngine::ChainingTrustEngine(const DOMElement* e) : TrustEngine(e) {
47 Category& log=Category::getInstance(XMLTOOLING_LOGCAT".TrustEngine."CHAINING_TRUSTENGINE);
48 e = e ? XMLHelper::getFirstChildElement(e, _TrustEngine) : NULL;
51 auto_ptr_char temp(e->getAttributeNS(NULL,type));
52 if (temp.get() && *temp.get()) {
53 log.info("building TrustEngine of type %s", temp.get());
54 TrustEngine* engine = XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(temp.get(), e);
55 m_engines.push_back(engine);
56 SignatureTrustEngine* sig = dynamic_cast<SignatureTrustEngine*>(engine);
58 m_sigEngines.push_back(sig);
59 X509TrustEngine* x509 = dynamic_cast<X509TrustEngine*>(engine);
61 m_x509Engines.push_back(x509);
62 OpenSSLTrustEngine* ossl = dynamic_cast<OpenSSLTrustEngine*>(engine);
64 m_osslEngines.push_back(ossl);
67 catch (exception& ex) {
68 log.error("error building TrustEngine: %s", ex.what());
70 e = XMLHelper::getNextSiblingElement(e, _TrustEngine);
74 ChainingTrustEngine::~ChainingTrustEngine() {
75 for_each(m_engines.begin(), m_engines.end(), xmltooling::cleanup<TrustEngine>());
78 bool ChainingTrustEngine::validate(Signature& sig, const CredentialResolver& credResolver, CredentialCriteria* criteria) const
80 for (vector<SignatureTrustEngine*>::const_iterator i=m_sigEngines.begin(); i!=m_sigEngines.end(); ++i) {
81 if ((*i)->validate(sig,credResolver,criteria))
87 bool ChainingTrustEngine::validate(
88 const XMLCh* sigAlgorithm,
93 const CredentialResolver& credResolver,
94 CredentialCriteria* criteria
97 for (vector<SignatureTrustEngine*>::const_iterator i=m_sigEngines.begin(); i!=m_sigEngines.end(); ++i) {
98 if ((*i)->validate(sigAlgorithm, sig, keyInfo, in, in_len, credResolver, criteria))
104 bool ChainingTrustEngine::validate(
105 XSECCryptoX509* certEE,
106 const vector<XSECCryptoX509*>& certChain,
107 const CredentialResolver& credResolver,
108 CredentialCriteria* criteria
111 for (vector<X509TrustEngine*>::const_iterator i=m_x509Engines.begin(); i!=m_x509Engines.end(); ++i) {
112 if ((*i)->validate(certEE,certChain,credResolver,criteria))
118 bool ChainingTrustEngine::validate(
120 STACK_OF(X509)* certChain,
121 const CredentialResolver& credResolver,
122 CredentialCriteria* criteria
125 for (vector<OpenSSLTrustEngine*>::const_iterator i=m_osslEngines.begin(); i!=m_osslEngines.end(); ++i) {
126 if ((*i)->validate(certEE,certChain,credResolver,criteria))