| 1 | // Copyright The Notary Project Authors. |
| 2 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | // you may not use this file except in compliance with the License. |
| 4 | // You may obtain a copy of the License at |
| 5 | // |
| 6 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | // |
| 8 | // Unless required by applicable law or agreed to in writing, software |
| 9 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | // See the License for the specific language governing permissions and |
| 12 | // limitations under the License. |
| 13 | |
| 14 | package pluginscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/ |
| 15 | |
| 16 | import ( |
| 17 | "reflectscip-go gomod github.com/golang/go/src go1.20 reflect/" |
| 18 | "timescip-go gomod github.com/golang/go/src go1.20 time/" |
| 19 | ) |
| 20 | |
| 21 | // VerifySignatureRequest contains the parameters passed in a verify-signature |
| 22 | // request. |
| 23 | type VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest# struct { |
| 24 | ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#ContractVersion. string `json:"contractVersion"` |
| 25 | Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature. Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature# `json:"signature"` |
| 26 | TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#TrustPolicy. TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy# `json:"trustPolicy"` |
| 27 | PluginConfigscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#PluginConfig. map[string]string `json:"pluginConfig,omitempty"` |
| 28 | } |
| 29 | |
| 30 | func (VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#) Commandscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Command().() Commandscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Command# { |
| 31 | return CommandVerifySignaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CommandVerifySignature. |
| 32 | } |
| 33 | |
| 34 | // Validate validates VerifySignatureRequest struct |
| 35 | func (r VerifySignatureRequestscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#) Validatescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Validate().() error { |
| 36 | if r.ContractVersionscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#ContractVersion. == "" { |
| 37 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("contractVersion cannot be empty") |
| 38 | } |
| 39 | |
| 40 | if reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.20 reflect/DeepEqual().(r.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature., Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#{}) { |
| 41 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature cannot be empty") |
| 42 | } |
| 43 | |
| 44 | if reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.20 reflect/DeepEqual().(r.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature..CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes., CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#{}) { |
| 45 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature's criticalAttributes cannot be empty") |
| 46 | } |
| 47 | |
| 48 | if r.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature..CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes..ContentTypescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#ContentType. == "" { |
| 49 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature's criticalAttributes's contentType cannot be empty") |
| 50 | } |
| 51 | |
| 52 | if r.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature..CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes..SigningSchemescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#SigningScheme. == "" { |
| 53 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature's criticalAttributes's signingScheme cannot be empty") |
| 54 | } |
| 55 | |
| 56 | if len(r.Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#Signature..CertificateChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CertificateChain.) == 0 { |
| 57 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature's criticalAttributes's certificateChain cannot be empty") |
| 58 | } |
| 59 | |
| 60 | if reflectscip-go gomod github.com/golang/go/src go1.20 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.20 reflect/DeepEqual().(r.TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#TrustPolicy., TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#{}) { |
| 61 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature's trustPolicy cannot be empty") |
| 62 | } |
| 63 | |
| 64 | if len(r.TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureRequest#TrustPolicy..SignatureVerificationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#SignatureVerification.) == 0 { |
| 65 | return NewValidationErrorscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/NewValidationError().("signature's trustPolicy's signatureVerification cannot be empty") |
| 66 | } |
| 67 | |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | // Signature represents a signature pulled from the envelope |
| 72 | type Signaturescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature# struct { |
| 73 | CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CriticalAttributes. CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes# `json:"criticalAttributes"` |
| 74 | UnprocessedAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#UnprocessedAttributes. []string `json:"unprocessedAttributes"` |
| 75 | CertificateChainscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Signature#CertificateChain. [][]byte `json:"certificateChain"` |
| 76 | } |
| 77 | |
| 78 | // CriticalAttributes contains all critical attributes and |
| 79 | // their values in the signature envelope |
| 80 | type CriticalAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes# struct { |
| 81 | ContentTypescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#ContentType. string `json:"contentType"` |
| 82 | SigningSchemescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#SigningScheme. string `json:"signingScheme"` |
| 83 | Expiryscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#Expiry. *timescip-go gomod github.com/golang/go/src go1.20 time/.Timescip-go gomod github.com/golang/go/src go1.20 time/Time# `json:"expiry,omitempty"` |
| 84 | AuthenticSigningTimescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#AuthenticSigningTime. *timescip-go gomod github.com/golang/go/src go1.20 time/.Timescip-go gomod github.com/golang/go/src go1.20 time/Time# `json:"authenticSigningTime,omitempty"` |
| 85 | ExtendedAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/CriticalAttributes#ExtendedAttributes. map[string]interface{} `json:"extendedAttributes,omitempty"` |
| 86 | } |
| 87 | |
| 88 | // TrustPolicy represents trusted identities that sign the artifacts |
| 89 | type TrustPolicyscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy# struct { |
| 90 | TrustedIdentitiesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#TrustedIdentities. []string `json:"trustedIdentities"` |
| 91 | SignatureVerificationscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/TrustPolicy#SignatureVerification. []Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability# `json:"signatureVerification"` |
| 92 | } |
| 93 | |
| 94 | // VerifySignatureResponse is the response of a verify-signature request. |
| 95 | type VerifySignatureResponsescip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureResponse# struct { |
| 96 | VerificationResultsscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureResponse#VerificationResults. map[Capabilityscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/Capability#]*VerificationResultscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerificationResult# `json:"verificationResults"` |
| 97 | ProcessedAttributesscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerifySignatureResponse#ProcessedAttributes. []interface{} `json:"processedAttributes"` |
| 98 | } |
| 99 | |
| 100 | // VerificationResult is the result of a verification performed by the plugin |
| 101 | type VerificationResultscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerificationResult# struct { |
| 102 | Successscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerificationResult#Success. bool `json:"success"` |
| 103 | Reasonscip-go gomod github.com/notaryproject/notation-plugin-framework-go . `github.com/notaryproject/notation-plugin-framework-go/plugin`/VerificationResult#Reason. string `json:"reason,omitempty"` |
| 104 | } |