2.0 SOAP Encoder
[shibboleth/cpp-opensaml.git] / saml / security / AbstractPKIXTrustEngine.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/AbstractPKIXTrustEngine.h
19  * 
20  * A trust engine that uses X.509 trust anchors and CRLs associated with a role
21  * to perform PKIX validation of signatures and certificates.
22  */
23
24 #ifndef __saml_pkixtrust_h__
25 #define __saml_pkixtrust_h__
26
27 #include <saml/security/X509TrustEngine.h>
28 #include <xmltooling/security/XSECCryptoX509CRL.h>
29
30 namespace opensaml {
31
32     /**
33      * A trust engine that uses X.509 trust anchors and CRLs associated with a role
34      * to perform PKIX validation of signatures and certificates.
35      */
36     class SAML_API AbstractPKIXTrustEngine : public X509TrustEngine
37     {
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         AbstractPKIXTrustEngine(const DOMElement* e=NULL);
53         
54         /**
55          * Checks that either the ID for the entity with the given role or the key names
56          * for the given role match the subject or subject alternate names
57          * of the entity's certificate.
58          * 
59          * @param certEE    the credential for the entity to validate
60          * @param role      the descriptor of the role the entity is supposed to be acting in
61          * 
62          * @return true the name check succeeds, false if not
63          */
64         bool checkEntityNames(XSECCryptoX509* certEE, const saml2md::RoleDescriptor& role) const;
65         
66         /** An inline KeyResolver for extracting certificates out of a signature. */
67         xmlsignature::KeyResolver* m_inlineResolver;
68         
69     public:
70         virtual ~AbstractPKIXTrustEngine();
71
72         virtual bool validate(
73             xmlsignature::Signature& sig,
74             const saml2md::RoleDescriptor& role,
75             const xmlsignature::KeyResolver* keyResolver=NULL
76             ) const;
77
78         virtual 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 saml2md::RoleDescriptor& role,
85             const xmlsignature::KeyResolver* keyResolver=NULL
86             ) const;
87
88         virtual bool validate(
89             XSECCryptoX509* certEE,
90             const std::vector<XSECCryptoX509*>& certChain,
91             const saml2md::RoleDescriptor& role,
92             bool checkName=true,
93             const xmlsignature::KeyResolver* keyResolver=NULL
94             ) const;
95
96         /**
97          * Stateful interface that supplies PKIX validation data to the trust engine.
98          * Applications can adapt this TrustEngine to their environment by returning
99          * implementations of this interface from the getPKIXValidationInfoIterator
100          * method.
101          */
102         class SAML_API PKIXValidationInfoIterator {
103             MAKE_NONCOPYABLE(PKIXValidationInfoIterator);
104         protected:
105             PKIXValidationInfoIterator() {}
106         public:
107             virtual ~PKIXValidationInfoIterator() {}
108             
109             /**
110              * Advances to the next set of information, if any.
111              * 
112              * @return true iff another set of information is available
113              */
114             virtual bool next()=0;
115             
116             /**
117              * Returns the allowable trust chain verification depth for the
118              * validation data in the current position.
119              * 
120              * @return  allowable trust chain verification depth
121              */
122             virtual int getVerificationDepth() const=0;
123             
124             /**
125              * Returns the set of trust anchors for the validation data in the
126              * current position. Keeping the certificates beyond the lifetime
127              * of the iterator or after advancing to the next position requires
128              * copying them.
129              * 
130              * @return  set of trust anchors
131              */
132             virtual const std::vector<XSECCryptoX509*>& getTrustAnchors() const=0;
133
134             /**
135              * Returns the set of CRLs for the validation data in the
136              * current position. Keeping the CRLs beyond the lifetime
137              * of the iterator or after advancing to the next position requires
138              * copying them.
139              * 
140              * @return  set of CRLs
141              */
142             virtual const std::vector<xmltooling::XSECCryptoX509CRL*>& getCRLs() const=0;
143         };
144         
145         /**
146          * Provides access to the information necessary, for the given role, for
147          * PKIX validation of credentials. Each set of validation information returned
148          * will be tried, in turn, until one succeeds or no more remain.
149          * The caller must free the returned interface when finished with it.
150          * 
151          * @return interface for obtaining validation data  
152          */
153         virtual PKIXValidationInfoIterator* getPKIXValidationInfoIterator(const saml2md::RoleDescriptor& role) const=0;
154     };
155 };
156
157 #endif /* __saml_pkixtrust_h__ */