@@ -36,13 +36,14 @@ import (
3636 "crypto/tls"
3737 "crypto/x509"
3838 "encoding/pem"
39- "fmt"
40- "github.com/Sirupsen/logrus"
4139 "io/ioutil"
4240 "os"
4341 "path/filepath"
4442 "strings"
4543 "time"
44+
45+ "github.com/Sirupsen/logrus"
46+ "github.com/pkg/errors"
4647)
4748
4849type CertCache struct {
@@ -113,19 +114,19 @@ func (c *CertCache) readAndValidateCertificate(key string, hosts []string, now t
113114 }
114115 }
115116 if certDerBytes == nil {
116- return nil , fmt .Errorf ("No valid certificate contained in %s" , path )
117+ return nil , errors .Errorf ("no valid certificate contained in %s" , path )
117118 }
118119 x509Cert , err := x509 .ParseCertificate (certDerBytes )
119120 if err != nil {
120- return nil , fmt . Errorf ( "Invalid certificate found in %s (%s) " , path , err . Error () )
121+ return nil , errors . Wrapf ( err , "invalid certificate found in %s" , path )
121122 }
122123 x509Cert .RawIssuer = c .issuerCert .Raw
123124 err = x509Cert .CheckSignatureFrom (c .issuerCert )
124125 if err != nil {
125- return nil , fmt . Errorf ( "Invalid certificate found in %s (%s) " , path , err . Error () )
126+ return nil , errors . Wrapf ( err , "invalid certificate found in %s" , path )
126127 }
127128 if ! now .Before (x509Cert .NotAfter ) {
128- return nil , fmt .Errorf ("Ceritificate no longer valid (not after: %s, now: %s)" , x509Cert .NotAfter .Local ().Format (time .RFC1123 ), now .Local ().Format (time .RFC1123 ))
129+ return nil , errors .Errorf ("ceritificate no longer valid (not after: %s, now: %s)" , x509Cert .NotAfter .Local ().Format (time .RFC1123 ), now .Local ().Format (time .RFC1123 ))
129130 }
130131
131132outer:
@@ -135,7 +136,7 @@ outer:
135136 break outer
136137 }
137138 }
138- return nil , fmt .Errorf ("Certificate does not cover the host name %s" , a )
139+ return nil , errors .Errorf ("certificate does not cover the host name %s" , a )
139140 }
140141
141142 return & tls.Certificate {
0 commit comments