From 0f3fb330bf47d6de0592a66a6e738f55dad88067 Mon Sep 17 00:00:00 2001
From: Adil El Farissi <144741970+AdilElFarissi@users.noreply.github.com>
Date: Tue, 17 Sep 2024 18:23:22 +0000
Subject: [PATCH] Update Util.cs
---
OpenSim/Framework/Util.cs | 29 +++++++++++++++++++----------
1 file changed, 19 insertions(+), 10 deletions(-)
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 7ca7d93416..6ef4785e87 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1570,19 +1570,28 @@ namespace OpenSim.Framework
/// The path of fullchain.pem. If your CA don't provide
/// the fullchain file, you can set the cert.pem instead.
/// The path of the private key (privkey.pem).
- /// The output certificates password.
+ /// The output certificates password.
private static void ConvertPemToPKCS12Certificate(string certFileName, string certPath, string keyPath, string outputPassword)
{
if(string.IsNullOrEmpty(certPath) || string.IsNullOrEmpty(keyPath)){
- m_log.ErrorFormat("[UTIL]: Missing or invalid fullchain.pem / privkey.pem path!.");
+ m_log.Error($"[UTIL PemToPKCS12]: Missing fullchain.pem or privkey.pem path!.");
return;
}
- // Create the SSL folder and sub folders if not exists.
- if (!Directory.Exists("SSL\\ssl\\"))
- Directory.CreateDirectory("SSL\\ssl\\");
// Convert .pem (like Let's Encrypt files) to X509Certificate2 certificate.
- X509Certificate2 certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath);
+ try
+ {
+ X509Certificate2 certificate = X509Certificate2.CreateFromPemFile(certPath, keyPath);
+ }
+ catch(CryptographicException e)
+ {
+ m_log.Error($"[UTIL PemToPKCS12]: {e.Message}" );
+ return;
+ }
+
+ // Create the SSL folder and ssl sub folder if not exists.
+ if (!Directory.Exists("SSL\\ssl\\"))
+ Directory.CreateDirectory("SSL\\ssl\\");
// Export and store the .pfx and .p12 certificates in SSL\ssl\.
byte[] pfxCertBytes = string.IsNullOrEmpty(outputPassword)
@@ -1590,10 +1599,10 @@ namespace OpenSim.Framework
: certificate.Export(X509ContentType.Pfx, outputPassword);
File.WriteAllBytes($"SSL\\ssl\\{certFileName}.pfx", pfxCertBytes);
- byte[] p12CertBytes = string.IsNullOrEmpty(outputPassword)
- ? certificate.Export(X509ContentType.Pkcs12)
- : certificate.Export(X509ContentType.Pkcs12, outputPassword);
- File.WriteAllBytes($"SSL\\ssl\\{certFileName}.p12", p12CertBytes);
+ byte[] p12CertBytes = string.IsNullOrEmpty(outputPassword)
+ ? certificate.Export(X509ContentType.Pkcs12)
+ : certificate.Export(X509ContentType.Pkcs12, outputPassword);
+ File.WriteAllBytes($"SSL\\ssl\\{certFileName}.p12", p12CertBytes);
}