Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial RFC 5280 test cases #7

Merged
merged 28 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
20a0b17
assets: fix issuers
woodruffw Jun 15, 2023
da7ea44
limbo: begin work on 5280 testcases
woodruffw Jun 20, 2023
43d1e41
Merge remote-tracking branch 'origin/main' into rfc5280
woodruffw Jun 20, 2023
4e1fa79
reformat, linting
woodruffw Jun 20, 2023
79ec0e5
cleanup
woodruffw Jun 22, 2023
01b3544
limbo: add a stub webpki mod
woodruffw Jun 22, 2023
70479da
testcases/rfc5280: critical aki, unknown ext
tnytown Jun 30, 2023
28a073c
Merge remote-tracking branch 'origin/main' into rfc5280
tnytown Jun 30, 2023
439855b
limbo: replace `v3_root_ca`, more rfc5280 tests
tnytown Jul 6, 2023
43b43c5
Merge remote-tracking branch 'origin/main' into rfc5280
tnytown Jul 6, 2023
d0c24a7
limbo.json: regenerate
tnytown Jul 6, 2023
d30d511
limbo: AKI, SAN test cases
tnytown Jul 6, 2023
79a198a
Merge remote-tracking branch 'origin/main' into rfc5280
tnytown Jul 6, 2023
512cbe9
limbo: conform to CA/B on partial wildcards
tnytown Jul 6, 2023
d6ba2ef
Update limbo/testcases/webpki.py
tnytown Jul 7, 2023
cb0be5f
gocryptox509: implement skipping
tnytown Jul 7, 2023
8ce9927
limbo: rework `Builder.intermediate_ca`
tnytown Jul 10, 2023
5683e35
webpki: `cryptography.io` chain happy path test
tnytown Jul 10, 2023
e8e873e
Merge remote-tracking branch 'origin/main' into rfc5280
tnytown Jul 10, 2023
1be4eb0
gocryptox509: squash bug with ExpectedResult
tnytown Jul 10, 2023
8b745af
`make reformat`
tnytown Jul 10, 2023
c1cd565
webpki: negative `cryptography.io` case
tnytown Jul 10, 2023
6d2a416
assets: cryptography.io.cer -> cryptography.io.pem
tnytown Jul 10, 2023
3b7c6f5
webpki: chain of pain case
tnytown Jul 11, 2023
c8722d7
webpki: `chain_untrusted_root`
tnytown Jul 11, 2023
7f1731d
`make reformat`
tnytown Jul 11, 2023
2ff083d
limbo: use `importlib.resources` for `_assets`
tnytown Jul 11, 2023
809f5d0
`make reformat`
tnytown Jul 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/test-harness.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test-harness

on:
push:
branches:
- main
pull_request:

jobs:
test-gocryptox509:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: ">=1.20.5"

- name: run tests
run: make test-go
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ limbo.json: $(NEEDS_VENV)
.PHONY: testcases
testcases: $(NEEDS_VENV)
$(MAKE) run ARGS="compile --testcases testcases/ --force"

.PHONY: test-go
test-go:
$(MAKE) -C harness/gocryptox509 run
10 changes: 10 additions & 0 deletions harness/gocryptox509/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: all
all:
@echo "Run my targets individually!"

.PHONY: run
run:
go run .

schema.go: ../../limbo-schema.json
go generate
8 changes: 8 additions & 0 deletions harness/gocryptox509/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/x509-limbo/harness/gocryptox509

go 1.20

require (
github.com/davecgh/go-spew v1.1.1
github.com/pkg/errors v0.9.1
)
4 changes: 4 additions & 0 deletions harness/gocryptox509/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
116 changes: 116 additions & 0 deletions harness/gocryptox509/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package main

//go:generate go run github.com/atombender/go-jsonschema/cmd/gojsonschema@latest -v -p main -o schema.go ../../limbo-schema.json

import (
"bytes"
"crypto/x509"
"encoding/json"
"encoding/pem"
"flag"
"fmt"
"io/ioutil"
"os"
"time"

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
)

func main() {
testCasePath := flag.String("testcases", "../../limbo.json", "testcases")
flag.Parse()

testcases, err := loadTestcases(*testCasePath)
if err != nil {
panic(err)
}
fmt.Printf("Loaded testcases from %s\n", *testCasePath)

var success, fail int
for _, tc := range testcases.Testcases {
fmt.Printf("test id=%s ... ", tc.Id)
if err := evaluateTestcase(tc); err != nil {
fmt.Printf("fail\n\n%+#v\n\nTest description:\n\n%s\n", err, tc.Description)
fail++
} else {
fmt.Printf("ok\n")
success++
}
}

fmt.Printf("done! succeeded/failed/total %d/%d/%d.\n", success, fail, len(testcases.Testcases))
if fail > 0 {
os.Exit(1)
}
}

func loadTestcases(path string) (testcases LimboSchemaJson, err error) {
contents, err := ioutil.ReadFile(path)
if err != nil {
return
}

err = json.Unmarshal(contents, &testcases)
return
}

func concatPEMCerts(certs []string) []byte {
var buf bytes.Buffer
for _, cert := range certs {
buf.WriteString(cert)
}
return buf.Bytes()
}

const (
validationKindClient = "CLIENT"
validationKindServer = "SERVER"

resultSuccess = "SUCCESS"
resultFailure = "FAILURE"
)

func evaluateTestcase(testcase Testcase) error {
_ = spew.Dump
ts := time.Now()
expectSuccess := testcase.ExpectedResult == resultSuccess

switch testcase.ValidationKind {
case validationKindClient:
roots, intermediates := x509.NewCertPool(), x509.NewCertPool()
roots.AppendCertsFromPEM(concatPEMCerts(testcase.TrustedCerts))
intermediates.AppendCertsFromPEM(concatPEMCerts(testcase.UntrustedIntermediates))

peerAsPEM, rest := pem.Decode([]byte(testcase.PeerCertificate))
if peerAsPEM == nil || peerAsPEM.Type != "CERTIFICATE" {
return fmt.Errorf("unexpected data, expected cert: %+#v", *peerAsPEM)
} else if len(rest) > 0 {
return fmt.Errorf("peer certificate has %d trailing bytes", len(rest))
}

peer, err := x509.ParseCertificate(peerAsPEM.Bytes)
if err != nil {
return errors.Wrap(err, "unable to parse ASN1 certificate from PEM")
}

opts := x509.VerifyOptions{
Intermediates: intermediates,
Roots: roots,
CurrentTime: ts,
KeyUsages: nil,
}
chain, err := peer.Verify(opts)
_ = chain

if err != nil && expectSuccess {
return errors.Wrap(err, "validation failed when success was expected")
} else if err == nil && !expectSuccess {
return fmt.Errorf("validation succeeded when failure was expected")
}
case validationKindServer:
return fmt.Errorf("unimplemented validationKindServer")
}

return nil
}
Loading
Loading