Skip to content

Commit 7dd03dc

Browse files
committed
update readme file
1 parent 9543b1d commit 7dd03dc

File tree

2 files changed

+92
-20
lines changed

2 files changed

+92
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- add nuget package icon
55
- enable deterministic build
66
- generate symbols package
7+
- update readme file
78
- test : fix pin
89

910
## 2.2.3

README.md

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,99 @@
1-
SecureHttpClient
2-
================
1+
# SecureHttpClient
32

4-
[![NuGet](https://img.shields.io/nuget/v/securehttpclient.svg?label=NuGet)](https://www.nuget.org/packages/securehttpclient/)
3+
SecureHttpClient is a dotnet cross-platform HttpClientHandler library, with additional security features.
54

6-
SecureHttpClient is a cross-platform HttpClientHandler library, with additional security features:
7-
- certificate pinning
8-
- TLS 1.2+
9-
- client certificates
5+
## Features
106

11-
Usage:
12-
- basic usage is similar to System.Net.Http.HttpClientHandler.
13-
- for advanced usage examples, look into the SecureHttpClient.Test folder.
7+
| Feature | Android | iOS | Windows |
8+
| ---: | :---: | :---: | :---: |
9+
| Certificate pinning | :white_check_mark: | :white_check_mark: | :white_check_mark: |
10+
| TLS 1.2+ | :white_check_mark: | :white_check_mark: | :white_check_mark: |
11+
| HTTP/2 | :white_check_mark: | :white_check_mark: | :white_check_mark: |
12+
| Compression (gzip / deflate / br) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
13+
| Client certificates | :white_check_mark: | :white_check_mark: | :white_check_mark: |
14+
| Headers ordering | :white_check_mark: | :x: | :x: |
15+
| Cookies | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1416

15-
Tested on the following platforms:
16-
- Android 5-14 (api 21-34)
17+
## Installation
18+
19+
[![NuGet](https://img.shields.io/nuget/v/SecureHttpClient)](https://www.nuget.org/packages/SecureHttpClient/)
20+
21+
The most recent version is available (and is tested) on the following platforms:
22+
- Android 5-14 (API 21-34)
1723
- iOS 17.2
1824
- .net 8.0
1925

20-
About cookies and redirects:
21-
- SecureHttpClient handles cookies and redirects, but the behavior can differ a bit from one platform to another, because of different implementations in the native libraries used by SecureHttpClient.
22-
- for identical behavior between platforms, it's recommended to use [Flurl](https://github.com/tmenier/Flurl) on top of SecureHttpClient, and let [Flurl](https://github.com/tmenier/Flurl) handle cookies and redirects.
26+
Older versions support older frameworks (but they are not maintained anymore):
27+
- v2.1: net7.0 (android / ios / windows)
28+
- v2.0: net6.0 (android / ios / windows)
29+
- v1.x: MonoAndroid ; Xamarin.iOS ; NetStandard
30+
31+
## Basic usage
32+
33+
Basic usage is similar to using `System.Net.Http.HttpClientHandler`.
34+
```csharp
35+
// create the SecureHttpClientHandler
36+
var secureHttpClientHandler = new SecureHttpClientHandler(null);
37+
38+
// create the HttpClient
39+
var httpClient = new HttpClient(secureHttpClientHandler);
40+
41+
// example of a simple GET request
42+
var response = await httpClient.GetAsync("https://www.github.com");
43+
var html = await response.Content.ReadAsStringAsync();
44+
```
45+
46+
## Certificate pining
47+
48+
After creating a `SecureHttpClientHandler` object, call `AddCertificatePinner` to add one or more certificate pinner.
49+
50+
The request will fail if the certificate pin is not correct.
51+
52+
```csharp
53+
// create the SecureHttpClientHandler
54+
var secureHttpClientHandler = new SecureHttpClientHandler(null);
55+
56+
// add certificate pinner
57+
secureHttpClientHandler.AddCertificatePinner("www.github.com", ["sha256/YH8+l6PDvIo1Q5o6varvw2edPgfyJFY5fHuSlsVdvdc="]);
58+
59+
// create the HttpClient
60+
var httpClient = new HttpClient(secureHttpClientHandler);
61+
62+
// example of a simple GET request
63+
var response = await httpClient.GetAsync("https://www.github.com");
64+
var html = await response.Content.ReadAsStringAsync();
65+
```
66+
67+
In order to compute the pin (SPKI fingerprint of the server's SSL certificate), you can execute the following command (here for `www.github.com` host):
68+
```shell
69+
openssl s_client -connect www.github.com:443 -servername www.github.com | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | openssl x509 -noout -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
70+
```
71+
72+
## Cookies and Redirect
73+
74+
SecureHttpClient handles cookies and redirects, but the behavior can differ a bit from one platform to another, because of different implementations in the native libraries used internally.
75+
76+
For strictly identical behavior between platforms, it's recommended to use [Flurl](https://github.com/tmenier/Flurl) on top of SecureHttpClient, and let it handle cookies and redirects.
77+
78+
```csharp
79+
// create the SecureHttpClientHandler
80+
var secureHttpClientHandler = new SecureHttpClientHandler(null);
81+
82+
// disable redirect and cookies management in this handler
83+
secureHttpClientHandler.AllowAutoRedirect = false;
84+
secureHttpClientHandler.UseCookies = false;
85+
86+
// create the FlurlClient and CookieSession, they will manage redirect and cookies
87+
var httpClient = new HttpClient(secureHttpClientHandler);
88+
var flurlClient = new FlurlClient(httpClient);
89+
var flurlSession = new CookieSession(flurlClient);
90+
91+
// example of a simple GET request using Flurl
92+
var html = await flurlSession
93+
.Request("https://www.github.com")
94+
.GetStringAsync();
95+
```
96+
97+
## Advanced usage
2398

24-
Supported frameworks:
25-
- version 1.x: MonoAndroid ; Xamarin.iOS ; NetStandard
26-
- version 2.0: net6.0-android ; net6.0-ios ; net6.0-windows
27-
- version 2.1: net7.0-android ; net7.0-ios ; net7.0-windows
28-
- version 2.2: net8.0-android ; net8.0-ios ; net8.0-windows
99+
For more advanced usage (logging, client certificates, cookies ordering...), have a look into the SecureHttpClient.Test folder for more code examples.

0 commit comments

Comments
 (0)