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

Tsa #3

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4b42738
initial test
Two-Hearts Dec 1, 2023
ca5bba2
fix trust store
Two-Hearts Dec 4, 2023
73ec77c
resolved conflicts
Two-Hearts Dec 26, 2023
2937f68
Merge branch 'notaryproject:main' into tsa
Two-Hearts Dec 28, 2023
f06d289
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 12, 2024
9819ba2
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 15, 2024
8e6bbdb
initial commits
Two-Hearts Jan 15, 2024
b454646
initial commits
Two-Hearts Jan 15, 2024
d058046
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 16, 2024
1df563c
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 19, 2024
9cd5aaf
updated to use tspclient-go
Two-Hearts Jan 23, 2024
ef01821
resolved conflicts
Two-Hearts Jan 24, 2024
e655c04
Merge branch 'notaryproject:main' into tsa
Two-Hearts Jan 31, 2024
ea97a99
updated tspclient-go
Two-Hearts Jan 31, 2024
fa4eaaf
test
Two-Hearts Feb 1, 2024
dc9c5fe
update
Two-Hearts Feb 1, 2024
00d7dfd
Merge branch 'notaryproject:main' into tsa
Two-Hearts Feb 1, 2024
62bacd0
resolved conflicts
Two-Hearts Feb 2, 2024
1f4bd5c
Merge branch 'notaryproject:main' into tsa
Two-Hearts Mar 18, 2024
3b98cd7
update sign with timestamping
Two-Hearts Mar 22, 2024
09810a9
resolved conflicts
Two-Hearts Mar 22, 2024
e598416
update timestamp verification
Two-Hearts Mar 22, 2024
be2ea0e
updated timestmap
Two-Hearts Mar 27, 2024
c8f8e4e
updated timestamp
Two-Hearts Mar 27, 2024
28e0166
resolve conflicts
Two-Hearts Mar 28, 2024
200a071
added tsa cert chain revocation check
Two-Hearts Apr 8, 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
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/go-ldap/ldap/v3 v3.4.6
github.com/notaryproject/notation-core-go v1.0.3-0.20240325061945-807a3386734e
github.com/notaryproject/notation-plugin-framework-go v1.0.0
github.com/notaryproject/tspclient-go v0.0.0-20240122083733-a373599795a2
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/veraison/go-cose v1.1.0
Expand All @@ -23,3 +24,7 @@ require (
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/sync v0.6.0 // indirect
)

replace github.com/notaryproject/notation-core-go => github.com/Two-Hearts/notation-core-go v0.0.0-20240408025912-2338257358ed

replace github.com/notaryproject/tspclient-go => github.com/Two-Hearts/tspclient-go v0.0.0-20240327080830-9d2a35b7f3f0
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 h1:mFRzDkZVAjdal+s7s0MwaRv9igoPqLRdzOLzw/8Xvq8=
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358/go.mod h1:chxPXzSsl7ZWRAuOIE23GDNzjWuZquvFlgA8xmpunjU=
github.com/Two-Hearts/notation-core-go v0.0.0-20240408025912-2338257358ed h1:9HuLSjZdpwFQXxeL0N/dy/9N1nmxNsqnI6jHiud5Wjo=
github.com/Two-Hearts/notation-core-go v0.0.0-20240408025912-2338257358ed/go.mod h1:GsHR/83xmdubOk+77PlzIilthZNt+qCY4I9BxMKXbxg=
github.com/Two-Hearts/tspclient-go v0.0.0-20240327080830-9d2a35b7f3f0 h1:EbUo6vzeco2sq3ipHCL7JtsgAwOXNiM7BRRRLVp2o3U=
github.com/Two-Hearts/tspclient-go v0.0.0-20240327080830-9d2a35b7f3f0/go.mod h1:LGyA/6Kwd2FlM0uk8Vc5il3j0CddbWSHBj/4kxQDbjs=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA=
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -15,8 +19,6 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOW
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/notaryproject/notation-core-go v1.0.3-0.20240325061945-807a3386734e h1:GdPnC0iJ2gIhed529oaVXtzWUTyDafmOUah/07uEQVo=
github.com/notaryproject/notation-core-go v1.0.3-0.20240325061945-807a3386734e/go.mod h1:HsaLU1gXhal0p5a0noBFEZxs2NIDCqdFgx4mD4DmlmY=
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/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand Down
3 changes: 3 additions & 0 deletions notation.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ type SignerSignOptions struct {

// SigningAgent sets the signing agent name
SigningAgent string

// TSA denotes the TSA server URL
TSAServerURL string
}

// Signer is a generic interface for signing an OCI artifact.
Expand Down
11 changes: 8 additions & 3 deletions signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (s *GenericSigner) Sign(ctx context.Context, desc ocispec.Descriptor, opts
SigningTime: time.Now(),
SigningScheme: signature.SigningSchemeX509,
SigningAgent: signingAgentId,
TSAServerURL: opts.TSAServerURL,
}

// Add expiry only if ExpiryDuration is not zero
Expand All @@ -135,16 +136,22 @@ func (s *GenericSigner) Sign(ctx context.Context, desc ocispec.Descriptor, opts
logger.Debugf(" Expiry: %v", signReq.Expiry)
logger.Debugf(" SigningScheme: %v", signReq.SigningScheme)
logger.Debugf(" SigningAgent: %v", signReq.SigningAgent)
logger.Debugf(" TSAServerURL: %v", signReq.TSAServerURL)

// perform signing
sigEnv, err := signature.NewEnvelope(opts.SignatureMediaType)
if err != nil {
return nil, nil, err
}

var timestampErr *signature.TimestampError
sig, err := sigEnv.Sign(signReq)
if err != nil {
return nil, nil, err
if !errors.As(err, &timestampErr) {
return nil, nil, err
}
// warn on timestamping error, but do not fail the signing process
logger.Warnf("Failed to timestamp the signature. Error: %v", timestampErr)
}

envContent, err := sigEnv.Verify()
Expand All @@ -154,8 +161,6 @@ func (s *GenericSigner) Sign(ctx context.Context, desc ocispec.Descriptor, opts
if err := envelope.ValidatePayloadContentType(&envContent.Payload); err != nil {
return nil, nil, err
}

// TODO: re-enable timestamping https://github.com/notaryproject/notation-go/issues/78
return sig, &envContent.SignerInfo, nil
}

Expand Down
64 changes: 39 additions & 25 deletions verifier/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,7 @@ func loadX509TrustStores(ctx context.Context, scheme signature.SigningScheme, po
default:
return nil, truststore.TrustStoreError{Msg: fmt.Sprintf("error while loading the trust store, unrecognized signing scheme %q", scheme)}
}

processedStoreSet := set.New[string]()
var certificates []*x509.Certificate
for _, trustStore := range policy.TrustStores {
if processedStoreSet.Contains(trustStore) {
// we loaded this trust store already
continue
}

storeType, name, found := strings.Cut(trustStore, ":")
if !found {
return nil, truststore.TrustStoreError{Msg: fmt.Sprintf("error while loading the trust store, trust policy statement %q is missing separator in trust store value %q. The required format is <TrustStoreType>:<TrustStoreName>", policy.Name, trustStore)}
}
if typeToLoad != truststore.Type(storeType) {
continue
}

certs, err := x509TrustStore.GetCertificates(ctx, typeToLoad, name)
if err != nil {
return nil, err
}
certificates = append(certificates, certs...)
processedStoreSet.Add(trustStore)
}
return certificates, nil
return loadX509TrustStoresWithType(ctx, typeToLoad, policy, x509TrustStore)
}

// isCriticalFailure checks whether a VerificationResult fails the entire
Expand Down Expand Up @@ -154,3 +130,41 @@ func getVerificationPluginMinVersion(signerInfo *signature.SignerInfo) (string,
}
return version, nil
}

func loadX509TSATrustStores(ctx context.Context, scheme signature.SigningScheme, policy *trustpolicy.TrustPolicy, x509TrustStore truststore.X509TrustStore) ([]*x509.Certificate, error) {
var typeToLoad truststore.Type
switch scheme {
case signature.SigningSchemeX509:
typeToLoad = truststore.TypeTSA
default:
return nil, truststore.TrustStoreError{Msg: fmt.Sprintf("error while loading the TSA trust store, signing scheme must be notary.x509, but got %s", scheme)}
}
return loadX509TrustStoresWithType(ctx, typeToLoad, policy, x509TrustStore)
}

func loadX509TrustStoresWithType(ctx context.Context, trustStoreType truststore.Type, policy *trustpolicy.TrustPolicy, x509TrustStore truststore.X509TrustStore) ([]*x509.Certificate, error) {
processedStoreSet := set.New[string]()
var certificates []*x509.Certificate
for _, trustStore := range policy.TrustStores {
if processedStoreSet.Contains(trustStore) {
// we loaded this trust store already
continue
}

storeType, name, found := strings.Cut(trustStore, ":")
if !found {
return nil, truststore.TrustStoreError{Msg: fmt.Sprintf("error while loading the trust store, trust policy statement %q is missing separator in trust store value %q. The required format is <TrustStoreType>:<TrustStoreName>", policy.Name, trustStore)}
}
if trustStoreType != truststore.Type(storeType) {
continue
}

certs, err := x509TrustStore.GetCertificates(ctx, trustStoreType, name)
if err != nil {
return nil, err
}
certificates = append(certificates, certs...)
processedStoreSet.Add(trustStore)
}
return certificates, nil
}
2 changes: 2 additions & 0 deletions verifier/truststore/truststore.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ type Type string
const (
TypeCA Type = "ca"
TypeSigningAuthority Type = "signingAuthority"
TypeTSA Type = "tsa"
)

var (
Types = []Type{
TypeCA,
TypeSigningAuthority,
TypeTSA,
}
)

Expand Down
Loading
Loading