Skip to content

Commit 9deaefb

Browse files
committed
feat: support binary and pem encoded crl files
See merge request https://ref.ci/fsrvcorp/pki/ocspcrl/-/merge_requests/2
2 parents c373fd7 + 6f18548 commit 9deaefb

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

main.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"bytes"
45
"crypto/tls"
56
"crypto/x509"
67
"encoding/pem"
@@ -26,11 +27,21 @@ func loadCrlFromFile(path string) (*x509.RevocationList, error) {
2627
if openCrlError != nil {
2728
return nil, openCrlError
2829
}
29-
block, rest := pem.Decode(crlContent)
30-
if len(rest) > 0 {
31-
return nil, fmt.Errorf("failed to decode crl")
30+
31+
// if the file contains a pem block, decode it
32+
// otherwise, assume it is a DER encoded CRL
33+
crlBlock := &pem.Block{}
34+
if bytes.Contains(crlContent, []byte("BEGIN")) {
35+
block, rest := pem.Decode(crlContent)
36+
if len(rest) > 0 {
37+
return nil, fmt.Errorf("failed to decode crl")
38+
}
39+
crlBlock = block
40+
} else {
41+
crlBlock = &pem.Block{Type: "X509 CRL", Bytes: crlContent}
3242
}
33-
crl, parseCrlError := x509.ParseRevocationList(block.Bytes)
43+
44+
crl, parseCrlError := x509.ParseRevocationList(crlBlock.Bytes)
3445
if parseCrlError != nil {
3546
return nil, parseCrlError
3647
}

0 commit comments

Comments
 (0)