Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / CredentialCriteria.h
1 /*
2  *  Copyright 2001-2007 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/CredentialCriteria.h
19  * 
20  * Class for specifying criteria by which a CredentialResolver should resolve credentials. 
21  */
22
23 #if !defined(__xmltooling_credcrit_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_credcrit_h__
25
26 #include <xmltooling/unicode.h>
27 #include <xmltooling/signature/KeyInfo.h>
28 #include <xmltooling/signature/Signature.h>
29
30 #include <string>
31 #include <xsec/dsig/DSIGKeyInfoList.hpp>
32 #include <xsec/dsig/DSIGKeyInfoName.hpp>
33
34 namespace xmltooling {
35
36     /**
37      * Class for specifying criteria by which a CredentialResolver should resolve credentials.
38      */
39     class XMLTOOL_API CredentialCriteria
40     {
41         MAKE_NONCOPYABLE(CredentialCriteria);
42     public:
43         CredentialCriteria() : m_keyUsage(UNSPECIFIED_CREDENTIAL), m_keyInfo(NULL), m_nativeKeyInfo(NULL) {}
44         virtual ~CredentialCriteria() {}
45
46         enum UsageType {
47             UNSPECIFIED_CREDENTIAL,
48             SIGNING_CREDENTIAL,
49             TLS_CREDENTIAL,
50             ENCRYPTION_CREDENTIAL
51         };
52         
53         /**
54          * Get the key usage criteria.
55          * 
56          * @return the usage.
57          */
58         UsageType getUsage() const {
59             return m_keyUsage;
60         }
61     
62         /**
63          * Set the key usage criteria.
64          * 
65          * @param usage the usage to set
66          */
67         void setUsage(UsageType usage) {
68             m_keyUsage = usage;
69         }
70
71         /**
72          * Get the peer name criteria.
73          * 
74          * @return the peer name
75          */
76         const char* getPeerName() const {
77             return m_peerName.c_str();
78         }
79     
80         /**
81          * Set the peer name criteria.
82          * 
83          * @param peerName peer name to set
84          */
85         void setPeerName(const char* peerName) {
86             m_peerName.erase();
87             if (peerName)
88                 m_peerName = peerName;
89         }
90     
91         /**
92          * Get the key algorithm criteria.
93          * 
94          * @return returns the keyAlgorithm.
95          */
96         const char* getKeyAlgorithm() const {
97             return m_keyAlgorithm.c_str();
98         }
99     
100         /**
101          * Set the key algorithm criteria.
102          * 
103          * @param keyAlgorithm The keyAlgorithm to set.
104          */
105         void setKeyAlgorithm(const char* keyAlgorithm) {
106             m_keyAlgorithm.erase();
107             if (keyAlgorithm)
108                 m_keyAlgorithm = keyAlgorithm;
109         }
110     
111         /**
112          * Get the key name criteria.
113          * 
114          * @return the key name
115          */
116         const char* getKeyName() const {
117             return m_keyName.c_str();
118         }
119     
120         /**
121          * Set the key name criteria.
122          * 
123          * @param keyName key name to set
124          */
125         void setKeyName(const char* keyName) {
126             m_keyName.erase();
127             if (keyName)
128                 m_keyName = keyName;
129         }
130         
131         /**
132          * Gets the KeyInfo criteria.
133          * 
134          * @return the KeyInfo criteria
135          */
136         const xmlsignature::KeyInfo* getKeyInfo() const {
137             return m_keyInfo;
138         }
139     
140         /**
141          * Sets the KeyInfo criteria.
142          * 
143          * @param keyInfo   the KeyInfo criteria
144          */
145         void setKeyInfo(const xmlsignature::KeyInfo* keyInfo) {
146             m_keyInfo = keyInfo;
147         } 
148
149         /**
150          * Gets the native KeyInfo criteria.
151          * 
152          * @return the native KeyInfo criteria
153          */
154         DSIGKeyInfoList* getNativeKeyInfo() const {
155             return m_nativeKeyInfo;
156         }
157
158         /**
159          * Sets the KeyInfo criteria.
160          * 
161          * @param keyInfo   the KeyInfo criteria
162          */
163         void setNativeKeyInfo(DSIGKeyInfoList* keyInfo) {
164             m_nativeKeyInfo = keyInfo;
165         }
166
167         void setSignature(const xmlsignature::Signature& sig) {
168             xmlsignature::KeyInfo* k = sig.getKeyInfo();
169             if (k)
170                 return setKeyInfo(k);
171             DSIGSignature* dsig = sig.getXMLSignature();
172             if (dsig)
173                 setNativeKeyInfo(dsig->getKeyInfoList());
174         }
175
176     private:
177         UsageType m_keyUsage;
178         std::string m_peerName,m_keyAlgorithm,m_keyName;
179         const xmlsignature::KeyInfo* m_keyInfo;
180         DSIGKeyInfoList* m_nativeKeyInfo;
181     };
182 };
183
184 #endif /* __xmltooling_credcrit_h__ */