Search in sources :

Example 1 with SignatureFunction

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);
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) SignatureFunction(com.jd.blockchain.crypto.SignatureFunction)

Example 2 with SignatureFunction

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;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) SignatureFunction(com.jd.blockchain.crypto.SignatureFunction)

Example 3 with SignatureFunction

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;
}
Also used : SignatureFunction(com.jd.blockchain.crypto.SignatureFunction) SignatureDigest(com.jd.blockchain.crypto.SignatureDigest)

Example 4 with SignatureFunction

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);
}
Also used : SignatureFunction(com.jd.blockchain.crypto.SignatureFunction)

Example 5 with SignatureFunction

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

SignatureFunction (com.jd.blockchain.crypto.SignatureFunction)13 PubKey (com.jd.blockchain.crypto.PubKey)6 SignatureDigest (com.jd.blockchain.crypto.SignatureDigest)6 AsymmetricKeypair (com.jd.blockchain.crypto.AsymmetricKeypair)2 CryptoAlgorithm (com.jd.blockchain.crypto.CryptoAlgorithm)2 LedgerInitException (com.jd.blockchain.ledger.LedgerInitException)2 CertificateUtils (com.jd.blockchain.ca.CertificateUtils)1 BftsmartClientAuthCredit (com.jd.blockchain.consensus.bftsmart.BftsmartClientAuthCredit)1 BftsmartSessionCredential (com.jd.blockchain.consensus.bftsmart.BftsmartSessionCredential)1 PrivKey (com.jd.blockchain.crypto.PrivKey)1 ParticipantProperties (com.jd.blockchain.ledger.LedgerInitProperties.ParticipantProperties)1 ParticipantNode (com.jd.blockchain.ledger.ParticipantNode)1 LedgerInitProposalData (com.jd.blockchain.ledger.core.LedgerInitProposalData)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1