ecd575a18b466a4dcee952b680036b2f46a11219
[shibboleth/cpp-xmltooling.git] / xmltooling / security / Credential.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/Credential.h
19  *
20  * Wraps keys and related functionality.
21  */
22
23 #if !defined(__xmltooling_cred_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_cred_h__
25
26 #include <xmltooling/base.h>
27 #include <xsec/enc/XSECCryptoKey.hpp>
28
29 #include <set>
30 #include <string>
31
32 namespace xmlsignature {
33     class XMLTOOL_API KeyInfo;
34 };
35
36 namespace xmltooling {
37
38     class XMLTOOL_API CredentialCriteria;
39     class XMLTOOL_API CredentialContext;
40
41     /**
42      * Wraps keys and related functionality.
43      *
44      * <p>Shared credential implementations should implement reference counting
45      * and honor any locking parameters to ensure appropriate synchronization.
46      */
47     class XMLTOOL_API Credential
48     {
49         MAKE_NONCOPYABLE(Credential);
50     protected:
51         Credential() {}
52
53     public:
54         virtual ~Credential() {}
55
56         /**
57          * Bitmask constants for limiting resolution process inside a CredentialResolver.
58          */
59         enum ResolveTypes {
60             RESOLVE_KEYS = 1,
61             RESOLVE_NAMES = 2
62         };
63
64         /**
65          * Bitmask of use cases for credentials.
66          */
67         enum UsageTypes {
68             UNSPECIFIED_CREDENTIAL = 0,
69             SIGNING_CREDENTIAL = 1,
70             TLS_CREDENTIAL = 2,
71             ENCRYPTION_CREDENTIAL = 4
72         };
73
74         /**
75          * Bitmask of supported KeyInfo content to generate.
76          */
77         enum KeyInfoTypes {
78             KEYINFO_KEY_VALUE = 1,
79             KEYINFO_KEY_NAME = 2
80         };
81
82         /**
83          * Get credential usage types.
84          *
85          * @return the usage bitmask
86          */
87         virtual unsigned int getUsage() const=0;
88
89         /**
90          * Returns an algorithm identifier for the Credential.
91          *
92          * @return  the Credential algorithm, or NULL if indeterminate
93          */
94         virtual const char* getAlgorithm() const=0;
95
96         /**
97          * Returns the size of the key.
98          *
99          * @return  the key size, or 0 if indeterminate
100          */
101         virtual unsigned int getKeySize() const=0;
102
103         /**
104          * Returns a secret or private key to use for signing or decryption operations.
105          *
106          * @return  a secret or private key
107          */
108         virtual XSECCryptoKey* getPrivateKey() const=0;
109
110         /**
111          * Returns a secret or public key to use for verification or encryption operations.
112          *
113          * @return  a secret or public key
114          */
115         virtual XSECCryptoKey* getPublicKey() const=0;
116
117         /**
118          * Returns names representing the Credential.
119          *
120          * <p>Names should be unique in the context of the comparisons against CredentialCriteria
121          * that deployments expect to see.
122          *
123          * @return  a sorted set of names
124          */
125         virtual const std::set<std::string>& getKeyNames() const=0;
126
127         /**
128          * Returns a ds:KeyInfo object representing the Credential for use in
129          * communicating with other entities.
130          *
131          * @param compact   true iff the communication medium is such that only compact forms should be included
132          * @return a KeyInfo object, which must be freed by the caller
133          */
134         virtual xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const=0;
135
136         /**
137          * Get the credential context information, which provides additional information
138          * specific to the context in which the credential was resolved.
139          *
140          * @return resolution context of the credential
141          */
142         virtual const CredentialContext* getCredentalContext() const {
143             return NULL;
144         }
145     };
146 };
147
148 #endif /* __xmltooling_cred_h__ */