fix: cert fix

This commit is contained in:
2025-06-05 19:24:14 +08:00
parent adaf954ae7
commit 51305b71c3
3 changed files with 42 additions and 9 deletions

View File

@@ -1,28 +1,33 @@
import { generate } from 'selfsigned';
type Attributes = {
export type Attributes = {
name: string;
value: string;
};
type AltNames = {
export type AltNames = {
type: number;
value?: string;
ip?: string;
};
export const createCert = (attrs: Attributes[] = [], altNames: AltNames[] = []) => {
let attributes = [
{ name: 'commonName', value: '*' }, // 通配符域名
{ name: 'countryName', value: 'CN' }, // 国家代码
{ name: 'stateOrProvinceName', value: 'ZheJiang' }, // 州名
{ name: 'localityName', value: 'Hangzhou' }, // 城市名
{ name: 'organizationName', value: 'Envision' }, // 组织名
{ name: 'organizationalUnitName', value: 'IT' }, // 组织单位
{ name: 'localityName', value: 'HangZhou' }, // 城市名
{ name: 'organizationName', value: 'Kevisual' }, // 组织名
{ name: 'organizationalUnitName', value: 'ev' }, // 组织单位
...attrs,
];
// attribute 根据name去重复, 后面的覆盖前面的
attributes = attributes.filter((item, index, self) => {
return self.findIndex((t) => t.name === item.name) === index;
});
attributes = Object.values(
attributes.reduce(
(acc, attr) => ({
...acc,
[attr.name]: attr,
}),
{} as Record<string, Attributes>,
),
);
const options = {
days: 365, // 证书有效期(天)
@@ -32,6 +37,14 @@ export const createCert = (attrs: Attributes[] = [], altNames: AltNames[] = [])
altNames: [
{ type: 2, value: '*' }, // DNS 名称
{ type: 2, value: 'localhost' }, // DNS
{
type: 2,
value: '[::1]',
},
{
type: 7,
ip: 'fe80::1',
},
{ type: 7, ip: '127.0.0.1' }, // IP 地址
...altNames,
],