Search in sources :

Example 1 with AlgorithmTypeEnum

use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.

the class BaseResArrayModel method verify.

@Override
public boolean verify() throws Exception {
    String signValue = (this.header == null ? "" : this.header.getHeaderString());
    for (int i = 0; i < this.body.size(); i++) {
        signValue += this.body.get(i).getEncryptionValue();
    }
    AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
    AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
    boolean verify = algorithmTypeContext.getAlgorithmTypeHandle().verify(PublicConfig.getPublicKey(algorithmTypeEnum), this.mac, signValue);
    return verify;
}
Also used : AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum) AlgorithmTypeContext(com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext)

Example 2 with AlgorithmTypeEnum

use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.

the class BaseResModel method verify.

/**
 * Gateway returns the result of signature verfication
 */
@Override
public boolean verify() throws Exception {
    String signValue = (this.header == null ? "" : this.header.getHeaderString()) + (this.body == null ? "" : this.body.getEncryptionValue());
    AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
    AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
    boolean verify = algorithmTypeContext.getAlgorithmTypeHandle().verify(PublicConfig.getPublicKey(algorithmTypeEnum), this.mac, signValue);
    return verify;
}
Also used : AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum) AlgorithmTypeContext(com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext)

Example 3 with AlgorithmTypeEnum

use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.

the class TransactionService method nodeTrans.

/**
 * Invoke chaincode in Public Key Upload Mode
 * <p>
 * When the user of the public key upload mode application needs to initiate a transaction from the off-chain system to the chaincode on the chain, he/she needs to assemble the transaction message locally and call this interface to initiate the transaction.
 */
public static ResKeyEscrowNo nodeTrans(@NotNull ReqKeyEscrow reqkey) throws NoSuchAlgorithmException {
    String api = Config.config.getApi() + PathUtil.FABRIC_NODE_TRANS;
    TransactionUser user = null;
    try {
        user = Config.config.getKeyStore().loadUser(reqkey.getUserName(), Config.config.getAppCode());
        user.setMspId(Config.config.getAppInfo().getMspId());
        AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
        if (algorithmTypeEnum == AlgorithmTypeEnum.AppAlgorithmType_SM2 && Config.config.getAppInfo().getFabricVersion().equals("2.2.1")) {
            user.setSM3(true);
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.USER_CERTIFICATE_ERROR.getMsg());
    }
    // Assemble the transaction information
    TransactionRequest request = new TransactionRequest();
    request.setChannelId(Config.config.getAppInfo().getChannelId());
    request.setArgs(Common.StringBytesConvert(reqkey.getArgs()));
    request.setTransientMap(reqkey.getTransientData());
    request.setChaincodeId(reqkey.getChainCode());
    request.setFcn(reqkey.getFuncName());
    String transData = null;
    try {
        transData = getTransdata(request, user);
    } catch (Exception e) {
        e.printStackTrace();
        throw new GlobalException(ResultInfoEnum.TRANSACTION_CONVERSION_ERROR.getMsg());
    }
    ReqKeyEscrowNo keyNo = new ReqKeyEscrowNo();
    keyNo.setTransData(transData);
    BaseReqModel<ReqKeyEscrowNo> req = new BaseReqModel<ReqKeyEscrowNo>();
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    req.setBody(keyNo);
    HttpService<ReqKeyEscrowNo, ResKeyEscrowNo> httpService = new HttpService<ReqKeyEscrowNo, ResKeyEscrowNo>();
    BaseResModel<ResKeyEscrowNo> res = httpService.post(req, api, ResKeyEscrowNo.class);
    return res.getBody();
}
Also used : ResKeyEscrowNo(com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo) ReqKeyEscrowNo(com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo) IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) TransactionRequest(com.bsnbase.sdk.entity.transactionHeader.TransactionRequest) IOException(java.io.IOException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) TransactionUser(com.bsnbase.sdk.entity.transactionHeader.TransactionUser) HttpService(com.bsnbase.sdk.util.common.HttpService) AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)

Example 4 with AlgorithmTypeEnum

use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.

the class FiscoTransUtil method getEncryptTypeByAlgorithmType.

private static EncryptType getEncryptTypeByAlgorithmType(Integer algorithmType) {
    EncryptType encryptType = null;
    AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(algorithmType);
    switch(algorithmTypeEnum) {
        case AppAlgorithmType_SM2:
            encryptType = new EncryptType(1);
            break;
        case AppAlgorithmType_K1:
            encryptType = new EncryptType(0);
            break;
        default:
    }
    if (Objects.isNull(encryptType)) {
        throw new GlobalException(ResultInfoEnum.ALGORITHM_TYPE_ERROR);
    }
    return encryptType;
}
Also used : EncryptType(org.fisco.bcos.web3j.crypto.EncryptType) AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Example 5 with AlgorithmTypeEnum

use of com.bsnbase.sdk.util.enums.AlgorithmTypeEnum in project PCNGateway-Java-SDK by BSNDA.

the class StoreUtils method generateCSR.

/**
 * csr generation
 *
 * @param name
 * @param appCode
 * @return
 */
public static UserCertInfo generateCSR(String name, String appCode) {
    try {
        String DN = "CN=" + Common.getCNName(name, appCode) + ",OU=client";
        AlgorithmTypeEnum algorithmTypeEnum = AlgorithmTypeEnum.fromAlgorithmTypeEnum(Config.config.getAppInfo().getAlgorithmType());
        AlgorithmTypeContext algorithmTypeContext = new AlgorithmTypeContext(algorithmTypeEnum);
        UserCertInfo certInfo = algorithmTypeContext.getAlgorithmTypeHandle().getUserCertInfo(DN);
        if (Objects.isNull(certInfo)) {
            throw new GlobalException(ResultInfoEnum.ALGORITHM_TYPE_ERROR);
        }
        return certInfo;
    } catch (Exception e) {
        logger.error("Get CSR Exception", e);
        throw new GlobalException("Get CSR Exception");
    }
}
Also used : AlgorithmTypeEnum(com.bsnbase.sdk.util.enums.AlgorithmTypeEnum) AlgorithmTypeContext(com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext) GlobalException(com.bsnbase.sdk.util.exception.GlobalException) GlobalException(com.bsnbase.sdk.util.exception.GlobalException)

Aggregations

AlgorithmTypeEnum (com.bsnbase.sdk.util.enums.AlgorithmTypeEnum)7 GlobalException (com.bsnbase.sdk.util.exception.GlobalException)5 AlgorithmTypeContext (com.bsnbase.sdk.util.algorithm.AlgorithmTypeContext)4 IOException (java.io.IOException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)1 ReqKeyEscrowNo (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowNo)1 ResKeyEscrowNo (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowNo)1 TransactionRequest (com.bsnbase.sdk.entity.transactionHeader.TransactionRequest)1 TransactionUser (com.bsnbase.sdk.entity.transactionHeader.TransactionUser)1 HttpService (com.bsnbase.sdk.util.common.HttpService)1 EncryptType (org.fisco.bcos.web3j.crypto.EncryptType)1 ProposalPackage (org.hyperledger.fabric.protos.peer.ProposalPackage)1