use of org.fisco.bcos.channel.protocol.TopicVerifyRespProtocol in project web3sdk by FISCO-BCOS.
the class Service method signForAmop.
public void signForAmop(ChannelHandlerContext ctx, ChannelMessage2 message) throws IOException {
SocketChannel socketChannel = (SocketChannel) ctx.channel();
logger.info("sign ChannelResponse seq:{} msgtype:{} address:{} port:{}", message.getSeq(), message.getType(), socketChannel.remoteAddress().getAddress().getHostAddress(), socketChannel.remoteAddress().getPort());
logger.info("sign request :{} length:{}", Arrays.toString(message.getData()), message.getLength());
String content = topicVerify.parseDataFromPush(message.getLength(), message.getData());
logger.info("content:{} content:{}", content, Arrays.toString(content.getBytes()));
TopicVerifyReqProtocol topicVerifyProtocol = ObjectMapperFactory.getObjectMapper().readValue(content, TopicVerifyReqProtocol.class);
String randValue = topicVerifyProtocol.getRandValue();
String topic = topicVerifyProtocol.getTopic();
logger.info("sign rand_value:{} sign topic:{}", randValue, topic);
String signature = topicVerify.signatureForRandValue(topic, randValue);
TopicVerifyRespProtocol topicVerifyRespProtocol = new TopicVerifyRespProtocol();
topicVerifyRespProtocol.setSignature(signature);
String jsonStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(topicVerifyRespProtocol);
logger.info("signature jsonStr result:{}", jsonStr);
byte[] bytes = topicVerify.getByteBuffByString(message.getTopic(), jsonStr);
ChannelResponse response = new ChannelResponse();
response.setMessageID(message.getSeq());
response.setErrorCode(0);
response.setContent(bytes);
sendResponseMessage2(response, ctx, message.getSeq(), message.getTopic());
}
use of org.fisco.bcos.channel.protocol.TopicVerifyRespProtocol in project web3sdk by FISCO-BCOS.
the class Service method checkSignForAmop.
public void checkSignForAmop(String topic, String randValue, String nodeid, ChannelHandlerContext ctx, ChannelResponse response) throws IOException {
if (response.getErrorCode() != 0) {
logger.error("get signature failed :{}:{}", response.getErrorCode(), response.getErrorMessage());
return;
}
logger.info("check signature:{} length:{}", Arrays.toString(response.getContentByteArray()), response.getContentByteArray().length);
String content = topicVerify.parseDataFromPush(response.getContentByteArray().length, response.getContentByteArray());
logger.info("content:{} content:{}", content, Arrays.toString(content.getBytes()));
TopicVerifyRespProtocol topicVerifyRespProtocol = ObjectMapperFactory.getObjectMapper().readValue(content, TopicVerifyRespProtocol.class);
String signature = topicVerifyRespProtocol.getSignature();
logger.info("signature:{} ", signature);
int checkResult = topicVerify.checkSignatureValidate(topic, signature, randValue);
SdkRequestNodeUpdateTopicStatus sdkRequestNodeUpdateTopicStatus = new SdkRequestNodeUpdateTopicStatus();
sdkRequestNodeUpdateTopicStatus.setCheckResult(checkResult);
sdkRequestNodeUpdateTopicStatus.setNodeId(nodeid);
sdkRequestNodeUpdateTopicStatus.setTopic(topic);
String jsonStr = ObjectMapperFactory.getObjectMapper().writeValueAsString(sdkRequestNodeUpdateTopicStatus);
logger.info("check signature result:{}", jsonStr);
ChannelRequest request = new ChannelRequest();
request.setMessageID(newSeq());
request.setToTopic(topic);
request.setTimeout(5000);
request.setContent(jsonStr.getBytes());
sendCheckResultToNode(request, ctx, (short) ChannelMessageType.UPDATE_TOPIICSTATUS.getType());
}
Aggregations