Skip to content
Permalink
Browse files

Toggle secure/dev signing key at build time

  • Loading branch information...
snikolayev committed May 2, 2017
1 parent 87b3639 commit d902996788264da466377e1a07575de75addc473
@@ -0,0 +1 @@
0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9
BIN +596 Bytes SigningKey.snk
Binary file not shown.
@@ -41,13 +41,35 @@ task Clean -depends Init {
Delete-Directory $binaries_dir
}

task SetVersion {
Write-Host Build Version: $version
task PatchFiles {
Update-Version $version

$signingKey = "$base_dir\SigningKey.snk"
$secureKey = "$base_dir\..\SecureSigningKey.snk"
$secureHash = "$base_dir\..\SecureSigningKey.sha1"

if ((Test-Path $secureKey) -and (Test-Path $secureHash)) {
Write-Host "Using secure signing key." -ForegroundColor Magenta
$publicKey = Get-Content $secureHash
$publicKey = $publicKey.Trim()
Update-InternalsVisible $src_dir $publicKey
Copy-Item $secureKey -Destination $signingKey -Force
} else {
Write-Host "Secure signing key does not exist. Using development key." -ForegroundColor Yellow
}
}

task ResetVersion {
task ResetPatch {
Reset-Version

$signingKey = "$base_dir\SigningKey.snk"
$devKey = "$base_dir\DevSigningKey.snk"
$devHash = "$base_dir\DevSigningKey.sha1"

$publicKey = Get-Content $devHash
$publicKey = $publicKey.Trim()
Update-InternalsVisible $src_dir $publicKey
Copy-Item $devKey -Destination $signingKey -Force
}

task RestoreDependencies -precondition { return $component.ContainsKey('restore') } {
@@ -59,7 +81,7 @@ task RestoreDependencies -precondition { return $component.ContainsKey('restore'
}
}

task Compile -depends Init, Clean, SetVersion, RestoreDependencies -precondition { return $component.ContainsKey('build') } {
task Compile -depends Init, Clean, PatchFiles, RestoreDependencies -precondition { return $component.ContainsKey('build') } {
Create-Directory $build_dir

$solution_file = "$src_dir\$($component.name).sln"
@@ -93,7 +115,7 @@ task Test -depends Compile -precondition { return $component.ContainsKey('test')
}
}

task Build -depends Compile, Test, ResetVersion -precondition { return $component.ContainsKey('build') } {
task Build -depends Compile, Test, ResetPatch -precondition { return $component.ContainsKey('build') } {
if (-not $component.ContainsKey('bin')) {
return
}
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using NRules.Debugger.Visualizer;
@@ -11,4 +11,4 @@
typeof(SessionVisualizer),
typeof(SessionObjectSource),
Target = typeof (NRules.Session),
Description = "NRules Session Visualizer")]
Description = "NRules Session Visualizer")]
@@ -6,7 +6,7 @@
<TargetFramework>net45</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\DevSigningKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\..\..\..\SigningKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
@@ -1,6 +1,6 @@
using System.Reflection;
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("NRules.Integration.Autofac")]
[assembly: AssemblyDescription("Autofac integration for NRules")]
[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
@@ -6,7 +6,7 @@
<TargetFrameworks>net45;netstandard1.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\DevSigningKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\..\..\SigningKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -10,4 +10,4 @@
[assembly: CLSCompliant(true)]
[assembly: AllowPartiallyTrustedCallers]

[assembly: InternalsVisibleTo("NRules.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9")]
[assembly: InternalsVisibleTo("NRules.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9")]
@@ -6,7 +6,7 @@
<TargetFrameworks>net45;netstandard1.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\DevSigningKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\..\..\SigningKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -10,4 +10,4 @@
[assembly: CLSCompliant(true)]
[assembly: AllowPartiallyTrustedCallers]

[assembly: InternalsVisibleTo("NRules.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9")]
[assembly: InternalsVisibleTo("NRules.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9")]
@@ -6,7 +6,7 @@
<TargetFrameworks>net45;netstandard1.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\DevSigningKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\..\..\SigningKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
@@ -1,4 +1,4 @@
using System;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -12,4 +12,4 @@

[assembly: InternalsVisibleTo("NRules.Tests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9")]
[assembly: InternalsVisibleTo("NRules.IntegrationTests,PublicKey=0024000004800000940000000602000000240000525341310004000001000100f707beb2a866b43617af35c82a8f2f6e5b594ecdc9c27921ede22c5ed35fe8bffae26ab16e8d8ba5f02f091f189cbe3033a2b8f6ee02eb8a76662050179ebe9f789b21327aff7f4a01f6c57e361baf8bf72b2938cfd96662368076e6c45436660fcdd6bdf2b979450502fc6719ec51e63c8a8fd9dd74221c80d2fa6f6a9e8dd9")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2,PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
@@ -5,7 +5,7 @@
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\DevSigningKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\..\..\..\SigningKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
@@ -1,3 +1,3 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
@@ -5,7 +5,7 @@
<NoWarn>$(NoWarn);CS1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\DevSigningKey.snk</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>..\..\..\..\SigningKey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup>
@@ -1,3 +1,3 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

[assembly: ComVisible(false)]
[assembly: ComVisible(false)]
@@ -20,6 +20,25 @@ function Get-RegistryValue($key, $value) {
(Get-ItemProperty $key $value -ErrorAction SilentlyContinue).$value
}

function Update-InternalsVisible([string] $path, [string] $publicKey, [string] $assemblyInfoFileName = "AssemblyInfo.cs") {
Write-Host Patching AssemblyInfo files with public key

$internalsVisibleToPattern = '\[assembly\:\s*InternalsVisibleTo\(\"(NRules.+?),PublicKey=.*?\"\)\]'
$internalsVisibleTo = '[assembly: InternalsVisibleTo("$1,PublicKey=' + $publicKey + '")]';

Get-ChildItem -Path $path -Recurse -Filter $assemblyInfoFileName | % {
$filename = $_.fullname

$tmp = ($filename + ".tmp")
Delete-File $tmp

(Get-Content $filename) |
% {$_ -replace $internalsVisibleToPattern, $internalsVisibleTo } |
out-file $tmp -Encoding ASCII
Move-Item $tmp $filename -Force
}
}

function Update-Properties([string] $version, [string] $propsFileName = "Common.props") {
if ($version -notmatch "[0-9]+(\.([0-9]+|\*)){1,3}") {
Write-Error "Version number incorrect format: $version"
@@ -29,15 +48,15 @@ function Update-Properties([string] $version, [string] $propsFileName = "Common.
$versionPrefixPattern = '<VersionPrefix>[0-9]+(\.([0-9]+|\*)){1,3}<\/VersionPrefix>'
$versionPrefix = '<VersionPrefix>' + $version + '</VersionPrefix>';

Get-ChildItem -r -filter $propsFileName | % {
Get-ChildItem -Recurse -Filter $propsFileName | % {
$filename = $_.fullname

$tmp = ($filename + ".tmp")
Delete-File $tmp

(Get-Content $filename) |
% {$_ -replace $versionPrefixPattern, $versionPrefix } |
out-file $tmp -encoding ASCII
out-file $tmp -Encoding ASCII
Move-Item $tmp $filename -Force
}
}
@@ -55,7 +74,7 @@ function Update-AssemblyInfoFiles([string] $version, [string] $assemblyInfoFileN
$assemblyInfoVersionPattern = 'AssemblyInformationalVersionAttribute\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$assemblyInfoVersion = 'AssemblyInformationalVersionAttribute("' + $version + '")';

Get-ChildItem -r -filter $assemblyInfoFileName | % {
Get-ChildItem -Recurse -Filter $assemblyInfoFileName | % {
$filename = $_.fullname

$tmp = ($filename + ".tmp")
@@ -65,7 +84,7 @@ function Update-AssemblyInfoFiles([string] $version, [string] $assemblyInfoFileN
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $assemblyFileVersionPattern, $assemblyFileVersion } |
% {$_ -replace $assemblyInfoVersionPattern, $assemblyInfoVersion } |
out-file $tmp -encoding ASCII
out-file $tmp -Encoding ASCII
Move-Item $tmp $filename -Force
}
}

0 comments on commit d902996

Please sign in to comment.
You can’t perform that action at this time.