Search in sources :

Example 1 with PubKey

use of com.jd.blockchain.crypto.PubKey in project jdchain-core by blockchain-jd-com.

the class MsgQueueConsensusManageService method isLegal.

public boolean isLegal(ClientCredential authId) {
    PubKey pubKey = authId.getPubKey();
    byte[] identityInfo = BinaryProtocol.encode(authId.getSessionCredential(), MQCredentialInfo.class);
    SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm());
    return signatureFunction.verify(authId.getSignature(), pubKey, identityInfo);
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) SignatureFunction(com.jd.blockchain.crypto.SignatureFunction)

Example 2 with PubKey

use of com.jd.blockchain.crypto.PubKey in project jdchain-core by blockchain-jd-com.

the class RaftNodeConfig method init.

public void init(Properties props, int id) {
    this.setId(id);
    String host = props.getProperty(String.format(SYSTEM_SERVER_D_NETWORK_HOST, id));
    int port = Integer.parseInt(props.getProperty(String.format(SYSTEM_SERVER_D_NETWORK_PORT, id)));
    boolean secure = Boolean.parseBoolean(props.getProperty(String.format(SYSTEM_SERVER_D_NETWORK_SECURE, id)));
    byte[] pubKeyBytes = Base58Utils.decode(props.getProperty(String.format(SYSTEM_SERVER_D_PUBKEY, id)));
    PubKey pubKey = Crypto.resolveAsPubKey(pubKeyBytes);
    this.setAddress(AddressEncoding.generateAddress(pubKey).toBase58());
    this.setPubKey(pubKey);
    this.setNetworkAddress(new NetworkAddress(host, port, secure));
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) NetworkAddress(utils.net.NetworkAddress)

Example 3 with PubKey

use of com.jd.blockchain.crypto.PubKey in project jdchain-core by blockchain-jd-com.

the class LedgerInitializeWebController method validateAndRecordDecision.

/**
 * 校验并记录指定的参与方做出的决定;
 * <p>
 * 注:对 {@link DecisionResultHandle#setValue(LedgerInitDecision)}
 * 方法的调用不是线程安全的,但由于是在满足有效性校验之后才调用,具有幂等性,所以不必对该方法的多处调用进行同步;
 *
 * @param targetDecision
 * @param resultHandle
 * @param hashAlgorithm
 * @return
 */
private synchronized boolean validateAndRecordDecision(LedgerInitDecision targetDecision, DecisionResultHandle resultHandle) {
    if ((!localDecision.getLedgerHash().equals(targetDecision.getLedgerHash())) && resultHandle.getValue() == null) {
        // 如果结果已经被
        prompter.error("The received ledger hash of participant isn't equal to ledger hash of current participant! --[Id=%s]", targetDecision.getParticipantId());
        return false;
    }
    // 检查签名;
    PubKey targetPubKey = ledgerInitConfig.getParticipant(targetDecision.getParticipantId()).getPubKey();
    byte[] deciBytes = getDecisionBytes(targetDecision.getParticipantId(), targetDecision.getLedgerHash());
    SignatureFunction signatureFunction = Crypto.getSignatureFunction(targetPubKey.getAlgorithm());
    if ((!signatureFunction.verify(targetDecision.getSignature(), targetPubKey, deciBytes)) && resultHandle.getValue() == null) {
        prompter.error("The signature of received decision is invalid! --[Id=%s]", targetDecision.getParticipantId());
        return false;
    }
    resultHandle.setValue(targetDecision);
    return true;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) SignatureFunction(com.jd.blockchain.crypto.SignatureFunction)

Example 4 with PubKey

use of com.jd.blockchain.crypto.PubKey in project jdchain-core by blockchain-jd-com.

the class LedgerTestUtils method createKeyPair.

public static BlockchainKeypair createKeyPair(String pub, String priv) {
    PubKey pubKey = Crypto.resolveAsPubKey(Base58Utils.decode(pub));
    PrivKey privKey = Crypto.resolveAsPrivKey(Base58Utils.decode(priv));
    return new BlockchainKeypair(pubKey, privKey);
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) PrivKey(com.jd.blockchain.crypto.PrivKey)

Example 5 with PubKey

use of com.jd.blockchain.crypto.PubKey in project jdchain-core by blockchain-jd-com.

the class BftsmartConsensusClientFactory method buildCredential.

@Override
public BftsmartClientAuthCredit buildCredential(SessionCredential sessionCredential, AsymmetricKeypair clientKeyPair, X509Certificate gatewayCertificate) {
    if (sessionCredential == null) {
        sessionCredential = BftsmartSessionCredentialConfig.createEmptyCredential();
    } else if (!(sessionCredential instanceof BftsmartSessionCredential)) {
        throw new IllegalArgumentException("Illegal credential info type! Requrie [" + BftsmartSessionCredential.class.getName() + "] but it is [" + sessionCredential.getClass().getName() + "]!");
    }
    PubKey pubKey = clientKeyPair.getPubKey();
    PrivKey privKey = clientKeyPair.getPrivKey();
    SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm());
    byte[] credentialBytes = BinaryProtocol.encode(sessionCredential, BftsmartSessionCredential.class);
    SignatureDigest signatureDigest = signatureFunction.sign(privKey, credentialBytes);
    BftsmartClientAuthCredit bftsmartClientAuthCredential = new BftsmartClientAuthCredit();
    bftsmartClientAuthCredential.setSessionCredential((BftsmartSessionCredential) sessionCredential);
    bftsmartClientAuthCredential.setPubKey(pubKey);
    bftsmartClientAuthCredential.setSignatureDigest(signatureDigest);
    bftsmartClientAuthCredential.setCertificate(null != gatewayCertificate ? CertificateUtils.toPEMString(gatewayCertificate) : null);
    return bftsmartClientAuthCredential;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) BftsmartClientAuthCredit(com.jd.blockchain.consensus.bftsmart.BftsmartClientAuthCredit) SignatureFunction(com.jd.blockchain.crypto.SignatureFunction) SignatureDigest(com.jd.blockchain.crypto.SignatureDigest) BftsmartSessionCredential(com.jd.blockchain.consensus.bftsmart.BftsmartSessionCredential) PrivKey(com.jd.blockchain.crypto.PrivKey)

Aggregations

PubKey (com.jd.blockchain.crypto.PubKey)21 SignatureFunction (com.jd.blockchain.crypto.SignatureFunction)6 SignatureDigest (com.jd.blockchain.crypto.SignatureDigest)5 Bytes (utils.Bytes)5 PrivKey (com.jd.blockchain.crypto.PrivKey)4 ParticipantNode (com.jd.blockchain.ledger.ParticipantNode)4 NetworkAddress (utils.net.NetworkAddress)4 NodeSettings (com.jd.blockchain.consensus.NodeSettings)3 LedgerInitException (com.jd.blockchain.ledger.LedgerInitException)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 MsgQueueConsensusConfig (com.jd.blockchain.consensus.mq.config.MsgQueueConsensusConfig)2 MsgQueueNodeConfig (com.jd.blockchain.consensus.mq.config.MsgQueueNodeConfig)2 BlockchainKeypair (com.jd.blockchain.ledger.BlockchainKeypair)2 LedgerException (com.jd.blockchain.ledger.LedgerException)2 NetworkReplica (com.jd.blockchain.consensus.NetworkReplica)1 BftsmartClientAuthCredit (com.jd.blockchain.consensus.bftsmart.BftsmartClientAuthCredit)1 BftsmartConsensusConfig (com.jd.blockchain.consensus.bftsmart.BftsmartConsensusConfig)1 BftsmartNodeConfig (com.jd.blockchain.consensus.bftsmart.BftsmartNodeConfig)1 BftsmartNodeSettings (com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings)1