Merge branch '1.x' of ssh://authdev.it.ohio-state.edu/~scantor/git/cpp-xmltooling...
[shibboleth/cpp-xmltooling.git] / xmltooling / security / ChainingTrustEngine.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * @file xmltooling/security/ChainingTrustEngine.h
23  * 
24  * OpenSSLTrustEngine that uses multiple engines in sequence.
25  */
26
27 #if !defined(__xmltooling_chaintrust_h__) && !defined(XMLTOOLING_NO_XMLSEC)
28 #define __xmltooling_chaintrust_h__
29
30 #include <xmltooling/security/OpenSSLTrustEngine.h>
31 #include <xmltooling/security/SignatureTrustEngine.h>
32
33 #include <vector>
34
35 namespace xmltooling {
36
37     /**
38      * OpenSSLTrustEngine that uses multiple engines in sequence.
39      */
40     class XMLTOOL_API ChainingTrustEngine : public SignatureTrustEngine, public OpenSSLTrustEngine {
41     public:
42         /**
43          * Constructor.
44          * 
45          * If a DOM is supplied, the following XML content is supported:
46          * 
47          * <ul>
48          *  <li>&lt;TrustEngine&gt; elements with a type attribute
49          * </ul>
50          * 
51          * XML namespaces are ignored in the processing of this content.
52          * 
53          * @param e DOM to supply configuration for provider
54          */
55         ChainingTrustEngine(const xercesc::DOMElement* e=nullptr);
56         
57         /**
58          * Destructor will delete any embedded engines.
59          */
60         virtual ~ChainingTrustEngine();
61
62         /**
63          * Adds a trust engine for future calls.
64          * 
65          * @param newEngine trust engine to add
66          */
67         void addTrustEngine(TrustEngine* newEngine);
68
69         /**
70          * Removes a trust engine. The caller must delete the engine if necessary.
71          * 
72          * @param oldEngine trust engine to remove
73          * @return  the old engine
74          */
75         TrustEngine* removeTrustEngine(TrustEngine* oldEngine);
76
77         bool validate(
78             xmlsignature::Signature& sig,
79             const CredentialResolver& credResolver,
80             CredentialCriteria* criteria=nullptr
81             ) const;
82         bool validate(
83             const XMLCh* sigAlgorithm,
84             const char* sig,
85             xmlsignature::KeyInfo* keyInfo,
86             const char* in,
87             unsigned int in_len,
88             const CredentialResolver& credResolver,
89             CredentialCriteria* criteria=nullptr
90             ) const;
91         bool validate(
92             XSECCryptoX509* certEE,
93             const std::vector<XSECCryptoX509*>& certChain,
94             const CredentialResolver& credResolver,
95             CredentialCriteria* criteria=nullptr
96             ) const;
97         bool validate(
98             X509* certEE,
99             STACK_OF(X509)* certChain,
100             const CredentialResolver& credResolver,
101             CredentialCriteria* criteria=nullptr
102             ) const;
103     private:
104         std::vector<TrustEngine*> m_engines;
105         std::vector<SignatureTrustEngine*> m_sigEngines;
106         std::vector<X509TrustEngine*> m_x509Engines;
107         std::vector<OpenSSLTrustEngine*> m_osslEngines;
108     };
109     
110 };
111
112 #endif /* __xmltooling_chaintrust_h__ */