def _get_not_trust_private_key(self): name = self.GetCertName() not_trust_tran_private_path = self.config.mspDir + r'\keystore\\' + name + '_private.pem' log_info(("用户私钥路径", not_trust_tran_private_path)) with open(not_trust_tran_private_path, "rb") as f: key_data = f.read() return key_data
def sign(self, message): log_info("ECDSA sign") # load private key # Sign using the function in the official library signature = Ecies(CURVE_P_256_Size, SHA2).sign(private_key=self.private_key_data, message=message.encode('utf-8')) # print("signature:", signature) # return signarure value in base64 format return base64.b64encode(signature)
def verify(self, message, signature): log_info("ECDSA verify signature") print(message) # read the signed data mac = signature # verify the signature verify_results = Ecies().verify(public_key=self.pubilc_key_data, message=message.encode('utf-8'), signature=base64.b64decode(mac)) # print("verify_results:", verify_results) # return value T or F return verify_results
def _get_not_trust_private_key(self): """ :description : get application certificate :param : :return : """ name = self.GetCertName() not_trust_tran_private_path = self.config.mspDir + r'\keystore\\' + name + '_private.pem' log_info(("user private key path", not_trust_tran_private_path)) with open(not_trust_tran_private_path, "rb") as f: key_data = f.read() return key_data
def request_post(self, req_url, data): log_info(("请求地址:", req_url)) log_info(("请求数据:", data)) headers = {'content-type': 'application/json'} if any((self.http_client_cert, )): res = requests.post(req_url, headers=headers, json=data, verify=self.http_client_cert) else: res = requests.post(req_url, headers=headers, json=data, verify=False) resCode = res.status_code resHeaders = res.headers log_info(('接受到的响应headers:', resHeaders)) if resCode != 200: raise Exception('请求失败,http code为{}'.format(resCode, )) resBody = res.json() log_info(('接受到的响应:', resBody)) if resBody['header'][ "code"] != ResCode.ResCode_Suc.value: # 返回成功,则需要进行解密 raise BsnException(resBody['header']["code"], resBody['header']["msg"]) return resBody
def get_transaction(self, txId): """ Get transaction info :param txId: :return: """ req_url = self.config.nodeApi + "/api/fabric/v1/node/getTransaction" get_transaction_obj = GetTransaction(txId) get_transaction_obj.set_config(self.config) req_data = self.build_req_data(get_transaction_obj.req_body()) log_info(req_data) mac = get_transaction_obj.sign(req_data) req_data["mac"] = mac res_data = self.common_request(req_url, req_data) log_info(res_data) assert get_transaction_obj.verify(res_data) return res_data
def request_post(self, req_url, data): """ :description : post request :param : req_url : request url :param : data : request data :return : """ log_info(("request address:", req_url)) log_info(("request data:", data)) headers = {'content-type': 'application/json'} # res = requests.post(req_url, headers=headers, json=data, verify=self.cert_path) res = requests.post(req_url, headers=headers, json=data, verify=False) resCode = res.status_code # resHeaders = res.headers # log_info(('received response headers:', resHeaders)) if resCode != 200: raise Exception('request failure,http code:{}'.format(resCode, )) resBody = res.json() log_info(('response:', resBody)) if resBody['header'][ "code"] != ResCode.ResCode_Suc.value: # return success, decrypt raise BsnException(resBody['header']["code"], resBody['header']["msg"]) return resBody
def verify(self, message, signature): log_info("SM2 verify the signature") return True
def sign(self, message): log_info("SM2 sign") return message
def test_log_info(self): log_info('1111111111')