瀏覽代碼

增加授权文件解密与授权内容加密测试接口

luoshi 1 年之前
父節點
當前提交
d1adcd50a3

+ 20 - 1
src/main/java/com/qmth/ops/api/controller/admin/DeployController.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.boot.core.exception.ParameterException;
+import com.qmth.boot.core.solar.crypto.AppLicenseUtil;
 import com.qmth.boot.tools.device.DeviceInfo;
 import com.qmth.ops.api.constants.OpsApiConstants;
 import com.qmth.ops.api.dto.DeployForm;
@@ -158,6 +159,21 @@ public class DeployController {
                 response.getOutputStream());
     }
 
+    @PostMapping("/license/decrypt")
+    @Aac(auth = false)
+    public Object decryptLicense(@RequestParam MultipartFile file, @RequestParam(required = false) String version)
+            throws Exception {
+        return AppLicenseUtil.parseLicense(file.getBytes(), version);
+    }
+
+    @PostMapping("/license/encrypt")
+    @Aac(auth = false)
+    public void encryptLicense(HttpServletResponse response, @RequestBody Object body) throws Exception {
+        response.setContentType("application/octet-stream; charset=utf-8");
+        response.setHeader("Content-Disposition", "attachment; filename=app.lic");
+        licenseService.encrypt(body, null, null, response.getOutputStream());
+    }
+
     @PostMapping("/org/list")
     public List<OrgVO> listOrg(@RequestParam Long id) {
         OrgQuery query = new OrgQuery();
@@ -170,8 +186,11 @@ public class DeployController {
 
     @PostMapping("/org/update")
     public Object updateOrg(@RequestAttribute AdminSession adminSession, @RequestParam Long id,
-            @RequestParam Long[] orgId) {
+            @RequestParam(required = false) Long[] orgId) {
         adminSession.hasPermission(Permission.DEPLOY_ORG_EDIT, id);
+        if (orgId == null) {
+            orgId = new Long[] {};
+        }
         Deploy deploy = deployService.findById(id);
         if (deploy != null) {
             deployService.updateOrg(deploy, orgId);

+ 5 - 1
src/main/java/com/qmth/ops/biz/service/LicenseService.java

@@ -72,7 +72,11 @@ public class LicenseService {
             }
             query.setPageNumber(query.getPageNumber() + 1);
         }
-        byte[] data = new ObjectMapper().writeValueAsBytes(license);
+        encrypt(license, deviceId, version, ous);
+    }
+
+    public void encrypt(Object content, String deviceId, String version, @NotNull OutputStream ous) throws Exception {
+        byte[] data = new ObjectMapper().writeValueAsBytes(content);
         ByteArrayOutputStream temp = new ByteArrayOutputStream();
         temp.write(CodecUtils.md5(data));
         temp.write(privateKey.encrypt(data).value());

+ 2 - 1
src/main/resources/application.properties

@@ -12,4 +12,5 @@ com.qmth.fss.server=http://oss-file.qmth.com.cn/solar
 
 com.qmth.sms.server=http://127.0.0.1:8090
 
-admin.private-key=/Users/luoshi/Downloads/ops/rsa/test/test-private.key
+admin.private-key=/Users/luoshi/Downloads/ops/rsa/test/test-private.key
+##admin.private-key=/Users/luoshi/Downloads/ops/rsa/prod/prod-private.key