From 263e55364cef2e85d0831d823791ac79a8941edc Mon Sep 17 00:00:00 2001 From: haritz Date: Wed, 22 Jan 2025 13:53:59 +0100 Subject: [PATCH] fix csr cn generation using utf8 encoding Signed-off-by: haritz --- src/utils/crypto/csr.ts | 2 +- src/views/CAs/IssuedCertificates.tsx | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/utils/crypto/csr.ts b/src/utils/crypto/csr.ts index 2abf80b..fe295d5 100644 --- a/src/utils/crypto/csr.ts +++ b/src/utils/crypto/csr.ts @@ -53,7 +53,7 @@ export const createCSR = async (keyPair: CryptoKeyPair, hashAlg: "SHA-1" | "SHA- if (subjectProps[key]) { pkcs10.subject.typesAndValues.push(new pkijs.AttributeTypeAndValue({ type: key, - value: new asn1js.PrintableString({ value: subjectProps[key] }) + value: new asn1js.Utf8String({ value: subjectProps[key] }) })); } } diff --git a/src/views/CAs/IssuedCertificates.tsx b/src/views/CAs/IssuedCertificates.tsx index 21a5fc4..161e1de 100644 --- a/src/views/CAs/IssuedCertificates.tsx +++ b/src/views/CAs/IssuedCertificates.tsx @@ -22,6 +22,7 @@ import PublishIcon from "@mui/icons-material/Publish"; import React, { useEffect, useState } from "react"; import RefreshIcon from "@mui/icons-material/Refresh"; import apicalls from "ducks/apicalls"; +import { errorToString } from "ducks/services/api-client"; const queryableFields = [ { key: "subject.common_name", title: "Common Name", operator: "contains" }, @@ -64,8 +65,12 @@ export const IssuedCertificates: React.FC = ({ caData }) => { component: ( { setImportSignStatus({ loading: true, errMessage: "", response: undefined }); - const singResp = await apicalls.cas.signCertificateRequest(caData.id, window.window.btoa(csr)); - setImportSignStatus({ loading: false, errMessage: "", response: singResp }); + try { + const singResp = await apicalls.cas.signCertificateRequest(caData.id, window.window.btoa(csr)); + setImportSignStatus({ loading: false, errMessage: "", response: singResp }); + } catch (error: any) { + setImportSignStatus({ loading: false, errMessage: errorToString(error), response: undefined }); + } }} /> ) }, { @@ -289,7 +294,17 @@ export const IssuedCertificates: React.FC = ({ caData }) => { ? ( importSignStatus.errMessage !== "" ? ( - <>{importSignStatus.errMessage} + + + { resetAddCertificate(); setDisplayIssueCert(false); }}> + Go Back + + }> + {importSignStatus.errMessage} + + + ) : ( importSignStatus.response !== undefined