Skip to content

Commit

Permalink
Merge pull request choria-legacy#14 from vjanelle/intermediate_client…
Browse files Browse the repository at this point in the history
…_certs

(choria-legacy#13) Add intermediate client certificate support
  • Loading branch information
ripienaar authored Nov 12, 2018
2 parents 59996c6 + 8a6539a commit 64e0a0d
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 0 deletions.
8 changes: 8 additions & 0 deletions filesec/file_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,16 @@ func (s *FileSecurity) VerifyCertificate(certpem []byte, name string) error {
return err
}

intermediates := x509.NewCertPool()
if !intermediates.AppendCertsFromPEM(certpem) {
s.log.Warnf("Could not add intermediates: %s", err)
return err
}

opts := x509.VerifyOptions{
Roots: roots,
Intermediates: intermediates,
KeyUsages: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth},
}

if name != "" {
Expand Down
17 changes: 17 additions & 0 deletions filesec/file_security_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,23 @@ var _ = Describe("FileSSL", func() {
err := prov.VerifyCertificate(pem, "rip.mcollective")
Expect(err).ToNot(HaveOccurred())
})

It("Should work with client provided intermediate chains", func() {
c, err := config.NewDefaultConfig()
Expect(err).ToNot(HaveOccurred())

c.Choria.FileSecurityCA = filepath.Join("..", "testdata", "intermediate", "certs", "ca.pem")
c.Choria.FileSecurityCache = filepath.Join("..", "testdata", "intermediate", "certs")

prov, err := New(WithChoriaConfig(c), WithLog(l.WithFields(logrus.Fields{})))
Expect(err).ToNot(HaveOccurred())

pem, err = ioutil.ReadFile(filepath.Join("..", "testdata", "intermediate", "certs", "rip.mcollective.pem"))
Expect(err).ToNot(HaveOccurred())

err = prov.VerifyCertificate(pem, "rip.mcollective")
Expect(err).ToNot(HaveOccurred())
})
})

Describe("PublicCertPem", func() {
Expand Down
6 changes: 6 additions & 0 deletions testdata/intermediate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Intermediate certs
---

Requires `cfssl` and friends. Install them from https://github.com/cloudflare/cfssl

Run the Makefile to regenerate the CA, intermediate CA, and the chained cert. This test does not currently need the private keys around.
14 changes: 14 additions & 0 deletions testdata/intermediate/certs/ca.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-----BEGIN CERTIFICATE-----
MIICOTCCAd+gAwIBAgIUHcItm2WcJQd0By9Sg5Wqlt0sONIwCgYIKoZIzj0EAwIw
eTELMAkGA1UEBhMCWFgxETAPBgNVBAgTCExvY2FsaXR5MQ0wCwYDVQQHEwRDaXR5
MQ8wDQYDVQQKEwZDaG9yaWExJTAjBgNVBAsTHFVuaXQgdGVzdGluZyBJbnRlcm1l
ZGlhdGUgQ0ExEDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTgxMTExMjEzMDAwWhcNNDgx
MTAzMjEzMDAwWjB5MQswCQYDVQQGEwJYWDERMA8GA1UECBMITG9jYWxpdHkxDTAL
BgNVBAcTBENpdHkxDzANBgNVBAoTBkNob3JpYTElMCMGA1UECxMcVW5pdCB0ZXN0
aW5nIEludGVybWVkaWF0ZSBDQTEQMA4GA1UEAxMHUm9vdCBDQTBZMBMGByqGSM49
AgEGCCqGSM49AwEHA0IABPt/emjXdaHwnClOeT4qCjjPgOy8P5+sWwkV7UvWqDGW
YozFo0J9Sy5zBDAEdw6vmFA9F1yqx4Huuip4M/yF6USjRTBDMA4GA1UdDwEB/wQE
AwIBBjASBgNVHRMBAf8ECDAGAQH/AgEBMB0GA1UdDgQWBBRT2Qng+4kiaIILKMQ1
n9xNF5Rj3DAKBggqhkjOPQQDAgNIADBFAiEA+4RpvLfS0zX5T/uPXr2vHX7Ws78J
P/EyAiAYha39SNwCIDuRVsoTy72UtQdSkUAhslporEUNkNtbphynP3DaLZdd
-----END CERTIFICATE-----
34 changes: 34 additions & 0 deletions testdata/intermediate/certs/rip.mcollective.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-----BEGIN CERTIFICATE-----
MIIDBjCCAqygAwIBAgIUVH5ROCpcZSA1u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-----
MIICYzCCAgmgAwIBAgIUM0jKjSKTjq5eO7N1jAHG+pVH3FUwCgYIKoZIzj0EAwIw
eTELMAkGA1UEBhMCWFgxETAPBgNVBAgTCExvY2FsaXR5MQ0wCwYDVQQHEwRDaXR5
MQ8wDQYDVQQKEwZDaG9yaWExJTAjBgNVBAsTHFVuaXQgdGVzdGluZyBJbnRlcm1l
ZGlhdGUgQ0ExEDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTgxMTExMjEzMDAwWhcNNDgx
MTAzMjEzMDAwWjCBgTELMAkGA1UEBhMCWFgxETAPBgNVBAgTCExvY2FsaXR5MQ0w
CwYDVQQHEwRDaXR5MQ8wDQYDVQQKEwZDaG9yaWExJTAjBgNVBAsTHFVuaXQgdGVz
dGluZyBJbnRlcm1lZGlhdGUgQ0ExGDAWBgNVBAMTD0ludGVybWVkaWF0ZSBDQTBZ
MBMGByqGSM49AgEGCCqGSM49AwEHA0IABLrrCCE1cvyKEHwmmKu5x2/eCnR8Qgkk
/TGi3eygp671u0G9kZOy2MdvgCecHCF/zR/YUPozEILZE9QldXVQWg+jZjBkMA4G
A1UdDwEB/wQEAwIBpjASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBTE9RmI
wQ7C2pfp37E4djWmkQrMyzAfBgNVHSMEGDAWgBRT2Qng+4kiaIILKMQ1n9xNF5Rj
3DAKBggqhkjOPQQDAgNIADBFAiEAtH7hxZ7QcPlFnM+YJuptChhGox7fSwwPbnyH
z7YMKygCIGn4lC2hIXRTk9FHPPCcZSPi8bJ9j5ZgKJO08xh3UGkb
-----END CERTIFICATE-----
36 changes: 36 additions & 0 deletions testdata/intermediate/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"signing": {
"default": {
"expiry": "262800h"
},
"profiles": {
"ca-to-root": {
"usages": [
"signing",
"key encipherment",
"cert sign",
"crl sign"
],
"ca_constraint": {"is_ca": true, "max_path_len":0, "max_path_len_zero": true},
"expiry": "262800h"
},
"client": {
"usages": [
"client auth",
"key encipherment",
"digital signature"
],
"expiry": "262800h"
},
"server": {
"usages": [
"server auth",
"client auth",
"key encipherment",
"digital signature"
],
"expiry": "262800h"
}
}
}
}
10 changes: 10 additions & 0 deletions testdata/intermediate/csr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosts": [
"rip.mcollective"
],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [ ]
}
20 changes: 20 additions & 0 deletions testdata/intermediate/intermediate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"CN": "Intermediate CA",
"key": {
"algo": "ecdsa",
"size": 256
},
"ca": {
"expiry": "262800h",
"pathlen": 0
},
"names": [
{
"C": "XX",
"L": "City",
"O": "Choria",
"OU": "Unit testing Intermediate CA",
"ST": "Locality"
}
]
}
20 changes: 20 additions & 0 deletions testdata/intermediate/root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"CN": "Root CA",
"key": {
"algo": "ecdsa",
"size": 256
},
"ca": {
"expiry": "262800h",
"pathlen": 1
},
"names": [
{
"C": "XX",
"L": "City",
"O": "Choria",
"OU": "Unit testing Intermediate CA",
"ST": "Locality"
}
]
}
4 changes: 4 additions & 0 deletions testdata/intermediate/subject.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"CN": "rip.mcollective",
"names": []
}

0 comments on commit 64e0a0d

Please sign in to comment.