Debian Codegraph @

plugin/verify.go

raw symbols SCIP
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 plugin
15
16 import (
17 "reflect"
18 "time"
19 )
20
21 // VerifySignatureRequest contains the parameters passed in a verify-signature
22 // request.
23 type VerifySignatureRequest struct {
24 ContractVersion string `json:"contractVersion"`
25 Signature Signature `json:"signature"`
26 TrustPolicy TrustPolicy `json:"trustPolicy"`
27 PluginConfig map[string]string `json:"pluginConfig,omitempty"`
28 }
29
30 func (VerifySignatureRequest) Command() Command {
31 return CommandVerifySignature
32 }
33
34 // Validate validates VerifySignatureRequest struct
35 func (r VerifySignatureRequest) Validate() error {
36 if r.ContractVersion == "" {
37 return NewValidationError("contractVersion cannot be empty")
38 }
39
40 if reflect.DeepEqual(r.Signature, Signature{}) {
41 return NewValidationError("signature cannot be empty")
42 }
43
44 if reflect.DeepEqual(r.Signature.CriticalAttributes, CriticalAttributes{}) {
45 return NewValidationError("signature's criticalAttributes cannot be empty")
46 }
47
48 if r.Signature.CriticalAttributes.ContentType == "" {
49 return NewValidationError("signature's criticalAttributes's contentType cannot be empty")
50 }
51
52 if r.Signature.CriticalAttributes.SigningScheme == "" {
53 return NewValidationError("signature's criticalAttributes's signingScheme cannot be empty")
54 }
55
56 if len(r.Signature.CertificateChain) == 0 {
57 return NewValidationError("signature's criticalAttributes's certificateChain cannot be empty")
58 }
59
60 if reflect.DeepEqual(r.TrustPolicy, TrustPolicy{}) {
61 return NewValidationError("signature's trustPolicy cannot be empty")
62 }
63
64 if len(r.TrustPolicy.SignatureVerification) == 0 {
65 return 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 Signature struct {
73 CriticalAttributes CriticalAttributes `json:"criticalAttributes"`
74 UnprocessedAttributes []string `json:"unprocessedAttributes"`
75 CertificateChain [][]byte `json:"certificateChain"`
76 }
77
78 // CriticalAttributes contains all critical attributes and
79 // their values in the signature envelope
80 type CriticalAttributes struct {
81 ContentType string `json:"contentType"`
82 SigningScheme string `json:"signingScheme"`
83 Expiry *time.Time `json:"expiry,omitempty"`
84 AuthenticSigningTime *time.Time `json:"authenticSigningTime,omitempty"`
85 ExtendedAttributes map[string]interface{} `json:"extendedAttributes,omitempty"`
86 }
87
88 // TrustPolicy represents trusted identities that sign the artifacts
89 type TrustPolicy struct {
90 TrustedIdentities []string `json:"trustedIdentities"`
91 SignatureVerification []Capability `json:"signatureVerification"`
92 }
93
94 // VerifySignatureResponse is the response of a verify-signature request.
95 type VerifySignatureResponse struct {
96 VerificationResults map[Capability]*VerificationResult `json:"verificationResults"`
97 ProcessedAttributes []interface{} `json:"processedAttributes"`
98 }
99
100 // VerificationResult is the result of a verification performed by the plugin
101 type VerificationResult struct {
102 Success bool `json:"success"`
103 Reason string `json:"reason,omitempty"`
104 }