111
111
class SignableTagFile:
112
112
"""Base class for signed file verification."""
114
115
signingkey = None
115
parsed_content = None
119
if self.signingkey is not None:
120
return self.signingkey.owner
122
def parse(self, verify_signature=True):
123
"""Parse the tag file, optionally verifying the signature.
125
If verify_signature is True, signingkey will be set to the signing
126
`IGPGKey`, and only the verified content will be parsed. Otherwise,
127
any signature will be stripped and the contained content parsed.
129
Will raise an `UploadError` if the tag file was unparsable,
130
or if signature verification was requested but failed.
133
with open(self.filepath, 'rb') as f:
134
self.raw_content = f.read()
135
except IOError, error:
137
"Unable to read %s: %s" % (self.filename, error))
140
self.signingkey, self.parsed_content = self.verifySignature(
141
self.raw_content, self.filepath)
143
self.logger.debug("%s can be unsigned." % self.filename)
144
self.parsed_content = self.raw_content
146
self._dict = parse_tagfile_content(
147
self.parsed_content, filename=self.filepath)
148
except TagFileParseError, error:
150
"Unable to parse %s: %s" % (self.filename, error))
152
def verifySignature(self, content, filename):
153
"""Verify the signature on the file content.
118
def processSignature(self):
119
"""Verify the signature on the filename.
121
Stores the fingerprint, the IGPGKey used to sign, the owner of
122
the key and a dictionary containing
155
124
Raise UploadError if the signing key cannot be found in launchpad
156
125
or if the GPG verification failed for any other reason.
158
Returns a tuple of the key (`IGPGKey` object) and the verified
127
Returns the key owner (person object), the key (gpgkey object) and
128
the pyme signature as a three-tuple
162
"Verifying signature on %s" % os.path.basename(filename))
130
self.logger.debug("Verifying signature on %s" % self.filename)
131
assert os.path.exists(self.filepath), (
132
"File not found: %s" % self.filepath)
165
135
sig = getUtility(IGPGHandler).getVerifiedSignatureResilient(
136
file(self.filepath, "rb").read())
167
137
except GPGVerificationError, error:
168
138
raise UploadError(
169
139
"GPG verification of %s failed: %s" % (
170
filename, str(error)))
140
self.filename, str(error)))
172
142
key = getUtility(IGPGKeySet).getByFingerprint(sig.fingerprint)
177
147
if key.active == False:
178
148
raise UploadError("File %s is signed with a deactivated key %s"
179
% (filename, key.keyid))
149
% (self.filename, key.keyid))
181
return (key, sig.plain_data)
151
self.fingerprint = sig.fingerprint
152
self.signingkey = key
153
self.signer = key.owner
154
self.signer_address = self.parseAddress("%s <%s>" % (
155
self.signer.displayname, self.signer.preferredemail.email))
183
157
def parseAddress(self, addr, fieldname="Maintainer"):
184
158
"""Parse an address, using the policy to decide if we should add a
267
242
SourceUploadFile.__init__(
268
243
self, filepath, digest, size, component_and_section, priority,
269
244
package, version, changes, policy, logger)
270
self.parse(verify_signature=not policy.unsigned_dsc_ok)
246
self._dict = parse_tagfile(
247
self.filepath, dsc_whitespace_rules=1,
248
allow_unsigned=self.policy.unsigned_dsc_ok)
249
except (IOError, TagFileParseError), error:
251
"Unable to parse the dsc %s: %s" % (self.filename, error))
272
253
self.logger.debug("Performing DSC verification.")
273
254
for mandatory_field in self.mandatory_fields:
667
652
creator=self.changes.changed_by['person'],
668
653
urgency=self.changes.converted_urgency,
669
654
homepage=encoded.get('homepage'),
670
dsc=encoded_raw_content,
655
dsc=encoded['filecontents'],
671
656
dscsigningkey=self.signingkey,
672
657
dsc_maintainer_rfc822=encoded['Maintainer'],
673
658
dsc_format=encoded['Format'],