2.0 SOAP Encoder
[shibboleth/cpp-opensaml.git] / saml / security / TrustEngine.h
1 /*
2  *  Copyright 2001-2006 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 saml/security/TrustEngine.h
19  * 
20  * SAML-specific TrustEngine API
21  */
22
23 #ifndef __saml_trust_h__
24 #define __saml_trust_h__
25
26 #include <saml/base.h>
27 #include <saml/saml2/metadata/Metadata.h>
28 #include <xmltooling/signature/KeyResolver.h>
29
30 namespace opensaml {
31
32     /**
33      * Adapts SAML metadata as a source of KeyInfo for a TrustEngine
34      * and adds SAML-specific signature validation.
35      */
36     class SAML_API TrustEngine {
37         MAKE_NONCOPYABLE(TrustEngine);
38     protected:
39         /**
40          * Constructor.
41          * 
42          * If a DOM is supplied, the following XML content is supported:
43          * 
44          * <ul>
45          *  <li>&lt;KeyResolver&gt; elements with a type attribute
46          * </ul>
47          * 
48          * XML namespaces are ignored in the processing of this content.
49          * 
50          * @param e DOM to supply configuration for provider
51          */
52         TrustEngine(const DOMElement* e=NULL) {}
53         
54     public:
55         virtual ~TrustEngine() {}
56
57         /**
58          * Determines whether a signed SAML object is correct and valid with respect
59          * to the information known about the issuer.
60          * 
61          * A custom KeyResolver can be supplied from outside the TrustEngine.
62          * Alternatively, one may be specified to the plugin constructor.
63          * A non-caching, inline resolver will be used as a fallback.
64          * 
65          * @param sig           reference to a signature object to validate
66          * @param role          metadata role supplying key information
67          * @param keyResolver   optional externally supplied KeyResolver, or NULL
68          * @return  true iff the signature validates
69          */
70         virtual bool validate(
71             xmlsignature::Signature& sig,
72             const saml2md::RoleDescriptor& role,
73             const xmlsignature::KeyResolver* keyResolver=NULL
74             ) const=0;
75
76         /**
77          * Determines whether a raw signature is correct and valid with respect to
78          * the information known about the signer.
79          * 
80          * <p>A custom KeyResolver can be supplied from outside the TrustEngine.
81          * Alternatively, one may be specified to the plugin constructor.
82          * A non-caching, inline resolver will be used as a fallback.
83          * 
84          * @param sigAlgorithm  XML Signature identifier for the algorithm used
85          * @param sig           null-terminated base64-encoded signature value
86          * @param keyInfo       KeyInfo object accompanying the signature, if any
87          * @param in            the input data over which the signature was created
88          * @param in_len        size of input data in bytes
89          * @param role          metadata role supplying key information
90          * @param keyResolver   optional externally supplied KeyResolver, or NULL
91          * @return  true iff the signature validates
92          */
93         virtual bool validate(
94             const XMLCh* sigAlgorithm,
95             const char* sig,
96             xmlsignature::KeyInfo* keyInfo,
97             const char* in,
98             unsigned int in_len,
99             const saml2md::RoleDescriptor& role,
100             const xmlsignature::KeyResolver* keyResolver=NULL
101             ) const=0;
102     };
103     
104
105     /**
106      * Registers TrustEngine classes into the runtime.
107      */
108     void SAML_API registerTrustEngines();
109
110     /** TrustEngine based on explicit key information resolved from metadata. */
111     #define EXPLICIT_KEY_SAMLTRUSTENGINE  "org.opensaml.security.ExplicitKeyTrustEngine"
112
113     /** TrustEngine that tries multiple engines in sequence. */
114     #define CHAINING_SAMLTRUSTENGINE  "org.opensaml.security.ChainingTrustEngine"
115 };
116
117 #endif /* __saml_trust_h__ */