Skip to content

Commit 2f674bb

Browse files
committed
Move TSA blob tests into Go test suite
Run the e2e_signblob_tsa_mtls.sh tests in Go. The e2e-tsa-mtls job in the e2e-tests workflow is fully removed since these are now all covered in e2e-cross. Signed-off-by: Colleen Murphy <[email protected]>
1 parent 69209ea commit 2f674bb

File tree

10 files changed

+71
-355
lines changed

10 files changed

+71
-355
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,14 @@ jobs:
4848
- name: Run cross platform e2e tests
4949
run: go test -tags=e2e,cross -v ./test/...
5050

51-
e2e-tsa-mtls:
52-
strategy:
53-
matrix:
54-
os: [macos-latest, ubuntu-latest]
55-
runs-on: ${{ matrix.os }}
56-
57-
steps:
58-
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
59-
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
60-
with:
61-
go-version: '1.21'
62-
check-latest: true
63-
64-
- uses: imjasonh/setup-crane@00c9e93efa4e1138c9a7a5c594acd6c75a2fbf0c # v0.3
65-
66-
- name: Run e2e_signblob_tsa_mtls.sh
67-
shell: bash
68-
run: make && PATH="$PWD:$PATH" ./test/e2e_signblob_tsa_mtls.sh
69-
7051
e2e-test-pkcs11:
7152
runs-on: ubuntu-latest
7253

7354
steps:
7455
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
7556
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
7657
with:
77-
go-version: '1.21'
58+
go-version: '1.21'
7859
check-latest: true
7960

8061
- name: Run pkcs11 end-to-end tests

test/e2e_signblob_tsa_mtls.sh

Lines changed: 0 additions & 98 deletions
This file was deleted.

test/e2e_tsa_test.go

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"encoding/pem"
2323
"net/http/httptest"
2424
"path"
25+
"path/filepath"
2526
"testing"
2627
"time"
2728

@@ -49,23 +50,8 @@ func TestTSAMTLS(t *testing.T) {
4950

5051
// Set up TSA server with TLS
5152
timestampCACert, timestampServerCert, timestampServerKey, timestampClientCert, timestampClientKey := generateMTLSKeys(t, td)
52-
viper.Set("timestamp-signer", "memory")
53-
viper.Set("timestamp-signer-hash", "sha256")
54-
viper.Set("disable-ntp-monitoring", true)
55-
viper.Set("tls-host", "0.0.0.0")
56-
viper.Set("tls-port", 3000)
57-
viper.Set("tls-ca", timestampCACert)
58-
viper.Set("tls-key", timestampServerKey)
59-
viper.Set("tls-certificate", timestampServerCert)
60-
tsaAPIServer := tsaserver.NewRestAPIServer("localhost", 3000, []string{"https"}, false, 10*time.Second, 10*time.Second)
61-
tsaServer := httptest.NewServer(tsaAPIServer.GetHandler())
62-
t.Cleanup(tsaServer.Close)
63-
tsaClient, err := tsaclient.GetTimestampClient(tsaServer.URL)
64-
must(err, t)
65-
tsaChain, err := tsaClient.Timestamp.GetTimestampCertChain(nil)
66-
must(err, t)
67-
timestampServerURL := tsaServer.URL + "/api/v1/timestamp"
68-
timestampChainFile := mkfile(tsaChain.Payload, td, t)
53+
timestampServerURL, timestampChainFile, tsaCleanup := setUpTSAServerWithTLS(t, td, timestampCACert, timestampServerKey, timestampServerCert)
54+
t.Cleanup(tsaCleanup)
6955

7056
ko := options.KeyOpts{
7157
KeyRef: pemKeyRef,
@@ -98,6 +84,53 @@ func TestTSAMTLS(t *testing.T) {
9884
must(verifyCmd.Exec(context.Background(), []string{imgName}), t)
9985
}
10086

87+
func TestSignBlobTSAMTLS(t *testing.T) {
88+
td := t.TempDir()
89+
blob := time.Now().Format("Mon Jan 2 15:04:05 MST 2006")
90+
blobPath := mkfile(blob, td, t)
91+
timestampPath := filepath.Join(td, "timestamp.txt")
92+
bundlePath := filepath.Join(td, "cosign.bundle")
93+
94+
_, privKey, pubKey := keypair(t, td)
95+
96+
// Set up TSA server with TLS
97+
timestampCACert, timestampServerCert, timestampServerKey, timestampClientCert, timestampClientKey := generateMTLSKeys(t, td)
98+
timestampServerURL, timestampChainFile, tsaCleanup := setUpTSAServerWithTLS(t, td, timestampCACert, timestampServerKey, timestampServerCert)
99+
t.Cleanup(tsaCleanup)
100+
101+
signingKO := options.KeyOpts{
102+
KeyRef: privKey,
103+
PassFunc: passFunc,
104+
TSAServerURL: timestampServerURL,
105+
TSAClientCACert: timestampCACert,
106+
TSAClientCert: timestampClientCert,
107+
TSAClientKey: timestampClientKey,
108+
TSAServerName: "server.example.com",
109+
RFC3161TimestampPath: timestampPath,
110+
BundlePath: bundlePath,
111+
}
112+
sig, err := sign.SignBlobCmd(ro, signingKO, blobPath, true, "", "", false)
113+
must(err, t)
114+
115+
verifyKO := options.KeyOpts{
116+
KeyRef: pubKey,
117+
TSACertChainPath: timestampChainFile,
118+
RFC3161TimestampPath: timestampPath,
119+
BundlePath: bundlePath,
120+
}
121+
122+
verifyCmd := cliverify.VerifyBlobCmd{
123+
KeyOpts: verifyKO,
124+
SigRef: string(sig),
125+
CertVerifyOptions: options.CertVerifyOptions{
126+
CertIdentityRegexp: ".*",
127+
CertOidcIssuerRegexp: ".*",
128+
},
129+
IgnoreTlog: true,
130+
}
131+
must(verifyCmd.Exec(context.Background(), blobPath), t)
132+
}
133+
101134
func generateSigningKeys(t *testing.T, td string) (string, string, string) {
102135
rootCert, rootKey, _ := GenerateRootCa()
103136
pemRoot := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: rootCert.Raw})
@@ -141,3 +174,23 @@ func generateMTLSKeys(t *testing.T, td string) (string, string, string, string,
141174
clientPemKeyRef := mkfile(string(clientKeyPem), td, t)
142175
return pemRootRef, serverPemLeafRef, serverPemKeyRef, clientPemLeafRef, clientPemKeyRef
143176
}
177+
178+
func setUpTSAServerWithTLS(t *testing.T, td, timestampCACert, timestampServerKey, timestampServerCert string) (string, string, func()) {
179+
viper.Set("timestamp-signer", "memory")
180+
viper.Set("timestamp-signer-hash", "sha256")
181+
viper.Set("disable-ntp-monitoring", true)
182+
viper.Set("tls-host", "0.0.0.0")
183+
viper.Set("tls-port", 3000)
184+
viper.Set("tls-ca", timestampCACert)
185+
viper.Set("tls-key", timestampServerKey)
186+
viper.Set("tls-certificate", timestampServerCert)
187+
tsaAPIServer := tsaserver.NewRestAPIServer("localhost", 3000, []string{"https"}, false, 10*time.Second, 10*time.Second)
188+
tsaServer := httptest.NewServer(tsaAPIServer.GetHandler())
189+
tsaClient, err := tsaclient.GetTimestampClient(tsaServer.URL)
190+
must(err, t)
191+
tsaChain, err := tsaClient.Timestamp.GetTimestampCertChain(nil)
192+
must(err, t)
193+
timestampServerURL := tsaServer.URL + "/api/v1/timestamp"
194+
timestampChainFile := mkfile(tsaChain.Payload, td, t)
195+
return timestampServerURL, timestampChainFile, tsaServer.Close
196+
}

test/gencert/main.go

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)