Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: packagerSafari.py

Issue 29349869: Issue 4339 - Replace M2Crypto by PyCrypto (Closed)
Left Patch Set: Addressed comments Created Aug. 17, 2016, 10:02 a.m.
Right Patch Set: Addressed more nits Created Aug. 17, 2016, 7:20 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « packagerChrome.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import base64 5 import base64
6 import ConfigParser 6 import ConfigParser
7 import json 7 import json
8 import os 8 import os
9 import re 9 import re
10 from urlparse import urlparse 10 from urlparse import urlparse
11 11
12 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files 12 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl ate, Files
13 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa ckageFiles, defaultLocale, createScriptPage 13 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa ckageFiles, defaultLocale, createScriptPage
14
15 PRIVATE_KEY_REGEXP = r'-+BEGIN PRIVATE KEY-+(.*?)-+END PRIVATE KEY-+'
16 CERTIFICATE_REGEXP = r'-+BEGIN CERTIFICATE-+(.*?)-+END CERTIFICATE-+'
17 14
18 15
19 def processFile(path, data, params): 16 def processFile(path, data, params):
20 return data 17 return data
21 18
22 19
23 def createManifest(params, files): 20 def createManifest(params, files):
24 template = getTemplate('Info.plist.tmpl', autoEscape=True) 21 template = getTemplate('Info.plist.tmpl', autoEscape=True)
25 metadata = params['metadata'] 22 metadata = params['metadata']
26 catalog = json.loads(files['_locales/%s/messages.json' % defaultLocale]) 23 catalog = json.loads(files['_locales/%s/messages.json' % defaultLocale])
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 files[filename] = re.sub( 106 files[filename] = re.sub(
110 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', 107 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+',
111 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), 108 r'\1' + '/'.join(['..'] * filename.count('/') + ['']),
112 content, re.S | re.I 109 content, re.S | re.I
113 ) 110 )
114 111
115 112
116 def get_certificates_and_key(keyfile): 113 def get_certificates_and_key(keyfile):
117 from Crypto.PublicKey import RSA 114 from Crypto.PublicKey import RSA
118 115
119 certs = []
120 with open(keyfile, 'r') as file: 116 with open(keyfile, 'r') as file:
121 data = file.read() 117 data = file.read()
122 match = re.search(PRIVATE_KEY_REGEXP, data, re.S) 118
123 if not match: 119 certificates = []
124 raise Exception('Cound not find private key in file') 120 key = None
125 key = RSA.importKey(match.group(0)) 121 for match in re.finditer(r'-+BEGIN (.*?)-+(.*?)-+END \1-+', data, re.S):
126 122 section = match.group(1)
127 for match in re.finditer(CERTIFICATE_REGEXP, data, re.S): 123 if section == 'CERTIFICATE':
Sebastian Noack 2016/08/17 12:19:24 I think it might make sense to unify the logic her
Wladimir Palant 2016/08/17 14:10:03 Done.
128 certs.append(base64.b64decode(match.group(1))) 124 certificates.append(base64.b64decode(match.group(2)))
129 125 elif section == 'PRIVATE KEY':
130 return certs, key 126 key = RSA.importKey(match.group(0))
127 if not key:
128 raise Exception('Could not find private key in file')
129
130 return certificates, key
131 131
132 132
133 def _get_sequence(data): 133 def _get_sequence(data):
134 from Crypto.Util import asn1 134 from Crypto.Util import asn1
135 sequence = asn1.DerSequence() 135 sequence = asn1.DerSequence()
136 sequence.decode(data) 136 sequence.decode(data)
137 return sequence 137 return sequence
138 138
139 139
140 def get_developer_identifier(certs): 140 def get_developer_identifier(certs):
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 fixAbsoluteUrls(files) 288 fixAbsoluteUrls(files)
289 289
290 dirname = metadata.get('general', 'basename') + '.safariextension' 290 dirname = metadata.get('general', 'basename') + '.safariextension'
291 for filename in files.keys(): 291 for filename in files.keys():
292 files[os.path.join(dirname, filename)] = files.pop(filename) 292 files[os.path.join(dirname, filename)] = files.pop(filename)
293 293
294 if not devenv and keyFile: 294 if not devenv and keyFile:
295 createSignedXarArchive(outFile, files, certs, key) 295 createSignedXarArchive(outFile, files, certs, key)
296 else: 296 else:
297 files.zip(outFile) 297 files.zip(outFile)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld