| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -915,6 +915,18 @@ BIOPointer X509View::toDER() const { | |||
| 915 | 915 | return bio; | |
| 916 | 916 | } | |
| 917 | 917 | ||
| 918 | + 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 | + | ||
| 918 | 930 | BIOPointer X509View::getSubject() const { | |
| 919 | 931 | ClearErrorOnReturn clearErrorOnReturn; | |
| 920 | 932 | if (cert_ == nullptr) return {}; | |
@@ -2390,6 +2402,15 @@ EVPKeyPointer::operator Rsa() const { | |||
| 2390 | 2402 | return Rsa(rsa); | |
| 2391 | 2403 | } | |
| 2392 | 2404 | ||
| 2405 | + 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 | + | ||
| 2393 | 2414 | bool EVPKeyPointer::validateDsaParameters() const { | |
| 2394 | 2415 | if (!pkey_) return false; | |
| 2395 | 2416 | /* Validate DSA2 parameters from FIPS 186-4 */ | |
@@ -2585,6 +2606,24 @@ EVPKeyPointer SSLPointer::getPeerTempKey() const { | |||
| 2585 | 2606 | return EVPKeyPointer(raw_key); | |
| 2586 | 2607 | } | |
| 2587 | 2608 | ||
| 2609 | + 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 | + | ||
| 2588 | 2627 | SSLCtxPointer::SSLCtxPointer(SSL_CTX* ctx) : ctx_(ctx) {} | |
| 2589 | 2628 | ||
| 2590 | 2629 | SSLCtxPointer::SSLCtxPointer(SSLCtxPointer&& other) noexcept | |
@@ -2630,8 +2669,8 @@ bool SSLCtxPointer::setGroups(const char* groups) { | |||
| 2630 | 2669 | ||
| 2631 | 2670 | // ============================================================================ | |
| 2632 | 2671 | ||
| 2633 | - 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())); | ||
| 2635 | 2674 | } | |
| 2636 | 2675 | ||
| 2637 | 2676 | const Cipher Cipher::FromNid(int nid) { | |
@@ -3813,4 +3852,93 @@ DataPointer hashDigest(const Buffer<const unsigned char>& buf, | |||
| 3813 | 3852 | return data.resize(result_size); | |
| 3814 | 3853 | } | |
| 3815 | 3854 | ||
| 3855 | + // ============================================================================ | ||
| 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 | + | ||
| 3816 | 3944 | } // namespace ncrypto | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,6 +221,7 @@ class ECDSASigPointer; | |||
| 221 | 221 | class ECGroupPointer; | |
| 222 | 222 | class ECPointPointer; | |
| 223 | 223 | class ECKeyPointer; | |
| 224 | + class Dsa; | ||
| 224 | 225 | class Rsa; | |
| 225 | 226 | class Ec; | |
| 226 | 227 | ||
@@ -267,7 +268,7 @@ class Cipher final { | |||
| 267 | 268 | ||
| 268 | 269 | bool isSupportedAuthenticatedMode() const; | |
| 269 | 270 | ||
| 270 | - static const Cipher FromName(const char* name); | ||
| 271 | + static const Cipher FromName(std::string_view name); | ||
| 271 | 272 | static const Cipher FromNid(int nid); | |
| 272 | 273 | static const Cipher FromCtx(const CipherCtxPointer& ctx); | |
| 273 | 274 | ||
@@ -292,10 +293,35 @@ class Cipher final { | |||
| 292 | 293 | const CipherParams& params, | |
| 293 | 294 | const Buffer<const void> in); | |
| 294 | 295 | ||
| 296 | + static constexpr bool IsValidGCMTagLength(unsigned int tag_len) { | ||
| 297 | + return tag_len == 4 || tag_len == 8 || (tag_len >= 12 && tag_len <= 16); | ||
| 298 | + } | ||
| 299 | + | ||
| 295 | 300 | private: | |
| 296 | 301 | const EVP_CIPHER* cipher_ = nullptr; | |
| 297 | 302 | }; | |
| 298 | 303 | ||
| 304 | + // ============================================================================ | ||
| 305 | + // DSA | ||
| 306 | + | ||
| 307 | + class Dsa final { | ||
| 308 | + public: | ||
| 309 | + Dsa(); | ||
| 310 | + Dsa(OSSL3_CONST DSA* dsa); | ||
| 311 | + NCRYPTO_DISALLOW_COPY_AND_MOVE(Dsa) | ||
| 312 | + | ||
| 313 | + inline operator bool() const { return dsa_ != nullptr; } | ||
| 314 | + inline operator OSSL3_CONST DSA*() const { return dsa_; } | ||
| 315 | + | ||
| 316 | + const BIGNUM* getP() const; | ||
| 317 | + const BIGNUM* getQ() const; | ||
| 318 | + size_t getModulusLength() const; | ||
| 319 | + size_t getDivisorLength() const; | ||
| 320 | + | ||
| 321 | + private: | ||
| 322 | + OSSL3_CONST DSA* dsa_; | ||
| 323 | + }; | ||
| 324 | + | ||
| 299 | 325 | // ============================================================================ | |
| 300 | 326 | // RSA | |
| 301 | 327 | ||
@@ -384,7 +410,12 @@ class DataPointer final { | |||
| 384 | 410 | ||
| 385 | 411 | inline bool operator==(std::nullptr_t) noexcept { return data_ == nullptr; } | |
| 386 | 412 | inline operator bool() const { return data_ != nullptr; } | |
| 387 | - inline void* get() const noexcept { return data_; } | ||
| 413 | + | ||
| 414 | + template <typename T = void> | ||
| 415 | + inline T* get() const noexcept { | ||
| 416 | + return static_cast<T*>(data_); | ||
| 417 | + } | ||
| 418 | + | ||
| 388 | 419 | inline size_t size() const noexcept { return len_; } | |
| 389 | 420 | void reset(void* data = nullptr, size_t len = 0); | |
| 390 | 421 | void reset(const Buffer<void>& buffer); | |
@@ -762,6 +793,7 @@ class EVPKeyPointer final { | |||
| 762 | 793 | std::optional<uint32_t> getBytesOfRS() const; | |
| 763 | 794 | int getDefaultSignPadding() const; | |
| 764 | 795 | operator Rsa() const; | |
| 796 | + operator Dsa() const; | ||
| 765 | 797 | ||
| 766 | 798 | bool isRsaVariant() const; | |
| 767 | 799 | bool isOneShotVariant() const; | |
@@ -914,6 +946,10 @@ class SSLPointer final { | |||
| 914 | 946 | const SSL_CIPHER* getCipher() const; | |
| 915 | 947 | bool isServer() const; | |
| 916 | 948 | ||
| 949 | + std::optional<std::string_view> getCipherName() const; | ||
| 950 | + std::optional<std::string_view> getCipherStandardName() const; | ||
| 951 | + std::optional<std::string_view> getCipherVersion() const; | ||
| 952 | + | ||
| 917 | 953 | std::optional<uint32_t> verifyPeerCertificate() const; | |
| 918 | 954 | ||
| 919 | 955 | void getCiphers(std::function<void(const std::string_view)> cb) const; | |
@@ -925,6 +961,43 @@ class SSLPointer final { | |||
| 925 | 961 | DeleteFnPtr<SSL, SSL_free> ssl_; | |
| 926 | 962 | }; | |
| 927 | 963 | ||
| 964 | + class X509Name final { | ||
| 965 | + public: | ||
| 966 | + X509Name(); | ||
| 967 | + explicit X509Name(const X509_NAME* name); | ||
| 968 | + NCRYPTO_DISALLOW_COPY_AND_MOVE(X509Name) | ||
| 969 | + | ||
| 970 | + inline operator const X509_NAME*() const { return name_; } | ||
| 971 | + inline operator bool() const { return name_ != nullptr; } | ||
| 972 | + inline const X509_NAME* get() const { return name_; } | ||
| 973 | + inline size_t size() const { return total_; } | ||
| 974 | + | ||
| 975 | + class Iterator final { | ||
| 976 | + public: | ||
| 977 | + Iterator(const X509Name& name, int pos); | ||
| 978 | + Iterator(const Iterator& other) = default; | ||
| 979 | + Iterator(Iterator&& other) = default; | ||
| 980 | + Iterator& operator=(const Iterator& other) = delete; | ||
| 981 | + Iterator& operator=(Iterator&& other) = delete; | ||
| 982 | + Iterator& operator++(); | ||
| 983 | + operator bool() const; | ||
| 984 | + bool operator==(const Iterator& other) const; | ||
| 985 | + bool operator!=(const Iterator& other) const; | ||
| 986 | + std::pair<std::string, std::string> operator*() const; | ||
| 987 | + | ||
| 988 | + private: | ||
| 989 | + const X509Name& name_; | ||
| 990 | + int loc_; | ||
| 991 | + }; | ||
| 992 | + | ||
| 993 | + inline Iterator begin() const { return Iterator(*this, 0); } | ||
| 994 | + inline Iterator end() const { return Iterator(*this, total_); } | ||
| 995 | + | ||
| 996 | + private: | ||
| 997 | + const X509_NAME* name_; | ||
| 998 | + int total_; | ||
| 999 | + }; | ||
| 1000 | + | ||
| 928 | 1001 | class X509View final { | |
| 929 | 1002 | public: | |
| 930 | 1003 | static X509View From(const SSLPointer& ssl); | |
@@ -946,6 +1019,8 @@ class X509View final { | |||
| 946 | 1019 | BIOPointer toPEM() const; | |
| 947 | 1020 | BIOPointer toDER() const; | |
| 948 | 1021 | ||
| 1022 | + const X509Name getSubjectName() const; | ||
| 1023 | + const X509Name getIssuerName() const; | ||
| 949 | 1024 | BIOPointer getSubject() const; | |
| 950 | 1025 | BIOPointer getSubjectAltName() const; | |
| 951 | 1026 | BIOPointer getIssuer() const; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,10 +106,6 @@ an `ArrayBuffer` (`v8::BackingStore`), or allocated data. | |||
| 106 | 106 | * If allocated data is used, then it must have been allocated using OpenSSL's | |
| 107 | 107 | allocator. It will be freed automatically when the `ByteSource` is destroyed. | |
| 108 | 108 | ||
| 109 | - The `ByteSource::Builder` class can be used to allocate writable memory that can | ||
| 110 | - then be released as a `ByteSource`, making it read-only, or freed by destroying | ||
| 111 | - the `ByteSource::Builder` without releasing it as a `ByteSource`. | ||
| 112 | - | ||
| 113 | 109 | ### `ArrayBufferOrViewContents` | |
| 114 | 110 | ||
| 115 | 111 | The `ArrayBufferOrViewContents` class is a helper utility that abstracts | |
| Back | FazBrowse Home | New Git URL |
0 commit comments