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

feat: Timestamp #978

Merged
merged 103 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
e04d7cd
tsa
Two-Hearts Dec 6, 2023
b90399c
resolved conflicts
Two-Hearts Jan 4, 2024
f249e7a
update
Two-Hearts Jan 4, 2024
7d888dc
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 15, 2024
3cbd3e5
update
Two-Hearts Jan 16, 2024
9edc3c0
resolve conflicts
Two-Hearts Jan 16, 2024
d2a86e4
resolved conflicts
Two-Hearts Jan 23, 2024
95aad90
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 24, 2024
68036b6
resolved conflicts
Two-Hearts Jan 25, 2024
1622205
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 25, 2024
f14a98b
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 31, 2024
e84f407
update tspclient-go
Two-Hearts Feb 1, 2024
0e83d2f
tsa
Two-Hearts Feb 1, 2024
a45c5dc
update
Two-Hearts Feb 1, 2024
d7d7a1a
resolved conflicts
Two-Hearts Feb 2, 2024
e73312f
resolved conflicts
Two-Hearts Mar 18, 2024
c15b58d
Merge branch 'notaryproject:main' into tsa
Two-Hearts Mar 22, 2024
a851775
update
Two-Hearts Mar 22, 2024
0bd76bc
Merge branch 'notaryproject:main' into tsa
Two-Hearts Mar 27, 2024
eb0fcc9
updated timestamp
Two-Hearts Mar 27, 2024
7f60e9e
Merge branch 'notaryproject:main' into tsa
Two-Hearts Mar 28, 2024
f7bd27c
Merge branch 'notaryproject:main' into tsa
Two-Hearts Apr 8, 2024
be15eb2
test
Two-Hearts Apr 8, 2024
d4fa037
Merge branch 'notaryproject:main' into tsa
Two-Hearts Apr 10, 2024
177be5b
update
Two-Hearts Apr 10, 2024
64ffee5
added at-timestamped-time in verification
Two-Hearts Apr 11, 2024
b0c8b45
added cli spec
Two-Hearts Apr 12, 2024
d9ae5aa
resolved conflicts
Two-Hearts Apr 16, 2024
47872ad
update
Two-Hearts Apr 18, 2024
f3a96c0
Merge branch 'notaryproject:main' into tsa
Two-Hearts Apr 18, 2024
5c7a70b
test
Two-Hearts Apr 18, 2024
7aee992
fixed e2e tests
Two-Hearts Apr 18, 2024
991b5d4
Merge branch 'notaryproject:main' into tsa
Two-Hearts Apr 25, 2024
4b3a06d
updated per spec
Two-Hearts May 8, 2024
4cb6be6
fixed e2e tests
Two-Hearts May 8, 2024
b498611
updated tspclient-go
Two-Hearts May 10, 2024
1456f7a
resolved conflicts
Two-Hearts Jun 4, 2024
7ffa82b
timestamping
Two-Hearts Jun 4, 2024
ca20476
fixed e2e tests
Two-Hearts Jun 4, 2024
9e60d23
resolved conflicts
Two-Hearts Jun 11, 2024
9dca4dc
update
Two-Hearts Jun 11, 2024
61107e5
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jun 18, 2024
6cd87c8
updated timestamping
Two-Hearts Jun 18, 2024
0040af6
update
Two-Hearts Jun 20, 2024
a860d8b
updated timestamp
Two-Hearts Jun 21, 2024
9ecbb9a
adding tests
Two-Hearts Jun 24, 2024
ad1fb95
fix tests
Two-Hearts Jun 24, 2024
e148bba
fix tests
Two-Hearts Jun 24, 2024
d7e5186
added more e2e tests
Two-Hearts Jun 24, 2024
388d223
fix e2e
Two-Hearts Jun 24, 2024
e34897c
fix e2e
Two-Hearts Jun 24, 2024
c7debce
fix e2e
Two-Hearts Jun 24, 2024
c8c4a09
added tsa-root-cert
Two-Hearts Jun 24, 2024
7ef3850
updated e2e tests
Two-Hearts Jun 25, 2024
03f3303
fixed e2e tests
Two-Hearts Jun 25, 2024
8e0f32c
update
Two-Hearts Jun 25, 2024
480bd4b
updated CLI spec for timestamping
Two-Hearts Jun 25, 2024
7cd46ab
update
Two-Hearts Jun 26, 2024
92b5ce9
update
Two-Hearts Jun 27, 2024
f9ca829
test
Two-Hearts Jun 27, 2024
1a8fe7b
test
Two-Hearts Jun 27, 2024
1526dbe
add more tests
Two-Hearts Jun 27, 2024
f78ee81
fix e2e
Two-Hearts Jun 27, 2024
670e39d
updated tspclient-go
Two-Hearts Jun 27, 2024
a11b692
updated timestamping
Two-Hearts Jul 1, 2024
10a2b63
fixed E2E test
Two-Hearts Jul 1, 2024
bd7212d
updated timestamping
Two-Hearts Jul 3, 2024
b241460
updated timestamping
Two-Hearts Jul 3, 2024
8900872
updated timestamping
Two-Hearts Jul 3, 2024
bdf1264
updated notation-go
Two-Hearts Jul 8, 2024
04579ca
updated notation-go
Two-Hearts Jul 9, 2024
52f7052
updated notation-go
Two-Hearts Jul 11, 2024
1e4422d
update
Two-Hearts Jul 11, 2024
34e2f1f
updated notation-go
Two-Hearts Jul 11, 2024
ec602c0
updated notation-go
Two-Hearts Jul 12, 2024
e4564a3
fixed e2e
Two-Hearts Jul 12, 2024
469c37a
resolved conflicts
Two-Hearts Jul 12, 2024
f5a4ad9
updated notation-go
Two-Hearts Jul 12, 2024
aa35f19
updated dependencies
Two-Hearts Jul 15, 2024
1a82b19
updated dependencies
Two-Hearts Jul 15, 2024
abcc089
updated verify spec
Two-Hearts Jul 15, 2024
940a728
updated verify spec
Two-Hearts Jul 15, 2024
6332224
updated specs
Two-Hearts Jul 15, 2024
7959952
updated per code review
Two-Hearts Jul 15, 2024
efa5a28
updated per code review
Two-Hearts Jul 16, 2024
a95b987
update
Two-Hearts Jul 16, 2024
76ee7c7
fix
Two-Hearts Jul 16, 2024
4364750
update dependencies
Two-Hearts Jul 16, 2024
ebebefe
update
Two-Hearts Jul 16, 2024
41b5551
naming
Two-Hearts Jul 17, 2024
81f01ba
updated per code review
Two-Hearts Jul 17, 2024
f8c2d8e
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jul 17, 2024
1b97540
update
Two-Hearts Jul 17, 2024
49c8b81
updated per code review
Two-Hearts Jul 22, 2024
5c177c0
fix E2E test
Two-Hearts Jul 22, 2024
7c44b3e
update
Two-Hearts Jul 22, 2024
6aafe34
update
Two-Hearts Jul 22, 2024
26bc1d3
updated E2E tests
Two-Hearts Jul 22, 2024
7b996ec
fixed E2E tests
Two-Hearts Jul 22, 2024
7aef357
fixed E2E tests
Two-Hearts Jul 22, 2024
3196711
fixed E2E tests
Two-Hearts Jul 22, 2024
cafc2e1
updated dependencies
Two-Hearts Jul 22, 2024
b05572b
updated per code review
Two-Hearts Jul 22, 2024
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
17 changes: 15 additions & 2 deletions cmd/notation/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"github.com/notaryproject/notation/internal/cmd"
"github.com/notaryproject/notation/internal/envelope"
"github.com/notaryproject/notation/internal/httputil"
nx509 "github.com/notaryproject/notation/internal/x509"
"github.com/notaryproject/tspclient-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -222,7 +223,7 @@
fmt.Printf("Configured to timestamp with TSA %q\n", opts.tsaServerURL)
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
signOpts.Timestamper, err = tspclient.NewHTTPTimestamper(httputil.NewClient(ctx, &http.Client{Timeout: timestampingTimeout}), opts.tsaServerURL)
if err != nil {
return notation.SignOptions{}, fmt.Errorf("cannot get http timestamper for timestamping: %w", err)

Check warning on line 226 in cmd/notation/sign.go

View check run for this annotation

Codecov / codecov/patch

cmd/notation/sign.go#L226

Added line #L226 was not covered by tests
}

rootCerts, err := corex509.ReadCertificateFile(opts.tsaRootCertificatePath)
Expand All @@ -230,10 +231,22 @@
return notation.SignOptions{}, err
}
if len(rootCerts) == 0 {
return notation.SignOptions{}, fmt.Errorf("cannot find any tsa root certificate from %q. Expecting x509 certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
return notation.SignOptions{}, fmt.Errorf("cannot find any certificate from %q. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
}
if len(rootCerts) > 1 {
return notation.SignOptions{}, fmt.Errorf("found more than one certificates from %q. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)
}
tsaRootCert := rootCerts[0]
isRoot, err := nx509.IsRootCertificate(tsaRootCert)
if err != nil {
return notation.SignOptions{}, fmt.Errorf("failed to check root certificate with error: %w", err)
}
if !isRoot {
return notation.SignOptions{}, fmt.Errorf("certificate from %q is not a root certificate. Expecting single x509 root certificate in PEM or DER format from the file", opts.tsaRootCertificatePath)

}
rootCAs := x509.NewCertPool()
rootCAs.AddCert(rootCerts[0])
rootCAs.AddCert(tsaRootCert)
signOpts.TSARootCAs = rootCAs
}
return signOpts, nil
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
github.com/notaryproject/notation-core-go v1.0.4-0.20240716001320-f45197cbd53b
github.com/notaryproject/notation-go v1.1.1-0.20240715044011-b52583166f2b
github.com/notaryproject/notation-go v1.1.1-0.20240719045753-83409204754a
github.com/notaryproject/tspclient-go v0.1.1-0.20240715235637-df25ef8d2172
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZ
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/notaryproject/notation-core-go v1.0.4-0.20240716001320-f45197cbd53b h1:uJ4bmNieZRkPj3UgmKr3bZr8vs7UJ2MdlJMeB0oOaZw=
github.com/notaryproject/notation-core-go v1.0.4-0.20240716001320-f45197cbd53b/go.mod h1:MdxSbL9F5h63EmtXWfYMWy7hEmGmOmsfN4B6KM2WyhY=
github.com/notaryproject/notation-go v1.1.1-0.20240715044011-b52583166f2b h1:Bz/b2CxF5zs4/+/o37zC47U8yipMBkFdP5QTZtqZfJc=
github.com/notaryproject/notation-go v1.1.1-0.20240715044011-b52583166f2b/go.mod h1:h0U0bVTjCxnozj1OhyeqQsNWWd7frFK+DUJsnH6tAhI=
github.com/notaryproject/notation-go v1.1.1-0.20240719045753-83409204754a h1:o3kYOcQii0dMaDKdxnr1wPlEskXHHkDZDDb3kuss+W0=
github.com/notaryproject/notation-go v1.1.1-0.20240719045753-83409204754a/go.mod h1:FwHtZC29bBvFdJu0NYM5MHxSrHJGwhkPRvEgevNo9wo=
github.com/notaryproject/notation-plugin-framework-go v1.0.0 h1:6Qzr7DGXoCgXEQN+1gTZWuJAZvxh3p8Lryjn5FaLzi4=
github.com/notaryproject/notation-plugin-framework-go v1.0.0/go.mod h1:RqWSrTOtEASCrGOEffq0n8pSg2KOgKYiWqFWczRSics=
github.com/notaryproject/tspclient-go v0.1.1-0.20240715235637-df25ef8d2172 h1:Q8UsmeFMzyFuMMq4dlbIRJUi7khEKXKUe2H2Hm3W92Y=
Expand Down
17 changes: 17 additions & 0 deletions internal/testdata/intermediate.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICyjCCAbKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARSb290
MCAXDTIyMDYzMDE5MjAwM1oYDzMwMjExMDMxMTkyMDAzWjAYMRYwFAYDVQQDDA1J
bnRlcm1lZGlhdGUxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1JTs
aiC/7+bho43kMVyHDwCsuocYp4PvYahB59NsKDR4QbrImU5ziaQ94D0DQqthe9pm
qOW0SxN/vSRJAZFELxacrB9hc1y4MjiDYaRSt/LVx7astylBV/QRpmxWSEqp0Avu
6nMJivIa1sD0WIEchizx6jG9BI5ULr9LbJICYvMgDalQR+0JGG+rKWnf1mPZyxEu
9zEh215LCg5K56P3W5kC8fKBXSdSgTqZAvHzp6u78qet9S8gARtOEfS03A/7y7MC
U0Sn2wdQyQdci0PBsR2sTZvUw179Cr93r5aRbb3I6jXgMWHAP2vvIndb9CM9ePyY
yEy4Je7oWVVfMQ3CWQIDAQABoyYwJDASBgNVHRMBAf8ECDAGAQH/AgEBMA4GA1Ud
DwEB/wQEAwICBDANBgkqhkiG9w0BAQsFAAOCAQEALR0apUQVbWGmagLUz4Y/bRsl
mY9EJJXCiLuSxVWd3offjZfQTlGkQkCAW9FOQnm7JhEtaaHF1+AEVLo56/Gsd/hk
sXsrBagYGi72jun7QTb6j7iZ3X9zanrP3SjdkpjVnqxRfH83diSh0r68Xruq1NSK
qhUy1V+KQaXF0SSEutPqdTCoXUyxyXohVLU78uqZX/jx9Nc1XDuW9AZd+hMsLdk8
qGJqHYFvj2vOHGMTeYk8dWgMBthQeL0wdsg2AvKtAvn6FQXCN7mKCWjpFTtYsU8v
NsesS9M/i+geJjR/8/DDT3RP7S100BtCMm4XfHfmKcjXVaBh5evQVqGsa6TKLw==
-----END CERTIFICATE-----
21 changes: 21 additions & 0 deletions internal/testdata/notSelfIssued.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMQswCQYDVQQGEwJVUzEJ
MAcGA1UECBMAMQkwBwYDVQQHEwAxDzANBgNVBAoTBk5vdGFyeTENMAsGA1UEAxME
dGVzdDAeFw0yNDA3MjIwNTIwMzZaFw0yNDA4MjIwNTIwMzZaMEwxCzAJBgNVBAYT
AlVTMQswCQYDVQQIEwJXQTEQMA4GA1UEBxMHU2VhdHRsZTEPMA0GA1UEChMGTm90
YXJ5MQ0wCwYDVQQDEwR0ZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
AQEAp7XmYGf3p4JS/y5v6AIc/TxQvPTwIRxVmctNmDm5kG3LDUoGAAJbicTUfI/0
Un38j/PlHNKQz9hKPwV+oYotKuQrVhaA2fft+INl36tvgCAPr8yX3ToOMCLr/UlT
zQ7o9TB7IpnVT9DR9uik9MWfkz0Db5ARG1POquvSy2QM5wseEA58313YJ/7Em/Cq
FCH5s9THCfQKpb09MZ/RTEggNqU4zGADah8e1KieYeZntM/hrw7sW5oeUueKG4D4
3kvL8o7n1k6C+w8LwaOGhYXCQ51JxTE3lnmTrDdFRuKGObpNFNbLxdJPVLuHT1Nu
bwVxj5APBJQyEyja3jJ9qLQANwIDAQABo1owWDAOBgNVHQ8BAf8EBAMCAgQwEwYD
VR0lBAwwCgYIKwYBBQUHAwMwEgYDVR0TAQH/BAgwBgEB/wIBATAdBgNVHQ4EFgQU
yPScYtI4hs0+ibHaRV9BsgY734AwDQYJKoZIhvcNAQELBQADggEBABJHh3NELq1b
jcJiJX76DwDTx+FGGN96/+T5622FGg1kHeAwuxS6pQODJNrVofbrhGAqaXTDT/Tz
0b0AA5XCohmBFZQRwMh+C5QkFiIcZ9VMMBc6KTQT8DEgjI6Qo/OW2TDGOoFuAhmh
4a1ACHszuHS55Th+0TKLqeZNA6DnL9IBm0RX1FJXbqhjX52ZnRH3Zqe7uML+kxKt
LUdfnxHrpA1G2ugyAj+K7K6vth5QpezwCS1PZD2s5vlJd6clawxm5qRyyU46ow/y
7bpTSEyg6PIWWh/qv4O2t4NMa1OoRkIXx/ppsKH9XwbRg/WZ0VWlGVS6GxBtLSpG
tkyaxSRLdz0=
-----END CERTIFICATE-----
20 changes: 20 additions & 0 deletions internal/testdata/self-signed.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDPjCCAiagAwIBAgIBeTANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzEL
MAkGA1UECBMCV0ExEDAOBgNVBAcTB1Nl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ATE-----
Binary file added internal/testdata/tsaRootCA.cer
Binary file not shown.
30 changes: 30 additions & 0 deletions internal/x509/cert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright The Notary Project Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package x509

import (
"bytes"
"crypto/x509"
)

// IsRootCertificate returns true if cert is a root certificate.
// A root certificate MUST be a self-signed and self-issued CA certificate with
// valid BasicConstraints.
func IsRootCertificate(cert *x509.Certificate) (bool, error) {
// CheckSignatureFrom also checks cert.BasicConstraintsValid
if err := cert.CheckSignatureFrom(cert); err != nil {
return false, err
}
return cert.IsCA && bytes.Equal(cert.RawSubject, cert.RawIssuer), nil
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved
}
67 changes: 67 additions & 0 deletions internal/x509/cert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright The Notary Project Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package x509

import (
"testing"

corex509 "github.com/notaryproject/notation-core-go/x509"
)

func TestIsRootCertificate(t *testing.T) {
tsaRoot, err := corex509.ReadCertificateFile("../testdata/tsaRootCA.cer")
if err != nil {
t.Fatal(err)
}
isRoot, err := IsRootCertificate(tsaRoot[0])
if err != nil {
t.Fatal(err)
}
if !isRoot {
t.Fatal("expected IsRootCertificate to return true")
}

intermediate, err := corex509.ReadCertificateFile("../testdata/intermediate.pem")
if err != nil {
t.Fatal(err)
}
expectedErrMsg := "crypto/rsa: verification error"
_, err = IsRootCertificate(intermediate[0])
if err == nil || err.Error() != expectedErrMsg {
t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
}

selfSigned, err := corex509.ReadCertificateFile("../testdata/self-signed.crt")
if err != nil {
t.Fatal(err)
}
expectedErrMsg = "x509: invalid signature: parent certificate cannot sign this kind of certificate"
_, err = IsRootCertificate(selfSigned[0])
if err == nil || err.Error() != expectedErrMsg {
t.Fatalf("expected %s, but got %s", expectedErrMsg, err)
}

notSelfIssued, err := corex509.ReadCertificateFile("../testdata/notSelfIssued.crt")
if err != nil {
t.Fatal(err)
}
expectedErrMsg = "x509: invalid signature: parent certificate cannot sign this kind of certificate"
isRoot, err = IsRootCertificate(notSelfIssued[0])
if err != nil {
t.Fatal(err)
}
if isRoot {
t.Fatal("expected IsRootCertificate to return false")
}
}
2 changes: 1 addition & 1 deletion test/e2e/plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/notaryproject/notation-core-go v1.0.4-0.20240716001320-f45197cbd53b
github.com/notaryproject/notation-go v1.1.1-0.20240715044011-b52583166f2b
github.com/notaryproject/notation-go v1.1.1-0.20240719045753-83409204754a
github.com/notaryproject/notation-plugin-framework-go v1.0.0
github.com/spf13/cobra v1.7.0
)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/plugin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZ
github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/notaryproject/notation-core-go v1.0.4-0.20240716001320-f45197cbd53b h1:uJ4bmNieZRkPj3UgmKr3bZr8vs7UJ2MdlJMeB0oOaZw=
github.com/notaryproject/notation-core-go v1.0.4-0.20240716001320-f45197cbd53b/go.mod h1:MdxSbL9F5h63EmtXWfYMWy7hEmGmOmsfN4B6KM2WyhY=
github.com/notaryproject/notation-go v1.1.1-0.20240715044011-b52583166f2b h1:Bz/b2CxF5zs4/+/o37zC47U8yipMBkFdP5QTZtqZfJc=
github.com/notaryproject/notation-go v1.1.1-0.20240715044011-b52583166f2b/go.mod h1:h0U0bVTjCxnozj1OhyeqQsNWWd7frFK+DUJsnH6tAhI=
github.com/notaryproject/notation-go v1.1.1-0.20240719045753-83409204754a h1:o3kYOcQii0dMaDKdxnr1wPlEskXHHkDZDDb3kuss+W0=
github.com/notaryproject/notation-go v1.1.1-0.20240719045753-83409204754a/go.mod h1:FwHtZC29bBvFdJu0NYM5MHxSrHJGwhkPRvEgevNo9wo=
github.com/notaryproject/notation-plugin-framework-go v1.0.0 h1:6Qzr7DGXoCgXEQN+1gTZWuJAZvxh3p8Lryjn5FaLzi4=
github.com/notaryproject/notation-plugin-framework-go v1.0.0/go.mod h1:RqWSrTOtEASCrGOEffq0n8pSg2KOgKYiWqFWczRSics=
github.com/notaryproject/tspclient-go v0.1.1-0.20240715235637-df25ef8d2172 h1:Q8UsmeFMzyFuMMq4dlbIRJUi7khEKXKUe2H2Hm3W92Y=
Expand Down
38 changes: 34 additions & 4 deletions test/e2e/suite/command/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,32 +280,62 @@ var _ = Describe("notation sign", func() {
})
})

It("with empty tsa server", func() {
It("with timestamping and empty tsa server", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "globalsignTSARoot.cer"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("Error: timestamping: tsa url cannot be empty")
})
})

It("with empty tsa root cert", func() {
It("with timestamping and empty tsa root cert", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "dummy", "--timestamp-root-cert", "", artifact.ReferenceWithDigest()).
MatchErrKeyWords("Error: timestamping: tsa root certificate path cannot be empty")
})
})

It("with invalid tsa server", func() {
It("with timestamping and invalid tsa server", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "http://invalid.com", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "globalsignTSARoot.cer"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("Error: timestamp: Post \"http://invalid.com\"").
MatchErrKeyWords("server misbehaving")
})
})

It("with invalid tsa root certificate", func() {
It("with timestamping and invalid tsa root certificate", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "http://timestamp.digicert.com", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "invalid.crt"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("Error: x509: malformed certificate")
})
})

It("with timestamping and empty tsa root certificate file", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "http://timestamp.digicert.com", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "Empty.txt"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("cannot find any certificate from").
MatchErrKeyWords("Expecting single x509 root certificate in PEM or DER format from the file")
})
})

It("with timestamping and more than one certificates in tsa root certificate file", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "http://timestamp.digicert.com", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "CertChain.pem"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("found more than one certificates").
MatchErrKeyWords("Expecting single x509 root certificate in PEM or DER format from the file")
})
})

It("with timestamping and intermediate certificate file", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "http://timestamp.digicert.com", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "intermediate.pem"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("failed to check root certificate with error: crypto/rsa: verification error")
})
})

It("with timestamping and not self-issued certificate file", func() {
Host(BaseOptions(), func(notation *utils.ExecOpts, artifact *Artifact, vhost *utils.VirtualHost) {
notation.ExpectFailure().Exec("sign", "--timestamp-url", "http://timestamp.digicert.com", "--timestamp-root-cert", filepath.Join(NotationE2EConfigPath, "timestamp", "notSelfIssued.crt"), artifact.ReferenceWithDigest()).
MatchErrKeyWords("is not a root certificate. Expecting single x509 root certificate in PEM or DER format from the file")
})
})
})
22 changes: 22 additions & 0 deletions test/e2e/testdata/config/timestamp/CertChain.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIBljCCATugAwIBAgIQJOyDt70f+HOyQMEt06yvpjAKBggqhkjOPQQDAjAkMRAw
DgYDVQQKEwdBY21lIENvMRAwDgYDVQQDEwdSb290IENBMB4XDTIyMDcyMjA1MjEz
N1oXDTIzMDcyMjA1MjEzN1owKDEQMA4GA1UEChMHQWNtZSBDbzEUMBIGA1UEAwwL
dGVzdF9jZXJ0XzEwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAATnf3lSRtUYOeph
UQZvUm5niB8kpm7kn6iAm2zwCTBeqKbUtgESCbN+x6TTpWZIaEo+CDu1rPUdicB3
FUwXNzz8o0swSTAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEw
DAYDVR0TAQH/BAIwADAUBgNVHREEDTALgglsb2NhbGhvc3QwCgYIKoZIzj0EAwID
SQAwRgIhAMgdV/zJnwK0J4ZBXZVwAB6abpgNcESFScDeQQyIzRs8AiEAjjLTfkXp
CuoXnu5/hYy6Li7Smw3UbW3XKkekOELMFYo=
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIBnjCCAUOgAwIBAgIQBUvhbMcjM35qmJzncyZ5tzAKBggqhkjOPQQDAjAkMRAw
DgYDVQQKEwdBY21lIENvMRAwDgYDVQQDEwdSb290IENBMB4XDTIyMDcyMjA1MjEz
N1oXDTIzMDcyMjA1MjEzN1owJDEQMA4GA1UEChMHQWNtZSBDbzEQMA4GA1UEAxMH
Um9vdCBDQTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGmby5GUiBDR+Ge+s/R9
EqOfoDwEdDBPYU0emJg8j8CPJGM0ldalI1Sk7YMTIi34clvfTqEixE7nDwQj8FjQ
VvCjVzBVMA4GA1UdDwEB/wQEAwICBDATBgNVHSUEDDAKBggrBgEFBQcDATAPBgNV
HRMBAf8EBTADAQH/MB0GA1UdDgQWBBTcOHZMx0z3I9Hi8oa2Kp0umdXOsTAKBggq
hkjOPQQDAgNJADBGAiEArHTaO3f6vaiI+4IOrR7SYSzeHIAqoFAWFcf1yOzxDA4C
IQDRcDIPWJd7pXvFJT/Q++Vkq9QuUhqrigCQDkgksnxf5w==
-----END CERTIFICATE-----
Empty file.
17 changes: 17 additions & 0 deletions test/e2e/testdata/config/timestamp/intermediate.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-----BEGIN CERTIFICATE-----
MIICyjCCAbKgAwIBAgIBATANBgkqhkiG9w0BAQsFADAPMQ0wCwYDVQQDDARSb290
MCAXDTIyMDYzMDE5MjAwM1oYDzMwMjExMDMxMTkyMDAzWjAYMRYwFAYDVQQDDA1J
bnRlcm1lZGlhdGUxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1JTs
aiC/7+bho43kMVyHDwCsuocYp4PvYahB59NsKDR4QbrImU5ziaQ94D0DQqthe9pm
qOW0SxN/vSRJAZFELxacrB9hc1y4MjiDYaRSt/LVx7astylBV/QRpmxWSEqp0Avu
6nMJivIa1sD0WIEchizx6jG9BI5ULr9LbJICYvMgDalQR+0JGG+rKWnf1mPZyxEu
9zEh215LCg5K56P3W5kC8fKBXSdSgTqZAvHzp6u78qet9S8gARtOEfS03A/7y7MC
U0Sn2wdQyQdci0PBsR2sTZvUw179Cr93r5aRbb3I6jXgMWHAP2vvIndb9CM9ePyY
yEy4Je7oWVVfMQ3CWQIDAQABoyYwJDASBgNVHRMBAf8ECDAGAQH/AgEBMA4GA1Ud
DwEB/wQEAwICBDANBgkqhkiG9w0BAQsFAAOCAQEALR0apUQVbWGmagLUz4Y/bRsl
mY9EJJXCiLuSxVWd3offjZfQTlGkQkCAW9FOQnm7JhEtaaHF1+AEVLo56/Gsd/hk
sXsrBagYGi72jun7QTb6j7iZ3X9zanrP3SjdkpjVnqxRfH83diSh0r68Xruq1NSK
qhUy1V+KQaXF0SSEutPqdTCoXUyxyXohVLU78uqZX/jx9Nc1XDuW9AZd+hMsLdk8
qGJqHYFvj2vOHGMTeYk8dWgMBthQeL0wdsg2AvKtAvn6FQXCN7mKCWjpFTtYsU8v
NsesS9M/i+geJjR/8/DDT3RP7S100BtCMm4XfHfmKcjXVaBh5evQVqGsa6TKLw==
-----END CERTIFICATE-----
21 changes: 21 additions & 0 deletions test/e2e/testdata/config/timestamp/notSelfIssued.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDZDCCAkygAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMQswCQYDVQQGEwJVUzEJ
MAcGA1UECBMAMQkwBwYDVQQHEwAxDzANBgNVBAoTBk5vdGFyeTENMAsGA1UEAxME
dGVzdDAeFw0yNDA3MjIwNTIwMzZaFw0yNDA4MjIwNTI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