Exemplo n.º 1
0
    def load_private_key(self):
        """
        Loads private key and public key from path.

        Returns:
            True on successs, False otherwise
        """

        if self.path == '' or self.suffix == '':
            return False
        # Load public key
        self.load_public_key(from_private=True)

        file_path = self.path + '/private_%s.pem' % self.suffix

        p_file = _libc.fopen(ctypes.c_char_p(bytes(file_path.encode('utf-8'))),
                             ctypes.c_char_p(b'r'))

        _ssl.PEM_read_RSAPrivateKey(p_file, ctypes.byref(self.key), None, None)

        # Cleanup
        _libc.fclose(p_file)

        # Turn on blinding
        if _ssl.RSA_blinding_on(self.key, None) != 1:
            logging.debug('This message should go to the log file')
            return False

        self.is_private = True

        return True
Exemplo n.º 2
0
    def load_public_key(self, from_private=False):
        """
        Loads public key from path.

        Returns:
            True on success, False otherwise
        """

        if self.path == '' or self.suffix == '':
            return False

        file_path = self.path + '/public_%s.pem' % self.suffix

        p_file = _libc.fopen(ctypes.c_char_p(file_path.encode('utf-8')),
                             ctypes.c_char_p(b'r'))

        _ssl.PEM_read_RSAPublicKey(p_file, ctypes.byref(self.key), None, None)

        # Cleanup
        _libc.fclose(p_file)

        # Turn on blinding
        if not from_private and _ssl.RSA_blinding_on(self.key, None) != 1:
            logging.debug('Failed to turn on blinding for RSA key')
            return False

        self.size = _ssl.RSA_size(self.key)
        self.bn_n = self._get_mod()

        return True