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