Example #1
0
    def parse(self):
        super().parse()

        i = 1
        self.reason_code = struct.unpack(">L", self.buf[i:i+4])[0]
        i += 4
        l, self.description = sshtype.parseString(self.buf[i:])
        i += l
        l, self.language_code = sshtype.parseString(self.buf[i:])
Example #2
0
    def parse(self):
        super().parse()

        i = 1
        self.reason_code = struct.unpack(">L", self.buf[i:i + 4])[0]
        i += 4
        l, self.description = sshtype.parseString(self.buf[i:])
        i += l
        l, self.language_code = sshtype.parseString(self.buf[i:])
Example #3
0
    def __init__(self, data=None, privdata=None, filename=None, password=None, vals=None, file_obj=None):
        self.n = None
        self.e = None
        self.d = None
        self.p = None
        self.q = None

        self.__public_key = None
        self.__public_key_bytes = None
        self.__private_key = None
        self.__rsassa_pss_signer = None
        self.__rsassa_pss_verifier = None

        if file_obj is not None:
            self._from_private_key(file_obj, password)
            return
        if filename is not None:
            self._from_private_key_file(filename, password)
            return
        if vals is not None:
            self.e, self.n = vals
        else:
            if data is None:
                if privdata is None:
                    raise SshException('Key object may not be empty')
                else:
                    self._decode_key(privdata)
            else:
                i, v = sshtype.parseString(data)
                if v != 'ssh-rsa':
                    raise SshException('Invalid key')
                l, self.e = sshtype.parseMpint(data[i:])
                i += l
                l, self.n = sshtype.parseMpint(data[i:])
        self.size = util.bit_length(self.n)
Example #4
0
    def parse(self):
        super().parse()

        i = 1
        l, self.algorithm_name = sshtype.parseString(self.buf[i:])
        i += l
        l, self.public_key = sshtype.parseBinary(self.buf[i:])
Example #5
0
    def parse(self):
        super().parse()

        i = 1
        l, self.algorithm_name = sshtype.parseString(self.buf[i:])
        i += l
        l, self.public_key = sshtype.parseBinary(self.buf[i:])
Example #6
0
    def __init__(self, data=None, privdata=None, filename=None, password=None, vals=None, file_obj=None):
        self.n = None
        self.e = None
        self.d = None
        self.p = None
        self.q = None

        self.__public_key = None
        self.__private_key = None
        self.__rsassa_pss_signer = None
        self.__rsassa_pss_verifier = None

        if file_obj is not None:
            self._from_private_key(file_obj, password)
            return
        if filename is not None:
            self._from_private_key_file(filename, password)
            return
        if vals is not None:
            self.e, self.n = vals
        else:
            if data is None:
                if privdata is None:
                    raise SshException("Key object may not be empty")
                else:
                    self._decode_key(privdata)
            else:
                i, v = sshtype.parseString(data)
                if v != "ssh-rsa":
                    raise SshException("Invalid key")
                l, self.e = sshtype.parseMpint(data[i:])
                i += l
                l, self.n = sshtype.parseMpint(data[i:])
        self.size = util.bit_length(self.n)
Example #7
0
 def channel_request(self, peer, msg):
     if msg.request_type == "shell":
         shell = self.shells.get(msg.recipient_channel)
         if not shell:
             return
         asyncio. async (shell.cmdloop(), loop=self.loop)
     elif msg.request_type == "exec":
         shell = self.shells.get(msg.recipient_channel)
         if not shell:
             return
         l, cmd = sshtype.parseString(msg.payload)
         asyncio. async (self._shell_exec(shell, cmd), loop=self.loop)
Example #8
0
    def parse(self):
        super().parse()

        i = 1
        l, self.user_name = sshtype.parseString(self.buf[i:])
        i += l
        l, self.service_name = sshtype.parseString(self.buf[i:])
        i += l
        l, self.method_name = sshtype.parseString(self.buf[i:])
        i += l

        if self.method_name == "publickey":
            self.signature_present = struct.unpack("?", self.buf[i:i+1])[0]
            i += 1
            l, self.algorithm_name = sshtype.parseString(self.buf[i:])
            i += l
            l, self.public_key = sshtype.parseBinary(self.buf[i:])
            if self.signature_present:
                i += l
                l, self.signature = sshtype.parseBinary(self.buf[i:])
                self.signature_length = l
Example #9
0
    def parse(self):
        super().parse()

        i = 1
        l, self.user_name = sshtype.parseString(self.buf[i:])
        i += l
        l, self.service_name = sshtype.parseString(self.buf[i:])
        i += l
        l, self.method_name = sshtype.parseString(self.buf[i:])
        i += l

        if self.method_name == "publickey":
            self.signature_present = struct.unpack("?", self.buf[i:i + 1])[0]
            i += 1
            l, self.algorithm_name = sshtype.parseString(self.buf[i:])
            i += l
            l, self.public_key = sshtype.parseBinary(self.buf[i:])
            if self.signature_present:
                i += l
                l, self.signature = sshtype.parseBinary(self.buf[i:])
                self.signature_length = l
Example #10
0
 def channel_request(self, peer, msg):
     if msg.request_type == "shell":
         shell = self.shells.get(msg.recipient_channel)
         if not shell:
             return
         asyncio.async(shell.cmdloop(), loop=self.loop)
     elif msg.request_type == "exec":
         shell = self.shells.get(msg.recipient_channel)
         if not shell:
             return
         l, cmd = sshtype.parseString(msg.payload)
         asyncio.async(self._shell_exec(shell, cmd), loop=self.loop)
Example #11
0
    def parse(self):
        i = super().parse()

        self.recipient_channel = struct.unpack(">L", self.buf[i:i + 4])[0]
        i += 4
        l, self.request_type = sshtype.parseString(self.buf[i:])
        i += l
        self.want_reply = struct.unpack("?", self.buf[i:i + 1])[0]
        i += 1

        if i == len(self.buf):
            return
        self.payload = self.buf[i:]
Example #12
0
    def parse(self):
        i = super().parse()

        self.recipient_channel = struct.unpack(">L", self.buf[i:i+4])[0]
        i += 4
        l, self.request_type = sshtype.parseString(self.buf[i:])
        i += l
        self.want_reply = struct.unpack("?", self.buf[i:i+1])[0]
        i += 1

        if i == len(self.buf):
            return
        self.payload = self.buf[i:]
Example #13
0
    def parse(self):
        super().parse()

        i = 1
        l, self.channel_type = sshtype.parseString(self.buf[i:])
        i += l
        self.sender_channel = struct.unpack(">L", self.buf[i:i+4])[0]
        i += 4
        self.initial_window_size = struct.unpack(">L", self.buf[i:i+4])[0]
        i += 4
        self.maximum_packet_size = struct.unpack(">L", self.buf[i:i+4])[0]
        i += 4

        if i < len(self.buf):
            self.data_packet = self.buf[i:]
Example #14
0
    def parse(self):
        super().parse()

        i = 1
        l, self.channel_type = sshtype.parseString(self.buf[i:])
        i += l
        self.sender_channel = struct.unpack(">L", self.buf[i:i + 4])[0]
        i += 4
        self.initial_window_size = struct.unpack(">L", self.buf[i:i + 4])[0]
        i += 4
        self.maximum_packet_size = struct.unpack(">L", self.buf[i:i + 4])[0]
        i += 4

        if i < len(self.buf):
            self.data_packet = self.buf[i:]
Example #15
0
 def verify_ssh_sig(self, key_data, sig_msg):
     i, v = sshtype.parseString(sig_msg)
     if v != 'ssh-rsa':
         log.warning("Not an ssh-rsa signature!")
         return False
     if log.isEnabledFor(logging.DEBUG):
         log.debug("l[{}][{}]".format(i, len(sig_msg)))
     sig = util.inflate_long(sshtype.parseBinary(sig_msg[i:])[1], True)
     # verify the signature by SHA'ing the key_data and encrypting it using the
     # public key.  some wackiness ensues where we "pkcs1imify" the 20-byte
     # hash into a string as long as the RSA key.
     if log.isEnabledFor(logging.DEBUG):
         log.debug("sig=[{}].".format(sig))
     hash_obj = util.inflate_long(self._pkcs1imify(sha1(key_data).digest()), True)
     rsa = self._public_key()
     return rsa.verify(hash_obj, (sig, ))
Example #16
0
 def verify_ssh_sig(self, key_data, sig_msg):
     i, v = sshtype.parseString(sig_msg)
     if v != "ssh-rsa":
         log.warning("Not an ssh-rsa signature!")
         return False
     if log.isEnabledFor(logging.DEBUG):
         log.debug("l[{}][{}]".format(i, len(sig_msg)))
     sig = util.inflate_long(sshtype.parseBinary(sig_msg[i:])[1], True)
     # verify the signature by SHA'ing the key_data and encrypting it using the
     # public key.  some wackiness ensues where we "pkcs1imify" the 20-byte
     # hash into a string as long as the RSA key.
     if log.isEnabledFor(logging.DEBUG):
         log.debug("sig=[{}].".format(sig))
     hash_obj = util.inflate_long(self._pkcs1imify(sha1(key_data).digest()), True)
     rsa = self._public_key()
     return rsa.verify(hash_obj, (sig,))
Example #17
0
    def parse(self):
        super().parse()
        i = 1
        pcnt = struct.unpack(">L", self.buf[i:i + 4])[0]
        i += 4
        self.peers = []
        for n in range(pcnt):
            if log.isEnabledFor(logging.DEBUG):
                log.debug("Reading record {}.".format(n))
            peer = Peer()  # db.Peer.
            l, peer.address = sshtype.parseString(self.buf[i:])
            i += l
            l, peer.node_id = sshtype.parseBinary(self.buf[i:])
            i += l
            l, peer.pubkey = sshtype.parseBinary(self.buf[i:])
            i += l

            self.peers.append(peer)
Example #18
0
    def parse(self):
        super().parse()
        i = 1
        pcnt = struct.unpack(">L", self.buf[i : i + 4])[0]
        i += 4
        self.peers = []
        for n in range(pcnt):
            if log.isEnabledFor(logging.DEBUG):
                log.debug("Reading record {}.".format(n))
            peer = Peer()  # db.Peer.
            l, peer.address = sshtype.parseString(self.buf[i:])
            i += l
            l, peer.node_id = sshtype.parseBinary(self.buf[i:])
            i += l
            l, peer.pubkey = sshtype.parseBinary(self.buf[i:])
            i += l

            self.peers.append(peer)
Example #19
0
    def parse(self):
        super().parse()

        i = 1
        l, self.service_name = sshtype.parseString(self.buf[i:])
Example #20
0
    def parse(self):
        super().parse()

        i = 1
        l, self.sender_address = sshtype.parseString(self.buf[i:])
Example #21
0
    def parse(self):
        super().parse()

        i = 1
        l, self.service_name = sshtype.parseString(self.buf[i:])