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