示例#1
0
    def __init__(self, ssh_public_key):
        """
        Extracts the useful ED25519 Public Key information from an SSH Public Key file.
        :param ssh_public_key: SSH Public Key file contents. (i.e. 'ssh-ed25519 AAAAB3NzaC1yc2E..').
        """
        super(ED25519PublicKey, self).__init__()

        self.type = SSHPublicKeyType.ED25519

        split_ssh_public_key = ssh_public_key.split(' ')
        split_key_len = len(split_ssh_public_key)

        # is there a key comment at the end?
        if split_key_len > 2:
            self.key_comment = ' '.join(split_ssh_public_key[2:])
        else:
            self.key_comment = ''

        # hazmat does not support ed25519 so we have out own loader based on serialization.load_ssh_public_key

        if split_key_len < 2:
            raise ValueError(
                'Key is not in the proper format or contains extra data.')

        key_type = split_ssh_public_key[0]
        key_body = split_ssh_public_key[1]

        if key_type != SSHPublicKeyType.ED25519:
            raise TypeError("Public Key is not the correct type or format")

        try:
            decoded_data = base64.b64decode(key_body)
        except TypeError:
            raise ValueError('Key is not in the proper format.')

        inner_key_type, rest = serialization._ssh_read_next_string(
            decoded_data)

        if inner_key_type != key_type:
            raise ValueError(
                'Key header and key body contain different key type values.')

        # ed25519 public key is a single string https://tools.ietf.org/html/rfc8032#section-5.1.5
        self.a, rest = serialization._ssh_read_next_string(rest)

        key_bytes = base64.b64decode(split_ssh_public_key[1])
        fingerprint = hashlib.md5(key_bytes).hexdigest()

        self.fingerprint = 'ED25519 ' + ':'.join(
            fingerprint[i:i + 2] for i in range(0, len(fingerprint), 2))
示例#2
0
    def __init__(self, ssh_public_key):
        """
        Extracts the useful ED25519 Public Key information from an SSH Public Key file.
        :param ssh_public_key: SSH Public Key file contents. (i.e. 'ssh-ed25519 AAAAB3NzaC1yc2E..').
        """
        super(ED25519PublicKey, self).__init__()

        self.type = SSHPublicKeyType.ED25519

        split_ssh_public_key = ssh_public_key.split(' ')
        split_key_len = len(split_ssh_public_key)

        # is there a key comment at the end?
        if split_key_len > 2:
            self.key_comment = ' '.join(split_ssh_public_key[2:])
        else:
            self.key_comment = ''

        # hazmat does not support ed25519 so we have out own loader based on serialization.load_ssh_public_key

        if split_key_len < 2:
            raise ValueError(
                'Key is not in the proper format or contains extra data.')

        key_type = split_ssh_public_key[0]
        key_body = split_ssh_public_key[1]

        if key_type != SSHPublicKeyType.ED25519:
            raise TypeError("Public Key is not the correct type or format")

        try:
            decoded_data = base64.b64decode(key_body)
        except TypeError:
            raise ValueError('Key is not in the proper format.')

        inner_key_type, rest = serialization._ssh_read_next_string(decoded_data)

        if inner_key_type != key_type.encode("utf-8"):
            raise ValueError(
                'Key header and key body contain different key type values.'
            )

        # ed25519 public key is a single string https://tools.ietf.org/html/rfc8032#section-5.1.5
        self.a, rest = serialization._ssh_read_next_string(rest)

        key_bytes = base64.b64decode(split_ssh_public_key[1])
        fingerprint = hashlib.md5(key_bytes).hexdigest()

        self.fingerprint = 'ED25519 ' + ':'.join(
            fingerprint[i:i + 2] for i in range(0, len(fingerprint), 2))
def extract_nonce_from_cert(cert_file):
    cert = cert_file.split(' ')[1]
    cert_type, cert_remainder = _ssh_read_next_string(base64.b64decode(cert))
    nonce, cert_remainder = _ssh_read_next_string(cert_remainder)
    return nonce
def extract_nonce_from_cert(cert_file):
    cert = cert_file.split(' ')[1]
    cert_type, cert_remainder = _ssh_read_next_string(base64.b64decode(cert))
    nonce, cert_remainder = _ssh_read_next_string(cert_remainder)
    return nonce