Ejemplo n.º 1
0
    def _process_tokens(self, input, affordances):

        handler = self.service.current_tornado_request_handler

        try:
            authz_header_value = handler.request.headers['Authorization']
        except KeyError:
            raise _exc.NoValidTokensScanned\
                   (self, 'no Authorization header field')
        match = self._AUTHORIZATION_HEADER_RE.match(authz_header_value)

        if not match:
            raise _exc.NoValidTokensScanned\
                   (self, 'unrecognized Authorization header field value')

        creds_base64 = match.group('creds_base64')
        try:
            creds = _b64decode(creds_base64)
        except TypeError:
            raise _exc.NoValidTokensScanned\
                   (self, 'credentials string is not a valid Base64 string')

        try:
            user, password = creds.split(':', 1)
        except ValueError:
            raise _exc.NoValidTokensScanned\
                   (self, 'invalid decoded credentials string')

        tokens = {'user': user, 'password': password}
        return _info.RequestAuthInfo(tokens=tokens,
                                     provisions=_plain.PlainAuth.PROVISIONS)
Ejemplo n.º 2
0
def urlsafe_b64decode(s):
    """
    Like ``base64.b64decode`` but with validation.
    """
    if not _b64decode_validator.match(s):
        raise Error('Non-base64 digit found')
    return _b64decode(s, altchars=b"-_")
Ejemplo n.º 3
0
    def load_from_file(metadatafile):
        """Loads the metadata from a file.

        Args:
            metadatafile (path): The path for the metadatafile.

        Returns:
            The MixSliceMetadata object created from reading the file.
        """
        with open(metadatafile, "r") as fp:
            metadata = _json.load(fp)

        return _MixSliceMetadata(
            key=_b64decode(metadata["key"].encode("ascii")),
            iv=_b64decode(metadata["iv"].encode("ascii")),
            rsakey=_RSA.importKey(metadata["rsakey"].encode("ascii")),
            order=metadata["order"],
            state=metadata["state"])
Ejemplo n.º 4
0
    def download_screenshot(self, data_uri):
        result = self.window.create_file_dialog(
            dialog_type=webview.SAVE_DIALOG,
            save_filename=config.app_configurations.default_download_filename)
        header, encoded = data_uri.split(",", 1)
        data = _b64decode(encoded)

        if isinstance(result, tuple):
            result = result[0]
        with open(result, "wb") as f:
            f.write(data)
        return None
Ejemplo n.º 5
0
def b64decode(obj: Union[str, bytes], encoding="utf-8") -> str:
    """HTML unescape encoded string

    Args:
        s: string or bytes to decode

    Returns:
        str: decoded string
    """
    _obj = obj
    if not isinstance(obj, bytes):
        _obj = str(obj).encode(encoding)
    return _b64decode(_obj).decode(encoding)
Ejemplo n.º 6
0
def decrypt(cipher: str, key: str, base64=True) -> str:
    """Decrypt strings using Vigenere Cipher

    Args:
        cipher (str): Encrypted plain text that needs to be decrypted.
        key (str): Key for vigenere cipher
        base64 (bool): Set to true if the cipher text is encoded in base64.
        Defaults to True.

    Returns:
        str: Deciphered Text
    """
    if base64:
        cipher = _b64decode(cipher.encode()).decode()
    return str(_transform(cipher, key, mode="decrypt"))
Ejemplo n.º 7
0
    def _process_tokens(self, input, affordances):

        handler = self.service.current_tornado_request_handler

        try:
            authz_header_value = handler.request.headers['Authorization']
        except KeyError:
            raise _exc.NoValidTokensScanned\
                   (self, 'no Authorization header field')
        match = self._AUTHORIZATION_HEADER_RE.match(authz_header_value)

        if not match:
            raise _exc.NoValidTokensScanned\
                   (self, 'unrecognized Authorization header field value')

        tokens = {}
        for name in self._DIGEST_USER_REQUIRED_TOKENS:
            token = match.group(name)

            if token is None:
                raise _exc.NoValidTokensScanned\
                       (self,
                        'missing required authentication token {!r}'
                         .format(name))

            tokens[name] = token
        for name in self._DIGEST_USER_OPTIONAL_TOKENS:
            token = match.group(name)
            if token is not None:
                tokens[name] = token
        opaque_data = match.group('opaque')
        if opaque_data is not None:
            tokens['__'] = _b64decode(opaque_data)

        provisions = None
        if all(token in tokens
               for token in _digest.DigestAuth.TOKENS_NO_QOP):
            provisions = _digest.DigestAuth.PROVISIONS_NO_QOP
            if all(token in tokens
                   for token in _digest.DigestAuth.TOKENS_QOP_AUTH):
                provisions = _digest.DigestAuth.PROVISIONS_QOP_AUTH
                if all(token in tokens
                       for token in _digest.DigestAuth.TOKENS_QOP_AUTH_INT):
                    provisions = _digest.DigestAuth.PROVISIONS_QOP_AUTH_INT

        return _info.RequestAuthInfo(tokens=tokens, provisions=provisions)
Ejemplo n.º 8
0
 def b64decode(b):
     return _b64decode(b.encode("ascii"))
Ejemplo n.º 9
0
 def b64decode(b):
     return _b64decode(b.encode("ascii"))
Ejemplo n.º 10
0
def b64decode(data):
    missing_padding = len(data) % 4
    if missing_padding:
        data += '=' * (4 - missing_padding)
    return _b64decode(data)
Ejemplo n.º 11
0
 def b64decode(val, **kwargs):  # pylint: disable=C0111
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
 def b64decode(b):
     return _b64decode(b.encode('ascii'))
Ejemplo n.º 13
0
        if encoding is not None:
            return string.encode(encoding)
        else:
            return string
    else:
        if encoding is not None:
            return unicode(string, encoding)
        else:
            return unicode(string)


# base64 compat
if sys.hexversion >= 0x03000000:
    from base64 import b64encode as _b64encode, b64decode as _b64decode
    b64encode = lambda s: _b64encode(s.encode('UTF-8')).decode('UTF-8')
    b64decode = lambda s: _b64decode(s.encode('UTF-8')).decode('UTF-8')
else:
    from base64 import b64encode, b64decode

try:
    input = raw_input
except NameError:
    input = input

try:
    reduce = reduce
except NameError:
    from functools import reduce

try:
    from collections import MutableMapping
Ejemplo n.º 14
0
 def b64decode(b):
     return _b64decode(b.encode('ascii'))
Ejemplo n.º 15
0
    if sys.hexversion >= 0x03000000:
        if encoding is not None:
            return string.encode(encoding)
        else:
            return string
    else:
        if encoding is not None:
            return unicode(string, encoding)
        else:
            return unicode(string)

# base64 compat
if sys.hexversion >= 0x03000000:
    from base64 import b64encode as _b64encode, b64decode as _b64decode
    b64encode = lambda s: _b64encode(s.encode('UTF-8')).decode('UTF-8')
    b64decode = lambda s: _b64decode(s.encode('UTF-8')).decode('UTF-8')
else:
    from base64 import b64encode, b64decode

try:
    input = raw_input
except NameError:
    input = input

try:
    reduce = reduce
except NameError:
    from functools import reduce

try:
    from collections import MutableMapping
Ejemplo n.º 16
0
 def b64decode(val, **kwargs):
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
Ejemplo n.º 17
0
def getSecret():
    return _b64decode(_current_app.config.get('SECRET_KEY'))
Ejemplo n.º 18
0
            return string
    else:
        if encoding is not None:
            return unicode(string, encoding)
        else:
            return unicode(string)

try:
    unicode = unicode
except:
    unicode = str

# base64 compat
from base64 import b64encode as _b64encode, b64decode as _b64decode
b64encode = lambda s: _b64encode(s.encode('ascii')).decode('ascii')
b64decode = lambda s: _b64decode(s.encode('ascii')).decode('ascii')

try:
    input = raw_input
except:
    input = input

try:
    reduce = reduce
except NameError:
    from functools import reduce

try:
    from collections import MutableMapping
except ImportError:
    from UserDict import DictMixin as MutableMapping
Ejemplo n.º 19
0
def b64decode(s):
    return _b64decode(s).decode('utf-8')
Ejemplo n.º 20
0
 def b64decode(val, **kwargs):
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
Ejemplo n.º 21
0
            return string.encode(encoding)
        else:
            return string
    else:
        if encoding is not None:
            return unicode(string, encoding)
        else:
            return unicode(string)


# base64 compat
if sys.hexversion >= 0x03000000:
    from base64 import b64encode as _b64encode, b64decode as _b64decode

    b64encode = lambda s: _b64encode(s.encode("UTF-8")).decode("UTF-8")
    b64decode = lambda s: _b64decode(s.encode("UTF-8")).decode("UTF-8")
else:
    from base64 import b64encode, b64decode

try:
    input = raw_input
except NameError:
    input = input

try:
    reduce = reduce
except NameError:
    from functools import reduce

try:
    from collections import MutableMapping
Ejemplo n.º 22
0
 def b64decode(val, **kwargs):  # pylint: disable=C0111
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
Ejemplo n.º 23
0
def b64decode(s):
    return _b64decode(s).decode('utf-8')