Skip to content

Commit 60fe4b3

Browse files
authored
Merge pull request #6 from quix-labs/dev
fix: do not ignore fetch_full_chain
2 parents a5870fc + 214de01 commit 60fe4b3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ caddy
44
out
55
dist/
66
/build
7-
test.pfx
7+
*.pfx

module.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (getter *PfxCertGetter) GetCertificate(ctx context.Context, hello *tls.Clie
7676
storage := getter.ctx.Storage()
7777

7878
if !storage.Exists(ctx, getter.CacheCertName) {
79-
err := getter.GenerateParsedKeys(ctx)
79+
err := getter.GenerateFullPEM(ctx)
8080
if err != nil {
8181
getter.logger.Error("failed to decode pfx certificate", zap.Error(err))
8282
return nil, err
@@ -180,7 +180,7 @@ func (getter *PfxCertGetter) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
180180
return nil
181181
}
182182

183-
func (getter *PfxCertGetter) GenerateParsedKeys(ctx context.Context) error {
183+
func (getter *PfxCertGetter) GenerateFullPEM(ctx context.Context) error {
184184
storage := getter.ctx.Storage()
185185

186186
// Read the PFX file
@@ -204,10 +204,13 @@ func (getter *PfxCertGetter) GenerateParsedKeys(ctx context.Context) error {
204204
Bytes: x509.MarshalPKCS1PrivateKey(privateKey.(*rsa.PrivateKey)),
205205
})...)
206206

207-
// Combine leaf and intermediates from PFX and fetch the full chain automatically
208-
chain, err := getCertificateChain(append([]*x509.Certificate{certificate}, caCerts...))
209-
if err != nil {
210-
return err
207+
// Combine leaf and intermediates from PFX
208+
chain := append([]*x509.Certificate{certificate}, caCerts...)
209+
if *getter.FetchFullChain {
210+
// Fetch the full chain automatically is certificates missing
211+
if chain, err = getCertificateChain(chain); err != nil {
212+
return err
213+
}
211214
}
212215

213216
// Append all certificates

0 commit comments

Comments
 (0)