1
1
package kube
2
2
3
3
import (
4
- "errors"
5
4
"fmt"
6
5
"io"
7
6
@@ -16,8 +15,6 @@ import (
16
15
17
16
// in case of local kube config
18
17
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
19
-
20
- "github.com/utilitywarehouse/semaphore-wireguard/log"
21
18
)
22
19
23
20
type certMan struct {
@@ -26,21 +23,24 @@ type certMan struct {
26
23
27
24
func (cm * certMan ) verifyConn (cs tls.ConnectionState ) error {
28
25
resp , err := http .Get (cm .caURL )
26
+ if err != nil {
27
+ return fmt .Errorf ("error getting remote CA from %s: %v" , cm .caURL , err )
28
+ }
29
29
defer func () {
30
30
io .Copy (ioutil .Discard , resp .Body )
31
31
resp .Body .Close ()
32
32
}()
33
- if err != nil {
34
- log .Logger .Error (
35
- "error getting remote CA" ,
36
- "err" , err )
37
- return err
33
+ if resp .StatusCode != http .StatusOK {
34
+ return fmt .Errorf ("expected %d response from %s, got %d" , http .StatusOK , cm .caURL , resp .StatusCode )
38
35
}
39
36
body , err := ioutil .ReadAll (resp .Body )
37
+ if err != nil {
38
+ return fmt .Errorf ("error reading response body from %s: %v" , cm .caURL , err )
39
+ }
40
40
roots := x509 .NewCertPool ()
41
41
ok := roots .AppendCertsFromPEM (body )
42
42
if ! ok {
43
- return errors . New ("failed to parse root certificate" )
43
+ return fmt . Errorf ("failed to parse root certificate from %s" , cm . caURL )
44
44
}
45
45
opts := x509.VerifyOptions {
46
46
DNSName : cs .ServerName ,
0 commit comments