Skip to content

Commit 2c268a7

Browse files
authored
Merge pull request #8 from FlashpointProject/dev
Dev
2 parents 3ab1ef3 + 63bc01b commit 2c268a7

24 files changed

+1105
-342
lines changed

FlashpointSecurePlayer/CustomSecurityManager.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.IO;
45
using System.Linq;
56
using System.Runtime.InteropServices;
67
using System.Runtime.InteropServices.ComTypes;
@@ -14,6 +15,9 @@
1415

1516
namespace FlashpointSecurePlayer {
1617
public class CustomSecurityManager : InternetInterfaces.IServiceProvider, InternetInterfaces.IInternetSecurityManager {
18+
private const string FLASH_EXTENSION = ".SWF";
19+
20+
// https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms537182(v=vs.85)?redirectedfrom=MSDN
1721
public CustomSecurityManager(WebBrowser _WebBrowser) {
1822
InternetInterfaces.IServiceProvider webBrowserServiceProviderInterface = _WebBrowser.ActiveXInstance as InternetInterfaces.IServiceProvider;
1923
IntPtr profferServiceInterfacePointer = IntPtr.Zero;
@@ -63,19 +67,23 @@ int InternetInterfaces.IInternetSecurityManager.MapUrlToZone([MarshalAs(Unmanage
6367
// behave like local intranet
6468
pdwZone = 1;
6569

70+
// don't map zone for file:// URLs, that's outside the proxy
6671
if ((dwFlags & MUTZ_ISFILE) == MUTZ_ISFILE) {
6772
return INET_E_DEFAULT_ACTION;
6873
}
6974

75+
// error if URL is null
7076
if (pwszUrl == null) {
7177
return E_INVALIDARG;
7278
}
7379

80+
// unescape URL if needed
7481
if ((dwFlags & MUTZ_DONT_UNESCAPE) != MUTZ_DONT_UNESCAPE) {
7582
try {
7683
pwszUrl = Uri.UnescapeDataString(pwszUrl);
7784
} catch (ArgumentNullException) {
78-
return INET_E_DEFAULT_ACTION;
85+
// error if URL is null
86+
return E_INVALIDARG;
7987
}
8088
}
8189

@@ -95,14 +103,31 @@ int InternetInterfaces.IInternetSecurityManager.GetSecurityId([MarshalAs(Unmanag
95103
int InternetInterfaces.IInternetSecurityManager.ProcessUrlAction([MarshalAs(UnmanagedType.LPWStr)] string pwszUrl, uint dwAction, out uint pPolicy, uint cbPolicy, byte pContext, uint cbContext, uint dwFlags, uint dwReserved) {
96104
pPolicy = URLPOLICY_DISALLOW;
97105

106+
if (cbPolicy < Marshal.SizeOf(pPolicy.GetType())) {
107+
return S_FALSE;
108+
}
109+
110+
// don't process file:// URLS, they are outside the proxy
98111
if ((dwFlags & PUAF_ISFILE) == PUAF_ISFILE) {
99112
return INET_E_DEFAULT_ACTION;
100113
}
101114

115+
// error if URL is null
102116
if (pwszUrl == null) {
103117
return E_INVALIDARG;
104118
}
105119

120+
try {
121+
if (Path.GetExtension(new Uri(pwszUrl).LocalPath).ToUpper() == FLASH_EXTENSION) {
122+
if (dwAction == URLACTION_ACTIVEX_TREATASUNTRUSTED) { // don't trust Flash ActiveX Controls
123+
pPolicy = URLPOLICY_ALLOW;
124+
}
125+
return S_OK;
126+
}
127+
} catch {
128+
return S_FALSE;
129+
}
130+
106131
pwszUrl = pwszUrl.ToLower();
107132

108133
if (pwszUrl.IndexOf("http://") != 0 && pwszUrl.IndexOf("https://") != 0 && pwszUrl.IndexOf("ftp://") != 0) {
@@ -113,7 +138,7 @@ int InternetInterfaces.IInternetSecurityManager.ProcessUrlAction([MarshalAs(Unma
113138
return INET_E_DEFAULT_ACTION;
114139
}
115140

116-
if (dwAction == URLACTION_ACTIVEX_TREATASUNTRUSTED || // trust ActiveX Controls always
141+
if (dwAction == URLACTION_ACTIVEX_TREATASUNTRUSTED || // trust other ActiveX Controls
117142
dwAction == URLACTION_HTML_MIXED_CONTENT || // block HTTPS content on HTTP websites for Flashpoint Proxy
118143
dwAction == URLACTION_CLIENT_CERT_PROMPT || // don't allow invalid certificates
119144
dwAction == URLACTION_AUTOMATIC_ACTIVEX_UI || // do not display the install dialog for ActiveX Controls

FlashpointSecurePlayer/EnvironmentVariables.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ public EnvironmentVariables(Form form) : base(form) { }
1919

2020
public void Activate(string name, string server, string applicationMutexName) {
2121
base.Activate(name);
22-
ModificationsElement modificationsElement = GetModificationsElement(true, Name);
22+
ModificationsElement modificationsElement = GetModificationsElement(false, Name);
23+
24+
if (modificationsElement == null) {
25+
return;
26+
}
27+
2328
string value = null;
2429
List<string> values = null;
2530
string compatibilityLayerValue = null;
2631
List<string> compatibilityLayerValues = new List<string>();
2732

2833
try {
34+
// we need to find the compatibility layers so we can check later if the ones we want are already set
2935
compatibilityLayerValue = Environment.GetEnvironmentVariable(COMPATIBILITY_LAYER_NAME);
3036
} catch (ArgumentException) {
3137
throw new EnvironmentVariablesFailedException("Failed to get the " + COMPATIBILITY_LAYER_NAME + " Environment Variable.");
@@ -61,6 +67,8 @@ public void Activate(string name, string server, string applicationMutexName) {
6167
if (environmentVariablesElement.Name == COMPATIBILITY_LAYER_NAME && !String.IsNullOrEmpty(server)) {
6268
values = new List<string>();
6369

70+
// the compatibility layers may contain more values
71+
// but we're only concerned if it contains the values we want
6472
if (compatibilityLayerValue != null) {
6573
compatibilityLayerValues = compatibilityLayerValue.ToUpper().Split(' ').ToList();
6674
}
@@ -69,8 +77,11 @@ public void Activate(string name, string server, string applicationMutexName) {
6977
values = value.ToUpper().Split(' ').ToList();
7078
}
7179

80+
// we have to restart in this case in server mode
81+
// because the compatibility layers only take effect
82+
// on process start
7283
if (values.Except(compatibilityLayerValues).Any()) {
73-
throw new CompatibilityLayersException("The Compatibility Layers (" + String.Join(", ", compatibilityLayerValues) + ") cannot be set.");
84+
throw new CompatibilityLayersException("The Compatibility Layers (" + value + ") cannot be set.");
7485
}
7586
}
7687

@@ -82,12 +93,14 @@ public void Activate(string name, string server, string applicationMutexName) {
8293
}
8394

8495
public void Deactivate(string server) {
96+
// do the reverse of activation because we can
8597
base.Deactivate();
8698

8799
if (String.IsNullOrEmpty(Name)) {
88100
return;
89101
}
90102

103+
// don't need to get active name, we're only deactivating for this process
91104
ModificationsElement modificationsElement = GetModificationsElement(false, Name);
92105

93106
if (modificationsElement == null) {

0 commit comments

Comments
 (0)