How to use the sshpubkeys.exceptions.InvalidTypeError 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 ojarva / python-sshpubkeys / tests / invalid_keys.py View on Github external
from sshpubkeys.exceptions import (InvalidKeyError, InvalidKeyLengthError, InvalidTypeError, MalformedDataError,
                                   TooLongKeyError, TooShortKeyError)

keys = [
    [
        "ssh-dss AAAAB3NzaC1kc3MAAACBAPlHIP5sD+T8/Sx1DGEiCzCXqpl7ww40jBg7wTkxu44OH6pNog5PjJt5M4NBULhKva/i+bhIM3ba+H1Or+aHWWFHACV6W2FCGk/k37ApRF8sIa4hsnN0P9qn6VfhbJKee+DBxa21WjjY/MZiljmJz7IQHx5RTxX9I/hJ7cL+aNmrAAAAFQCKteqc4IkgIrjpcpStsxYAhb3MqQAAAIEA+SfIKuTr7QPcinsZQDdmZOXqcg+u9TLzHA4c47y0Kns3T3BVPr9rWdmuh6eImzLO4wMLxLvcg3ecrqFuiCp1IHvXENkGlpB17S+uOXlVDY+sTdXyvYKRKirg5IZefIAP/m08c0QGkhFDbo4ysr9D5gXgH3LB2rMPIAbvMWm/HZQAAACBAKWtAE3hXRQX5KtI4AoIWVTly/6T4JNBt4u24ZRqV7X//CZEZ0cS5YpR/frlpUDI3WKoMtS+VmT3cBFZINashIxZyfBF8+0UX3s34HwNfp0hDW3ZdgZJU56GC2eclMantYGeVrMxgTQd80pxZFgByEhoXGeZaAwUzN8ULo9jHQo=",
        MalformedDataError, "too_short_data", ["loose", "strict"]
    ],
    [
        "ssh-dss AAAAB3NzaC1kc3MAAACBAPlHIP5sD+T8/Sx1DGEiCzCXqpl7ww40jBg7wTkxu44OH6pNog5PjJt5M4NBULhKva/i+bhIM3ba+H1Or+aHWWFHACV6W2FCGk/k37ApRF8sIa4hsnN0P9qn6VfhbJKee+DBxa21WjjY/MZiljmJz7IQHx5RTxX9I/hJ7cL+aNmrAAAAFQCKteqc4IkgIrjpcpStsxYAhb3MqQAAAIEA+SfIKuTr7QPcinsZQDdmZOXqcg+u9TLzHA4c47y0Kns3T3BVPr9rWdmuh6eImzLO4wMLxLvcg3ecrqFuiCp1IHvXENkGlpB17S+uOXlVDY+sTdXyvYKRKirg5IZefIAP/m08c0QGkhFDbo4ysr9D5gXgH3LB2rMPIAbvMWm/HZQAAACBAKWtAE3hXRQX5KtI4AoIWVTly/6T4JNBt4u24ZRqV7X//CZEZ0cS5YpR/frlpUDI3WKoMtS+VmT3cBFZINashIxZyfBF8+0UX3s34HwNfp0hDW3ZdgZJU56GC2eclMantYGeVrMxgTQd80pxZFgByEhoXGeZaAwUzN8ULo9jHQqMjA==",
        MalformedDataError, "too_long_data", ["loose", "strict"]
    ],
    [
        "ssh-dss AAAAB3NzaC1yc2EAAACBAPlHIP5sD+T8/Sx1DGEiCzCXqpl7ww40jBg7wTkxu44OH6pNog5PjJt5M4NBULhKva/i+bhIM3ba+H1Or+aHWWFHACV6W2FCGk/k37ApRF8sIa4hsnN0P9qn6VfhbJKee+DBxa21WjjY/MZiljmJz7IQHx5RTxX9I/hJ7cL+aNmrAAAAFQCKteqc4IkgIrjpcpStsxYAhb3MqQAAAIEA+SfIKuTr7QPcinsZQDdmZOXqcg+u9TLzHA4c47y0Kns3T3BVPr9rWdmuh6eImzLO4wMLxLvcg3ecrqFuiCp1IHvXENkGlpB17S+uOXlVDY+sTdXyvYKRKirg5IZefIAP/m08c0QGkhFDbo4ysr9D5gXgH3LB2rMPIAbvMWm/HZQAAACBAKWtAE3hXRQX5KtI4AoIWVTly/6T4JNBt4u24ZRqV7X//CZEZ0cS5YpR/frlpUDI3WKoMtS+VmT3cBFZINashIxZyfBF8+0UX3s34HwNfp0hDW3ZdgZJU56GC2eclMantYGeVrMxgTQd80pxZFgByEhoXGeZaAwUzN8ULo9jHQqM",
        InvalidTypeError, "key_type_mismatch", ["loose", "strict"]
    ],
    [
        "ssh-dss AAAAB3NzaC1yc2EAAAADA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T0PFD1is6JbtIk5i+liS+hiuzSF6NGouSuxDy95yWSG8/84fgPDFtvXtOD7Kl4P7EpEAL+VBZnremT9I8tRl1wOHxJKe7jbEcWC2zkuHNlju0Nv5SFijF9c+krRbHDYEzsxPpdqlI4gPtDFdkKwaKN6BrsxBsz9u+PhS1AloUYcxKRqWbqHuDBrKmxnhOgFqJ9ITX0RajtrApt1LfkSBXcFrVEx2nhQkGa6VwjcX/zw2I2iuJFOCQmc9udHIlyaCCSe1PqOIbOlOk5h/Gl1QvRNwSIgf9dZ05lZr6dc+VX8YGdyHsjQ==",
        InvalidTypeError, "rsa_key_no_match", ["loose", "strict"]
    ],
    [
        "ssh-dss AAAAB3NzaC1kc3MAAACAwQBAoKCAoECggSAgAOAAwOCg4AEAIMBAgMBAYSBg4GBggKAgwOBAwEDBAMCgwECg4GCBAAEhAABhIOCBIIEAQECg4GEAoQEgQQBgAGEAYQEAgCDAoCDgoIDBICAAAOCgwGDhAAAAwQEBIKCAYEBA4ODg4EDggSAgAGEgAQCAAOAAAAAgAAAAAAAAAAAAAAAAAACEAYKAgICCAIMAAYCBAYICAoAAAACAgKEgQCEhIKDgISCAAIDgwGEgASEg4GAgwQDAoCEAAEDBICDhAAABACCgIACBAIBAwOEgQEAA4KBBAOAAIIDAIQAgoGBgYGCgYCCAYEEgoEEgAABAIACAIAChAKCgoKAhIMDAgMEBIIDgAQEgwCDAAMBA4KAgACBAgCCgIGBAoGAAAACAwKAgAIBgIIBhAIBgQSAAgMAAQICggQDg4SCgoACgASCAwKCAYSAAoMCAYAEAoKBgoQEBIAAgICBAoMDBAMEgYIAgYKDggSDAoQDgQEAgAOBgQAAggQCAoCAgwAEBIEDgYABAgOEAwECAQECAAQDAAECBIGBAgEBA4AAgQSEBAKA=",
        InvalidKeyError, "invalid_q_for_dsa", ["loose", "strict"]
    ],
    [
        "ssh-dss AAAAB3NzaC1kc3MAAACAgIBAAIBgQJAwgJCAQCBwICAwYFAwcEBQMBBwUHAgcCAAkEAQQECQkBAgkGAwcEAAkIAAMAAwAJAAcABQQCAwIHAwIIAwYAAwICCQkAAAUHAwIBCAMBBQcCAQAFBggEBAQDAgIHAwUJAwkFCQUDBwkIAQEGAwICAQADAwcJAAEJAAAAAgAAAAAAAAAAAAAAAAhIIAggODBAAEgwIAhIGChIICBAAAAACAwQJBAcECQQBAQIGBAEHBQEGBgYCAAQGCAIECQMHBwAIAAIDBAMIBgEEAQADBwIDAgcABAYHBwMDAgcABQgABwAHAAkBBwYAAwYJBwgAAwQFCQICAQgFAQICAgAIAwQHBQYJBQADAgAIAgMHBwkJAQEFBAMGAQAGBQQHAggBAQIA=",
        MalformedDataError, "missing_y_from_dsa", ["loose", "strict"]
    ],
    [
        'ssh-dss AAAAB3NzaC1kc3MAAAIBANmIbHMDdrRAyd9rMdYoAAxxTIIke8xxS7txH16etsax8YlUEojvIEKRS/C5hulXw+fZYjdz0vjhTamoRo76ML2qz4X2lh96tJxoHVMVtXTdSDKfra4VuTp1mkYr6ycH9h7PEop+9WuB/Jx9ua/OCQ6cB6QePvg/XEaoKETHqrH7IilfJfBeLGgZc76q6+xjw5Qwtmu5nyImd17dWCa4ECdGw7NlbuuZHUs0/TfcJ/UHHuBgj1FKHEINBu3bcZdYKsyOm0VmxRw9Kkvh7qobBMXaNN9l3YvySTsSSbEWboK7jcFEC904i+hHxuYRa/K1x4v8SDaiOkxuJHGOCbfK/TaQdnyUBA2OEgt3MIuQGzc0xSXE5rEkLcjjkadkLA79Z/kajTNWzx54PT1qv6jP8kaa9OCzI+9aml+Lw2dtyDdBN3UDdSZj/823ABEm/zEgifziFrJbz32y3cdza9Jj/EcHCxDiN66Ghj2uLBERhXDxBWPZPoPlKeH+Bk/X/2CqA2H51RgLHtsVvqdrIWSXpAYYpGDaLnsG0yfsSrjGGIs6S9My+1ZSJPE0x568g6vbsTkuLJ70HwY4nhb/yuT0CuzPXsHnzKifzWMZldJki2KDowbJXye2ZJkz6PoknxC1ygT76AFxFvnZUHBMQQxrzV7j3op9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2jAh+60og6TVvpgOHhw+BGc6pBgzkxhY46MvgOuOSr7V9ikk6h11IFTn2wHTB14NibS+fA8NOadAHB6OklY7pEMgadSgFC3kOzKpHeoEPosnHr7TgtiGwOhfAVlr/DbsgQnoQaMHdMAaJ1iTAMhwDZNpFSzgU5WjUnMQjydJKkDo/3OUksrMyEXR4kHt0vbmLBKmUVSX02MpQqEzXNPqxEbjfg7jYezZfjbsN36bD87BLpjZhlxkDECvTKPD45Af3di0Cams7tlc0RJxnj8TvMhG9NTjsIjaqLGCLZHeF0rnWE9nteKO8JLGBXgv/12nOUy66NwIbiTohTJvsIYaIyXCA==',
        InvalidKeyLengthError, "too_long_dsa_4096", ["loose", "strict"]
github ojarva / python-sshpubkeys / sshpubkeys / keys.py View on Github external
if keydata.startswith("---- BEGIN SSH2 PUBLIC KEY ----"):
            # SSH2 key format
            key_type = None  # There is no redundant key-type field - skip comparing plain-text and encoded data.
            pubkey_content = "".join([line for line in keydata.split("\n") if ":" not in line and "----" not in line])
        else:
            key_parts = self._split_key(keydata)
            key_type = key_parts[0]
            pubkey_content = key_parts[1]

        self._decoded_key = self.decode_key(pubkey_content)

        # Check key type
        current_position, unpacked_key_type = self._unpack_by_int(self._decoded_key, 0)
        if key_type is not None and key_type != unpacked_key_type.decode():
            raise InvalidTypeError("Keytype mismatch: %s != %s" % (key_type, unpacked_key_type))

        self.key_type = unpacked_key_type

        key_data_length = self._process_key(self._decoded_key[current_position:])
        current_position = current_position + key_data_length

        if current_position != len(self._decoded_key):
            raise MalformedDataError("Leftover data: %s bytes" % (len(self._decoded_key) - current_position))

        if self.disallow_options and self.options:
            raise InvalidOptionsError("Options are disallowed.")