@@ -2,7 +2,6 @@ package storage
2
2
3
3
import (
4
4
"context"
5
- "crypto"
6
5
"encoding/json"
7
6
"io"
8
7
"io/fs"
@@ -30,32 +29,24 @@ func SignatureZipFilename(manifest *VSIXManifest) string {
30
29
31
30
// Signature is a storage wrapper that can sign extensions on demand.
32
31
type Signature struct {
33
- // Signer if provided, will be used to sign extensions. If not provided,
34
- // no extensions will be signed.
35
- Signer crypto.Signer
36
- Logger slog.Logger
37
- // SaveSigZips is a flag that will save the signed extension to disk.
38
- // This is useful for debugging, but the server will never use this file.
39
- saveSigZips bool
32
+ Logger slog.Logger
33
+ IncludeEmptySignatures bool
40
34
Storage
41
35
}
42
36
43
- func NewSignatureStorage (logger slog.Logger , signer crypto.Signer , s Storage ) * Signature {
44
- return & Signature {
45
- Signer : signer ,
46
- Storage : s ,
37
+ func NewSignatureStorage (logger slog.Logger , includeEmptySignatures bool , s Storage ) * Signature {
38
+ if includeEmptySignatures {
39
+ logger .Info (context .Background (), "Signature storage enabled, if using VSCode on Windows, this will not work." )
47
40
}
48
- }
49
-
50
- func (s * Signature ) SaveSigZips () {
51
- if ! s .saveSigZips {
52
- s .Logger .Info (context .Background (), "extension signatures will be saved to disk, do not use this in production" )
41
+ return & Signature {
42
+ Logger : logger ,
43
+ IncludeEmptySignatures : includeEmptySignatures ,
44
+ Storage : s ,
53
45
}
54
- s .saveSigZips = true
55
46
}
56
47
57
48
func (s * Signature ) SigningEnabled () bool {
58
- return s .Signer != nil
49
+ return s .IncludeEmptySignatures
59
50
}
60
51
61
52
// AddExtension includes the signature manifest of the vsix. Signing happens on
@@ -72,18 +63,6 @@ func (s *Signature) AddExtension(ctx context.Context, manifest *VSIXManifest, vs
72
63
return "" , xerrors .Errorf ("encode signature manifest: %w" , err )
73
64
}
74
65
75
- if s .SigningEnabled () && s .saveSigZips {
76
- signed , err := s .SigZip (ctx , vsix , sigManifestJSON )
77
- if err != nil {
78
- s .Logger .Error (ctx , "signing manifest" , slog .Error (err ))
79
- return "" , xerrors .Errorf ("sign and zip manifest: %w" , err )
80
- }
81
- extra = append (extra , File {
82
- RelativePath : SignatureZipFilename (manifest ),
83
- Content : signed ,
84
- })
85
- }
86
-
87
66
return s .Storage .AddExtension (ctx , manifest , vsix , append (extra , File {
88
67
RelativePath : sigManifestName ,
89
68
Content : sigManifestJSON ,
@@ -125,20 +104,12 @@ func (s *Signature) Manifest(ctx context.Context, publisher, name string, versio
125
104
// the signature. Meaning the signature could be empty, incorrect, or a
126
105
// picture of cat and it would work. There is no signature verification.
127
106
//
128
- // - VSCode requires a signature payload to exist, but the context appear
129
- // to be somewhat optional.
130
- // Following another open source implementation, it appears the '.signature.p7s'
131
- // file must exist, but it can be empty.
132
- // The signature is stored in a '.signature.sig' file, although it is unclear
133
- // is VSCode ever reads this file.
134
- // TODO: Properly implement the p7s file, and diverge from the other open
135
- // source implementation. Ideally this marketplace would match Microsoft's
136
- // marketplace API.
107
+ // - VSCode requires a signature payload to exist, but the content is optional
108
+ // for linux users.
109
+ // For windows users, the signature must be valid, and this implementation
110
+ // will not work.
137
111
func (s * Signature ) Open (ctx context.Context , fp string ) (fs.File , error ) {
138
112
if s .SigningEnabled () && strings .HasSuffix (filepath .Base (fp ), SigzipFileExtension ) {
139
- base := filepath .Base (fp )
140
- vsixPath := strings .TrimSuffix (base , SigzipFileExtension )
141
-
142
113
// hijack this request, sign the sig manifest
143
114
manifest , err := s .Storage .Open (ctx , filepath .Join (filepath .Dir (fp ), sigManifestName ))
144
115
if err != nil {
@@ -154,22 +125,7 @@ func (s *Signature) Open(ctx context.Context, fp string) (fs.File, error) {
154
125
return nil , xerrors .Errorf ("read signature manifest: %w" , err )
155
126
}
156
127
157
- vsix , err := s .Storage .Open (ctx , filepath .Join (filepath .Dir (fp ), vsixPath + ".vsix" ))
158
- if err != nil {
159
- // If this file is missing, it means the extension was added before
160
- // signatures were handled by the marketplace.
161
- // TODO: Generate the sig manifest payload and insert it?
162
- return nil , xerrors .Errorf ("open signature manifest: %w" , err )
163
- }
164
- defer vsix .Close ()
165
-
166
- vsixData , err := io .ReadAll (vsix )
167
- if err != nil {
168
- return nil , xerrors .Errorf ("read signature manifest: %w" , err )
169
- }
170
-
171
- // TODO: Fetch the VSIX payload from the storage
172
- signed , err := s .SigZip (ctx , vsixData , manifestData )
128
+ signed , err := s .SigZip (ctx , manifestData )
173
129
if err != nil {
174
130
return nil , xerrors .Errorf ("sign and zip manifest: %w" , err )
175
131
}
@@ -182,8 +138,9 @@ func (s *Signature) Open(ctx context.Context, fp string) (fs.File, error) {
182
138
return s .Storage .Open (ctx , fp )
183
139
}
184
140
185
- func (s * Signature ) SigZip (ctx context.Context , vsix []byte , sigManifest []byte ) ([]byte , error ) {
186
- signed , err := extensionsign .SignAndZipManifest (s .Signer , vsix , sigManifest )
141
+ // SigZip currently just returns an empty signature.
142
+ func (s * Signature ) SigZip (ctx context.Context , sigManifest []byte ) ([]byte , error ) {
143
+ signed , err := extensionsign .IncludeEmptySignature (sigManifest )
187
144
if err != nil {
188
145
s .Logger .Error (ctx , "signing manifest" , slog .Error (err ))
189
146
return nil , xerrors .Errorf ("sign and zip manifest: %w" , err )
0 commit comments