mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
[autofix.ci] apply automated fixes
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
export const extractExpirationDate = (certData: string): Date | null => {
|
export const extractExpirationDate = (certData: string): Date | null => {
|
||||||
try {
|
try {
|
||||||
// Decode PEM base64 to DER binary
|
// Decode PEM base64 to DER binary
|
||||||
const b64 = certData.replace(/-----[^-]+-----/g, '').replace(/\s+/g, '');
|
const b64 = certData.replace(/-----[^-]+-----/g, "").replace(/\s+/g, "");
|
||||||
const binStr = atob(b64);
|
const binStr = atob(b64);
|
||||||
const der = new Uint8Array(binStr.length);
|
const der = new Uint8Array(binStr.length);
|
||||||
for (let i = 0; i < binStr.length; i++) {
|
for (let i = 0; i < binStr.length; i++) {
|
||||||
@@ -32,7 +32,7 @@ export const extractExpirationDate = (certData: string): Date | null => {
|
|||||||
({ offset } = readLength(offset));
|
({ offset } = readLength(offset));
|
||||||
|
|
||||||
// Check for optional version field (context-specific tag [0])
|
// Check for optional version field (context-specific tag [0])
|
||||||
if (der[offset] === 0xA0) {
|
if (der[offset] === 0xa0) {
|
||||||
offset++;
|
offset++;
|
||||||
const versionLen = readLength(offset);
|
const versionLen = readLength(offset);
|
||||||
offset = versionLen.offset + versionLen.length;
|
offset = versionLen.offset + versionLen.length;
|
||||||
@@ -40,7 +40,8 @@ export const extractExpirationDate = (certData: string): Date | null => {
|
|||||||
|
|
||||||
// Skip serialNumber, signature, issuer
|
// Skip serialNumber, signature, issuer
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
if (der[offset] !== 0x30 && der[offset] !== 0x02) throw new Error("Unexpected structure");
|
if (der[offset] !== 0x30 && der[offset] !== 0x02)
|
||||||
|
throw new Error("Unexpected structure");
|
||||||
offset++;
|
offset++;
|
||||||
const fieldLen = readLength(offset);
|
const fieldLen = readLength(offset);
|
||||||
offset = fieldLen.offset + fieldLen.length;
|
offset = fieldLen.offset + fieldLen.length;
|
||||||
@@ -59,7 +60,9 @@ export const extractExpirationDate = (certData: string): Date | null => {
|
|||||||
// notAfter
|
// notAfter
|
||||||
offset++;
|
offset++;
|
||||||
const notAfterLen = readLength(offset);
|
const notAfterLen = readLength(offset);
|
||||||
const notAfterStr = new TextDecoder().decode(der.slice(notAfterLen.offset, notAfterLen.offset + notAfterLen.length));
|
const notAfterStr = new TextDecoder().decode(
|
||||||
|
der.slice(notAfterLen.offset, notAfterLen.offset + notAfterLen.length),
|
||||||
|
);
|
||||||
|
|
||||||
// Parse GeneralizedTime (15 chars) or UTCTime (13 chars)
|
// Parse GeneralizedTime (15 chars) or UTCTime (13 chars)
|
||||||
function parseTime(str: string): Date {
|
function parseTime(str: string): Date {
|
||||||
@@ -67,10 +70,14 @@ export const extractExpirationDate = (certData: string): Date | null => {
|
|||||||
// UTCTime YYMMDDhhmmssZ
|
// UTCTime YYMMDDhhmmssZ
|
||||||
const year = parseInt(str.slice(0, 2), 10);
|
const year = parseInt(str.slice(0, 2), 10);
|
||||||
const fullYear = year < 50 ? 2000 + year : 1900 + year;
|
const fullYear = year < 50 ? 2000 + year : 1900 + year;
|
||||||
return new Date(`${fullYear}-${str.slice(2, 4)}-${str.slice(4, 6)}T${str.slice(6, 8)}:${str.slice(8, 10)}:${str.slice(10, 12)}Z`);
|
return new Date(
|
||||||
|
`${fullYear}-${str.slice(2, 4)}-${str.slice(4, 6)}T${str.slice(6, 8)}:${str.slice(8, 10)}:${str.slice(10, 12)}Z`,
|
||||||
|
);
|
||||||
} else if (str.length === 15) {
|
} else if (str.length === 15) {
|
||||||
// GeneralizedTime YYYYMMDDhhmmssZ
|
// GeneralizedTime YYYYMMDDhhmmssZ
|
||||||
return new Date(`${str.slice(0, 4)}-${str.slice(4, 6)}-${str.slice(6, 8)}T${str.slice(8, 10)}:${str.slice(10, 12)}:${str.slice(12, 14)}Z`);
|
return new Date(
|
||||||
|
`${str.slice(0, 4)}-${str.slice(4, 6)}-${str.slice(6, 8)}T${str.slice(8, 10)}:${str.slice(10, 12)}:${str.slice(12, 14)}Z`,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Invalid ASN.1 time format");
|
throw new Error("Invalid ASN.1 time format");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user