diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-06-01 15:47:39 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-06-01 15:47:39 +0100 |
| commit | 099e93f617e3cfc8cd371d652c2d2ed040f94e7b (patch) | |
| tree | ec239146628cfb33d0883a1cb74582569e52d489 | |
| parent | a6aaf223e085e9ef7f2bc1cc37614ecb13d323ec (diff) | |
More changes to X509{Issuer,Subject}Name.
Before, we had a fixed order for the components of a name like
dnQualifier=\+LLvuYNO4YBJSp9Jjmlv8oippzQ=,CN=.DC.DMS.DC2.SMPTE,OU=DC.DOREMILABS.COM,O=DC2.SMPTE.DOREMILABS.COM
It started off as dnQualifier,CN,OU,O
then we changed it to
O,OU,CN,dnQualifier
This is another speculative change which uses a libssl
function to get the name, rather than building it up from
components ourselves. It may help or hinder ingestion
of signed DCPS and/or KDMs.
| -rw-r--r-- | src/certificates.cc | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/certificates.cc b/src/certificates.cc index 0d92699d..8682b831 100644 --- a/src/certificates.cc +++ b/src/certificates.cc @@ -168,22 +168,28 @@ Certificate::get_name_part (X509_NAME* n, int nid) assert (p != -1); return asn_to_utf8 (X509_NAME_ENTRY_get_data (X509_NAME_get_entry (n, p))); } - string -Certificate::name_for_xml (X509_NAME * n) +Certificate::name_for_xml (X509_NAME* name) { - assert (n); - - string s = String::compose ( - "O=%1,OU=%2,CN=%3,dnQualifier=%4", - get_name_part (n, NID_organizationName), - get_name_part (n, NID_organizationalUnitName), - get_name_part (n, NID_commonName), - get_name_part (n, NID_dnQualifier) - ); - - boost::replace_all (s, "+", "\\+"); + assert (name); + + BIO* bio = BIO_new (BIO_s_mem ()); + if (!bio) { + throw MiscError ("could not create memory BIO"); + } + + X509_NAME_print_ex (bio, name, 0, XN_FLAG_RFC2253); + int n = BIO_pending (bio); + char* result = new char[n + 1]; + n = BIO_read (bio, result, n); + result[n] = '\0'; + + BIO_free (bio); + + string s = result; + delete[] result; + return s; } |
