-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.cs
70 lines (59 loc) · 1.89 KB
/
App.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace ExampleCert
{
class App : Application
{
public App()
{
MainPage = new ContentPage
{
Content = new Button
{
Text = "Request",
TextTransform = TextTransform.Uppercase,
HeightRequest = 60,
WidthRequest = 120,
Command = new Command(OnClick)
}
};
}
const string Url = "URL";
const string Password = "PASSWORD";
async void OnClick()
{
try
{
Stream stream = await FileSystem.OpenAppPackageFileAsync("certificate.cer");
using MemoryStream s = new();
stream.CopyTo(s);
stream.Dispose();
X509Certificate2 cert = new(s.ToArray(), Password);
SocketsHttpHandler shh = new()
{
UseCookies = true,
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
SslOptions =
{
EnabledSslProtocols = System.Security.Authentication.SslProtocols.Tls12,
LocalCertificateSelectionCallback = (a,b,c,d,e) => c[0],
RemoteCertificateValidationCallback = (a,b,c,d) => true,
}
};
shh.SslOptions.ClientCertificates.Add(cert);
HttpClient c = new(shh);
var x = await c.GetAsync(new Uri(Url));
_ = 1;
}
catch (Exception e)
{
_ = e;
}
}
}
}