2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/security/BasicX509Credential.h
20 * Wraps an X.509-based Credential by storing key/cert objects inside.
23 #if !defined(__xmltooling_basicx509cred_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_basicx509cred_h__
26 #include <xmltooling/security/X509Credential.h>
27 #include <xmltooling/signature/KeyInfo.h>
31 namespace xmltooling {
34 * Wraps an X.509-based Credential by storing key/cert objects inside.
36 class XMLTOOL_API BasicX509Credential : public virtual X509Credential
42 * @param ownCerts true iff any certificates subsequently stored should be freed by destructor
44 BasicX509Credential(bool ownCerts) : m_key(NULL), m_ownCerts(ownCerts), m_keyInfo(NULL), m_compactKeyInfo(NULL) {
50 * @param key key pair or secret key
51 * @param certs array of X.509 certificates, the first entry being the entity certificate
52 * @param crl optional CRL
54 BasicX509Credential(XSECCryptoKey* key, const std::vector<XSECCryptoX509*>& certs, XSECCryptoX509CRL* crl=NULL)
55 : m_key(key), m_xseccerts(certs), m_ownCerts(true), m_keyInfo(NULL), m_compactKeyInfo(NULL) {
57 m_crls.push_back(crl);
63 * @param key key pair or secret key
64 * @param certs array of X.509 certificates, the first entry being the entity certificate
65 * @param crls array of X.509 CRLs
67 BasicX509Credential(XSECCryptoKey* key, const std::vector<XSECCryptoX509*>& certs, const std::vector<XSECCryptoX509CRL*>& crls)
68 : m_key(key), m_xseccerts(certs), m_ownCerts(true), m_crls(crls), m_keyInfo(NULL), m_compactKeyInfo(NULL) {
71 /** The private/secret key/keypair. */
74 /** Key names (derived from credential, KeyInfo, or both). */
75 std::set<std::string> m_keyNames;
78 std::string m_subjectName;
81 std::string m_issuerName;
86 /** The X.509 certificate chain. */
87 std::vector<XSECCryptoX509*> m_xseccerts;
89 /** Indicates whether to destroy certificates. */
92 /** The X.509 CRLs. */
93 std::vector<XSECCryptoX509CRL*> m_crls;
95 /** The KeyInfo object representing the information. */
96 xmlsignature::KeyInfo* m_keyInfo;
98 /** The KeyInfo object representing the information in compact form. */
99 xmlsignature::KeyInfo* m_compactKeyInfo;
102 * Initializes (or reinitializes) a ds:KeyInfo to represent the Credential.
104 * @param types the kinds of KeyInfo content to include
106 void initKeyInfo(unsigned int types=0);
109 virtual ~BasicX509Credential();
111 unsigned int getUsage() const {
112 return UNSPECIFIED_CREDENTIAL;
114 const char* getAlgorithm() const;
115 unsigned int getKeySize() const;
117 XSECCryptoKey* getPrivateKey() const {
119 XSECCryptoKey::KeyType type = m_key->getKeyType();
120 if (type!=XSECCryptoKey::KEY_RSA_PUBLIC && type!=XSECCryptoKey::KEY_DSA_PUBLIC)
126 XSECCryptoKey* getPublicKey() const {
128 XSECCryptoKey::KeyType type = m_key->getKeyType();
129 if (type!=XSECCryptoKey::KEY_RSA_PRIVATE && type!=XSECCryptoKey::KEY_DSA_PRIVATE)
135 const std::set<std::string>& getKeyNames() const {
139 xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const {
140 if (compact || !m_keyInfo)
141 return m_compactKeyInfo ? m_compactKeyInfo->cloneKeyInfo() : NULL;
142 return m_keyInfo->cloneKeyInfo();
145 const std::vector<XSECCryptoX509*>& getEntityCertificateChain() const {
149 XSECCryptoX509CRL* getCRL() const {
150 return m_crls.empty() ? NULL : m_crls.front();
153 const std::vector<XSECCryptoX509CRL*>& getCRLs() const {
157 const char* getSubjectName() const {
158 return m_subjectName.c_str();
161 const char* getIssuerName() const {
162 return m_issuerName.c_str();
165 const char* getSerialNumber() const {
166 return m_serial.c_str();
173 #endif /* __xmltooling_basicx509cred_h__ */