Skip to content

Commit 29680e5

Browse files
committed
Added signed configurations
1 parent 0a787e2 commit 29680e5

6 files changed

Lines changed: 487 additions & 15 deletions

File tree

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
using DWORD = System.UInt32;
4+
using BOOL = System.UInt32;
5+
6+
namespace wcommsixwrap
7+
{
8+
/// <summary>
9+
/// Contains all of the native Win32 stuff
10+
/// </summary>
11+
class NativeMethods
12+
{
13+
[StructLayout(LayoutKind.Sequential)]
14+
internal struct CRYPTCATATTRIBUTE
15+
{
16+
private DWORD _cbStruct;
17+
[MarshalAs(UnmanagedType.LPWStr)]
18+
internal string pwszReferenceTag;
19+
private DWORD _dwAttrTypeAndAction;
20+
internal DWORD cbValue;
21+
internal System.IntPtr pbValue;
22+
private DWORD _dwReserved;
23+
};
24+
25+
[StructLayout(LayoutKind.Sequential)]
26+
internal struct CRYPTCATMEMBER
27+
{
28+
internal DWORD cbStruct;
29+
[MarshalAs(UnmanagedType.LPWStr)]
30+
internal string pwszReferenceTag;
31+
[MarshalAs(UnmanagedType.LPWStr)]
32+
internal string pwszFileName;
33+
internal GUID gSubjectType;
34+
internal DWORD fdwMemberFlags;
35+
internal IntPtr pIndirectData;
36+
internal DWORD dwCertVersion;
37+
internal DWORD dwReserved;
38+
internal IntPtr hReserved;
39+
internal CRYPT_ATTR_BLOB sEncodedIndirectData;
40+
internal CRYPT_ATTR_BLOB sEncodedMemberInfo;
41+
};
42+
43+
[StructLayout(LayoutKind.Sequential)]
44+
internal struct CRYPT_ATTR_BLOB
45+
{
46+
/// DWORD->unsigned int
47+
public uint cbData;
48+
49+
/// BYTE*
50+
public System.IntPtr pbData;
51+
}
52+
53+
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
54+
internal struct GUID
55+
{
56+
/// unsigned int
57+
internal uint Data1;
58+
59+
/// unsigned short
60+
internal ushort Data2;
61+
62+
/// unsigned short
63+
internal ushort Data3;
64+
65+
/// unsigned char[8]
66+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
67+
internal byte[] Data4;
68+
}
69+
70+
[StructLayout(LayoutKind.Sequential)]
71+
internal struct SIP_INDIRECT_DATA
72+
{
73+
internal CRYPT_ATTRIBUTE_TYPE_VALUE Data;
74+
internal CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm;
75+
internal CRYPT_ATTR_BLOB Digest;
76+
}
77+
78+
[StructLayout(LayoutKind.Sequential)]
79+
internal struct CRYPT_ATTRIBUTE_TYPE_VALUE
80+
{
81+
[MarshalAs(UnmanagedType.LPStr)]
82+
internal string pszObjId;
83+
internal CRYPT_ATTR_BLOB Value;
84+
}
85+
86+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
87+
internal static extern IntPtr CryptCATOpen(
88+
[MarshalAs(UnmanagedType.LPWStr)]
89+
string pwszFilePath,
90+
DWORD fdwOpenFlags,
91+
IntPtr hProv,
92+
DWORD dwPublicVersion,
93+
DWORD dwEncodingType
94+
);
95+
96+
[StructLayoutAttribute(LayoutKind.Sequential)]
97+
internal struct CRYPT_ALGORITHM_IDENTIFIER
98+
{
99+
/// LPSTR->CHAR*
100+
[MarshalAsAttribute(UnmanagedType.LPStr)]
101+
internal string pszObjId;
102+
103+
/// CRYPT_OBJID_BLOB->_CRYPTOAPI_BLOB
104+
internal CRYPT_ATTR_BLOB Parameters;
105+
}
106+
107+
[StructLayout(LayoutKind.Sequential)]
108+
internal struct CRYPTCATSTORE
109+
{
110+
private DWORD _cbStruct;
111+
internal DWORD dwPublicVersion;
112+
[MarshalAs(UnmanagedType.LPWStr)]
113+
internal string pwszP7File;
114+
private IntPtr _hProv;
115+
private DWORD _dwEncodingType;
116+
private DWORD _fdwStoreFlags;
117+
private IntPtr _hReserved;
118+
private IntPtr _hAttrs;
119+
private IntPtr _hCryptMsg;
120+
private IntPtr _hSorted;
121+
};
122+
123+
[DllImport("wintrust.dll")]
124+
internal static extern BOOL CryptCATClose(
125+
IntPtr hCatalog
126+
);
127+
128+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
129+
internal static extern IntPtr CryptCATEnumerateCatAttr(
130+
IntPtr hCatalog,
131+
IntPtr pPrevAttr
132+
);
133+
134+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
135+
internal static extern IntPtr CryptCATEnumerateMember(
136+
IntPtr hCatalog,
137+
IntPtr pPrevMember
138+
);
139+
140+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
141+
internal static extern IntPtr CryptCATEnumerateAttr(
142+
IntPtr hCatalog,
143+
IntPtr pCatMember,
144+
IntPtr pPrevAttr
145+
);
146+
147+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
148+
internal static extern IntPtr CryptCATStoreFromHandle(
149+
IntPtr hCatalog
150+
);
151+
152+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
153+
internal static extern bool CryptCATAdminAcquireContext2(
154+
ref IntPtr phCatAdmin,
155+
IntPtr pgSubsystem,
156+
[MarshalAs(UnmanagedType.LPWStr)]
157+
string pwszHashAlgorithm,
158+
IntPtr pStrongHashPolicy,
159+
DWORD dwFlags
160+
);
161+
162+
[DllImport("wintrust.dll", SetLastError = true, CharSet = CharSet.Unicode)]
163+
internal static extern bool CryptCATAdminCalcHashFromFileHandle2(
164+
IntPtr hCatAdmin,
165+
IntPtr hFile,
166+
[In, Out] ref DWORD pcbHash,
167+
IntPtr pbHash,
168+
DWORD dwFlags
169+
);
170+
171+
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Unicode)]
172+
internal static extern unsafe IntPtr CreateFile(
173+
string lpFileName,
174+
DWORD dwDesiredAccess,
175+
DWORD dwShareMode,
176+
DWORD lpSecurityAttributes,
177+
DWORD dwCreationDisposition,
178+
DWORD dwFlagsAndAttributes,
179+
IntPtr hTemplateFile
180+
);
181+
182+
[DllImport("wintrust.dll", CharSet = CharSet.Unicode)]
183+
internal static extern bool CryptCATAdminReleaseContext(
184+
IntPtr phCatAdmin,
185+
DWORD dwFlags
186+
);
187+
188+
internal const string CloseHandleDllName = "api-ms-win-core-handle-l1-1-0.dll"; /*32*/
189+
/// Return Type: BOOL->int
190+
///hObject: HANDLE->void*
191+
[DllImportAttribute(CloseHandleDllName, EntryPoint = "CloseHandle")]
192+
[return: MarshalAsAttribute(UnmanagedType.Bool)]
193+
internal static extern bool CloseHandle([InAttribute()] System.IntPtr hObject);
194+
}
195+
}

Source/wcommsixwrap/Program.cs

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5-
65
using System.Linq;
76
using System.Reflection;
7+
using System.Runtime.CompilerServices;
88
using System.Runtime.InteropServices;
99
using System.Text;
1010
using System.Text.RegularExpressions;
1111
using System.Threading.Tasks;
1212
using System.Windows;
1313
using System.Windows.Forms;
1414
using System.Xml;
15+
using wincatalogdotnet;
16+
1517
//using Windows.ApplicationModel;
1618

1719
namespace wcommsixwrap
@@ -25,22 +27,47 @@ static void Main(string[] args)
2527
System.Windows.Forms.Application.EnableVisualStyles();
2628
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
2729

28-
30+
bool testSignature = true;
2931
string location = System.Reflection.Assembly.GetEntryAssembly().Location;
3032
string configlocation = location + ".wrunconfig";
33+
string signaturelocation = location + ".cat";
3134
string wrapperAppData = ResolveVariables("[WRAPPER_APPDATA]");
3235

3336
CreateDirectoryRecursively(wrapperAppData);
3437

38+
LogWriter myLogWriter = new LogWriter("Main");
39+
myLogWriter.LogWrite("MSIX Power-Wrapper started.");
40+
41+
myLogWriter.LogWrite("Configuration location is " + configlocation);
42+
43+
if ( testSignature )
44+
{
45+
myLogWriter.LogWrite("Validating catalog signature");
46+
WinCatalog catalog = new WinCatalog(signaturelocation);
47+
48+
bool isValid = catalog.IsSignatureValid();
49+
bool IsFileInCatalog = catalog.IsFileInCatalog(configlocation);
50+
51+
if (!isValid)
52+
{
53+
myLogWriter.LogWrite("Signature of the catalog file is not valid", 3);
54+
throw new Exception("Signature of the catalog file is not valid");
55+
}
56+
if (!IsFileInCatalog)
57+
{
58+
myLogWriter.LogWrite("Filehash not found in catalog", 3);
59+
throw new Exception("Filehash not found in catalog");
60+
}
61+
myLogWriter.LogWrite("Signature successfully validated", 1);
62+
63+
}
64+
3565
// ConfigurationReader configReader = new ConfigurationReader();
3666
// bool test = configReader.validateSignature("C:\\Users\\hauke\\GitHub\\Winget-AutoUpdate-Intune\\WinGet-AutoUpdate-Configurator\\wcommsixconfig.cat");
3767

3868
// bool test2 = configReader.validateFileAgainstHash("C:\\Users\\hauke\\GitHub\\Winget-AutoUpdate-Intune\\WinGet-AutoUpdate-Configurator\\wcommsixconfig.cat", "C:\\Users\\hauke\\GitHub\\Winget-AutoUpdate-Intune\\WinGet-AutoUpdate-Configurator\\Winget-AutoUpdate-x64.exe.wrunconfig");
3969

40-
LogWriter myLogWriter = new LogWriter("Main");
41-
myLogWriter.LogWrite("MSIX Powerwrapper started.");
4270

43-
myLogWriter.LogWrite("Configuration location is " + configlocation);
4471

4572
List<VirtualFile> myFiles = new List<VirtualFile>();
4673
List<VirtualFolder> myVirtualFolders = new List<VirtualFolder>();
@@ -421,9 +448,9 @@ static string[] prepareParameters(string variable)
421448

422449
static string getResolvedVariable(string variable)
423450
{
424-
LogWriter myLogWriter = new LogWriter("getResolvedVariable");
425-
myLogWriter.LogWrite("Resolving " + variable + " to ");
426-
Console.Write("Resolving " + variable + " to ");
451+
// LogWriter myLogWriter = new LogWriter("getResolvedVariable");
452+
// myLogWriter.LogWrite("Resolving " + variable + " to ");
453+
// Console.Write("Resolving " + variable + " to ");
427454
string[] parameters = prepareParameters(variable);
428455
string value = "";
429456
/* if ( variable.Contains("|") )
@@ -501,8 +528,8 @@ static string getResolvedVariable(string variable)
501528

502529
}
503530

504-
myLogWriter.LogWrite(value);
505-
Console.WriteLine(value);
531+
// myLogWriter.LogWrite(value);
532+
// Console.WriteLine(value);
506533
return value;
507534

508535
}

Source/wcommsixwrap/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// Allgemeine Informationen über eine Assembly werden über die folgenden
66
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
77
// die einer Assembly zugeordnet sind.
8-
[assembly: AssemblyTitle("MSIX Powerwrapper")]
8+
[assembly: AssemblyTitle("MSIX Power-Wrapper")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("Hauke Götze")]
12-
[assembly: AssemblyProduct("MSIX Powerwrapper")]
13-
[assembly: AssemblyCopyright("Copyright © Hauke Götze 2021")]
12+
[assembly: AssemblyProduct("MSIX Power-Wrapper")]
13+
[assembly: AssemblyCopyright("Copyright © Hauke Götze 2025")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
3333
// indem Sie "*" wie unten gezeigt eingeben:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.1.0")]
36-
[assembly: AssemblyFileVersion("1.0.1.0")]
35+
[assembly: AssemblyVersion("1.0.2.0")]
36+
[assembly: AssemblyFileVersion("1.0.2.0")]

Source/wcommsixwrap/Runtime.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Runtime
1616
private string arguments;
1717
private string windowStyle;
1818
private bool waitForExit = true;
19+
private bool useShellExecute = true;
1920
public bool WaitForExit {
2021
get { return this.waitForExit; }
2122
}
@@ -60,6 +61,11 @@ public void processXml (XmlReader reader)
6061
if (reader.Value == "false" || reader.Value == "0")
6162
waitForExit = false;
6263
break;
64+
case "UseShellExecute":
65+
reader.Read();
66+
if (reader.Value == "false" || reader.Value == "0")
67+
useShellExecute = false;
68+
break;
6369
case "WindowStyle":
6470
reader.Read();
6571
windowStyle = reader.Value;
@@ -135,6 +141,8 @@ public void Execute()
135141
myLogWriter.LogWrite("WindowStyle will be " + myProcess.StartInfo.WindowStyle);
136142
myProcess.StartInfo.WorkingDirectory = this.getWorkingDirectory();
137143
myLogWriter.LogWrite("WorkingDirectory will be " + myProcess.StartInfo.WorkingDirectory);
144+
myProcess.StartInfo.UseShellExecute = useShellExecute;
145+
myLogWriter.LogWrite("UseShellExecute will be " + useShellExecute);
138146
myProcess.Start();
139147
myLogWriter.LogWrite("Process has started");
140148

0 commit comments

Comments
 (0)