bd97ac962e6dc56a4bf2402ce736109151ff1d3a
[shibboleth/cpp-xmltooling.git] / xmltooling / security / ChainingTrustEngine.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file xmltooling/security/ChainingTrustEngine.h
19  * 
20  * OpenSSLTrustEngine that uses multiple engines in sequence.
21  */
22
23 #if !defined(__xmltooling_chaintrust_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_chaintrust_h__
25
26 #include <xmltooling/security/OpenSSLTrustEngine.h>
27 #include <xmltooling/security/SignatureTrustEngine.h>
28
29 namespace xmltooling {
30
31     /**
32      * OpenSSLTrustEngine that uses multiple engines in sequence.
33      */
34     class XMLTOOL_API ChainingTrustEngine : public SignatureTrustEngine, public OpenSSLTrustEngine {
35     public:
36         /**
37          * Constructor.
38          * 
39          * If a DOM is supplied, the following XML content is supported:
40          * 
41          * <ul>
42          *  <li>&lt;TrustEngine&gt; elements with a type attribute
43          * </ul>
44          * 
45          * XML namespaces are ignored in the processing of this content.
46          * 
47          * @param e DOM to supply configuration for provider
48          */
49         ChainingTrustEngine(const xercesc::DOMElement* e=NULL);
50         
51         /**
52          * Destructor will delete any embedded engines.
53          */
54         virtual ~ChainingTrustEngine();
55
56         /**
57          * Adds a trust engine for future calls.
58          * 
59          * @param newEngine trust engine to add
60          */
61         void addTrustEngine(TrustEngine* newEngine) {
62             m_engines.push_back(newEngine);
63         }
64
65         /**
66          * Removes a trust engine. The caller must delete the engine if necessary.
67          * 
68          * @param oldEngine trust engine to remove
69          * @return  the old engine
70          */
71         TrustEngine* removeTrustEngine(TrustEngine* oldEngine) {
72             for (std::vector<TrustEngine*>::iterator i=m_engines.begin(); i!=m_engines.end(); i++) {
73                 if (oldEngine==(*i)) {
74                     m_engines.erase(i);
75                     return oldEngine;
76                 }
77             }
78             return NULL;
79         }
80
81         bool validate(
82             xmlsignature::Signature& sig,
83             const CredentialResolver& credResolver,
84             CredentialCriteria* criteria=NULL
85             ) const;
86         bool validate(
87             const XMLCh* sigAlgorithm,
88             const char* sig,
89             xmlsignature::KeyInfo* keyInfo,
90             const char* in,
91             unsigned int in_len,
92             const CredentialResolver& credResolver,
93             CredentialCriteria* criteria=NULL
94             ) const;
95         bool validate(
96             XSECCryptoX509* certEE,
97             const std::vector<XSECCryptoX509*>& certChain,
98             const CredentialResolver& credResolver,
99             CredentialCriteria* criteria=NULL
100             ) const;
101         bool validate(
102             X509* certEE,
103             STACK_OF(X509)* certChain,
104             const CredentialResolver& credResolver,
105             CredentialCriteria* criteria=NULL
106             ) const;
107     private:
108         std::vector<TrustEngine*> m_engines;
109         std::vector<SignatureTrustEngine*> m_sigEngines;
110         std::vector<X509TrustEngine*> m_x509Engines;
111         std::vector<OpenSSLTrustEngine*> m_osslEngines;
112     };
113     
114 };
115
116 #endif /* __xmltooling_chaintrust_h__ */