diff options
| author | Rob Mensching <rob@firegiant.com> | 2020-01-24 15:27:20 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2020-02-05 16:15:47 -0800 |
| commit | 6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d (patch) | |
| tree | c717333cd10d5592e59dfb898b391275bba1f389 /src/WixToolset.Core.WindowsInstaller/Inscribe | |
| parent | 6e2e67ab55c75f4655397588c0dcc64f50d22f92 (diff) | |
| download | wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.tar.gz wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.tar.bz2 wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.zip | |
Start on new patch infrastructure
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Inscribe')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Inscribe/InscribeMsiPackageCommand.cs | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Inscribe/InscribeMsiPackageCommand.cs b/src/WixToolset.Core.WindowsInstaller/Inscribe/InscribeMsiPackageCommand.cs index ff7472ff..582e179e 100644 --- a/src/WixToolset.Core.WindowsInstaller/Inscribe/InscribeMsiPackageCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Inscribe/InscribeMsiPackageCommand.cs | |||
| @@ -33,40 +33,40 @@ namespace WixToolset.Core.WindowsInstaller.Inscribe | |||
| 33 | public bool Execute() | 33 | public bool Execute() |
| 34 | { | 34 | { |
| 35 | // 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 | 35 | // 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 |
| 36 | bool foundUnsignedExternals = false; | 36 | var foundUnsignedExternals = false; |
| 37 | bool shouldCommit = false; | 37 | var shouldCommit = false; |
| 38 | 38 | ||
| 39 | FileAttributes attributes = File.GetAttributes(this.Context.InputFilePath); | 39 | var attributes = File.GetAttributes(this.Context.InputFilePath); |
| 40 | if (FileAttributes.ReadOnly == (attributes & FileAttributes.ReadOnly)) | 40 | if (FileAttributes.ReadOnly == (attributes & FileAttributes.ReadOnly)) |
| 41 | { | 41 | { |
| 42 | this.Messaging.Write(ErrorMessages.ReadOnlyOutputFile(this.Context.InputFilePath)); | 42 | this.Messaging.Write(ErrorMessages.ReadOnlyOutputFile(this.Context.InputFilePath)); |
| 43 | return shouldCommit; | 43 | return shouldCommit; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | using (Database database = new Database(this.Context.InputFilePath, OpenDatabase.Transact)) | 46 | using (var database = new Database(this.Context.InputFilePath, OpenDatabase.Transact)) |
| 47 | { | 47 | { |
| 48 | // Just use the English codepage, because the tables we're importing only have binary streams / MSI identifiers / other non-localizable content | 48 | // Just use the English codepage, because the tables we're importing only have binary streams / MSI identifiers / other non-localizable content |
| 49 | int codepage = 1252; | 49 | var codepage = 1252; |
| 50 | 50 | ||
| 51 | // list of certificates for this database (hash/identifier) | 51 | // list of certificates for this database (hash/identifier) |
| 52 | Dictionary<string, string> certificates = new Dictionary<string, string>(); | 52 | var certificates = new Dictionary<string, string>(); |
| 53 | 53 | ||
| 54 | // Reset the in-memory tables for this new database | 54 | // Reset the in-memory tables for this new database |
| 55 | Table digitalSignatureTable = new Table(this.TableDefinitions["MsiDigitalSignature"]); | 55 | var digitalSignatureTable = new Table(this.TableDefinitions["MsiDigitalSignature"]); |
| 56 | Table digitalCertificateTable = new Table(this.TableDefinitions["MsiDigitalCertificate"]); | 56 | var digitalCertificateTable = new Table(this.TableDefinitions["MsiDigitalCertificate"]); |
| 57 | 57 | ||
| 58 | // If any digital signature records exist that are not of the media type, preserve them | 58 | // If any digital signature records exist that are not of the media type, preserve them |
| 59 | if (database.TableExists("MsiDigitalSignature")) | 59 | if (database.TableExists("MsiDigitalSignature")) |
| 60 | { | 60 | { |
| 61 | using (View digitalSignatureView = database.OpenExecuteView("SELECT `Table`, `SignObject`, `DigitalCertificate_`, `Hash` FROM `MsiDigitalSignature` WHERE `Table` <> 'Media'")) | 61 | using (var digitalSignatureView = database.OpenExecuteView("SELECT `Table`, `SignObject`, `DigitalCertificate_`, `Hash` FROM `MsiDigitalSignature` WHERE `Table` <> 'Media'")) |
| 62 | { | 62 | { |
| 63 | foreach (Record digitalSignatureRecord in digitalSignatureView.Records) | 63 | foreach (var digitalSignatureRecord in digitalSignatureView.Records) |
| 64 | { | 64 | { |
| 65 | Row digitalSignatureRow = null; | 65 | Row digitalSignatureRow = null; |
| 66 | digitalSignatureRow = digitalSignatureTable.CreateRow(null); | 66 | digitalSignatureRow = digitalSignatureTable.CreateRow(null); |
| 67 | 67 | ||
| 68 | string table = digitalSignatureRecord.GetString(0); | 68 | var table = digitalSignatureRecord.GetString(0); |
| 69 | string signObject = digitalSignatureRecord.GetString(1); | 69 | var signObject = digitalSignatureRecord.GetString(1); |
| 70 | 70 | ||
| 71 | digitalSignatureRow[0] = table; | 71 | digitalSignatureRow[0] = table; |
| 72 | digitalSignatureRow[1] = signObject; | 72 | digitalSignatureRow[1] = signObject; |
| @@ -75,16 +75,16 @@ namespace WixToolset.Core.WindowsInstaller.Inscribe | |||
| 75 | if (false == digitalSignatureRecord.IsNull(3)) | 75 | if (false == digitalSignatureRecord.IsNull(3)) |
| 76 | { | 76 | { |
| 77 | // Export to a file, because the MSI API's require us to provide a file path on disk | 77 | // Export to a file, because the MSI API's require us to provide a file path on disk |
| 78 | string hashPath = Path.Combine(this.Context.IntermediateFolder, "MsiDigitalSignature"); | 78 | var hashPath = Path.Combine(this.Context.IntermediateFolder, "MsiDigitalSignature"); |
| 79 | string hashFileName = string.Concat(table, ".", signObject, ".bin"); | 79 | var hashFileName = String.Concat(table, ".", signObject, ".bin"); |
| 80 | 80 | ||
| 81 | Directory.CreateDirectory(hashPath); | 81 | Directory.CreateDirectory(hashPath); |
| 82 | hashPath = Path.Combine(hashPath, hashFileName); | 82 | hashPath = Path.Combine(hashPath, hashFileName); |
| 83 | 83 | ||
| 84 | using (FileStream fs = File.Create(hashPath)) | 84 | using (var fs = File.Create(hashPath)) |
| 85 | { | 85 | { |
| 86 | int bytesRead; | 86 | int bytesRead; |
| 87 | byte[] buffer = new byte[1024 * 4]; | 87 | var buffer = new byte[1024 * 4]; |
| 88 | 88 | ||
| 89 | while (0 != (bytesRead = digitalSignatureRecord.GetStream(3, buffer, buffer.Length))) | 89 | while (0 != (bytesRead = digitalSignatureRecord.GetStream(3, buffer, buffer.Length))) |
| 90 | { | 90 | { |
| @@ -101,21 +101,21 @@ namespace WixToolset.Core.WindowsInstaller.Inscribe | |||
| 101 | // If any digital certificates exist, extract and preserve them | 101 | // If any digital certificates exist, extract and preserve them |
| 102 | if (database.TableExists("MsiDigitalCertificate")) | 102 | if (database.TableExists("MsiDigitalCertificate")) |
| 103 | { | 103 | { |
| 104 | using (View digitalCertificateView = database.OpenExecuteView("SELECT * FROM `MsiDigitalCertificate`")) | 104 | using (var digitalCertificateView = database.OpenExecuteView("SELECT * FROM `MsiDigitalCertificate`")) |
| 105 | { | 105 | { |
| 106 | foreach (Record digitalCertificateRecord in digitalCertificateView.Records) | 106 | foreach (var digitalCertificateRecord in digitalCertificateView.Records) |
| 107 | { | 107 | { |
| 108 | string certificateId = digitalCertificateRecord.GetString(1); // get the identifier of the certificate | 108 | var certificateId = digitalCertificateRecord.GetString(1); // get the identifier of the certificate |
| 109 | 109 | ||
| 110 | // Export to a file, because the MSI API's require us to provide a file path on disk | 110 | // Export to a file, because the MSI API's require us to provide a file path on disk |
| 111 | string certPath = Path.Combine(this.Context.IntermediateFolder, "MsiDigitalCertificate"); | 111 | var certPath = Path.Combine(this.Context.IntermediateFolder, "MsiDigitalCertificate"); |
| 112 | Directory.CreateDirectory(certPath); | 112 | Directory.CreateDirectory(certPath); |
| 113 | certPath = Path.Combine(certPath, string.Concat(certificateId, ".cer")); | 113 | certPath = Path.Combine(certPath, String.Concat(certificateId, ".cer")); |
| 114 | 114 | ||
| 115 | using (FileStream fs = File.Create(certPath)) | 115 | using (var fs = File.Create(certPath)) |
| 116 | { | 116 | { |
| 117 | int bytesRead; | 117 | int bytesRead; |
| 118 | byte[] buffer = new byte[1024 * 4]; | 118 | var buffer = new byte[1024 * 4]; |
| 119 | 119 | ||
| 120 | while (0 != (bytesRead = digitalCertificateRecord.GetStream(2, buffer, buffer.Length))) | 120 | while (0 != (bytesRead = digitalCertificateRecord.GetStream(2, buffer, buffer.Length))) |
| 121 | { | 121 | { |
| @@ -124,37 +124,37 @@ namespace WixToolset.Core.WindowsInstaller.Inscribe | |||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | // Add it to our "add to MsiDigitalCertificate" table dictionary | 126 | // Add it to our "add to MsiDigitalCertificate" table dictionary |
| 127 | Row digitalCertificateRow = digitalCertificateTable.CreateRow(null); | 127 | var digitalCertificateRow = digitalCertificateTable.CreateRow(null); |
| 128 | digitalCertificateRow[0] = certificateId; | 128 | digitalCertificateRow[0] = certificateId; |
| 129 | 129 | ||
| 130 | // Now set the file path on disk where this binary stream will be picked up at import time | 130 | // Now set the file path on disk where this binary stream will be picked up at import time |
| 131 | digitalCertificateRow[1] = string.Concat(certificateId, ".cer"); | 131 | digitalCertificateRow[1] = String.Concat(certificateId, ".cer"); |
| 132 | 132 | ||
| 133 | // Load the cert to get it's thumbprint | 133 | // Load the cert to get it's thumbprint |
| 134 | X509Certificate cert = X509Certificate.CreateFromCertFile(certPath); | 134 | var cert = X509Certificate.CreateFromCertFile(certPath); |
| 135 | X509Certificate2 cert2 = new X509Certificate2(cert); | 135 | var cert2 = new X509Certificate2(cert); |
| 136 | 136 | ||
| 137 | certificates.Add(cert2.Thumbprint, certificateId); | 137 | certificates.Add(cert2.Thumbprint, certificateId); |
| 138 | } | 138 | } |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | using (View mediaView = database.OpenExecuteView("SELECT * FROM `Media`")) | 142 | using (var mediaView = database.OpenExecuteView("SELECT * FROM `Media`")) |
| 143 | { | 143 | { |
| 144 | foreach (Record mediaRecord in mediaView.Records) | 144 | foreach (var mediaRecord in mediaView.Records) |
| 145 | { | 145 | { |
| 146 | X509Certificate2 cert2 = null; | 146 | X509Certificate2 cert2 = null; |
| 147 | Row digitalSignatureRow = null; | 147 | Row digitalSignatureRow = null; |
| 148 | 148 | ||
| 149 | string cabName = mediaRecord.GetString(4); // get the name of the cab | 149 | var cabName = mediaRecord.GetString(4); // get the name of the cab |
| 150 | // If there is no cabinet or it's an internal cab, skip it. | 150 | // If there is no cabinet or it's an internal cab, skip it. |
| 151 | if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal)) | 151 | if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal)) |
| 152 | { | 152 | { |
| 153 | continue; | 153 | continue; |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | string cabId = mediaRecord.GetString(1); // get the ID of the cab | 156 | var cabId = mediaRecord.GetString(1); // get the ID of the cab |
| 157 | string cabPath = Path.Combine(Path.GetDirectoryName(this.Context.InputFilePath), cabName); | 157 | var cabPath = Path.Combine(Path.GetDirectoryName(this.Context.InputFilePath), cabName); |
| 158 | 158 | ||
| 159 | // If the cabs aren't there, throw an error but continue to catch the other errors | 159 | // If the cabs aren't there, throw an error but continue to catch the other errors |
| 160 | if (!File.Exists(cabPath)) | 160 | if (!File.Exists(cabPath)) |
| @@ -166,12 +166,12 @@ namespace WixToolset.Core.WindowsInstaller.Inscribe | |||
| 166 | try | 166 | try |
| 167 | { | 167 | { |
| 168 | // Get the certificate from the cab | 168 | // Get the certificate from the cab |
| 169 | X509Certificate signedFileCert = X509Certificate.CreateFromSignedFile(cabPath); | 169 | var signedFileCert = X509Certificate.CreateFromSignedFile(cabPath); |
| 170 | cert2 = new X509Certificate2(signedFileCert); | 170 | cert2 = new X509Certificate2(signedFileCert); |
| 171 | } | 171 | } |
| 172 | catch (System.Security.Cryptography.CryptographicException e) | 172 | catch (System.Security.Cryptography.CryptographicException e) |
| 173 | { | 173 | { |
| 174 | uint HResult = unchecked((uint)Marshal.GetHRForException(e)); | 174 | var HResult = unchecked((uint)Marshal.GetHRForException(e)); |
| 175 | 175 | ||
| 176 | // If the file has no cert, continue, but flag that we found at least one so we can later give a warning | 176 | // If the file has no cert, continue, but flag that we found at least one so we can later give a warning |
| 177 | if (0x80092009 == HResult) // CRYPT_E_NO_MATCH | 177 | if (0x80092009 == HResult) // CRYPT_E_NO_MATCH |
| @@ -197,26 +197,26 @@ namespace WixToolset.Core.WindowsInstaller.Inscribe | |||
| 197 | if (!certificates.ContainsKey(cert2.Thumbprint)) | 197 | if (!certificates.ContainsKey(cert2.Thumbprint)) |
| 198 | { | 198 | { |
| 199 | // generate a stable identifier | 199 | // generate a stable identifier |
| 200 | string certificateGeneratedId = Common.GenerateIdentifier("cer", cert2.Thumbprint); | 200 | var certificateGeneratedId = Common.GenerateIdentifier("cer", cert2.Thumbprint); |
| 201 | 201 | ||
| 202 | // Add it to our "add to MsiDigitalCertificate" table dictionary | 202 | // Add it to our "add to MsiDigitalCertificate" table dictionary |
| 203 | Row digitalCertificateRow = digitalCertificateTable.CreateRow(null); | 203 | var digitalCertificateRow = digitalCertificateTable.CreateRow(null); |
| 204 | digitalCertificateRow[0] = certificateGeneratedId; | 204 | digitalCertificateRow[0] = certificateGeneratedId; |
| 205 | 205 | ||
| 206 | // Export to a file, because the MSI API's require us to provide a file path on disk | 206 | // Export to a file, because the MSI API's require us to provide a file path on disk |
| 207 | string certPath = Path.Combine(this.Context.IntermediateFolder, "MsiDigitalCertificate"); | 207 | var certPath = Path.Combine(this.Context.IntermediateFolder, "MsiDigitalCertificate"); |
| 208 | Directory.CreateDirectory(certPath); | 208 | Directory.CreateDirectory(certPath); |
| 209 | certPath = Path.Combine(certPath, string.Concat(cert2.Thumbprint, ".cer")); | 209 | certPath = Path.Combine(certPath, String.Concat(cert2.Thumbprint, ".cer")); |
| 210 | File.Delete(certPath); | 210 | File.Delete(certPath); |
| 211 | 211 | ||
| 212 | using (BinaryWriter writer = new BinaryWriter(File.Open(certPath, FileMode.Create))) | 212 | using (var writer = new BinaryWriter(File.Open(certPath, FileMode.Create))) |
| 213 | { | 213 | { |
| 214 | writer.Write(cert2.RawData); | 214 | writer.Write(cert2.RawData); |
| 215 | writer.Close(); | 215 | writer.Close(); |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | // Now set the file path on disk where this binary stream will be picked up at import time | 218 | // Now set the file path on disk where this binary stream will be picked up at import time |
| 219 | digitalCertificateRow[1] = string.Concat(cert2.Thumbprint, ".cer"); | 219 | digitalCertificateRow[1] = String.Concat(cert2.Thumbprint, ".cer"); |
| 220 | 220 | ||
| 221 | certificates.Add(cert2.Thumbprint, certificateGeneratedId); | 221 | certificates.Add(cert2.Thumbprint, certificateGeneratedId); |
| 222 | } | 222 | } |
