使用“api-monitor工具”及应用程序读取smart card 信息

2023-10-29


采用工具:api-monitor(下载地址:点击打开链接



使用步骤:

1、运行mstsc。

2、运行apimonitor-x86.exe,如下图所示,定位要监视的应用程序。


3、然后点击mstsc的编辑项



4、当mstsc列出所有凭据时,此时可以看到调用了API的情况:





二、API分析

1、

CertCreateCertificateContext Function

The CertCreateCertificateContext function creates a certificatecontext from an encoded certificate. The created context is not persisted(不变的) to a certificate store. The function makes a copy of the encoded certificate within the created context.


PCCERT_CONTEXT WINAPI CertCreateCertificateContext(
  __in  DWORD dwCertEncodingType,
  __in  const BYTE* pbCertEncoded,
  __in  DWORD cbCertEncoded
);

Parameters

dwCertEncodingType

Specifies the type of encoding used. It is always acceptable to specify both the certificate andmessage encoding types by combining them with a bitwise-OR operation as shown in the following example:

X509_ASN_ENCODING | PKCS_7_ASN_ENCODING

Currently defined encoding types are:

  • X509_ASN_ENCODING
  • PKCS_7_ASN_ENCODING

pbCertEncoded

A pointer to a buffer that contains the encoded certificate from which the context is to be created.

cbCertEncoded

The size, in bytes, of the pbCertEncoded buffer.

Return Value

If the function succeeds, the function returns a pointer to a read-only CERT_CONTEXT. When you have finished using the certificate context, free it by calling theCertFreeCertificateContext function.

If the function is unable to decode and create the certificate context, it returns NULL. For extended error information, callGetLastError. Some possible error codes follow.

Return code Description

E_INVALIDARG

A certificate encoding type that is not valid was specified. Currently, only the X509_ASN_ENCODING type is supported.

If the function fails, GetLastError may return an Abstract Syntax Notation One (ASN.1) encoding/decoding error. For information about these errors, seeASN.1 Encoding/Decoding Return Values.

Remarks

The CERT_CONTEXT must be freed by calling CertFreeCertificateContext.CertDuplicateCertificateContext can be called to make a duplicate.CertSetCertificateContextProperty andCertGetCertificateContextProperty can be called to store and read properties for the certificate.

Example Code [C++]

The following example shows creating a certificate context from an encoded certificate. The created context is not put in a certificate store. For another example that uses this function, seeExample C Program: Certificate Store Operations.

#define MY_ENCODING_TYPE  (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)

PCCERT_CONTEXT  pCertContext = NULL; 

//------------------------------------------------------------------ 
//  Create a new certificate from the encoded part of
//  an available certificate. pDesiredCert is a previously
//  assigned PCCERT_CONTEXT variable.
if(pCertContext = CertCreateCertificateContext(
    MY_ENCODING_TYPE,              // The encoding type
    pDesiredCert->pbCertEncoded,   // The encoded data from
                                   // the certificate retrieved
    pDesiredCert->cbCertEncoded))  // The length of the encoded data
{
    printf("A new certificate as been created.\n");
 
    // Use the certificate context as needed.
    // ...

    // When finished, free the certificate context.
    CertFreeCertificateContext(pCertContext);
}
else
{
    printf("A new certificate could not be created.\n");
    exit(1);
}

CertAddCertificateContextToStore Function

The CertAddCertificateContextToStore function adds a certificate context to the certificate store.

Syntax

BOOL WINAPI CertAddCertificateContextToStore(
  __in       HCERTSTORE hCertStore,
  __in       PCCERT_CONTEXT pCertContext,
  __in       DWORD dwAddDisposition,
  __out_opt  PCCERT_CONTEXT* ppStoreContext
);

Parameters

hCertStore

Handle of a certificate store.

pCertContext

A pointer to the CERT_CONTEXT structure to be added to the store.

dwAddDisposition

Specifies the action to take if a matching certificate or a link to a matching certificate already exists in the store. Currently defined disposition values and their uses are as follows.

Value Meaning

CERT_STORE_ADD_ALWAYS

The function makes no check for an existing matching certificate or link to a matching certificate. A new certificate is always added to the store. This can lead to duplicates in a store.

CERT_STORE_ADD_NEW

If a matching certificate or a link to a matching certificate exists, the operation fails.GetLastError returns the CRYPT_E_EXISTS code.

CERT_STORE_ADD_REPLACE_EXISTING

If a link to a matching certificate exists, that existing certificate or link is deleted and a new certificate is created and added to the store. If a matching certificate or a link to a matching certificate does not exist, a new link is added.

CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES

If a matching certificate exists in the store, the existing context is deleted before creating and adding the new context. The new added context inherits properties from the existing certificate.

CERT_STORE_ADD_USE_EXISTING

If a matching certificate or a link to a matching certificate exists, that existing certificate or link is used and properties from the new certificate are added. The function does not fail, but it does not add a new context. IfppCertContext is not NULL, the existing context is duplicated.

If a matching certificate or a link to a matching certificate does not exist, a new certificate is added.

ppStoreContext

A pointer to a pointer to the copy to be made of the certificate that was added to the store.

The ppStoreContext parameter can be NULL, indicating that the calling application does not require a copy of the added certificate. If a copy is made, it must be freed by usingCertFreeCertificateContext.

Return Value

If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE. For extended error information, callGetLastError. Some possible error codes follow.



CertEnumCertificatesInStore Function

The CertEnumCertificatesInStore function retrieves the first or next certificate in a certificate store. Used in a loop, this function can retrieve in sequence all certificates in a certificate store.

Syntax

PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(
  __in  HCERTSTORE hCertStore,
  __in  PCCERT_CONTEXT pPrevCertContext
);

Parameters

hCertStore

A handle of a certificate store.

pPrevCertContext

A pointer to the CERT_CONTEXT of the previouscertificate context found.

This parameter must be NULL to begin the enumeration and get the first certificate in the store. Successive certificates are enumerated by settingpPrevCertContext to the pointer returned by a previous call to the function. This function frees theCERT_CONTEXT referenced by non-NULL values of this parameter.

For logical stores, including collection stores, a duplicate of the pCertContext returned by this function cannot be used to begin a new subsequence of enumerations because the duplicated certificate loses the initial enumerationstate. The enumeration skips any certificate previously deleted by CertDeleteCertificateFromStore.

Return Value

If the function succeeds, the function returns a pointer to the next CERT_CONTEXT in the store. If no more certificates exist in the store, the function returns NULL.

For extended error information, call GetLastError. Some possible error codes follow.

Remarks

The returned pointer is freed when passed as the pPrevCertContext parameter on a subsequent call. Otherwise, the pointer must be freed by callingCertFreeCertificateContext. A non-NULLpPrevCertContext passed toCertEnumCertificatesInStore is always freed even for an error.

A duplicate of the currently enumerated certificate can be made by calling CertDuplicateCertificateContext.

Example Code [C++]

The following example lists the certificate contexts in the certificate store. For another example that uses this function, seeExample C Program: Deleting Certificates from a Certificate Store.

void TestCertEnumCertificatesInStore()
{
	// Declare and initialize variables.
	HANDLE          hStoreHandle = NULL;
	PCCERT_CONTEXT  pCertContext = NULL;   
	char * pszStoreName = "CA";

	//--------------------------------------------------------------------
	// 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
	{
		//----------------------------------------------------------------
		// Do whatever is needed for a current certificate.
		// ...
	} // End of while.

	//--------------------------------------------------------------------
	//   Clean up.
	if (!CertCloseStore(
		hStoreHandle,
		0))
	{
		printf("Failed CertCloseStore\n");
		exit(1);
	}
}






1、可以读到smart card 的PIN码、域名、用户名(读到的是UTF8编码的)。

使用的API是:GetCerfication


读到信息后可以调用凭据组件中使用的GetSerial函数来获得更多信息。

2、

3、

4、


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用“api-monitor工具”及应用程序读取smart card 信息 的相关文章

  • 前端面试总结心得

    1 放在HTML里的哪一部分JavaScripts会在页面加载的时候被执行 A 文件头部位置 B 文件尾 C 标签部分 D 标签部分 正确答案D 2 队列和栈的区别是什么 答案 栈先进后出 队列先进先出 3 Http永久重定向的状态码是什么
  • CPU占用高解决方案

    TOP 首先查看系统资源占用信息 TOP看一下 发现正在运行的JAVA项目CPU占用率很高 百分之200左右了 那么问题一定出在这个程序中 Ps mp pid o THREAD tid time 再通过ps命令查看这个程序的线程信息 tid
  • 关于浏览器中使用迅雷组件下载文件的问题

    目录 前言 场景 问题 解决 前言 在项目开发中肯定会涉及到下载导出功能 对于开发人员来说一般习惯使用谷歌 火狐等其他浏览器进行功能测试 例如谷歌浏览器支持加入扩展程序 扩展程序的位置在 点击右上角三个点 gt 找到设置点开 gt 点击左下
  • 机器学习笔记: 聚类 模糊聚类与模糊层次聚类(论文笔记 Fuzzy Agglomerative Clustering :ICAISC 2015)

    前言 模糊层次聚类是参考了论文 A Spatial Temporal Decomposition Based Deep Neural Network for TimeSeries Forecasting 中的preliminary部分 我不
  • HTTP协议详细总结

    HTTP超文本传输协议 是WWW上应用的最多的协议 了解和掌握HTTP协议是对程序人员的基本要求 转载请注明出处 http www cnblogs com zrtqsk p 3746891 html 谢谢 一 HTTP介绍 HTTP是一个基
  • 牛客网专项练习(八)

    1 对线性表进行折半查找时 要求线性表必须以链式方式存储 且结点按关键字有序排列 这样的说法正确吗 正确答案 B 正确 不正确 分析 二分查找也称折半查找 Binary Search 它是一种效率较高的查找方法 但是 折半查找要求线性表必须
  • includes()的使用场景和作用。

    学习 includes 方法用于判断字符串是否包含指定的子字符串 或者判断数组中是否有指定的元素 例如 hellow world includes hellow 如果数组存在指定元素就会返回true 没有就返回false 问题 当在做逻辑判
  • Python 笔记 — 面向对象进阶

    目录 一 封装 1 类中封装数据 2 类中定义私有的 二 继承 1 新式类与旧式类 经典类 1 1 旧式类 经典类 1 2 新式类 1 3 Python 3 中的统一 1 4 差异 2 单继承 3 继承的传递性 4 重写 5 继承父类构造方
  • 后台复杂json格式拼写方法

    JSONObject jsonObject new JSONObject List
  • 【排序算法】归并排序算法原理

    归并排序 概念 使用前提 算法思路 适用场景 算法描述 递归法 Top down 分而治之 迭代法 Bottom up 迭代 概念 归并排序是建立在归并操作上的一种有效的排序算法 该算法是采用分治法的一个非常典型的应用 将已有序的子序列合并

随机推荐