Skip to content

Commit a71e8c5

Browse files
committed
Allow empty x509 bundles to be sent in responses
The specification already allows this to happen: https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE_Trust_Domain_and_Bundle.md\#413-keys
1 parent f3ecfcf commit a71e8c5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

v2/bundle/x509bundle/bundle.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ func Read(trustDomain spiffeid.TrustDomain, r io.Reader) (*Bundle, error) {
6363
// blocks.
6464
func Parse(trustDomain spiffeid.TrustDomain, b []byte) (*Bundle, error) {
6565
bundle := New(trustDomain)
66+
if len(b) == 0 {
67+
return bundle, nil
68+
}
69+
6670
certs, err := pemutil.ParseCertificates(b)
6771
if err != nil {
6872
return nil, x509bundleErr.New("cannot parse certificate: %v", err)
6973
}
70-
if len(certs) == 0 {
71-
return nil, x509bundleErr.New("no certificates found")
72-
}
7374
for _, cert := range certs {
7475
bundle.AddX509Authority(cert)
7576
}
@@ -80,13 +81,14 @@ func Parse(trustDomain spiffeid.TrustDomain, b []byte) (*Bundle, error) {
8081
// with no intermediate padding if there are more than one certificate)
8182
func ParseRaw(trustDomain spiffeid.TrustDomain, b []byte) (*Bundle, error) {
8283
bundle := New(trustDomain)
84+
if len(b) == 0 {
85+
return bundle, nil
86+
}
87+
8388
certs, err := x509.ParseCertificates(b)
8489
if err != nil {
8590
return nil, x509bundleErr.New("cannot parse certificate: %v", err)
8691
}
87-
if len(certs) == 0 {
88-
return nil, x509bundleErr.New("no certificates found")
89-
}
9092
for _, cert := range certs {
9193
bundle.AddX509Authority(cert)
9294
}

v2/workloadapi/client.go

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/x509"
66
"errors"
7-
"fmt"
87
"time"
98

109
"github.com/spiffe/go-spiffe/v2/bundle/jwtbundle"
@@ -489,9 +488,6 @@ func parseX509Bundle(spiffeID string, bundle []byte) (*x509bundle.Bundle, error)
489488
if err != nil {
490489
return nil, err
491490
}
492-
if len(certs) == 0 {
493-
return nil, fmt.Errorf("empty X.509 bundle for trust domain %q", td)
494-
}
495491
return x509bundle.FromX509Authorities(td, certs), nil
496492
}
497493

0 commit comments

Comments
 (0)