summaryrefslogtreecommitdiff
path: root/poppler/CertificateInfo.h
blob: 1d12c9d9c2898772f041802d75f0ea6edf3fefb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//========================================================================
//
// CertificateInfo.h
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65@gmail.com>
// Copyright 2018, 2019 Albert Astals Cid <aacid@kde.org>
// Copyright 2018 Oliver Sander <oliver.sander@tu-dresden.de>
//
//========================================================================

#ifndef CERTIFICATEINFO_H
#define CERTIFICATEINFO_H

#include <memory>
#include <ctime>
#include "goo/GooString.h"

enum CertificateKeyUsageExtension
{
  KU_DIGITAL_SIGNATURE = 0x80,
  KU_NON_REPUDIATION   = 0x40,
  KU_KEY_ENCIPHERMENT  = 0x20,
  KU_DATA_ENCIPHERMENT = 0x10,
  KU_KEY_AGREEMENT     = 0x08,
  KU_KEY_CERT_SIGN     = 0x04,
  KU_CRL_SIGN          = 0x02,
  KU_ENCIPHER_ONLY     = 0x01,
  KU_NONE              = 0x00
};

enum PublicKeyType
{
  RSAKEY,
  DSAKEY,
  ECKEY,
  OTHERKEY
};

class X509CertificateInfo {
public:
  X509CertificateInfo();
  ~X509CertificateInfo();

  X509CertificateInfo(const X509CertificateInfo &) = delete;
  X509CertificateInfo& operator=(const X509CertificateInfo &) = delete;

  struct PublicKeyInfo {
    PublicKeyInfo();

    PublicKeyInfo(PublicKeyInfo &&) noexcept;
    PublicKeyInfo &operator=(PublicKeyInfo &&) noexcept;

    PublicKeyInfo(const PublicKeyInfo &) = delete;
    PublicKeyInfo &operator=(const PublicKeyInfo &) = delete;

    GooString publicKey;
    PublicKeyType publicKeyType;
    unsigned int publicKeyStrength; // in bits
  };

  struct EntityInfo {
    EntityInfo();
    ~EntityInfo();

    EntityInfo(EntityInfo &&) noexcept;
    EntityInfo &operator=(EntityInfo &&) noexcept;

    EntityInfo(const EntityInfo &) = delete;
    EntityInfo &operator=(const EntityInfo &) = delete;

    std::string commonName;
    std::string distinguishedName;
    std::string email;
    std::string organization;
  };

   struct Validity {
    Validity() : notBefore(0), notAfter(0) {}

    time_t notBefore;
    time_t notAfter;
  };

  /* GETTERS */
  int getVersion() const;
  const GooString &getSerialNumber() const;
  const EntityInfo &getIssuerInfo() const;
  const Validity &getValidity() const;
  const EntityInfo &getSubjectInfo() const;
  const PublicKeyInfo &getPublicKeyInfo() const;
  unsigned int getKeyUsageExtensions() const;
  const GooString &getCertificateDER() const;
  bool getIsSelfSigned() const;

  /* SETTERS */
  void setVersion(int);
  void setSerialNumber(const GooString &);
  void setIssuerInfo(EntityInfo &&);
  void setValidity(Validity);
  void setSubjectInfo(EntityInfo &&);
  void setPublicKeyInfo(PublicKeyInfo &&);
  void setKeyUsageExtensions(unsigned int);
  void setCertificateDER(const GooString &);
  void setIsSelfSigned(bool);

private:
  EntityInfo issuer_info;
  EntityInfo subject_info;
  PublicKeyInfo public_key_info;
  Validity cert_validity;
  GooString cert_serial;
  GooString cert_der;
  unsigned int ku_extensions;
  int cert_version;
  bool is_self_signed;
};

#endif