Merge branch '1.x' of ssh://authdev.it.ohio-state.edu/~scantor/git/cpp-xmltooling...
[shibboleth/cpp-xmltooling.git] / xmltooling / security / BasicX509Credential.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * @file xmltooling/security/BasicX509Credential.h
23  * 
24  * Wraps an X.509-based Credential by storing key/cert objects inside. 
25  */
26
27 #if !defined(__xmltooling_basicx509cred_h__) && !defined(XMLTOOLING_NO_XMLSEC)
28 #define __xmltooling_basicx509cred_h__
29
30 #include <xmltooling/security/X509Credential.h>
31
32 #include <set>
33 #include <vector>
34 #include <string>
35
36 namespace xmlsignature {
37     class XMLTOOL_API KeyInfo;
38 };
39
40 namespace xmltooling {
41
42     /**
43      * Wraps an X.509-based Credential by storing key/cert objects inside.
44      */
45     class XMLTOOL_API BasicX509Credential : public virtual X509Credential
46     {
47     protected:
48         /**
49          * Constructor.
50          * 
51          * @param ownCerts  true iff any certificates subsequently stored should be freed by destructor
52          */
53         BasicX509Credential(bool ownCerts);
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 crl   optional CRL
61          */
62         BasicX509Credential(XSECCryptoKey* key, const std::vector<XSECCryptoX509*>& certs, XSECCryptoX509CRL* crl=nullptr);
63
64         /**
65          * Constructor.
66          * 
67          * @param key   key pair or secret key
68          * @param certs array of X.509 certificates, the first entry being the entity certificate
69          * @param crls  array of X.509 CRLs
70          */
71         BasicX509Credential(XSECCryptoKey* key, const std::vector<XSECCryptoX509*>& certs, const std::vector<XSECCryptoX509CRL*>& crls);
72
73         /** The private/secret key/keypair. */
74         XSECCryptoKey* m_key;
75
76         /** Key names (derived from credential, KeyInfo, or both). */
77         std::set<std::string> m_keyNames;
78
79         /** Subject DN. */
80         std::string m_subjectName;
81
82         /** Issuer DN. */
83         std::string m_issuerName;
84
85         /** Serial number. */
86         std::string m_serial;
87
88         /** The X.509 certificate chain. */
89         std::vector<XSECCryptoX509*> m_xseccerts;
90
91         /** Indicates whether to destroy certificates. */
92         bool m_ownCerts;
93
94         /** The X.509 CRLs. */
95         std::vector<XSECCryptoX509CRL*> m_crls;
96
97         /** The KeyInfo object representing the information. */
98         xmlsignature::KeyInfo* m_keyInfo;
99
100         /** The KeyInfo object representing the information in compact form. */
101         xmlsignature::KeyInfo* m_compactKeyInfo;
102
103         /**
104          * Initializes (or reinitializes) a ds:KeyInfo to represent the Credential.
105          *
106          * @param types the kinds of KeyInfo content to include 
107          */
108         void initKeyInfo(unsigned int types=0);
109
110     public:
111         virtual ~BasicX509Credential();
112         
113         // Virtual function overrides.
114         unsigned int getUsage() const;
115         const char* getAlgorithm() const;
116         unsigned int getKeySize() const;
117         XSECCryptoKey* getPrivateKey() const;
118         XSECCryptoKey* getPublicKey() const;
119         const std::set<std::string>& getKeyNames() const;
120         xmlsignature::KeyInfo* getKeyInfo(bool compact=false) const;
121         const std::vector<XSECCryptoX509*>& getEntityCertificateChain() const;
122         XSECCryptoX509CRL* getCRL() const;
123         const std::vector<XSECCryptoX509CRL*>& getCRLs() const;
124         const char* getSubjectName() const;
125         const char* getIssuerName() const;
126         const char* getSerialNumber() const;
127         void extract();
128     };
129 };
130
131 #endif /* __xmltooling_basicx509cred_h__ */