aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Inscriber.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Inscriber.cs')
-rw-r--r--src/WixToolset.Core/Inscriber.cs437
1 files changed, 0 insertions, 437 deletions
diff --git a/src/WixToolset.Core/Inscriber.cs b/src/WixToolset.Core/Inscriber.cs
deleted file mode 100644
index cff2dab2..00000000
--- a/src/WixToolset.Core/Inscriber.cs
+++ /dev/null
@@ -1,437 +0,0 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3namespace WixToolset.Core
4{
5 using System.IO;
6 using WixToolset.Data;
7
8 /// <summary>
9 /// Converts a wixout representation of an MSM database into a ComponentGroup the form of WiX source.
10 /// </summary>
11 internal class Inscriber
12 {
13 // <summary>
14 // Gets or sets the temp files collection.
15 // </summary>
16 // <value>The temp files collection.</value>
17 // public TempFileCollection TempFiles
18 // {
19 // get { return this.tempFiles; }
20 // set { this.tempFiles = value; }
21 // }
22
23 /// <summary>
24 /// Gets or sets the path to the temp files location.
25 /// </summary>
26 /// <value>The path to the temp files location.</value>
27 public string TempFilesLocation
28 {
29 get
30 {
31 // if (null == this.tempFiles)
32 // {
33 // return null;
34 // }
35 // else
36 // {
37 // return this.tempFiles.BasePath;
38 // }
39 return Path.GetTempPath();
40 }
41 // set
42 // {
43 // this.DeleteTempFiles();
44
45 // if (null == value)
46 // {
47 // this.tempFiles = new TempFileCollection();
48 // }
49 // else
50 // {
51 // this.tempFiles = new TempFileCollection(value);
52 // }
53
54 // // ensure the base path exists
55 // Directory.CreateDirectory(this.tempFiles.BasePath);
56 // }
57 }
58
59 /// <summary>
60 /// Extracts engine from attached container and updates engine with detached container signatures.
61 /// </summary>
62 /// <param name="bundleFile">Bundle with attached container.</param>
63 /// <param name="outputFile">Bundle engine only.</param>
64 /// <returns>True if bundle was updated.</returns>
65 public bool InscribeBundleEngine(string bundleFile, string outputFile)
66 {
67 //string tempFile = Path.Combine(this.TempFilesLocation, "bundle_engine_unsigned.exe");
68
69 //using (BurnReader reader = BurnReader.Open(bundleFile))
70 //using (FileStream writer = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete))
71 //{
72 // reader.Stream.Seek(0, SeekOrigin.Begin);
73
74 // byte[] buffer = new byte[4 * 1024];
75 // int total = 0;
76 // int read = 0;
77 // do
78 // {
79 // read = Math.Min(buffer.Length, (int)reader.EngineSize - total);
80
81 // read = reader.Stream.Read(buffer, 0, read);
82 // writer.Write(buffer, 0, read);
83
84 // total += read;
85 // } while (total < reader.EngineSize && 0 < read);
86
87 // if (total != reader.EngineSize)
88 // {
89 // throw new InvalidOperationException("Failed to copy engine out of bundle.");
90 // }
91
92 // // TODO: update writer with detached container signatures.
93 //}
94
95 //Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
96 //if (File.Exists(outputFile))
97 //{
98 // File.Delete(outputFile);
99 //}
100 //File.Move(tempFile, outputFile);
101 //WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { outputFile }, 1);
102
103 return true;
104 }
105
106 /// <summary>
107 /// Updates engine with attached container information and adds attached container again.
108 /// </summary>
109 /// <param name="bundleFile">Bundle with attached container.</param>
110 /// <param name="signedEngineFile">Signed bundle engine.</param>
111 /// <param name="outputFile">Signed engine with attached container.</param>
112 /// <returns>True if bundle was updated.</returns>
113 public bool InscribeBundle(string bundleFile, string signedEngineFile, string outputFile)
114 {
115 //bool inscribed = false;
116 //string tempFile = Path.Combine(this.TempFilesLocation, "bundle_engine_signed.exe");
117
118 //using (BurnReader reader = BurnReader.Open(bundleFile))
119 //{
120 // File.Copy(signedEngineFile, tempFile, true);
121
122 // // If there was an attached container on the original (unsigned) bundle, put it back.
123 // if (reader.AttachedContainerSize > 0)
124 // {
125 // reader.Stream.Seek(reader.AttachedContainerAddress, SeekOrigin.Begin);
126
127 // using (BurnWriter writer = BurnWriter.Open(tempFile))
128 // {
129 // writer.RememberThenResetSignature();
130 // writer.AppendContainer(reader.Stream, reader.AttachedContainerSize, BurnCommon.Container.Attached);
131 // inscribed = true;
132 // }
133 // }
134 //}
135
136 //Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
137 //if (File.Exists(outputFile))
138 //{
139 // File.Delete(outputFile);
140 //}
141 //File.Move(tempFile, outputFile);
142 //WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { outputFile }, 1);
143
144 //return inscribed;
145 return false;
146 }
147
148 /// <summary>
149 /// Updates database with signatures from external cabinets.
150 /// </summary>
151 /// <param name="databaseFile">Path to MSI database.</param>
152 /// <param name="outputFile">Ouput for updated MSI database.</param>
153 /// <param name="tidy">Clean up files.</param>
154 /// <returns>True if database is updated.</returns>
155 public bool InscribeDatabase(string databaseFile, string outputFile, bool tidy)
156 {
157 //// Keeps track of whether we've encountered at least one signed cab or not - we'll throw a warning if no signed cabs were encountered
158 //bool foundUnsignedExternals = false;
159 //bool shouldCommit = false;
160
161 //FileAttributes attributes = File.GetAttributes(databaseFile);
162 //if (FileAttributes.ReadOnly == (attributes & FileAttributes.ReadOnly))
163 //{
164 // this.OnMessage(WixErrors.ReadOnlyOutputFile(databaseFile));
165 // return shouldCommit;
166 //}
167
168 //using (Database database = new Database(databaseFile, OpenDatabase.Transact))
169 //{
170 // // Just use the English codepage, because the tables we're importing only have binary streams / MSI identifiers / other non-localizable content
171 // int codepage = 1252;
172
173 // // list of certificates for this database (hash/identifier)
174 // Dictionary<string, string> certificates = new Dictionary<string, string>();
175
176 // // Reset the in-memory tables for this new database
177 // Table digitalSignatureTable = new Table(null, this.tableDefinitions["MsiDigitalSignature"]);
178 // Table digitalCertificateTable = new Table(null, this.tableDefinitions["MsiDigitalCertificate"]);
179
180 // // If any digital signature records exist that are not of the media type, preserve them
181 // if (database.TableExists("MsiDigitalSignature"))
182 // {
183 // using (View digitalSignatureView = database.OpenExecuteView("SELECT `Table`, `SignObject`, `DigitalCertificate_`, `Hash` FROM `MsiDigitalSignature` WHERE `Table` <> 'Media'"))
184 // {
185 // while (true)
186 // {
187 // using (Record digitalSignatureRecord = digitalSignatureView.Fetch())
188 // {
189 // if (null == digitalSignatureRecord)
190 // {
191 // break;
192 // }
193
194 // Row digitalSignatureRow = null;
195 // digitalSignatureRow = digitalSignatureTable.CreateRow(null);
196
197 // string table = digitalSignatureRecord.GetString(0);
198 // string signObject = digitalSignatureRecord.GetString(1);
199
200 // digitalSignatureRow[0] = table;
201 // digitalSignatureRow[1] = signObject;
202 // digitalSignatureRow[2] = digitalSignatureRecord.GetString(2);
203
204 // if (false == digitalSignatureRecord.IsNull(3))
205 // {
206 // // Export to a file, because the MSI API's require us to provide a file path on disk
207 // string hashPath = Path.Combine(this.TempFilesLocation, "MsiDigitalSignature");
208 // string hashFileName = string.Concat(table, ".", signObject, ".bin");
209
210 // Directory.CreateDirectory(hashPath);
211 // hashPath = Path.Combine(hashPath, hashFileName);
212
213 // using (FileStream fs = File.Create(hashPath))
214 // {
215 // int bytesRead;
216 // byte[] buffer = new byte[1024 * 4];
217
218 // while (0 != (bytesRead = digitalSignatureRecord.GetStream(3, buffer, buffer.Length)))
219 // {
220 // fs.Write(buffer, 0, bytesRead);
221 // }
222 // }
223
224 // digitalSignatureRow[3] = hashFileName;
225 // }
226 // }
227 // }
228 // }
229 // }
230
231 // // If any digital certificates exist, extract and preserve them
232 // if (database.TableExists("MsiDigitalCertificate"))
233 // {
234 // using (View digitalCertificateView = database.OpenExecuteView("SELECT * FROM `MsiDigitalCertificate`"))
235 // {
236 // while (true)
237 // {
238 // using (Record digitalCertificateRecord = digitalCertificateView.Fetch())
239 // {
240 // if (null == digitalCertificateRecord)
241 // {
242 // break;
243 // }
244
245 // string certificateId = digitalCertificateRecord.GetString(1); // get the identifier of the certificate
246
247 // // Export to a file, because the MSI API's require us to provide a file path on disk
248 // string certPath = Path.Combine(this.TempFilesLocation, "MsiDigitalCertificate");
249 // Directory.CreateDirectory(certPath);
250 // certPath = Path.Combine(certPath, string.Concat(certificateId, ".cer"));
251
252 // using (FileStream fs = File.Create(certPath))
253 // {
254 // int bytesRead;
255 // byte[] buffer = new byte[1024 * 4];
256
257 // while (0 != (bytesRead = digitalCertificateRecord.GetStream(2, buffer, buffer.Length)))
258 // {
259 // fs.Write(buffer, 0, bytesRead);
260 // }
261 // }
262
263 // // Add it to our "add to MsiDigitalCertificate" table dictionary
264 // Row digitalCertificateRow = digitalCertificateTable.CreateRow(null);
265 // digitalCertificateRow[0] = certificateId;
266
267 // // Now set the file path on disk where this binary stream will be picked up at import time
268 // digitalCertificateRow[1] = string.Concat(certificateId, ".cer");
269
270 // // Load the cert to get it's thumbprint
271 // X509Certificate cert = X509Certificate.CreateFromCertFile(certPath);
272 // X509Certificate2 cert2 = new X509Certificate2(cert);
273
274 // certificates.Add(cert2.Thumbprint, certificateId);
275 // }
276 // }
277 // }
278 // }
279
280 // using (View mediaView = database.OpenExecuteView("SELECT * FROM `Media`"))
281 // {
282 // while (true)
283 // {
284 // using (Record mediaRecord = mediaView.Fetch())
285 // {
286 // if (null == mediaRecord)
287 // {
288 // break;
289 // }
290
291 // X509Certificate2 cert2 = null;
292 // Row digitalSignatureRow = null;
293
294 // string cabName = mediaRecord.GetString(4); // get the name of the cab
295 // // If there is no cabinet or it's an internal cab, skip it.
296 // if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal))
297 // {
298 // continue;
299 // }
300
301 // string cabId = mediaRecord.GetString(1); // get the ID of the cab
302 // string cabPath = Path.Combine(Path.GetDirectoryName(databaseFile), cabName);
303
304 // // If the cabs aren't there, throw an error but continue to catch the other errors
305 // if (!File.Exists(cabPath))
306 // {
307 // this.OnMessage(WixErrors.WixFileNotFound(cabPath));
308 // continue;
309 // }
310
311 // try
312 // {
313 // // Get the certificate from the cab
314 // X509Certificate signedFileCert = X509Certificate.CreateFromSignedFile(cabPath);
315 // cert2 = new X509Certificate2(signedFileCert);
316 // }
317 // catch (System.Security.Cryptography.CryptographicException e)
318 // {
319 // uint HResult = unchecked((uint)Marshal.GetHRForException(e));
320
321 // // If the file has no cert, continue, but flag that we found at least one so we can later give a warning
322 // if (0x80092009 == HResult) // CRYPT_E_NO_MATCH
323 // {
324 // foundUnsignedExternals = true;
325 // continue;
326 // }
327
328 // // todo: exactly which HRESULT corresponds to this issue?
329 // // If it's one of these exact platforms, warn the user that it may be due to their OS.
330 // if ((5 == Environment.OSVersion.Version.Major && 2 == Environment.OSVersion.Version.Minor) || // W2K3
331 // (5 == Environment.OSVersion.Version.Major && 1 == Environment.OSVersion.Version.Minor)) // XP
332 // {
333 // this.OnMessage(WixErrors.UnableToGetAuthenticodeCertOfFileDownlevelOS(cabPath, String.Format(CultureInfo.InvariantCulture, "HRESULT: 0x{0:x8}", HResult)));
334 // }
335 // else // otherwise, generic error
336 // {
337 // this.OnMessage(WixErrors.UnableToGetAuthenticodeCertOfFile(cabPath, String.Format(CultureInfo.InvariantCulture, "HRESULT: 0x{0:x8}", HResult)));
338 // }
339 // }
340
341 // // If we haven't added this cert to the MsiDigitalCertificate table, set it up to be added
342 // if (!certificates.ContainsKey(cert2.Thumbprint))
343 // {
344 // // generate a stable identifier
345 // string certificateGeneratedId = Common.GenerateIdentifier("cer", cert2.Thumbprint);
346
347 // // Add it to our "add to MsiDigitalCertificate" table dictionary
348 // Row digitalCertificateRow = digitalCertificateTable.CreateRow(null);
349 // digitalCertificateRow[0] = certificateGeneratedId;
350
351 // // Export to a file, because the MSI API's require us to provide a file path on disk
352 // string certPath = Path.Combine(this.TempFilesLocation, "MsiDigitalCertificate");
353 // Directory.CreateDirectory(certPath);
354 // certPath = Path.Combine(certPath, string.Concat(cert2.Thumbprint, ".cer"));
355 // File.Delete(certPath);
356
357 // using (BinaryWriter writer = new BinaryWriter(File.Open(certPath, FileMode.Create)))
358 // {
359 // writer.Write(cert2.RawData);
360 // writer.Close();
361 // }
362
363 // // Now set the file path on disk where this binary stream will be picked up at import time
364 // digitalCertificateRow[1] = string.Concat(cert2.Thumbprint, ".cer");
365
366 // certificates.Add(cert2.Thumbprint, certificateGeneratedId);
367 // }
368
369 // digitalSignatureRow = digitalSignatureTable.CreateRow(null);
370
371 // digitalSignatureRow[0] = "Media";
372 // digitalSignatureRow[1] = cabId;
373 // digitalSignatureRow[2] = certificates[cert2.Thumbprint];
374 // }
375 // }
376 // }
377
378 // if (digitalCertificateTable.Rows.Count > 0)
379 // {
380 // database.ImportTable(codepage, digitalCertificateTable, this.TempFilesLocation, true);
381 // shouldCommit = true;
382 // }
383
384 // if (digitalSignatureTable.Rows.Count > 0)
385 // {
386 // database.ImportTable(codepage, digitalSignatureTable, this.TempFilesLocation, true);
387 // shouldCommit = true;
388 // }
389
390 // // TODO: if we created the table(s), then we should add the _Validation records for them.
391
392 // certificates = null;
393
394 // // If we did find external cabs but none of them were signed, give a warning
395 // if (foundUnsignedExternals)
396 // {
397 // this.OnMessage(WixWarnings.ExternalCabsAreNotSigned(databaseFile));
398 // }
399
400 // if (shouldCommit)
401 // {
402 // database.Commit();
403 // }
404 //}
405
406 //return shouldCommit;
407 return false;
408 }
409
410 /// <summary>
411 /// Cleans up the temp files used by the Inscriber.
412 /// </summary>
413 /// <returns>True if all files were deleted, false otherwise.</returns>
414 public bool DeleteTempFiles()
415 {
416#if REDO_IN_NETCORE
417 if (null == this.tempFiles)
418 {
419 return true; // no work to do
420 }
421 else
422 {
423 bool deleted = Common.DeleteTempFiles(this.TempFilesLocation, this);
424
425 if (deleted)
426 {
427 ((IDisposable)this.tempFiles).Dispose();
428 this.tempFiles = null; // temp files have been deleted, no need to remember this now
429 }
430
431 return deleted;
432 }
433#endif
434 return true;
435 }
436 }
437}