Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: tools/crx_id/crx_id.py

Issue 16346003: Fix extension id calculation to take into account Windows encoding. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/crx_id/crx_id_unittest.py » ('j') | tools/telemetry/telemetry/core/extension_to_load.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/crx_id/crx_id.py
diff --git a/tools/crx_id/crx_id.py b/tools/crx_id/crx_id.py
index 5f8e2b227907fde1f204e14ef8f7ee696f9f695c..2bd13d70070baf070bf9c4e37145003193a009d7 100755
--- a/tools/crx_id/crx_id.py
+++ b/tools/crx_id/crx_id.py
@@ -75,7 +75,7 @@ def GetPublicKeyPacked(f):
pub_key = f.read(pub_key_len_bytes)
return pub_key
-def GetPublicKeyFromPath(filepath):
+def GetPublicKeyFromPath(filepath, encode_path_for_windows=False):
# Normalize the path for windows to have capital drive letters.
# We intentionally don't check if sys.platform == 'win32' and just
# check if this looks like drive letter so that we can test this
@@ -83,7 +83,15 @@ def GetPublicKeyFromPath(filepath):
if (len(filepath) >= 2 and
filepath[0].islower() and
filepath[1] == ':'):
- return filepath[0].upper() + filepath[1:]
+ filepath = filepath[0].upper() + filepath[1:]
+
+ # On Windows, filepaths are encoded using UTF-16, little endian byte order,
+ # using "wide characters" that are 16 bits in size. On POSIX systems, the
+ # encoding is generally UTF-8, which has the property of being equivalent to
+ # ASCII when only ASCII characters are in the path.
+ if encode_path_for_windows:
+ filepath = filepath.encode('utf-16le')
+
return filepath
def GetPublicKeyUnpacked(f, filepath):
@@ -102,9 +110,10 @@ def HasPublicKey(filename):
return 'key' in manifest
return False
-def GetPublicKey(filename, from_file_path):
+def GetPublicKey(filename, from_file_path, encode_path_for_windows=False):
achuithb 2013/06/04 18:33:29 encode_path_for_windows seems overly verbose. is_w
Tim Song 2013/06/05 18:36:27 Done.
if from_file_path:
- return GetPublicKeyFromPath(filename)
+ return GetPublicKeyFromPath(
+ filename, encode_path_for_windows=encode_path_for_windows)
pub_key = ''
if os.path.isdir(filename):
@@ -119,13 +128,15 @@ def GetPublicKey(filename, from_file_path):
f.close()
return pub_key
-def GetCRXHash(filename, from_file_path=False):
- pub_key = GetPublicKey(filename, from_file_path)
+def GetCRXHash(filename, from_file_path=False, encode_path_for_windows=False):
+ pub_key = GetPublicKey(filename, from_file_path,
+ encode_path_for_windows=encode_path_for_windows)
pub_key_hash = hashlib.sha256(pub_key).digest()
return HexTo256(pub_key_hash)
-def GetCRXAppID(filename, from_file_path=False):
- pub_key = GetPublicKey(filename, from_file_path)
+def GetCRXAppID(filename, from_file_path=False, encode_path_for_windows=False):
+ pub_key = GetPublicKey(filename, from_file_path,
+ encode_path_for_windows=encode_path_for_windows)
pub_key_hash = hashlib.sha256(pub_key).digest()
# AppID is the MPDecimal of only the first 128 bits of the hash.
return HexToMPDecimal(pub_key_hash[:128/8])
« no previous file with comments | « no previous file | tools/crx_id/crx_id_unittest.py » ('j') | tools/telemetry/telemetry/core/extension_to_load.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698