Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 518b578

Browse filesBrowse files
mertcanaltinaduh95
authored andcommitted
crypto: add memory tracking for secureContext openssl objects
PR-URL: #59051 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 06defaa commit 518b578
Copy full SHA for 518b578

4 files changed

+36-2Lines changed: 36 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/crypto/crypto_context.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_context.cc
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,6 +2439,12 @@ void SecureContext::GetCertificate(const FunctionCallbackInfo<Value>& args) {
24392439
args.GetReturnValue().Set(buff);
24402440
}
24412441

2442+
void SecureContext::MemoryInfo(MemoryTracker* tracker) const {
2443+
tracker->TrackFieldWithSize("ctx", ctx_ ? kSizeOf_SSL_CTX : 0);
2444+
tracker->TrackFieldWithSize("cert", cert_ ? kSizeOf_X509 : 0);
2445+
tracker->TrackFieldWithSize("issuer", issuer_ ? kSizeOf_X509 : 0);
2446+
}
2447+
24422448
// UseExtraCaCerts is called only once at the start of the Node.js process.
24432449
void UseExtraCaCerts(std::string_view file) {
24442450
extra_root_certs_file = file;
Collapse file

‎src/crypto/crypto_context.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_context.h
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ class SecureContext final : public BaseObject {
6767
void SetX509StoreFlag(unsigned long flags); // NOLINT(runtime/int)
6868
X509_STORE* GetCertStoreOwnedByThisSecureContext();
6969

70-
// TODO(joyeecheung): track the memory used by OpenSSL types
71-
SET_NO_MEMORY_INFO()
70+
void MemoryInfo(MemoryTracker* tracker) const override;
7271
SET_MEMORY_INFO_NAME(SecureContext)
7372
SET_SELF_SIZE(SecureContext)
7473

Collapse file

‎src/crypto/crypto_util.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_util.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ constexpr size_t kSizeOf_EVP_MD_CTX = 48;
3636
constexpr size_t kSizeOf_EVP_PKEY = 72;
3737
constexpr size_t kSizeOf_EVP_PKEY_CTX = 80;
3838
constexpr size_t kSizeOf_HMAC_CTX = 32;
39+
constexpr size_t kSizeOf_SSL_CTX = 240;
40+
constexpr size_t kSizeOf_X509 = 128;
3941

4042
bool ProcessFipsOptions();
4143

Collapse file

‎test/cctest/test_node_crypto.cc‎

Copy file name to clipboardExpand all lines: test/cctest/test_node_crypto.cc
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,30 @@ TEST(NodeCrypto, NewRootCertStore) {
2121
"any errors on the OpenSSL error stack\n";
2222
X509_STORE_free(store);
2323
}
24+
25+
/*
26+
* This test verifies that OpenSSL memory tracking constants are properly
27+
* defined.
28+
*/
29+
TEST(NodeCrypto, MemoryTrackingConstants) {
30+
// Verify that our memory tracking constants are defined and reasonable
31+
EXPECT_GT(node::crypto::kSizeOf_SSL_CTX, 0)
32+
<< "SSL_CTX size constant should be positive";
33+
EXPECT_GT(node::crypto::kSizeOf_X509, 0)
34+
<< "X509 size constant should be positive";
35+
EXPECT_GT(node::crypto::kSizeOf_EVP_MD_CTX, 0)
36+
<< "EVP_MD_CTX size constant should be positive";
37+
38+
// Verify reasonable size ranges (basic sanity check)
39+
EXPECT_LT(node::crypto::kSizeOf_SSL_CTX, 10000)
40+
<< "SSL_CTX size should be reasonable";
41+
EXPECT_LT(node::crypto::kSizeOf_X509, 10000)
42+
<< "X509 size should be reasonable";
43+
EXPECT_LT(node::crypto::kSizeOf_EVP_MD_CTX, 1000)
44+
<< "EVP_MD_CTX size should be reasonable";
45+
46+
// Specific values we expect based on our implementation
47+
EXPECT_EQ(node::crypto::kSizeOf_SSL_CTX, 240);
48+
EXPECT_EQ(node::crypto::kSizeOf_X509, 128);
49+
EXPECT_EQ(node::crypto::kSizeOf_EVP_MD_CTX, 48);
50+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.