8000 src: remove unused x509 functions · nodejs/node@d4e5d1b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit d4e5d1b

Browse files
tniessenkumarak
authored andcommitted
src: remove unused x509 functions
These functions are currently not being used and their security should be audited before any potential future use. Co-authored-by: Akshay K <iit.akshay@gmail.com> Backport-PR-URL: nodejs-private/node-private#306 PR-URL: nodejs-private/node-private#300 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent be69403 commit d4e5d1b

File tree

2 files changed

+0
-76
lines changed

2 files changed

+0
-76
lines changed

src/node_crypto_common.cc

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -133,76 +133,6 @@ SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) {
133133
return SSLSessionPointer(d2i_SSL_SESSION(nullptr, &buf, length));
134134
}
135135

136-
std::unordered_multimap<std::string, std::string>
137-
GetCertificateAltNames(X509* cert) {
138-
std::unordered_multimap<std::string, std::string> map;
139-
BIOPointer bio(BIO_new(BIO_s_mem()));
140-
BUF_MEM* mem;
141-
int idx = X509_get_ext_by_NID(cert, NID_subject_alt_name, -1);
142-
if (idx < 0) // There is no subject alt name
143-
return map;
144-
145-
X509_EXTENSION* ext = X509_get_ext(cert, idx);
146-
CHECK_NOT_NULL(ext);
147-
const X509V3_EXT_METHOD* method = X509V3_EXT_get(ext);
148-
CHECK_EQ(method, X509V3_EXT_get_nid(NID_subject_alt_name));
149-
150-
GENERAL_NAMES* names = static_cast<GENERAL_NAMES*>(X509V3_EXT_d2i(ext));
151-
if (names == nullptr) // There are no names
152-
return map;
153-
154-
for (int i = 0; i < sk_GENERAL_NAME_num(names); i++) {
155-
USE(BIO_reset(bio.get()));
156-
GENERAL_NAME* gen = sk_GENERAL_NAME_value(names, i);
157-
if (gen->type == GEN_DNS) {
158-
ASN1_IA5STRING* name = gen->d.dNSName;
159-
BIO_write(bio.get(), name->data, name->length);
160-
BIO_get_mem_ptr(bio.get(), &mem);
161-
map.emplace("dns", std::string(mem->data, mem->length));
162-
} else {
163-
STACK_OF(CONF_VALUE)* nval = i2v_GENERAL_NAME(
164-
const_cast<X509V3_EXT_METHOD*>(method), gen, nullptr);
165-
if (nval == nullptr)
166-
continue;
167-
X509V3_EXT_val_prn(bio.get(), nval, 0, 0);
168-
sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
169-
BIO_get_mem_ptr(bio.get(), &mem);
170-
std::string value(mem->data, mem->length);
171-
if (value.compare(0, 11, "IP Address:") == 0) {
172-
map.emplace("ip", value.substr(11));
173-
} else if (value.compare(0, 4, "URI:") == 0) {
174-
url::URL url(value.substr(4));
175-
if (url.flags() & url::URL_FLAGS_CANNOT_BE_BASE ||
176-
url.flags() & url::URL_FLAGS_FAILED) {
177-
continue; // Skip this one
178-
}
179-
map.emplace("uri", url.host());
180-
}
181-
}
182-
}
183-
sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
184-
return map;
185-
}
186-
187-
std::string GetCertificateCN(X509* cert) {
188-
X509_NAME* subject = X509_get_subject_name(cert);
189-
if (subject != nullptr) {
190-
int nid = OBJ_txt2nid("CN");
191-
int idx = X509_NAME_get_index_by_NID(subject, nid, -1);
192-
if (idx != -1) {
193-
X509_NAME_ENTRY* cn = X509_NAME_get_entry(subject, idx);
194-
if (cn != nullptr) {
195-
ASN1_STRING* cn_str = X509_NAME_ENTRY_get_data(cn);
196-
if (cn_str != nullptr) {
197-
return std::string(reinterpret_cast<const char*>(
198-
ASN1_STRING_get0_data(cn_str)));
199-
}
200-
}
201-
}
202-
}
203-
return std::string();
204-
}
205-
206136
long VerifyPeerCertificate( // NOLINT(runtime/int)
207137
const SSLPointer& ssl,
208138
long def) { // NOLINT(runtime/int)

src/node_crypto_common.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <openssl/x509v3.h>
1010

1111
#include <string>
12-
#include <unordered_map>
1312

1413
namespace node {
1514
namespace crypto {
@@ -62,11 +61,6 @@ SSLSessionPointer GetTLSSession(v8::Local<v8::Value> val);
6261

6362
SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length);
6463

65-
std::unordered_multimap<std::string, std::string>
66-
GetCertificateAltNames(X509* cert);
67-
68-
std::string GetCertificateCN(X509* cert);
69-
7064
long VerifyPeerCertificate( // NOLINT(runtime/int)
7165
const SSLPointer& ssl,
7266
long def = X509_V_ERR_UNSPECIFIED); // NOLINT(runtime/int)

0 commit comments

Comments
 (0)
0