[smuxi/experiments/certfp: 55/55] WIP
- From: Mirco M. M. Bauer <mmmbauer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [smuxi/experiments/certfp: 55/55] WIP
- Date: Sun, 12 Jan 2014 07:30:37 +0000 (UTC)
commit 50b19d4bc3515eee44c50c838b6f345c3018d31a
Author: Mirco Bauer <meebey meebey net>
Date: Sun Jan 12 08:26:40 2014 +0100
WIP
src/Engine-IRC/Protocols/Irc/IrcProtocolManager.cs | 21 ++++++++++++++++++++
src/Engine/Config/Config.cs | 1 +
src/Engine/Config/ServerModel.cs | 14 +++++++++++++
src/Frontend-GNOME/Views/MenuWidget.cs | 1 +
4 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/src/Engine-IRC/Protocols/Irc/IrcProtocolManager.cs
b/src/Engine-IRC/Protocols/Irc/IrcProtocolManager.cs
index e8812f9..ddd9d1e 100644
--- a/src/Engine-IRC/Protocols/Irc/IrcProtocolManager.cs
+++ b/src/Engine-IRC/Protocols/Irc/IrcProtocolManager.cs
@@ -21,6 +21,7 @@
*/
using System;
+using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Cryptography.X509Certificates;
@@ -2548,6 +2549,26 @@ namespace Smuxi.Engine
if (server != null) {
_IrcClient.UseSsl = server.UseEncryption;
_IrcClient.ValidateServerCertificate = server.ValidateServerCertificate;
+ if (String.IsNullOrEmpty(server.ClientCertificateFilename)) {
+ _IrcClient.SslClientCertificate = null;
+ } else {
+ var certFile = server.ClientCertificateFilename;
+ if (!Path.IsPathRooted(certFile)) {
+ var configPath = Environment.GetFolderPath(
+ Environment.SpecialFolder.ApplicationData
+ );
+ configPath = Path.Combine(configPath, "smuxi");
+ var certPath = Path.Combine(configPath, "certs");
+ certFile = Path.Combine(certPath, certFile);
+ }
+ var certType = X509Certificate2.GetCertContentType(certFile);
+ if (certType != X509ContentType.Unknown) {
+ var cert = new X509Certificate2();
+ cert.Import(certFile, "", X509KeyStorageFlags.PersistKeySet);
+ _IrcClient.SslClientCertificate = cert;
+ // X509Certificate2.CreateFromCertFile(certFile);
+ }
+ }
}
}
diff --git a/src/Engine/Config/Config.cs b/src/Engine/Config/Config.cs
index b02f6dd..5fa6ca6 100644
--- a/src/Engine/Config/Config.cs
+++ b/src/Engine/Config/Config.cs
@@ -575,6 +575,7 @@ namespace Smuxi.Engine
LoadEntry(sprefix+"Password", String.Empty);
LoadEntry(sprefix+"UseEncryption", false);
LoadEntry(sprefix+"ValidateServerCertificate", false);
+ LoadEntry(sprefix+"ClientCertificateFilename", String.Empty);
LoadEntry(sprefix+"OnStartupConnect", false);
string[] commands = GetList(sprefix + "OnConnectCommands");
if (commands == null) {
diff --git a/src/Engine/Config/ServerModel.cs b/src/Engine/Config/ServerModel.cs
index d8994b5..5656378 100644
--- a/src/Engine/Config/ServerModel.cs
+++ b/src/Engine/Config/ServerModel.cs
@@ -32,6 +32,7 @@ namespace Smuxi.Engine
{
public bool UseEncryption { get; set; }
public bool ValidateServerCertificate { get; set; }
+ public string ClientCertificateFilename { get; set; }
public string Protocol { get; set; }
public string Hostname { get; set; }
public int Port { get; set; }
@@ -89,6 +90,9 @@ namespace Smuxi.Engine
ValidateServerCertificate = (bool)e.Value;
foundValidation = true;
break;
+ case "ClientCertificateFilename":
+ ClientCertificateFilename = (string) e.Value;
+ break;
}
}
if (foundServerID == false) {
@@ -115,6 +119,12 @@ namespace Smuxi.Engine
if (ServerID != null) {
info.AddValue("_ServerID", ServerID);
}
+ // HACK: skip ClientCertificateFilename if it has no value as it
+ // breaks older ServerModel implementations that relied on automatic
+ // serialization which was the case in < 0.8.11
+ if (String.IsNullOrEmpty(ClientCertificateFilename)) {
+ info.AddValue("ClientCertificateFilename", ClientCertificateFilename);
+ }
info.AddValue("_Protocol", Protocol);
info.AddValue("_Hostname", Hostname);
info.AddValue("_Port", Port);
@@ -156,6 +166,8 @@ namespace Smuxi.Engine
UseEncryption = (bool) config[ConfigKeyPrefix + "UseEncryption"];
ValidateServerCertificate =
(bool) config[ConfigKeyPrefix + "ValidateServerCertificate"];
+ ClientCertificateFilename = (string) config[ConfigKeyPrefix + "ClientCertificateFilename"];
+ Password = (string) config[ConfigKeyPrefix + "Password"];
if (config[ConfigKeyPrefix + "OnStartupConnect"] != null) {
OnStartupConnect = (bool) config[ConfigKeyPrefix + "OnStartupConnect"];
}
@@ -175,6 +187,8 @@ namespace Smuxi.Engine
config[ConfigKeyPrefix + "UseEncryption"] = UseEncryption;
config[ConfigKeyPrefix + "ValidateServerCertificate"] =
ValidateServerCertificate;
+ config[ConfigKeyPrefix + "ClientCertificateFilename"] =
+ ClientCertificateFilename;
config[ConfigKeyPrefix + "OnStartupConnect"] = OnStartupConnect;
config[ConfigKeyPrefix + "OnConnectCommands"] = OnConnectCommands;
}
diff --git a/src/Frontend-GNOME/Views/MenuWidget.cs b/src/Frontend-GNOME/Views/MenuWidget.cs
index 1e6106d..cf6bb93 100644
--- a/src/Frontend-GNOME/Views/MenuWidget.cs
+++ b/src/Frontend-GNOME/Views/MenuWidget.cs
@@ -225,6 +225,7 @@ namespace Smuxi.Frontend.Gnome
// which we skip by setting this to null, see:
// ServerModel.GetObjectData()
server.ServerID = null;
+ server.ClientCertificateFilename = null;
}
Frontend.Session.Connect(server, Frontend.FrontendManager);
} catch (Exception ex) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]