📄 mycerts.c
字号:
/** \file myCerts.c * $Id: myCerts.c,v 1.6 2004/11/26 14:40:38 rchantereau Exp $ * * CSP #11 -- Cryptographic Service Provider PKCS #11 certificate shower. * * This file contains certificate from personnal store shower (to be clean). * The main use is to have information on crypt_key_prov_info. * * Copyright © 2004 Entr'ouvert * http://csp11.labs.libre-entreprise.org * * \author Romain Chantereau <rchantereau@entrouvert.com> * \date 2004 * \version 0.1 * * \ingroup cert-installer * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *//** \defgroup utils Utilities. * * */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <windows.h>#include <wincrypt.h>#include "misscrypt.h"#define ENTRYPOINT APIENTRY /**< define the WinMain type.*/static HINSTANCE module; /**< The program windows instance.*/static HCRYPTPROV hProv; /**< The handler to the CSP.*/static HCRYPTKEY hUserKey; /**< The handler to the user key set.*/static HCRYPTHASH hHash; /**< Handle to the test hash.*/static HWND hMainWnd; /**< Handle the main window.*/static int selected; /**< Index in the certs list of the selected Item.*/HANDLE heapHandle; /**< handle to the test heap.*/#define DER_LENGTH 8192 /**< Length of a Der encoded certificate.*/int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hInstPrevious, LPSTR c, int d){ // Write the certificat cert into the Personnal Store : PCCERT_CONTEXT pCertContext = NULL; PCCERT_CONTEXT pPrevCertContext = NULL; HCERTSTORE LocalStore = NULL; HCRYPTPROV hProv = 0; char data[2048]; wchar_t wdata[1024]; DWORD dataLen; CRYPT_KEY_PROV_INFO *ckp; if (!(LocalStore = CertOpenStore((LPCSTR) CERT_STORE_PROV_SYSTEM,0, 0,CERT_SYSTEM_STORE_CURRENT_USER,L"My"))) { printf("Error Cannot open user store !!!\n"); return 1; } /** - Enumerate all certificates in this store.*/ pCertContext = CertEnumCertificatesInStore(LocalStore, NULL); if(pCertContext == NULL) { printf("No certificate in personnal store.\n"); } while(pCertContext != NULL) { dataLen = 1024*sizeof(wchar_t); if(!CertGetCertificateContextProperty(pCertContext, CERT_FRIENDLY_NAME_PROP_ID, wdata, &dataLen)) { printf("Error Cannot get cert friendly name !!!\n"); } else { wprintf(L"===========%s============\n",wdata); } dataLen = 2048; ckp = malloc(dataLen); if(ckp == NULL) { printf("Error no more memory ?!!!\n"); exit(1); } if(!CertGetCertificateContextProperty(pCertContext, CERT_KEY_PROV_INFO_PROP_ID, ckp, &dataLen)) { printf("Error Cannot get cert key provider info !!!\n"); } else { if(ckp->pwszProvName == NULL) { wprintf(L"\"Default provider\"\n"); } else { wprintf(L"CSP name : %s\n", ckp->pwszProvName); } if(ckp->pwszContainerName == NULL) { wprintf(L"\"Default provider container\"\n"); } else { wprintf(L"Container name : %s\n", ckp->pwszContainerName); } printf( "Provider type : %d\n", ckp->dwProvType); printf( "Provider flags : %d\n", ckp->dwFlags); if(ckp->dwKeySpec == AT_KEYEXCHANGE) { printf( "Key specs : AT_KEYEXCHANGE\n"); } else { if (ckp->dwKeySpec == AT_SIGNATURE) { printf( "Key specs : AT_SIGNATURE\n"); } else { printf( "Key specs ??? : %d\n", ckp->dwKeySpec); } } free(ckp); } printf("==========N==e==x==t=================\n\n"); pPrevCertContext = pCertContext; pCertContext = CertEnumCertificatesInStore(LocalStore, pPrevCertContext); } CertCloseStore(LocalStore,CERT_CLOSE_STORE_FORCE_FLAG); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -