80e584957d10abba3c718599bd916f4b6c5ec266
[shibboleth/cpp-xmltooling.git] / xmltooling / security / ChainingTrustEngine.h
1 /*
2  *  Copyright 2001-2010 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 #include <vector>
30
31 namespace xmltooling {
32
33     /**
34      * OpenSSLTrustEngine that uses multiple engines in sequence.
35      */
36     class XMLTOOL_API ChainingTrustEngine : public SignatureTrustEngine, public OpenSSLTrustEngine {
37     public:
38         /**
39          * Constructor.
40          * 
41          * If a DOM is supplied, the following XML content is supported:
42          * 
43          * <ul>
44          *  <li>&lt;TrustEngine&gt; elements with a type attribute
45          * </ul>
46          * 
47          * XML namespaces are ignored in the processing of this content.
48          * 
49          * @param e DOM to supply configuration for provider
50          */
51         ChainingTrustEngine(const xercesc::DOMElement* e=nullptr);
52         
53         /**
54          * Destructor will delete any embedded engines.
55          */
56         virtual ~ChainingTrustEngine();
57
58         /**
59          * Adds a trust engine for future calls.
60          * 
61          * @param newEngine trust engine to add
62          */
63         void addTrustEngine(TrustEngine* newEngine);
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
73         bool validate(
74             xmlsignature::Signature& sig,
75             const CredentialResolver& credResolver,
76             CredentialCriteria* criteria=nullptr
77             ) const;
78         bool validate(
79             const XMLCh* sigAlgorithm,
80             const char* sig,
81             xmlsignature::KeyInfo* keyInfo,
82             const char* in,
83             unsigned int in_len,
84             const CredentialResolver& credResolver,
85             CredentialCriteria* criteria=nullptr
86             ) const;
87         bool validate(
88             XSECCryptoX509* certEE,
89             const std::vector<XSECCryptoX509*>& certChain,
90             const CredentialResolver& credResolver,
91             CredentialCriteria* criteria=nullptr
92             ) const;
93         bool validate(
94             X509* certEE,
95             STACK_OF(X509)* certChain,
96             const CredentialResolver& credResolver,
97             CredentialCriteria* criteria=nullptr
98             ) const;
99     private:
100         std::vector<TrustEngine*> m_engines;
101         std::vector<SignatureTrustEngine*> m_sigEngines;
102         std::vector<X509TrustEngine*> m_x509Engines;
103         std::vector<OpenSSLTrustEngine*> m_osslEngines;
104     };
105     
106 };
107
108 #endif /* __xmltooling_chaintrust_h__ */