Esempio n. 1
0
 def seventh_get(self):
     print("A用KA解密数据,得到主通信密钥和B的IP地址,验证结束")
     self._decode_data(function_id=2, key=self.COMMUNICATION_KEY)
     dict = file2dict('tmp.txt')
     print("Decode Data")
     print(dict)
     self.IP_TARGET = dict['IP_TARGET']
     self.MAIN_COMMUNICATION_KEY = dict['KC']
Esempio n. 2
0
 def fourth_verify_and_send(self):
     print("用自己的通信密钥KB解密数据")
     self._decode_data(function_id=2, key=COMMUNICATION_KEY_DICT['KB'])
     dict = file2dict('tmp.txt')
     if True:
         pass
         print("Decode Data")
         print(dict)
         self.IP_TARGET = dict['IP_TARGET']
         print("经过一些验证措施之后,保存A的IP地址")
         # 省略一些验证步骤
     else:
         print('get false msg! ')
Esempio n. 3
0
 def second_get(self):
     print("用私钥解密数据")
     self._decode_data()
     dict = file2dict('tmp.txt')
     print("Decode Data")
     print(dict)
     print("保存 KA,KB")
     self.COMMUNICATION_KEY_CHAIN['KA'] = dict['A_COMMUNICATION_KEY']
     self.COMMUNICATION_KEY_CHAIN['KB'] = COMMUNICATION_KEY_DICT['KB']
     if self.get_privilege('MA', 'MB'):
         # 获取权限
         print("允许访问")
         self.__third_send_flag = True
         return True
     else:
         return False
Esempio n. 4
0
 def sixth_send(self):
     print("用B的通信密钥解密数据包,保存主通信密钥")
     self._decode_data(2, self.COMMUNICATION_KEY_CHAIN['KB'])
     dict = file2dict('tmp.txt')
     self.COMMUNICATION_KEY_CHAIN['KC'] = dict['C_COMMUNICATION_KEY']
     print("Decode Data")
     print(dict)
     print("随后,将B的IP地址和主通信密钥用KA加密后发送给A")
     data = OrderedDict()
     # 看上去是这么发,实际上IP地址本来就包含在数据包中,这么做只是为了强调
     data['SIP'] = self.IP
     data['TIP'] = IPADDR_DICT['MA']
     data['SMAC'] = self.DEVICE_ID
     data['TMAC'] = DEVICE_ID_DICT['MA']
     data['CONTENT'] = 'IT IS B\' IP DECODE BY YOUR KEY '
     data['IP_TARGET'] = IPADDR_DICT['MB']
     data['KC'] = self.COMMUNICATION_KEY_CHAIN['KC']
     data['FLAG'] = 'CER-6-INFORM'
     print("Raw Data")
     print(data)
     dict2file(data, 'tmp.txt')
     self._encode_data(method='AES', key=self.COMMUNICATION_KEY_CHAIN['KA'])
     print("Encode Data")
     print(open('tmp.txt', 'rb').read())
Esempio n. 5
0
 def commnication_get(self):
     print("接受的时候,接受方用主通信密钥解密数据")
     self._decode_data(function_id=2, key=self.MAIN_COMMUNICATION_KEY)
     dict = file2dict('tmp.txt')
     print('GET CONTENT')
     print(dict['CONTENT'])