Skip to content

Commit

Permalink
Merge remote-tracking branch 'juju/2.8' into 2.8-to-2.9-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tlm committed May 14, 2021
2 parents 55387eb + 2b95011 commit 1d4a5ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pki/tls/sni.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ func AuthoritySNITLSGetter(authority pki.Authority, logger Logger) func(*tls.Cli
if hello.ServerName == "" {
logger.Debugf("tls client hello server name is empty. Attempting to provide ip address certificate")
leaf, err := authority.LeafForGroup(pki.ControllerIPLeafGroup)
if err != nil && !errors.IsNotFound(err) {
if err == nil {
cert = leaf.TLSCertificate()
} else if !errors.IsNotFound(err) {
return nil, errors.Annotate(err, "fetching ip address certificate")
}
cert = leaf.TLSCertificate()
} else {
authority.LeafRange(func(leaf pki.Leaf) bool {
if err := hello.SupportsCertificate(leaf.TLSCertificate()); err == nil {
Expand Down
20 changes: 19 additions & 1 deletion pki/tls/sni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SNISuite struct {

var _ = gc.Suite(&SNISuite{})

func (s *SNISuite) SetUpSuite(c *gc.C) {
func (s *SNISuite) SetUpTest(c *gc.C) {
pki.DefaultKeyProfile = pkitest.OriginalDefaultKeyProfile
authority, err := pkitest.NewTestAuthority()
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -119,3 +119,21 @@ func (s *SNISuite) TestAuthorityTLSGetter(c *gc.C) {
TLSCertificatesEqual(c, cert, leaf.TLSCertificate())
}
}

func (s *SNISuite) TestNonExistantIPLeafReturnsDefault(c *gc.C) {
leaf, err := s.authority.LeafRequestForGroup(pki.DefaultLeafGroup).
AddDNSNames("juju-app").
Commit()
c.Assert(err, jc.ErrorIsNil)

helloRequest := &tls.ClientHelloInfo{
ServerName: "",
SignatureSchemes: []tls.SignatureScheme{tls.PSSWithSHA256},
SupportedVersions: []uint16{tls.VersionTLS13, tls.VersionTLS12},
}

cert, err := s.sniGetter(helloRequest)
c.Assert(err, jc.ErrorIsNil)

TLSCertificatesEqual(c, cert, leaf.TLSCertificate())
}

0 comments on commit 1d4a5ac

Please sign in to comment.