go.temporal.io/server/tests/testutils/certificate.go

126 LOC · 71 covered · 55 uncovered · 13 ranges · 19 concepts · 1 introducers · 9 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filego.temporal.io/server/tests/testutils/tls.go · 186 LOCtestutils/tls.golocal_store_cert_provider.go ×11 · 47 introduced LOClocal_store_cert_provide…tls_config_helper.go ×1 · 2 introduced LOCtls_config_helper.go ×1TestRingpopInvalidTLS · 0 introduced LOCTestRingpopInvalidTLSlocal_store_tls_provider.go ×4 · 17 introduced LOClocal_store_tls_provider…local_store_cert_provider.go ×5 · 12 introduced LOClocal_store_cert_provide…local_store_cert_provider.go ×51 · 202 introduced LOClocal_store_cert_provide…TestTokenAuthHeader_ReceiverRejectsWrongToken · 0 introduced LOCTestTokenAuthHeader_Rece…TestTokenAuthHeader_SentOnRemoteConnection · 0 introduced LOCTestTokenAuthHeader_Sent…rpc.go ×1 · 1 introduced LOCrpc.go ×1rpc.go ×1 · 2 introduced LOCrpc.go ×1service_grpc.pb.go ×1 · 2 introduced LOCservice_grpc.pb.go ×1request_response.pb.go ×2 · 17 introduced LOCrequest_response.pb.go ×…rpc.go ×4 · 12 introduced LOCrpc.go ×4service_grpc.pb.go ×4 · 24 introduced LOCservice_grpc.pb.go ×4rpc.go ×4 · 32 introduced LOCrpc.go ×4TestHostsMode · 0 introduced LOCTestHostsModefactory.go ×1 · 2 introduced LOCfactory.go ×1tls.go ×2 · 4 introduced LOCtls.go ×2tls.go ×20 · 133 introduced LOCtls.go ×20TestHostsMode · introduced test · go.temporal.io/server/common/membership/ringpop/TestRingpopSuite/TestHostsModeTestHostsModeTestInvalidBroadcastAddress · introduced test · go.temporal.io/server/common/membership/ringpop/TestRingpopSuite/TestInvalidBroadcastAddressTestInvalidBroadcastAddr…TestRingpopInvalidTLS · introduced test · go.temporal.io/server/common/membership/ringpop/TestRingpopSuite/TestRingpopInvalidTLSTestRingpopInvalidTLSTestRingpopMutualTLS · introduced test · go.temporal.io/server/common/membership/ringpop/TestRingpopSuite/TestRingpopMutualTLSTestRingpopMutualTLSTestRingpopServerTLS · introduced test · go.temporal.io/server/common/membership/ringpop/TestRingpopSuite/TestRingpopServerTLSTestRingpopServerTLSTestTokenAuthHeader_NotSentWhenNoProvider · introduced test · go.temporal.io/server/common/rpc/test/TestTokenAuthHeader_NotSentWhenNoProviderTestTokenAuthHeader_NotS…TestTokenAuthHeader_ReceiverRejectsWrongToken · introduced test · go.temporal.io/server/common/rpc/test/TestTokenAuthHeader_ReceiverRejectsWrongTokenTestTokenAuthHeader_Rece…TestTokenAuthHeader_SentOnRemoteConnection · introduced test · go.temporal.io/server/common/rpc/test/TestTokenAuthHeader_SentOnRemoteConnectionTestTokenAuthHeader_Sent…TestTokenAuthHeader_StrictModeRejectsEmptyToken · introduced test · go.temporal.io/server/common/rpc/test/TestTokenAuthHeader_StrictModeRejectsEmptyTokenTestTokenAuthHeader_Stri…Focused file · go.temporal.io/server/tests/testutils/certificate.go · 126 LOCtestutils/certificate.go

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package testutils
2
3 import (
4 "crypto/rand"
5 "crypto/rsa"
6 "crypto/tls"
7 "crypto/x509"
8 "crypto/x509/pkix"
9 "math/big"
10 mathrand "math/rand"
11 "net"
12 "strings"
13 "time"
14 )
15
16 // GenerateSelfSignedX509CA generates a TLS serverCert that is self-signed
17 > func generateSelfSignedX509CA(commonName string, extUsage []x509.ExtKeyUsage, keyLengthBits int) (*tls.Certificate, error) { tls.go ×20
18 > now := time.Now().UTC()
19 >
20 > template := &x509.Certificate{
21 > SerialNumber: big.NewInt(now.Unix()),
22 > Subject: pkix.Name{
23 > CommonName: commonName,
24 > Country: []string{"USA"},
25 > Organization: []string{"TemporalTechnologiesTesting"},
26 > },
27 > NotBefore: now.Add(-time.Minute),
28 > NotAfter: now.AddDate(0, 0, 1), // 1 day expiry
29 > BasicConstraintsValid: true,
30 > IsCA: true,
31 > ExtKeyUsage: extUsage,
32 > KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageKeyEncipherment |
33 > x509.KeyUsageDigitalSignature,
34 > }
35 >
36 > if ip := net.ParseIP(commonName); ip != nil {
37 if ip.IsLoopback() {
38 template.IPAddresses = []net.IP{net.IPv6loopback, net.IPv4(127, 0, 0, 1)}
39 template.DNSNames = []string{"localhost"}
40 } else {
41 template.IPAddresses = []net.IP{ip}
42 }
43 > } else { tls.go ×20
44 > template.DNSNames = []string{commonName}
45 > }
46
47 > if strings.ToLower(commonName) == "localhost" { tls.go ×20
48 template.IPAddresses = []net.IP{net.IPv6loopback, net.IPv4(127, 0, 0, 1)}
49 }
50
51 > privateKey, err := rsa.GenerateKey(rand.Reader, keyLengthBits) tls.go ×20
52 > if err != nil {
53 return &tls.Certificate{}, err
54 }
55
56 > cert, err := x509.CreateCertificate(rand.Reader, template, template, privateKey.Public(), privateKey) tls.go ×20
57 > if err != nil {
58 return &tls.Certificate{}, err
59 }
60
61 > var tlsCert tls.Certificate tls.go ×20
62 > tlsCert.Certificate = append(tlsCert.Certificate, cert)
63 > tlsCert.PrivateKey = privateKey
64 >
65 > return &tlsCert, nil
66 }
67
68 // GenerateServerX509UsingCA generates a TLS serverCert that is self-signed
69 > func generateServerX509UsingCAAndSerialNumber(commonName string, serialNumber int64, ca *tls.Certificate) (*tls.Certificate, *rsa.PrivateKey, error) { tls.go ×20
70 > now := time.Now().UTC()
71 >
72 > i := serialNumber
73 > if i == 0 {
74 > i = mathrand.Int63n(100000000000000000)
75 > }
76
77 > template := &x509.Certificate{ tls.go ×20
78 > SerialNumber: big.NewInt(i),
79 > Subject: pkix.Name{
80 > CommonName: commonName,
81 > Country: []string{"USA"},
82 > Organization: []string{"TemporalTechnologiesTesting"},
83 > },
84 > NotBefore: now.Add(-time.Minute),
85 > NotAfter: now.AddDate(0, 0, 1), // 1 day expiry
86 > BasicConstraintsValid: true,
87 > ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
88 > KeyUsage: x509.KeyUsageDigitalSignature,
89 > }
90 >
91 > if ip := net.ParseIP(commonName); ip != nil {
92 > if ip.IsLoopback() {
93 > template.IPAddresses = []net.IP{net.IPv6loopback, net.IPv4(127, 0, 0, 1)}
94 > template.DNSNames = []string{"localhost"}
95 > } else {
96 template.IPAddresses = []net.IP{ip}
97 }
98 } else {
99 template.DNSNames = []string{commonName}
100 }
101
102 > if strings.ToLower(commonName) == "localhost" { tls.go ×20
103 template.IPAddresses = []net.IP{net.IPv6loopback, net.IPv4(127, 0, 0, 1)}
104 }
105
106 > privateKey, err := rsa.GenerateKey(rand.Reader, 4096) tls.go ×20
107 > if err != nil {
108 return &tls.Certificate{}, nil, err
109 }
110
111 > caCert, err := x509.ParseCertificate(ca.Certificate[0]) tls.go ×20
112 > if err != nil {
113 return nil, nil, err
114 }
115
116 > cert, err := x509.CreateCertificate(rand.Reader, template, caCert, privateKey.Public(), ca.PrivateKey) tls.go ×20
117 > if err != nil {
118 return &tls.Certificate{}, nil, err
119 }
120
121 > var tlsCert tls.Certificate tls.go ×20
122 > tlsCert.Certificate = append(tlsCert.Certificate, cert)
123 > tlsCert.PrivateKey = privateKey
124 >
125 > return &tlsCert, privateKey, err
126 }