1 |
commit: a33ebb12913282a3ddb579d2b7ac1c9fadbe97e5 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Feb 1 11:41:22 2018 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 5 18:41:33 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a33ebb12 |
7 |
|
8 |
rsync: Use gemato routines directly instead of calling the CLI tool |
9 |
|
10 |
Reviewed-by: Zac Medico <zmedico <AT> gentoo.org> |
11 |
|
12 |
pym/portage/sync/modules/rsync/rsync.py | 66 ++++++++++++++++++++++++++++----- |
13 |
1 file changed, 57 insertions(+), 9 deletions(-) |
14 |
|
15 |
diff --git a/pym/portage/sync/modules/rsync/rsync.py b/pym/portage/sync/modules/rsync/rsync.py |
16 |
index ec28af366..39c4066d8 100644 |
17 |
--- a/pym/portage/sync/modules/rsync/rsync.py |
18 |
+++ b/pym/portage/sync/modules/rsync/rsync.py |
19 |
@@ -6,6 +6,7 @@ import logging |
20 |
import time |
21 |
import signal |
22 |
import socket |
23 |
+import io |
24 |
import re |
25 |
import random |
26 |
import tempfile |
27 |
@@ -25,6 +26,13 @@ from portage.sync.getaddrinfo_validate import getaddrinfo_validate |
28 |
from _emerge.UserQuery import UserQuery |
29 |
from portage.sync.syncbase import NewBase |
30 |
|
31 |
+try: |
32 |
+ from gemato.exceptions import GematoException |
33 |
+ import gemato.openpgp |
34 |
+ import gemato.recursiveloader |
35 |
+except ImportError: |
36 |
+ gemato = None |
37 |
+ |
38 |
if sys.hexversion >= 0x3000000: |
39 |
# pylint: disable=W0622 |
40 |
_unicode = str |
41 |
@@ -285,17 +293,57 @@ class RsyncSync(NewBase): |
42 |
|
43 |
# if synced successfully, verify now |
44 |
if exitcode == 0 and not local_state_unchanged and self.verify_metamanifest: |
45 |
- command = ['gemato', 'verify', '-s', self.repo.location] |
46 |
- if self.repo.sync_openpgp_key_path is not None: |
47 |
- command += ['-K', self.repo.sync_openpgp_key_path] |
48 |
- if self.verify_jobs is not None: |
49 |
- command += ['-j', str(self.verify_jobs)] |
50 |
- try: |
51 |
- exitcode = portage.process.spawn(command, **self.spawn_kwargs) |
52 |
- except CommandNotFound as e: |
53 |
- writemsg_level("!!! Command not found: %s\n" % (command[0],), |
54 |
+ if gemato is None: |
55 |
+ writemsg_level("!!! Unable to verify: gemato-11.0+ is required\n", |
56 |
level=logging.ERROR, noiselevel=-1) |
57 |
exitcode = 127 |
58 |
+ else: |
59 |
+ # Use isolated environment if key is specified, |
60 |
+ # system environment otherwise |
61 |
+ if self.repo.sync_openpgp_key_path is not None: |
62 |
+ openpgp_env_cls = gemato.openpgp.OpenPGPEnvironment |
63 |
+ else: |
64 |
+ openpgp_env_cls = gemato.openpgp.OpenPGPSystemEnvironment |
65 |
+ |
66 |
+ try: |
67 |
+ with openpgp_env_cls() as openpgp_env: |
68 |
+ if self.repo.sync_openpgp_key_path is not None: |
69 |
+ out.einfo('Using keys from %s' % (self.repo.sync_openpgp_key_path,)) |
70 |
+ with io.open(self.repo.sync_openpgp_key_path, 'rb') as f: |
71 |
+ openpgp_env.import_key(f) |
72 |
+ out.ebegin('Refreshing keys from keyserver') |
73 |
+ openpgp_env.refresh_keys() |
74 |
+ out.eend(0) |
75 |
+ |
76 |
+ m = gemato.recursiveloader.ManifestRecursiveLoader( |
77 |
+ os.path.join(self.repo.location, 'Manifest'), |
78 |
+ verify_openpgp=True, |
79 |
+ openpgp_env=openpgp_env, |
80 |
+ max_jobs=self.verify_jobs) |
81 |
+ if not m.openpgp_signed: |
82 |
+ raise RuntimeError('OpenPGP signature not found on Manifest') |
83 |
+ |
84 |
+ ts = m.find_timestamp() |
85 |
+ if ts is None: |
86 |
+ raise RuntimeError('Timestamp not found in Manifest') |
87 |
+ |
88 |
+ out.einfo('Manifest timestamp: %s UTC' % (ts.ts,)) |
89 |
+ out.einfo('Valid OpenPGP signature found:') |
90 |
+ out.einfo('- primary key: %s' % ( |
91 |
+ m.openpgp_signature.primary_key_fingerprint)) |
92 |
+ out.einfo('- subkey: %s' % ( |
93 |
+ m.openpgp_signature.fingerprint)) |
94 |
+ out.einfo('- timestamp: %s UTC' % ( |
95 |
+ m.openpgp_signature.timestamp)) |
96 |
+ |
97 |
+ out.ebegin('Verifying %s' % (self.repo.location,)) |
98 |
+ m.assert_directory_verifies() |
99 |
+ out.eend(0) |
100 |
+ except GematoException as e: |
101 |
+ writemsg_level("!!! Manifest verification failed:\n%s\n" |
102 |
+ % (e,), |
103 |
+ level=logging.ERROR, noiselevel=-1) |
104 |
+ exitcode = 1 |
105 |
|
106 |
return (exitcode, updatecache_flg) |