SSL Certificates

Checks exipery days for SSL certificate accepts one argument in the form of a URL with Socket and returns statistic in days

Example: www.google.com:443
  • FormerMember
    FormerMember

    Awesome script d4less!  I modified is slightly so that I don't need to manually modify the temporary text file for each script.  It parses out what you pass in and uses the hostname prior to :<port> and adds .txt to the end.  Here is the full script with my modification:

    <script>

    Option Explicit

    Dim oShell

    Dim ArgObj

    Dim Fh

    Dim FSO

    Dim Line

    Dim Expiry

    Dim DaysLeft

    Dim ExpDate

    Dim oExec

    Dim cert

    Dim tstream

    Dim i

    Dim str

    Dim PluginPath

    Dim CertFilePath

    Dim char

    Dim XString

    Dim colonIndex

    Dim name

    Const ForReading = 1

    colonIndex = InStrRev( wscript.Arguments(0), ":" )

    name = Mid( wscript.Arguments(0), 1, colonIndex-1 ) & ".txt"

    CertFilePath = "C:\TMP\" & name

    PluginPath = "C:\OpenSSL\bin\"

    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set tstream = FSO.createtextfile(CertFilePath, True)

    ArgObj = wscript.Arguments(0)

    Set oShell = wscript.CreateObject("WScript.Shell")

    'Calling funtion to retieve the host

    Set oExec = oShell.exec(PluginPath & "openssl.exe s_client -connect " & ArgObj)

    'Write the certificate into a text file

    Do Until oExec.StdOut.AtEndOfStream

        char = oExec.StdOut.Read(1)

        tstream.Write (char)

        If Len(XString) < 20 Then

    XString = XString & char

        ElseIf XString = "END CERTIFICATE-----" Then

    Exit Do

        Else

    XString = Mid(XString, 2, 19)

    XString = XString & char

        End If

    Loop

    tstream.Close

    oExec.Terminate

    'Read SSL certificate for start date and end date

    Set oExec = oShell.exec(PluginPath & "openssl.exe x509 -noout -in " & CertFilePath & " -dates")

    'Return start date and end date of the certificate

    Line = oExec.StdOut.Readall

    'Get the expiration date of the certificate

    Expiry = (Mid(Line, Len(Line) - 24, 24))

    ExpDate = ConvertDate(Expiry)

    'Calculating number of days

    DaysLeft = DateDiff("d", Now(), ExpDate)

    'Display the number of days remaining until expiration

    wscript.echo "Statistic: " & DaysLeft

    wscript.echo "Message: " & wscript.Arguments(0) & " expires in " & DaysLeft & " days"

    'Object Closing code

    oExec.Terminate

    Set oShell = Nothing

    Set oExec = Nothing

    'This function converts the date into the required format

    Function ConvertDate(DateStr)

    Dim Components

    Dim Month

    Dim Day

    Dim Year

    Components = Split(DateStr)

    Select Case Components(0)

        Case "Jan", "January"

        Month = 1

        Case "Feb", "February"

        Month = 2

        Case "Mar", "March"

        Month = 3

        Case "Apr", "April"

        Month = 4

        Case "May"

        Month = 5

        Case "Jun", "June"

        Month = 6

        Case "Jul", "July"

        Month = 7

        Case "Aug", "August"

        Month = 8

        Case "Sep", "Sept", "September"

        Month = 9

        Case "Oct", "October"

        Month = 10

        Case "Nov", "November"

        Month = 11

        Case "Dec", "December"

        Month = 12

    Case Else

        Month = 1

    End Select

        Day = Components(1)

        Year = Components(3)

    If UBound(Components) = 5 Then

        Day = Components(2)

        Year = Components(4)

    Else

        Day = Components(1)

        Year = Components(3)

    End If

    ConvertDate = CDate(Day & "/" & Month & "/" & Year)

    End Function

    </script>

  • FormerMember
    FormerMember
    Hey I am getting error on last line " specified file doesn't exist" on this like " Set oExec = oShell.exec(PluginPath & "openssl.exe s_client -connect " & ArgObj)"

    ---start script from here----

    Option Explicit

    Dim oShell
    Dim ArgObj
    Dim Fh
    Dim FSO
    Dim Line
    Dim Expiry
    Dim DaysLeft
    Dim ExpDate
    Dim oExec
    Dim cert
    Dim tstream
    Dim i
    Dim str
    Dim PluginPath
    Dim CertFilePath
    Dim char
    Dim XString

    Const ForReading = 1

    CertFilePath = "C:\TMP\cert99.txt"
    PluginPath = "C:\OpenSSL-Win32\bin"

    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set tstream = FSO.createtextfile(CertFilePath, True)

    ArgObj = wscript.Arguments(0)

    Set oShell = wscript.CreateObject("WScript.Shell")

    'Calling funtion to retieve the host
    Set oExec = oShell.exec(PluginPath & "openssl.exe s_client -connect " & ArgObj)

  • New SSL monitor posted on APM content doesn't require the botch of having to use external executable, done through Powershell making use of built in .net . As you can assign the template to a windows box to run the script locally and point the URL to anything that has a web server and certificates, a lamp server or whatever
  • I'm having the same issue with a much shorter script. It appears that StdOut isn't returning any data when used through Orion APM. The same script works as a VBS on the same machine. I've pasted the code below. As you can see, most is commented out to try to isolate the issue. The issue seems to be that StdOut just isn't passing anything. It causes Mid to fail as well. Any comments/suggestions would be appreciated.

    Dim WshShell,oExec,fso,fout
    Set WshShell = CreateObject("WScript.Shell")
    Set oExec = WshShell.Exec("cmd /c schtasks /query /fo list /v /s {ServerName}")
    'Set fso = CreateObject("Scripting.FileSystemObject")

    strHold = oExec.StdOut.ReadAll
    'intLast = Instr(1,strHold,"Power Management")
    'strResult = Trim(Mid(strHold,Instr(1,strHold,"Creator")-7,5))
    'strResult2 = Trim(Mid(strHold,Instr(intLast,strHold,"Creator")-7,5))

    'strNextRun = Trim(Mid(strHold,Instr(1,strHold,"Status")-24,22))
    'strNextRun2 = Trim(Mid(strHold,Instr(intLast,strHold,"Status")-24,22))

    'strMessage = "Backup - Result:" & strResult & " Next Run:" & strNextRun & _
    ' " MoveBackup - Result:" & strResult2 & " Next Run:" & strNextRun2

    WScript.Echo "Message:" & Instr(1,strHold,"Status")
    WScript.Echo "Statistic:0"
    'WScript.Echo "Message:" & strMessage
    'WScript.Echo "Statistic:" & strResult + strResult2
  • As per script above, 2 mods; 1 to truncate the certificate lenght to stop error and only take what is needed
    2. In the convert exipery date function to handle some certificates returning a space rather than a zero in the date, had date returned as NOV2 rather then NOV02, (splitDate function relies on space as delimiter)