◐ Shell
clean mode source ↗

src: clean up some obsolete crypto methods · nodejs/node@94a0237

@@ -915,6 +915,18 @@ BIOPointer X509View::toDER() const {

915915

return bio;

916916

}

917917918+

const X509Name X509View::getSubjectName() const {

919+

ClearErrorOnReturn clearErrorOnReturn;

920+

if (cert_ == nullptr) return {};

921+

return X509Name(X509_get_subject_name(cert_));

922+

}

923+924+

const X509Name X509View::getIssuerName() const {

925+

ClearErrorOnReturn clearErrorOnReturn;

926+

if (cert_ == nullptr) return {};

927+

return X509Name(X509_get_issuer_name(cert_));

928+

}

929+918930

BIOPointer X509View::getSubject() const {

919931

ClearErrorOnReturn clearErrorOnReturn;

920932

if (cert_ == nullptr) return {};

@@ -2390,6 +2402,15 @@ EVPKeyPointer::operator Rsa() const {

23902402

return Rsa(rsa);

23912403

}

239224042405+

EVPKeyPointer::operator Dsa() const {

2406+

int type = id();

2407+

if (type != EVP_PKEY_DSA) return {};

2408+2409+

OSSL3_CONST DSA* dsa = EVP_PKEY_get0_DSA(get());

2410+

if (dsa == nullptr) return {};

2411+

return Dsa(dsa);

2412+

}

2413+23932414

bool EVPKeyPointer::validateDsaParameters() const {

23942415

if (!pkey_) return false;

23952416

/* Validate DSA2 parameters from FIPS 186-4 */

@@ -2585,6 +2606,24 @@ EVPKeyPointer SSLPointer::getPeerTempKey() const {

25852606

return EVPKeyPointer(raw_key);

25862607

}

258726082609+

std::optional<std::string_view> SSLPointer::getCipherName() const {

2610+

auto cipher = getCipher();

2611+

if (cipher == nullptr) return std::nullopt;

2612+

return SSL_CIPHER_get_name(cipher);

2613+

}

2614+2615+

std::optional<std::string_view> SSLPointer::getCipherStandardName() const {

2616+

auto cipher = getCipher();

2617+

if (cipher == nullptr) return std::nullopt;

2618+

return SSL_CIPHER_standard_name(cipher);

2619+

}

2620+2621+

std::optional<std::string_view> SSLPointer::getCipherVersion() const {

2622+

auto cipher = getCipher();

2623+

if (cipher == nullptr) return std::nullopt;

2624+

return SSL_CIPHER_get_version(cipher);

2625+

}

2626+25882627

SSLCtxPointer::SSLCtxPointer(SSL_CTX* ctx) : ctx_(ctx) {}

2589262825902629

SSLCtxPointer::SSLCtxPointer(SSLCtxPointer&& other) noexcept

@@ -2630,8 +2669,8 @@ bool SSLCtxPointer::setGroups(const char* groups) {

2630266926312670

// ============================================================================

263226712633-

const Cipher Cipher::FromName(const char* name) {

2634-

return Cipher(EVP_get_cipherbyname(name));

2672+

const Cipher Cipher::FromName(std::string_view name) {

2673+

return Cipher(EVP_get_cipherbyname(name.data()));

26352674

}

2636267526372676

const Cipher Cipher::FromNid(int nid) {

@@ -3813,4 +3852,93 @@ DataPointer hashDigest(const Buffer<const unsigned char>& buf,

38133852

return data.resize(result_size);

38143853

}

381538543855+

// ============================================================================

3856+3857+

X509Name::X509Name() : name_(nullptr), total_(0) {}

3858+3859+

X509Name::X509Name(const X509_NAME* name)

3860+

: name_(name), total_(X509_NAME_entry_count(name)) {}

3861+3862+

X509Name::Iterator::Iterator(const X509Name& name, int pos)

3863+

: name_(name), loc_(pos) {}

3864+3865+

X509Name::Iterator& X509Name::Iterator::operator++() {

3866+

++loc_;

3867+

return *this;

3868+

}

3869+3870+

X509Name::Iterator::operator bool() const {

3871+

return loc_ < name_.total_;

3872+

}

3873+3874+

bool X509Name::Iterator::operator==(const Iterator& other) const {

3875+

return loc_ == other.loc_;

3876+

}

3877+3878+

bool X509Name::Iterator::operator!=(const Iterator& other) const {

3879+

return loc_ != other.loc_;

3880+

}

3881+3882+

std::pair<std::string, std::string> X509Name::Iterator::operator*() const {

3883+

if (loc_ == name_.total_) return {{}, {}};

3884+3885+

X509_NAME_ENTRY* entry = X509_NAME_get_entry(name_, loc_);

3886+

if (entry == nullptr) [[unlikely]]

3887+

return {{}, {}};

3888+3889+

ASN1_OBJECT* name = X509_NAME_ENTRY_get_object(entry);

3890+

ASN1_STRING* value = X509_NAME_ENTRY_get_data(entry);

3891+3892+

if (name == nullptr || value == nullptr) [[unlikely]] {

3893+

return {{}, {}};

3894+

}

3895+3896+

int nid = OBJ_obj2nid(name);

3897+

std::string name_str;

3898+

if (nid != NID_undef) {

3899+

name_str = std::string(OBJ_nid2sn(nid));

3900+

} else {

3901+

char buf[80];

3902+

OBJ_obj2txt(buf, sizeof(buf), name, 0);

3903+

name_str = std::string(buf);

3904+

}

3905+3906+

unsigned char* value_str;

3907+

int value_str_size = ASN1_STRING_to_UTF8(&value_str, value);

3908+3909+

return {

3910+

std::move(name_str),

3911+

std::string(reinterpret_cast<const char*>(value_str), value_str_size)};

3912+

}

3913+3914+

// ============================================================================

3915+3916+

Dsa::Dsa() : dsa_(nullptr) {}

3917+3918+

Dsa::Dsa(OSSL3_CONST DSA* dsa) : dsa_(dsa) {}

3919+3920+

const BIGNUM* Dsa::getP() const {

3921+

if (dsa_ == nullptr) return nullptr;

3922+

const BIGNUM* p;

3923+

DSA_get0_pqg(dsa_, &p, nullptr, nullptr);

3924+

return p;

3925+

}

3926+3927+

const BIGNUM* Dsa::getQ() const {

3928+

if (dsa_ == nullptr) return nullptr;

3929+

const BIGNUM* q;

3930+

DSA_get0_pqg(dsa_, nullptr, &q, nullptr);

3931+

return q;

3932+

}

3933+3934+

size_t Dsa::getModulusLength() const {

3935+

if (dsa_ == nullptr) return 0;

3936+

return BignumPointer::GetBitCount(getP());

3937+

}

3938+3939+

size_t Dsa::getDivisorLength() const {

3940+

if (dsa_ == nullptr) return 0;

3941+

return BignumPointer::GetBitCount(getQ());

3942+

}

3943+38163944

} // namespace ncrypto