Search in sources :

Example 1 with SignatureDigest

use of com.jd.blockchain.crypto.SignatureDigest 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 2 with SignatureDigest

use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.

the class LedgerTransactionDataTest method initTxRequestMessage.

private TxRequestMessage initTxRequestMessage(CryptoAlgorithm hashAlgorithm) throws Exception {
    TransactionContent txContent = initTransactionContent();
    HashDigest txHash = TxBuilder.computeTxContentHash(hashAlgorithm, txContent);
    TxRequestMessage txRequestMessage = new TxRequestMessage(txHash, txContent);
    AsymmetricKeypair keypair2 = ClassicCryptoService.ED25519.generateKeypair();
    SignatureDigest digest1 = ClassicCryptoService.ED25519.sign(keypair.getPrivKey(), "zhangsan".getBytes());
    SignatureDigest digest2 = ClassicCryptoService.ED25519.sign(keypair.getPrivKey(), "lisi".getBytes());
    DigitalSignatureBlob endPoint1 = new DigitalSignatureBlob(keypair.getPubKey(), digest1);
    DigitalSignatureBlob endPoint2 = new DigitalSignatureBlob(keypair2.getPubKey(), digest2);
    txRequestMessage.addEndpointSignatures(endPoint1);
    txRequestMessage.addEndpointSignatures(endPoint2);
    AsymmetricKeypair keypair4 = ClassicCryptoService.ED25519.generateKeypair();
    SignatureDigest digest3 = ClassicCryptoService.ED25519.sign(keypair.getPrivKey(), "wangwu".getBytes());
    SignatureDigest digest4 = ClassicCryptoService.ED25519.sign(keypair4.getPrivKey(), "zhaoliu".getBytes());
    DigitalSignatureBlob node1 = new DigitalSignatureBlob(keypair.getPubKey(), digest3);
    DigitalSignatureBlob node2 = new DigitalSignatureBlob(keypair4.getPubKey(), digest4);
    txRequestMessage.addNodeSignatures(node1);
    txRequestMessage.addNodeSignatures(node2);
    return txRequestMessage;
}
Also used : AsymmetricKeypair(com.jd.blockchain.crypto.AsymmetricKeypair) HashDigest(com.jd.blockchain.crypto.HashDigest) SignatureDigest(com.jd.blockchain.crypto.SignatureDigest) DigitalSignatureBlob(com.jd.blockchain.transaction.DigitalSignatureBlob) TxRequestMessage(com.jd.blockchain.transaction.TxRequestMessage) TransactionContent(com.jd.blockchain.ledger.TransactionContent)

Example 3 with SignatureDigest

use of com.jd.blockchain.crypto.SignatureDigest 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)

Example 4 with SignatureDigest

use of com.jd.blockchain.crypto.SignatureDigest in project jdchain-core by blockchain-jd-com.

the class MsgQueueClientFactory method buildCredential.

@Override
public MsgQueueClientIdentification buildCredential(SessionCredential credentialInfo, AsymmetricKeypair clientKeyPair, X509Certificate gatewayCertificate) {
    MQCredentialInfo mqCredentialInfo = (MQCredentialInfo) credentialInfo;
    if (null == mqCredentialInfo) {
        mqCredentialInfo = MQCredentialConfig.createEmptyCredential();
    }
    byte[] credentialBytes = BinaryProtocol.encode(mqCredentialInfo, MQCredentialInfo.class);
    PubKey pubKey = clientKeyPair.getPubKey();
    // byte[] address = pubKey.toBytes(); // 使用公钥地址作为认证信息
    SignatureFunction signatureFunction = Crypto.getSignatureFunction(pubKey.getAlgorithm());
    SignatureDigest signatureDigest = signatureFunction.sign(clientKeyPair.getPrivKey(), credentialBytes);
    MsgQueueClientIdentification mqci = new MsgQueueClientIdentification().setPubKey(clientKeyPair.getPubKey()).setIdentityInfo(mqCredentialInfo).setSignature(signatureDigest).setCertificate(gatewayCertificate != null ? CertificateUtils.toPEMString(gatewayCertificate) : null);
    ;
    return mqci;
}
Also used : PubKey(com.jd.blockchain.crypto.PubKey) SignatureFunction(com.jd.blockchain.crypto.SignatureFunction) SignatureDigest(com.jd.blockchain.crypto.SignatureDigest)

Example 5 with SignatureDigest

use of com.jd.blockchain.crypto.SignatureDigest 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

SignatureDigest (com.jd.blockchain.crypto.SignatureDigest)9 SignatureFunction (com.jd.blockchain.crypto.SignatureFunction)6 PubKey (com.jd.blockchain.crypto.PubKey)5 LedgerInitException (com.jd.blockchain.ledger.LedgerInitException)2 ParticipantNode (com.jd.blockchain.ledger.ParticipantNode)2 DigitalSignatureBlob (com.jd.blockchain.transaction.DigitalSignatureBlob)2 ArrayList (java.util.ArrayList)2 CertificateUtils (com.jd.blockchain.ca.CertificateUtils)1 BftsmartClientAuthCredit (com.jd.blockchain.consensus.bftsmart.BftsmartClientAuthCredit)1 BftsmartSessionCredential (com.jd.blockchain.consensus.bftsmart.BftsmartSessionCredential)1 AsymmetricKeypair (com.jd.blockchain.crypto.AsymmetricKeypair)1 HashDigest (com.jd.blockchain.crypto.HashDigest)1 PrivKey (com.jd.blockchain.crypto.PrivKey)1 DigitalSignature (com.jd.blockchain.ledger.DigitalSignature)1 ParticipantProperties (com.jd.blockchain.ledger.LedgerInitProperties.ParticipantProperties)1 TransactionContent (com.jd.blockchain.ledger.TransactionContent)1 LedgerInitProposal (com.jd.blockchain.ledger.core.LedgerInitProposal)1 LedgerInitProposalData (com.jd.blockchain.ledger.core.LedgerInitProposalData)1 TxRequestMessage (com.jd.blockchain.transaction.TxRequestMessage)1 CountDownLatch (java.util.concurrent.CountDownLatch)1