コード例 #1
0
ファイル: crypto.py プロジェクト: be-engineer/winpdb
    def __encrypt(self, s):
        s_padded = s + as_bytes('\x00') * (DES.block_size -
                                           (len(s) % DES.block_size))

        key_padded = (self.m_key + as_bytes('0') *
                      (DES.key_size -
                       (len(self.m_key) % DES.key_size)))[:DES.key_size]
        iv = as_bytes('0') * DES.block_size

        d = DES.new(key_padded, DES.MODE_CBC, iv)
        r = d.encrypt(s_padded)

        return r
コード例 #2
0
ファイル: crypto.py プロジェクト: be-engineer/winpdb
    def __decrypt(self, s):
        try:
            key_padded = (self.m_key + as_bytes('0') *
                          (DES.key_size -
                           (len(self.m_key) % DES.key_size)))[:DES.key_size]
            iv = as_bytes('0') * DES.block_size

            d = DES.new(key_padded, DES.MODE_CBC, iv)
            _s = d.decrypt(s).strip(as_bytes('\x00'))

            return _s

        except:
            self.__wait_a_little()
            raise DecryptionFailure
コード例 #3
0
def source_provider_filesystem(filename):
    l = mygetfile(filename)

    if l[:3] == as_bytes(ENCODING_UTF8_PREFIX_1):
        l = l[3:]

    return l
コード例 #4
0
ファイル: crypto.py プロジェクト: be-engineer/winpdb
    def __calc_key(self, _rpdb2_pwd):
        """
        Create and return a key from a password.
        A Weak password means a weak key.
        """

        if _rpdb2_pwd in CCrypto.m_keys:
            return CCrypto.m_keys[_rpdb2_pwd]

        key = as_bytes(_rpdb2_pwd)
        suffix = key[:16]

        d = hmac.new(key, digestmod=_md5)

        #
        # The following loop takes around a second to complete
        # and should strengthen the password by ~12 bits.
        # a good password is ~30 bits strong so we are looking
        # at ~42 bits strong key
        #
        for i in range(2**12):
            d.update((key + suffix) * 16)
            key = d.digest()

        CCrypto.m_keys[_rpdb2_pwd] = key

        return key
コード例 #5
0
    def __client(self):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.settimeout(self.m_timeout)

        try:
            try:
                s.connect((LOOPBACK, CFirewallTest.m_port))

                s.send(as_bytes('Hello, world'))
                data = self.__recv(s, 1024)
                self.m_result = True

            except socket.error:
                e = sys.exc_info()[1]
                self.m_last_client_error = e
                self.m_result = False

        finally:
            s.close()
コード例 #6
0
def ParseEncoding(txt):
    """
    Parse document encoding according to:
    http://docs.python.org/ref/encodings.html
    """

    eol = '\n'
    if not is_unicode(txt):
        eol = as_bytes('\n')

    l = txt.split(eol, 20)[:-1]

    for line in l:
        line = as_unicode(line)
        encoding = ParseLineEncoding(line)
        if encoding is not None:
            try:
                codecs.lookup(encoding)
                return encoding

            except:
                return 'utf-8'

    return 'utf-8'
コード例 #7
0
ファイル: crypto.py プロジェクト: be-engineer/winpdb
    def undo_crypto(self, fencrypt, fcompress, digest, msg, fVerifyIndex=True):
        """
        Take crypto string, verify its signature and decrypt it, if
        needed.
        """

        if not fencrypt and not self.m_fAllowUnencrypted:
            raise EncryptionExpected

        if fencrypt and not is_encryption_supported():
            raise EncryptionNotSupported

        s = as_bytes(msg)
        s = base64_decodestring(s)

        if fencrypt:
            s = self.__decrypt(s)

        if fcompress:
            s = zlib.decompress(s)

        args, id = self.__verify_signature(digest, s, fVerifyIndex)

        return (args, id)
コード例 #8
0
import sys, os

from rpdb.utils import as_unicode, is_unicode, print_debug_exception, ENCODING_RAW_I, as_bytes
from rpdb.compat import sets, unicode


def is_py3k():
    return sys.version_info[0] >= 3


DEFAULT_PATH_SUFFIX_LENGTH = 55

ELLIPSIS_UNICODE = as_unicode('...')
ELLIPSIS_BYTES = as_bytes('...')


def calc_suffix(_str, n):
    """
    Return an n charaters suffix of the argument string of the form
    '...suffix'.
    """

    if len(_str) <= n:
        return _str

    return '...' + _str[-(n - 3):]


def class_name(c):
    s = safe_str(c)