Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hash algorithm used with long net.pipe urls #1196

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/CoreWCF.NetNamedPipe/src/CoreWCF/Channels/PipeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ public static string GetPath(Uri uri)
return path;
}

internal const string UseSha1InMsmqEncryptionAlgorithmString = "Switch.System.ServiceModel.UseSha1InMsmqEncryptionAlgorithm";
internal static bool s_useSha1InPipeConnectionGetHashAlgorithm = AppContext.TryGetSwitch(UseSha1InMsmqEncryptionAlgorithmString, out bool enabled) && enabled;
internal const string UseSha1InPipeConnectionGetHashAlgorithmString = "Switch.System.ServiceModel.UseSha1InPipeConnectionGetHashAlgorithm";
internal static bool s_useSha1InPipeConnectionGetHashAlgorithm = AppContext.TryGetSwitch(UseSha1InPipeConnectionGetHashAlgorithmString, out bool enabled) && enabled;

private static HashAlgorithm GetHashAlgorithm()
{
if (s_useSha1InPipeConnectionGetHashAlgorithm)
{
return SHA256.Create();
return SHA1.Create();
}
else
{
return SHA1.Create();
return SHA256.Create();
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions src/CoreWCF.NetNamedPipe/tests/BasicServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ public void NetPipeRequestReplyEchoString()
}
}

[Fact]
public void NetPipeLongPathHashesCorrectly()
{
string testString = new string('a', 3000);
// Path is hashed if it's longer than 128 bytes
string basePath = $"{nameof(NetPipeLongPathHashesCorrectly)}{new string('a', 128)}";
var host = ServiceHelper.CreateWebHostBuilder<Startup>(_output, basePath).Build();

using (host)
{
host.Start();
var binding = new System.ServiceModel.NetNamedPipeBinding();
var factory = new System.ServiceModel.ChannelFactory<IEchoService>(binding,
new System.ServiceModel.EndpointAddress(new Uri($"net.pipe://localhost/{basePath}/netpipe.svc")));
var channel = factory.CreateChannel();
System.ServiceModel.Channels.IChannel ichannel = (System.ServiceModel.Channels.IChannel)channel;
ichannel.Open();
var result = channel.EchoString(testString);
Assert.Equal(testString, result);
ichannel.Close();
}
}

internal class Startup
{
public void ConfigureServices(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<PackageReference Include="System.ServiceModel.Primitives" Version="6.0.0-preview1.23060.3" />
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="6.0.0-preview1.23060.3" />
<PackageReference Include="System.ServiceModel.Primitives" Version="6.0.0" />
<PackageReference Include="System.ServiceModel.NetNamedPipe" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down