Update client credentials (not currently enabled)
This commit is contained in:
parent
68caa8d7a0
commit
187a3a47f2
1
Pal.Client/.gitignore
vendored
1
Pal.Client/.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/dist
|
/dist
|
||||||
|
/Secrets.cs
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<LangVersion>9.0</LangVersion>
|
<LangVersion>9.0</LangVersion>
|
||||||
<Version>1.10.0.0</Version>
|
<Version>1.11.0.0</Version>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@ -17,8 +17,18 @@
|
|||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
<OutputPath>dist</OutputPath>
|
<OutputPath>dist</OutputPath>
|
||||||
|
<DebugType>none</DebugType>
|
||||||
|
<DebugSymbols>false</DebugSymbols>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(Configuration)' == 'Release' And Exists('Certificate.pfx')">
|
||||||
|
<None Remove="Certificate.pfx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition="'$(Configuration)' == 'Release' And Exists('Certificate.pfx')">
|
||||||
|
<EmbeddedResource Include="Certificate.pfx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DalamudPackager" Version="2.1.8" />
|
<PackageReference Include="DalamudPackager" Version="2.1.8" />
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.21.8" />
|
<PackageReference Include="Google.Protobuf" Version="3.21.8" />
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
using Account;
|
using Account;
|
||||||
using Grpc.Core;
|
using Grpc.Core;
|
||||||
using Grpc.Core.Interceptors;
|
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
using Palace;
|
using Palace;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Security;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ namespace Pal.Client
|
|||||||
HttpHandler = new SocketsHttpHandler
|
HttpHandler = new SocketsHttpHandler
|
||||||
{
|
{
|
||||||
ConnectTimeout = TimeSpan.FromSeconds(5),
|
ConnectTimeout = TimeSpan.FromSeconds(5),
|
||||||
|
SslOptions = GetSslClientAuthenticationOptions(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
await _channel.ConnectAsync(cancellationToken);
|
await _channel.ConnectAsync(cancellationToken);
|
||||||
@ -159,6 +161,36 @@ namespace Pal.Client
|
|||||||
{ "User-Agent", UserAgent },
|
{ "User-Agent", UserAgent },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private SslClientAuthenticationOptions? GetSslClientAuthenticationOptions()
|
||||||
|
{
|
||||||
|
#if !DEBUG
|
||||||
|
var secrets = typeof(RemoteApi).Assembly.GetType("Pal.Client.Secrets");
|
||||||
|
if (secrets == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var pass = secrets.GetProperty("CertPassword")?.GetValue(null) as string;
|
||||||
|
if (pass == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var manifestResourceStream = typeof(RemoteApi).Assembly.GetManifestResourceStream("Pal.Client.Certificate.pfx");
|
||||||
|
if (manifestResourceStream == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var bytes = new byte[manifestResourceStream.Length];
|
||||||
|
manifestResourceStream.Read(bytes, 0, bytes.Length);
|
||||||
|
|
||||||
|
return new SslClientAuthenticationOptions
|
||||||
|
{
|
||||||
|
ClientCertificates = new X509CertificateCollection()
|
||||||
|
{
|
||||||
|
new X509Certificate2(bytes, pass, X509KeyStorageFlags.DefaultKeySet),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
return null;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_channel?.Dispose();
|
_channel?.Dispose();
|
||||||
|
Loading…
Reference in New Issue
Block a user