From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 68BD51FF0C0 for ; Wed, 18 Nov 2026 11:32:33 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id BB52021894; Wed, 18 Nov 2026 11:31:41 +0100 (CET) From: Thomas Ellmenreich To: pve-devel@lists.proxmox.com Subject: [PATCH common v2 11/11] pom parsing: allow for CRLF line ending Date: Wed, 18 Nov 2026 11:31:25 +0100 Message-ID: <20261118103127.165100-12-t.ellmenreich@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118103127.165100-1-t.ellmenreich@proxmox.com> References: <20261118103127.165100-1-t.ellmenreich@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794997890034 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.330 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 537NY4ZYMAKLH76HKZSB5B5B5IAIRMKA X-Message-ID-Hash: 537NY4ZYMAKLH76HKZSB5B5B5IAIRMKA X-MailFrom: t.ellmenreich@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Thomas Ellmenreich X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: According to RFC 7468 CRLF line endings are allowed which means that our functions should support this. We simply replace all CRLF line endings with normal newlines to also produce coherent results. Also add some tests to check that they are accepted as expected. Signed-off-by: Thomas Ellmenreich --- src/PVE/Certificate.pm | 3 +++ test/certificate_utils_test.pl | 8 ++++++++ test/check_pem_test.pl | 18 ++++++++++++++++++ test/pem_to_der_test.pl | 11 +++++++++++ test/split_pem_test.pl | 21 +++++++++++++++++++++ 5 files changed, 61 insertions(+) diff --git a/src/PVE/Certificate.pm b/src/PVE/Certificate.pm index c89c9e2..d400ae7 100644 --- a/src/PVE/Certificate.pm +++ b/src/PVE/Certificate.pm @@ -165,6 +165,7 @@ sub strip_leading_text { sub split_pem { my ($content, %opts) = @_; + $content =~ s/\r\n/\n/g; $content = trim_trailing_space($content); my $footer = $footer_re->($opts{label} // $ANY_LABEL); @@ -176,6 +177,7 @@ sub split_pem { sub check_pem { my ($content, %opts) = @_; + $content =~ s/\r\n/\n/g; my $label = $opts{label} // ($opts{any_label} ? $ANY_LABEL : 'CERTIFICATE'); my $re = __pem_re($label); @@ -211,6 +213,7 @@ sub check_pem { sub pem_to_der { my ($content) = @_; + $content =~ s/\r\n/\n/g; my $header = $header_re->($ANY_LABEL); my $footer = $footer_re->($ANY_LABEL); diff --git a/test/certificate_utils_test.pl b/test/certificate_utils_test.pl index 873a549..915076b 100755 --- a/test/certificate_utils_test.pl +++ b/test/certificate_utils_test.pl @@ -226,6 +226,14 @@ some extra content TG9yZW0gaXBzdW0= +-----END CERTIFICATE-----}, + }, + { + name => "blank line after header", + expected_match => 1, + pem => q{-----BEGIN CERTIFICATE----- + +TG9yZW0gaXBzdW0= -----END CERTIFICATE-----}, }, { diff --git a/test/check_pem_test.pl b/test/check_pem_test.pl index 73e9826..3c939fb 100755 --- a/test/check_pem_test.pl +++ b/test/check_pem_test.pl @@ -238,6 +238,24 @@ TG9yZW0gaXBzdW0= TG9yZW0gaXBzdW0= -----END EC PRIVATE KEY-----} }, + { + expected_success => 1, + name => "chain with crlf line endings", + multiple => 1, + pem => q{-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE----- +} =~ s/\n/\r\n/gr, + expected_result => q{-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE-----}, + }, ]; for my $data ($setup->@*) { diff --git a/test/pem_to_der_test.pl b/test/pem_to_der_test.pl index c35e1f4..debfed3 100755 --- a/test/pem_to_der_test.pl +++ b/test/pem_to_der_test.pl @@ -117,6 +117,17 @@ TG9yZW0gaXBzdW0gMw== }, expected_decoded_result => "Lorem ipsum 1", }, + { + name => "multiple pem crlf line endings", + pem => q{-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0gMQ== +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0gMg== +-----END CERTIFICATE----- +} =~ s/\n/\r\n/gr, + expected_decoded_result => "Lorem ipsum 1", + }, { name => "all in one line", pem => "-----BEGIN CERTIFICATE-----TG9yZW0gaXBzdW0=-----END CERTIFICATE-----", diff --git a/test/split_pem_test.pl b/test/split_pem_test.pl index 02cce94..0e2f6be 100755 --- a/test/split_pem_test.pl +++ b/test/split_pem_test.pl @@ -239,6 +239,27 @@ TG9yZW0gaXBzdW0= -----END LABEL B-----}, ], }, + { + expected_success => 1, + name => "crlf line endings pem", + pem => q{-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE----- +-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE----- +} =~ s/\n/\r\n/gr, + + expected_result => [ + q{-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE----- +}, + q{-----BEGIN CERTIFICATE----- +TG9yZW0gaXBzdW0= +-----END CERTIFICATE-----}, + ], + }, ]; for my $data ($setup->@*) { -- 2.47.3