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 using xercesc::DOMElement;
38 namespace xmltooling {
39 TrustEngine* XMLTOOL_DLLLOCAL ChainingTrustEngineFactory(const DOMElement* const & e)
41 return new ChainingTrustEngine(e);
45 static const XMLCh _TrustEngine[] = UNICODE_LITERAL_11(T,r,u,s,t,E,n,g,i,n,e);
46 static const XMLCh type[] = UNICODE_LITERAL_4(t,y,p,e);
48 ChainingTrustEngine::ChainingTrustEngine(const DOMElement* e) : TrustEngine(e) {
49 Category& log=Category::getInstance(XMLTOOLING_LOGCAT".TrustEngine."CHAINING_TRUSTENGINE);
50 e = e ? XMLHelper::getFirstChildElement(e, _TrustEngine) : NULL;
53 auto_ptr_char temp(e->getAttributeNS(NULL,type));
54 if (temp.get() && *temp.get()) {
55 log.info("building TrustEngine of type %s", temp.get());
56 TrustEngine* engine = XMLToolingConfig::getConfig().TrustEngineManager.newPlugin(temp.get(), e);
57 m_engines.push_back(engine);
58 SignatureTrustEngine* sig = dynamic_cast<SignatureTrustEngine*>(engine);
60 m_sigEngines.push_back(sig);
61 X509TrustEngine* x509 = dynamic_cast<X509TrustEngine*>(engine);
63 m_x509Engines.push_back(x509);
64 OpenSSLTrustEngine* ossl = dynamic_cast<OpenSSLTrustEngine*>(engine);
66 m_osslEngines.push_back(ossl);
69 catch (exception& ex) {
70 log.error("error building TrustEngine: %s", ex.what());
72 e = XMLHelper::getNextSiblingElement(e, _TrustEngine);
76 ChainingTrustEngine::~ChainingTrustEngine() {
77 for_each(m_engines.begin(), m_engines.end(), xmltooling::cleanup<TrustEngine>());
80 bool ChainingTrustEngine::validate(Signature& sig, const CredentialResolver& credResolver, CredentialCriteria* criteria) const
82 for (vector<SignatureTrustEngine*>::const_iterator i=m_sigEngines.begin(); i!=m_sigEngines.end(); ++i) {
83 if ((*i)->validate(sig,credResolver,criteria))
89 bool ChainingTrustEngine::validate(
90 const XMLCh* sigAlgorithm,
95 const CredentialResolver& credResolver,
96 CredentialCriteria* criteria
99 for (vector<SignatureTrustEngine*>::const_iterator i=m_sigEngines.begin(); i!=m_sigEngines.end(); ++i) {
100 if ((*i)->validate(sigAlgorithm, sig, keyInfo, in, in_len, credResolver, criteria))
106 bool ChainingTrustEngine::validate(
107 XSECCryptoX509* certEE,
108 const vector<XSECCryptoX509*>& certChain,
109 const CredentialResolver& credResolver,
110 CredentialCriteria* criteria
113 for (vector<X509TrustEngine*>::const_iterator i=m_x509Engines.begin(); i!=m_x509Engines.end(); ++i) {
114 if ((*i)->validate(certEE,certChain,credResolver,criteria))
120 bool ChainingTrustEngine::validate(
122 STACK_OF(X509)* certChain,
123 const CredentialResolver& credResolver,
124 CredentialCriteria* criteria
127 for (vector<OpenSSLTrustEngine*>::const_iterator i=m_osslEngines.begin(); i!=m_osslEngines.end(); ++i) {
128 if ((*i)->validate(certEE,certChain,credResolver,criteria))