def srv_msg_wrap(msg, client_id): encoded_int = (my_rsa.encode(msg, "keys/" + client_id + ".pem")) encoded_bytes = base64.b64encode(my_rsa.pack(encoded_int)) json_data_id = json.dumps({ "data": encoded_bytes, "exp_time": int(time.time()) + 10 }) sign = my_sign.sign_data(json_data_id, KEY_PATH) json_send = json.dumps({ "sign": sign, "data_id": json_data_id, }) send_data = json_send return send_data
def msg_wrap_to_send(msg): encoded_int = (my_rsa.encode(msg, SRV_KEY_PATH)) encoded_bytes = base64.b64encode(my_rsa.pack(encoded_int)) json_data_id = json.dumps({ "data": encoded_bytes, "id": CAR_ID, "type": "car_serial", "exp_time": int(time.time()) + 10 }) sign = my_sign.sign_data(json_data_id, PRIVATE_KEY_PATH) json_send = json.dumps({ "sign": sign, "data_id": json_data_id, }) # print(json_send) send_data = json_send # send_data += (b'\x00') return send_data
def send_data(self, obj): print(obj) (ipaddr, keys_path, own_keys_path, phone_number) = self.load_strings() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((ipaddr, 50012)) except socket.error as s_err: if s_err.errno != 111: raise s_err tryes = 5 print "Connection refused, retrying.." for i in range(0, tryes + 1): print "Try number ", str(i) try: s.connect((ipaddr, 50012)) except socket.error as try_err: if try_err.errno != 111: raise try_err time.sleep(1) print "Connection error" self.output.text = "Connection error" return encoded_int = (my_rsa.encode(self.message.text, keys_path)) encoded_bytes = base64.b64encode(my_rsa.pack(encoded_int)) json_data_id = json.dumps({ "data": encoded_bytes, "id": phone_number, "type": "phone_number", "exp_time": int(time.time()) + 10 }) sign = my_sign.sign_data(json_data_id, own_keys_path) json_send = json.dumps({ "sign": sign, "data_id": json_data_id, }) send_data1 = json_send send_data1 += (b'\x00') s.sendall(send_data1) self.output.text = self.get_response(s, keys_path, own_keys_path) s.close()
import my_rsa import my_sign import json import base64 import time s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("127.0.0.1", 50012)) encoded_int = (my_rsa.encode(sys.argv[1], "../numbers.txt")) encoded_bytes = base64.b64encode(my_rsa.pack(encoded_int)) json_data_id = json.dumps({ "data": encoded_bytes, "id": "1234", "type": "phone_number", "exp_time": int(time.time()) + 10 }) sign = my_sign.sign_data(json_data_id, "keys/1234.pem") json_send = json.dumps({ "sign": sign, "data_id": json_data_id, }) print(json_send) send_data = json_send send_data += (b'\x00') # print(send_data) # data = s.recv(1024) # print ('Received ', (data.decode())) s.sendall(send_data) s.close()