From ca0646d94605a025f9bbd44500f2072ed9539256 Mon Sep 17 00:00:00 2001 From: CAFB385655BEB1060E85B6C080B432F8EB2A2AF78459BD6532124977B933154A <133057011+iadgovuser59@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:13:18 -0400 Subject: [PATCH] [#787] Saving attestation certificate to file (#788) * Saving attestation certificate to file * Updates to provisioner certificate generation --- .../hirs/src/provisioner/Provisioner.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs b/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs index 0a8f3e40..adb65155 100644 --- a/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs +++ b/HIRS_Provisioner.NET/hirs/src/provisioner/Provisioner.cs @@ -14,6 +14,9 @@ namespace hirs { private Settings settings = null; private IHirsDeviceInfoCollector deviceInfoCollector = null; private IHirsAcaClient acaClient = null; + + private const string DefaultCertFileName = "attestationkey.pem"; + public Provisioner() { } @@ -279,6 +282,20 @@ namespace hirs { } if (cr.HasCertificate) { certificate = cr.Certificate.ToByteArray(); // contains certificate + String certificateDirPath = settings.efi_prefix; + if (certificateDirPath != null) { + String certificateFilePath = certificateFilePath = certificateDirPath + DefaultCertFileName; + try { + if (!Directory.Exists(certificateDirPath)) { + Directory.CreateDirectory(certificateDirPath); + } + File.WriteAllBytes(certificateFilePath, certificate); + Log.Debug("Certificate written to local file system: ", certificateFilePath); + } + catch (Exception) { + Log.Debug("Failed to write certificate to local file system."); + } + } Log.Debug("Printing attestation key certificate: " + BitConverter.ToString(certificate)); } } else {