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