GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/crypto/crypto_x509.h Lines: 7 14 50.0 %
Date: 2021-04-22 04:13:51 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
10
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
12
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 v8::Local<v8::FunctionTemplate> GetConstructorTemplate(
47
      Environment* env);
48
  static bool HasInstance(Environment* env, v8::Local<v8::Object> object);
49
50
  static v8::MaybeLocal<v8::Object> New(
51
      Environment* env,
52
      X509Pointer cert,
53
      STACK_OF(X509)* issuer_chain = nullptr);
54
55
  static v8::MaybeLocal<v8::Object> New(
56
      Environment* env,
57
      std::shared_ptr<ManagedX509> cert,
58
      STACK_OF(X509)* issuer_chain = nullptr);
59
60
  static v8::MaybeLocal<v8::Object> GetCert(
61
      Environment* env,
62
      const SSLPointer& ssl);
63
64
  static v8::MaybeLocal<v8::Object> GetPeerCert(
65
      Environment* env,
66
      const SSLPointer& ssl,
67
      GetPeerCertificateFlag flag);
68
69
  static v8::Local<v8::Object> Wrap(
70
      Environment* env,
71
      v8::Local<v8::Object> object,
72
      X509Pointer cert);
73
74
  static void Parse(const v8::FunctionCallbackInfo<v8::Value>& args);
75
  static void Subject(const v8::FunctionCallbackInfo<v8::Value>& args);
76
  static void SubjectAltName(const v8::FunctionCallbackInfo<v8::Value>& args);
77
  static void Issuer(const v8::FunctionCallbackInfo<v8::Value>& args);
78
  static void InfoAccess(const v8::FunctionCallbackInfo<v8::Value>& args);
79
  static void ValidFrom(const v8::FunctionCallbackInfo<v8::Value>& args);
80
  static void ValidTo(const v8::FunctionCallbackInfo<v8::Value>& args);
81
  static void Fingerprint(const v8::FunctionCallbackInfo<v8::Value>& args);
82
  static void Fingerprint256(const v8::FunctionCallbackInfo<v8::Value>& args);
83
  static void KeyUsage(const v8::FunctionCallbackInfo<v8::Value>& args);
84
  static void SerialNumber(const v8::FunctionCallbackInfo<v8::Value>& args);
85
  static void Raw(const v8::FunctionCallbackInfo<v8::Value>& args);
86
  static void PublicKey(const v8::FunctionCallbackInfo<v8::Value>& args);
87
  static void Pem(const v8::FunctionCallbackInfo<v8::Value>& args);
88
  static void CheckCA(const v8::FunctionCallbackInfo<v8::Value>& args);
89
  static void CheckHost(const v8::FunctionCallbackInfo<v8::Value>& args);
90
  static void CheckEmail(const v8::FunctionCallbackInfo<v8::Value>& args);
91
  static void CheckIP(const v8::FunctionCallbackInfo<v8::Value>& args);
92
  static void CheckIssued(const v8::FunctionCallbackInfo<v8::Value>& args);
93
  static void CheckPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args);
94
  static void Verify(const v8::FunctionCallbackInfo<v8::Value>& args);
95
  static void ToLegacy(const v8::FunctionCallbackInfo<v8::Value>& args);
96
  static void GetIssuerCert(const v8::FunctionCallbackInfo<v8::Value>& args);
97
98
35
  X509* get() { return cert_->get(); }
99
100
  void MemoryInfo(MemoryTracker* tracker) const override;
101
  SET_MEMORY_INFO_NAME(X509Certificate);
102
  SET_SELF_SIZE(X509Certificate);
103
104
2
  class X509CertificateTransferData : public worker::TransferData {
105
   public:
106
1
    explicit X509CertificateTransferData(
107
        const std::shared_ptr<ManagedX509>& data)
108
1
        : data_(data) {}
109
110
    BaseObjectPtr<BaseObject> Deserialize(
111
        Environment* env,
112
        v8::Local<v8::Context> context,
113
        std::unique_ptr<worker::TransferData> self) override;
114
115
    SET_MEMORY_INFO_NAME(X509CertificateTransferData)
116
    SET_SELF_SIZE(X509CertificateTransferData)
117
    SET_NO_MEMORY_INFO()
118
119
   private:
120
    std::shared_ptr<ManagedX509> data_;
121
  };
122
123
  BaseObject::TransferMode GetTransferMode() const override;
124
  std::unique_ptr<worker::TransferData> CloneForMessaging() const override;
125
126
 private:
127
  X509Certificate(
128
      Environment* env,
129
      v8::Local<v8::Object> object,
130
      std::shared_ptr<ManagedX509> cert,
131
      STACK_OF(X509)* issuer_chain = nullptr);
132
133
  std::shared_ptr<ManagedX509> cert_;
134
  BaseObjectPtr<X509Certificate> issuer_cert_;
135
};
136
137
}  // namespace crypto
138
}  // namespace node
139
140
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
141
#endif  // SRC_CRYPTO_CRYPTO_X509_H_