Skip to content

Commit e1fb6ae

Browse files
authored
crypto: prettify othername in PrintGeneralName
Refs: 466e541 PR-URL: #42123 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 36fb790 commit e1fb6ae

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/crypto/crypto_common.cc

+13-15
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,8 @@ static inline void PrintUtf8AltName(const BIOPointer& out,
692692
true, safe_prefix);
693693
}
694694

695-
// This function currently emulates the behavior of i2v_GENERAL_NAME in a safer
696-
// and less ambiguous way.
697-
// TODO(tniessen): gradually improve the format in the next major version(s)
695+
// This function emulates the behavior of i2v_GENERAL_NAME in a safer and less
696+
// ambiguous way. "othername:" entries use the GENERAL_NAME_print format.
698697
static bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
699698
if (gen->type == GEN_DNS) {
700699
ASN1_IA5STRING* name = gen->d.dNSName;
@@ -767,33 +766,32 @@ static bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) {
767766
OBJ_obj2txt(oline, sizeof(oline), gen->d.rid, true);
768767
BIO_printf(out.get(), "Registered ID:%s", oline);
769768
} else if (gen->type == GEN_OTHERNAME) {
770-
// TODO(tniessen): the format that is used here is based on OpenSSL's
771-
// implementation of i2v_GENERAL_NAME (as of OpenSSL 3.0.1), mostly for
772-
// backward compatibility. It is somewhat awkward, especially when passed to
773-
// translatePeerCertificate, and should be changed in the future, probably
774-
// to the format used by GENERAL_NAME_print (in a major release).
769+
// The format that is used here is based on OpenSSL's implementation of
770+
// GENERAL_NAME_print (as of OpenSSL 3.0.1). Earlier versions of Node.js
771+
// instead produced the same format as i2v_GENERAL_NAME, which was somewhat
772+
// awkward, especially when passed to translatePeerCertificate.
775773
bool unicode = true;
776774
const char* prefix = nullptr;
777-
// OpenSSL 1.1.1 does not support othername in i2v_GENERAL_NAME and may not
778-
// define these NIDs.
775+
// OpenSSL 1.1.1 does not support othername in GENERAL_NAME_print and may
776+
// not define these NIDs.
779777
#if OPENSSL_VERSION_MAJOR >= 3
780778
int nid = OBJ_obj2nid(gen->d.otherName->type_id);
781779
switch (nid) {
782780
case NID_id_on_SmtpUTF8Mailbox:
783-
prefix = " SmtpUTF8Mailbox:";
781+
prefix = "SmtpUTF8Mailbox";
784782
break;
785783
case NID_XmppAddr:
786-
prefix = " XmppAddr:";
784+
prefix = "XmppAddr";
787785
break;
788786
case NID_SRVName:
789-
prefix = " SRVName:";
787+
prefix = "SRVName";
790788
unicode = false;
791789
break;
792790
case NID_ms_upn:
793-
prefix = " UPN:";
791+
prefix = "UPN";
794792
break;
795793
case NID_NAIRealm:
796-
prefix = " NAIRealm:";
794+
prefix = "NAIRealm";
797795
break;
798796
}
799797
#endif // OPENSSL_VERSION_MAJOR >= 3

test/parallel/test-x509-escaping.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ const { hasOpenSSL3 } = common;
8888
// OpenSSL should not know it.
8989
'Registered ID:1.3.9999.12.34',
9090
hasOpenSSL3 ?
91-
'othername: XmppAddr::abc123' :
91+
'othername:XmppAddr:abc123' :
9292
'othername:<unsupported>',
9393
hasOpenSSL3 ?
94-
'othername:" XmppAddr::abc123\\u002c DNS:good.example.com"' :
94+
'othername:"XmppAddr:abc123\\u002c DNS:good.example.com"' :
9595
'othername:<unsupported>',
9696
hasOpenSSL3 ?
97-
'othername:" XmppAddr::good.example.com\\u0000abc123"' :
97+
'othername:"XmppAddr:good.example.com\\u0000abc123"' :
9898
'othername:<unsupported>',
9999
// This is unsupported because the OID is not recognized.
100100
'othername:<unsupported>',
101-
hasOpenSSL3 ? 'othername: SRVName::abc123' : 'othername:<unsupported>',
101+
hasOpenSSL3 ? 'othername:SRVName:abc123' : 'othername:<unsupported>',
102102
// This is unsupported because it is an SRVName with a UTF8String value,
103103
// which is not allowed for SRVName.
104104
'othername:<unsupported>',
105105
hasOpenSSL3 ?
106-
'othername:" SRVName::abc\\u0000def"' :
106+
'othername:"SRVName:abc\\u0000def"' :
107107
'othername:<unsupported>',
108108
];
109109

@@ -173,14 +173,14 @@ const { hasOpenSSL3 } = common;
173173
},
174174
},
175175
hasOpenSSL3 ? {
176-
text: 'OCSP - othername: XmppAddr::good.example.com\n' +
176+
text: 'OCSP - othername:XmppAddr:good.example.com\n' +
177177
'OCSP - othername:<unsupported>\n' +
178-
'OCSP - othername: SRVName::abc123',
178+
'OCSP - othername:SRVName:abc123',
179179
legacy: {
180180
'OCSP - othername': [
181-
' XmppAddr::good.example.com',
181+
'XmppAddr:good.example.com',
182182
'<unsupported>',
183-
' SRVName::abc123',
183+
'SRVName:abc123',
184184
],
185185
},
186186
} : {
@@ -196,10 +196,10 @@ const { hasOpenSSL3 } = common;
196196
},
197197
},
198198
hasOpenSSL3 ? {
199-
text: 'OCSP - othername:" XmppAddr::good.example.com\\u0000abc123"',
199+
text: 'OCSP - othername:"XmppAddr:good.example.com\\u0000abc123"',
200200
legacy: {
201201
'OCSP - othername': [
202-
' XmppAddr::good.example.com\0abc123',
202+
'XmppAddr:good.example.com\0abc123',
203203
],
204204
},
205205
} : {

0 commit comments

Comments
 (0)