Skip to content

Commit

Permalink
Fix certificate name (label)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed Jul 23, 2024
1 parent 04d3582 commit a455cd4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/components/certificates-list/CertificatesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import { CertificateName } from "../certificate-name";
import { CertificateSerialNumber } from "../certificate-serial-number";
import { downloadCertificate } from "../../utils/download-certificate";
import { CopyIconButton } from "../copy-icon-button";
import { certificateRawToPem } from "../../utils/certificate";
import {
certificateRawToPem,
getCertificateName,
} from "../../utils/certificate";
import { SortButton } from "../sort-button";

import { CertificateProps } from "../../types";
Expand Down Expand Up @@ -184,9 +187,11 @@ export const CertificatesList: React.FunctionComponent<
<TableCell>
<CertificateTypeLabel type={type} />
</TableCell>
{/* // TODO: not sure about label as name */}
<TableCell>
<CertificateName highlight={highlightedText} name={label} />
<CertificateName
highlight={highlightedText}
name={getCertificateName(certificate)}
/>
</TableCell>
<TableCell>
<CertificateSerialNumber value={serialNumber} />
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface CertificateSubjectProps {
L?: string;
ST?: string;
C?: string;
G?: string;
SN?: string;
}

export type CertificateAlgorithmProps = {
Expand Down
28 changes: 27 additions & 1 deletion src/utils/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Pkcs10CertificateRequest, X509Certificate } from "@peculiar/x509";

import { CertificateSubjectProps, CertificateType } from "../types";
import {
CertificateProps,
CertificateSubjectProps,
CertificateType,
} from "../types";

export function certificateRawToPem(raw: ArrayBuffer, type: CertificateType) {
let pem;
Expand Down Expand Up @@ -33,3 +37,25 @@ export function certificateSubjectToString(

return parts.join(", ");
}

export function getCertificateName(certificate: CertificateProps) {
const { G, CN, SN, E } =
certificate.subject as unknown as CertificateSubjectProps;

// Return Common Name if present.
if (CN) {
return CN;
}

// Return Given Name + Surname if both present.
if (G && SN) {
return `${G} ${SN}`;
}

// Return Email if none of the above present
if (E) {
return E;
}

return certificate.subjectName;
}

0 comments on commit a455cd4

Please sign in to comment.