use of com.jd.blockchain.crypto.SignatureFunction 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);
}
use of com.jd.blockchain.crypto.SignatureFunction 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;
}
use of com.jd.blockchain.crypto.SignatureFunction in project jdchain-core by blockchain-jd-com.
the class LedgerInitializeWebController method signPermissionRequest.
public SignatureDigest signPermissionRequest(int requesterId, PrivKey privKey) {
byte[] reqAuthBytes = BytesUtils.concat(BytesUtils.toBytes(requesterId), ledgerInitConfig.getLedgerSettings().getLedgerSeed());
SignatureFunction signatureFunction = Crypto.getSignatureFunction(privKey.getAlgorithm());
SignatureDigest reqAuthSign = signatureFunction.sign(privKey, reqAuthBytes);
return reqAuthSign;
}
use of com.jd.blockchain.crypto.SignatureFunction in project jdchain-core by blockchain-jd-com.
the class BftsmartClientAuthencationService method verify.
private boolean verify(ClientCredential credential) {
byte[] credentialBytes = BinaryProtocol.encode(credential.getSessionCredential(), BftsmartSessionCredential.class);
SignatureFunction signatureFunction = Crypto.getSignatureFunction(credential.getPubKey().getAlgorithm());
return signatureFunction.verify(credential.getSignature(), credential.getPubKey(), credentialBytes);
}
use of com.jd.blockchain.crypto.SignatureFunction 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;
}
Aggregations