{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7092","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7092/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7092/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7092/events","html_url":"https://github.com/PowerShell/PowerShell/issues/7092","id":333065734,"node_id":"MDU6SXNzdWUzMzMwNjU3MzQ=","number":7092,"title":"The type or namespace name 'ICertificatePolicy' could not be found (Extracting Thumbprint for SHA256)","user":{"login":"lamw","id":602199,"node_id":"MDQ6VXNlcjYwMjE5OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/602199?v=4","gravatar_id":"","url":"https://api.github.com/users/lamw","html_url":"https://github.com/lamw","followers_url":"https://api.github.com/users/lamw/followers","following_url":"https://api.github.com/users/lamw/following{/other_user}","gists_url":"https://api.github.com/users/lamw/gists{/gist_id}","starred_url":"https://api.github.com/users/lamw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamw/subscriptions","organizations_url":"https://api.github.com/users/lamw/orgs","repos_url":"https://api.github.com/users/lamw/repos","events_url":"https://api.github.com/users/lamw/events{/privacy}","received_events_url":"https://api.github.com/users/lamw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-06-17T14:12:36Z","updated_at":"2018-06-18T10:07:46Z","closed_at":null,"author_association":"NONE","body":"FYI - I'm not sure if this is the *best* way to extract the SHA256 Thumbprint, but this has worked for me on Windows. If there is a better/recommended method that works on standard PowerShell for Windows as well PowerShell Core, I am definitely open to suggestion. \r\n\r\nSteps to reproduce\r\n------------------\r\n\r\n```powershell\r\nFunction Get-SSLThumbprint256 {\r\n    param(\r\n    [Parameter(\r\n        Position=0,\r\n        Mandatory=$true,\r\n        ValueFromPipeline=$true,\r\n        ValueFromPipelineByPropertyName=$true)\r\n    ]\r\n    [Alias('FullName')]\r\n    [String]$URL\r\n    )\r\n\r\nadd-type @\"\r\n        using System.Net;\r\n        using System.Security.Cryptography.X509Certificates;\r\n            public class IDontCarePolicy : ICertificatePolicy {\r\n            public IDontCarePolicy() {}\r\n            public bool CheckValidationResult(\r\n                ServicePoint sPoint, X509Certificate cert,\r\n                WebRequest wRequest, int certProb) {\r\n                return true;\r\n            }\r\n        }\r\n\"@\r\n    [System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy\r\n\r\n    # Need to connect using simple GET operation for this to work\r\n    Invoke-RestMethod -Uri $URL -Method Get | Out-Null\r\n\r\n    $ENDPOINT_REQUEST = [System.Net.Webrequest]::Create(\"$URL\")\r\n    $CERT = $ENDPOINT_REQUEST.ServicePoint.Certificate\r\n    # https://stackoverflow.com/a/22251597\r\n    $BYTES = $cert.Export([Security.Cryptography.X509Certificates.X509ContentType]::Cert)\r\n    Set-content -value $BYTES -encoding byte -path $ENV:TMP\\cert-temp\r\n    $SSL_THUMBPRINT = (Get-FileHash -Path $ENV:TMP\\cert-temp -Algorithm SHA256).Hash\r\n    return $SSL_THUMBPRINT -replace '(..(?!$))','$1:'\r\n}\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\n\r\nThe ability to extract the SHA256 SSL Thumbprint from a given endpoint. An example is provided below which works on standard Windows PowerShell 5.1 (5.1.17134.112 )\r\n\r\n```powershell\r\nGet-SSLThumbprint256 -URL \"https://google.com:443\"\r\nB9:B0:D3:46:36:83:13:6F:9E:32:80:61:0C:EC:0D:D2:1F:65:BE:3C:2F:81:92:CF:7B:C8:90:F1:71:2A:1C:F5\r\n```\r\n\r\nActual behavior\r\n---------------\r\n\r\nWhen performing this on latest PowerShell Core, the following error is thrown:\r\n```powershell\r\nGet-SSLThumbprint256 -URL \"https://google.com:443\"\r\nadd-type : (3) : The type or namespace name 'ICertificatePolicy' could not be found (are you missing a using directive or an assembly reference?)\r\n(2) :         using System.Security.Cryptography.X509Certificates;\r\n(3) : >>>             public class IDontCarePolicy : ICertificatePolicy {\r\n(4) :             public IDontCarePolicy() {}\r\nAt line:13 char:1\r\n+ add-type @\"\r\n+ ~~~~~~~~~~~\r\n+ CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception\r\n+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand\r\n\r\nadd-type : Cannot add type. Compilation errors occurred.\r\nAt line:13 char:1\r\n+ add-type @\"\r\n+ ~~~~~~~~~~~\r\n+ CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException\r\n+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand\r\n\r\nnew-object : Cannot find type [IDontCarePolicy]: verify that the assembly containing this type is loaded.\r\nAt line:25 char:59\r\n+ ... .ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy\r\n+                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException\r\n+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand\r\n\r\nYou cannot call a method on a null-valued expression.\r\nAt line:33 char:5\r\n+     $BYTES = $cert.Export([Security.Cryptography.X509Certificates.X50 ...\r\n+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException\r\n+ FullyQualifiedErrorId : InvokeMethodOnNull\r\n\r\nSet-Content : Cannot bind parameter 'Encoding'. Cannot convert the \"byte\" value of type \"System.String\" to type \"System.Text.Encoding\".\r\nAt line:34 char:41\r\n+     Set-content -value $BYTES -encoding byte -path /tmp/cert-temp\r\n+                                         ~~~~\r\n+ CategoryInfo          : InvalidArgument: (:) [Set-Content], ParameterBindingException\r\n+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SetContentCommand\r\n\r\nGet-FileHash : Cannot find path '/tmp/cert-temp' because it does not exist.\r\nAt line:35 char:24\r\n+ ... UMBPRINT = (Get-FileHash -Path /tmp/cert-temp -Algorithm SHA256).Hash ...\r\n+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo          : ObjectNotFound: (/tmp/cert-temp:String) [Get-FileHash], ItemNotFoundException\r\n+ FullyQualifiedErrorId : FileNotFound,Microsoft.PowerShell.Commands.GetFileHashCommand\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n```powershell\r\n> $PSVersionTable\r\nName                           Value\r\n----                           -----\r\nPSVersion                      6.0.2\r\nPSEdition                      Core\r\nGitCommitId                    v6.0.2\r\nOS                             Darwin 17.6.0 Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64\r\nPlatform                       Unix\r\nPSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}\r\nPSRemotingProtocolVersion      2.3\r\nSerializationVersion           1.1.0.1\r\nWSManStackVersion              3.0\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/398006028","html_url":"https://github.com/PowerShell/PowerShell/issues/7092#issuecomment-398006028","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/7092","id":398006028,"node_id":"MDEyOklzc3VlQ29tbWVudDM5ODAwNjAyOA==","user":{"login":"markekraus","id":6509955,"node_id":"MDQ6VXNlcjY1MDk5NTU=","avatar_url":"https://avatars3.githubusercontent.com/u/6509955?v=4","gravatar_id":"","url":"https://api.github.com/users/markekraus","html_url":"https://github.com/markekraus","followers_url":"https://api.github.com/users/markekraus/followers","following_url":"https://api.github.com/users/markekraus/following{/other_user}","gists_url":"https://api.github.com/users/markekraus/gists{/gist_id}","starred_url":"https://api.github.com/users/markekraus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markekraus/subscriptions","organizations_url":"https://api.github.com/users/markekraus/orgs","repos_url":"https://api.github.com/users/markekraus/repos","events_url":"https://api.github.com/users/markekraus/events{/privacy}","received_events_url":"https://api.github.com/users/markekraus/received_events","type":"User","site_admin":false},"created_at":"2018-06-18T10:07:46Z","updated_at":"2018-06-18T10:07:46Z","author_association":"COLLABORATOR","body":"For clarity, this is the result of changes in .NET and not PowerShell itself.\r\n\r\nAlso, I missed that you were doing the sha265 thumbprint, but you should be able to adapt your code with what I provided."}}
{"actor":{"display_login":"markekraus"}}