aviv18

certificate expiration check script

2 posts in this topic

Hi! 
We are using smartcards. 
I want to send an email/popup message to the user 30 days before user certificate expired. 
the cached certificates are stored in for any user in : current user\personal\certificates . 
  
does someone have a script for that? 
  

Thanks, 
Aviv Hassidim 

Share this post


Link to post
Share on other sites



Some time ago I started to play with

Certificate Enrollment API
https://msdn.microsoft.com/en-us/library/windows/desktop/aa374863(v=vs.85).aspx

Here is what I get so far:

#include <MsgBoxConstants.au3>


_Example()
Func _Example()
    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    Local $oCX509PrivateKey = ObjCreate("X509Enrollment.CX509PrivateKey.1")
    If @error Then MsgBox($MB_ICONERROR, '', _
            '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    Local $oCX509CertificateRequestCertificate = ObjCreate("X509Enrollment.CX509CertificateRequestCertificate")
    If @error Then MsgBox($MB_ICONERROR, '', _
            '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    Local $oCSP1 = $oCX509CertificateRequestCertificate.Initialize(1)
    Local $oCSP_Coll = $oCX509CertificateRequestCertificate.CspInformations
    Local $oCSP_Unizeto = Null

    For $oCSP_enum In $oCSP_Coll
;~      ConsoleWrite('$oCX509CertificateRequestCertificate.IsSmartCard=' & $oCX509CertificateRequestCertificate.IsSmartCard & @CRLF)
        ConsoleWrite('$oCSP_enum.Name=' & $oCSP_enum.Name & @CRLF)
        ConsoleWrite('$oCSP_enum.Type=' & $oCSP_enum.Type & @CRLF)
        If $oCSP_enum.Name = 'cryptoCertum3 CSP - profil bezpieczny' Then
            $oCSP_Unizeto = $oCSP_enum
        EndIf
        ConsoleWrite('$oCSP_enum.IsSmartCard=' & $oCSP_enum.IsSmartCard & @CRLF)
        ConsoleWrite('$oCSP_enum.IsSoftwareDevice=' & $oCSP_enum.IsSoftwareDevice & @CRLF)
        ConsoleWrite('$oCSP_enum.KeySpec=' & $oCSP_enum.KeySpec & @CRLF)
        ConsoleWrite('$oCSP_enum.LegacyCsp=' & $oCSP_enum.LegacyCsp & @CRLF)
        ConsoleWrite('$oCSP_enum.Valid=' & $oCSP_enum.Valid & @CRLF)
        ConsoleWrite('$oCSP_enum.Version=' & $oCSP_enum.Version & @CRLF)
        ConsoleWrite('' & @CRLF)

    Next
    If @error Then MsgBox($MB_ICONERROR, '', _
            '@error = ' & @error & @CRLF & '@extended = ' & @extended)

    $oCSP_Unizeto.InitializeFromName('cryptoCertum3 CSP - profil bezpieczny')

    $oCX509PrivateKey.CspInformations = $oCSP_Coll

;~  $oCX509PrivateKey.CspInformations
    $oCX509PrivateKey.Silent = False
    $oCX509PrivateKey.ProviderName = 'cryptoCertum3 CSP - profil bezpieczny'
    $oCX509PrivateKey.ProviderType = 1
    MsgBox(0, '', $oCX509PrivateKey.SecurityDescriptor)
    $oCX509PrivateKey.Open()
;~  ConsoleWrite('$oCX509PrivateKey.CspStatus=' & $oCX509PrivateKey.CspStatus & @CRLF)
;~  ConsoleWrite('$oCX509PrivateKey.UniqueContainerName=' & $oCX509PrivateKey.UniqueContainerName & @CRLF)
;~  ConsoleWrite('$oCX509PrivateKey.UIContextMessage=' & $oCX509PrivateKey.UIContextMessage & @CRLF)
    ConsoleWrite('$oCX509PrivateKey.MachineContext=' & $oCX509PrivateKey.MachineContext & @CRLF)
;~  MsgBox(0, '', $oCX509PrivateKey.ReaderName)
;~  MsgBox(0, '', $oCX509PrivateKey.ProviderType)
;~  MsgBox(0, '', $oCX509PrivateKey.ProviderName)
;~  MsgBox(0, '', $oCX509PrivateKey.FriendlyName)
    ConsoleWrite('$oCX509PrivateKey.DefaultContainer=' & $oCX509PrivateKey.DefaultContainer & @CRLF)
    ConsoleWrite('$oCX509PrivateKey.Opened=' & $oCX509PrivateKey.Opened & @CRLF)


EndFunc    ;==>_Example



; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc    ;==>_ErrFunc


#Region  HOW TO , GUID, DOC

#cs
    http://blogs.technet.com/b/vishalagarwal/archive/2009/08/22/generating-a-certificate-self-signed-using-powershell-and-certenroll-interfaces.aspx

    Security Descriptor String Format
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa379570(v=vs.85).aspx

    ACE Strings
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa374928(v=vs.85).aspx

    How to create a certificate request with CertEnroll (JavaScript)
    https://blogs.msdn.microsoft.com/alejacma/2009/01/28/how-to-create-a-certificate-request-with-certenroll-javascript/
#CE

#EndRegion   HOW TO , GUID, DOC

Note: this was only a few hour's so this is not too much, as this was my fist step.

mLipok

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now