| LEFT | RIGHT |
| 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 ConfigParser | 6 import ConfigParser |
| 6 import json | 7 import json |
| 7 import os | 8 import os |
| 8 import re | 9 import re |
| 9 from urlparse import urlparse | 10 from urlparse import urlparse |
| 10 | 11 |
| 11 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl
ate, Files | 12 from packager import readMetadata, getDefaultFileName, getBuildVersion, getTempl
ate, Files |
| 12 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa
ckageFiles, defaultLocale, createScriptPage | 13 from packagerChrome import convertJS, importGeckoLocales, getIgnoredFiles, getPa
ckageFiles, defaultLocale, createScriptPage |
| 13 | 14 |
| 14 | 15 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 def fixAbsoluteUrls(files): | 103 def fixAbsoluteUrls(files): |
| 103 for filename, content in files.iteritems(): | 104 for filename, content in files.iteritems(): |
| 104 if os.path.splitext(filename)[1].lower() == '.html': | 105 if os.path.splitext(filename)[1].lower() == '.html': |
| 105 files[filename] = re.sub( | 106 files[filename] = re.sub( |
| 106 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', | 107 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', |
| 107 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), | 108 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), |
| 108 content, re.S | re.I | 109 content, re.S | re.I |
| 109 ) | 110 ) |
| 110 | 111 |
| 111 | 112 |
| 113 def _get_sequence(data): |
| 114 from Crypto.Util import asn1 |
| 115 sequence = asn1.DerSequence() |
| 116 sequence.decode(data) |
| 117 return sequence |
| 118 |
| 119 |
| 112 def get_developer_identifier(certs): | 120 def get_developer_identifier(certs): |
| 113 from Crypto.Util import asn1 | |
| 114 def get_sequence(data): | |
| 115 sequence = asn1.DerSequence() | |
| 116 sequence.decode(data) | |
| 117 return sequence | |
| 118 | |
| 119 for cert in certs: | 121 for cert in certs: |
| 120 # See https://tools.ietf.org/html/rfc5280#section-4 | 122 # See https://tools.ietf.org/html/rfc5280#section-4 |
| 121 tbsCertificate = get_sequence(cert)[0] | 123 tbscertificate = _get_sequence(base64.b64decode(cert))[0] |
| 122 subject = get_sequence(tbsCertificate)[5] | 124 subject = _get_sequence(tbscertificate)[5] |
| 123 | 125 |
| 124 # We could decode the subject but since we have to apply a regular | 126 # We could decode the subject but since we have to apply a regular |
| 125 # expression on CN entry anyway we can just skip that. | 127 # expression on CN entry anyway we can just skip that. |
| 126 m = re.search(r'Safari Developer: \((\S*?)\)', subject) | 128 m = re.search(r'Safari Developer: \((\S*?)\)', subject) |
| 127 if m: | 129 if m: |
| 128 return m.group(1) | 130 return m.group(1) |
| 129 | 131 |
| 130 raise Exception('No Safari developer certificate found in chain') | 132 raise Exception('No Safari developer certificate found in chain') |
| 131 | 133 |
| 132 | 134 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 163 | 165 |
| 164 if metadata.has_section('import_locales'): | 166 if metadata.has_section('import_locales'): |
| 165 importGeckoLocales(params, files) | 167 importGeckoLocales(params, files) |
| 166 | 168 |
| 167 if metadata.has_option('general', 'testScripts'): | 169 if metadata.has_option('general', 'testScripts'): |
| 168 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp
l', | 170 files['qunit/index.html'] = createScriptPage(params, 'testIndex.html.tmp
l', |
| 169 ('general', 'testScripts')) | 171 ('general', 'testScripts')) |
| 170 | 172 |
| 171 if keyFile: | 173 if keyFile: |
| 172 from buildtools import xarfile | 174 from buildtools import xarfile |
| 173 certs = xarfile.read_certificates(keyFile) | 175 certs, key = xarfile.read_certificates_and_key(keyFile) |
| 174 params['developerIdentifier'] = get_developer_identifier(certs) | 176 params['developerIdentifier'] = get_developer_identifier(certs) |
| 175 | 177 |
| 176 files['lib/info.js'] = createInfoModule(params) | 178 files['lib/info.js'] = createInfoModule(params) |
| 177 files['background.html'] = createScriptPage(params, 'background.html.tmpl', | 179 files['background.html'] = createScriptPage(params, 'background.html.tmpl', |
| 178 ('general', 'backgroundScripts')
) | 180 ('general', 'backgroundScripts')
) |
| 179 files['Info.plist'] = createManifest(params, files) | 181 files['Info.plist'] = createManifest(params, files) |
| 180 | 182 |
| 181 fixAbsoluteUrls(files) | 183 fixAbsoluteUrls(files) |
| 182 | 184 |
| 183 dirname = metadata.get('general', 'basename') + '.safariextension' | 185 dirname = metadata.get('general', 'basename') + '.safariextension' |
| 184 for filename in files.keys(): | 186 for filename in files.keys(): |
| 185 files[os.path.join(dirname, filename)] = files.pop(filename) | 187 files[os.path.join(dirname, filename)] = files.pop(filename) |
| 186 | 188 |
| 187 if not devenv and keyFile: | 189 if not devenv and keyFile: |
| 188 from buildtools import xarfile | 190 from buildtools import xarfile |
| 189 xarfile.create(outFile, files, keyFile) | 191 xarfile.create(outFile, files, keyFile) |
| 190 else: | 192 else: |
| 191 files.zip(outFile) | 193 files.zip(outFile) |
| LEFT | RIGHT |