GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: crypto/crypto_x509.h Lines: 4 11 36.4 %
Date: 2021-11-06 03:13:44 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_CRYPTO_CRYPTO_X509_H_
2
#define SRC_CRYPTO_CRYPTO_X509_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "base_object.h"
7
#include "crypto/crypto_util.h"
8
#include "env.h"
9
#include "memory_tracker.h"
10
#include "node_worker.h"
11
#include "v8.h"
12
13
namespace node {
14
namespace crypto {
15
16
// The ManagedX509 class is essentially a smart pointer for
17
// X509 objects that allows an X509Certificate instance to
18
// be cloned at the JS level while pointing at the same
19
// underlying X509 instance.
20
class ManagedX509 : public MemoryRetainer {
21
 public:
22
  ManagedX509() = default;
23
  explicit ManagedX509(X509Pointer&& cert);
24
  ManagedX509(const ManagedX509& that);
25
  ManagedX509& operator=(const ManagedX509& that);
26
27
  operator bool() const { return !!cert_; }
28
35
  X509* get() const { return cert_.get(); }
29
30
  void MemoryInfo(MemoryTracker* tracker) const override;
31
  SET_MEMORY_INFO_NAME(ManagedX509)
32
  SET_SELF_SIZE(ManagedX509)
33
34
 private:
35
  X509Pointer cert_;
36
};
37
38
class X509Certificate : public BaseObject {
39
 public:
40
  enum class GetPeerCertificateFlag {
41
    NONE,
42
    SERVER
43
  };
44
45
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
46
  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
47
  static v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
48
      Environment* env);
49
  static bool HasInstance(Environment* env, v8::Local<v8::Object> object);
50
51
  static v8::MaybeLocal<v8::Object> New(
52
      Environment* env,
53
      X509Pointer cert,
54
      STACK_OF(X509)* issuer_chain = nullptr);
55
56
  static v8::MaybeLocal<v8::Object> New(
57
      Environment* env,
58
      std::shared_ptr<ManagedX509> cert,
59
      STACK_OF(X509)* issuer_chain = nullptr);
60
61
  static v8::MaybeLocal<v8::Object> GetCert(
62
      Environment* env,
63
      const SSLPointer& ssl);
64
65
  static v8::MaybeLocal<v8::Object> GetPeerCert(
66
      Environment* env,
67
      const SSLPointer& ssl,
68
      GetPeerCertificateFlag flag);
69
70
  static v8::Local<v8::Object> Wrap(
71
      Environment* env,
72
      v8::Local<v8::Object> object,
73
      X509Pointer cert);
74
75
  static void Parse(const v8::FunctionCallbackInfo<v8::Value>& args);
76
  static void Subject(const v8::FunctionCallbackInfo<v8::Value>& args);
77
  static void SubjectAltName(const v8::FunctionCallbackInfo<v8::Value>& args);
78
  static void Issuer(const v8::FunctionCallbackInfo<v8::Value>& args);
79
  static void InfoAccess(const v8::FunctionCallbackInfo<v8::Value>& args);
80
  static void ValidFrom(const v8::FunctionCallbackInfo<v8::Value>& args);
81
  static void ValidTo(const v8::FunctionCallbackInfo<v8::Value>& args);
82
  static void Fingerprint(const v8::FunctionCallbackInfo<v8::Value>& args);
83
  static void Fingerprint256(const v8::FunctionCallbackInfo<v8::Value>& args);
84
  static void KeyUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
85
  static void SerialNumber(const v8::FunctionCallbackInfo<v8::Value>& args);
86
  static void Raw(const v8::FunctionCallbackInfo<v8::Value>& args);
87
  static void PublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
88
  static void Pem(const v8::FunctionCallbackInfo<v8::Value>& args);
89
  static void CheckCA(const v8::FunctionCallbackInfo<v8::Value>& args);
90
  static void CheckHost(const v8::FunctionCallbackInfo<v8::Value>& args);
91
  static void CheckEmail(const v8::FunctionCallbackInfo<v8::Value>& args);
92
  static void CheckIP(const v8::FunctionCallbackInfo<v8::Value>& args);
93
  static void CheckIssued(const v8::FunctionCallbackInfo<v8::Value>& args);
94
  static void CheckPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
95
  static void Verify(const v8::FunctionCallbackInfo<v8::Value>& args);
96
  static void ToLegacy(const v8::FunctionCallbackInfo<v8::Value>& args);
97
  static void GetIssuerCert(const v8::FunctionCallbackInfo<v8::Value>& args);
98
99
35
  X509* get() { return cert_->get(); }
100
101
  void MemoryInfo(MemoryTracker* tracker) const override;
102
  SET_MEMORY_INFO_NAME(X509Certificate)
103
  SET_SELF_SIZE(X509Certificate)
104
105
  class X509CertificateTransferData : public worker::TransferData {
106
   public:
107
1
    explicit X509CertificateTransferData(
108
        const std::shared_ptr<ManagedX509>& data)
109
1
        : data_(data) {}
110
111
    BaseObjectPtr<BaseObject> Deserialize(
112
        Environment* env,
113
        v8::Local<v8::Context> context,
114
        std::unique_ptr<worker::TransferData> self) override;
115
116
    SET_MEMORY_INFO_NAME(X509CertificateTransferData)
117
    SET_SELF_SIZE(X509CertificateTransferData)
118
    SET_NO_MEMORY_INFO()
119
120
   private:
121
    std::shared_ptr<ManagedX509> data_;
122
  };
123
124
  BaseObject::TransferMode GetTransferMode() const override;
125
  std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
126
127
 private:
128
  X509Certificate(
129
      Environment* env,
130
      v8::Local<v8::Object> object,
131
      std::shared_ptr<ManagedX509> cert,
132
      STACK_OF(X509)* issuer_chain = nullptr);
133
134
  std::shared_ptr<ManagedX509> cert_;
135
  BaseObjectPtr<X509Certificate> issuer_cert_;
136
};
137
138
}  // namespace crypto
139
}  // namespace node
140
141
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
142
#endif  // SRC_CRYPTO_CRYPTO_X509_H_