Skip to content

Commit

Permalink
Merge pull request #16 from rchincha/tls
Browse files Browse the repository at this point in the history
tls: harden TLS path
  • Loading branch information
rchincha authored Aug 27, 2019
2 parents d8cde53 + b6a0077 commit ae6651a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ var (
ErrBadBlob = errors.New("blob: bad blob")
ErrBadBlobDigest = errors.New("blob: bad blob digest")
ErrUnknownCode = errors.New("error: unknown error code")
ErrBadCACert = errors.New("tls: invalid ca cert")
)
12 changes: 9 additions & 3 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"

"github.com/anuvu/zot/errors"
"github.com/anuvu/zot/pkg/storage"
"github.com/gorilla/mux"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -56,11 +57,16 @@ func (c *Controller) Run() error {
panic(err)
}
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
if !caCertPool.AppendCertsFromPEM(caCert) {
panic(errors.ErrBadCACert)
}
server.TLSConfig = &tls.Config{
ClientAuth: clientAuth,
ClientCAs: caCertPool,
ClientAuth: clientAuth,
ClientCAs: caCertPool,
PreferServerCipherSuites: true,
MinVersion: tls.VersionTLS12,
}
server.TLSConfig.BuildNameToCertificate()
}

return server.ServeTLS(l, c.Config.HTTP.TLS.Cert, c.Config.HTTP.TLS.Key)
Expand Down

0 comments on commit ae6651a

Please sign in to comment.