2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * @file KeyResolver.h
\r
20 * Resolves public keys and certificates based on KeyInfo information or
\r
21 * external factors.
\r
24 #if !defined(__xmltooling_keyres_h__) && !defined(XMLTOOLING_NO_XMLSEC)
\r
25 #define __xmltooling_keyres_h__
\r
27 #include <xmltooling/security/XSECCryptoX509CRL.h>
\r
29 #include <xsec/dsig/DSIGKeyInfoList.hpp>
\r
30 #include <xsec/enc/XSECCryptoKey.hpp>
\r
31 #include <xsec/enc/XSECCryptoX509.hpp>
\r
33 #include <algorithm>
\r
36 namespace xmlsignature {
\r
37 class XMLTOOL_API KeyInfo;
\r
38 class XMLTOOL_API Signature;
\r
41 * An API for resolving keys. The default/simple implementation
\r
42 * allows a hard-wired key to be supplied. This is mostly
\r
43 * useful for testing, or to adapt another mechanism for supplying
\r
44 * keys to this interface.
\r
46 class XMLTOOL_API KeyResolver {
\r
47 MAKE_NONCOPYABLE(KeyResolver);
\r
50 * Constructor based on a single externally supplied key.
\r
51 * The key will be destroyed when the resolver is.
\r
53 * @param key external key
\r
55 KeyResolver(XSECCryptoKey* key=NULL) : m_key(key) {}
\r
57 virtual ~KeyResolver() {
\r
62 * Returns a key based on the supplied KeyInfo information.
\r
63 * The caller must delete the key when done with it.
\r
65 * @param keyInfo the key information
\r
66 * @return the resolved key
\r
68 virtual XSECCryptoKey* resolveKey(const KeyInfo* keyInfo) const {
\r
69 return m_key ? m_key->clone() : NULL;
\r
73 * Returns a key based on the supplied KeyInfo information.
\r
74 * The caller must delete the key when done with it.
\r
76 * @param keyInfo the key information
\r
77 * @return the resolved key
\r
79 virtual XSECCryptoKey* resolveKey(DSIGKeyInfoList* keyInfo) const {
\r
80 return m_key ? m_key->clone() : NULL;
\r
84 * Returns a key based on the supplied KeyInfo information.
\r
85 * The caller must delete the key when done with it.
\r
87 * @param sig signature containing the key information
\r
88 * @return the resolved key
\r
90 XSECCryptoKey* resolveKey(const Signature* sig) const;
\r
93 * A wrapper that handles disposal of certificates when required.
\r
95 class XMLTOOL_API ResolvedCertificates {
\r
96 MAKE_NONCOPYABLE(ResolvedCertificates);
\r
98 std::vector<XSECCryptoX509*> m_certs;
\r
100 ResolvedCertificates() : m_owned(false) {}
\r
101 ~ResolvedCertificates() {
\r
103 std::for_each(m_certs.begin(), m_certs.end(), xmltooling::cleanup<XSECCryptoX509>());
\r
106 const std::vector<XSECCryptoX509*>& v() const {
\r
109 friend class XMLTOOL_API KeyResolver;
\r
113 * Returns a set of certificates based on the supplied KeyInfo information.
\r
114 * The certificates must be cloned if kept beyond the lifetime of the KeyInfo source.
\r
116 * @param keyInfo the key information
\r
117 * @param certs reference to object to hold certificates
\r
118 * @return number of certificates returned
\r
120 virtual std::vector<XSECCryptoX509*>::size_type resolveCertificates(
\r
121 const KeyInfo* keyInfo, ResolvedCertificates& certs
\r
125 * Returns a set of certificates based on the supplied KeyInfo information.
\r
126 * The certificates must be cloned if kept beyond the lifetime of the KeyInfo source.
\r
128 * @param keyInfo the key information
\r
129 * @param certs reference to object to hold certificates
\r
130 * @return number of certificates returned
\r
132 virtual std::vector<XSECCryptoX509*>::size_type resolveCertificates(
\r
133 DSIGKeyInfoList* keyInfo, ResolvedCertificates& certs
\r
137 * Returns a set of certificates based on the supplied KeyInfo information.
\r
138 * The certificates must be cloned if kept beyond the lifetime of the KeyInfo source.
\r
140 * @param sig signature containing the key information
\r
141 * @param certs reference to object to hold certificates
\r
142 * @return number of certificates returned
\r
144 std::vector<XSECCryptoX509*>::size_type resolveCertificates(
\r
145 const Signature* sig, ResolvedCertificates& certs
\r
149 * Returns a CRL based on the supplied KeyInfo information.
\r
150 * The caller must delete the CRL when done with it.
\r
152 * @param keyInfo the key information
\r
153 * @return the resolved CRL
\r
155 virtual xmltooling::XSECCryptoX509CRL* resolveCRL(const KeyInfo* keyInfo) const;
\r
158 * Returns a CRL based on the supplied KeyInfo information.
\r
159 * The caller must delete the CRL when done with it.
\r
161 * @param keyInfo the key information
\r
162 * @return the resolved CRL
\r
164 virtual xmltooling::XSECCryptoX509CRL* resolveCRL(DSIGKeyInfoList* keyInfo) const;
\r
167 * Returns a CRL based on the supplied KeyInfo information.
\r
168 * The caller must delete the CRL when done with it.
\r
170 * @param sig signature containing the key information
\r
171 * @return the resolved CRL
\r
173 xmltooling::XSECCryptoX509CRL* resolveCRL(const Signature* sig) const;
\r
176 XSECCryptoKey* m_key;
\r
179 * Accessor for certificate vector from derived KeyResolver classes.
\r
181 * @param certs certificate wrapper to access
\r
182 * @return modifiable reference to vector inside wrapper
\r
184 std::vector<XSECCryptoX509*>& accessCertificates(ResolvedCertificates& certs) const {
\r
185 return certs.m_certs;
\r
189 * Accessor for certificate ownership flag from derived KeyResolver classes.
\r
191 * @param certs certificate wrapper to access
\r
192 * @return modifiable reference to ownership flag inside wrapper
\r
194 bool& accessOwned(ResolvedCertificates& certs) const {
\r
195 return certs.m_owned;
\r
200 * Registers KeyResolver classes into the runtime.
\r
202 void XMLTOOL_API registerKeyResolvers();
\r
204 /** KeyResolver based on hard-wired key */
\r
205 #define FILESYSTEM_KEY_RESOLVER "org.opensaml.xmlooling.FilesystemKeyResolver"
\r
207 /** KeyResolver based on extracting information directly out of a KeyInfo */
\r
208 #define INLINE_KEY_RESOLVER "org.opensaml.xmlooling.InlineKeyResolver"
\r
211 #endif /* __xmltooling_keyres_h__ */
\r