Skip to content

Commit

Permalink
Fix certificate error detection on Go 1.20 and 1.21.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomclegg committed Dec 1, 2023
1 parent a004c57 commit a1a8ab8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
14 changes: 14 additions & 0 deletions cert_error_go119.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build !go1.20
// +build !go1.20

package retryablehttp

import "crypto/x509"

func isCertError(err error) bool {
_, ok := err.(x509.UnknownAuthorityError)
return ok
}
14 changes: 14 additions & 0 deletions cert_error_go120.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build go1.20
// +build go1.20

package retryablehttp

import "crypto/tls"

func isCertError(err error) bool {
_, ok := err.(*tls.CertificateVerificationError)
return ok
}
3 changes: 1 addition & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package retryablehttp
import (
"bytes"
"context"
"crypto/x509"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -508,7 +507,7 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
if notTrustedErrorRe.MatchString(v.Error()) {
return false, v
}
if _, ok := v.Err.(x509.UnknownAuthorityError); ok {
if isCertError(v.Err) {
return false, v
}
}
Expand Down

0 comments on commit a1a8ab8

Please sign in to comment.