Windows Benutzerzertifikate auslesen



  • Hallo zusammen,

    ich habe die Aufgabe die Windows Benutzerzertifikate aus dem Zertifikatsspeicher auszulesen. Normal anschauen kann man sich die über die MMC und dem Snap-In Zertifikate.

    Ist das möglich, wenn ja wie? Ich habe nur ein Beispiel gefunden, welches auf dem .net Framework aufbaut. Da ich dieses aber meiden soll, stehe ich wie Ochs vorm Berge.
    --> .net Variante: http://msdn2.microsoft.com/en-gb/library/ms148473.aspx

    Wäre sehr dankbar für eure Hilfe, Ratschläge oder Belehrungen 🙂

    Besten Dank und Grüße,
    Gerri


  • Mod



  • So hier mal wie weit ich bisher gekommen bin:

    C++:
    #include <stdio.h>
    #include <windows.h>
    #include <wincrypt.h>
    
    void main(void)
    {
    
    //--------------------------------------------------------------------
    // Declare and initialize variables.
    HANDLE          hStoreHandle = NULL;
    PCCERT_CONTEXT  pCertContext = NULL;  
    char * pszStoreName = "MY";
    
    //--------------------------------------------------------------------
    // Open a system certificate store.
    if (hStoreHandle = CertOpenSystemStore(
         NULL,    
         pszStoreName))
        {
             printf("The %s store has been opened. \n", pszStoreName);
        }
        else
        {
             printf("The store was not opened.\n");
             exit(1);
        }
    
    //-------------------------------------------------------------------
    // Find the certificates in the system store.
    while(pCertContext= CertEnumCertificatesInStore(
          hStoreHandle,
          pCertContext)) // on the first call to the function,
                         // this parameter is NULL
                         // on all subsequent calls,
                         // this parameter is the last pointer
                         // returned by the function
    {
    
         printf("Zert. gefunden\n");
    
         CERT_INFO ci = *(pCertContext->pCertInfo);
         printf("Vers. = %d Extension = %d\n", ci.dwVersion, ci.cExtension);
         CERT_NAME_BLOB blob = ci.Subject;
         printf("cbData = %d\n", blob.cbData);
    
         char *text;
    
         text = (char*) blob.pbData;
         printf ("pbData = %s\n", text);
    
         FILETIME von, bis;
         SYSTEMTIME stUTC, stLocal;
    
         von = ci.NotBefore;
         bis = ci.NotAfter;
    
         FileTimeToSystemTime(&von, &stUTC);
        SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
    
        // Build a string showing the date and time.
        printf("von = %02d/%02d/%d  %02d:%02d\n",
            stLocal.wDay, stLocal.wMonth, stLocal.wYear,
            stLocal.wHour, stLocal.wMinute);
    
         FileTimeToSystemTime(&bis, &stUTC);
        SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);
    
        // Build a string showing the date and time.
        printf("bis = %02d/%02d/%d  %02d:%02d\n",
            stLocal.wDay, stLocal.wMonth, stLocal.wYear,
            stLocal.wHour, stLocal.wMinute);
    
        //----------------------------------------------------------------
        // Do whatever is needed for a current certificate.
        // ...
    } // End of while
    
    //--------------------------------------------------------------------
    //   Clean up.
    if (!CertCloseStore(
             hStoreHandle,
             0))
    {
        printf("Failed CertCloseStore\n");
        exit(1);
    }
    }
    

    Leider verstehe ich jetzt noch nicht wie ich genau an alle Informationen des Zertifikats rankomme. Datum und Uhrzeit sieht gut aus, jedoch der Rest sieht komisch aus...

    Wäre cool wenn mir da noch jemand unter die Arme greifen könnte.


Anmelden zum Antworten