-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmtls.pwn
More file actions
41 lines (36 loc) · 1.19 KB
/
mtls.pwn
File metadata and controls
41 lines (36 loc) · 1.19 KB
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
// mtls.pwn — install a client certificate identity for mutual TLS.
//
// Demonstrates:
// * Loading a combined PEM (cert + key) from disk.
// * Issuing a request that automatically uses the installed identity.
// * Clearing the identity when done.
#include <a_samp>
#include <https_samp>
public OnGameModeInit()
{
// The PEM file must contain both the client certificate and the private
// key. Files larger than 256 KiB are refused by the loader.
if (!https_mtls_set_pem_file("scriptfiles/client-identity.pem"))
{
print("[example] failed to install mTLS identity");
return 1;
}
// All subsequent requests use the installed identity until cleared.
https(1, HTTPS_GET, "https://mtls.example.com/whoami", "", "OnMtlsDone");
return 1;
}
forward OnMtlsDone(index, response[], status, error);
public OnMtlsDone(index, response[], status, error)
{
if (error != HTTPS_ERROR_NONE)
{
printf("[example] mtls req %d failed: error=%d", index, error);
}
else
{
printf("[example] mtls req %d ok: status=%d", index, status);
}
// Remove the identity now that the protected call is done.
https_mtls_clear();
return 1;
}