| OLD | NEW |
| 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 os | 5 import os |
| 6 import sys | 6 import sys |
| 7 import re | 7 import re |
| 8 import hashlib | 8 import hashlib |
| 9 import base64 | 9 import base64 |
| 10 import urllib | 10 import urllib |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 if not len(missing): | 280 if not len(missing): |
| 281 break | 281 break |
| 282 for path, moduleFile in missing: | 282 for path, moduleFile in missing: |
| 283 files.read(path, moduleFile) | 283 files.read(path, moduleFile) |
| 284 checkScript(moduleFile) | 284 checkScript(moduleFile) |
| 285 | 285 |
| 286 template = getTemplate('bootstrap.js.tmpl') | 286 template = getTemplate('bootstrap.js.tmpl') |
| 287 files['bootstrap.js'] = template.render(templateData).encode('utf-8') | 287 files['bootstrap.js'] = template.render(templateData).encode('utf-8') |
| 288 | 288 |
| 289 | 289 |
| 290 def signFiles(files, keyFile): | 290 def createBuild(baseDir, type='gecko', outFile=None, locales=None, buildNum=None
, releaseBuild=False, multicompartment=False): |
| 291 import M2Crypto | |
| 292 manifest = [] | |
| 293 signature = [] | |
| 294 | |
| 295 def getDigest(data): | |
| 296 md5 = hashlib.md5() | |
| 297 md5.update(data) | |
| 298 sha1 = hashlib.sha1() | |
| 299 sha1.update(data) | |
| 300 return 'Digest-Algorithms: MD5 SHA1\nMD5-Digest: %s\nSHA1-Digest: %s\n'
% (base64.b64encode(md5.digest()), base64.b64encode(sha1.digest())) | |
| 301 | |
| 302 def addSection(manifestData, signaturePrefix): | |
| 303 manifest.append(manifestData) | |
| 304 signatureData = '' | |
| 305 if signaturePrefix: | |
| 306 signatureData += signaturePrefix | |
| 307 signatureData += getDigest(manifestData) | |
| 308 signature.append(signatureData) | |
| 309 | |
| 310 addSection('Manifest-Version: 1.0\n', 'Signature-Version: 1.0\n') | |
| 311 fileNames = files.keys() | |
| 312 fileNames.sort() | |
| 313 for fileName in fileNames: | |
| 314 addSection('Name: %s\n%s' % (fileName, getDigest(files[fileName])), 'Nam
e: %s\n' % fileName) | |
| 315 files['META-INF/manifest.mf'] = '\n'.join(manifest) | |
| 316 files['META-INF/zigbert.sf'] = '\n'.join(signature) | |
| 317 | |
| 318 keyHandle = open(keyFile, 'rb') | |
| 319 keyData = keyHandle.read() | |
| 320 keyHandle.close() | |
| 321 stack = M2Crypto.X509.X509_Stack() | |
| 322 first = True | |
| 323 for match in re.finditer(r'-----BEGIN CERTIFICATE-----.*?-----END CERTIFICAT
E-----', keyData, re.S): | |
| 324 if first: | |
| 325 # Skip first certificate | |
| 326 first = False | |
| 327 else: | |
| 328 stack.push(M2Crypto.X509.load_cert_string(match.group(0))) | |
| 329 | |
| 330 mime = M2Crypto.SMIME.SMIME() | |
| 331 mime.load_key(keyFile) | |
| 332 mime.set_x509_stack(stack) | |
| 333 signature = mime.sign(M2Crypto.BIO.MemoryBuffer(files['META-INF/zigbert.sf']
.encode('utf-8')), M2Crypto.SMIME.PKCS7_DETACHED | M2Crypto.SMIME.PKCS7_BINARY) | |
| 334 | |
| 335 buffer = M2Crypto.BIO.MemoryBuffer() | |
| 336 signature.write_der(buffer) | |
| 337 files['META-INF/zigbert.rsa'] = buffer.read() | |
| 338 | |
| 339 | |
| 340 def createBuild(baseDir, type='gecko', outFile=None, locales=None, buildNum=None
, releaseBuild=False, keyFile=None, multicompartment=False): | |
| 341 if locales == None: | 291 if locales == None: |
| 342 locales = getLocales(baseDir) | 292 locales = getLocales(baseDir) |
| 343 elif locales == 'all': | 293 elif locales == 'all': |
| 344 locales = getLocales(baseDir, True) | 294 locales = getLocales(baseDir, True) |
| 345 | 295 |
| 346 metadata = readMetadata(baseDir, type) | 296 metadata = readMetadata(baseDir, type) |
| 347 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) | 297 version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum) |
| 348 | 298 |
| 349 if outFile == None: | 299 if outFile == None: |
| 350 outFile = getDefaultFileName(metadata, version, 'xpi') | 300 outFile = getDefaultFileName(metadata, version, 'xpi') |
| (...skipping 21 matching lines...) Expand all Loading... |
| 372 for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): | 322 for name, path in getChromeSubdirs(baseDir, params['locales']).iteritems(): |
| 373 if os.path.isdir(path): | 323 if os.path.isdir(path): |
| 374 files.read(path, 'chrome/%s' % name, skip=skip) | 324 files.read(path, 'chrome/%s' % name, skip=skip) |
| 375 importLocales(params, files) | 325 importLocales(params, files) |
| 376 fixupLocales(params, files) | 326 fixupLocales(params, files) |
| 377 processJSONFiles(params, files) | 327 processJSONFiles(params, files) |
| 378 if not 'bootstrap.js' in files: | 328 if not 'bootstrap.js' in files: |
| 379 addMissingFiles(params, files) | 329 addMissingFiles(params, files) |
| 380 if metadata.has_section('preprocess'): | 330 if metadata.has_section('preprocess'): |
| 381 files.preprocess([f for f, _ in metadata.items('preprocess')]) | 331 files.preprocess([f for f, _ in metadata.items('preprocess')]) |
| 382 if keyFile: | |
| 383 signFiles(files, keyFile) | |
| 384 files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else
x) | 332 files.zip(outFile, sortKey=lambda x: '!' if x == 'META-INF/zigbert.rsa' else
x) |
| 385 | 333 |
| 386 | 334 |
| 387 def autoInstall(baseDir, type, host, port, multicompartment=False): | 335 def autoInstall(baseDir, type, host, port, multicompartment=False): |
| 388 fileBuffer = StringIO() | 336 fileBuffer = StringIO() |
| 389 createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multico
mpartment) | 337 createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multico
mpartment) |
| 390 urllib.urlopen('http://%s:%s/' % (host, port), data=fileBuffer.getvalue()) | 338 urllib.urlopen('http://%s:%s/' % (host, port), data=fileBuffer.getvalue()) |
| OLD | NEW |