diff options
Diffstat (limited to 'meta/lib/oe/gpg_sign.py')
-rw-r--r-- | meta/lib/oe/gpg_sign.py | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/meta/lib/oe/gpg_sign.py b/meta/lib/oe/gpg_sign.py index ada1b2f408..059381d5e3 100644 --- a/meta/lib/oe/gpg_sign.py +++ b/meta/lib/oe/gpg_sign.py | |||
@@ -50,6 +50,7 @@ class LocalSigner(object): | |||
50 | bb.error('rpmsign failed: %s' % proc.before.strip()) | 50 | bb.error('rpmsign failed: %s' % proc.before.strip()) |
51 | raise bb.build.FuncFailed("Failed to sign RPM packages") | 51 | raise bb.build.FuncFailed("Failed to sign RPM packages") |
52 | 52 | ||
53 | |||
53 | def detach_sign(self, input_file, keyid, passphrase_file, passphrase=None, armor=True): | 54 | def detach_sign(self, input_file, keyid, passphrase_file, passphrase=None, armor=True): |
54 | """Create a detached signature of a file""" | 55 | """Create a detached signature of a file""" |
55 | import subprocess | 56 | import subprocess |
@@ -58,22 +59,35 @@ class LocalSigner(object): | |||
58 | raise Exception("You should use either passphrase_file of passphrase, not both") | 59 | raise Exception("You should use either passphrase_file of passphrase, not both") |
59 | 60 | ||
60 | cmd = [self.gpg_bin, '--detach-sign', '--batch', '--no-tty', '--yes', | 61 | cmd = [self.gpg_bin, '--detach-sign', '--batch', '--no-tty', '--yes', |
61 | '-u', keyid] | 62 | '--passphrase-fd', '0', '-u', keyid] |
62 | if passphrase_file: | 63 | |
63 | cmd += ['--passphrase-file', passphrase_file] | ||
64 | else: | ||
65 | cmd += ['--passphrase-fd', '0'] | ||
66 | if self.gpg_path: | 64 | if self.gpg_path: |
67 | cmd += ['--homedir', self.gpg_path] | 65 | cmd += ['--homedir', self.gpg_path] |
68 | if armor: | 66 | if armor: |
69 | cmd += ['--armor'] | 67 | cmd += ['--armor'] |
70 | cmd.append(input_file) | 68 | |
71 | job = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, | 69 | cmd += [input_file] |
72 | stderr=subprocess.PIPE) | 70 | |
73 | _, stderr = job.communicate(passphrase) | 71 | try: |
74 | if job.returncode: | 72 | if passphrase_file: |
75 | raise bb.build.FuncFailed("Failed to create signature for '%s': %s" % | 73 | with open(passphrase_file) as fobj: |
76 | (input_file, stderr)) | 74 | passphrase = fobj.readline(); |
75 | |||
76 | job = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE) | ||
77 | (_, stderr) = job.communicate(passphrase) | ||
78 | |||
79 | if job.returncode: | ||
80 | raise bb.build.FuncFailed("GPG exited with code %d: %s" % | ||
81 | (job.returncode, stderr)) | ||
82 | |||
83 | except IOError as e: | ||
84 | bb.error("IO error (%s): %s" % (e.errno, e.strerror)) | ||
85 | raise Exception("Failed to sign '%s'" % input_file) | ||
86 | |||
87 | except OSError as e: | ||
88 | bb.error("OS error (%s): %s" % (e.errno, e.strerror)) | ||
89 | raise Exception("Failed to sign '%s" % input_file) | ||
90 | |||
77 | 91 | ||
78 | def verify(self, sig_file): | 92 | def verify(self, sig_file): |
79 | """Verify signature""" | 93 | """Verify signature""" |