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;
}
Aggregations