Convert from NULL macro to nullptr.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / SignatureTrustEngine.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/SignatureTrustEngine.h
19  * 
20  * TrustEngine interface that adds validation of digital signatures.
21  */
22
23 #if !defined(__xmltooling_sigtrust_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_sigtrust_h__
25
26 #include <xmltooling/security/TrustEngine.h>
27
28 namespace xmlsignature {
29     class XMLTOOL_API KeyInfo;
30     class XMLTOOL_API Signature;
31 };
32
33 namespace xmltooling {
34
35     class XMLTOOL_API CredentialCriteria;
36     class XMLTOOL_API CredentialResolver;
37
38     /**
39      * TrustEngine interface that adds validation of digital signatures.
40      */
41     class XMLTOOL_API SignatureTrustEngine : public virtual TrustEngine {
42     protected:
43         /**
44          * Constructor.
45          * 
46          * If a DOM is supplied, the following XML content is supported:
47          * 
48          * <ul>
49          *  <li>&lt;KeyInfoResolver&gt; elements with a type attribute
50          * </ul>
51          * 
52          * XML namespaces are ignored in the processing of this content.
53          * 
54          * @param e DOM to supply configuration for provider
55          */
56         SignatureTrustEngine(const xercesc::DOMElement* e=nullptr);
57         
58     public:
59         virtual ~SignatureTrustEngine();
60
61         /**
62          * Determines whether an XML signature is correct and valid with respect to
63          * the source of credentials supplied.
64          * 
65          * <p>It is the responsibility of the application to ensure that the credentials
66          * supplied are in fact associated with the peer who created the signature.
67          * 
68          * <p>If criteria with a peer name are supplied, the "name" of the Credential that verifies
69          * the signature may also be checked to ensure that it identifies the intended peer.
70          * The peer name itself or implementation-specific rules based on the content of the
71          * peer credentials may be applied. Implementations may omit this check if they
72          * deem it unnecessary.
73          * 
74          * @param sig           reference to a signature object to validate
75          * @param credResolver  a locked resolver to supply trusted peer credentials to the TrustEngine
76          * @param criteria      criteria for selecting peer credentials
77          * @return  true iff the signature validates
78          */
79         virtual bool validate(
80             xmlsignature::Signature& sig,
81             const CredentialResolver& credResolver,
82             CredentialCriteria* criteria=nullptr
83             ) const=0;
84
85         /**
86          * Determines whether a raw signature is correct and valid with respect to
87          * the source of credentials supplied.
88          * 
89          * <p>It is the responsibility of the application to ensure that the Credentials
90          * supplied are in fact associated with the peer who created the signature.
91          * 
92          * <p>If criteria with a peer name are supplied, the "name" of the Credential that verifies
93          * the signature may also be checked to ensure that it identifies the intended peer.
94          * The peer name itself or implementation-specific rules based on the content of the
95          * peer credentials may be applied. Implementations may omit this check if they
96          * deem it unnecessary.
97          *
98          * <p>Note that the keyInfo parameter is not part of the implicitly trusted
99          * set of information supplied via the CredentialResolver, but rather advisory
100          * data that may have accompanied the signature itself.
101          * 
102          * @param sigAlgorithm  XML Signature identifier for the algorithm used
103          * @param sig           null-terminated base64-encoded signature value
104          * @param keyInfo       KeyInfo object accompanying the signature, if any
105          * @param in            the input data over which the signature was created
106          * @param in_len        size of input data in bytes
107          * @param credResolver  a locked resolver to supply trusted peer credentials to the TrustEngine
108          * @param criteria      criteria for selecting peer credentials
109          * @return  true iff the signature validates
110          */
111         virtual bool validate(
112             const XMLCh* sigAlgorithm,
113             const char* sig,
114             xmlsignature::KeyInfo* keyInfo,
115             const char* in,
116             unsigned int in_len,
117             const CredentialResolver& credResolver,
118             CredentialCriteria* criteria=nullptr
119             ) const=0;
120     };
121 };
122
123 #endif /* __xmltooling_sigtrust_h__ */