all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pve-devel@lists.proxmox.com,
	Thomas Ellmenreich <t.ellmenreich@proxmox.com>
Subject: Re: [PATCH proxmox-acme 2/2] fix #5978: pem parser: relax parsing of chain entries:
Date: Mon, 15 Jun 2026 13:34:36 +0200	[thread overview]
Message-ID: <1781517444.kty0u965x5.astroid@yuna.none> (raw)
In-Reply-To: <20260609131549.104216-3-t.ellmenreich@proxmox.com>

On June 9, 2026 3:15 pm, Thomas Ellmenreich wrote:
> Instead of using a custom regex to parse pem chains, now uses
> the pve-common Certificate::check_pem function to do so. This
> now allows for additional text and whitespace inbetween the
> chain entries.
> 
> Signed-off-by: Thomas Ellmenreich <t.ellmenreich@proxmox.com>
> ---
>  src/PVE/ACME.pm | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/src/PVE/ACME.pm b/src/PVE/ACME.pm
> index e6fb9c2..ff10c22 100644
> --- a/src/PVE/ACME.pm
> +++ b/src/PVE/ACME.pm
> @@ -530,9 +530,11 @@ sub get_certificate {
>                  if !defined($res);
>          }
>  
> -        if ($res =~ /^(-----BEGIN CERTIFICATE-----)(.+)(-----END CERTIFICATE-----)$/s) { # untaint
> -            return $1 . $2 . $3;
> -        }
> +        my $checked = PVE::Certificate::check_pem->($res, no_err => 1);

no_err is actually noerr in PVE::Certificate, so setting it this way has
no effect. but I don't think we need to set it here at all, we can
simply do

return PVE::Certificate::check_pem($res);

it will either die (with a hopefully meaningful error), or return the
cleaned up PEM data.

if you want to customize the error message, something like

my $res = eval { ... };
die "Server reply does not look like a PEM encoded certificate: $@\n"
  if $@;

return $res;

would be a common pattern we use in our code. eval {} is similar to
try/catch in other languages, if the code in the body dies with a fatal
error, it is stored in $@ which can be checked after.

setting noerr is usually reserved for parsing where an error is not
fatal. e.g. if we wanted to parse the data here with multiple possible
labels, we might set noerr for each attempt and only die with an error
if we find no label.

> +        if (defined $checked) {
> +            return $checked;
> +        } 

nit the last line here has trailing whitespace (you can configure your
editor or git to make this more obvious, e.g. mark it as red)

> +
>          die "Server reply does not look like a PEM encoded certificate\n";
>      };
>      $self->fatal("POST of '$order->{certificate}' failed - $@", $r) if $@;
> -- 
> 2.47.3
> 
> 
> 
> 
> 
> 




      reply	other threads:[~2026-06-15 11:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-09 13:15 [PATCH common/proxmox-acme 0/2] fix #5978: pem parser: relax parsing of chain entries Thomas Ellmenreich
2026-06-09 13:15 ` [PATCH common 1/2] fix #5978: pem parser: relax parsing of chain entries: Thomas Ellmenreich
2026-06-15 11:34   ` Fabian Grünbichler
2026-06-09 13:15 ` [PATCH proxmox-acme 2/2] " Thomas Ellmenreich
2026-06-15 11:34   ` Fabian Grünbichler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1781517444.kty0u965x5.astroid@yuna.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=t.ellmenreich@proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal