From c5913b61e17d8c1c434f3671ad0e7c2c3ebf78e8 Mon Sep 17 00:00:00 2001 From: silambarasu D Date: Tue, 10 Jun 2025 21:40:31 +0530 Subject: [PATCH 1/4] GUB-75792: update m_SafeServerURL method to handle IP addresses and enforce HTTPS for non-IP hosts --- Granicus.MediaManager.UserSDK/MediaManager.cs | 15 +++++++++++---- Granicus.MediaManager.UserSDK/MediaVault.cs | 13 +++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Granicus.MediaManager.UserSDK/MediaManager.cs b/Granicus.MediaManager.UserSDK/MediaManager.cs index 8411a87..bc9fa96 100644 --- a/Granicus.MediaManager.UserSDK/MediaManager.cs +++ b/Granicus.MediaManager.UserSDK/MediaManager.cs @@ -124,9 +124,16 @@ private string m_SafeServerURL(string Server) { if (!Server.StartsWith("https://") && !Server.StartsWith("http://")) { - Server = "https://" + Server; - } else if(Server.StartsWith("http://") && !Server.Contains("mm.lvh.me")) { - Server = Server.Replace("http://","https://"); + System.Net.IPAddress ipAddress; + bool isIp = System.Net.IPAddress.TryParse(Server, out ipAddress); + if (isIp) + { + Server = "http://" + Server; + } + else + { + Server = "https://" + Server; + } } if (!Server.EndsWith("/")) { @@ -1456,7 +1463,7 @@ public void DeleteClip(int ClipID) /// properties of the root level object that is passed in allowing the /// caller to specify the place in the MetaData tree where the object should be added. /// - /// The object to add. + /// The object to /// An array of objects that can be used to get the /// IDs of the newly added objects. [System.Web.Services.Protocols.SoapRpcMethodAttribute("urn:UserSDK#userwebservice#AddClipMetaData", RequestNamespace = "urn:UserSDK", ResponseNamespace = "urn:UserSDK")] diff --git a/Granicus.MediaManager.UserSDK/MediaVault.cs b/Granicus.MediaManager.UserSDK/MediaVault.cs index 362b3ed..574461e 100644 --- a/Granicus.MediaManager.UserSDK/MediaVault.cs +++ b/Granicus.MediaManager.UserSDK/MediaVault.cs @@ -201,9 +201,18 @@ protected override WebRequest GetWebRequest(Uri uri) /// private string m_SafeServerURL(ServerInterfaceData Server) { - if (!Server.Host.StartsWith("http://")) + if (!Server.Host.StartsWith("http://") && !Server.Host.StartsWith("https://")) { - Server.Host = "http://" + Server.Host; + System.Net.IPAddress ipAddress; + bool isIp = System.Net.IPAddress.TryParse(Server.Host, out ipAddress); + if (isIp) + { + Server.Host = "http://" + Server.Host; + } + else + { + Server.Host = "https://" + Server.Host; + } } if (Server.Host.EndsWith("/")) { From e8c2ce57bb7fed415b22818c211dd9b8dbc5bba1 Mon Sep 17 00:00:00 2001 From: silambarasu D Date: Thu, 12 Jun 2025 15:01:15 +0530 Subject: [PATCH 2/4] Add logging functionality to MediaManager and MediaVault classes --- Granicus.MediaManager.UserSDK/MediaManager.cs | 28 +++++++++++++++++-- Granicus.MediaManager.UserSDK/MediaVault.cs | 27 ++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Granicus.MediaManager.UserSDK/MediaManager.cs b/Granicus.MediaManager.UserSDK/MediaManager.cs index bc9fa96..8dc6194 100644 --- a/Granicus.MediaManager.UserSDK/MediaManager.cs +++ b/Granicus.MediaManager.UserSDK/MediaManager.cs @@ -96,6 +96,7 @@ public MediaManager(string Server, string Username, string Password) private const int RETRY_INTERVAL = 2000; private const int MAXIMUM_RETRIES = 3; private const int MESSAGE_COMPLEXITY = 128; + private readonly string logFilePath = "C:\\Program Files\\Bakers_MediaManager.log"; #endregion #region Base Class Overrides @@ -113,6 +114,16 @@ protected override WebRequest GetWebRequest(Uri uri) } #endregion + + private void LogToFile(string message) + { + try + { + System.IO.File.AppendAllText(logFilePath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}\r\n"); + } + catch { /* Ignore logging errors */ } + } + #region Private Utility Methods /// /// Converts server name (i.e. streaming.granicus.com) into complete url useful to base @@ -122,23 +133,36 @@ protected override WebRequest GetWebRequest(Uri uri) /// private string m_SafeServerURL(string Server) { + LogToFile($"m_SafeServerURL called with Server='{Server}'"); if (!Server.StartsWith("https://") && !Server.StartsWith("http://")) { + LogToFile($"m_SafeServerURL reached if conditon='{Server}'"); + string serverHost = Server.Split(':')[0]; // Remove port if present + LogToFile($"m_SafeServerURL serverHost ='{serverHost}'"); System.Net.IPAddress ipAddress; - bool isIp = System.Net.IPAddress.TryParse(Server, out ipAddress); + bool isIp = System.Net.IPAddress.TryParse(serverHost, out ipAddress); + LogToFile($"m_SafeServerURL isIp ='{isIp}'"); if (isIp) { + LogToFile($"m_SafeServerURL reached into isIp if conditon='{isIp}'"); Server = "http://" + Server; + LogToFile($"Detected IP. Using http. Result: '{Server}'"); } else { + LogToFile($"m_SafeServerURL reached into isIp else conditon='{isIp}'"); Server = "https://" + Server; + LogToFile($"Detected DNS. Using https. Result: '{Server}'"); } + LogToFile($"m_SafeServerURL end if conditon Server ='{Server}'"); } if (!Server.EndsWith("/")) { Server = Server + "/"; + LogToFile($"Appended trailing slash. Result: '{Server}'"); } + string finalUrl = Server + m_urlSuffix; + LogToFile($"Final URL: '{finalUrl}'"); return Server + m_urlSuffix; } @@ -1463,7 +1487,7 @@ public void DeleteClip(int ClipID) /// properties of the root level object that is passed in allowing the /// caller to specify the place in the MetaData tree where the object should be added. /// - /// The object to + /// The object to add. /// An array of objects that can be used to get the /// IDs of the newly added objects. [System.Web.Services.Protocols.SoapRpcMethodAttribute("urn:UserSDK#userwebservice#AddClipMetaData", RequestNamespace = "urn:UserSDK", ResponseNamespace = "urn:UserSDK")] diff --git a/Granicus.MediaManager.UserSDK/MediaVault.cs b/Granicus.MediaManager.UserSDK/MediaVault.cs index 574461e..c3892e3 100644 --- a/Granicus.MediaManager.UserSDK/MediaVault.cs +++ b/Granicus.MediaManager.UserSDK/MediaVault.cs @@ -199,25 +199,48 @@ protected override WebRequest GetWebRequest(Uri uri) /// /// Server Name (i.e. streaming.granicus.com) /// + private readonly string logFilePath = "C:\\Program Files\\Bakers_MediaVault.log"; + + private void LogToFile(string message) + { + try + { + System.IO.File.AppendAllText(logFilePath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}\r\n"); + } + catch { /* Ignore logging errors */ } + } + private string m_SafeServerURL(ServerInterfaceData Server) { + LogToFile($"m_SafeServerURL called with Server='{Server}'"); + LogToFile($"m_SafeServerURL Server.Host='{Server.Host}', ControlPort='{Server.ControlPort}'"); if (!Server.Host.StartsWith("http://") && !Server.Host.StartsWith("https://")) { + LogToFile($"m_SafeServerURL reached if condition. Server.Host='{Server.Host}'"); System.Net.IPAddress ipAddress; bool isIp = System.Net.IPAddress.TryParse(Server.Host, out ipAddress); + LogToFile($"m_SafeServerURL isIp='{isIp}' for Host='{Server.Host}'"); if (isIp) { + LogToFile($"m_SafeServerURL reached into isIp if condition. isIp='{isIp}'"); Server.Host = "http://" + Server.Host; + LogToFile($"Detected IP. Using http. Result: '{Server.Host}'"); } else { + LogToFile($"m_SafeServerURL reached into isIp else condition. isIp='{isIp}'"); Server.Host = "https://" + Server.Host; + LogToFile($"Detected DNS. Using https. Result: '{Server.Host}'"); } + LogToFile($"m_SafeServerURL end if condition. Server='{Server}'"); } if (Server.Host.EndsWith("/")) { Server.Host.TrimEnd("/".ToCharArray()); + LogToFile($"Trimmed trailing slash. Result: '{Server.Host}'"); } + string finalUrl = Server.Host + ":" + Server.ControlPort + m_urlSuffix; + LogToFile($"Final URL: '{finalUrl}'"); return Server.Host + ":" + Server.ControlPort + m_urlSuffix; } #endregion @@ -250,11 +273,15 @@ public bool Connected /// A valid ImpersonationToken. public void Connect(ServerInterfaceData Server, string MediaManagerServer, string ImpersonationToken) { + LogToFile($"Connect() called with Server='{Server}'"); + LogToFile($"Connect() called with MediaManagerServer='{MediaManagerServer}'"); + LogToFile($"Connect() called with ImpersonationToken='{ImpersonationToken}'"); base.Url = m_SafeServerURL(Server); SecurityHeaderValue = new SecurityHeader(); SecurityHeaderValue.ServiceHost = MediaManagerServer; SecurityHeaderValue.SecurityToken = ImpersonationToken; this.m_Connected = true; + LogToFile($"Connect() end with Server='{Server}'"); } /// From e8f8bed74261f4ad760f2af5aca813a3c0561dc7 Mon Sep 17 00:00:00 2001 From: silambarasu D Date: Thu, 12 Jun 2025 16:03:10 +0530 Subject: [PATCH 3/4] Remove logging functionality from MediaManager and MediaVault classes --- Granicus.MediaManager.UserSDK/MediaManager.cs | 23 ---------------- Granicus.MediaManager.UserSDK/MediaVault.cs | 26 ------------------- 2 files changed, 49 deletions(-) diff --git a/Granicus.MediaManager.UserSDK/MediaManager.cs b/Granicus.MediaManager.UserSDK/MediaManager.cs index 8dc6194..d95046b 100644 --- a/Granicus.MediaManager.UserSDK/MediaManager.cs +++ b/Granicus.MediaManager.UserSDK/MediaManager.cs @@ -96,7 +96,6 @@ public MediaManager(string Server, string Username, string Password) private const int RETRY_INTERVAL = 2000; private const int MAXIMUM_RETRIES = 3; private const int MESSAGE_COMPLEXITY = 128; - private readonly string logFilePath = "C:\\Program Files\\Bakers_MediaManager.log"; #endregion #region Base Class Overrides @@ -114,16 +113,6 @@ protected override WebRequest GetWebRequest(Uri uri) } #endregion - - private void LogToFile(string message) - { - try - { - System.IO.File.AppendAllText(logFilePath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}\r\n"); - } - catch { /* Ignore logging errors */ } - } - #region Private Utility Methods /// /// Converts server name (i.e. streaming.granicus.com) into complete url useful to base @@ -133,36 +122,24 @@ private void LogToFile(string message) /// private string m_SafeServerURL(string Server) { - LogToFile($"m_SafeServerURL called with Server='{Server}'"); if (!Server.StartsWith("https://") && !Server.StartsWith("http://")) { - LogToFile($"m_SafeServerURL reached if conditon='{Server}'"); string serverHost = Server.Split(':')[0]; // Remove port if present - LogToFile($"m_SafeServerURL serverHost ='{serverHost}'"); System.Net.IPAddress ipAddress; bool isIp = System.Net.IPAddress.TryParse(serverHost, out ipAddress); - LogToFile($"m_SafeServerURL isIp ='{isIp}'"); if (isIp) { - LogToFile($"m_SafeServerURL reached into isIp if conditon='{isIp}'"); Server = "http://" + Server; - LogToFile($"Detected IP. Using http. Result: '{Server}'"); } else { - LogToFile($"m_SafeServerURL reached into isIp else conditon='{isIp}'"); Server = "https://" + Server; - LogToFile($"Detected DNS. Using https. Result: '{Server}'"); } - LogToFile($"m_SafeServerURL end if conditon Server ='{Server}'"); } if (!Server.EndsWith("/")) { Server = Server + "/"; - LogToFile($"Appended trailing slash. Result: '{Server}'"); } - string finalUrl = Server + m_urlSuffix; - LogToFile($"Final URL: '{finalUrl}'"); return Server + m_urlSuffix; } diff --git a/Granicus.MediaManager.UserSDK/MediaVault.cs b/Granicus.MediaManager.UserSDK/MediaVault.cs index c3892e3..db6dfeb 100644 --- a/Granicus.MediaManager.UserSDK/MediaVault.cs +++ b/Granicus.MediaManager.UserSDK/MediaVault.cs @@ -199,48 +199,26 @@ protected override WebRequest GetWebRequest(Uri uri) /// /// Server Name (i.e. streaming.granicus.com) /// - private readonly string logFilePath = "C:\\Program Files\\Bakers_MediaVault.log"; - - private void LogToFile(string message) - { - try - { - System.IO.File.AppendAllText(logFilePath, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}\r\n"); - } - catch { /* Ignore logging errors */ } - } private string m_SafeServerURL(ServerInterfaceData Server) { - LogToFile($"m_SafeServerURL called with Server='{Server}'"); - LogToFile($"m_SafeServerURL Server.Host='{Server.Host}', ControlPort='{Server.ControlPort}'"); if (!Server.Host.StartsWith("http://") && !Server.Host.StartsWith("https://")) { - LogToFile($"m_SafeServerURL reached if condition. Server.Host='{Server.Host}'"); System.Net.IPAddress ipAddress; bool isIp = System.Net.IPAddress.TryParse(Server.Host, out ipAddress); - LogToFile($"m_SafeServerURL isIp='{isIp}' for Host='{Server.Host}'"); if (isIp) { - LogToFile($"m_SafeServerURL reached into isIp if condition. isIp='{isIp}'"); Server.Host = "http://" + Server.Host; - LogToFile($"Detected IP. Using http. Result: '{Server.Host}'"); } else { - LogToFile($"m_SafeServerURL reached into isIp else condition. isIp='{isIp}'"); Server.Host = "https://" + Server.Host; - LogToFile($"Detected DNS. Using https. Result: '{Server.Host}'"); } - LogToFile($"m_SafeServerURL end if condition. Server='{Server}'"); } if (Server.Host.EndsWith("/")) { Server.Host.TrimEnd("/".ToCharArray()); - LogToFile($"Trimmed trailing slash. Result: '{Server.Host}'"); } - string finalUrl = Server.Host + ":" + Server.ControlPort + m_urlSuffix; - LogToFile($"Final URL: '{finalUrl}'"); return Server.Host + ":" + Server.ControlPort + m_urlSuffix; } #endregion @@ -273,15 +251,11 @@ public bool Connected /// A valid ImpersonationToken. public void Connect(ServerInterfaceData Server, string MediaManagerServer, string ImpersonationToken) { - LogToFile($"Connect() called with Server='{Server}'"); - LogToFile($"Connect() called with MediaManagerServer='{MediaManagerServer}'"); - LogToFile($"Connect() called with ImpersonationToken='{ImpersonationToken}'"); base.Url = m_SafeServerURL(Server); SecurityHeaderValue = new SecurityHeader(); SecurityHeaderValue.ServiceHost = MediaManagerServer; SecurityHeaderValue.SecurityToken = ImpersonationToken; this.m_Connected = true; - LogToFile($"Connect() end with Server='{Server}'"); } /// From 475f86b0b44b289148e50f2c7b030c561618c5f9 Mon Sep 17 00:00:00 2001 From: silambarasu D Date: Thu, 12 Jun 2025 17:01:52 +0530 Subject: [PATCH 4/4] Remove unnecessary blank line before m_SafeServerURL method in MediaVault class --- Granicus.MediaManager.UserSDK/MediaVault.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Granicus.MediaManager.UserSDK/MediaVault.cs b/Granicus.MediaManager.UserSDK/MediaVault.cs index db6dfeb..574461e 100644 --- a/Granicus.MediaManager.UserSDK/MediaVault.cs +++ b/Granicus.MediaManager.UserSDK/MediaVault.cs @@ -199,7 +199,6 @@ protected override WebRequest GetWebRequest(Uri uri) /// /// Server Name (i.e. streaming.granicus.com) /// - private string m_SafeServerURL(ServerInterfaceData Server) { if (!Server.Host.StartsWith("http://") && !Server.Host.StartsWith("https://"))