Friday, June 14, 2019

HTTPS Cert Expired and I don't care

Cert expiration is the bain of web administrators and Internet Web Properties.
use to be, you had to pay richly for the grand privilege of having a certificate on your website.
Now it just a matter of course.

Use this PowerShell incantation to set the "I Don't Care" on the certificate checking code.


[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }


Yes, I know it is not secure now, but I need to get to the site for testing or whatever, and I am willing to accept a connection to allow me to do what I need. 

* Use of course at your own risk. 

Enable Proxy server settings in PowerShell

proxy servers don't like you to go straight to the internet.

you get an error something like:

Invoke-WebRequest :
This Page Cannot Be Displayed
Authentication is required to access the Internet using this system. A valid user ID and password must be entered when prompted.

so you need to give this Powershell Incantation

#Proxy
$wc = New-Object Net.WebClient
    $wc.UseDefaultCredentials = $true
    $wc.Proxy.Credentials = $wc.Credentials

You can guess from this that you can actually set proxy credentials with this. But I haven't worked that out yet.

Web-request all TLS modes

I had fits and starts connecting to servers that had the TLS hardening put on them for web requests.
And a simple setting allowed you to connect to tls1.2 configured web servers.

However, since I was writing a script that could talk to any mode TLS server Like a normal web browser,  I experiment with my limited understanding of .NET request and came up with a short but sweet way to set it.

The I painfully discovered that if you set this more than 2 times, then webrequests would break.
So I added a check to see if it was set, so if this gets in a loop the access doesn't break.


#enable TLS*
if ([Net.ServicePointManager]::SecurityProtocol -ne
    ([Net.SecurityProtocolType].GetEnumNames() |
        ? { $_ -like "Tls*" }))
{
    [Net.ServicePointManager]::SecurityProtocol =
    ([Net.SecurityProtocolType].GetEnumNames() |
        ? { $_ -like "Tls*" }) }
br /> You can set a servers TLS and Crypto setting with:
  http://www.hass.de/content/setup-your-iis-ssl-perfect-forward-secrecy-and-tls-12
  By Alexander Hass
        at your own risk.

I modified his script to not disable any the TLS modes so This could be applied without risk to servers to fix access problems without creating a new problem for apps / scripts that can't ope with TLS ver 1&2
(Which is not to say some other archaic system might have a sezure with changing the criypto settings.