Skip to content

Commit

Permalink
fix: modify certificate alternate DNS duplication
Browse files Browse the repository at this point in the history
Signed-off-by: zhj0811 <zhaojian@peerfintech.cn>
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
zhaojianpeerfintech authored and sykesm committed Aug 3, 2020
1 parent 6e97dd0 commit cce8553
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/cryptogen/ca/ca.go
Expand Up @@ -147,7 +147,7 @@ func (ca *CA) SignCertificate(
if ip != nil {
template.IPAddresses = append(template.IPAddresses, ip)
} else {
template.DNSNames = append(template.DNSNames, alternateNames...)
template.DNSNames = append(template.DNSNames, san)
}
}

Expand Down
4 changes: 3 additions & 1 deletion internal/cryptogen/ca/ca_test.go
Expand Up @@ -229,12 +229,14 @@ func TestGenerateSignCertificate(t *testing.T) {
assert.Contains(t, cert.Subject.OrganizationalUnit, ous[1])

// make sure sans are correctly set
sans := []string{testName2, testIP}
sans := []string{testName2, testName3, testIP}
cert, err = rootCA.SignCertificate(certDir, testName, nil, sans, &priv.PublicKey,
x509.KeyUsageDigitalSignature, []x509.ExtKeyUsage{})
assert.NoError(t, err)
assert.Contains(t, cert.DNSNames, testName2)
assert.Contains(t, cert.DNSNames, testName3)
assert.Contains(t, cert.IPAddresses, net.ParseIP(testIP).To4())
assert.Equal(t, len(cert.DNSNames), 2)

// check to make sure the signed public key was stored
pemFile := filepath.Join(certDir, testName+"-cert.pem")
Expand Down

0 comments on commit cce8553

Please sign in to comment.