Skip to content

Commit

Permalink
wip download simulators
Browse files Browse the repository at this point in the history
  • Loading branch information
benma committed Jun 11, 2024
1 parent 2d1f436 commit ff18a68
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions scripts/download_and_verify_simlators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# Copyright 2024 Shift Crypto AG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import requests
import gnupg

# Constants
GITHUB_API_URL = "https://api.github.com"
REPO_OWNER = "BitBoxSwiss"
REPO_NAME = "bitbox02-firmware"
TAG_PREFIX = "firmware/"
DOWNLOAD_DIR = "downloads"

# [email protected] pubkey
PUB_KEY = '''
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGKYcqYBEACtZpDdv1FlJmNsN+tFDhoK9EkO2sKwnQh4mPkuWZ0wAWQabo4k
bLAPr9VJG6lP4BNimXIgy8+0nZzzZEcTS9VTo7Ap44CjgHwcE31LAsI/TLIDauMa
PL89Zzf5NElnVKmrZP3jsAHMQy+teZMLeiJX5FPnmFP6Q9GOCUm2EntCzBCRuHts
zr0hR/Envtk642KbVTQAyrAFAshV/zwu96ijM9braxVjuxyKPPrjKIjqbpuK/rNb
LpSmjo76NKGk05HRx3aqRzcgebosBl6XEQmApE94z/PoZ6nFx88uPWHKI35PIqfk
U23hZV/Mf2SGROGLPcOx0XdbXNBkLgoQ1PNfFAzZ2LAt3qY4Rp7SIQ9JiaxIdLpS
/n3iFtRagRUK/o3d8NeV+Sv9BoGrKa6qZap3wdc4TV0P55M4b5LvXU9Fch6AdjFp
7aa54poTElzenZBAebWyFnHxIDcaqqRSZt2e/QEh5IU5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UIrBTTTgv
4RFEkBmodpDh6KPK09YMBKFF8qJkcfRsxo6GRpBQKThae/bgbS7Cq6Bukztrzc5c
rc55awNHFCYiEnYNq+CsPoTEgdSiY20rzbkHMezAjOuSiJYWusD3Ou7IY+qoAYl8
unESXp5J/fv7pyK8xdovITPEEYQx6/VfmkRbrvPXyjZ1yltctFlG3oxIiEN/FbgH
dtmqcTscKfygEGnoP4Kw9q1c6bvyM2T4Iq/xF5FWutxwC4/vfdM/HOKShm09t7Wa
dtFP9E6Gr1j6rMpvu6wCikeRPpQCngpxswLcAEqV07hQEL4eAlIRpWO1njrr8E7K
x/HayFb+OcRvewKDsUaj+UVnRigptSbb80IB+UuSg2/OEzJjzPTE3tqwgASs1l/m
jLZugv6bMuMLjA==
=0krM
-----END PGP PUBLIC KEY BLOCK-----
'''

# Initialize GPG
gpg = gnupg.GPG()

def import_public_key(pub_key):
result = gpg.import_keys(pub_key)
if result.count == 0:
raise Exception("Failed to import public key")

def download_file(url, dest_path):
if os.path.isfile(dest_path):
print(f"File already exists, skipping. {dest_path}")
return
response = requests.get(url)
response.raise_for_status()
with open(dest_path, 'wb') as f:
f.write(response.content)

def verify_signature(sig_path, file_path):
with open(sig_path, 'rb') as sig_file:
verified = gpg.verify_file(sig_file, file_path)
if not verified:
raise Exception(f"Signature verification failed for {file_path}")

def download_and_verify_assets():
# Get list of releases
releases_url = f"{GITHUB_API_URL}/repos/{REPO_OWNER}/{REPO_NAME}/releases"
response = requests.get(releases_url)
response.raise_for_status()
releases = response.json()

if not os.path.exists(DOWNLOAD_DIR):
os.makedirs(DOWNLOAD_DIR)
for release in releases:
if release['tag_name'].startswith(TAG_PREFIX):
sig_assets = [asset for asset in release['assets'] if asset['name'].endswith('.asc')]
print(f"Found {len(sig_assets)} signatures in release {release['tag_name']}")
for asset in sig_assets:
asset_url = asset['browser_download_url']
asset_name = asset['name']
asset_path = os.path.join(DOWNLOAD_DIR, asset_name)

print(f"Downloading {asset_name} from {asset_url}")
download_file(asset_url, asset_path)

binary_name = asset_name[:-4]
binary_path = os.path.join(DOWNLOAD_DIR, binary_name)
binary_url = asset_url[:-4]
print(f"Downloading {binary_name} from {binary_url}")
download_file(binary_url, binary_path)

print(f"Verifying {asset_name}")
verify_signature(asset_path, binary_path)

if __name__ == "__main__":
import_public_key(PUB_KEY)
download_and_verify_assets()
print("Download and verification complete")

0 comments on commit ff18a68

Please sign in to comment.