diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-03-08 21:26:21 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-03-08 21:26:21 +0000 |
| commit | 77e70f82829aee382105f3d5520edd630933b765 (patch) | |
| tree | 7e24e438d36d5e85a9fedb7ae885ef3f1c242e22 /src | |
| parent | 230d989d46375a968a03e34bad429c67c75ebab8 (diff) | |
Add method to detect utf8 strings.
Diffstat (limited to 'src')
| -rw-r--r-- | src/certificate.cc | 16 | ||||
| -rw-r--r-- | src/certificate.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/certificate.cc b/src/certificate.cc index 64fb3626..8064e4ab 100644 --- a/src/certificate.cc +++ b/src/certificate.cc @@ -408,6 +408,22 @@ Certificate::public_key () const return _public_key; } +static bool string_is_utf8 (X509_NAME* n, int nid) +{ + int p = -1; + p = X509_NAME_get_index_by_NID (n, nid, p); + return p != -1 && X509_NAME_ENTRY_get_data(X509_NAME_get_entry(n, p))->type == V_ASN1_UTF8STRING; +} + +bool +Certificate::has_utf8_strings () const +{ + X509_NAME* n = X509_get_subject_name (_certificate); + return string_is_utf8(n, NID_commonName) || + string_is_utf8(n, NID_organizationName) || + string_is_utf8(n, NID_organizationalUnitName); +} + bool dcp::operator== (Certificate const & a, Certificate const & b) { diff --git a/src/certificate.h b/src/certificate.h index 326f277b..0d333f1e 100644 --- a/src/certificate.h +++ b/src/certificate.h @@ -90,6 +90,8 @@ public: std::string thumbprint () const; + bool has_utf8_strings () const; + private: static std::string name_for_xml (X509_NAME *); |
