Skip to content

Commit f623ace

Browse files
committed
Fixes issue in SNI getter for IP certificates.
If no ip certificate is defined on the authority it would result in a panic from the function for accessing nil memory.
1 parent 90ca89f commit f623ace

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

pki/tls/sni.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ func AuthoritySNITLSGetter(authority pki.Authority, logger Logger) func(*tls.Cli
3030
if hello.ServerName == "" {
3131
logger.Debugf("tls client hello server name is empty. Attempting to provide ip address certificate")
3232
leaf, err := authority.LeafForGroup(pki.ControllerIPLeafGroup)
33-
if err != nil && !errors.IsNotFound(err) {
33+
if err == nil {
34+
cert = leaf.TLSCertificate()
35+
} else if !errors.IsNotFound(err) {
3436
return nil, errors.Annotate(err, "fetching ip address certificate")
3537
}
36-
cert = leaf.TLSCertificate()
3738
} else {
3839
authority.LeafRange(func(leaf pki.Leaf) bool {
3940
if err := hello.SupportsCertificate(leaf.TLSCertificate()); err == nil {

pki/tls/sni_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type SNISuite struct {
2323

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

26-
func (s *SNISuite) SetUpSuite(c *gc.C) {
26+
func (s *SNISuite) SetUpTest(c *gc.C) {
2727
pki.DefaultKeyProfile = pkitest.OriginalDefaultKeyProfile
2828
authority, err := pkitest.NewTestAuthority()
2929
c.Assert(err, jc.ErrorIsNil)
@@ -119,3 +119,21 @@ func (s *SNISuite) TestAuthorityTLSGetter(c *gc.C) {
119119
TLSCertificatesEqual(c, cert, leaf.TLSCertificate())
120120
}
121121
}
122+
123+
func (s *SNISuite) TestNonExistantIPLeafReturnsDefault(c *gc.C) {
124+
leaf, err := s.authority.LeafRequestForGroup(pki.DefaultLeafGroup).
125+
AddDNSNames("juju-app").
126+
Commit()
127+
c.Assert(err, jc.ErrorIsNil)
128+
129+
helloRequest := &tls.ClientHelloInfo{
130+
ServerName: "",
131+
SignatureSchemes: []tls.SignatureScheme{tls.PSSWithSHA256},
132+
SupportedVersions: []uint16{tls.VersionTLS13, tls.VersionTLS12},
133+
}
134+
135+
cert, err := s.sniGetter(helloRequest)
136+
c.Assert(err, jc.ErrorIsNil)
137+
138+
TLSCertificatesEqual(c, cert, leaf.TLSCertificate())
139+
}

0 commit comments

Comments
 (0)