Removed Portable provider from CSharp IVT tests

Big chunk of usage removed with this change. Lots to go though.
上级 27be7c41
...@@ -137,9 +137,10 @@ internal sealed partial class SourceAssemblySymbol : MetadataOrSourceAssemblySym ...@@ -137,9 +137,10 @@ internal sealed partial class SourceAssemblySymbol : MetadataOrSourceAssemblySym
if (!compilation.Options.CryptoPublicKey.IsEmpty) if (!compilation.Options.CryptoPublicKey.IsEmpty)
{ {
// TODO: this is suspicious. When it's set here it's never re-computed hence it will never get the private
// key. This appears to be what is used for emit though. Need to follow up on this.
// Private key is not necessary for assembly identity, only when emitting. For this reason, the private key can remain null. // Private key is not necessary for assembly identity, only when emitting. For this reason, the private key can remain null.
RSAParameters? privateKey = null; _lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey: null, hasCounterSignature: false, MessageProvider.Instance);
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey, MessageProvider.Instance);
} }
} }
...@@ -503,7 +504,8 @@ private StrongNameKeys ComputeStrongNameKeys() ...@@ -503,7 +504,8 @@ private StrongNameKeys ComputeStrongNameKeys()
} }
} }
return StrongNameKeys.Create(DeclaringCompilation.Options.StrongNameProvider, keyFile, keyContainer, MessageProvider.Instance); var hasCounterSignature = !string.IsNullOrEmpty(this.SignatureKey);
return StrongNameKeys.Create(DeclaringCompilation.Options.StrongNameProvider, keyFile, keyContainer, hasCounterSignature, MessageProvider.Instance);
} }
// A collection of assemblies to which we were granted internals access by only checking matches for assembly name // A collection of assemblies to which we were granted internals access by only checking matches for assembly name
......
...@@ -41,8 +41,8 @@ internal override Stream CreateInputStream() ...@@ -41,8 +41,8 @@ internal override Stream CreateInputStream()
throw ThrownException; throw ThrownException;
} }
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) => internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasSignatureKey, CommonMessageProvider messageProvider) =>
_underlyingProvider.CreateKeys(keyFilePath, keyContainerName, messageProvider); _underlyingProvider.CreateKeys(keyFilePath, keyContainerName, hasSignatureKey, messageProvider);
internal override void SignStream(StrongNameKeys keys, Stream inputStream, Stream outputStream) => internal override void SignStream(StrongNameKeys keys, Stream inputStream, Stream outputStream) =>
_underlyingProvider.SignStream(keys, inputStream, outputStream); _underlyingProvider.SignStream(keys, inputStream, outputStream);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
...@@ -20,6 +21,28 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests ...@@ -20,6 +21,28 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{ {
public partial class InternalsVisibleToAndStrongNameTests : CSharpTestBase public partial class InternalsVisibleToAndStrongNameTests : CSharpTestBase
{ {
public static IEnumerable<object[]> AllProviderParseOptions
{
get
{
if (ExecutionConditionUtil.IsWindows)
{
return new[]
{
new object[] { TestOptions.Regular },
new object[] { TestOptions.RegularWithLegacyStrongName }
};
}
return SpecializedCollections.SingletonEnumerable(new object[] { TestOptions.Regular });
}
}
public static readonly CSharpCompilationOptions SigningReleaseDll = TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider);
public static readonly CSharpCompilationOptions SigningReleaseExe = TestOptions.ReleaseExe.WithStrongNameProvider(s_defaultDesktopProvider);
public static readonly CSharpCompilationOptions SigningReleaseModule = TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultDesktopProvider);
public static readonly CSharpCompilationOptions SigningDebugDll = TestOptions.DebugDll.WithStrongNameProvider(s_defaultDesktopProvider);
#region Helpers #region Helpers
public InternalsVisibleToAndStrongNameTests() public InternalsVisibleToAndStrongNameTests()
...@@ -74,7 +97,7 @@ public void PubKeyFromKeyFileAttribute() ...@@ -74,7 +97,7 @@ public void PubKeyFromKeyFileAttribute()
var x = s_keyPairFile; var x = s_keyPairFile;
string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}"); string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}");
var other = CreateCompilation(s, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseDll);
other.VerifyDiagnostics(); other.VerifyDiagnostics();
Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey));
...@@ -158,7 +181,7 @@ public void SigningNotAvailable001() ...@@ -158,7 +181,7 @@ public void SigningNotAvailable001()
string keyFileName = Path.GetFileName(s_keyPairFile); string keyFileName = Path.GetFileName(s_keyPairFile);
string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""..\", keyFileName, @""")] public class C {}"); string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""..\", keyFileName, @""")] public class C {}");
var syntaxTree = Parse(s, @"IVTAndStrongNameTests\AnotherTempDir\temp.cs"); var syntaxTree = Parse(s, @"IVTAndStrongNameTests\AnotherTempDir\temp.cs", TestOptions.RegularWithLegacyStrongName);
var options = TestOptions.ReleaseDll var options = TestOptions.ReleaseDll
.WithStrongNameProvider(GetProviderWithPath(PathUtilities.CombineAbsoluteAndRelativePaths(keyFileDir, @"TempSubDir\"))); .WithStrongNameProvider(GetProviderWithPath(PathUtilities.CombineAbsoluteAndRelativePaths(keyFileDir, @"TempSubDir\")));
...@@ -185,7 +208,7 @@ public void PubKeyFromKeyContainerAttribute() ...@@ -185,7 +208,7 @@ public void PubKeyFromKeyContainerAttribute()
var x = s_keyPairFile; var x = s_keyPairFile;
string s = @"[assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")] public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseDll);
other.VerifyDiagnostics(); other.VerifyDiagnostics();
Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey));
...@@ -210,7 +233,7 @@ public void PubKeyFromKeyContainerAttribute() ...@@ -210,7 +233,7 @@ public void PubKeyFromKeyContainerAttribute()
public void PubKeyFromKeyFileOptions() public void PubKeyFromKeyFileOptions()
{ {
string s = "public class C {}"; string s = "public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
other.VerifyDiagnostics(); other.VerifyDiagnostics();
Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey));
...@@ -226,7 +249,7 @@ public void PubKeyFromKeyFileOptions_ReferenceResolver() ...@@ -226,7 +249,7 @@ public void PubKeyFromKeyFileOptions_ReferenceResolver()
var syntaxTree = Parse(s, @"IVTAndStrongNameTests\AnotherTempDir\temp.cs"); var syntaxTree = Parse(s, @"IVTAndStrongNameTests\AnotherTempDir\temp.cs");
// verify failure with default resolver // verify failure with default resolver
var comp = CreateCompilation(s, options: TestOptions.ReleaseDll.WithCryptoKeyFile(keyFileName).WithStrongNameProvider(s_defaultDesktopProvider)); var comp = CreateCompilation(s, options: SigningReleaseDll.WithCryptoKeyFile(keyFileName));
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
// error CS7027: Error extracting public key from file 'KeyPairFile.snk' -- File not found. // error CS7027: Error extracting public key from file 'KeyPairFile.snk' -- File not found.
...@@ -250,7 +273,7 @@ public void PubKeyFromKeyFileOptionsJustPublicKey() ...@@ -250,7 +273,7 @@ public void PubKeyFromKeyFileOptionsJustPublicKey()
{ {
string s = "public class C {}"; string s = "public class C {}";
var other = CreateCompilation(s, var other = CreateCompilation(s,
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true));
other.VerifyDiagnostics(); other.VerifyDiagnostics();
Assert.True(ByteSequenceComparer.Equals(TestResources.General.snPublicKey.AsImmutableOrNull(), other.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(TestResources.General.snPublicKey.AsImmutableOrNull(), other.Assembly.Identity.PublicKey));
} }
...@@ -266,7 +289,7 @@ public void PubKeyFromKeyFileOptionsJustPublicKey_ReferenceResolver() ...@@ -266,7 +289,7 @@ public void PubKeyFromKeyFileOptionsJustPublicKey_ReferenceResolver()
// verify failure with default resolver // verify failure with default resolver
var comp = CreateCompilation(s, var comp = CreateCompilation(s,
options: TestOptions.ReleaseDll.WithCryptoKeyFile(publicKeyFileName).WithDelaySign(true).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(publicKeyFileName).WithDelaySign(true));
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
// error CS7027: Error extracting public key from file 'PublicKeyFile.snk' -- File not found. // error CS7027: Error extracting public key from file 'PublicKeyFile.snk' -- File not found.
...@@ -291,8 +314,7 @@ public void PubKeyFromKeyFileOptionsJustPublicKey_ReferenceResolver() ...@@ -291,8 +314,7 @@ public void PubKeyFromKeyFileOptionsJustPublicKey_ReferenceResolver()
public void PubKeyFileNotFoundOptions() public void PubKeyFileNotFoundOptions()
{ {
string s = "public class C {}"; string s = "public class C {}";
var other = CreateCompilation(s, var other = CreateCompilation(s, options: SigningReleaseDll.WithCryptoKeyFile("goo"));
options: TestOptions.ReleaseDll.WithCryptoKeyFile("goo").WithStrongNameProvider(s_defaultDesktopProvider));
other.VerifyDiagnostics( other.VerifyDiagnostics(
Diagnostic(ErrorCode.ERR_PublicKeyFileFailure).WithArguments("goo", CodeAnalysisResources.FileNotFound)); Diagnostic(ErrorCode.ERR_PublicKeyFileFailure).WithArguments("goo", CodeAnalysisResources.FileNotFound));
...@@ -318,8 +340,7 @@ public void PubKeyFileBogusOptions() ...@@ -318,8 +340,7 @@ public void PubKeyFileBogusOptions()
public void PubKeyContainerBogusOptions() public void PubKeyContainerBogusOptions()
{ {
string s = "public class C {}"; string s = "public class C {}";
var other = CreateCompilation(s, var other = CreateCompilation(s, options: SigningReleaseDll.WithCryptoKeyContainer("goo"));
options: TestOptions.ReleaseDll.WithCryptoKeyContainer("goo").WithStrongNameProvider(s_defaultDesktopProvider));
// error CS7028: Error signing output with public key from container 'goo' -- Keyset does not exist (Exception from HRESULT: 0x80090016) // error CS7028: Error signing output with public key from container 'goo' -- Keyset does not exist (Exception from HRESULT: 0x80090016)
var err = other.GetDiagnostics().Single(); var err = other.GetDiagnostics().Single();
...@@ -337,8 +358,7 @@ public void KeyFileAttributeOptionConflict() ...@@ -337,8 +358,7 @@ public void KeyFileAttributeOptionConflict()
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyFile(""bogus"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyFile(""bogus"")] public class C {}";
var other = CreateCompilation(s, var other = CreateCompilation(s, options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider));
other.VerifyDiagnostics(Diagnostic(ErrorCode.WRN_CmdOptionConflictsSource).WithArguments("CryptoKeyFile", "System.Reflection.AssemblyKeyFileAttribute")); other.VerifyDiagnostics(Diagnostic(ErrorCode.WRN_CmdOptionConflictsSource).WithArguments("CryptoKeyFile", "System.Reflection.AssemblyKeyFileAttribute"));
Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey));
...@@ -349,8 +369,7 @@ public void KeyContainerAttributeOptionConflict() ...@@ -349,8 +369,7 @@ public void KeyContainerAttributeOptionConflict()
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyName(""bogus"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyName(""bogus"")] public class C {}";
var other = CreateCompilation(s, var other = CreateCompilation(s, options: SigningReleaseDll.WithCryptoKeyContainer("RoslynTestContainer"));
options: TestOptions.ReleaseDll.WithCryptoKeyContainer("RoslynTestContainer").WithStrongNameProvider(s_defaultDesktopProvider));
other.VerifyDiagnostics(Diagnostic(ErrorCode.WRN_CmdOptionConflictsSource).WithArguments("CryptoKeyContainer", "System.Reflection.AssemblyKeyNameAttribute")); other.VerifyDiagnostics(Diagnostic(ErrorCode.WRN_CmdOptionConflictsSource).WithArguments("CryptoKeyContainer", "System.Reflection.AssemblyKeyNameAttribute"));
Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, other.Assembly.Identity.PublicKey));
...@@ -361,7 +380,7 @@ public void KeyFileAttributeEmpty() ...@@ -361,7 +380,7 @@ public void KeyFileAttributeEmpty()
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyFile("""")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyFile("""")] public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseDll);
Assert.True(other.Assembly.Identity.PublicKey.IsEmpty); Assert.True(other.Assembly.Identity.PublicKey.IsEmpty);
other.VerifyDiagnostics(); other.VerifyDiagnostics();
} }
...@@ -371,7 +390,7 @@ public void KeyContainerEmpty() ...@@ -371,7 +390,7 @@ public void KeyContainerEmpty()
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyName("""")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyName("""")] public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseDll);
Assert.True(other.Assembly.Identity.PublicKey.IsEmpty); Assert.True(other.Assembly.Identity.PublicKey.IsEmpty);
other.VerifyDiagnostics(); other.VerifyDiagnostics();
} }
...@@ -422,14 +441,14 @@ public class C {} ...@@ -422,14 +441,14 @@ public class C {}
AssertEx.Equal(identity.PublicKey, s_publicKey); AssertEx.Equal(identity.PublicKey, s_publicKey);
Assert.Equal(CorFlags.ILOnly | CorFlags.StrongNameSigned, metadata.Module.PEReaderOpt.PEHeaders.CorHeader.Flags); Assert.Equal(CorFlags.ILOnly | CorFlags.StrongNameSigned, metadata.Module.PEReaderOpt.PEHeaders.CorHeader.Flags);
c = CreateCompilation(source, options: TestOptions.ReleaseModule.WithCryptoPublicKey(s_publicKey).WithPublicSign(true)); c = CreateCompilation(source, options: SigningReleaseModule.WithCryptoPublicKey(s_publicKey).WithPublicSign(true));
c.VerifyDiagnostics( c.VerifyDiagnostics(
// error CS8201: Public signing is not supported for netmodules. // error CS8201: Public signing is not supported for netmodules.
Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1) Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1)
); );
c = CreateCompilation(source, options: TestOptions.ReleaseModule.WithCryptoKeyFile(s_publicKeyFile).WithPublicSign(true)); c = CreateCompilation(source, options: SigningReleaseModule.WithCryptoKeyFile(s_publicKeyFile).WithPublicSign(true));
c.VerifyDiagnostics( c.VerifyDiagnostics(
// error CS7091: Attribute 'System.Reflection.AssemblyKeyFileAttribute' given in a source file conflicts with option 'CryptoKeyFile'. // error CS7091: Attribute 'System.Reflection.AssemblyKeyFileAttribute' given in a source file conflicts with option 'CryptoKeyFile'.
...@@ -446,7 +465,7 @@ public class C {} ...@@ -446,7 +465,7 @@ public class C {}
public class C {} public class C {}
"; ";
c = CreateCompilation(source1, options: TestOptions.ReleaseModule.WithCryptoKeyFile(snk.Path).WithPublicSign(true)); c = CreateCompilation(source1, options: SigningReleaseModule.WithCryptoKeyFile(snk.Path).WithPublicSign(true));
c.VerifyDiagnostics( c.VerifyDiagnostics(
// error CS8201: Public signing is not supported for netmodules. // error CS8201: Public signing is not supported for netmodules.
Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1) Diagnostic(ErrorCode.ERR_PublicSignNetModule).WithLocation(1, 1)
...@@ -588,9 +607,8 @@ public void KeyContainerNoSNProvider_PublicSign() ...@@ -588,9 +607,8 @@ public void KeyContainerNoSNProvider_PublicSign()
public void KeyContainerDesktopProvider_PublicSign() public void KeyContainerDesktopProvider_PublicSign()
{ {
var comp = CreateCompilation("public class C {}", var comp = CreateCompilation("public class C {}",
options: TestOptions.ReleaseDll options: SigningReleaseDll
.WithCryptoKeyContainer("roslynTestContainer") .WithCryptoKeyContainer("roslynTestContainer")
.WithStrongNameProvider(s_defaultDesktopProvider)
.WithPublicSign(true)); .WithPublicSign(true));
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
...@@ -660,11 +678,10 @@ public void PublicKeyFromOptions_InvalidCompilationOptions() ...@@ -660,11 +678,10 @@ public void PublicKeyFromOptions_InvalidCompilationOptions()
{ {
string source = @"public class C {}"; string source = @"public class C {}";
var c = CreateCompilation(source, options: TestOptions.ReleaseDll. var c = CreateCompilation(source, options: SigningReleaseDll.
WithCryptoPublicKey(ImmutableArray.Create<byte>(1, 2, 3)). WithCryptoPublicKey(ImmutableArray.Create<byte>(1, 2, 3)).
WithCryptoKeyContainer("roslynTestContainer"). WithCryptoKeyContainer("roslynTestContainer").
WithCryptoKeyFile("file.snk"). WithCryptoKeyFile("file.snk"));
WithStrongNameProvider(s_defaultDesktopProvider));
c.VerifyDiagnostics( c.VerifyDiagnostics(
// error CS7102: Compilation options 'CryptoPublicKey' and 'CryptoKeyFile' can't both be specified at the same time. // error CS7102: Compilation options 'CryptoPublicKey' and 'CryptoKeyFile' can't both be specified at the same time.
...@@ -685,7 +702,7 @@ public void IVTBasicCompilation() ...@@ -685,7 +702,7 @@ public void IVTBasicCompilation()
string s = @"[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""WantsIVTAccess"")] string s = @"[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""WantsIVTAccess"")]
public class C { internal void Goo() {} }"; public class C { internal void Goo() {} }";
var other = CreateCompilation(s, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "Paul"); var other = CreateCompilation(s, options: SigningReleaseDll, assemblyName: "Paul");
var c = CreateCompilation( var c = CreateCompilation(
@"public class A @"public class A
...@@ -700,7 +717,7 @@ protected B(C o) ...@@ -700,7 +717,7 @@ protected B(C o)
}", }",
new[] { new CSharpCompilationReference(other) }, new[] { new CSharpCompilationReference(other) },
assemblyName: "WantsIVTAccessButCantHave", assemblyName: "WantsIVTAccessButCantHave",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
//compilation should not succeed, and internals should not be imported. //compilation should not succeed, and internals should not be imported.
c.VerifyDiagnostics( c.VerifyDiagnostics(
...@@ -723,7 +740,7 @@ protected B(C o) ...@@ -723,7 +740,7 @@ protected B(C o)
}", }",
new[] { new CSharpCompilationReference(other) }, new[] { new CSharpCompilationReference(other) },
assemblyName: "WantsIVTAccess", assemblyName: "WantsIVTAccess",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
Assert.Empty(c2.GetDiagnostics()); Assert.Empty(c2.GetDiagnostics());
} }
...@@ -734,7 +751,7 @@ public void IVTBasicMetadata() ...@@ -734,7 +751,7 @@ public void IVTBasicMetadata()
string s = @"[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""WantsIVTAccess"")] string s = @"[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""WantsIVTAccess"")]
public class C { internal void Goo() {} }"; public class C { internal void Goo() {} }";
var otherStream = CreateCompilation(s, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)).EmitToStream(); var otherStream = CreateCompilation(s, options: SigningReleaseDll).EmitToStream();
var c = CreateCompilation( var c = CreateCompilation(
@"public class A @"public class A
...@@ -749,7 +766,7 @@ protected B(C o) ...@@ -749,7 +766,7 @@ protected B(C o)
}", }",
references: new[] { AssemblyMetadata.CreateFromStream(otherStream, leaveOpen: true).GetReference() }, references: new[] { AssemblyMetadata.CreateFromStream(otherStream, leaveOpen: true).GetReference() },
assemblyName: "WantsIVTAccessButCantHave", assemblyName: "WantsIVTAccessButCantHave",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
//compilation should not succeed, and internals should not be imported. //compilation should not succeed, and internals should not be imported.
c.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "Goo").WithArguments("C", "Goo")); c.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_NoSuchMemberOrExtension, "Goo").WithArguments("C", "Goo"));
...@@ -769,7 +786,7 @@ protected B(C o) ...@@ -769,7 +786,7 @@ protected B(C o)
}", }",
new[] { MetadataReference.CreateFromStream(otherStream) }, new[] { MetadataReference.CreateFromStream(otherStream) },
assemblyName: "WantsIVTAccess", assemblyName: "WantsIVTAccess",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
Assert.Empty(c2.GetDiagnostics()); Assert.Empty(c2.GetDiagnostics());
} }
...@@ -781,7 +798,7 @@ public void IVTSigned() ...@@ -781,7 +798,7 @@ public void IVTSigned()
public class C { internal void Goo() {} }"; public class C { internal void Goo() {} }";
var other = CreateCompilation(s, var other = CreateCompilation(s,
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile),
assemblyName: "Paul"); assemblyName: "Paul");
other.VerifyDiagnostics(); other.VerifyDiagnostics();
...@@ -798,7 +815,7 @@ protected B(C o) ...@@ -798,7 +815,7 @@ protected B(C o)
} }
}", }",
new MetadataReference[] { new CSharpCompilationReference(other) }, new MetadataReference[] { new CSharpCompilationReference(other) },
TestOptions.ReleaseDll.WithCryptoKeyContainer("roslynTestContainer").WithStrongNameProvider(s_defaultDesktopProvider), SigningReleaseDll.WithCryptoKeyContainer("roslynTestContainer"),
assemblyName: "John"); assemblyName: "John");
Assert.Empty(requestor.GetDiagnostics()); Assert.Empty(requestor.GetDiagnostics());
...@@ -810,7 +827,7 @@ public void IVTNotBothSigned_CStoCS() ...@@ -810,7 +827,7 @@ public void IVTNotBothSigned_CStoCS()
string s = @"[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""John, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b986f6b5ea5717d35c72d38561f413e267029efa9b5f107b9331d83df657381325b3a67b75812f63a9436ceccb49494de8f574f8e639d4d26c0fcf8b0e9a1a196b80b6f6ed053628d10d027e032df2ed1d60835e5f47d32c9ef6da10d0366a319573362c821b5f8fa5abc5bb22241de6f666a85d82d6ba8c3090d01636bd2bb"")] string s = @"[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(""John, PublicKey=00240000048000009400000006020000002400005253413100040000010001002b986f6b5ea5717d35c72d38561f413e267029efa9b5f107b9331d83df657381325b3a67b75812f63a9436ceccb49494de8f574f8e639d4d26c0fcf8b0e9a1a196b80b6f6ed053628d10d027e032df2ed1d60835e5f47d32c9ef6da10d0366a319573362c821b5f8fa5abc5bb22241de6f666a85d82d6ba8c3090d01636bd2bb"")]
public class C { internal void Goo() {} }"; public class C { internal void Goo() {} }";
var other = CreateCompilation(s, assemblyName: "Paul", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, assemblyName: "Paul", options: SigningReleaseDll);
other.VerifyDiagnostics(); other.VerifyDiagnostics();
var requestor = CreateCompilation( var requestor = CreateCompilation(
...@@ -826,7 +843,7 @@ protected B(C o) ...@@ -826,7 +843,7 @@ protected B(C o)
}", }",
references: new[] { new CSharpCompilationReference(other) }, references: new[] { new CSharpCompilationReference(other) },
assemblyName: "John", assemblyName: "John",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
// We allow John to access Paul's internal Goo even though strong-named John should not be referencing weak-named Paul. // We allow John to access Paul's internal Goo even though strong-named John should not be referencing weak-named Paul.
// Paul has, after all, specifically granted access to John. // Paul has, after all, specifically granted access to John.
...@@ -865,7 +882,7 @@ static void Main () ...@@ -865,7 +882,7 @@ static void Main ()
PublicClass.PrivateProtectedMethod(); PublicClass.PrivateProtectedMethod();
} }
}"; }";
var other = CreateCompilation(cs0281, references: new[] { friendClass.EmitToImageReference() }, assemblyName: "cs0281", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(cs0281, references: new[] { friendClass.EmitToImageReference() }, assemblyName: "cs0281", options: SigningReleaseDll);
other.VerifyDiagnostics( other.VerifyDiagnostics(
// (7,15): error CS0281: Friend access was granted by 'Paul, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', but the public key of the output assembly ('') does not match that specified by the InternalsVisibleTo attribute in the granting assembly. // (7,15): error CS0281: Friend access was granted by 'Paul, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', but the public key of the output assembly ('') does not match that specified by the InternalsVisibleTo attribute in the granting assembly.
// PublicClass.InternalMethod(); // PublicClass.InternalMethod();
...@@ -908,7 +925,7 @@ static void Main () ...@@ -908,7 +925,7 @@ static void Main ()
FriendClass.MyMethod (); FriendClass.MyMethod ();
} }
}"; }";
var other = CreateCompilation(cs0281, references: new[] { friendClass.EmitToImageReference() }, assemblyName: "cs0281", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(cs0281, references: new[] { friendClass.EmitToImageReference() }, assemblyName: "cs0281", options: SigningReleaseDll);
// (7, 3): error CS0281: Friend access was granted by 'Paul, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', but the public key of the output assembly ('') // (7, 3): error CS0281: Friend access was granted by 'Paul, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null', but the public key of the output assembly ('')
// does not match that specified by the InternalsVisibleTo attribute in the granting assembly. // does not match that specified by the InternalsVisibleTo attribute in the granting assembly.
...@@ -947,7 +964,7 @@ protected B(C o) ...@@ -947,7 +964,7 @@ protected B(C o)
}", }",
references: new[] { MetadataReference.CreateFromImage(other.EmitToArray()) }, references: new[] { MetadataReference.CreateFromImage(other.EmitToArray()) },
assemblyName: "John", assemblyName: "John",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
// We allow John to access Paul's internal Goo even though strong-named John should not be referencing weak-named Paul. // We allow John to access Paul's internal Goo even though strong-named John should not be referencing weak-named Paul.
// Paul has, after all, specifically granted access to John. // Paul has, after all, specifically granted access to John.
...@@ -965,7 +982,7 @@ internal class CAttribute : System.Attribute { public CAttribute() {} }"; ...@@ -965,7 +982,7 @@ internal class CAttribute : System.Attribute { public CAttribute() {} }";
var other = CreateCompilation(s, var other = CreateCompilation(s,
assemblyName: "Paul", assemblyName: "Paul",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
other.VerifyDiagnostics(); other.VerifyDiagnostics();
...@@ -978,7 +995,7 @@ public class A ...@@ -978,7 +995,7 @@ public class A
}", }",
new[] { new CSharpCompilationReference(other) }, new[] { new CSharpCompilationReference(other) },
assemblyName: "John", assemblyName: "John",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
Assert.True(ByteSequenceComparer.Equals(s_publicKey, requestor.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, requestor.Assembly.Identity.PublicKey));
Assert.Empty(requestor.GetDiagnostics()); Assert.Empty(requestor.GetDiagnostics());
...@@ -992,7 +1009,7 @@ internal class CAttribute : System.Attribute { public CAttribute() {} }"; ...@@ -992,7 +1009,7 @@ internal class CAttribute : System.Attribute { public CAttribute() {} }";
var other = CreateCompilation(s, var other = CreateCompilation(s,
assemblyName: "Paul", assemblyName: "Paul",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); //not signed. cryptoKeyFile: KeyPairFile, options: SigningReleaseDll); //not signed. cryptoKeyFile: KeyPairFile,
other.VerifyDiagnostics(); other.VerifyDiagnostics();
...@@ -1005,7 +1022,7 @@ public class A ...@@ -1005,7 +1022,7 @@ public class A
}", }",
new[] { new CSharpCompilationReference(other) }, new[] { new CSharpCompilationReference(other) },
assemblyName: "John", assemblyName: "John",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
Assert.True(ByteSequenceComparer.Equals(s_publicKey, requestor.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, requestor.Assembly.Identity.PublicKey));
requestor.VerifyDiagnostics( requestor.VerifyDiagnostics(
...@@ -1020,7 +1037,7 @@ public void IVTDeferredFailKeyMismatch() ...@@ -1020,7 +1037,7 @@ public void IVTDeferredFailKeyMismatch()
internal class CAttribute : System.Attribute { public CAttribute() {} }"; internal class CAttribute : System.Attribute { public CAttribute() {} }";
var other = CreateCompilation(s, var other = CreateCompilation(s,
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile),
assemblyName: "Paul"); assemblyName: "Paul");
other.VerifyDiagnostics(); other.VerifyDiagnostics();
...@@ -1034,7 +1051,7 @@ public class A ...@@ -1034,7 +1051,7 @@ public class A
}", }",
new MetadataReference[] { new CSharpCompilationReference(other) }, new MetadataReference[] { new CSharpCompilationReference(other) },
assemblyName: "John", assemblyName: "John",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
Assert.True(ByteSequenceComparer.Equals(s_publicKey, requestor.Assembly.Identity.PublicKey)); Assert.True(ByteSequenceComparer.Equals(s_publicKey, requestor.Assembly.Identity.PublicKey));
requestor.VerifyDiagnostics( requestor.VerifyDiagnostics(
...@@ -1055,7 +1072,7 @@ internal class CAttribute : System.Attribute { public CAttribute() {} }"; ...@@ -1055,7 +1072,7 @@ internal class CAttribute : System.Attribute { public CAttribute() {} }";
var other = CreateCompilation(s, var other = CreateCompilation(s,
assemblyName: "Paul", assemblyName: "Paul",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
other.VerifyDiagnostics(); other.VerifyDiagnostics();
...@@ -1067,7 +1084,7 @@ public class A ...@@ -1067,7 +1084,7 @@ public class A
{ {
}", }",
new MetadataReference[] { new CSharpCompilationReference(other) }, new MetadataReference[] { new CSharpCompilationReference(other) },
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll,
assemblyName: "John"); assemblyName: "John");
Assert.True(((IAssemblySymbol)other.Assembly).GivesAccessTo(requestor.Assembly)); Assert.True(((IAssemblySymbol)other.Assembly).GivesAccessTo(requestor.Assembly));
...@@ -1082,7 +1099,7 @@ public void IVTDeferredFailKeyMismatchIAssembly() ...@@ -1082,7 +1099,7 @@ public void IVTDeferredFailKeyMismatchIAssembly()
internal class CAttribute : System.Attribute { public CAttribute() {} }"; internal class CAttribute : System.Attribute { public CAttribute() {} }";
var other = CreateCompilation(s, var other = CreateCompilation(s,
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile),
assemblyName: "Paul"); assemblyName: "Paul");
other.VerifyDiagnostics(); other.VerifyDiagnostics();
...@@ -1096,7 +1113,7 @@ public class A ...@@ -1096,7 +1113,7 @@ public class A
{ {
}", }",
new MetadataReference[] { new CSharpCompilationReference(other) }, new MetadataReference[] { new CSharpCompilationReference(other) },
TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), SigningReleaseDll,
assemblyName: "John"); assemblyName: "John");
Assert.False(((IAssemblySymbol)other.Assembly).GivesAccessTo(requestor.Assembly)); Assert.False(((IAssemblySymbol)other.Assembly).GivesAccessTo(requestor.Assembly));
...@@ -1119,7 +1136,7 @@ namespace ClassLibrary1 { internal class Class1 { } } "; ...@@ -1119,7 +1136,7 @@ namespace ClassLibrary1 { internal class Class1 { } } ";
var giver = CreateCompilation(s, var giver = CreateCompilation(s,
assemblyName: "Paul", assemblyName: "Paul",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(SigningTestHelpers.KeyPairFile2).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(SigningTestHelpers.KeyPairFile2));
giver.VerifyDiagnostics(); giver.VerifyDiagnostics();
...@@ -1135,7 +1152,7 @@ public void Goo(ClassLibrary1.Class1 a) ...@@ -1135,7 +1152,7 @@ public void Goo(ClassLibrary1.Class1 a)
} }
}", }",
new MetadataReference[] { new CSharpCompilationReference(giver) }, new MetadataReference[] { new CSharpCompilationReference(giver) },
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile),
assemblyName: "John"); assemblyName: "John");
Assert.True(((IAssemblySymbol)giver.Assembly).GivesAccessTo(requestor.Assembly)); Assert.True(((IAssemblySymbol)giver.Assembly).GivesAccessTo(requestor.Assembly));
...@@ -1156,7 +1173,7 @@ public class C ...@@ -1156,7 +1173,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
} }
", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); ", options: SigningReleaseDll);
other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_FriendAssemblyBadArgs, @"InternalsVisibleTo(""WantsIVTAccess, Culture=neutral"")").WithArguments("WantsIVTAccess, Culture=neutral")); other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_FriendAssemblyBadArgs, @"InternalsVisibleTo(""WantsIVTAccess, Culture=neutral"")").WithArguments("WantsIVTAccess, Culture=neutral"));
} }
...@@ -1172,7 +1189,7 @@ public class C ...@@ -1172,7 +1189,7 @@ public class C
{ {
static void Main() {} static void Main() {}
} }
", options: TestOptions.ReleaseExe.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); ", options: SigningReleaseExe.WithCryptoKeyFile(s_keyPairFile));
other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_FriendAssemblySNReq, @"InternalsVisibleTo(""WantsIVTAccess"")").WithArguments("WantsIVTAccess")); other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_FriendAssemblySNReq, @"InternalsVisibleTo(""WantsIVTAccess"")").WithArguments("WantsIVTAccess"));
} }
...@@ -1201,9 +1218,8 @@ public static void M() ...@@ -1201,9 +1218,8 @@ public static void M()
Console.WriteLine(""Called M""); Console.WriteLine(""Called M"");
}} }}
}}", }}",
options: TestOptions.ReleaseDll options: SigningReleaseDll
.WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile) .WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile));
.WithStrongNameProvider(s_defaultDesktopProvider));
comp.VerifyEmitDiagnostics(); comp.VerifyEmitDiagnostics();
...@@ -1223,9 +1239,8 @@ public static void Main() ...@@ -1223,9 +1239,8 @@ public static void Main()
var comp2 = CreateCompilation(src, var comp2 = CreateCompilation(src,
references: new[] { comp.ToMetadataReference() }, references: new[] { comp.ToMetadataReference() },
assemblyName: "MaxSizeComp2", assemblyName: "MaxSizeComp2",
options: TestOptions.ReleaseExe options: SigningReleaseExe
.WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile) .WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile));
.WithStrongNameProvider(s_defaultDesktopProvider));
CompileAndVerify(comp2, expectedOutput: "Called M"); CompileAndVerify(comp2, expectedOutput: "Called M");
Assert.Equal(TestResources.General.snMaxSizePublicKey, comp2.Assembly.Identity.PublicKey); Assert.Equal(TestResources.General.snMaxSizePublicKey, comp2.Assembly.Identity.PublicKey);
...@@ -1234,9 +1249,8 @@ public static void Main() ...@@ -1234,9 +1249,8 @@ public static void Main()
var comp3 = CreateCompilation(src, var comp3 = CreateCompilation(src,
references: new[] { comp.EmitToImageReference() }, references: new[] { comp.EmitToImageReference() },
assemblyName: "MaxSizeComp2", assemblyName: "MaxSizeComp2",
options: TestOptions.ReleaseExe options: SigningReleaseExe
.WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile) .WithCryptoKeyFile(SigningTestHelpers.MaxSizeKeyFile));
.WithStrongNameProvider(s_defaultDesktopProvider));
CompileAndVerify(comp3, expectedOutput: "Called M"); CompileAndVerify(comp3, expectedOutput: "Called M");
Assert.Equal(TestResources.General.snMaxSizePublicKey, comp3.Assembly.Identity.PublicKey); Assert.Equal(TestResources.General.snMaxSizePublicKey, comp3.Assembly.Identity.PublicKey);
...@@ -1252,7 +1266,7 @@ public class C ...@@ -1252,7 +1266,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -1273,7 +1287,7 @@ private static bool IsFileFullSigned(TempFile file) ...@@ -1273,7 +1287,7 @@ private static bool IsFileFullSigned(TempFile file)
} }
} }
private void ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(MemoryStream moduleContents, AttributeDescription expectedModuleAttr, bool legacyStrongName) private void ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(MemoryStream moduleContents, AttributeDescription expectedModuleAttr, CSharpParseOptions parseOptions)
{ {
//a module doesn't get signed for real. It should have either a keyfile or keycontainer attribute //a module doesn't get signed for real. It should have either a keyfile or keycontainer attribute
//parked on a typeRef named 'AssemblyAttributesGoHere.' When the module is added to an assembly, the //parked on a typeRef named 'AssemblyAttributesGoHere.' When the module is added to an assembly, the
...@@ -1299,13 +1313,12 @@ public class Z ...@@ -1299,13 +1313,12 @@ public class Z
{ {
}"; }";
StrongNameProvider provider = legacyStrongName ? s_defaultDesktopProvider : s_defaultPortableProvider;
//now that the module checks out, ensure that adding it to a compilation outputting a dll //now that the module checks out, ensure that adding it to a compilation outputting a dll
//results in a signed assembly. //results in a signed assembly.
var assemblyComp = CreateCompilation(source, var assemblyComp = CreateCompilation(source,
new[] { metadata.GetReference() }, new[] { metadata.GetReference() },
TestOptions.ReleaseDll.WithStrongNameProvider(provider)); SigningReleaseDll,
parseOptions: parseOptions);
using (var finalStrm = tempFile.Open()) using (var finalStrm = tempFile.Open())
{ {
...@@ -1319,45 +1332,30 @@ public class Z ...@@ -1319,45 +1332,30 @@ public class Z
Assert.True(IsFileFullSigned(tempFile)); Assert.True(IsFileFullSigned(tempFile));
} }
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void SignModuleKeyFileAttr() [MemberData(nameof(AllProviderParseOptions))]
{ public void SignModuleKeyFileAttr(CSharpParseOptions parseOptions)
var x = s_keyPairFile;
string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}");
var options = TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultPortableProvider);
var other = CreateCompilation(s, options: options);
var outStrm = other.EmitToStream();
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, legacyStrongName: false);
}
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")]
public void SignModuleKeyFileAttr_Legacy()
{ {
var x = s_keyPairFile; var x = s_keyPairFile;
string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}"); string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}");
var options = TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultDesktopProvider); var other = CreateCompilation(s, options: SigningReleaseModule);
var other = CreateCompilation(s, options: options);
var outStrm = other.EmitToStream(); var outStrm = other.EmitToStream();
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, legacyStrongName: true); ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, parseOptions);
} }
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void SignModuleKeyContainerAttr_Legacy() [MemberData(nameof(AllProviderParseOptions))]
public void SignModuleKeyContainerAttr(CSharpParseOptions parseOptions)
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")] public class C {}";
var options = TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultDesktopProvider); var other = CreateCompilation(s, options: SigningReleaseModule);
var other = CreateCompilation(s, options: options);
var outStrm = other.EmitToStream(); var outStrm = other.EmitToStream();
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyNameAttribute, legacyStrongName: true); ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyNameAttribute, parseOptions);
} }
[WorkItem(5665, "https://github.com/dotnet/roslyn/issues/5665")] [WorkItem(5665, "https://github.com/dotnet/roslyn/issues/5665")]
...@@ -1366,13 +1364,13 @@ public void SignModuleKeyContainerBogus() ...@@ -1366,13 +1364,13 @@ public void SignModuleKeyContainerBogus()
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyName(""bogus"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyName(""bogus"")] public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseModule);
//shouldn't have an error. The attribute's contents are checked when the module is added. //shouldn't have an error. The attribute's contents are checked when the module is added.
var reference = other.EmitToImageReference(); var reference = other.EmitToImageReference();
s = @"class D {}"; s = @"class D {}";
other = CreateCompilation(s, new[] { reference }, TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); other = CreateCompilation(s, new[] { reference }, SigningReleaseDll);
// error CS7028: Error signing output with public key from container 'bogus' -- Keyset does not exist (Exception from HRESULT: 0x80090016) // error CS7028: Error signing output with public key from container 'bogus' -- Keyset does not exist (Exception from HRESULT: 0x80090016)
var err = other.GetDiagnostics().Single(); var err = other.GetDiagnostics().Single();
...@@ -1388,41 +1386,25 @@ public void SignModuleKeyFileBogus() ...@@ -1388,41 +1386,25 @@ public void SignModuleKeyFileBogus()
{ {
string s = @"[assembly: System.Reflection.AssemblyKeyFile(""bogus"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyFile(""bogus"")] public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseModule);
//shouldn't have an error. The attribute's contents are checked when the module is added. //shouldn't have an error. The attribute's contents are checked when the module is added.
var reference = other.EmitToImageReference(); var reference = other.EmitToImageReference();
s = @"class D {}"; s = @"class D {}";
other = CreateCompilation(s, new[] { reference }, TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); other = CreateCompilation(s, new[] { reference }, SigningReleaseDll);
other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_PublicKeyFileFailure).WithArguments("bogus", CodeAnalysisResources.FileNotFound)); other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_PublicKeyFileFailure).WithArguments("bogus", CodeAnalysisResources.FileNotFound));
} }
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void AttemptToStrongNameWithOnlyPublicKey() [MemberData(nameof(AllProviderParseOptions))]
{ public void AttemptToStrongNameWithOnlyPublicKey(CSharpParseOptions parseOptions)
string s = "public class C {}";
var options = TestOptions.ReleaseDll.WithCryptoKeyFile(PublicKeyFile).WithStrongNameProvider(s_defaultPortableProvider);
var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream();
var refStrm = new MemoryStream();
var success = other.Emit(outStrm, metadataPEStream: refStrm);
Assert.False(success.Success);
// The diagnostic contains a random file path, so just check the code.
Assert.True(success.Diagnostics[0].Code == (int)ErrorCode.ERR_SignButNoPrivateKey);
}
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")]
public void AttemptToStrongNameWithOnlyPublicKey_Legacy()
{ {
string s = "public class C {}"; string s = "public class C {}";
var options = TestOptions.ReleaseDll.WithCryptoKeyFile(PublicKeyFile).WithStrongNameProvider(s_defaultDesktopProvider); var options = SigningReleaseDll.WithCryptoKeyFile(PublicKeyFile);
var other = CreateCompilation(s, options: options); var other = CreateCompilation(s, options: options, parseOptions: parseOptions);
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var refStrm = new MemoryStream(); var refStrm = new MemoryStream();
...@@ -1434,30 +1416,32 @@ public void AttemptToStrongNameWithOnlyPublicKey_Legacy() ...@@ -1434,30 +1416,32 @@ public void AttemptToStrongNameWithOnlyPublicKey_Legacy()
} }
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")] [WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void SignModuleKeyContainerCmdLine_Legacy() [MemberData(nameof(AllProviderParseOptions))]
public void SignModuleKeyContainerCmdLine(CSharpParseOptions parseOptions)
{ {
string s = "public class C {}"; string s = "public class C {}";
var options = TestOptions.ReleaseModule.WithCryptoKeyContainer("roslynTestContainer").WithStrongNameProvider(s_defaultDesktopProvider); var options = SigningReleaseModule.WithCryptoKeyContainer("roslynTestContainer");
var other = CreateCompilation(s, options: options); var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var success = other.Emit(outStrm); var success = other.Emit(outStrm);
Assert.True(success.Success); Assert.True(success.Success);
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyNameAttribute, legacyStrongName: true); ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyNameAttribute, parseOptions);
} }
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")] [WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void SignModuleKeyContainerCmdLine_1_Legacy() [MemberData(nameof(AllProviderParseOptions))]
public void SignModuleKeyContainerCmdLine_1(CSharpParseOptions parseOptions)
{ {
string s = @" string s = @"
[assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")] [assembly: System.Reflection.AssemblyKeyName(""roslynTestContainer"")]
public class C {}"; public class C {}";
var options = TestOptions.ReleaseModule.WithCryptoKeyContainer("roslynTestContainer").WithStrongNameProvider(s_defaultDesktopProvider); var options = SigningReleaseModule.WithCryptoKeyContainer("roslynTestContainer");
var other = CreateCompilation(s, options: options); var other = CreateCompilation(s, options: options);
...@@ -1465,7 +1449,7 @@ public class C {}"; ...@@ -1465,7 +1449,7 @@ public class C {}";
var success = other.Emit(outStrm); var success = other.Emit(outStrm);
Assert.True(success.Success); Assert.True(success.Success);
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyNameAttribute, legacyStrongName: true); ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyNameAttribute, parseOptions);
} }
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")] [WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
...@@ -1476,7 +1460,7 @@ public void SignModuleKeyContainerCmdLine_2() ...@@ -1476,7 +1460,7 @@ public void SignModuleKeyContainerCmdLine_2()
[assembly: System.Reflection.AssemblyKeyName(""bogus"")] [assembly: System.Reflection.AssemblyKeyName(""bogus"")]
public class C {}"; public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseModule.WithCryptoKeyContainer("roslynTestContainer").WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseModule.WithCryptoKeyContainer("roslynTestContainer"));
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var success = other.Emit(outStrm); var success = other.Emit(outStrm);
...@@ -1488,55 +1472,49 @@ public class C {}"; ...@@ -1488,55 +1472,49 @@ public class C {}";
} }
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")] [WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void SignModuleKeyFileCmdLine() [MemberData(nameof(AllProviderParseOptions))]
public void SignModuleKeyFileCmdLine(CSharpParseOptions parseOptions)
{ {
string s = "public class C {}"; string s = "public class C {}";
var options = TestOptions.ReleaseModule.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultPortableProvider); var options = SigningReleaseModule.WithCryptoKeyFile(s_keyPairFile);
var other = CreateCompilation(s, options: options); var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var success = other.Emit(outStrm); var success = other.Emit(outStrm);
Assert.True(success.Success); Assert.True(success.Success);
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, legacyStrongName: false); ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, parseOptions);
} }
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void BothLegacyAndNonLegacyGiveTheSameOutput() [MemberData(nameof(AllProviderParseOptions))]
public void BothLegacyAndNonLegacyGiveTheSameOutput(CSharpParseOptions parseOptions)
{ {
string s = "public class C {}"; string s = "public class C {}";
var commonOptions = TestOptions.ReleaseDll var options = SigningReleaseDll
.WithDeterministic(true) .WithDeterministic(true)
.WithModuleName("a.dll") .WithModuleName("a.dll")
.WithCryptoKeyFile(s_keyPairFile); .WithCryptoKeyFile(s_keyPairFile);
var emitOptions = EmitOptions.Default.WithOutputNameOverride("a.dll"); var emitOptions = EmitOptions.Default.WithOutputNameOverride("a.dll");
var compilation = CreateCompilation(s, options: options, parseOptions: parseOptions);
ImmutableArray<byte> EmitAndGetPublicKey(StrongNameProvider provider)
{
var options = commonOptions.WithStrongNameProvider(s_defaultPortableProvider);
var compilation = CreateCompilation(s, options: options);
var stream = compilation.EmitToStream(emitOptions); var stream = compilation.EmitToStream(emitOptions);
stream.Position = 0; stream.Position = 0;
using (var metadata = AssemblyMetadata.CreateFromStream(stream)) using (var metadata = AssemblyMetadata.CreateFromStream(stream))
{ {
return metadata.GetAssembly().Identity.PublicKey; var key = metadata.GetAssembly().Identity.PublicKey;
Assert.True(s_publicKey.SequenceEqual(key));
} }
} }
var portable = EmitAndGetPublicKey(s_defaultPortableProvider);
var desktop = EmitAndGetPublicKey(s_defaultDesktopProvider);
Assert.True(portable.SequenceEqual(desktop));
}
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")]
public void SignRefAssemblyKeyFileCmdLine() public void SignRefAssemblyKeyFileCmdLine()
{ {
string s = "public class C {}"; string s = "public class C {}";
var options = TestOptions.DebugDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultPortableProvider); var options = SigningDebugDll.WithCryptoKeyFile(s_keyPairFile);
var other = CreateCompilation(s, options: options); var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
...@@ -1552,53 +1530,21 @@ public void SignRefAssemblyKeyFileCmdLine() ...@@ -1552,53 +1530,21 @@ public void SignRefAssemblyKeyFileCmdLine()
} }
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")] [WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void SignModuleKeyFileCmdLine_Legacy() [MemberData(nameof(AllProviderParseOptions))]
{ public void SignModuleKeyFileCmdLine_1(CSharpParseOptions parseOptions)
string s = "public class C {}";
var options = TestOptions.ReleaseModule.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider);
var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream();
var success = other.Emit(outStrm);
Assert.True(success.Success);
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, legacyStrongName: true);
}
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")]
public void SignModuleKeyFileCmdLine_1()
{ {
var x = s_keyPairFile; var x = s_keyPairFile;
string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}"); string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}");
var options = TestOptions.ReleaseModule.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultPortableProvider); var options = SigningReleaseModule.WithCryptoKeyFile(s_keyPairFile);
var other = CreateCompilation(s, options: options); var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var success = other.Emit(outStrm); var success = other.Emit(outStrm);
Assert.True(success.Success); Assert.True(success.Success);
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, legacyStrongName: false); ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, parseOptions);
}
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")]
public void SignModuleKeyFileCmdLine_1_Legacy()
{
var x = s_keyPairFile;
string s = String.Format("{0}{1}{2}", @"[assembly: System.Reflection.AssemblyKeyFile(@""", x, @""")] public class C {}");
var options = TestOptions.ReleaseModule.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider);
var other = CreateCompilation(s, options: options);
var outStrm = new MemoryStream();
var success = other.Emit(outStrm);
Assert.True(success.Success);
ConfirmModuleAttributePresentAndAddingToAssemblyResultsInSignedOutput(outStrm, AttributeDescription.AssemblyKeyFileAttribute, legacyStrongName: true);
} }
[WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")] [WorkItem(531195, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531195")]
...@@ -1608,7 +1554,7 @@ public void SignModuleKeyFileCmdLine_2() ...@@ -1608,7 +1554,7 @@ public void SignModuleKeyFileCmdLine_2()
var x = s_keyPairFile; var x = s_keyPairFile;
string s = @"[assembly: System.Reflection.AssemblyKeyFile(""bogus"")] public class C {}"; string s = @"[assembly: System.Reflection.AssemblyKeyFile(""bogus"")] public class C {}";
var other = CreateCompilation(s, options: TestOptions.ReleaseModule.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); var other = CreateCompilation(s, options: SigningReleaseModule.WithCryptoKeyFile(s_keyPairFile));
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var success = other.Emit(outStrm); var success = other.Emit(outStrm);
...@@ -1627,17 +1573,17 @@ public class C ...@@ -1627,17 +1573,17 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile));
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var emitResult = other.Emit(outStrm); var emitResult = other.Emit(outStrm);
other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_SignButNoPrivateKey).WithArguments(s_publicKeyFile)); other.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_SignButNoPrivateKey).WithArguments(s_publicKeyFile));
other = other.WithOptions(TestOptions.ReleaseModule.WithCryptoKeyFile(s_publicKeyFile)); other = other.WithOptions(SigningReleaseModule.WithCryptoKeyFile(s_publicKeyFile));
var assembly = CreateCompilation("", var assembly = CreateCompilation("",
references: new[] { other.EmitToImageReference() }, references: new[] { other.EmitToImageReference() },
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
assembly.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_SignButNoPrivateKey).WithArguments(s_publicKeyFile)); assembly.VerifyDiagnostics(Diagnostic(ErrorCode.ERR_SignButNoPrivateKey).WithArguments(s_publicKeyFile));
} }
...@@ -1651,7 +1597,7 @@ public void DelaySignItWithOnlyPublicKey() ...@@ -1651,7 +1597,7 @@ public void DelaySignItWithOnlyPublicKey()
public class C public class C
{ {
static void Goo() {} static void Goo() {}
}", options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithStrongNameProvider(s_defaultDesktopProvider)); }", options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile));
using (var outStrm = new MemoryStream()) using (var outStrm = new MemoryStream())
{ {
...@@ -1670,7 +1616,7 @@ public class C ...@@ -1670,7 +1616,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll);
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var emitResult = other.Emit(outStrm); var emitResult = other.Emit(outStrm);
...@@ -1690,7 +1636,7 @@ public class C ...@@ -1690,7 +1636,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
var emitResult = other.Emit(outStrm); var emitResult = other.Emit(outStrm);
Assert.True(emitResult.Success); Assert.True(emitResult.Success);
...@@ -1705,7 +1651,7 @@ public void DelaySignConflict() ...@@ -1705,7 +1651,7 @@ public void DelaySignConflict()
public class C public class C
{ {
static void Goo() {} static void Goo() {}
}", options: TestOptions.ReleaseDll.WithDelaySign(false).WithStrongNameProvider(s_defaultDesktopProvider)); }", options: SigningReleaseDll.WithDelaySign(false));
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
//shouldn't get any key warning. //shouldn't get any key warning.
...@@ -1723,7 +1669,7 @@ public void DelaySignNoConflict() ...@@ -1723,7 +1669,7 @@ public void DelaySignNoConflict()
public class C public class C
{ {
static void Goo() {} static void Goo() {}
}", options: TestOptions.ReleaseDll.WithDelaySign(true).WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); }", options: SigningReleaseDll.WithDelaySign(true).WithCryptoKeyFile(s_keyPairFile));
var outStrm = new MemoryStream(); var outStrm = new MemoryStream();
//shouldn't get any key warning. //shouldn't get any key warning.
...@@ -1732,13 +1678,13 @@ public class C ...@@ -1732,13 +1678,13 @@ public class C
Assert.True(emitResult.Success); Assert.True(emitResult.Success);
} }
[ConditionalFact(typeof(WindowsDesktopOnly), Reason = "https://github.com/dotnet/roslyn/issues/30152")] [Theory]
public void DelaySignWithAssemblySignatureKey() [MemberData(nameof(AllProviderParseOptions))]
public void DelaySignWithAssemblySignatureKey(CSharpParseOptions parseOptions)
{ {
DelaySignWithAssemblySignatureKeyHelper(s_defaultPortableProvider); DelaySignWithAssemblySignatureKeyHelper();
DelaySignWithAssemblySignatureKeyHelper(s_defaultDesktopProvider);
void DelaySignWithAssemblySignatureKeyHelper(StrongNameProvider provider) void DelaySignWithAssemblySignatureKeyHelper()
{ {
//Note that this SignatureKey is some random one that I found in the devdiv build. //Note that this SignatureKey is some random one that I found in the devdiv build.
//It is not related to the other keys we use in these tests. //It is not related to the other keys we use in these tests.
...@@ -1748,10 +1694,9 @@ void DelaySignWithAssemblySignatureKeyHelper(StrongNameProvider provider) ...@@ -1748,10 +1694,9 @@ void DelaySignWithAssemblySignatureKeyHelper(StrongNameProvider provider)
//(rather than the contents of the keyfile or container) are used to compute the size needed to //(rather than the contents of the keyfile or container) are used to compute the size needed to
//reserve in the binary for its signature. Signing using this key is only supported via sn.exe //reserve in the binary for its signature. Signing using this key is only supported via sn.exe
var options = TestOptions.ReleaseDll var options = SigningReleaseDll
.WithDelaySign(true) .WithDelaySign(true)
.WithCryptoKeyFile(s_keyPairFile) .WithCryptoKeyFile(s_keyPairFile);
.WithStrongNameProvider(provider);
var other = CreateCompilation( var other = CreateCompilation(
@" @"
...@@ -1761,7 +1706,8 @@ public class C ...@@ -1761,7 +1706,8 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: options); options: options,
parseOptions: parseOptions);
using (var metadata = ModuleMetadata.CreateFromImage(other.EmitToArray())) using (var metadata = ModuleMetadata.CreateFromImage(other.EmitToArray()))
{ {
...@@ -1807,7 +1753,7 @@ class Derived : Base ...@@ -1807,7 +1753,7 @@ class Derived : Base
var ilRef = CompileIL(il, prependDefaultHeader: false); var ilRef = CompileIL(il, prependDefaultHeader: false);
var comp = CreateCompilation(csharp, new[] { ilRef }, assemblyName: "asm2", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider)); var comp = CreateCompilation(csharp, new[] { ilRef }, assemblyName: "asm2", options: SigningReleaseDll);
comp.VerifyDiagnostics( comp.VerifyDiagnostics(
// NOTE: dev10 reports WRN_InvalidAssemblyName, but Roslyn won't (DevDiv #15099). // NOTE: dev10 reports WRN_InvalidAssemblyName, but Roslyn won't (DevDiv #15099).
// (2,17): error CS0122: 'Base' is inaccessible due to its protection level // (2,17): error CS0122: 'Base' is inaccessible due to its protection level
...@@ -1864,15 +1810,15 @@ void TestET() ...@@ -1864,15 +1810,15 @@ void TestET()
} }
"; ";
var comp1 = CreateCompilationWithMscorlib45(source1, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm1"); var comp1 = CreateCompilationWithMscorlib45(source1, options: SigningReleaseDll, assemblyName: "asm1");
comp1.VerifyDiagnostics(); comp1.VerifyDiagnostics();
var ref1 = new CSharpCompilationReference(comp1); var ref1 = new CSharpCompilationReference(comp1);
var comp2 = CreateCompilationWithMscorlib45(source2, new[] { ref1 }, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm2"); var comp2 = CreateCompilationWithMscorlib45(source2, new[] { ref1 }, options: SigningReleaseDll, assemblyName: "asm2");
comp2.VerifyDiagnostics(); comp2.VerifyDiagnostics();
var ref2 = new CSharpCompilationReference(comp2); var ref2 = new CSharpCompilationReference(comp2);
var comp3 = CreateCompilationWithMscorlib45(source3, new[] { SystemCoreRef, ref1, ref2 }, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm3"); var comp3 = CreateCompilationWithMscorlib45(source3, new[] { SystemCoreRef, ref1, ref2 }, options: SigningReleaseDll, assemblyName: "asm3");
comp3.VerifyDiagnostics(); comp3.VerifyDiagnostics();
// Note: calls B.M, not A.M, since asm1 is not accessible. // Note: calls B.M, not A.M, since asm1 is not accessible.
...@@ -1981,19 +1927,19 @@ void TestET() ...@@ -1981,19 +1927,19 @@ void TestET()
} }
"; ";
var comp1 = CreateCompilationWithMscorlib45(source1, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm1"); var comp1 = CreateCompilationWithMscorlib45(source1, options: SigningReleaseDll, assemblyName: "asm1");
comp1.VerifyDiagnostics(); comp1.VerifyDiagnostics();
var ref1 = new CSharpCompilationReference(comp1); var ref1 = new CSharpCompilationReference(comp1);
var comp2 = CreateCompilationWithMscorlib45(source2, new[] { ref1 }, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm2"); var comp2 = CreateCompilationWithMscorlib45(source2, new[] { ref1 }, options: SigningReleaseDll, assemblyName: "asm2");
comp2.VerifyDiagnostics(); comp2.VerifyDiagnostics();
var ref2 = new CSharpCompilationReference(comp2); var ref2 = new CSharpCompilationReference(comp2);
var comp3 = CreateCompilationWithMscorlib45(source3, new[] { ref1, ref2 }, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm3"); var comp3 = CreateCompilationWithMscorlib45(source3, new[] { ref1, ref2 }, options: SigningReleaseDll, assemblyName: "asm3");
comp3.VerifyDiagnostics(); comp3.VerifyDiagnostics();
var ref3 = new CSharpCompilationReference(comp3); var ref3 = new CSharpCompilationReference(comp3);
var comp4 = CreateCompilationWithMscorlib45(source4, new[] { SystemCoreRef, ref1, ref2, ref3 }, options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "asm4"); var comp4 = CreateCompilationWithMscorlib45(source4, new[] { SystemCoreRef, ref1, ref2, ref3 }, options: SigningReleaseDll, assemblyName: "asm4");
comp4.VerifyDiagnostics(); comp4.VerifyDiagnostics();
// Note: calls C.M, not A.M, since asm2 is not accessible (stops search). // Note: calls C.M, not A.M, since asm2 is not accessible (stops search).
...@@ -2143,7 +2089,7 @@ void Test() ...@@ -2143,7 +2089,7 @@ void Test()
"; ";
var comp1 = CreateCompilation(source1, var comp1 = CreateCompilation(source1,
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll,
assemblyName: "asm1"); assemblyName: "asm1");
comp1.VerifyDiagnostics(); comp1.VerifyDiagnostics();
...@@ -2153,7 +2099,7 @@ void Test() ...@@ -2153,7 +2099,7 @@ void Test()
var comp3 = CreateCompilation(source3, var comp3 = CreateCompilation(source3,
new[] { ref1, ref2 }, new[] { ref1, ref2 },
options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseDll,
assemblyName: "asm3"); assemblyName: "asm3");
comp3.VerifyDiagnostics( comp3.VerifyDiagnostics(
...@@ -2173,7 +2119,7 @@ public void Bug529779_1() ...@@ -2173,7 +2119,7 @@ public void Bug529779_1()
@" @"
public class C1 public class C1
{} {}
", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "Unsigned"); ", options: SigningReleaseDll, assemblyName: "Unsigned");
CSharpCompilation other = CreateCompilation( CSharpCompilation other = CreateCompilation(
@" @"
...@@ -2185,7 +2131,7 @@ internal void Goo() ...@@ -2185,7 +2131,7 @@ internal void Goo()
System.Console.WriteLine(x); System.Console.WriteLine(x);
} }
} }
", options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider)); ", options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
CompileAndVerify(other.WithReferences(new[] { other.References.ElementAt(0), new CSharpCompilationReference(unsigned) })).VerifyDiagnostics(); CompileAndVerify(other.WithReferences(new[] { other.References.ElementAt(0), new CSharpCompilationReference(unsigned) })).VerifyDiagnostics();
...@@ -2200,7 +2146,7 @@ public void Bug529779_2() ...@@ -2200,7 +2146,7 @@ public void Bug529779_2()
@" @"
public class C1 public class C1
{} {}
", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "Unsigned"); ", options: SigningReleaseDll, assemblyName: "Unsigned");
CSharpCompilation other = CreateCompilation( CSharpCompilation other = CreateCompilation(
@" @"
...@@ -2212,7 +2158,7 @@ internal void Goo() ...@@ -2212,7 +2158,7 @@ internal void Goo()
System.Console.WriteLine(x); System.Console.WriteLine(x);
} }
} }
", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider).WithCryptoKeyFile(s_keyPairFile)); ", options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile));
var comps = new[] {other.WithReferences(new []{other.References.ElementAt(0), new CSharpCompilationReference(unsigned)}), var comps = new[] {other.WithReferences(new []{other.References.ElementAt(0), new CSharpCompilationReference(unsigned)}),
other.WithReferences(new []{other.References.ElementAt(0), MetadataReference.CreateFromStream(unsigned.EmitToStream()) })}; other.WithReferences(new []{other.References.ElementAt(0), MetadataReference.CreateFromStream(unsigned.EmitToStream()) })};
...@@ -2258,9 +2204,8 @@ public void Bug399() ...@@ -2258,9 +2204,8 @@ public void Bug399()
var compilation = CreateCompilation( var compilation = CreateCompilation(
"interface IDerived : ISigned { }", "interface IDerived : ISigned { }",
references: new[] { signed }, references: new[] { signed },
options: TestOptions.ReleaseDll options: SigningReleaseDll
.WithGeneralDiagnosticOption(ReportDiagnostic.Error) .WithGeneralDiagnosticOption(ReportDiagnostic.Error)
.WithStrongNameProvider(s_defaultDesktopProvider)
.WithCryptoKeyFile(s_keyPairFile)); .WithCryptoKeyFile(s_keyPairFile));
// ACTUAL: error CS8002: Referenced assembly 'Signed, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name. // ACTUAL: error CS8002: Referenced assembly 'Signed, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.
...@@ -2282,7 +2227,7 @@ public class C ...@@ -2282,7 +2227,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider), references: new[] { MscorlibRef_v4_0_30316_17626 }); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile), references: new[] { MscorlibRef_v4_0_30316_17626 });
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -2308,7 +2253,7 @@ public class C ...@@ -2308,7 +2253,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider), references: new[] { MscorlibRef_v4_0_30316_17626 }); options: SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile), references: new[] { MscorlibRef_v4_0_30316_17626 });
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -2336,7 +2281,7 @@ public class C ...@@ -2336,7 +2281,7 @@ public class C
static void Goo() {} static void Goo() {}
}"; }";
var options = TestOptions.ReleaseDll.WithCryptoKeyFile(s_keyPairFile).WithStrongNameProvider(s_defaultDesktopProvider); var options = SigningReleaseDll.WithCryptoKeyFile(s_keyPairFile);
var other = CreateEmptyCompilation(source, options: options, references: new[] { MscorlibRef_v4_0_30316_17626 }); var other = CreateEmptyCompilation(source, options: options, references: new[] { MscorlibRef_v4_0_30316_17626 });
...@@ -2365,7 +2310,7 @@ public class C ...@@ -2365,7 +2310,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true).WithStrongNameProvider(s_defaultDesktopProvider), references: new[] { MscorlibRef_v4_0_30316_17626 }); options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true), references: new[] { MscorlibRef_v4_0_30316_17626 });
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -2394,7 +2339,7 @@ public class C ...@@ -2394,7 +2339,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true).WithStrongNameProvider(s_defaultDesktopProvider), references: new[] { MscorlibRef_v4_0_30316_17626 }); options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true), references: new[] { MscorlibRef_v4_0_30316_17626 });
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -2418,7 +2363,7 @@ public class C ...@@ -2418,7 +2363,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true).WithStrongNameProvider(s_defaultDesktopProvider), references: new[] { MscorlibRef_v4_0_30316_17626 }); options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true), references: new[] { MscorlibRef_v4_0_30316_17626 });
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -2447,7 +2392,7 @@ public class C ...@@ -2447,7 +2392,7 @@ public class C
{ {
static void Goo() {} static void Goo() {}
}", }",
options: TestOptions.ReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true).WithStrongNameProvider(s_defaultDesktopProvider), references: new[] { MscorlibRef_v4_0_30316_17626 }); options: SigningReleaseDll.WithCryptoKeyFile(s_publicKeyFile).WithDelaySign(true), references: new[] { MscorlibRef_v4_0_30316_17626 });
var tempFile = Temp.CreateFile(); var tempFile = Temp.CreateFile();
...@@ -2470,7 +2415,7 @@ internal class A ...@@ -2470,7 +2415,7 @@ internal class A
{ {
public int Value = 3; public int Value = 3;
} }
", options: TestOptions.ReleaseDll.WithStrongNameProvider(s_defaultDesktopProvider), assemblyName: "Bug769840_A"); ", options: SigningReleaseDll, assemblyName: "Bug769840_A");
CompileAndVerify(ca); CompileAndVerify(ca);
...@@ -2483,7 +2428,7 @@ public A GetA() ...@@ -2483,7 +2428,7 @@ public A GetA()
return new A(); return new A();
} }
}", }",
options: TestOptions.ReleaseModule.WithStrongNameProvider(s_defaultDesktopProvider), options: SigningReleaseModule,
assemblyName: "Bug781312_B", assemblyName: "Bug781312_B",
references: new[] { new CSharpCompilationReference(ca) }); references: new[] { new CSharpCompilationReference(ca) });
......
...@@ -1657,11 +1657,13 @@ internal void SetupWin32Resources(CommonPEModuleBuilder moduleBeingBuilt, Stream ...@@ -1657,11 +1657,13 @@ internal void SetupWin32Resources(CommonPEModuleBuilder moduleBeingBuilt, Stream
/// 1. By directly signing the <see cref="PEBuilder"/> /// 1. By directly signing the <see cref="PEBuilder"/>
/// 2. Write the unsigned PE to disk and use CLR COM APIs to sign. /// 2. Write the unsigned PE to disk and use CLR COM APIs to sign.
/// The preferred method is #1 as it's more efficient and more resilient (no reliance on %TEMP%). But /// The preferred method is #1 as it's more efficient and more resilient (no reliance on %TEMP%). But
/// we must continue to support #2 as it's the only way to access private keys stored in a key /// we must continue to support #2 as it's the only way to do the following:
/// container. /// - Access private keys stored in a key
/// - Do proper counter signature verification for AssemblySignatureKey attributes
/// </summary> /// </summary>
internal bool SignUsingBuilder => internal bool SignUsingBuilder =>
string.IsNullOrEmpty(StrongNameKeys.KeyContainer) && string.IsNullOrEmpty(StrongNameKeys.KeyContainer) &&
!StrongNameKeys.HasCounterSignature &&
!_features.ContainsKey("UseLegacyStrongNameProvider"); !_features.ContainsKey("UseLegacyStrongNameProvider");
/// <summary> /// <summary>
......
...@@ -164,7 +164,7 @@ internal override Stream CreateInputStream() ...@@ -164,7 +164,7 @@ internal override Stream CreateInputStream()
return FileUtilities.CreateFileStreamChecked(streamConstructor, tempName); return FileUtilities.CreateFileStreamChecked(streamConstructor, tempName);
} }
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider)
{ {
var keyPair = default(ImmutableArray<byte>); var keyPair = default(ImmutableArray<byte>);
var publicKey = default(ImmutableArray<byte>); var publicKey = default(ImmutableArray<byte>);
...@@ -182,7 +182,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai ...@@ -182,7 +182,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai
Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile)); Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile));
var fileContent = ImmutableArray.Create(FileSystem.ReadAllBytes(resolvedKeyFile)); var fileContent = ImmutableArray.Create(FileSystem.ReadAllBytes(resolvedKeyFile));
return StrongNameKeys.CreateHelper(fileContent, keyFilePath); return StrongNameKeys.CreateHelper(fileContent, keyFilePath, hasCounterSignature);
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -207,7 +207,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai ...@@ -207,7 +207,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai
} }
} }
return new StrongNameKeys(keyPair, publicKey, null, container, keyFilePath); return new StrongNameKeys(keyPair, publicKey, null, container, keyFilePath, hasCounterSignature);
} }
/// <summary> /// <summary>
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
namespace Microsoft.CodeAnalysis namespace Microsoft.CodeAnalysis
{ {
// TODO: delete this
internal sealed class PortableStrongNameProvider : StrongNameProvider internal sealed class PortableStrongNameProvider : StrongNameProvider
{ {
private readonly DesktopStrongNameProvider _provider; private readonly DesktopStrongNameProvider _provider;
...@@ -30,9 +31,9 @@ public override int GetHashCode() ...@@ -30,9 +31,9 @@ public override int GetHashCode()
internal override StrongNameFileSystem FileSystem => _provider.FileSystem; internal override StrongNameFileSystem FileSystem => _provider.FileSystem;
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider)
{ {
return _provider.CreateKeys(keyFilePath, keyContainerName, messageProvider); return _provider.CreateKeys(keyFilePath, keyContainerName, hasCounterSignature, messageProvider);
} }
internal override void SignPeBuilder(ExtendedPEBuilder peBuilder, BlobBuilder peBlob, RSAParameters privateKey) internal override void SignPeBuilder(ExtendedPEBuilder peBuilder, BlobBuilder peBlob, RSAParameters privateKey)
......
...@@ -52,6 +52,12 @@ internal sealed class StrongNameKeys ...@@ -52,6 +52,12 @@ internal sealed class StrongNameKeys
/// </remarks> /// </remarks>
internal readonly string KeyFilePath; internal readonly string KeyFilePath;
/// <summary>
/// True when the assembly contains a <see cref="System.Reflection.AssemblySignatureKeyAttribute"/> value
/// and hence signing requires counter signature verification.
/// </summary>
internal readonly bool HasCounterSignature;
internal static readonly StrongNameKeys None = new StrongNameKeys(); internal static readonly StrongNameKeys None = new StrongNameKeys();
private StrongNameKeys() private StrongNameKeys()
...@@ -64,7 +70,7 @@ internal StrongNameKeys(Diagnostic diagnostic) ...@@ -64,7 +70,7 @@ internal StrongNameKeys(Diagnostic diagnostic)
this.DiagnosticOpt = diagnostic; this.DiagnosticOpt = diagnostic;
} }
internal StrongNameKeys(ImmutableArray<byte> keyPair, ImmutableArray<byte> publicKey, RSAParameters? privateKey, string keyContainerName, string keyFilePath) internal StrongNameKeys(ImmutableArray<byte> keyPair, ImmutableArray<byte> publicKey, RSAParameters? privateKey, string keyContainerName, string keyFilePath, bool hasCounterSignature)
{ {
Debug.Assert(keyContainerName == null || keyPair.IsDefault); Debug.Assert(keyContainerName == null || keyPair.IsDefault);
Debug.Assert(keyPair.IsDefault || keyFilePath != null); Debug.Assert(keyPair.IsDefault || keyFilePath != null);
...@@ -74,15 +80,16 @@ internal StrongNameKeys(ImmutableArray<byte> keyPair, ImmutableArray<byte> publi ...@@ -74,15 +80,16 @@ internal StrongNameKeys(ImmutableArray<byte> keyPair, ImmutableArray<byte> publi
this.PrivateKey = privateKey; this.PrivateKey = privateKey;
this.KeyContainer = keyContainerName; this.KeyContainer = keyContainerName;
this.KeyFilePath = keyFilePath; this.KeyFilePath = keyFilePath;
this.HasCounterSignature = hasCounterSignature;
} }
internal static StrongNameKeys Create(ImmutableArray<byte> publicKey, RSAParameters? privateKey, CommonMessageProvider messageProvider) internal static StrongNameKeys Create(ImmutableArray<byte> publicKey, RSAParameters? privateKey, bool hasCounterSignature, CommonMessageProvider messageProvider)
{ {
Debug.Assert(!publicKey.IsDefaultOrEmpty); Debug.Assert(!publicKey.IsDefaultOrEmpty);
if (MetadataHelpers.IsValidPublicKey(publicKey)) if (MetadataHelpers.IsValidPublicKey(publicKey))
{ {
return new StrongNameKeys(default(ImmutableArray<byte>), publicKey, privateKey, null, null); return new StrongNameKeys(default(ImmutableArray<byte>), publicKey, privateKey, null, null, hasCounterSignature);
} }
else else
{ {
...@@ -101,7 +108,7 @@ internal static StrongNameKeys Create(string keyFilePath, CommonMessageProvider ...@@ -101,7 +108,7 @@ internal static StrongNameKeys Create(string keyFilePath, CommonMessageProvider
try try
{ {
var fileContent = ImmutableArray.Create(File.ReadAllBytes(keyFilePath)); var fileContent = ImmutableArray.Create(File.ReadAllBytes(keyFilePath));
return CreateHelper(fileContent, keyFilePath); return CreateHelper(fileContent, keyFilePath, hasCounterSignature: false);
} }
catch (IOException ex) catch (IOException ex)
{ {
...@@ -116,7 +123,7 @@ internal static StrongNameKeys Create(string keyFilePath, CommonMessageProvider ...@@ -116,7 +123,7 @@ internal static StrongNameKeys Create(string keyFilePath, CommonMessageProvider
private static Tuple<ImmutableArray<byte>, ImmutableArray<byte>, RSAParameters?> s_lastSeenKeyPair; private static Tuple<ImmutableArray<byte>, ImmutableArray<byte>, RSAParameters?> s_lastSeenKeyPair;
// Note: Errors are reported by throwing an IOException // Note: Errors are reported by throwing an IOException
internal static StrongNameKeys CreateHelper(ImmutableArray<byte> keyFileContent, string keyFilePath) internal static StrongNameKeys CreateHelper(ImmutableArray<byte> keyFileContent, string keyFilePath, bool hasCounterSignature)
{ {
ImmutableArray<byte> keyPair; ImmutableArray<byte> keyPair;
ImmutableArray<byte> publicKey; ImmutableArray<byte> publicKey;
...@@ -151,10 +158,10 @@ internal static StrongNameKeys CreateHelper(ImmutableArray<byte> keyFileContent, ...@@ -151,10 +158,10 @@ internal static StrongNameKeys CreateHelper(ImmutableArray<byte> keyFileContent,
Interlocked.Exchange(ref s_lastSeenKeyPair, cachedKeyPair); Interlocked.Exchange(ref s_lastSeenKeyPair, cachedKeyPair);
} }
return new StrongNameKeys(keyPair, publicKey, privateKey, null, keyFilePath); return new StrongNameKeys(keyPair, publicKey, privateKey, null, keyFilePath, hasCounterSignature);
} }
internal static StrongNameKeys Create(StrongNameProvider providerOpt, string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) internal static StrongNameKeys Create(StrongNameProvider providerOpt, string keyFilePath, string keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider)
{ {
if (string.IsNullOrEmpty(keyFilePath) && string.IsNullOrEmpty(keyContainerName)) if (string.IsNullOrEmpty(keyFilePath) && string.IsNullOrEmpty(keyContainerName))
{ {
...@@ -167,7 +174,7 @@ internal static StrongNameKeys Create(StrongNameProvider providerOpt, string key ...@@ -167,7 +174,7 @@ internal static StrongNameKeys Create(StrongNameProvider providerOpt, string key
return new StrongNameKeys(diagnostic); return new StrongNameKeys(diagnostic);
} }
return providerOpt.CreateKeys(keyFilePath, keyContainerName, messageProvider); return providerOpt.CreateKeys(keyFilePath, keyContainerName, hasCounterSignature, messageProvider);
} }
/// <summary> /// <summary>
......
...@@ -46,6 +46,6 @@ protected StrongNameProvider() ...@@ -46,6 +46,6 @@ protected StrongNameProvider()
/// <summary> /// <summary>
/// Create a <see cref="StrongNameKeys"/> for the provided information. /// Create a <see cref="StrongNameKeys"/> for the provided information.
/// </summary> /// </summary>
internal abstract StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider); internal abstract StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasCounterSignature, CommonMessageProvider messageProvider);
} }
} }
...@@ -22,6 +22,7 @@ public static class TestOptions ...@@ -22,6 +22,7 @@ public static class TestOptions
public static readonly CSharpParseOptions Regular7_3 = Regular.WithLanguageVersion(LanguageVersion.CSharp7_3); public static readonly CSharpParseOptions Regular7_3 = Regular.WithLanguageVersion(LanguageVersion.CSharp7_3);
public static readonly CSharpParseOptions Regular8 = Regular.WithLanguageVersion(LanguageVersion.CSharp8); public static readonly CSharpParseOptions Regular8 = Regular.WithLanguageVersion(LanguageVersion.CSharp8);
public static readonly CSharpParseOptions RegularWithDocumentationComments = Regular.WithDocumentationMode(DocumentationMode.Diagnose); public static readonly CSharpParseOptions RegularWithDocumentationComments = Regular.WithDocumentationMode(DocumentationMode.Diagnose);
public static readonly CSharpParseOptions RegularWithLegacyStrongName = Regular.WithFeature("UseLegacyStrongNameProvider");
public static readonly CSharpParseOptions WithoutImprovedOverloadCandidates = Regular.WithLanguageVersion(MessageID.IDS_FeatureImprovedOverloadCandidates.RequiredVersion() - 1); public static readonly CSharpParseOptions WithoutImprovedOverloadCandidates = Regular.WithLanguageVersion(MessageID.IDS_FeatureImprovedOverloadCandidates.RequiredVersion() - 1);
private static readonly SmallDictionary<string, string> s_experimentalFeatures = new SmallDictionary<string, string> { }; private static readonly SmallDictionary<string, string> s_experimentalFeatures = new SmallDictionary<string, string> { };
......
...@@ -101,9 +101,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ...@@ -101,9 +101,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
_modules = moduleBuilder.ToImmutableAndFree() _modules = moduleBuilder.ToImmutableAndFree()
If Not compilation.Options.CryptoPublicKey.IsEmpty Then If Not compilation.Options.CryptoPublicKey.IsEmpty Then
' TODO: this Is suspicious.When it's set here it's never re-computed hence it will never get the private
' key. This appears to be what Is used for emit though. Need to follow up on this.
' Private key Is Not necessary for assembly identity, only when emitting. For this reason, the private key can remain null. ' Private key Is Not necessary for assembly identity, only when emitting. For this reason, the private key can remain null.
Dim privateKey As RSAParameters? = Nothing _lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey:=Nothing, hasCounterSignature:=False, MessageProvider.Instance)
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey, MessageProvider.Instance)
End If End If
End Sub End Sub
...@@ -1679,7 +1680,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ...@@ -1679,7 +1680,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
End If End If
End If End If
keys = StrongNameKeys.Create(DeclaringCompilation.Options.StrongNameProvider, keyFile, keyContainer, MessageProvider.Instance) Dim hasCounterSignature = Not String.IsNullOrEmpty(SignatureKey)
keys = StrongNameKeys.Create(DeclaringCompilation.Options.StrongNameProvider, keyFile, keyContainer, hasCounterSignature, MessageProvider.Instance)
Interlocked.CompareExchange(_lazyStrongNameKeys, keys, Nothing) Interlocked.CompareExchange(_lazyStrongNameKeys, keys, Nothing)
End Sub End Sub
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#if !NETSTANDARD2_0 #if !NETSTANDARD2_0
using System; using System;
using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册