Skip to main content

How to Check your SSL Certificate Activation Automatically in Windows

 I am currently waiting for Google to activate the SSL certificate on my custom domain name. Instead of checking every so often manually, I have created a small Power Shell script to do it for me every 30 minutes. If the certificate becomes valid, it opens the URL in your default browser. I am sharing the code below. You should just have to paste it in a file, and then execute the file in a Windows Power Shell interface.

 

 # VARIABLES TO CHANGE:
# This is the number of seconds the program will wait before checking the certificate again
$intervalInSeconds = 1800
# This is the URL you want to check the certificate of.
$urlToCheck = "https://google.ca"


function Get-PublicKey {
    PARAM (
        [Uri]$Uri
    )

    if (-Not ($uri.Scheme -eq "https")) {
        Write-Error "You can only get keys for https addresses"
        return
    }

    $request = [System.Net.HttpWebRequest]::Create($uri)

    try {
        #Make the request but ignore (dispose it) the response, since we only care about the service point
        $request.GetResponse().Dispose()
        Start-Process $uri
    }
    catch [System.Net.WebException] {
        if ($_.Exception.Status -eq [System.Net.WebExceptionStatus]::TrustFailure) {
            #The ServicePoint object should now contain the Certificate for the site.
            $servicePoint = $request.ServicePoint
            # $key = $servicePoint.Certificate.GetPublicKey()
            $name = $servicePoint.Certificate.GetName()
            Write-Output $name
            throw
            #We ignore trust failures, since we only want the certificate, and the service point is still populated at this point
        }
        else {
            #Let other exceptions bubble up, or write-error the exception and return from this method
            throw
        }
    }

}

function Confirm-SslCertificate {
    param (
        [string]$URL
    )
    Write-Output "Running..."
    $doRun = 1
    while ($doRun -eq 1) {
        try {
            Get-PublicKey($URL)
            Write-Output "The certificate is correct!"
            $doRun = 0
        
        }
        catch {
            # wait 30 minutes before checking again
            $now = Get-Date -Format "HH:mm"
            $message = $now + "  Trust failure, checking again later"
            Write-Output $message
            Start-Sleep -Seconds $intervalInSeconds
        
        }
    
    }
}

Confirm-SslCertificate($urlToCheck)

Comments

Popular posts from this blog

Installing Postgres on Linux Lite (Ubuntu)

I have followed these instructions from the Postgres documentation : # Create the file repository configuration: sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' # Import the repository signing key: wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - # Update the package lists: sudo apt-get update # Install the latest version of PostgreSQL. # If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql': sudo apt-get -y install postgresql   After that, I was having trouble authenticating to Postgresql after installing the db server on Linux Lite.  This stackoverflow answer was very helpful. Open the file pg_hba.conf . For Ubuntu, use for example /etc/postgresql/13/main$ sudo nano pg_hba.conf and change this line at the bottom of the file, it should be the first line of the settings: local all ...

Fixing x-invalid-end-tag lint error on Vuejs

  My situation is: Coding with vue in a Vue file. Using the Vetur plugin in VS code It then generates an error of type x-invalid-end-tag in a quite random fashion. To solve it, I have found one simple trick in this github issue: // .eslintrc.js module.exports = {  //... rules:  { 'vue/no-parsing-error': [2, { 'x-invalid-end-tag': false }]  }  }

Building a chess game in Go

Context  I have recently decided to focus my efforts on the Go programming language. I have used it professionally before and it is a pleasure to go back to it. I really enjoy working with it. In order to practice, I have created a very crude chess game. You can see the code on Github here: https://github.com/nakurai/go-chess-game.    I have tried several time to build the chess logic, and gave up every time. I am very happy to have completed it. I used the most naive data structures and algorithms in this logic, but that's how I was able to complete it. To handle the UI, I used Ebitengine . The documentation is quite sparse (at least for now) but it is a very neat library. I would like to do more with it in the future. As you can see in the video, the "AI" is for now very trivial. It just picks a move randomly among all the possible ones available. Challenges  In terms of challenges, learning how to use the game engine while ramping up my skills in Go was the main c...