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

Unified Diff: packagerChrome.py

Issue 29349869: Issue 4339 - Replace M2Crypto by PyCrypto (Closed)
Patch Set: Created Aug. 16, 2016, 2:59 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | packagerSafari.py » ('j') | packagerSafari.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packagerChrome.py
===================================================================
--- a/packagerChrome.py
+++ b/packagerChrome.py
@@ -1,19 +1,20 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-import sys
+import errno
+import io
+import json
import os
import re
-import json
+from StringIO import StringIO
import struct
-import io
-from StringIO import StringIO
+import sys
import packager
from packager import readMetadata, getMetadataPath, getDefaultFileName, getBuildVersion, getTemplate, Files
defaultLocale = 'en_US'
def getIgnoredFiles(params):
@@ -290,28 +291,37 @@ def fixTranslationsForCWS(files):
data.setdefault(name, info)
for name, limit in limits.iteritems():
if name in data:
data[name]['message'] = truncate(data[name]['message'], limit)
files[filename] = toJson(data)
def signBinary(zipdata, keyFile):
- import M2Crypto
- if not os.path.exists(keyFile):
- M2Crypto.RSA.gen_key(1024, 65537, callback=lambda x: None).save_key(keyFile, cipher=None)
- key = M2Crypto.EVP.load_key(keyFile)
- key.sign_init()
- key.sign_update(zipdata)
- return key.final()
+ from Crypto.Hash import SHA
+ from Crypto.PublicKey import RSA
+ from Crypto.Signature import PKCS1_v1_5
+
+ try:
+ with open(keyFile, 'rb') as file:
+ key = RSA.importKey(file.read())
+ except IOError as e:
+ if e.errno != errno.ENOENT:
+ raise
+ key = RSA.generate(2048)
+ with open(keyFile, 'wb') as file:
+ file.write(key.exportKey('PEM'))
+
+ return PKCS1_v1_5.new(key).sign(SHA.new(zipdata))
def getPublicKey(keyFile):
- import M2Crypto
- return M2Crypto.EVP.load_key(keyFile).as_der()
+ from Crypto.PublicKey import RSA
+ with open(keyFile, 'rb') as file:
+ return RSA.importKey(file.read()).publickey().exportKey('DER')
def writePackage(outputFile, pubkey, signature, zipdata):
if isinstance(outputFile, basestring):
file = open(outputFile, 'wb')
else:
file = outputFile
if pubkey != None and signature != None:
« no previous file with comments | « no previous file | packagerSafari.py » ('j') | packagerSafari.py » ('J')

Powered by Google App Engine
This is Rietveld