Search in sources :

Example 1 with TopicVerifyRespProtocol

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());
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) TopicVerifyReqProtocol(org.fisco.bcos.channel.protocol.TopicVerifyReqProtocol) ChannelResponse(org.fisco.bcos.channel.dto.ChannelResponse) TopicVerifyRespProtocol(org.fisco.bcos.channel.protocol.TopicVerifyRespProtocol)

Example 2 with TopicVerifyRespProtocol

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());
}
Also used : ChannelRequest(org.fisco.bcos.channel.dto.ChannelRequest) SdkRequestNodeUpdateTopicStatus(org.fisco.bcos.channel.protocol.SdkRequestNodeUpdateTopicStatus) TopicVerifyRespProtocol(org.fisco.bcos.channel.protocol.TopicVerifyRespProtocol)

Aggregations

TopicVerifyRespProtocol (org.fisco.bcos.channel.protocol.TopicVerifyRespProtocol)2 SocketChannel (io.netty.channel.socket.SocketChannel)1 ChannelRequest (org.fisco.bcos.channel.dto.ChannelRequest)1 ChannelResponse (org.fisco.bcos.channel.dto.ChannelResponse)1 SdkRequestNodeUpdateTopicStatus (org.fisco.bcos.channel.protocol.SdkRequestNodeUpdateTopicStatus)1 TopicVerifyReqProtocol (org.fisco.bcos.channel.protocol.TopicVerifyReqProtocol)1