示例#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)
示例#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"-_")
示例#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"])
示例#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
示例#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)
示例#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"))
示例#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)
示例#8
0
 def b64decode(b):
     return _b64decode(b.encode("ascii"))
示例#9
0
 def b64decode(b):
     return _b64decode(b.encode("ascii"))
示例#10
0
def b64decode(data):
    missing_padding = len(data) % 4
    if missing_padding:
        data += '=' * (4 - missing_padding)
    return _b64decode(data)
示例#11
0
文件: Compat.py 项目: danfoster/bcfg2
 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'))
示例#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
示例#14
0
文件: _compat.py 项目: ardeois/beaker
 def b64decode(b):
     return _b64decode(b.encode('ascii'))
示例#15
0
文件: Compat.py 项目: zenazn/bcfg2
    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
示例#16
0
文件: util.py 项目: afgane/pulsar
 def b64decode(val, **kwargs):
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
示例#17
0
def getSecret():
    return _b64decode(_current_app.config.get('SECRET_KEY'))
示例#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
示例#19
0
def b64decode(s):
    return _b64decode(s).decode('utf-8')
示例#20
0
文件: util.py 项目: cganote/pulsar
 def b64decode(val, **kwargs):
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
示例#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
示例#22
0
 def b64decode(val, **kwargs):  # pylint: disable=C0111
     return _b64decode(val.encode('UTF-8'), **kwargs).decode('UTF-8')
示例#23
0
def b64decode(s):
    return _b64decode(s).decode('utf-8')