b73895e439c1e3319fc9cfc7a2a77b6452cb6084
[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             XSECCryptoX509* certEE,
80             const std::vector<XSECCryptoX509*>& certChain,
81             const saml2md::RoleDescriptor& role,
82             bool checkName=true,
83             const xmlsignature::KeyResolver* keyResolver=NULL
84             ) const;
85
86         /**
87          * Stateful interface that supplies PKIX validation data to the trust engine.
88          * Applications can adapt this TrustEngine to their environment by returning
89          * implementations of this interface from the getPKIXValidationInfoIterator
90          * method.
91          */
92         class SAML_API PKIXValidationInfoIterator {
93             MAKE_NONCOPYABLE(PKIXValidationInfoIterator);
94         protected:
95             PKIXValidationInfoIterator() {}
96         public:
97             virtual ~PKIXValidationInfoIterator() {}
98             
99             /**
100              * Advances to the next set of information, if any.
101              * 
102              * @return true iff another set of information is available
103              */
104             virtual bool next()=0;
105             
106             /**
107              * Returns the allowable trust chain verification depth for the
108              * validation data in the current position.
109              * 
110              * @return  allowable trust chain verification depth
111              */
112             virtual int getVerificationDepth() const=0;
113             
114             /**
115              * Returns the set of trust anchors for the validation data in the
116              * current position. Keeping the certificates beyond the lifetime
117              * of the iterator or after advancing to the next position requires
118              * copying them.
119              * 
120              * @return  set of trust anchors
121              */
122             virtual const std::vector<XSECCryptoX509*>& getTrustAnchors() const=0;
123
124             /**
125              * Returns the set of CRLs for the validation data in the
126              * current position. Keeping the CRLs beyond the lifetime
127              * of the iterator or after advancing to the next position requires
128              * copying them.
129              * 
130              * @return  set of CRLs
131              */
132             virtual const std::vector<xmltooling::XSECCryptoX509CRL*>& getCRLs() const=0;
133         };
134         
135         /**
136          * Provides access to the information necessary, for the given role, for
137          * PKIX validation of credentials. Each set of validation information returned
138          * will be tried, in turn, until one succeeds or no more remain.
139          * The caller must free the returned interface when finished with it.
140          * 
141          * @return interface for obtaining validation data  
142          */
143         virtual PKIXValidationInfoIterator* getPKIXValidationInfoIterator(const saml2md::RoleDescriptor& role) const=0;
144     };
145 };
146
147 #endif /* __saml_pkixtrust_h__ */