def parse_public_key(public_key): """parse_public_key(public_key) -> SSH_Public_Private_Key instance This takes a public key and generates an SSH_Public_Private_Key instance. <public_key>: A packed public key. The format should be a packed string with the first value being a string to identify the type. """ data, offset = packet.unpack_payload_get_offset((packet.STRING,), public_key) keytype = data[0] if not keytypes.has_key(keytype): raise Unknown_Key_Type(keytype) key_obj = keytypes[keytype]() key_obj.set_public_key(public_key) return key_obj
def parse_public_key(public_key): """parse_public_key(public_key) -> SSH_Public_Private_Key instance This takes a public key and generates an SSH_Public_Private_Key instance. <public_key>: A packed public key. The format should be a packed string with the first value being a string to identify the type. """ data, offset = packet.unpack_payload_get_offset((packet.STRING,), public_key) keytype = data[0] if keytype not in keytypes: raise Unknown_Key_Type(keytype) key_obj = keytypes[keytype]() key_obj.set_public_key(public_key) return key_obj
def msg_channel_open_confirmation(self, pkt): data, offset = ssh_packet.unpack_payload_get_offset(SSH_MSG_CHANNEL_OPEN_CONFIRMATION_PAYLOAD, pkt) msg, recipient_channel, sender_channel, window_size, max_packet_size = data self.transport.debug.write(ssh_debug.DEBUG_1, 'channel %i open confirmation sender_channel=%i window_size=%i max_packet_size=%i', (recipient_channel, sender_channel, window_size, max_packet_size)) channel = self.local_channels[recipient_channel] # XXX: Assert that the channel is not already open? channel.closed = 0 channel.eof = 0 channel.remote_channel.closed = 0 channel.remote_channel.channel_id = sender_channel assert not self.remote_channels.has_key(sender_channel) self.remote_channels[sender_channel] = channel.remote_channel channel.remote_channel.window_size = window_size channel.remote_channel.window_data_left = window_size channel.remote_channel.max_packet_size = max_packet_size additional_data = ssh_packet.unpack_payload(channel.additional_packet_data_types, pkt, offset) channel.channel_open_success(additional_data)
def msg_channel_open_confirmation(self, pkt): data, offset = ssh_packet.unpack_payload_get_offset(SSH_MSG_CHANNEL_OPEN_CONFIRMATION_PAYLOAD, pkt) msg, recipient_channel, sender_channel, window_size, max_packet_size = data self.transport.debug.write( ssh_debug.DEBUG_1, 'channel %i open confirmation sender_channel=%i window_size=%i max_packet_size=%i', (recipient_channel, sender_channel, window_size, max_packet_size)) channel = self.local_channels[recipient_channel] # XXX: Assert that the channel is not already open? channel.closed = 0 channel.eof = 0 channel.remote_channel.closed = 0 channel.remote_channel.channel_id = sender_channel assert sender_channel not in self.remote_channels self.remote_channels[sender_channel] = channel.remote_channel channel.remote_channel.window_size = window_size channel.remote_channel.window_data_left = window_size channel.remote_channel.max_packet_size = max_packet_size additional_data = ssh_packet.unpack_payload(channel.additional_packet_data_types, pkt, offset) channel.channel_open_success(additional_data)
def msg_global_request(self, pkt): # XXX: finish this (it's a server thing) data, offset = ssh_packet.unpack_payload_get_offset(SSH_MSG_GLOBAL_REQUEST_PAYLOAD, pkt) msg, request_name, want_reply = data raise NotImplementedError
def msg_channel_request(self, pkt): data, offset = ssh_packet.unpack_payload_get_offset(SSH_MSG_CHANNEL_REQUEST_PAYLOAD, pkt) msg, channel_id, request_type, want_reply = data channel = self.local_channels[channel_id] channel.handle_request(request_type, want_reply, pkt[offset:])
def msg_global_request(self, pkt): # XXX: finish this (it's a server thing) data, offset = ssh_packet.unpack_payload_get_offset(SSH_MSG_GLOBAL_REQUEST_PAYLOAD, pkt) msg, request_name, want_reply = data raise NotImplementedError
def msg_channel_request(self, pkt): data, offset = ssh_packet.unpack_payload_get_offset(SSH_MSG_CHANNEL_REQUEST_PAYLOAD, pkt) msg, channel_id, request_type, want_reply = data channel = self.local_channels[channel_id] channel.handle_request(request_type, want_reply, pkt[offset:])