Search in sources :

Example 1 with CertificateUtils

use of com.jd.blockchain.ca.CertificateUtils in project jdchain-core by blockchain-jd-com.

the class RaftConsensusClientFactory method buildCredential.

@Override
public ClientCredential buildCredential(SessionCredential sessionCredential, AsymmetricKeypair clientKeyPair, X509Certificate gatewayCertificate) {
    if (sessionCredential == null) {
        sessionCredential = RaftSessionCredentialConfig.createEmptyCredential();
    }
    if (!(sessionCredential instanceof RaftSessionCredential)) {
        throw new IllegalArgumentException("Illegal credential info type! Requrie [" + RaftSessionCredential.class.getName() + "] but it is [" + sessionCredential.getClass().getName() + "]!");
    }
    SignatureFunction signatureFunction = Crypto.getSignatureFunction(clientKeyPair.getAlgorithm());
    byte[] credentialBytes = BinaryProtocol.encode(sessionCredential, RaftSessionCredential.class);
    SignatureDigest signatureDigest = signatureFunction.sign(clientKeyPair.getPrivKey(), credentialBytes);
    RaftClientCredential identification = new RaftClientCredential();
    identification.setIdentityInfo(sessionCredential);
    identification.setPubKey(clientKeyPair.getPubKey());
    identification.setSignature(signatureDigest);
    identification.setCertificate(Optional.ofNullable(gatewayCertificate).map(CertificateUtils::toPEMString).orElse(null));
    return identification;
}
Also used : SignatureFunction(com.jd.blockchain.crypto.SignatureFunction) SignatureDigest(com.jd.blockchain.crypto.SignatureDigest) CertificateUtils(com.jd.blockchain.ca.CertificateUtils)

Aggregations

CertificateUtils (com.jd.blockchain.ca.CertificateUtils)1 SignatureDigest (com.jd.blockchain.crypto.SignatureDigest)1 SignatureFunction (com.jd.blockchain.crypto.SignatureFunction)1