-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathverify_test.go
More file actions
65 lines (53 loc) · 1.69 KB
/
Copy pathverify_test.go
File metadata and controls
65 lines (53 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package tls
import (
"crypto/ed25519"
"crypto/x509"
"testing"
"github.com/stretchr/testify/require"
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature/signers/memory"
)
func TestVerifyCertificate(t *testing.T) {
require := require.New(t)
cert, err := Generate("my-common-name")
require.NoError(err, "Generate")
signer := memory.NewFromRuntime(cert.PrivateKey.(ed25519.PrivateKey))
signer2 := memory.NewTestSigner("common/crypto/tls: test signer")
certs := make([]*x509.Certificate, 0)
for _, der := range cert.Certificate {
c, err := x509.ParseCertificate(der)
require.NoError(err, "ParseCertificate")
certs = append(certs, c)
}
err = VerifyCertificates(certs, VerifyOptions{
CommonName: "my-common-name",
Keys: map[signature.PublicKey]bool{
signer.Public(): true,
},
})
require.NoError(err, "VerifyCertificate")
err = VerifyCertificates(certs, VerifyOptions{
CommonName: "my-common-name",
AllowUnknownKeys: true,
})
require.NoError(err, "VerifyCertificate")
err = VerifyCertificates(nil, VerifyOptions{
CommonName: "my-common-name",
AllowNoCertificate: true,
})
require.NoError(err, "VerifyCertificate")
err = VerifyCertificates(certs, VerifyOptions{
CommonName: "other-common-name",
Keys: map[signature.PublicKey]bool{
signer.Public(): true,
},
})
require.Error(err, "VerifyCertificate should fail with mismatched common name")
err = VerifyCertificates(certs, VerifyOptions{
CommonName: "my-common-name",
Keys: map[signature.PublicKey]bool{
signer2.Public(): true,
},
})
require.Error(err, "VerifyCertificate should fail with mismatched public key")
}