def IncrementalOTA_VerifyEnd(info): target_radio_img = FindRadio(info.target_zip) source_radio_img = FindRadio(info.source_zip) if not target_radio_img or not source_radio_img: return if source_radio_img != target_radio_img: info.script.CacheFreeSpaceCheck(len(source_radio_img)) radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) info.script.PatchCheck("%s:%s:%d:%s:%d:%s" % ( radio_type, radio_device, len(source_radio_img), common.sha1(source_radio_img).hexdigest(), len(target_radio_img), common.sha1(target_radio_img).hexdigest()))
def IncrementalOTA_VerifyEnd(info): try: target_radio_img = info.target_zip.read("RADIO/radio.img") source_radio_img = info.source_zip.read("RADIO/radio.img") except KeyError: # No source or target radio. Nothing to verify pass else: if source_radio_img != target_radio_img: info.script.CacheFreeSpaceCheck(len(source_radio_img)) radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) info.script.PatchCheck("%s:%s:%d:%s:%d:%s" % ( radio_type, radio_device, len(source_radio_img), common.sha1(source_radio_img).hexdigest(), len(target_radio_img), common.sha1(target_radio_img).hexdigest()))
def IncrementalOTA_VerifyEnd(info): target_radio_img = FindRadio(info.target_zip) if common.OPTIONS.full_radio: if not target_radio_img: assert False, "full radio option specified but no radio img found" else: return source_radio_img = FindRadio(info.source_zip) if not target_radio_img or not source_radio_img: return if source_radio_img != target_radio_img: info.script.CacheFreeSpaceCheck(len(source_radio_img)) radio_type, radio_device = common.GetTypeAndDevice("/radio", info.info_dict) info.script.PatchCheck("%s:%s:%d:%s:%d:%s" % ( radio_type, radio_device, len(source_radio_img), common.sha1(source_radio_img).hexdigest(), len(target_radio_img), common.sha1(target_radio_img).hexdigest()))
def WriteImageAssert(info, file_name, file_data, partition): checksum = common.sha1(file_data).hexdigest() file_size = len(file_data) info.script.AppendExtra('ifelse((sha1_check(read_file("EMMC:%s:%d:%s")) != ""),' '(ui_print("%s already up to date")),' '(package_extract_file("%s", "%s")));' % (partition, file_size, checksum, partition, file_name, partition))
def Add(self, cert, name=None): if cert in self.certs: if name: self.certs[cert] = self.certs[cert] + "," + name else: if name is None: name = "unknown cert %s (%s)" % (common.sha1(cert).hexdigest()[:12], GetCertSubject(cert)) self.certs[cert] = name
def q1(): # prints solution: 2203 15396F23938CD8E523F85D0C16A7D3BF4C922E5E ans = -1 for ii in range(10000): ii_hash = sha1(q1a_salt + str(ii).zfill(4).encode('utf-8')) if ii_hash == q1a_hash: ans = ii print(ii, ii_hash) return ans
def q2(guess=b'aaaaaa'): try: for guess in pw_gen(6, q1b_alpha, start=guess): guess_hash = sha1(q1b_salt + guess) if guess_hash == q1b_hash: print(guess, guess_hash) return guess except KeyboardInterrupt: print(guess) raise return None
def EspUpdateInit(info, incremental): global target_data global source_data global delete_files if incremental: target_data = LoadBootloaderFiles(info.target_zip) source_data = LoadBootloaderFiles(info.source_zip) else: target_data = LoadBootloaderFiles(info.input_zip) source_data = None diffs = [] for fn in sorted(target_data.keys()): tf = target_data[fn] if incremental: sf = source_data.get(fn, None) else: sf = None if sf is None: tf.AddToZip(info.output_zip) verbatim_targets.append(fn) elif tf.sha1 != sf.sha1: diffs.append(common.Difference(tf, sf)) if not incremental: return common.ComputeDifferences(diffs) for diff in diffs: tf, sf, d = diff.GetPatch() if d is None or len(d) > tf.size * 0.95: tf.AddToZip(info.output_zip) verbatim_targets.append(tf.name) else: common.ZipWriteStr(info.output_zip, "patch/" + tf.name + ".p", d) patch_list.append((tf.name, tf, sf, tf.size, common.sha1(d).hexdigest())) delete_files = (["/"+i[0] for i in verbatim_targets] + ["/"+i for i in sorted(source_data) if i not in target_data])
def FindLocalCerts(self): to_load = [] for top in OPTIONS.local_cert_dirs: for dirpath, _, filenames in os.walk(top): certs = [ os.path.join(dirpath, i) for i in filenames if i.endswith(".x509.pem") ] if certs: to_load.extend(certs) for i in to_load: with open(i) as f: cert = common.ParseCertificate(f.read()) name, _ = os.path.splitext(i) name, _ = os.path.splitext(name) cert_sha1 = common.sha1(cert).hexdigest() cert_subject = GetCertSubject(cert) self.Add(cert_sha1, cert_subject, name)
def ReadCertsDeprecated(self, full_filename): print("reading certs in deprecated way for {}".format(full_filename)) cert_digests = set() with zipfile.ZipFile(full_filename) as apk: for info in apk.infolist(): filename = info.filename if (filename.startswith("META-INF/") and info.filename.endswith((".DSA", ".RSA"))): pkcs7 = apk.read(filename) cert = CertFromPKCS7(pkcs7, filename) if not cert: continue cert_sha1 = common.sha1(cert).hexdigest() cert_subject = GetCertSubject(cert) ALL_CERTS.Add(cert_sha1, cert_subject) cert_digests.add(cert_sha1) if not cert_digests: AddProblem("No signature found") return self.cert_digests = frozenset(cert_digests)
def IncrementalEspUpdateInit(info): global target_data global source_data global delete_files global bootloader_update target_data = LoadBootloaderFiles(OPTIONS.target_tmp) source_data = LoadBootloaderFiles(OPTIONS.source_tmp) diffs = [] for fn in sorted(target_data.keys()): tf = target_data[fn] sf = source_data.get(fn, None) if sf is None: tf.AddToZip(info.output_zip) verbatim_targets.append(fn) elif tf.sha1 != sf.sha1: diffs.append(common.Difference(tf, sf)) common.ComputeDifferences(diffs) for diff in diffs: tf, sf, d = diff.GetPatch() if d is None or len(d) > tf.size * 0.95: tf.AddToZip(info.output_zip) verbatim_targets.append(tf.name) else: common.ZipWriteStr(info.output_zip, "patch/" + tf.name + ".p", d) patch_list.append( (tf.name, tf, sf, tf.size, common.sha1(d).hexdigest())) delete_files = ( ["/" + i[0] for i in verbatim_targets] + ["/" + i for i in sorted(source_data) if i not in target_data]) if (delete_files or patch_list or verbatim_targets or os.path.exists(os.path.join(OPTIONS.target_tmp, sfu_path))): print "EFI System Partition will be updated" bootloader_update = True
hgt.assertadmin([ 'dirstate', 'latest/big1', 'latest/big2']) hgt.assertpending([ 'big1', 'big1/ed4a77d1b56a118938788fc53037759b6c501e3d', 'big2', 'big2/2894ac4ba83af7de1cdcef23d72e68aed68b6624',]) hgt.assertcommitted([]) hgt.assertstandins([ 'big1', 'big2',]) hgt.announce('check hashes') hash = common.sha1('big1') hgt.assertequals(hash, common.sha1('.hg/bfiles/pending/big1/%s' % hash)) hgt.assertequals(hash + '\n', hgt.readfile('.hgbfiles/big1')) hgt.assertequals(hash + '\n', hgt.readfile('.hg/bfiles/latest/big1')) hgt.announce('modify big1 and bfrefresh') hgt.writefile('big1', 'x', mode='ab') hgt.hg(['bfrefresh', '-v'], stdout='big1\n' '1 big files refreshed\n') hgt.announce('check files created') hgt.hg(['bfstatus'], stdout='BPA big1\n' 'BPA big2\n') hgt.hg(['status'],