1 //======================================================================== 2 // 3 // CertificateInfo.h 4 // 5 // This file is licensed under the GPLv2 or later 6 // 7 // Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com> 8 // Copyright 2018, 2019 Albert Astals Cid <aacid@kde.org> 9 // Copyright 2018 Oliver Sander <oliver.sander@tu-dresden.de> 10 // Copyright 2020 Thorsten Behrens <Thorsten.Behrens@CIB.de> 11 // 12 //======================================================================== 13 14 #ifndef CERTIFICATEINFO_H 15 #define CERTIFICATEINFO_H 16 17 #include <memory> 18 #include <ctime> 19 #include "goo/GooString.h" 20 #include "poppler_private_export.h" 21 22 enum CertificateKeyUsageExtension 23 { 24 KU_DIGITAL_SIGNATURE = 0x80, 25 KU_NON_REPUDIATION = 0x40, 26 KU_KEY_ENCIPHERMENT = 0x20, 27 KU_DATA_ENCIPHERMENT = 0x10, 28 KU_KEY_AGREEMENT = 0x08, 29 KU_KEY_CERT_SIGN = 0x04, 30 KU_CRL_SIGN = 0x02, 31 KU_ENCIPHER_ONLY = 0x01, 32 KU_NONE = 0x00 33 }; 34 35 enum PublicKeyType 36 { 37 RSAKEY, 38 DSAKEY, 39 ECKEY, 40 OTHERKEY 41 }; 42 43 class POPPLER_PRIVATE_EXPORT X509CertificateInfo 44 { 45 public: 46 X509CertificateInfo(); 47 ~X509CertificateInfo(); 48 49 X509CertificateInfo(const X509CertificateInfo &) = delete; 50 X509CertificateInfo &operator=(const X509CertificateInfo &) = delete; 51 52 struct PublicKeyInfo 53 { 54 PublicKeyInfo(); 55 56 PublicKeyInfo(PublicKeyInfo &&) noexcept; 57 PublicKeyInfo &operator=(PublicKeyInfo &&) noexcept; 58 59 PublicKeyInfo(const PublicKeyInfo &) = delete; 60 PublicKeyInfo &operator=(const PublicKeyInfo &) = delete; 61 62 GooString publicKey; 63 PublicKeyType publicKeyType; 64 unsigned int publicKeyStrength; // in bits 65 }; 66 67 struct EntityInfo 68 { 69 EntityInfo(); 70 ~EntityInfo(); 71 72 EntityInfo(EntityInfo &&) noexcept; 73 EntityInfo &operator=(EntityInfo &&) noexcept; 74 75 EntityInfo(const EntityInfo &) = delete; 76 EntityInfo &operator=(const EntityInfo &) = delete; 77 78 std::string commonName; 79 std::string distinguishedName; 80 std::string email; 81 std::string organization; 82 }; 83 84 struct Validity 85 { ValidityValidity86 Validity() : notBefore(0), notAfter(0) { } 87 88 time_t notBefore; 89 time_t notAfter; 90 }; 91 92 /* GETTERS */ 93 int getVersion() const; 94 const GooString &getSerialNumber() const; 95 const GooString &getNickName() const; 96 const EntityInfo &getIssuerInfo() const; 97 const Validity &getValidity() const; 98 const EntityInfo &getSubjectInfo() const; 99 const PublicKeyInfo &getPublicKeyInfo() const; 100 unsigned int getKeyUsageExtensions() const; 101 const GooString &getCertificateDER() const; 102 bool getIsSelfSigned() const; 103 104 /* SETTERS */ 105 void setVersion(int); 106 void setSerialNumber(const GooString &); 107 void setNickName(const GooString &); 108 void setIssuerInfo(EntityInfo &&); 109 void setValidity(Validity); 110 void setSubjectInfo(EntityInfo &&); 111 void setPublicKeyInfo(PublicKeyInfo &&); 112 void setKeyUsageExtensions(unsigned int); 113 void setCertificateDER(const GooString &); 114 void setIsSelfSigned(bool); 115 116 private: 117 EntityInfo issuer_info; 118 EntityInfo subject_info; 119 PublicKeyInfo public_key_info; 120 Validity cert_validity; 121 GooString cert_serial; 122 GooString cert_der; 123 GooString cert_nick; 124 unsigned int ku_extensions; 125 int cert_version; 126 bool is_self_signed; 127 }; 128 129 #endif 130