libdigidocpp
X509Cert.h
Go to the documentation of this file.
1 /*
2  * libdigidocpp
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  */
19 
20 #pragma once
21 
22 #include "../../Exception.h"
23 
24 #ifdef WIN32 //hack for win32 build
25 #undef X509_NAME
26 #endif
27 #include <openssl/x509.h>
28 
29 namespace digidoc
30 {
35  {
36 
37  public:
38  enum KeyUsage
39  {
40  DigitalSignature = 0,
48  DecipherOnly
49  };
50 
51  X509Cert();
52  X509Cert(X509* cert) throw(IOException);
53  X509Cert(const std::vector<unsigned char> &bytes) throw(IOException);
54  X509Cert(const X509Cert& copy) throw(IOException);
55  ~X509Cert();
56  static X509* copyX509(X509* cert) throw(IOException);
57  static X509* loadX509(const std::string& path) throw(IOException);
58 
59  int getPaddingSize() const throw(IOException);
60  std::vector<unsigned char> encodeDER() const throw(IOException);
61  std::string getSerial() const throw(IOException);
62  X509_NAME* getIssuerNameAsn1() const;
63  std::string getIssuerName(const std::string &obj = "") const throw(IOException);
64  std::vector<KeyUsage> getKeyUsage() const throw(IOException);
65  std::vector<std::string> getCertificatePolicies() const throw(IOException);
66  std::string getSubjectName(const std::string &obj = "") const throw(IOException);
67  std::vector<unsigned char> getRsaModulus() const throw(IOException);
68  std::vector<unsigned char> getRsaExponent() const throw(IOException);
69 
70  X509* getX509() const throw(IOException);
71  X509* handle() const;
72  bool isValid() const throw(IOException);
73  bool verify() const throw(IOException);
74 
75  int compareIssuerToString(const std::string &name) const throw(IOException);
76 
77  X509Cert& operator=(const X509Cert& copy) throw(IOException);
78  bool operator ==(const X509Cert &other) const;
79 
80  private:
81  EVP_PKEY* getPublicKey() const throw(IOException);
82  std::string toString(X509_NAME *name, const std::string &obj) const throw(IOException);
83 
84  X509* cert;
85  };
86 }