Skip to content

Commit 388d3dc

Browse files
committed
save signatures as dict. input urls_to_verify to canary script.
1 parent 7066235 commit 388d3dc

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

encryptcontent/plugin.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ def __sign_file__(self, fname, url, key):
135135
with urlopen(url) as response:
136136
h.update(response.read())
137137
signer = eddsa.new(key, 'rfc8032')
138-
return (
139-
url,
140-
base64.b64encode(signer.sign(h)).decode()
141-
)
138+
return base64.b64encode(signer.sign(h)).decode()
142139

143140
def __encrypt_key__(self, key, password, iterations):
144141
""" Encrypts key with PBKDF2 and AES-256. """
@@ -833,21 +830,21 @@ def on_post_build(self, config, **kwargs):
833830
)
834831

835832
if self.config['sign_files']:
836-
signatures = []
833+
signatures = {}
834+
urls_to_verify = []
837835
for file in self.setup['files_to_sign']:
838-
signatures.append(
839-
self.__sign_file__(file['file'], file['url'], self.setup['sign_key'])
840-
)
836+
signatures[file['url']] = self.__sign_file__(file['file'], file['url'], self.setup['sign_key'])
837+
urls_to_verify.append(file['url'])
841838
if signatures:
842839
sign_file_path = Path(config.data["site_dir"] + '/' + self.config['sign_files'])
843840
with open(sign_file_path, "w") as file:
844841
file.write(json.dumps(signatures))
845842

846843
canary_file = self.setup['config_path'].joinpath('canary.py')
847-
if not exists(canary_file):
848-
canary_py = Template(self.setup['canary_template']).render({
849-
'public_key': self.setup['sign_key'].public_key().export_key(format='PEM'),
850-
'signature_url' : config.data["site_url"] + self.config['sign_files']
851-
})
852-
with open(canary_file, 'w') as file:
853-
file.write(canary_py)
844+
canary_py = Template(self.setup['canary_template']).render({
845+
'public_key': self.setup['sign_key'].public_key().export_key(format='PEM'),
846+
'signature_url': config.data["site_url"] + self.config['sign_files'],
847+
'urls_to_verify': json.dumps(urls_to_verify),
848+
})
849+
with open(canary_file, 'w') as file:
850+
file.write(canary_py)

0 commit comments

Comments
 (0)