Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
小吾立 2024-07-04 18:46:24 +08:00
commit b4b132beb5
3 changed files with 18 additions and 7 deletions

View File

@ -1,5 +1,13 @@
# 🚀 版本日志
## 2.11.8.3-beta (2024-07-05)
### 🐞 解决BUG、优化功能
1. 【server】修复 淘汰javax.security.cert.X509Certificate感谢[@Jie](https://github.com/index-jie) [Githup issues 84](https://github.com/dromara/Jpom/issues/86)
------
## 2.11.8.2-beta (2024-07-04)
### 🐞 解决BUG、优化功能

View File

@ -47,7 +47,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.security.cert.X509Certificate;
import java.security.cert.X509Certificate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
@ -239,7 +239,7 @@ public class CertificateInfoController extends BaseServerController {
PublicKey pubkey = certificate.getPublicKey();
certificateInfoService.testKey(pubkey, prikey);
//
X509Certificate cert = X509Certificate.getInstance(certificate.getEncoded());
X509Certificate cert = certificateInfoService.getInstance(certificate.getEncoded());
// 填充
CertificateInfoModel certificateInfoModel = certificateInfoService.filling(cert);
certificateInfoModel.setKeyType(keyStore.getType());

View File

@ -36,8 +36,8 @@ import org.dromara.jpom.service.h2db.BaseGlobalOrWorkspaceService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.security.cert.CertificateEncodingException;
import javax.security.cert.X509Certificate;
import java.io.ByteArrayInputStream;
import java.security.cert.*;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedInputStream;
import java.io.File;
@ -46,7 +46,6 @@ import java.nio.file.StandardCopyOption;
import java.security.Principal;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.util.*;
import java.util.stream.Collectors;
@ -141,8 +140,8 @@ public class CertificateInfoService extends BaseGlobalOrWorkspaceService<Certifi
.collect(Collectors.toList());
Certificate certificate0 = certificates.get(0);
Certificate certificate1 = CollUtil.get(certificates, 1);
X509Certificate x509Certificate0 = X509Certificate.getInstance(certificate0.getEncoded());
X509Certificate x509Certificate1 = certificate1 != null ? X509Certificate.getInstance(certificate1.getEncoded()) : null;
X509Certificate x509Certificate0 = getInstance(certificate0.getEncoded());
X509Certificate x509Certificate1 = certificate1 != null ? getInstance(certificate1.getEncoded()) : null;
Principal issuerDN = x509Certificate0.getIssuerDN();
Principal subjectDN = x509Certificate0.getSubjectDN();
Assert.state(issuerDN != null && subjectDN != null, I18nMessageUtil.get("i18n.certificate_info_error_issuer_or_subject_DN_not_found.805d"));
@ -191,6 +190,10 @@ public class CertificateInfoService extends BaseGlobalOrWorkspaceService<Certifi
}
}
public X509Certificate getInstance(byte[] bytes) throws CertificateException {
return (X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(bytes));
}
public File getFilePath(CertificateInfoModel model) {
File certificatePath = FileUtil.file(jpomApplication.getDataPath(), "certificate");
return FileUtil.file(certificatePath, model.getSerialNumberStr(), model.getKeyType());