How to use the sshpubkeys.SSHKey function in sshpubkeys

To help you get started, we’ve selected a few sshpubkeys examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dropbox / merou / tests / setup.py View on Github external
def add_public_key_to_user(self, key, user):
        # type: (str, str) -> None
        sql_user = User.get(self.session, name=user)
        assert sql_user
        public_key = SSHKey(key, strict=True)
        public_key.parse()
        sql_public_key = PublicKey(
            user_id=sql_user.id,
            public_key=public_key.keydata.strip(),
            fingerprint=public_key.hash_md5().replace("MD5:", ""),
            fingerprint_sha256=public_key.hash_sha256().replace("SHA256:", ""),
            key_size=public_key.bits,
            key_type=public_key.key_type,
            comment=public_key.comment,
        )
        sql_public_key.add(self.session)
github ansible / ansible / lib / ansible / modules / cloud / cloudstack / cs_sshkeypair.py View on Github external
def _get_ssh_fingerprint(self, public_key):
        key = sshpubkeys.SSHKey(public_key)
        if hasattr(key, 'hash_md5'):
            return key.hash_md5().replace(to_native('MD5:'), to_native(''))
        return key.hash()
github futurice / futurice-ldap-user-manager / fum / models.py View on Github external
def min_bits(self):
        """
        The minimum number of bits considered secure for the type of this key.
        """
        k = sshpubkeys.SSHKey(self.key)
        return settings.SSH_KEY_MIN_BITS_FOR_TYPE.get(k.key_type,
                settings.SSH_KEY_MIN_BITS_DEFAULT)
github getway / diting / apps / users / models / user.py View on Github external
def public_key_obj(self):
        class PubKey(object):
            def __getattr__(self, item):
                return ''
        if self.public_key:
            import sshpubkeys
            try:
                return sshpubkeys.SSHKey(self.public_key)
            except (TabError, TypeError):
                pass
        return PubKey()
github zalando-stups / piu / piu / cli.py View on Github external
def check_ssh_key(key_path: str) -> bool:
    if key_path and os.path.exists(key_path):
        with open(key_path) as key:
            contents = key.read()
            key = sshpubkeys.SSHKey(contents)
            try:
                key.parse()
            except (sshpubkeys.InvalidKeyError, NotImplementedError) as e:
                return False
        return True
    return False
github 0x27 / ssh_keyscanner / keyscanner.py View on Github external
def pubkey_to_fingerprint(pubkey): # done
    # converts pubkey in ssh-rsa BASE64SHIT to fingerprint
    try:
        msg_debug("Creating SSH key fingerprint")
        ssh = SSHKey(pubkey)
        fingerprint = ssh.hash()
        return fingerprint
    except Exception, e:
        msg_debug(e)
        msg_fail("ssh fingerprint generation failed.")