Skip to contentSkip to conversation

tools/certs: Make print-cert-tbs-hash.sh compatible with recent OpenSSL

PATCH In review Mickaël Salaün 2 participants 4 messages Jul 29, 2024 – Jul 9, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/certs: Make print-cert-tbs-hash.sh compatible with recent OpenSSL

Recent OpenSSL versions (2 or 3) broke the "x509" argument parsing by not handling "-in -" (unlike OpenSSL 1.1):
Could not open file or uri for loading certificate from -: No such file or directory

Avoid this issue and still make this script work with older versions of OpenSSL by using implicit arguments instead.

To hopefully make it more future-proof, apply the same simplifications for other OpenSSL commands.

Cc David Howells <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Eric Snowberg <[email protected]>
Cc Jarkko Sakkinen <[email protected]>
Fixes 58d416351e6d ("tools/certs: Add print-cert-tbs-hash.sh")
---
 tools/certs/print-cert-tbs-hash.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/certs/print-cert-tbs-hash.sh +3 -3
index c93df5387ec9..22bdeec4d286 100755
@@ -54,7 +54,7 @@ RANGE_AND_DIGEST_RE='
 '
 
 RANGE_AND_DIGEST=($(echo "${PEM}" | \
-	openssl asn1parse -in - | \
+	openssl asn1parse | \
 	sed -n -e "${RANGE_AND_DIGEST_RE}"))
 
 if [ "${#RANGE_AND_DIGEST[@]}" != 3 ]; then
@@ -85,7 +85,7 @@ if [ -z "${DIGEST_MATCH}" ]; then
 fi
 
 echo "${PEM}" | \
-	openssl x509 -in - -outform DER | \
+	openssl x509 -outform DER | \
 	dd "bs=1" "skip=${OFFSET}" "count=${END}" "status=none" | \
-	openssl dgst "-${DIGEST_MATCH}" - | \
+	openssl dgst "-${DIGEST_MATCH}" | \
 	awk '{printf "tbs:" $2}'
Signature · 1 line
2.45.2
#1 lore raw

Could someone please take this patch?

Quoted 48 lines · Mickaël Salaün

Recent OpenSSL versions (2 or 3) broke the "x509" argument parsing by not handling "-in -" (unlike OpenSSL 1.1):
Could not open file or uri for loading certificate from -: No such file or directory

Avoid this issue and still make this script work with older versions of OpenSSL by using implicit arguments instead.

To hopefully make it more future-proof, apply the same simplifications for other OpenSSL commands.

Cc David Howells <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Eric Snowberg <[email protected]>
Cc Jarkko Sakkinen <[email protected]>
Fixes 58d416351e6d ("tools/certs: Add print-cert-tbs-hash.sh")
---
 tools/certs/print-cert-tbs-hash.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/certs/print-cert-tbs-hash.sh +3 -3
index c93df5387ec9..22bdeec4d286 100755
@@ -54,7 +54,7 @@ RANGE_AND_DIGEST_RE='
 '
 
 RANGE_AND_DIGEST=($(echo "${PEM}" | \
-	openssl asn1parse -in - | \
+	openssl asn1parse | \
 	sed -n -e "${RANGE_AND_DIGEST_RE}"))
 
 if [ "${#RANGE_AND_DIGEST[@]}" != 3 ]; then
@@ -85,7 +85,7 @@ if [ -z "${DIGEST_MATCH}" ]; then
 fi
 
 echo "${PEM}" | \
-	openssl x509 -in - -outform DER | \
+	openssl x509 -outform DER | \
 	dd "bs=1" "skip=${OFFSET}" "count=${END}" "status=none" | \
-	openssl dgst "-${DIGEST_MATCH}" - | \
+	openssl dgst "-${DIGEST_MATCH}" | \
 	awk '{printf "tbs:" $2}'
Signature · 1 line
2.45.2
#2 lore raw

I can take it but I'd like an Acked-by please.

Quoted 51 lines · Mickaël Salaün

Could someone please take this patch?

Quoted 48 lines · Mickaël Salaün

Recent OpenSSL versions (2 or 3) broke the "x509" argument parsing by not handling "-in -" (unlike OpenSSL 1.1):
Could not open file or uri for loading certificate from -: No such file or directory

Avoid this issue and still make this script work with older versions of OpenSSL by using implicit arguments instead.

To hopefully make it more future-proof, apply the same simplifications for other OpenSSL commands.

Cc David Howells <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Eric Snowberg <[email protected]>
Cc Jarkko Sakkinen <[email protected]>
Fixes 58d416351e6d ("tools/certs: Add print-cert-tbs-hash.sh")
---
 tools/certs/print-cert-tbs-hash.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/certs/print-cert-tbs-hash.sh +3 -3
index c93df5387ec9..22bdeec4d286 100755
@@ -54,7 +54,7 @@ RANGE_AND_DIGEST_RE='
 '
 
 RANGE_AND_DIGEST=($(echo "${PEM}" | \
-	openssl asn1parse -in - | \
+	openssl asn1parse | \
 	sed -n -e "${RANGE_AND_DIGEST_RE}"))
 
 if [ "${#RANGE_AND_DIGEST[@]}" != 3 ]; then
@@ -85,7 +85,7 @@ if [ -z "${DIGEST_MATCH}" ]; then
 fi
 
 echo "${PEM}" | \
-	openssl x509 -in - -outform DER | \
+	openssl x509 -outform DER | \
 	dd "bs=1" "skip=${OFFSET}" "count=${END}" "status=none" | \
-	openssl dgst "-${DIGEST_MATCH}" - | \
+	openssl dgst "-${DIGEST_MATCH}" | \
 	awk '{printf "tbs:" $2}'
Signature · 1 line
2.45.2
maintainer Tested-by
#3 lore raw
Quoted 2 lines · Mickaël Salaün

I can take it but I'd like an Acked-by please.

% openssl -v
OpenSSL 3.5.1 1 Jul 2025 (Library: OpenSSL 3.5.1 1 Jul 2025)

With Linus' current tree:
% ./print-cert-tbs-hash.sh ./LVFS-CA.pem
Could not open file or uri for loading certificate from -: No such file or direc tory tbs:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

With the patch below:
% ./print-cert-tbs-hash.sh ./LVFS-CA.pem tbs:b11d0663606508a8510b760d68acb599f1911726f7c06c01df4d122fce8b957b

Quoted 51 lines · Mickaël Salaün
Quoted 50 lines

Could someone please take this patch?

Quoted 47 lines · Mickaël Salaün

Recent OpenSSL versions (2 or 3) broke the "x509" argument parsing by not handling "-in -" (unlike OpenSSL 1.1):
Could not open file or uri for loading certificate from -: No such file or directory

Avoid this issue and still make this script work with older versions of OpenSSL by using implicit arguments instead.

To hopefully make it more future-proof, apply the same simplifications for other OpenSSL commands.

Cc David Howells <[email protected]>
Cc David Woodhouse <[email protected]>
Cc Eric Snowberg <[email protected]>
Cc Jarkko Sakkinen <[email protected]>
Fixes 58d416351e6d ("tools/certs: Add print-cert-tbs-hash.sh")
---
 tools/certs/print-cert-tbs-hash.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/certs/print-cert-tbs-hash.sh +3 -4
index c93df5387ec9..22bdeec4d286 100755
@@ -54,7 +54,7 @@ RANGE_AND_DIGEST_RE='
 '
 
 RANGE_AND_DIGEST=($(echo "${PEM}" | \
-   openssl asn1parse -in - | \
+   openssl asn1parse | \
    sed -n -e "${RANGE_AND_DIGEST_RE}"))
 
 if [ "${#RANGE_AND_DIGEST[@]}" != 3 ]; then
@@ -85,7 +85,7 @@ if [ -z "${DIGEST_MATCH}" ]; then
 fi
 
 echo "${PEM}" | \
-   openssl x509 -in - -outform DER | \
+   openssl x509 -outform DER | \
    dd "bs=1" "skip=${OFFSET}" "count=${END}" "status=none" | \
-   openssl dgst "-${DIGEST_MATCH}" - | \
+   openssl dgst "-${DIGEST_MATCH}" | \
    awk '{printf "tbs:" $2}'
--

2.45.2

Signature · 1 line
paul-moore.com