Search in sources :

Example 16 with ProjectKeyInfo

use of com.itrus.portal.db.ProjectKeyInfo in project portal by ixinportal.

the class CustomerServerClientController method onLineByJieSuoYiChang.

/**
 * 解锁异常的的客服在线
 * @param certSn
 * @param keySn
 * @param enterpriseName
 * @param session
 * @param uiModel
 * @return
 */
@RequestMapping("/onLineByJieSuoYiChang")
public String onLineByJieSuoYiChang(@RequestParam(value = "certSn", required = true) String certSn, @RequestParam(value = "keySn", required = true) String keySn, HttpSession session, Model uiModel) {
    UserCert userCert = userCertService.getUserCertByCertSn(certSn);
    if (null == userCert || null == userCert.getUserinfo()) {
        return ComNames.DENG_LU_CLIENT;
    }
    UserInfo userInfo = userInfoService.getUserInfoById(userCert.getUserinfo());
    // 先根据key序列号取项目,若没有,则根据用户所属项目取项目信息
    Project project = null;
    if (StringUtils.isNotBlank(keySn) && StringUtils.isNotBlank(certSn)) {
        ProjectKeyInfo projectKeyInfo = cacheCustomer.findProjectByKey(keySn);
        if (null == projectKeyInfo) {
            uiModel.addAttribute("errorMsg", "无法识别的key序列号:" + keySn + ", 请联系系统管理员进行配置");
            return ComNames.CLIENTFW_ERRORPAGE;
        }
        project = projectService.selectByPrimaryKey(projectKeyInfo.getProject());
    }
    if (null == project) {
        project = projectService.selectByPrimaryKey(userInfo.getProject());
    }
    Map<String, String> map = questionService.auth(project.getId());
    if (map != null && !map.isEmpty()) {
        uiModel.addAttribute("qq", map.get("qq"));
        uiModel.addAttribute("phone", map.get("phone"));
        uiModel.addAttribute("questionUrl", map.get("questionUrl"));
        uiModel.addAttribute("downloadUrl", map.get("downloadUrl"));
    }
    return "clientFW/kefuzaixian";
}
Also used : Project(com.itrus.portal.db.Project) ProjectKeyInfo(com.itrus.portal.db.ProjectKeyInfo) UserInfo(com.itrus.portal.db.UserInfo) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ProjectKeyInfo

use of com.itrus.portal.db.ProjectKeyInfo in project portal by ixinportal.

the class DoUnlockKeyController method veryfyCodeZSJS.

/**
 * 校验解锁码是否正确,正确则返回订单对应的解锁码
 * @param certSn
 * @param keySn
 * @param enterpriseName
 * @param mPhone
 * @param code
 * @param session
 * @return
 */
@RequestMapping("/veryfyCodeZSJS")
@ResponseBody
public Map<String, Object> veryfyCodeZSJS(@RequestParam("billId") Long billId, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, @RequestParam(value = "mPhone", required = true) String mPhone, @RequestParam(value = "code", required = true) String code, HttpSession session) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("retCode", 0);
    Bill bill = null;
    UserInfo userInfo = null;
    try {
        // 发送验证码
        if (!dynamicCodeService.verifyCode(mPhone, code)) {
            retMap.put("retMsg", "动态码验证失败,请重新获取动态码");
            return retMap;
        }
        session.setAttribute("verifyCodeZSJS", true);
        bill = billService.getBill(billId);
        userInfo = userInfoService.getUserInfoById(bill.getUniqueId());
        // 根据key序列号,获取证书
        ProjectKeyInfo projectKeyInfo = cacheCustomer.findProjectByKey(keySn);
        if (null == projectKeyInfo) {
            retMap.put("retMsg", "无法识别该序列号:" + keySn + ", 请联系系统管理进行配置");
            return retMap;
        }
        // TODO 获取订单对应的解锁码,返回给客户端,可能会有解锁码过期 的问题,过期了则进行更新后在返回
        session.setAttribute("verifyCodeZSJS", true);
        KeyUnlock keyUnlock = keyUnlockService.getKeyUnlockByBillId(billId);
        if (!keyUnlockService.isUnlockCodeValid(keyUnlock)) {
            keyUnlock = unlockKeyService.generateUnlockCode(null, null, keyUnlock);
            // 再次进行解锁校验
            if (!keyUnlockService.isUnlockCodeValid(keyUnlock)) {
                retMap.put("retMsg", "产生解锁码失败,请联系系统管理员进行处理!");
                return retMap;
            }
        }
        retMap.put("reqCode", keyUnlock.getReqCode());
        retMap.put("repCode", keyUnlock.getRepCode());
        // 若存在,则返回第二个解锁码
        if (StringUtils.isNotBlank(keyUnlock.getRepCode2())) {
            retMap.put("repCode2", keyUnlock.getRepCode2());
        }
        retMap.put("retCode", 1);
        return retMap;
    } catch (Exception e) {
        retMap.put("retMsg", "校验解锁动态码出现异常,请联系系统管理员进行处理!");
        LogUtil.userlog(sqlSession, bill.getProject(), "校验动态码", "校验出现异常,keySn:" + keySn + "异常信息:" + e.getMessage(), "未知", "", null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
        return retMap;
    }
}
Also used : KeyUnlock(com.itrus.portal.db.KeyUnlock) HashMap(java.util.HashMap) ProjectKeyInfo(com.itrus.portal.db.ProjectKeyInfo) Bill(com.itrus.portal.db.Bill) UserInfo(com.itrus.portal.db.UserInfo) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with ProjectKeyInfo

use of com.itrus.portal.db.ProjectKeyInfo in project portal by ixinportal.

the class DoUnlockKeyController method sendCodeByZSJS.

/**
 * 发送解锁授权码
 * @param mphone
 * @return
 */
@RequestMapping("/sendCodeByZSJS")
@ResponseBody
public Map<String, Object> sendCodeByZSJS(@RequestParam("mPhone") String mPhone, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    retMap.put("retCode", 0);
    Project project = null;
    try {
        // 根据key序列号,获取证书
        ProjectKeyInfo projectKeyInfo = cacheCustomer.findProjectByKey(keySn);
        if (null == projectKeyInfo) {
            retMap.put("retMsg", "无法识别该序列号:" + keySn + ", 请联系系统管理进行配置");
            return retMap;
        }
        project = projectService.selectByPrimaryKey(projectKeyInfo.getProject());
        UserInfo userInfo = userInfoService.getUserInfoByMphone(mPhone);
        if (null == userInfo) {
            retMap.put("retMsg", "手机号对应的用户不存在,请检查手机号是否正确:" + mPhone);
            return retMap;
        }
        // ZSJS表示短信模版类型为‘证书解锁’。
        if (dynamicCodeService.sendCodeZSJS(mPhone, project.getId(), "ZSJS")) {
            retMap.put("retCode", 1);
            return retMap;
        }
    } catch (UserInfoServiceException e) {
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (Exception e) {
        retMap.put("retMsg", "发送证书解锁短信出现异常,请联系系统管理员");
        UserLog userLog = new UserLog();
        userLog.setCreateTime(new Date());
        userLog.setHostId("未知");
        userLog.setInfo(e.getMessage());
        userLog.setIp("未知");
        userLog.setProject(project.getId());
        userLog.setSn(null);
        userLog.setType("发送证书解锁短信");
        return retMap;
    }
    retMap.put("retMsg", "发送证书解锁短信失败,请联系系统管理员");
    return retMap;
}
Also used : Project(com.itrus.portal.db.Project) HashMap(java.util.HashMap) ProjectKeyInfo(com.itrus.portal.db.ProjectKeyInfo) UserInfo(com.itrus.portal.db.UserInfo) UserLog(com.itrus.portal.db.UserLog) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with ProjectKeyInfo

use of com.itrus.portal.db.ProjectKeyInfo in project portal by ixinportal.

the class UnlockKeyServiceImpl method generateUnlockCode.

/**
 * 根据输入的管理员pin码1和2,或者自动计算等生成对应的一个或者两个解锁码
 * @param adminPin
 * @param adminPin2
 * @param projectKeyInfo
 * @return
 * @throws UnlockKeyException
 * @throws NoSuchPaddingException
 * @throws NoSuchAlgorithmException
 * @throws Exception
 */
public KeyUnlock generateUnlockCode(String adminpin, String adminpin2, KeyUnlock keyunlock) throws UnlockKeyException, Exception {
    // 如果没有输入管理员PIN码,则检查预设的管理员PIN码
    // 根据解锁申请的序列号,查询序列号配置信息
    ProjectKeyInfo projectkeyinfo = cacheCustomer.findProjectByKey(keyunlock.getKeySn());
    if (null == projectkeyinfo) {
        throw new UnlockKeyException("无法识别的key序列号:" + keyunlock.getKeySn());
    }
    if (StringUtils.isBlank(adminpin)) {
        if (projectkeyinfo == null || projectkeyinfo.getAdminPinType() == null || projectkeyinfo.getAdminPinType().equals("null")) {
            return null;
        }
        if (projectkeyinfo.getAdminPinType().equals("fix")) {
            String unlockCipher = "AES";
            SecretKeySpec skeySpec = new SecretKeySpec(ProjectKeyInfoController.adminPinEncKey.substring(0, 16).getBytes(), unlockCipher);
            IvParameterSpec ivSpec = new IvParameterSpec(ProjectKeyInfoController.adminPinEncKey.substring(16, 32).getBytes());
            Cipher cipher = Cipher.getInstance(unlockCipher + "/CBC/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec, null);
            byte[] decadminpin = cipher.doFinal(Base64.decode(projectkeyinfo.getAdminPinValue().getBytes()));
            adminpin = new String(decadminpin);
        } else if (// 自动计算序列号
        projectkeyinfo.getAdminPinType().equals("autoht"))
            adminpin = HMACSHA1.getSoPinHT(keyunlock.getKeySn());
        else if (projectkeyinfo.getAdminPinType().equals("autoft"))
            adminpin = HMACSHA1.getSoPinFT(keyunlock.getKeySn());
        else if (projectkeyinfo.getAdminPinType().equals("autokoal"))
            adminpin = HMACSHA1.getSoPinKOAL(keyunlock.getKeySn());
    }
    // 再次判断,如果管理员PIN码为空,则要求重新输入
    if (adminpin == null || adminpin.length() == 0) {
        return null;
    }
    // 产生 encPrivateKeyKMC
    String unlockCipher = "AES";
    SecretKeySpec skeySpec = new SecretKeySpec(keyunlock.getReqCode().substring(0, 16).getBytes(), unlockCipher);
    IvParameterSpec ivSpec = new IvParameterSpec(keyunlock.getReqCode().substring(16).getBytes());
    Cipher cipher = Cipher.getInstance(unlockCipher + "/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec, ivSpec, null);
    byte[] encadminpin = cipher.doFinal(adminpin.getBytes());
    String sencadminpin = new String(Base64.encode(encadminpin));
    keyunlock.setRepCode(sencadminpin);
    // 产生第二个解锁码
    if (StringUtils.isBlank(adminpin2)) {
        if (null != projectkeyinfo && null != projectkeyinfo.getAdminPinType2() && !projectkeyinfo.getAdminPinType2().toLowerCase().equals("null")) {
            // 固定值序列号
            if (projectkeyinfo.getAdminPinType2().equals("fix")) {
                String unlockCipher2 = "AES";
                SecretKeySpec skeySpec2 = new SecretKeySpec(ProjectKeyInfoController.adminPinEncKey.substring(0, 16).getBytes(), unlockCipher2);
                IvParameterSpec ivSpec2 = new IvParameterSpec(ProjectKeyInfoController.adminPinEncKey.substring(16, 32).getBytes());
                Cipher cipher2 = Cipher.getInstance(unlockCipher2 + "/CBC/PKCS5Padding");
                cipher2.init(Cipher.DECRYPT_MODE, skeySpec2, ivSpec2, null);
                byte[] decadminpin2 = cipher2.doFinal(Base64.decode(projectkeyinfo.getAdminPinValue2().getBytes()));
                adminpin2 = new String(decadminpin2);
            } else // 自动计算序列号
            if (projectkeyinfo.getAdminPinType2().equals("autoht"))
                adminpin2 = HMACSHA1.getSoPinHT(keyunlock.getKeySn());
            else if (projectkeyinfo.getAdminPinType2().equals("autoft"))
                adminpin2 = HMACSHA1.getSoPinFT(keyunlock.getKeySn());
            else if (projectkeyinfo.getAdminPinType2().equals("autokoal"))
                adminpin2 = HMACSHA1.getSoPinKOAL(keyunlock.getKeySn());
        }
    }
    // 再次判断,如果管理员PIN2码为空,则返回输入的第一个管理员pin码即可
    if (StringUtils.isBlank(adminpin2)) {
        keyunlock.setApproveTime(new Date());
        keyunlock.setStatus("APPROVE");
        sqlSession.update("com.itrus.portal.db.KeyUnlockMapper.updateByPrimaryKey", keyunlock);
        return keyunlock;
    }
    // 产生 encPrivateKeyKMC
    String unlockCipher2 = "AES";
    SecretKeySpec skeySpec2 = new SecretKeySpec(keyunlock.getReqCode().substring(0, 16).getBytes(), unlockCipher2);
    IvParameterSpec ivSpec2 = new IvParameterSpec(keyunlock.getReqCode().substring(16).getBytes());
    Cipher cipher2 = Cipher.getInstance(unlockCipher2 + "/CBC/PKCS5Padding");
    cipher2.init(Cipher.ENCRYPT_MODE, skeySpec2, ivSpec2, null);
    byte[] encadminpin2 = cipher.doFinal(adminpin2.getBytes());
    String sencadminpin2 = new String(Base64.encode(encadminpin2));
    keyunlock.setRepCode2(sencadminpin2);
    keyunlock.setApproveTime(new Date());
    keyunlock.setStatus("APPROVE");
    sqlSession.update("com.itrus.portal.db.KeyUnlockMapper.updateByPrimaryKey", keyunlock);
    return keyunlock;
}
Also used : UnlockKeyException(com.itrus.portal.exception.UnlockKeyException) ProjectKeyInfo(com.itrus.portal.db.ProjectKeyInfo) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) Date(java.util.Date)

Aggregations

ProjectKeyInfo (com.itrus.portal.db.ProjectKeyInfo)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 Project (com.itrus.portal.db.Project)12 UserInfo (com.itrus.portal.db.UserInfo)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 HashMap (java.util.HashMap)6 UserCert (com.itrus.portal.db.UserCert)5 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)5 Enterprise (com.itrus.portal.db.Enterprise)4 ProjectKeyInfoExample (com.itrus.portal.db.ProjectKeyInfoExample)4 UserinfoEnterprise (com.itrus.portal.db.UserinfoEnterprise)3 Cipher (javax.crypto.Cipher)3 IvParameterSpec (javax.crypto.spec.IvParameterSpec)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 Ereceipt (com.itrus.portal.db.Ereceipt)2 Product (com.itrus.portal.db.Product)2 IOException (java.io.IOException)2 Date (java.util.Date)2 ActivityMsgTemp (com.itrus.portal.db.ActivityMsgTemp)1 Bill (com.itrus.portal.db.Bill)1