]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
apps: Escape control characters in DNs by default
authorTomas Mraz <tomas@openssl.org>
Fri, 28 Feb 2025 10:13:27 +0000 (11:13 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 3 Mar 2025 08:08:34 +0000 (09:08 +0100)
When displaying distinguished names the control characters
are escaped by default.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/26932)

CHANGES.md
apps/lib/apps.c
doc/man1/openssl-namedisplay-options.pod
test/certs/tab-in-dn.pem [new file with mode: 0644]
test/certs/tab-in-dn.text [new file with mode: 0644]
test/recipes/25-test_x509.t

index 1c54c33b1ddb07626b969074786405de0309970c..d38f3e060b80e468dbf4870a65e3dc80afd0bcd6 100644 (file)
@@ -253,7 +253,10 @@ OpenSSL 3.4
 
 ### Changes between 3.4.1 and 3.4.2 [xx XXX xxxx]
 
- * none yet
+ * When displaying distinguished names in the openssl application escape control
+   characters by default.
+
+   *Tomáš Mráz*
 
 ### Changes between 3.4.0 and 3.4.1 [11 Feb 2025]
 
index b31b1b47e2f660a48f8fb2077d4f60a5d5f8813e..47c699375b19b43e3ab62e4f18ef99de7490e6f5 100644 (file)
@@ -192,7 +192,11 @@ int set_nameopt(const char *arg)
 unsigned long get_nameopt(void)
 {
     return
-        nmflag_set ? nmflag : XN_FLAG_SEP_CPLUS_SPC | ASN1_STRFLGS_UTF8_CONVERT;
+        nmflag_set ? nmflag : XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN
+                              | ASN1_STRFLGS_ESC_CTRL
+                              | ASN1_STRFLGS_UTF8_CONVERT
+                              | ASN1_STRFLGS_DUMP_UNKNOWN
+                              | ASN1_STRFLGS_DUMP_DER;
 }
 
 void dump_cert_text(BIO *out, X509 *x)
index a12f4dbf66ca69462bf7ce4c54865e4163bad650..f16a582021f27c9edc28ce6978fdbd9911869c09 100644 (file)
@@ -18,8 +18,10 @@ displayed.
 This is specified by using the B<-nameopt> option, which takes a
 comma-separated list of options from the following set.
 An option may be preceded by a minus sign, C<->, to turn it off.
-The default value is C<utf8,sep_comma_plus_space>.
-The first four are the most commonly used.
+The first four option arguments are the most commonly used.
+
+The default value is
+C<esc_ctrl,utf8,dump_unknown,dump_der,sep_comma_plus_space,sname>.
 
 =head1 OPTIONS
 
diff --git a/test/certs/tab-in-dn.pem b/test/certs/tab-in-dn.pem
new file mode 100644 (file)
index 0000000..85b7b62
--- /dev/null
@@ -0,0 +1,8 @@
+-----BEGIN CERTIFICATE-----
+MIIBCjCBvaADAgECAhQtSLWSJKg8TpmuRG/UlzepKY2MazAFBgMrZXAwEzERMA8G
+A1UEAwwIVGVzdAlUQUIwIBcNMjUwMjI4MTAzNDE5WhgPMjEyNTAyMDQxMDM0MTla
+MBMxETAPBgNVBAMMCFRlc3QJVEFCMCowBQYDK2VwAyEA1ptSJCGrDHMlWEoirhZe
+s2TETOMe4f0G335qXYHDPP+jITAfMB0GA1UdDgQWBBQwCDnyYnvR2GXoToxSxPmp
+kvER+zAFBgMrZXADQQBszFQxeWW1BBUgWf9as2zDyYCO43kBWTFTypPsFkpuAg4t
+oxrqzb7Kd4RIT0TGtRGgd3gwRkqC0ecgM/NmXOYM
+-----END CERTIFICATE-----
diff --git a/test/certs/tab-in-dn.text b/test/certs/tab-in-dn.text
new file mode 100644 (file)
index 0000000..fc7dee8
--- /dev/null
@@ -0,0 +1,27 @@
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number:
+            2d:48:b5:92:24:a8:3c:4e:99:ae:44:6f:d4:97:37:a9:29:8d:8c:6b
+        Signature Algorithm: ED25519
+        Issuer: CN=Test\09TAB
+        Validity
+            Not Before: Feb 28 10:34:19 2025 GMT
+            Not After : Feb  4 10:34:19 2125 GMT
+        Subject: CN=Test\09TAB
+        Subject Public Key Info:
+            Public Key Algorithm: ED25519
+                ED25519 Public-Key:
+                pub:
+                    d6:9b:52:24:21:ab:0c:73:25:58:4a:22:ae:16:5e:
+                    b3:64:c4:4c:e3:1e:e1:fd:06:df:7e:6a:5d:81:c3:
+                    3c:ff
+        X509v3 extensions:
+            X509v3 Subject Key Identifier: 
+                30:08:39:F2:62:7B:D1:D8:65:E8:4E:8C:52:C4:F9:A9:92:F1:11:FB
+    Signature Algorithm: ED25519
+    Signature Value:
+        6c:cc:54:31:79:65:b5:04:15:20:59:ff:5a:b3:6c:c3:c9:80:
+        8e:e3:79:01:59:31:53:ca:93:ec:16:4a:6e:02:0e:2d:a3:1a:
+        ea:cd:be:ca:77:84:48:4f:44:c6:b5:11:a0:77:78:30:46:4a:
+        82:d1:e7:20:33:f3:66:5c:e6:0c
index 6be2d162160096016080b87e69a35335d334bdea..5a67e1556716702205d2bfa4690ca3147aa6cd76 100644 (file)
@@ -16,7 +16,7 @@ use OpenSSL::Test qw/:DEFAULT srctop_file/;
 
 setup("test_x509");
 
-plan tests => 132;
+plan tests => 134;
 
 # Prevent MSys2 filename munging for arguments that look like file paths but
 # aren't
@@ -42,6 +42,18 @@ ok(run(app(["openssl", "x509", "-text", "-in", $pem, "-out", $out_utf8,
 is(cmp_text($out_utf8, $utf),
    0, 'Comparing utf8 output with cyrillic.utf8');
 
+SKIP: {
+    skip "EdDSA disabled", 2 if disabled("ecx");
+
+    $pem = srctop_file(@certs, "tab-in-dn.pem");
+    my $out_text = "out-tab-in-dn.text";
+    my $text = srctop_file(@certs, "tab-in-dn.text");
+    ok(run(app(["openssl", "x509", "-text", "-noout",
+            "-in", $pem, "-out", $out_text])));
+    is(cmp_text($out_text, $text),
+       0, 'Comparing default output with tab-in-dn.text');
+}
+
 SKIP: {
     skip "DES disabled", 1 if disabled("des");
     skip "Platform doesn't support command line UTF-8", 1 if $^O =~ /^(VMS|msys)$/;