Client Certificate
Client certificate authentication for PowerShell Universal.
Client certificate authentication ensures that client machines hold a particular certificate when connecting to PowerShell Universal. The certificate check is handled during the HTTP negotiation so it affects the entire webserver and cannot be configured per route.
For detailed information about client certificate authentication in ASP.NET Core 5.0, you can visit the Microsoft documentation here.

Enable Client Certificate Authentication

You will need to enable HTTPS hosting and turn on client certificate authentication. First, ensure that you have an HTTP certificate selected and you have set the ClientCertificateMode to RequireCertificate. These settings can be set within the appsettings.json file.
1
"Kestrel": {
2
"Endpoints": {
3
"HTTPS": {
4
"Url": "https://*:5000",
5
"ClientCertificateMode": "RequireCertificate",
6
"Certificate": {
7
"Subject": "localhost",
8
"Store": "My",
9
"Location": "LocalMachine",
10
"AllowInvalid": "true"
11
}
12
}
13
},
14
"RedirectToHttps": "false"
15
},
Copied!
Next, you will need to enable client certificate authentication.
1
"ClientCertificate": {
2
"Enabled": "true"
3
},
Copied!

Authorization

You can use the roles.ps1 file to evaluate the certificate provided by the client. This can be used to determine which roles the user will receive when connecting to PSU.
To evaluate the properties that are available during authorization, you can serialize the $user variable provided to the role policy functions.
1
param($User)
2
3
$User | ConvertTo-Json | Out-File .\user.txt
4
5
$true
Copied!
You will receive information about the certificate within the user object similar to below.
1
{
2
"Claims": [
3
{
4
"Type": "issuer",
5
"Value": "CN=Cert1, OU=Cert2, O=Org, L=Scottsdale, S=Arizona, C=US",
6
"ValueType": "http://www.w3.org/2001/XMLSchema#string",
7
"Issuer": "LOCAL AUTHORITY",
8
"Properties": "System.Collections.Generic.Dictionary`2[System.String,System.String]"
9
},
10
{
11
"Type": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint",
12
"Value": "8D2212B6EA170A33055A5",
13
"ValueType": "http://www.w3.org/2001/XMLSchema#base64Binary",
14
"Issuer": "LOCAL AUTHORITY",
15
"Properties": "System.Collections.Generic.Dictionary`2[System.String,System.String]"
16
},
17
{
18
"Type": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/x500distinguishedname",
19
"Value": "CN=*.cert.com, OU=Domain Control Validated",
20
"ValueType": "http://www.w3.org/2001/XMLSchema#string",
21
"Issuer": "LOCAL AUTHORITY",
22
"Properties": "System.Collections.Generic.Dictionary`2[System.String,System.String]"
23
},
24
{
25
"Type": "http://schemas.microsoft.com/ws/2008/06/identity/claims/serialnumber",
26
"Value": "009D21369",
27
"ValueType": "http://www.w3.org/2001/XMLSchema#string",
28
"Issuer": "LOCAL AUTHORITY",
29
"Properties": "System.Collections.Generic.Dictionary`2[System.String,System.String]"
30
},
31
{
32
"Type": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns",
33
"Value": "*.cert.com",
34
"ValueType": "http://www.w3.org/2001/XMLSchema#string",
35
"Issuer": "LOCAL AUTHORITY",
36
"Properties": "System.Collections.Generic.Dictionary`2[System.String,System.String]"
37
},
38
{
39
"Type": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
40
"Value": "*.cert.com",
41
"ValueType": "http://www.w3.org/2001/XMLSchema#string",
42
"Issuer": "LOCAL AUTHORITY",
43
"Properties": "System.Collections.Generic.Dictionary`2[System.String,System.String]"
44
}
45
],
46
"Identity": {
47
"Name": "*.cert.com"
48
}
49
}
50
Copied!
You can evaluate the the claims using the HasClaim method. The following is an example of checking the thumbprint of the certificate.
1
param($User)
2
3
$User.HasClaim('http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint', '8D2212B6EA170A33055A5')
Copied!
Last modified 14d ago