Merge branch '1.x' of ssh://authdev.it.ohio-state.edu/~scantor/git/cpp-xmltooling...
[shibboleth/cpp-xmltooling.git] / xmltooling / security / CredentialCriteria.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/CredentialCriteria.h
23  * 
24  * Class for specifying criteria by which a CredentialResolver should resolve credentials.
25  */
26
27 #if !defined(__xmltooling_credcrit_h__) && !defined(XMLTOOLING_NO_XMLSEC)
28 #define __xmltooling_credcrit_h__
29
30 #include <xmltooling/base.h>
31
32 #include <set>
33
34 class DSIGKeyInfoList;
35 class XSECCryptoKey;
36
37 namespace xmlsignature {
38     class XMLTOOL_API KeyInfo;
39     class XMLTOOL_API Signature;
40 };
41
42 namespace xmltooling {
43
44     class XMLTOOL_API Credential;
45
46 #if defined (_MSC_VER)
47     #pragma warning( push )
48     #pragma warning( disable : 4251 )
49 #endif
50
51     /**
52      * Class for specifying criteria by which a CredentialResolver should resolve credentials.
53      */
54     class XMLTOOL_API CredentialCriteria
55     {
56         MAKE_NONCOPYABLE(CredentialCriteria);
57     public:
58         /** Default constructor. */
59         CredentialCriteria();
60
61         virtual ~CredentialCriteria();
62
63         /**
64          * Determines whether the supplied Credential matches this CredentialCriteria.
65          *
66          * @param credential    the Credential to evaluate
67          * @return true iff the Credential is consistent with this criteria
68          */
69         virtual bool matches(const Credential& credential) const;
70        
71         /**
72          * Get key usage criteria.
73          * 
74          * @return the usage mask
75          */
76         unsigned int getUsage() const;
77     
78         /**
79          * Set key usage criteria.
80          * 
81          * @param usage the usage mask to set
82          */
83         void setUsage(unsigned int usage);
84
85         /**
86          * Get the peer name criteria.
87          * 
88          * @return the peer name
89          */
90         const char* getPeerName() const;
91     
92         /**
93          * Set the peer name criteria.
94          * 
95          * @param peerName peer name to set
96          */
97         void setPeerName(const char* peerName);
98     
99         /**
100          * Get the key algorithm criteria.
101          * 
102          * @return the key algorithm
103          */
104         const char* getKeyAlgorithm() const;
105     
106         /**
107          * Set the key algorithm criteria.
108          * 
109          * @param keyAlgorithm the key algorithm to set
110          */
111         void setKeyAlgorithm(const char* keyAlgorithm);
112
113         /**
114          * Get the key size criteria.
115          * <p>If a a maximum size is also set, this is treated as a minimum.
116          *
117          * @return  the key size, or 0
118          */
119         unsigned int getKeySize() const;
120
121         /**
122          * Set the key size criteria.
123          * <p>If a a maximum size is also set, this is treated as a minimum.
124          *
125          * @param keySize key size to set
126          */
127         void setKeySize(unsigned int keySize);
128
129         /**
130          * Get the maximum key size criteria.
131          *
132          * @return  the maximum key size, or 0
133          */
134         unsigned int getMaxKeySize() const;
135
136         /**
137          * Set the maximum key size criteria.
138          *
139          * @param keySize maximum key size to set
140          */
141         void setMaxKeySize(unsigned int keySize);
142
143         /**
144          * Set the key algorithm and size criteria based on an XML algorithm specifier.
145          *
146          * @param algorithm XML algorithm specifier
147          */
148         void setXMLAlgorithm(const XMLCh* algorithm);
149
150         /**
151          * Gets key name criteria.
152          * 
153          * @return an immutable set of key names
154          */
155         const std::set<std::string>& getKeyNames() const;
156
157         /**
158          * Gets key name criteria.
159          * 
160          * @return a mutable set of key names
161          */
162         std::set<std::string>& getKeyNames();
163
164         /**
165          * Returns the public key criteria.
166          * 
167          * @return  a public key
168          */
169         virtual XSECCryptoKey* getPublicKey() const;
170
171         /**
172          * Sets the public key criteria.
173          *
174          * <p>The lifetime of the key <strong>MUST</strong> extend
175          * for the lifetime of this object.
176          * 
177          * @param key a public key
178          */
179         void setPublicKey(XSECCryptoKey* key);
180
181         /**
182          * Bitmask constants controlling the kinds of criteria set automatically
183          * based on a KeyInfo object.
184          */
185         enum keyinfo_extraction_t {
186             KEYINFO_EXTRACTION_KEY = 1,
187             KEYINFO_EXTRACTION_KEYNAMES = 2
188         };
189
190         /**
191          * Gets the KeyInfo criteria.
192          * 
193          * @return the KeyInfo criteria
194          */
195         const xmlsignature::KeyInfo* getKeyInfo() const;
196     
197         /**
198          * Sets the KeyInfo criteria.
199          * 
200          * @param keyInfo       the KeyInfo criteria
201          * @param extraction    bitmask of criteria to auto-extract from KeyInfo
202          */
203         virtual void setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int extraction=0);
204
205         /**
206          * Gets the native KeyInfo criteria.
207          * 
208          * @return the native KeyInfo criteria
209          */
210         DSIGKeyInfoList* getNativeKeyInfo() const;
211
212         /**
213          * Sets the KeyInfo criteria.
214          * 
215          * @param keyInfo       the KeyInfo criteria
216          * @param extraction    bitmask of criteria to auto-extract from KeyInfo
217          */
218         virtual void setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extraction=0);
219
220         /**
221          * Sets the KeyInfo criteria from an XML Signature.
222          * 
223          * @param sig           the Signature containing KeyInfo criteria
224          * @param extraction    bitmask of criteria to auto-extract from KeyInfo
225          */
226         void setSignature(const xmlsignature::Signature& sig, int extraction=0);
227
228         /**
229          * Resets object to a default state.
230          */
231         virtual void reset();
232
233     private:
234         unsigned int m_keyUsage;
235         unsigned int m_keySize,m_maxKeySize;
236         std::string m_peerName,m_keyAlgorithm;
237         std::set<std::string> m_keyNames;
238         XSECCryptoKey* m_key;
239         const xmlsignature::KeyInfo* m_keyInfo;
240         DSIGKeyInfoList* m_nativeKeyInfo;
241         Credential* m_credential;
242     };
243
244 #if defined (_MSC_VER)
245     #pragma warning( pop )
246 #endif
247 };
248
249 #endif /* __xmltooling_credcrit_h__ */