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

How to generate a self-signed certificate with Openssl (using git windows bash)

I recently needed to generate a self-signed certificate to test a website locally. I wasn't familiar with the process, and I wanted to share here what I learned. First, we need a private key. A private key is a long series of characters that must be kept secret. In my context, it will be used to encrypt messages before the client and the server, in a way secure enough to prevent anybody to spy on them. Once the private key is created, we need to generate another file that will be the "signature" of our certificate. Among other data, this file will contains some information specific to the server's context: country, organization's name, email address of the organization's technical contact, etc. Once this signature is established, there are two paths: - Path A: If we want our server to be publicly accessible, every browser in the world must able to trust the certificate. In order for that to happen, we need to send our signature file to one of the official SSL ...

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 }]  }  }

Connecting to MongoDB from WSL2

My application runs a web server connected to a MongoDB database. For all my development needs, I am using WSL on windows 10. Unfortunately, MongoDB is not available on WSL, so I have installed the Windows version and pointed my server to the localhost:27017 address, no issue. It worked well until the day I switched to WSL2. Then I would get some ECONNREFUSED errors. To solve this problem, I have found a simple three steps solution.  The whole idea is that WSL2 now uses a true VM and got its own network interface (IP, MAC address, etc.). I think it's a bit more complicated than that, but that's how I understand it. Long story short, you now have a windows IP, and a WSL IP. 1. Accessing  the windows host from WSL The first step is to make sure that you can ping the windows IP from WSL. It was not working for me right away. It seems like there are still inconsistencies in the WSL implementation, but this github issue thread gave a good solution. It's a script yo have to run...