主密钥校验值
This commit is contained in:
@@ -3,13 +3,19 @@ package com.sunyard.chsm.controller;
|
||||
import com.sunyard.chsm.model.R;
|
||||
import com.sunyard.chsm.model.dto.TmkStatus;
|
||||
import com.sunyard.chsm.service.TmkService;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 主密钥管理
|
||||
@@ -45,5 +51,63 @@ public class TmkController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份主密钥
|
||||
*/
|
||||
@PostMapping("/backup")
|
||||
public R<String> backup(@Valid @RequestBody TmkBackupReq req) {
|
||||
String en = tmkService.backup(req.pubKey);
|
||||
return R.data(en);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备公钥
|
||||
*/
|
||||
@GetMapping("/devicePubKey")
|
||||
public R<DevicePubKey> getDevicePubKey() {
|
||||
Pair<Long, String> pair = tmkService.getDevicePubKey();
|
||||
DevicePubKey res = new DevicePubKey();
|
||||
res.deviceId = pair.getLeft();
|
||||
res.pubKey = pair.getRight();
|
||||
return R.data(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入主密钥
|
||||
*/
|
||||
@PostMapping("/import")
|
||||
public R<Void> importTmk(@Valid @RequestBody TmkImportReq req) {
|
||||
tmkService.importTmk(req.deviceId, req.encTmk);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class DevicePubKey {
|
||||
private Long deviceId;
|
||||
private String pubKey;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TmkBackupReq {
|
||||
/**
|
||||
* ukey公钥
|
||||
*/
|
||||
@NotEmpty(message = "公钥不能为空")
|
||||
private String pubKey;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TmkImportReq {
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
@NotNull(message = "设备id不能为空")
|
||||
private Long deviceId;
|
||||
/**
|
||||
* 加密主密钥
|
||||
*/
|
||||
@NotEmpty(message = "加密主密钥不能为空")
|
||||
private String encTmk;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user