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
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.
RSAParameters? privateKey = null;
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey, MessageProvider.Instance);
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey: null, hasCounterSignature: false, MessageProvider.Instance);
}
}
......@@ -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
......
......@@ -41,8 +41,8 @@ internal override Stream CreateInputStream()
throw ThrownException;
}
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, CommonMessageProvider messageProvider) =>
_underlyingProvider.CreateKeys(keyFilePath, keyContainerName, messageProvider);
internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContainerName, bool hasSignatureKey, CommonMessageProvider messageProvider) =>
_underlyingProvider.CreateKeys(keyFilePath, keyContainerName, hasSignatureKey, messageProvider);
internal override void SignStream(StrongNameKeys keys, Stream inputStream, Stream outputStream) =>
_underlyingProvider.SignStream(keys, inputStream, outputStream);
......
......@@ -1657,11 +1657,13 @@ internal void SetupWin32Resources(CommonPEModuleBuilder moduleBeingBuilt, Stream
/// 1. By directly signing the <see cref="PEBuilder"/>
/// 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
/// we must continue to support #2 as it's the only way to access private keys stored in a key
/// container.
/// we must continue to support #2 as it's the only way to do the following:
/// - Access private keys stored in a key
/// - Do proper counter signature verification for AssemblySignatureKey attributes
/// </summary>
internal bool SignUsingBuilder =>
string.IsNullOrEmpty(StrongNameKeys.KeyContainer) &&
!StrongNameKeys.HasCounterSignature &&
!_features.ContainsKey("UseLegacyStrongNameProvider");
/// <summary>
......
......@@ -164,7 +164,7 @@ internal override Stream CreateInputStream()
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 publicKey = default(ImmutableArray<byte>);
......@@ -182,7 +182,7 @@ internal override StrongNameKeys CreateKeys(string keyFilePath, string keyContai
Debug.Assert(PathUtilities.IsAbsolute(resolvedKeyFile));
var fileContent = ImmutableArray.Create(FileSystem.ReadAllBytes(resolvedKeyFile));
return StrongNameKeys.CreateHelper(fileContent, keyFilePath);
return StrongNameKeys.CreateHelper(fileContent, keyFilePath, hasCounterSignature);
}
catch (Exception ex)
{
......@@ -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>
......
......@@ -14,6 +14,7 @@
namespace Microsoft.CodeAnalysis
{
// TODO: delete this
internal sealed class PortableStrongNameProvider : StrongNameProvider
{
private readonly DesktopStrongNameProvider _provider;
......@@ -30,9 +31,9 @@ public override int GetHashCode()
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)
......
......@@ -52,6 +52,12 @@ internal sealed class StrongNameKeys
/// </remarks>
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();
private StrongNameKeys()
......@@ -64,7 +70,7 @@ internal StrongNameKeys(Diagnostic 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(keyPair.IsDefault || keyFilePath != null);
......@@ -74,15 +80,16 @@ internal StrongNameKeys(ImmutableArray<byte> keyPair, ImmutableArray<byte> publi
this.PrivateKey = privateKey;
this.KeyContainer = keyContainerName;
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);
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
{
......@@ -101,7 +108,7 @@ internal static StrongNameKeys Create(string keyFilePath, CommonMessageProvider
try
{
var fileContent = ImmutableArray.Create(File.ReadAllBytes(keyFilePath));
return CreateHelper(fileContent, keyFilePath);
return CreateHelper(fileContent, keyFilePath, hasCounterSignature: false);
}
catch (IOException ex)
{
......@@ -116,7 +123,7 @@ internal static StrongNameKeys Create(string keyFilePath, CommonMessageProvider
private static Tuple<ImmutableArray<byte>, ImmutableArray<byte>, RSAParameters?> s_lastSeenKeyPair;
// 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> publicKey;
......@@ -151,10 +158,10 @@ internal static StrongNameKeys CreateHelper(ImmutableArray<byte> keyFileContent,
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))
{
......@@ -167,7 +174,7 @@ internal static StrongNameKeys Create(StrongNameProvider providerOpt, string key
return new StrongNameKeys(diagnostic);
}
return providerOpt.CreateKeys(keyFilePath, keyContainerName, messageProvider);
return providerOpt.CreateKeys(keyFilePath, keyContainerName, hasCounterSignature, messageProvider);
}
/// <summary>
......
......@@ -46,6 +46,6 @@ protected StrongNameProvider()
/// <summary>
/// Create a <see cref="StrongNameKeys"/> for the provided information.
/// </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
public static readonly CSharpParseOptions Regular7_3 = Regular.WithLanguageVersion(LanguageVersion.CSharp7_3);
public static readonly CSharpParseOptions Regular8 = Regular.WithLanguageVersion(LanguageVersion.CSharp8);
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);
private static readonly SmallDictionary<string, string> s_experimentalFeatures = new SmallDictionary<string, string> { };
......
......@@ -101,9 +101,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
_modules = moduleBuilder.ToImmutableAndFree()
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.
Dim privateKey As RSAParameters? = Nothing
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey, MessageProvider.Instance)
_lazyStrongNameKeys = StrongNameKeys.Create(compilation.Options.CryptoPublicKey, privateKey:=Nothing, hasCounterSignature:=False, MessageProvider.Instance)
End If
End Sub
......@@ -1679,7 +1680,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
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)
End Sub
......
......@@ -2,6 +2,7 @@
#if !NETSTANDARD2_0
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Runtime.InteropServices;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册