Search in sources :

Example 1 with ResKeyEscrowEnroll

use of com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowEnroll in project PCNGateway-Java-SDK by BSNDA.

the class UserService method userEnroll.

/**
 * User certificate registration in Public Key Upload Mode
 * When a user participated in the application in the public key upload mode needs to register a sub-user, after completing the user registration interface, he/she can call this interface to upload a public key certificate application file and obtain a sub-user certificate issued by the city node.
 * An exception will be returned when this interface is called in key trust mode.
 */
public static ResKeyEscrowEnroll userEnroll(@NotNull ReqKeyEscrowEnroll kes) throws IOException {
    String api = Config.config.getApi() + PathUtil.FABRIC_USER_ENROLL;
    UserCertInfo certInfo = StoreUtils.generateCSR(kes.getName(), Config.config.getAppCode());
    kes.setCsrPem(certInfo.getCSRPem());
    BaseReqModel<ReqKeyEscrowEnroll> req = new BaseReqModel<ReqKeyEscrowEnroll>();
    req.setReqHeader(Config.config.getUserCode(), Config.config.getAppCode());
    req.setBody(kes);
    HttpService<ReqKeyEscrowEnroll, ResKeyEscrowEnroll> httpService = new HttpService<ReqKeyEscrowEnroll, ResKeyEscrowEnroll>();
    BaseResModel<ResKeyEscrowEnroll> res = httpService.post(req, api, ResKeyEscrowEnroll.class);
    ResKeyEscrowEnroll body = res.getBody();
    // Save the private key
    Config.config.getKeyStore().storeUserPrivateKey(kes.getName(), Config.config.getAppCode(), certInfo.getKey());
    // Save the registered certificate
    Config.config.getKeyStore().storeUserCert(kes.getName(), Config.config.getAppCode(), body.getCert());
    return body;
}
Also used : UserCertInfo(com.bsnbase.sdk.util.common.UserCertInfo) BaseReqModel(com.bsnbase.sdk.entity.base.BaseReqModel) HttpService(com.bsnbase.sdk.util.common.HttpService) ReqKeyEscrowEnroll(com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowEnroll) ResKeyEscrowEnroll(com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowEnroll)

Aggregations

BaseReqModel (com.bsnbase.sdk.entity.base.BaseReqModel)1 ReqKeyEscrowEnroll (com.bsnbase.sdk.entity.req.fabric.ReqKeyEscrowEnroll)1 ResKeyEscrowEnroll (com.bsnbase.sdk.entity.resp.fabric.ResKeyEscrowEnroll)1 HttpService (com.bsnbase.sdk.util.common.HttpService)1 UserCertInfo (com.bsnbase.sdk.util.common.UserCertInfo)1