feat:文件上传的功能开发

chore/issuance-comments-zh
赵佳正 2 months ago
parent 9a55f2747f
commit 1cf2bac39a

@ -29,7 +29,11 @@ public class ControlSystemSignatureService {
@Resource private InstitutionTrainingErrorRecorder errorRecorder;
@Transactional
public ControlSystemDigestResult digest(String originalText, InstitutionKeySubject subject, String operator) {
public ControlSystemDigestResult digest(String originalText, String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
TransactionInformationIdentifierEntity transaction = requireQuotaVerified(subject);
String normalizedOriginalText = validateOriginalText(originalText, transaction, subject);
ControlSystemSignatureEntity current = latest(subject);
@ -73,7 +77,11 @@ public class ControlSystemSignatureService {
}
@Transactional
public ControlSystemSignatureResult sign(String privateKey, InstitutionKeySubject subject, String operator) {
public ControlSystemSignatureResult sign(String privateKey, String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
ControlSystemSignatureEntity value = requireLatest(subject);
requireResult(value.getDigest(), "请先计算控制系统签名摘要");
String signature = keyService.signCentralBank(subject, privateKey, value.getDigest());

@ -34,7 +34,11 @@ public class CurrencyGenerationRequestService {
@Transactional
public CurrencyDigestResult generateDigest(BigDecimal amount, String deliveryNodeCode,
String institutionIdentifier, String requestTimestamp,
InstitutionKeySubject subject, String operator) {
String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
IssuedInstitutionIdentifierResult identifier = identifierQueryService.requireLatestFeedbacked(subject);
if (!identifier.getInstitutionIdentifier().equals(institutionIdentifier)) {
throw new BusinessException(ErrorCode.VALIDATION_ERROR,
@ -67,7 +71,11 @@ public class CurrencyGenerationRequestService {
}
@Transactional
public CurrencyRequestResult sign(String privateKey, InstitutionKeySubject subject, String operator) {
public CurrencyRequestResult sign(String privateKey, String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CurrencyGenerationRequest request = requireCurrentIdentifierRequest(subject);
CurrencyGenerationRequest.Status expected = request.getStatus();
String signature = keyService.signCommercialBank(subject, privateKey, requireDigest(request));

@ -73,8 +73,12 @@ public class CurrencyGenerationVerificationService {
}
@Transactional
public CurrencyDigestResult calculateDigest(long id, String requestOriginalText,
public CurrencyDigestResult calculateDigest(long id, String requestOriginalText, String algorithm,
InstitutionKeySubject subject, String operator) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CurrencyGenerationVerification value = require(id, subject);
CurrencyGenerationVerification.Status expected = value.getStatus();
String digest = cryptography.sm3(requestOriginalText);
@ -120,7 +124,11 @@ public class CurrencyGenerationVerificationService {
@Transactional
public CurrencyConfirmationSignatureResult confirm(long id, String requestDigest, String privateKey,
InstitutionKeySubject subject, String operator) {
String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CurrencyGenerationVerification value = require(id, subject);
if (!value.getRequestDigest().equalsIgnoreCase(requestDigest)) {
throw scoreError(subject, "输入请求摘要与步骤二请求报文摘要不一致");

@ -52,7 +52,11 @@ public class InstitutionIdentifierStepService {
}
@Transactional
public InstitutionDigestResult digest(String originalText, InstitutionKeySubject subject, String operator) {
public InstitutionDigestResult digest(String originalText, String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
String normalizedOriginalText = normalize(originalText);
String[] parts = normalizedOriginalText.split("\\|", -1);
if (parts.length != 2) {
@ -79,7 +83,11 @@ public class InstitutionIdentifierStepService {
}
@Transactional
public InstitutionSignatureResult sign(String privateKey, InstitutionKeySubject subject, String operator) {
public InstitutionSignatureResult sign(String privateKey, String algorithm, InstitutionKeySubject subject, String operator) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
InstitutionIdentifierApplication application = requireCurrent(subject,
"当前没有待签名的本轮机构标识数据");
if (application.getDigest() == null) {

@ -158,8 +158,9 @@ public class QuotaControlBitService {
if (!expectedControlBit.equals(submittedControlBit)) {
throw keyError(subject, "完整额度控制位与静态段、动态段及央行签名段拼接结果不一致");
}
if (!"SM2".equalsIgnoreCase(algorithm == null ? "" : algorithm.trim())) {
throw keyError(subject, "签名算法必须选择SM2");
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
String signature = keyService.signCommercialBank(subject, privateKey, submittedControlBit);
if (signature == null) {

@ -74,8 +74,12 @@ public class TransactionInformationIdentifierService {
}
@Transactional
public TransactionDigestResult digest(String originalText, InstitutionKeySubject subject,
public TransactionDigestResult digest(String originalText, String algorithm, InstitutionKeySubject subject,
String operator) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CurrencyGenerationVerificationEntity verification = requireCompletedVerification(subject);
CurrencyGenerationRequestEntity request = requireCompletedRequest(verification.getRequestId(), subject);
InstitutionIdentifierApplicationEntity application = requireCompletedIdentifier(
@ -192,9 +196,13 @@ public class TransactionInformationIdentifierService {
return new QuotaRequestSourceDataResult(value);
}
@Transactional
public QuotaRequestDigestResult digestQuotaRequest(String originalText,
public QuotaRequestDigestResult digestQuotaRequest(String originalText, String algorithm,
InstitutionKeySubject subject,
String operator) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
TransactionInformationIdentifier value = requireLatest(subject);
TransactionInformationIdentifier.Status expected = value.getStatus();
String requestId = "QR_" + LocalDateTime.ofInstant(clock.instant(), ZoneOffset.UTC)
@ -212,8 +220,12 @@ public class TransactionInformationIdentifierService {
}
@Transactional
public TransactionInformationIdentifierResult signQuotaRequest(String privateKey, InstitutionKeySubject subject,
public TransactionInformationIdentifierResult signQuotaRequest(String privateKey, String algorithm, InstitutionKeySubject subject,
String operator) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
errorRecorder.recordScoreError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
TransactionInformationIdentifier value = requireLatest(subject);
if (value.getQuotaDigest() == null) {
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "请先完成步骤五额度请求摘要");

@ -24,8 +24,14 @@ public class CalculateCurrencyDigestRequest {
@NotBlank(message = "请求原文不能为空")
private String requestOriginalText;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
public Long getVerificationId() { return verificationId; }
public void setVerificationId(Long verificationId) { this.verificationId = verificationId; }
public String getRequestOriginalText() { return requestOriginalText; }
public void setRequestOriginalText(String requestOriginalText) { this.requestOriginalText = requestOriginalText; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -29,10 +29,16 @@ public class ConfirmCurrencyRequest {
@NotBlank(message = "中央银行第一私钥不能为空")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
public Long getVerificationId() { return verificationId; }
public void setVerificationId(Long verificationId) { this.verificationId = verificationId; }
public String getRequestDigest() { return requestDigest; }
public void setRequestDigest(String requestDigest) { this.requestDigest = requestDigest; }
public String getPrivateKey() { return privateKey; }
public void setPrivateKey(String privateKey) { this.privateKey = privateKey; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -11,6 +11,10 @@ public class ControlSystemDigestRequest {
example = "1589.85|ORG_3A4B5C6D7E8F|TXN_7A8B9C0D1E2F3A4B5C6D7E8F9A0B1C2D3E4F5A6B7C8D9E0F1A2B3C4D5E6F")
private String originalText;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
public String getOriginalText() {
return originalText;
}
@ -18,4 +22,6 @@ public class ControlSystemDigestRequest {
public void setOriginalText(String originalText) {
this.originalText = originalText;
}
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -10,6 +10,12 @@ public class ControlSystemSignRequest {
@Schema(description = "当前实训主体的中央银行第一私钥", required = true)
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
public String getPrivateKey() { return privateKey; }
public void setPrivateKey(String privateKey) { this.privateKey = privateKey; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotBlank;
@ApiModel(description = "货币生成的步骤二货币生成请求签名参数")
@Schema(description = "货币生成的步骤二货币生成请求签名参数;请求记录由JWT主体和货币生成的步骤一机构标识自动定位")
public class CurrencyRequestStepRequest {
@ -13,6 +15,12 @@ public class CurrencyRequestStepRequest {
example = "8A7B9C2D4F1E3A5B7C9D2E4F6A8B1C3D2E5F7A8B9C0D1E2F3A4B5C6D7E8F9A0B")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
public String getPrivateKey() { return privateKey; }
public void setPrivateKey(String privateKey) { this.privateKey = privateKey; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -49,6 +49,10 @@ public class GenerateCurrencyDigestRequest {
@Pattern(regexp = "\\d{14}", message = "请求时间戳格式不正确")
private String requestTimestamp;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
public BigDecimal getAmount() { return amount; }
public void setAmount(BigDecimal amount) { this.amount = amount; }
public String getDeliveryNodeCode() { return deliveryNodeCode; }
@ -57,4 +61,6 @@ public class GenerateCurrencyDigestRequest {
public void setInstitutionIdentifier(String institutionIdentifier) { this.institutionIdentifier = institutionIdentifier; }
public String getRequestTimestamp() { return requestTimestamp; }
public void setRequestTimestamp(String requestTimestamp) { this.requestTimestamp = requestTimestamp; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -12,6 +12,13 @@ import javax.validation.constraints.Pattern;
public class GenerateInstitutionIdentifierRequest {
@Schema(description = "完整申请原文,格式为银行代码|14位时间戳", required = true, example = "BKCHCNBJ00001|20260730143218")
private String bankCode;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
public String getBankCode() { return bankCode; }
public void setBankCode(String bankCode) { this.bankCode = bankCode; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -4,6 +4,8 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.NotBlank;
@ApiModel(description = "货币生成的步骤四生成交易信息摘要参数")
@Schema(description = "货币生成的步骤四生成交易信息摘要参数")
public class GenerateTransactionDigestRequest {
@ -13,6 +15,10 @@ public class GenerateTransactionDigestRequest {
// example = "1589.85|ORG_3A4B5C6D7E8F|20260730153330")
private String originalText;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
public String getOriginalText() {
return originalText;
}
@ -20,4 +26,6 @@ public class GenerateTransactionDigestRequest {
public void setOriginalText(String originalText) {
this.originalText = originalText;
}
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotBlank;
@ApiModel(description = "货币生成的步骤一商业银行签名请求")
@Schema(description = "货币生成的步骤一商业银行签名请求")
@ -13,6 +14,12 @@ public class InstitutionIdentifierStepRequest {
@Schema(description = "商业银行第二私钥完整值", required = true, example = "8A7B9C2D4F1E3A5B7C9D2E4F6A8B1C3D2E5F7A8B9C0D1E2F3A4B5C6D7E8F9A0B")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
public String getPrivateKey() { return privateKey; }
public void setPrivateKey(String privateKey) { this.privateKey = privateKey; }
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -11,6 +11,10 @@ public class QuotaRequestDigestRequest {
example = "1589.85|ORG_3A4B5C6D7E8F|TXN_7A8B9C0D1E2F3A4B5C6D7E8F9A0B1C2D3E4F5A6B7C8D9E0F1A2B3C4D5E6F")
private String originalText;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
public String getOriginalText() {
return originalText;
}
@ -18,4 +22,6 @@ public class QuotaRequestDigestRequest {
public void setOriginalText(String originalText) {
this.originalText = originalText;
}
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -10,6 +10,10 @@ public class QuotaRequestSignRequest {
@Schema(description = "当前实训主体的商业银行第二SM2私钥完整值", required = true)
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
public String getPrivateKey() {
return privateKey;
}
@ -17,4 +21,6 @@ public class QuotaRequestSignRequest {
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public String getAlgorithm() { return algorithm; }
public void setAlgorithm(String algorithm) { this.algorithm = algorithm; }
}

@ -36,8 +36,8 @@ public class ControlSystemSignatureController {
public ApiResponse<ControlSystemDigestResult> digest(
@Valid @RequestBody ControlSystemDigestRequest request) {
JwtUser user = AuthContextHolder.get();
return ApiResponse.success(service.digest(request.getOriginalText(), InstitutionKeySubject.from(user),
user.getUsername()), traceId());
return ApiResponse.success(service.digest(request.getOriginalText(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername()), traceId());
}
@PostMapping("/steps/sign")
@ -45,7 +45,7 @@ public class ControlSystemSignatureController {
public ApiResponse<SignatureResult> sign(
@Valid @RequestBody ControlSystemSignRequest request) {
JwtUser user = AuthContextHolder.get();
ControlSystemSignatureResult result = service.sign(request.getPrivateKey(),
ControlSystemSignatureResult result = service.sign(request.getPrivateKey(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername());
return ApiResponse.success(new SignatureResult(result.getSignature()), traceId());
}

@ -40,7 +40,7 @@ public class CurrencyGenerationRequestController {
JwtUser jwtUser = AuthContextHolder.get();
return ApiResponse.success(currencyRequestService.generateDigest(request.getAmount(),
request.getDeliveryNodeCode(), request.getInstitutionIdentifier(), request.getRequestTimestamp(),
InstitutionKeySubject.from(jwtUser), jwtUser.getUsername()), traceId());
request.getAlgorithm(), InstitutionKeySubject.from(jwtUser), jwtUser.getUsername()), traceId());
}
@PostMapping("/steps/sign")
@ -48,7 +48,7 @@ public class CurrencyGenerationRequestController {
public ApiResponse<SignatureResult> sign(
@Valid @RequestBody CurrencyRequestStepRequest request) {
JwtUser jwtUser = AuthContextHolder.get();
CurrencyRequestResult result = currencyRequestService.sign(request.getPrivateKey(),
CurrencyRequestResult result = currencyRequestService.sign(request.getPrivateKey(), request.getAlgorithm(),
InstitutionKeySubject.from(jwtUser), jwtUser.getUsername());
return ApiResponse.success(new SignatureResult(result.getBankSignature()), traceId());
}

@ -66,7 +66,8 @@ public class CurrencyGenerationVerificationController {
@Valid @RequestBody CalculateCurrencyDigestRequest request) {
JwtUser user = AuthContextHolder.get();
CurrencyDigestResult result = service.calculateDigest(request.getVerificationId(),
request.getRequestOriginalText(), InstitutionKeySubject.from(user), user.getUsername());
request.getRequestOriginalText(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername());
return ApiResponse.success(result, MDC.get(TraceIdFilter.MDC_KEY));
}
@ -96,8 +97,8 @@ public class CurrencyGenerationVerificationController {
@Valid @RequestBody ConfirmCurrencyRequest request) {
JwtUser user = AuthContextHolder.get();
CurrencyConfirmationSignatureResult result = service.confirm(request.getVerificationId(),
request.getRequestDigest(), request.getPrivateKey(), InstitutionKeySubject.from(user),
user.getUsername());
request.getRequestDigest(), request.getPrivateKey(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername());
return ApiResponse.success(new SignatureResult(result.getCentralBankSignature()),
MDC.get(TraceIdFilter.MDC_KEY));
}

@ -80,8 +80,8 @@ public class InstitutionIdentifierController {
public ApiResponse<InstitutionDigestResult> digest(
@Valid @RequestBody GenerateInstitutionIdentifierRequest request) {
JwtUser jwtUser = AuthContextHolder.get();
return ApiResponse.success(stepService.digest(request.getBankCode(), InstitutionKeySubject.from(jwtUser),
jwtUser.getUsername()), traceId());
return ApiResponse.success(stepService.digest(request.getBankCode(), request.getAlgorithm(),
InstitutionKeySubject.from(jwtUser), jwtUser.getUsername()), traceId());
}
@PostMapping("/steps/sign")
@ -90,7 +90,7 @@ public class InstitutionIdentifierController {
public ApiResponse<SignatureResult> sign(
@Valid @RequestBody InstitutionIdentifierStepRequest request) {
JwtUser jwtUser = AuthContextHolder.get();
InstitutionSignatureResult result = stepService.sign(request.getPrivateKey(),
InstitutionSignatureResult result = stepService.sign(request.getPrivateKey(), request.getAlgorithm(),
InstitutionKeySubject.from(jwtUser), jwtUser.getUsername());
return ApiResponse.success(new SignatureResult(result.getSignature()), traceId());
}

@ -48,7 +48,7 @@ public class QuotaRequestController {
public ApiResponse<QuotaRequestDigestResult> digest(
@Valid @RequestBody QuotaRequestDigestRequest request) {
JwtUser user = AuthContextHolder.get();
return ApiResponse.success(service.digestQuotaRequest(request.getOriginalText(),
return ApiResponse.success(service.digestQuotaRequest(request.getOriginalText(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername()), traceId());
}
@ -59,7 +59,8 @@ public class QuotaRequestController {
@Valid @RequestBody QuotaRequestSignRequest request) {
JwtUser user = AuthContextHolder.get();
TransactionInformationIdentifierResult result = service.signQuotaRequest(
request.getPrivateKey(), InstitutionKeySubject.from(user), user.getUsername());
request.getPrivateKey(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername());
return ApiResponse.success(new QuotaRequestSignatureResult(result.getQuotaSignature()), traceId());
}

@ -36,8 +36,8 @@ public class TransactionInformationIdentifierController {
public ApiResponse<TransactionDigestResult> digest(
@Valid @RequestBody GenerateTransactionDigestRequest request) {
JwtUser user = AuthContextHolder.get();
return ApiResponse.success(service.digest(request.getOriginalText(), InstitutionKeySubject.from(user),
user.getUsername()), MDC.get(TraceIdFilter.MDC_KEY));
return ApiResponse.success(service.digest(request.getOriginalText(), request.getAlgorithm(),
InstitutionKeySubject.from(user), user.getUsername()), MDC.get(TraceIdFilter.MDC_KEY));
}
@PostMapping("/steps/assemble")

@ -72,7 +72,11 @@ public class CentralWalletActivationService {
}
@Transactional
public CentralWalletActivationPageResult verifySignature(InstitutionKeySubject subject, String publicKeyInput) {
public CentralWalletActivationPageResult verifySignature(InstitutionKeySubject subject, String publicKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletActivation a = getOrCreate(subject);
if (!a.isReceived()) {
scoreService.recordError(subject.getUserId());
@ -102,7 +106,11 @@ public class CentralWalletActivationService {
}
@Transactional
public CentralWalletActivationPageResult recalculateDigest(InstitutionKeySubject subject) {
public CentralWalletActivationPageResult recalculateDigest(InstitutionKeySubject subject, String algorithm) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletActivation a = getOrCreate(subject);
if (a.getSignVerifyResult() == null || !a.getSignVerifyResult().startsWith("通过")) {
scoreService.recordError(subject.getUserId());
@ -148,7 +156,11 @@ public class CentralWalletActivationService {
}
@Transactional
public CentralWalletActivationPageResult verifyFinalSignature(InstitutionKeySubject subject, String publicKeyInput) {
public CentralWalletActivationPageResult verifyFinalSignature(InstitutionKeySubject subject, String publicKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletActivation a = getOrCreate(subject);
if (!a.isWalletActivated()) {
scoreService.recordError(subject.getUserId());
@ -181,7 +193,11 @@ public class CentralWalletActivationService {
}
@Transactional
public CentralWalletActivationPageResult finalSign(InstitutionKeySubject subject, String privateKeyInput) {
public CentralWalletActivationPageResult finalSign(InstitutionKeySubject subject, String privateKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletActivation a = getOrCreate(subject);
if (a.getStep5SignVerifyResult() == null || !a.getStep5SignVerifyResult().startsWith("通过")) {
scoreService.recordError(subject.getUserId());

@ -72,7 +72,11 @@ public class CentralWalletRegistrationService {
}
@Transactional
public String verifySignature(InstitutionKeySubject subject, String publicKeyInput) {
public String verifySignature(InstitutionKeySubject subject, String publicKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletRegistration c = getOrCreate(subject);
if (!c.isReceived()) {
scoreService.recordError(subject.getUserId());
@ -102,7 +106,11 @@ public class CentralWalletRegistrationService {
}
@Transactional
public String recalculateDigest(InstitutionKeySubject subject, String requestMessageInput) {
public String recalculateDigest(InstitutionKeySubject subject, String requestMessageInput, String algorithm) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletRegistration c = getOrCreate(subject);
if (c.getSignVerifyResult() == null || !c.getSignVerifyResult().startsWith("通过")) {
scoreService.recordError(subject.getUserId());
@ -133,7 +141,11 @@ public class CentralWalletRegistrationService {
}
@Transactional
public String cbSign(InstitutionKeySubject subject, String privateKeyInput) {
public String cbSign(InstitutionKeySubject subject, String privateKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
CentralWalletRegistration c = getOrCreate(subject);
if (c.getDigestMatchResult() == null || !c.getDigestMatchResult().startsWith("通过")) {
scoreService.recordError(subject.getUserId());

@ -58,6 +58,10 @@ public class SmartContractService {
@Transactional
public SmartContractPageResult computeContractDigest(InstitutionKeySubject subject, ContractDigestRequest request) {
if (!"SM3".equalsIgnoreCase(request.getAlgorithm() != null ? request.getAlgorithm().trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
SmartContractGeneration c = getOrCreate(subject);
if (c.getContractDigest() != null) {
return new SmartContractPageResult(c);
@ -121,6 +125,10 @@ public class SmartContractService {
@Transactional
public SmartContractPageResult computeActivateDigest(InstitutionKeySubject subject, ActivateDigestRequest request) {
if (!"SM3".equalsIgnoreCase(request.getAlgorithm() != null ? request.getAlgorithm().trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
SmartContractGeneration c = getOrCreate(subject);
if (c.getActivateDigest() != null) {
return new SmartContractPageResult(c);
@ -141,7 +149,11 @@ public class SmartContractService {
}
@Transactional
public SmartContractPageResult signActivate(InstitutionKeySubject subject, String privateKeyInput) {
public SmartContractPageResult signActivate(InstitutionKeySubject subject, String privateKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
SmartContractGeneration c = getOrCreate(subject);
if (c.getActivateSignature() != null) {
return new SmartContractPageResult(c);

@ -81,7 +81,11 @@ public class WalletIdentifierService {
}
@Transactional
public WalletDigestResult computeDigest(InstitutionKeySubject subject) {
public WalletDigestResult computeDigest(InstitutionKeySubject subject, String algorithm) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
WalletIdentifierGeneration generation = getOrCreate(subject);
if (generation.getDigestValue() != null) {
return new WalletDigestResult(generation.getHashAlgorithm(), generation.getDigestValue());

@ -100,7 +100,11 @@ public class WalletRegistrationService {
}
@Transactional
public WalletRegistrationDigestResult computeDigest(InstitutionKeySubject subject) {
public WalletRegistrationDigestResult computeDigest(InstitutionKeySubject subject, String algorithm) {
if (!"SM3".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
WalletRegistrationRequest request = getOrCreate(subject);
if (request.getDigestValue() != null) {
return new WalletRegistrationDigestResult(request.getDigestValue());
@ -116,7 +120,11 @@ public class WalletRegistrationService {
}
@Transactional
public WalletRegistrationSignatureResult sign(InstitutionKeySubject subject, String privateKeyInput) {
public WalletRegistrationSignatureResult sign(InstitutionKeySubject subject, String privateKeyInput, String algorithm) {
if (!"SM2".equalsIgnoreCase(algorithm != null ? algorithm.trim() : "")) {
scoreService.recordError(subject.getUserId());
throw new BusinessException(ErrorCode.VALIDATION_ERROR, "算法选择有误,错误数+1");
}
WalletRegistrationRequest request = getOrCreate(subject);
if (request.getSignature() != null) {
return new WalletRegistrationSignatureResult(request.getSignature());

@ -15,6 +15,7 @@ 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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -47,14 +48,14 @@ public class CentralBankWalletActivationController {
@Operation(summary = "SM2验证签名", description = "选择商业银行第二公钥进行SM2_Verify(第二公钥, 摘要值, 签名值),公钥错误则错误数+1")
public ApiResponse<CentralWalletActivationPageResult> verifySign(@Valid @RequestBody CentralActivationVerifySignRequest request) {
return ApiResponse.success(activationService.verifySignature(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPublicKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPublicKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/recalculate-digest")
@Operation(summary = "SM3计算新摘要H2", description = "根据报文字段按 ACTIVATE|钱包标识|机构代码|合约ID|时间戳 格式拼接原文,SM3重算得到H2")
public ApiResponse<CentralWalletActivationPageResult> recalculateDigest() {
public ApiResponse<CentralWalletActivationPageResult> recalculateDigest(@RequestParam String algorithm) {
return ApiResponse.success(activationService.recalculateDigest(
InstitutionKeySubject.from(AuthContextHolder.get())), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), algorithm), traceId());
}
@PostMapping("/match-digest")

@ -42,7 +42,7 @@ public class CentralBankWalletFinalConfirmController {
public ApiResponse<CentralWalletActivationPageResult> verifySign(
@Valid @RequestBody CentralActivationVerifySignRequest request) {
return ApiResponse.success(activationService.verifyFinalSignature(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPublicKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPublicKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/final-sign")
@ -51,7 +51,7 @@ public class CentralBankWalletFinalConfirmController {
public ApiResponse<CentralWalletActivationPageResult> finalSign(
@Valid @RequestBody FinalSignRequest request) {
return ApiResponse.success(activationService.finalSign(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/update-status")

@ -49,14 +49,14 @@ public class CentralBankWalletRegistrationController {
@Operation(summary = "SM2验证签名", description = "选择商业银行第二公钥进行SM2_Verify(第二公钥, 摘要值, 签名值),公钥错误则错误数+1")
public ApiResponse<String> verifySign(@Valid @RequestBody CentralWalletVerifySignRequest request) {
return ApiResponse.success(centralWalletRegistrationService.verifySignature(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPublicKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPublicKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/recalculate-digest")
@Operation(summary = "SM3计算新摘要H2", description = "输入请求原文,SM3重算得到新摘要值H2(不进行匹配),前置条件:已完成签名验证")
public ApiResponse<String> recalculateDigest(@Valid @RequestBody CentralWalletDigestRequest request) {
return ApiResponse.success(centralWalletRegistrationService.recalculateDigest(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getRequestMessage()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getRequestMessage(), request.getAlgorithm()), traceId());
}
@PostMapping("/match-digest")
@ -70,7 +70,7 @@ public class CentralBankWalletRegistrationController {
@Operation(summary = "央行根签", description = "选择央行第一私钥进行SM2_Sign(第一私钥, 摘要值),签名值前缀CB_ROOT_SIG_。私钥错误则错误数+1")
public ApiResponse<String> cbSign(@Valid @RequestBody CentralWalletSignRequest request) {
return ApiResponse.success(centralWalletRegistrationService.cbSign(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/register-wallet")

@ -73,7 +73,7 @@ public class CommercialBankSmartContractController {
@Operation(summary = "SM2签名确认报文", description = "使用商业银行第二私钥对确认摘要进行签名(签名值=SM2_Sign(第二私钥,摘要值)),私钥错误则错误数+1")
public ApiResponse<SmartContractPageResult> signActivate(@Valid @RequestBody SmartContractSignRequest request) {
return ApiResponse.success(smartContractService.signActivate(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/output-confirm")

@ -20,6 +20,7 @@ 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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -60,9 +61,9 @@ public class CommercialBankWalletIdentifierController {
@PostMapping("/digest")
@Operation(summary = "SM3哈希运算",
description = "选择SM3哈希算法点击运算,对拼接原文计算SM3摘要值并保存。前置条件:已拼接原文。")
public ApiResponse<WalletDigestResult> computeDigest() {
public ApiResponse<WalletDigestResult> computeDigest(@RequestParam String algorithm) {
return ApiResponse.success(walletIdentifierService.computeDigest(
InstitutionKeySubject.from(AuthContextHolder.get())), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), algorithm), traceId());
}
@PostMapping("/output")

@ -18,6 +18,7 @@ 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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@ -54,16 +55,16 @@ public class CommercialBankWalletRegistrationController {
@PostMapping("/digest")
@Operation(summary = "生成SM3摘要", description = "对拼接原文进行SM3哈希得到摘要值")
public ApiResponse<WalletRegistrationDigestResult> computeDigest() {
public ApiResponse<WalletRegistrationDigestResult> computeDigest(@RequestParam String algorithm) {
return ApiResponse.success(walletRegistrationService.computeDigest(
InstitutionKeySubject.from(AuthContextHolder.get())), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), algorithm), traceId());
}
@PostMapping("/sign")
@Operation(summary = "SM2签名", description = "使用商业银行第二私钥对摘要值进行SM2签名;私钥错误则错误数+1")
public ApiResponse<WalletRegistrationSignatureResult> sign(@Valid @RequestBody WalletRegistrationSignRequest request) {
return ApiResponse.success(walletRegistrationService.sign(
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey()), traceId());
InstitutionKeySubject.from(AuthContextHolder.get()), request.getPrivateKey(), request.getAlgorithm()), traceId());
}
@PostMapping("/output")

@ -1,11 +1,17 @@
package com.yau.digitalrmb.walletopening.interfaces.rest.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class ActivateDigestRequest {
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
@NotBlank(message = "请输入确认原文")
private String plaintext;
}

@ -1,5 +1,6 @@
package com.yau.digitalrmb.walletopening.interfaces.rest.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@ -7,5 +8,10 @@ import javax.validation.constraints.NotBlank;
@Data
public class CentralActivationVerifySignRequest {
@NotBlank(message = "请选择商业银行第二公钥")
@Schema(description = "选择的公钥(商业银行第二公钥)")
private String publicKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
}

@ -13,4 +13,8 @@ public class CentralWalletDigestRequest {
@NotBlank(message = "请求原文不能为空")
@Schema(description = "输入请求原文(拼接的请求信息)")
private String requestMessage;
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
}

@ -13,4 +13,8 @@ public class CentralWalletSignRequest {
@NotBlank(message = "签名密钥不能为空")
@Schema(description = "选择密钥(央行第一私钥)")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
}

@ -13,4 +13,8 @@ public class CentralWalletVerifySignRequest {
@NotBlank(message = "备案密钥不能为空")
@Schema(description = "选择备案的密钥(商业银行第二公钥)")
private String publicKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
}

@ -1,11 +1,17 @@
package com.yau.digitalrmb.walletopening.interfaces.rest.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@Data
public class ContractDigestRequest {
@NotBlank(message = "哈希算法不能为空")
@Schema(description = "选择的哈希算法(如:SM3)", example = "SM3", required = true)
private String algorithm;
@NotBlank(message = "请输入钱包标识ID")
private String walletId;
@NotBlank(message = "请选择钱包类型")

@ -1,5 +1,6 @@
package com.yau.digitalrmb.walletopening.interfaces.rest.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@ -8,4 +9,8 @@ import javax.validation.constraints.NotBlank;
public class FinalSignRequest {
@NotBlank(message = "请输入央行第一私钥")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
}

@ -1,5 +1,6 @@
package com.yau.digitalrmb.walletopening.interfaces.rest.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotBlank;
@ -8,4 +9,8 @@ import javax.validation.constraints.NotBlank;
public class SmartContractSignRequest {
@NotBlank(message = "请选择签名密钥(商业银行第二私钥)")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
}

@ -13,4 +13,8 @@ public class WalletRegistrationSignRequest {
@NotBlank(message = "签名私钥不能为空")
@Schema(description = "签名私钥(必须使用商业银行第二私钥)")
private String privateKey;
@NotBlank(message = "签名算法不能为空")
@Schema(description = "选择的签名算法(如:SM2)", example = "SM2", required = true)
private String algorithm;
}

@ -19,7 +19,7 @@ logging:
path: ./logs
server:
port: 8789
port: 8787
servlet:
encoding:
charset: UTF-8

Loading…
Cancel
Save