wofr06 / lesspipe

lesspipe - display more with less
GNU General Public License v2.0
484 stars 51 forks source link

pem files handling hides certificates #159

Closed arekm closed 3 weeks ago

arekm commented 3 weeks ago

If a .pem file contains multiple certificates and also private certificates like:

-----BEGIN CERTIFICATE-----
MIIDX...
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIDX...
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIDXT...
...
-----END CERTIFICATE-----
-----BEGIN PRIVATE KEY-----
MIIE...
...
-----END PRIVATE KEY-----

then lesspipe (looking at 2.14) makes that only first certificate is being displayed thus hiding the fact that there are other certificates in the file. That's very misleading.

Some other solution would be welcome like

cat a.pem | awk 'BEGIN {RS=""; FS="\n"}
  {
    for (i=1; i<=NF; i++) {
      if ($i ~ /-----BEGIN CERTIFICATE-----/) {
        print $0 | "openssl x509 -text -noout"
      }
      if ($i ~ /-----BEGIN PRIVATE KEY-----/ || $i ~ /-----BEGIN RSA PRIVATE KEY-----/) {
        print $0 | "openssl pkey -text -noout"
      }
    }
  }'

if that can be integrated into the way lesspipe is made.

wofr06 commented 3 weeks ago

I solved it differently. openssl has a command storeutl precisely for that. Did not know that up to now.