Skip to content

Commit 77006d8

Browse files
committed
install: validate checksums
Signed-off-by: Filipe Laíns <lains@archlinux.org>
1 parent 103f418 commit 77006d8

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ optional arguments:
2424
```
2525
2626
Missing components:
27-
- Checksum verification
2827
- Custom data installation:
2928
- `headers`
3029
- `data`
3130
3231
### Bootstraping
3332
3433
`install` has a dependency on `installer`, which is used for entrypoint script
35-
generation. As we don't install entrypoint scripts, this dependency is not needed
36-
to install a `install` wheel, making `install` bootstrapable without any
37-
dependencies.
34+
generation and checksum validation. As we don't install entrypoint scripts,
35+
this dependency is not needed to install a `install` wheel, making `install`
36+
bootstrapable without any dependencies. The only thing is that you won't get the
37+
checksum validation, but if you are building from source that shouldn't be a
38+
problem.

install/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ def _copy_dir(src, dst, ignore=[]): # type: (str, str, List[str]) -> None
9292
shutil.copy2(path, root)
9393

9494

95+
def _validate_checksums(dist_info, dir): # type: (str, str) -> None
96+
try:
97+
import installer.records
98+
99+
with open(os.path.join(dist_info, 'RECORD'), 'r') as f:
100+
lines = [line.strip() for line in f]
101+
102+
for record in installer.records.parse_record_file(lines):
103+
with open(os.path.join(dir, record.path.as_posix()), 'rb') as fr:
104+
if not record.validate(fr.read()):
105+
raise InstallException('Invalid checksum: {}'.format(record))
106+
except ImportError:
107+
warnings.warn("'installer' package missing, skipping checksum verification", RuntimeWarning)
108+
109+
95110
def _generate_entrypoint_scripts(file, dir): # type: (str, str) -> None
96111
entrypoints = configparser.ConfigParser()
97112
entrypoints.read(file)
@@ -228,6 +243,8 @@ def build(wheel, cache_dir, optimize=[0, 1, 2], verify_dependencies=False): # t
228243
elif optimize:
229244
compileall.compile_dir(pkg_cache_dir)
230245

246+
_validate_checksums(dist_info, pkg_cache_dir)
247+
231248
if os.path.isfile(entrypoints_file):
232249
_generate_entrypoint_scripts(entrypoints_file, scripts_cache_dir)
233250

0 commit comments

Comments
 (0)