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