Skip to content

Commit c85690b

Browse files
committed
Generate fingerprints for CSRs
This commit allows to generate fingerprints for CSR files to the `step certificate fingerprint` command.
1 parent c0af50f commit c85690b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

command/certificate/fingerprint.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func fingerprintCommand() cli.Command {
2424
[**--bundle**] [**--roots**=<root-bundle>] [**--servername**=<servername>]
2525
[**--format**=<format>] [**--sha1**] [**--insecure**]`,
2626
Description: `**step certificate fingerprint** reads a certificate and prints to STDOUT the
27-
certificate SHA256 of the raw certificate.
27+
certificate SHA256 of the raw certificate or certificate signing request.
2828
2929
If <crt-file> contains multiple certificates (i.e., it is a certificate
3030
"bundle") the fingerprint of the first certificate in the bundle will be
@@ -55,6 +55,12 @@ Get the fingerprints for a remote certificate with its intermediate:
5555
$ step certificate fingerprint --bundle https://smallstep.com
5656
e2c4f12edfc1816cc610755d32e6f45d5678ba21ecda1693bb5b246e3c48c03d
5757
25847d668eb4f04fdd40b12b6b0740c567da7d024308eb6c2c96fe41d9de218d
58+
'''
59+
60+
Get the fingerprint for a CSR using base64-url without padding encoding:
61+
'''
62+
$ step certificate fingerprint --format base64-url-raw hello.csr
63+
PJLNhtQoBE1yGN_ZKzr4Y2U5pyqIGiyyszkoz2raDOw
5864
'''`,
5965
Flags: []cli.Flag{
6066
cli.StringFlag{
@@ -128,7 +134,15 @@ func fingerprintAction(ctx *cli.Context) error {
128134
default:
129135
certs, err = pemutil.ReadCertificateBundle(crtFile)
130136
if err != nil {
131-
return err
137+
// Fallback to parse a CSR
138+
csr, csrErr := pemutil.ReadCertificateRequest(crtFile)
139+
if csrErr != nil {
140+
return err
141+
}
142+
// We will only need the raw the generate a fingerprint.
143+
certs = []*x509.Certificate{
144+
{Raw: csr.Raw},
145+
}
132146
}
133147
}
134148

0 commit comments

Comments
 (0)