{"id":19266969,"url":"https://github.com/webmd-health-services/tlscertificatevalidation","last_synced_at":"2025-07-07T08:08:46.426Z","repository":{"id":42514929,"uuid":"476012389","full_name":"webmd-health-services/TlsCertificateValidation","owner":"webmd-health-services","description":"A PowerShell module that enables and disables TLS server certificate validation, and allows you to register your own server certificate validation logic in pure PowerShell.","archived":false,"fork":false,"pushed_at":"2024-12-04T20:29:49.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-05T12:12:21.505Z","etag":null,"topics":["powershell","powershell-module","ssl","ssl-certificate","ssl-certificate-check","tls","tls-certificate","tls-certificate-checker"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webmd-health-services.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-30T18:53:01.000Z","updated_at":"2024-12-04T19:57:05.000Z","dependencies_parsed_at":"2024-04-23T21:21:09.793Z","dependency_job_id":"e0d0cc0d-e052-4515-b0ad-0b11da8f0846","html_url":"https://github.com/webmd-health-services/TlsCertificateValidation","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":"webmd-health-services/Template-PSModule-OSS-Apache2.0-AppVeyor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webmd-health-services%2FTlsCertificateValidation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webmd-health-services%2FTlsCertificateValidation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webmd-health-services%2FTlsCertificateValidation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webmd-health-services%2FTlsCertificateValidation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webmd-health-services","download_url":"https://codeload.github.com/webmd-health-services/TlsCertificateValidation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240367593,"owners_count":19790279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["powershell","powershell-module","ssl","ssl-certificate","ssl-certificate-check","tls","tls-certificate","tls-certificate-checker"],"created_at":"2024-11-09T20:08:38.849Z","updated_at":"2025-02-23T19:29:12.818Z","avatar_url":"https://github.com/webmd-health-services.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--markdownlint-disable MD012 no-multiple-blanks--\u003e\r\n\r\n# TlsCertificateValidation PowerShell Module\r\n\r\n## Overview\r\n\r\nThe \"TlsCertificateValidation\" PowerShell module allows you to manage how Windows PowerShell's `Invoke-WebRequest` and\r\n`Invoke-RestMethod` cmdlet validate TLS server certificates. With it, you can:\r\n\r\n* Completely disable TLS server certificate validation, with its `Disable-TlsCertificateValidation` function.\r\n* Write your own server certificate validation in PowerShell with its `Set-TlsCertificateValidator` function.\r\n* Check if PowerShell supports the `SkipCertificateCheck` switch on `Invoke-WebRequest` and `Invoke-RestMethod` with its\r\n  `Test-SkipCertificateChec` function.\r\n\r\n\r\n## System Requirements\r\n\r\n* Windows PowerShell 5.1 and .NET 4.8\r\n* PowerShell 6+ [1]\r\n\r\n## A Note About PowerShell 6 Support\r\n\r\nThis module uses the global `[Net.ServicePointManager]::ServerCertificateValidationCallback` callback to wire up custom\r\nvalidation. In PowerShell 6+, the `Invoke-WebRequest` and `Invoke-RestMethod` functions don't use this global callback,\r\nand instead have a `SkipCertificateCheck` switch to disable server certificate validation. This module will not work\r\non PowerShell 6+ when trying to bypass server certificate checks that fail under `Invoke-WebRequest` and\r\n`Invoke-RestMethod`. This module should work with other .NET classes that use the\r\n`[Net.ServicePointManager]::ServerCertificateValidationCallback` callback.\r\n\r\n\r\n## Installing\r\n\r\nTo install globally:\r\n\r\n```powershell\r\nInstall-Module -Name 'TlsCertificateValidation'\r\nImport-Module -Name 'TlsCertificateValidation'\r\n```\r\n\r\nTo install privately:\r\n\r\n```powershell\r\nSave-Module -Name 'TlsCertificateValidation' -Path '.'\r\nImport-Module -Name '.\\TlsCertificateValidation'\r\n```\r\n\r\n## Usage\r\n\r\n```powershell\r\n$iwrArgs = @{}\r\nif( (Test-SkipCertificateCheck) )\r\n{\r\n    $iwrArgs['SkipCertificateCheck'] = $true\r\n}\r\nelse\r\n{\r\n    Disable-TlsCertificateValidation\r\n}\r\n\r\ntry\r\n{\r\n    Invoke-WebRequest -Uri 'https://expired.badssl.com/' @iwrArgs\r\n}\r\nfinally\r\n{\r\n    if( -not (Test-SkipCertificateCheck) )\r\n    {\r\n        Enable-TlsCertificateValidation\r\n    }\r\n}\r\n```\r\n\r\n\r\n## Commands\r\n\r\n### Disable-TlsCertificateValidation\r\n\r\nDisables all TLS server certificate validation by accepting all certificates.\r\n\r\n```powershell\r\nDisable-TlsCertificateValidation\r\n```\r\n\r\n### Enable-TlsCertificateValidation\r\n\r\nRe-enables PowerShell's default server certificate validation behavior.\r\n\r\n```powershell\r\nEnable-TlsCertificateValidation\r\n```\r\n\r\n### Set-TlsCertificateValidator\r\n\r\nUse your own code to validate TLS server certificates:\r\n\r\n```powershell\r\nSet-TlsCertificateValidator -ScriptBlock {\r\n    param(\r\n        [Object] $Sender,\r\n\r\n        [Security.Cryptography.X509Certificates.X509Certificate2] $Certificate,\r\n\r\n        [Security.Cryptography.X509Certificates.X509Chain] $Chain,\r\n\r\n        [Net.Security.SslPolicyErrors] $PolicyErrors\r\n    )\r\n\r\n    # Callback always gets called, even if there are no errors, so make sure you add this if you don't care about valid\r\n    # certificates.\r\n    if( $PolicyErrors -eq [Net.Security.SslPolicyErrors]::None )\r\n    {\r\n        return $true\r\n    }\r\n\r\n    if( $Certificate.Issuer -eq $Certificate.Subject )\r\n    {\r\n        return $true\r\n    }\r\n\r\n    return $false\r\n}\r\n```\r\n\r\nThe above example demonstrates a server certificate validation script block that accepts self-signed certificates.\r\n\r\n### Clear-TlsCertificateValidator\r\n\r\nRemoves your custom validator. Call this function once you've finished making requests, otherwise your validator will\r\ncontinue to be used in the current PowerShell session.\r\n\r\n```powershell\r\nClear-TlsCertificateValidator\r\n```\r\n\r\n### Test-SkipCertificateCheck\r\n\r\nUse this function if you want to support multiple versions of PowerShell and some of those versions don't have the\r\n`SkipCertificateCheck` functionality. Returns `$true` if PowerShell's `Invoke-WebRequest` and `Invoke-RestMethod`\r\ncmdlets have the `SkipCertificateCheck` switch. Return `$false` otherwise.\r\n\r\n```powershell\r\n$iwrArgs = @{}\r\nif( (Test-SkipCertificateCheck) )\r\n{\r\n    $iwrArgs['SkipCertificateCheck'] = $true\r\n}\r\nelse\r\n{\r\n    Disable-TlsCertificateValidation\r\n}\r\n\r\ntry\r\n{\r\n    Invoke-WebRequest -Uri 'https://expired.badssl.com/' @iwrArgs\r\n}\r\nfinally\r\n{\r\n    if( -not (Test-SkipCertificateCheck) )\r\n    {\r\n        Enable-TlsCertificateValidation\r\n    }\r\n}\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebmd-health-services%2Ftlscertificatevalidation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebmd-health-services%2Ftlscertificatevalidation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebmd-health-services%2Ftlscertificatevalidation/lists"}