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 |
|
119 |
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 Fingerprint512(const v8::FunctionCallbackInfo<v8::Value>& args); |
85 |
|
|
static void KeyUsage(const v8::FunctionCallbackInfo<v8::Value>& args); |
86 |
|
|
static void SerialNumber(const v8::FunctionCallbackInfo<v8::Value>& args); |
87 |
|
|
static void Raw(const v8::FunctionCallbackInfo<v8::Value>& args); |
88 |
|
|
static void PublicKey(const v8::FunctionCallbackInfo<v8::Value>& args); |
89 |
|
|
static void Pem(const v8::FunctionCallbackInfo<v8::Value>& args); |
90 |
|
|
static void CheckCA(const v8::FunctionCallbackInfo<v8::Value>& args); |
91 |
|
|
static void CheckHost(const v8::FunctionCallbackInfo<v8::Value>& args); |
92 |
|
|
static void CheckEmail(const v8::FunctionCallbackInfo<v8::Value>& args); |
93 |
|
|
static void CheckIP(const v8::FunctionCallbackInfo<v8::Value>& args); |
94 |
|
|
static void CheckIssued(const v8::FunctionCallbackInfo<v8::Value>& args); |
95 |
|
|
static void CheckPrivateKey(const v8::FunctionCallbackInfo<v8::Value>& args); |
96 |
|
|
static void Verify(const v8::FunctionCallbackInfo<v8::Value>& args); |
97 |
|
|
static void ToLegacy(const v8::FunctionCallbackInfo<v8::Value>& args); |
98 |
|
|
static void GetIssuerCert(const v8::FunctionCallbackInfo<v8::Value>& args); |
99 |
|
|
|
100 |
|
119 |
X509* get() { return cert_->get(); } |
101 |
|
|
|
102 |
|
|
void MemoryInfo(MemoryTracker* tracker) const override; |
103 |
|
|
SET_MEMORY_INFO_NAME(X509Certificate) |
104 |
|
|
SET_SELF_SIZE(X509Certificate) |
105 |
|
|
|
106 |
|
|
class X509CertificateTransferData : public worker::TransferData { |
107 |
|
|
public: |
108 |
|
1 |
explicit X509CertificateTransferData( |
109 |
|
|
const std::shared_ptr<ManagedX509>& data) |
110 |
|
1 |
: data_(data) {} |
111 |
|
|
|
112 |
|
|
BaseObjectPtr<BaseObject> Deserialize( |
113 |
|
|
Environment* env, |
114 |
|
|
v8::Local<v8::Context> context, |
115 |
|
|
std::unique_ptr<worker::TransferData> self) override; |
116 |
|
|
|
117 |
|
|
SET_MEMORY_INFO_NAME(X509CertificateTransferData) |
118 |
|
|
SET_SELF_SIZE(X509CertificateTransferData) |
119 |
|
|
SET_NO_MEMORY_INFO() |
120 |
|
|
|
121 |
|
|
private: |
122 |
|
|
std::shared_ptr<ManagedX509> data_; |
123 |
|
|
}; |
124 |
|
|
|
125 |
|
|
BaseObject::TransferMode GetTransferMode() const override; |
126 |
|
|
std::unique_ptr<worker::TransferData> CloneForMessaging() const override; |
127 |
|
|
|
128 |
|
|
private: |
129 |
|
|
X509Certificate( |
130 |
|
|
Environment* env, |
131 |
|
|
v8::Local<v8::Object> object, |
132 |
|
|
std::shared_ptr<ManagedX509> cert, |
133 |
|
|
STACK_OF(X509)* issuer_chain = nullptr); |
134 |
|
|
|
135 |
|
|
std::shared_ptr<ManagedX509> cert_; |
136 |
|
|
BaseObjectPtr<X509Certificate> issuer_cert_; |
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
} // namespace crypto |
140 |
|
|
} // namespace node |
141 |
|
|
|
142 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
143 |
|
|
#endif // SRC_CRYPTO_CRYPTO_X509_H_ |