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

186 LOC · 66 covered · 120 uncovered · 22 ranges · 19 concepts · 2 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/certificate.go · 126 LOCtestutils/certificate.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/tls.go · 186 LOCtestutils/tls.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 "bytes"
5 "crypto/tls"
6 "crypto/x509"
7 "encoding/base64"
8 "encoding/pem"
9 "fmt"
10 "os"
11 )
12
13 type CertChain struct {
14 CertPubFile string
15 CertKeyFile string
16 CaPubFile string
17 }
18
19 > func CertFilePath(dir string) string { tls.go ×20
20 > return dir + "/cert_pub.pem"
21 > }
22
23 > func KeyFilePath(dir string) string { tls.go ×20
24 > return dir + "/cert_priv.pem"
25 > }
26
27 > func CAFilePath(dir string) string { tls.go ×20
28 > return dir + "/ca_pub.pem"
29 > }
30
31 > func ConvertFileToBase64(file string) string { tls.go ×2
32 > fileBytes, err := os.ReadFile(file)
33 > if err != nil {
34 panic(err)
35 }
36
37 > return base64.StdEncoding.EncodeToString(fileBytes) tls.go ×2
38 }
39
40 > func GenerateTestChain(tempDir string, commonName string) (CertChain, error) { tls.go ×20
41 >
42 > chain, _, err := GenerateTestChainWithSN(tempDir, commonName, 0)
43 > return chain, err
44 > }
45
46 func GenerateTestChainWithSN(tempDir string, commonName string, serialNumber int64,
47 > ) (CertChain, *tls.Certificate, error) { tls.go ×20
48 >
49 > caPubFile := CAFilePath(tempDir)
50 > certPubFile := CertFilePath(tempDir)
51 > certPrivFile := KeyFilePath(tempDir)
52 >
53 > caCert, err := GenerateSelfSignedCA(caPubFile)
54 > if err != nil {
55 return CertChain{}, nil, err
56 }
57
58 > if _, err = GenerateServerCert(caCert, commonName, serialNumber, certPubFile, certPrivFile); err != nil { tls.go ×20
59 return CertChain{}, nil, err
60 }
61
62 > return CertChain{CaPubFile: caPubFile, CertPubFile: certPubFile, CertKeyFile: certPrivFile}, caCert, err tls.go ×20
63 }
64
65 func GenerateTestCerts(tempDir string, commonName string, num int) ([]*tls.Certificate, *x509.CertPool, *x509.CertPool, error) {
66
67 caCert, err := GenerateSelfSignedCA(CAFilePath(tempDir))
68 if err != nil {
69 return nil, nil, nil, err
70 }
71 caPool, err := GenerateSelfSignedCAPool(caCert)
72 if err != nil {
73 return nil, nil, nil, err
74 }
75
76 chains := make([]*tls.Certificate, num)
77 for i := range num {
78 certPubFile := tempDir + fmt.Sprintf("/cert_pub_%d.pem", i)
79 certPrivFile := tempDir + fmt.Sprintf("/cert_priv_%d.pem", i)
80 cert, err := GenerateServerCert(caCert, commonName, int64(i+100), certPubFile, certPrivFile)
81 if err != nil {
82 return nil, nil, nil, err
83 }
84 chains[i] = cert
85 }
86
87 wrongCACert, err := GenerateSelfSignedCA(CAFilePath(tempDir))
88 if err != nil {
89 return nil, nil, nil, err
90 }
91
92 wrongCAPool, err := GenerateSelfSignedCAPool(wrongCACert)
93
94 return chains, caPool, wrongCAPool, err
95 }
96
97 func GenerateSelfSignedCAPool(caCert *tls.Certificate) (*x509.CertPool, error) {
98 caPEM := &pem.Block{
99 Type: "CERTIFICATE",
100 Bytes: caCert.Certificate[0],
101 }
102 caPool := x509.NewCertPool()
103 caPem, err := pemEncodeToBytes(caPEM)
104 if err != nil {
105 return nil, err
106 }
107 caPool.AppendCertsFromPEM(caPem)
108 return caPool, nil
109 }
110
111 > func GenerateSelfSignedCA(filePath string) (*tls.Certificate, error) { tls.go ×20
112 > caCert, err := generateSelfSignedX509CA("undefined", nil, 1024)
113 > if err != nil {
114 return nil, err
115 }
116
117 > if err := pemEncodeToFile(filePath, &pem.Block{ tls.go ×20
118 > Type: "CERTIFICATE",
119 > Bytes: caCert.Certificate[0],
120 > }); err != nil {
121 return nil, err
122 }
123 > return caCert, nil tls.go ×20
124 }
125
126 func GenerateServerCert(
127 caCert *tls.Certificate,
128 commonName string,
129 serialNumber int64,
130 certPubFile string,
131 certPrivFile string,
132 > ) (*tls.Certificate, error) { tls.go ×20
133 >
134 > serverCert, privKey, err := generateServerX509UsingCAAndSerialNumber(commonName, serialNumber, caCert)
135 > if err != nil {
136 return nil, err
137 }
138
139 > certPEM := &pem.Block{ tls.go ×20
140 > Type: "CERTIFICATE",
141 > Bytes: serverCert.Certificate[0],
142 > }
143 > if err := pemEncodeToFile(certPubFile, certPEM); err != nil {
144 return nil, err
145 }
146
147 > keyPEM := &pem.Block{ tls.go ×20
148 > Type: "RSA PRIVATE KEY",
149 > Bytes: x509.MarshalPKCS1PrivateKey(privKey),
150 > }
151 > err = pemEncodeToFile(certPrivFile, keyPEM)
152 > if err != nil {
153 return nil, err
154 }
155
156 > certPem, err := pemEncodeToBytes(certPEM) tls.go ×20
157 > if err != nil {
158 return nil, err
159 }
160
161 > keyPem, err := pemEncodeToBytes(keyPEM) tls.go ×20
162 > if err != nil {
163 return nil, err
164 }
165
166 > cert, err := tls.X509KeyPair(certPem, keyPem) tls.go ×20
167 > return &cert, err
168 }
169
170 > func pemEncodeToFile(file string, block *pem.Block) error { tls.go ×20
171 > bytes, err := pemEncodeToBytes(block)
172 > if err != nil {
173 return err
174 }
175 > return os.WriteFile(file, bytes, os.FileMode(0644)) tls.go ×20
176 }
177
178 > func pemEncodeToBytes(block *pem.Block) ([]byte, error) { tls.go ×20
179 > pemBuffer := new(bytes.Buffer)
180 > err := pem.Encode(pemBuffer, block)
181 > if err != nil {
182 return nil, err
183 }
184
185 > return pemBuffer.Bytes(), nil tls.go ×20
186 }