Search in sources :

Example 1 with BftsmartClientAuthCredit

use of com.jd.blockchain.consensus.bftsmart.BftsmartClientAuthCredit 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

BftsmartClientAuthCredit (com.jd.blockchain.consensus.bftsmart.BftsmartClientAuthCredit)1 BftsmartSessionCredential (com.jd.blockchain.consensus.bftsmart.BftsmartSessionCredential)1 PrivKey (com.jd.blockchain.crypto.PrivKey)1 PubKey (com.jd.blockchain.crypto.PubKey)1 SignatureDigest (com.jd.blockchain.crypto.SignatureDigest)1 SignatureFunction (com.jd.blockchain.crypto.SignatureFunction)1