| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- package com.ymwk.supervisionserver.pki.controller;
- import com.ymwk.supervisionserver.component.PageResult;
- import com.ymwk.supervisionserver.component.ResponseDTO;
- import com.ymwk.supervisionserver.pki.entity.CertificateEntity;
- import com.ymwk.supervisionserver.pki.model.*;
- import com.ymwk.supervisionserver.pki.service.CertificateService;
- import jakarta.servlet.http.HttpServletResponse;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.*;
- import org.springframework.web.multipart.MultipartFile;
- import java.nio.charset.StandardCharsets;
- import java.util.Map;
- @RestController
- @RequestMapping("/api/v1/certificate")
- public class CertificateController {
- @Autowired
- private CertificateService certificateService;
- //证书列表
- @PostMapping("/list")
- public ResponseDTO<PageResult<CertificateEntity>> getCertificateList(@RequestBody certListRequest certListRequest) {
- return certificateService.getCertificateList(certListRequest);
- }
- //删除证书记录(不删除MinIO文件)
- @PostMapping("/delete")
- public ResponseDTO<String> deleteCertificate(@RequestParam Long id) {
- return certificateService.deleteCertificate(id);
- }
- //证书延期
- @PostMapping("/renew")
- public ResponseDTO<CertificateEntity> renewCertificate(@RequestBody RenewRequest request) throws Exception {
- return certificateService.renewCertificate(request);
- }
- //证书冻结
- @PostMapping("/freeze")
- public ResponseDTO<CertificateEntity> freezeCertificate(@RequestBody FreezeCertificateRequest request) {
- return certificateService.freezeCertificate(request);
- }
- //证书解冻
- @PostMapping("/unfreeze")
- public ResponseDTO<CertificateEntity> unfreezeCertificate(@RequestBody FreezeCertificateRequest request) throws Exception {
- return certificateService.unfreezeCertificate(request);
- }
- //证书吊销
- @PostMapping("/revoke")
- public ResponseDTO<CertificateEntity> revokeCertificate(@RequestBody RevokeCertificateRequest request) throws Exception {
- return certificateService.revokeCertificate(request);
- }
- // Deprecated: use OCSP for certificate status checks.
- @Deprecated
- @PostMapping("/crl")
- public ResponseEntity<String> downloadCrl(@RequestBody DownloadRequest request, HttpServletResponse response) {
- return certificateService.downloadCrl(request.getId(), response);
- }
- @PostMapping(value = "/ocsp", consumes = "application/ocsp-request", produces = "application/ocsp-response")
- public ResponseEntity<byte[]> ocsp(@RequestBody byte[] requestBytes) throws Exception {
- return certificateService.respondToOcspRequest(requestBytes);
- }
- // 上传根证书(接收合并 PEM:cert [+ chain] + private key)
- @PostMapping("/uploadRoot")
- public ResponseDTO<String> uploadRootCertificate(@RequestParam("file") MultipartFile file,
- @RequestParam(value = "certName", required = false) String certName) throws Exception {
- String content = new String(file.getBytes(), StandardCharsets.UTF_8);
- return certificateService.uploadRootCertificate(content, certName);
- }
- //生成根证书
- @PostMapping("/issueRootCertificate")
- public ResponseDTO<CertificateEntity> issueRootCertificate(@RequestBody IssueRequest issueRequest) throws Exception {
- return certificateService.issueRootCertificate(issueRequest);
- }
- // 生成普通证书(由已有 Root CA 签发)
- @PostMapping("/issuePersonalCertificate")
- public ResponseDTO<CertificateEntity> issuePersonalCertificate(@RequestBody IssueRequest issueRequest) throws Exception {
- return certificateService.issuePersonalCertificate(issueRequest);
- }
- /**
- * 下载PEM格式(三份分开)
- */
- @PostMapping("/download/pem-separate")
- public ResponseEntity<Map<String, String>> downloadPemSeparate(@RequestBody DownloadRequest downloadRequest) {
- return certificateService.downloadPemSeparate(downloadRequest.getId());
- }
- /**
- * 下载合并的PEM(cert + private-key)
- * GET /api/v1/ca/certificate/{serialNumber}/download/pem-combined
- */
- @PostMapping("/download/pem-combined")
- public ResponseEntity<byte[]> downloadPemCombined(@RequestBody DownloadRequest downloadRequest, HttpServletResponse response) {
- return certificateService.downloadPemCombined(downloadRequest.getId(), response);
- }
- /**
- * 下载PKCS#12格式(需要提供密码)
- * POST /api/v1/ca/certificate/{serialNumber}/download/pkcs12
- */
- @PostMapping("/download/pkcs12")
- public ResponseEntity<byte[]> downloadPkcs12(@RequestBody Pkcs12DownloadRequest request, HttpServletResponse response) {
- return certificateService.downloadPkcs12(request, response);
- }
- /**
- * 下载证书链
- * GET /api/v1/ca/certificate/{serialNumber}/download/chain
- */
- @PostMapping("/download/chain")
- public ResponseEntity<String> downloadChain(@RequestBody String id, HttpServletResponse response) {
- return certificateService.downloadChain(id, response);
- }
- }
|