bin/Invoke-VerifySubject.ps1

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
function Invoke-VerifySubject
{
    # Determine if a Client Cert exist in the Request.
    if ($null -ne $script:ClientCert)
    {
        # First, Validate that the RootCA matches.
        . $RestPSLocalRoot\bin\Invoke-VerifyRootCA.ps1
        $script:VerifyStatus = Invoke-VerifyRootCA
        if ($script:VerifyStatus -eq $true)
        {
            # Root CA Matched, Verifying the ACL list
            . $RestPSLocalRoot\bin\Get-RestAclList.ps1
            $RestACL = Get-RestAclList
            Write-Output "ACL is:" $RestACL
            if ($null -ne $RestACL)
            {
                $RawSubject = $script:ClientCert.Subject
                $1, $script:Subject = $RawSubject.split("=")
                Write-Output "Subject name is" $script:Subject
                if ($null -ne $script:Subject)
                {
                    if ($RestACL.contains($script:Subject))
                    {
                        Write-Output "Client access is Verified."
                        $script:VerifyStatus = $true
                    }
                    else
                    {
                        Write-Output "Client does not exist in ACL."
                        $script:VerifyStatus = $false
                    }
                }
                else
                {
                    Write-Output "Client Subject Name does not exist."
                    $script:VerifyStatus = $false
                }
            }
            else
            {
                Write-Output "No ACL list available."
                $script:VerifyStatus = $false
            }
        }
        else
        {
            Write-Output "The Root CA did not match, Not attempting to Validate ACL List."
            $script:VerifyStatus = $false
        }
    }
    else
    {
        Write-Output "No Client Certificate Received."
        $script:VerifyStatus = $false
    }
    $script:VerifyStatus
}