0d899fdc46cc3f3dcbeec2c39f2c56abc9f7ed70
[shibboleth/cpp-xmltooling.git] / xmltooling / security / BasicX509Credential.h
1 /*
2  *  Copyright 2001-2009 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/BasicX509Credential.h
19  * 
20  * Wraps an X.509-based Credential by storing key/cert objects inside. 
21  */
22
23 #if !defined(__xmltooling_basicx509cred_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_basicx509cred_h__
25
26 #include <xmltooling/security/X509Credential.h>
27 #include <xmltooling/signature/KeyInfo.h>
28
29 #include <algorithm>
30
31 namespace xmltooling {
32
33     /**
34      * Wraps an X.509-based Credential by storing key/cert objects inside.
35      */
36     class XMLTOOL_API BasicX509Credential : public virtual X509Credential
37     {
38     protected:
39         /**
40          * Constructor.
41          * 
42          * @param ownCerts  true iff any certificates subsequently stored should be freed by destructor
43          */
44         BasicX509Credential(bool ownCerts);
45
46         /**
47          * Constructor.
48          * 
49          * @param key   key pair or secret key
50          * @param certs array of X.509 certificates, the first entry being the entity certificate
51          * @param crl   optional CRL
52          */
53         BasicX509Credential(XSECCryptoKey* key, const std::vector<XSECCryptoX509*>& certs, XSECCryptoX509CRL* crl=NULL);
54
55         /**
56          * Constructor.
57          * 
58          * @param key   key pair or secret key
59          * @param certs array of X.509 certificates, the first entry being the entity certificate
60          * @param crls  array of X.509 CRLs
61          */
62         BasicX509Credential(XSECCryptoKey* key, const std::vector<XSECCryptoX509*>& certs, const std::vector<XSECCryptoX509CRL*>& crls);
63
64         /** The private/secret key/keypair. */
65         XSECCryptoKey* m_key;
66
67         /** Key names (derived from credential, KeyInfo, or both). */
68         std::set<std::string> m_keyNames;
69
70         /** Subject DN. */
71         std::string m_subjectName;
72
73         /** Issuer DN. */
74         std::string m_issuerName;
75
76         /** Serial number. */
77         std::string m_serial;
78
79         /** The X.509 certificate chain. */
80         std::vector<XSECCryptoX509*> m_xseccerts;
81
82         /** Indicates whether to destroy certificates. */
83         bool m_ownCerts;
84
85         /** The X.509 CRLs. */
86         std::vector<XSECCryptoX509CRL*> m_crls;
87
88         /** The KeyInfo object representing the information. */
89         xmlsignature::KeyInfo* m_keyInfo;
90
91         /** The KeyInfo object representing the information in compact form. */
92         xmlsignature::KeyInfo* m_compactKeyInfo;
93
94         /**
95          * Initializes (or reinitializes) a ds:KeyInfo to represent the Credential.
96          *
97          * @param types the kinds of KeyInfo content to include 
98          */
99         void initKeyInfo(unsigned int types=0);
100
101     public:
102         virtual ~BasicX509Credential();
103         
104         // Virtual overrides.
105         unsigned int getUsage() const;
106         const char* getAlgorithm() const;
107         unsigned int getKeySize() const;
108         XSECCryptoKey* getPrivateKey() const;
109         XSECCryptoKey* getPublicKey() const;
110         const std::set<std::string>& getKeyNames() const;
111         xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const;
112         const std::vector<XSECCryptoX509*>& getEntityCertificateChain() const;
113         XSECCryptoX509CRL* getCRL() const;
114         const std::vector<XSECCryptoX509CRL*>& getCRLs() const;
115         const char* getSubjectName() const;
116         const char* getIssuerName() const;
117         const char* getSerialNumber() const;
118         void extract();
119     };
120 };
121
122 #endif /* __xmltooling_basicx509cred_h__ */