当前位置: 首页>>代码示例>>C++>>正文


C++ CK_FUNCTION_LIST_PTR::C_GetAttributeValue方法代码示例

本文整理汇总了C++中CK_FUNCTION_LIST_PTR::C_GetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C++ CK_FUNCTION_LIST_PTR::C_GetAttributeValue方法的具体用法?C++ CK_FUNCTION_LIST_PTR::C_GetAttributeValue怎么用?C++ CK_FUNCTION_LIST_PTR::C_GetAttributeValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CK_FUNCTION_LIST_PTR的用法示例。


在下文中一共展示了CK_FUNCTION_LIST_PTR::C_GetAttributeValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: usage


//.........这里部分代码省略.........
        }

        PR_fprintf(PR_STDOUT, "    All objects:\n");

        while(1) {
          CK_OBJECT_HANDLE o = (CK_OBJECT_HANDLE)0;
          CK_ULONG nObjects = 0;
          CK_ULONG k;
          CK_ULONG nAttributes = 0;
          CK_ATTRIBUTE_PTR pT2;
          CK_ULONG l;

          ck_rv = epv->C_FindObjects(h, &o, 1, &nObjects);
          if( CKR_OK != ck_rv ) {
            PR_fprintf(PR_STDERR, "C_FindObjects(%lu, , 1, ) returned 0x%08x\n", h, ck_rv);
            return 1;
          }

          if( 0 == nObjects ) {
            PR_fprintf(PR_STDOUT, "\n");
            break;
          }

          tnObjects++;

          PR_fprintf(PR_STDOUT, "        OBJECT HANDLE %lu:\n", o);

          for( k = 0; k < number_of_all_known_attribute_types; k++ ) {
            pTemplate[k].type = all_known_attribute_types[k];
            pTemplate[k].pValue = (CK_VOID_PTR)CK_NULL_PTR;
            pTemplate[k].ulValueLen = 0;
          }

          ck_rv = epv->C_GetAttributeValue(h, o, pTemplate, number_of_all_known_attribute_types);
          switch( ck_rv ) {
          case CKR_OK:
          case CKR_ATTRIBUTE_SENSITIVE:
          case CKR_ATTRIBUTE_TYPE_INVALID:
          case CKR_BUFFER_TOO_SMALL:
            break;
          default:
            PR_fprintf(PR_STDERR, "C_GetAtributeValue(%lu, %lu, {all attribute types}, %lu) returned 0x%08x\n",
                       h, o, number_of_all_known_attribute_types, ck_rv);
            return 1;
          }

          for( k = 0; k < number_of_all_known_attribute_types; k++ ) {
            if( -1 != (CK_LONG)pTemplate[k].ulValueLen ) {
              nAttributes++;
            }
          }

          if( 1 ) {
            PR_fprintf(PR_STDOUT, "            %lu attributes:\n", nAttributes);
            for( k = 0; k < number_of_all_known_attribute_types; k++ ) {
              if( -1 != (CK_LONG)pTemplate[k].ulValueLen ) {
                PR_fprintf(PR_STDOUT, "                0x%08x (len = %lu)\n", pTemplate[k].type, 
                           pTemplate[k].ulValueLen);
              }
            }
            PR_fprintf(PR_STDOUT, "\n");
          }

          pT2 = (CK_ATTRIBUTE_PTR)PR_Calloc(nAttributes, sizeof(CK_ATTRIBUTE));
          if( (CK_ATTRIBUTE_PTR)NULL == pT2 ) {
            PR_fprintf(PR_STDERR, "[memory allocation of %lu bytes failed]\n", 
开发者ID:AOSC-Dev,项目名称:nss-purified,代码行数:67,代码来源:trivial.c

示例2: testRSAPub_keypair

int testRSAPub_keypair(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hPublicKey, CK_OBJECT_HANDLE hPrivateKey)
{
	CK_RV rv;
	CK_ATTRIBUTE pubTemplate[] = {
		{ CKA_PUBLIC_EXPONENT, NULL_PTR, 0 },
		{ CKA_MODULUS, NULL_PTR, 0 }
	};
	CK_BYTE_PTR public_exponent1 = NULL;
	CK_BYTE_PTR public_exponent2 = NULL;
	CK_ULONG public_exponent_len1 = 0;
	CK_ULONG public_exponent_len2 = 0;
	CK_BYTE_PTR modulus1 = NULL;
	CK_BYTE_PTR modulus2 = NULL;
	CK_ULONG modulus_len1 = 0;
	CK_ULONG modulus_len2 = 0;
	int retVal = 0;

	printf("Public key information from public key object: ");

	// Get buffer sizes
	rv = p11->C_GetAttributeValue(hSession, hPublicKey, pubTemplate,  2);
	if (rv != CKR_OK)
	{
		printf("Failed to get the size of modulus and pubexp. rv=%s\n", rv2string(rv));
		return 1;
	}

	// Allocate memory
	public_exponent_len1 = pubTemplate[0].ulValueLen;
	modulus_len1 = pubTemplate[1].ulValueLen;
	public_exponent1 = (CK_BYTE_PTR)malloc(public_exponent_len1);
	pubTemplate[0].pValue = public_exponent1;
	if (public_exponent1 == NULL)
	{
		printf("Failed to allocate memory\n");
		return 1;
	}
	modulus1 = (CK_BYTE_PTR)malloc(modulus_len1);
	pubTemplate[1].pValue = modulus1;
	if (modulus1 == NULL)
	{
		printf("Failed to allocate memory\n");
		free(public_exponent1);
		return 1;
	}

	// Get the information from the public key
	rv = p11->C_GetAttributeValue(hSession, hPublicKey, pubTemplate,  2);
	if (rv != CKR_OK)
	{
		printf("Failed to get the modulus and pubexp. rv=%s\n", rv2string(rv));
		free(public_exponent1);
		free(modulus1);
		return 1;
	}

	printf("OK\n");

	printf("Public key information from private key object: ");

	// Get buffer sizes
	pubTemplate[0].ulValueLen = 0;
	pubTemplate[1].ulValueLen = 0;
	pubTemplate[0].pValue = NULL_PTR;
	pubTemplate[1].pValue = NULL_PTR;
	rv = p11->C_GetAttributeValue(hSession, hPrivateKey, pubTemplate,  2);
	if (rv == CKR_ATTRIBUTE_TYPE_INVALID)
	{
		printf("Failed. The modulus or pubexp does not exist\n");
		free(public_exponent1);
		free(modulus1);
		return 1;
	}
	if (rv != CKR_OK)
	{
		printf("Failed to get the size of modulus and pubexp. rv=%s\n", rv2string(rv));
		free(public_exponent1);
		free(modulus1);
		return 1;
	}

	// Allocate memory
	public_exponent_len2 = pubTemplate[0].ulValueLen;
	modulus_len2 = pubTemplate[1].ulValueLen;
	public_exponent2 = (CK_BYTE_PTR)malloc(public_exponent_len2);
	pubTemplate[0].pValue = public_exponent2;
	if (public_exponent2 == NULL)
	{
		printf("Failed to allocate memory\n");
		free(public_exponent1);
		free(modulus1);
		return 1;
	}
	modulus2 = (CK_BYTE_PTR)malloc(modulus_len2);
	pubTemplate[1].pValue = modulus2;
	if (modulus2 == NULL)
	{
		printf("Failed to allocate memory\n");
		free(public_exponent1);
		free(modulus1);
//.........这里部分代码省略.........
开发者ID:opendnssec,项目名称:pkcs11-testing,代码行数:101,代码来源:publickey.cpp

示例3: DataMarshalling


//.........这里部分代码省略.........
				d2->setMsgType(d->getMsgType());
				d2->packInt((char *)&ret);
				d2->sendData();
				delete d2;
			}
		} else if (!strcmp(d->getMsgType(), "C_FindObjects")) {
			CK_SESSION_HANDLE	sessionId = 0;
			CK_OBJECT_HANDLE_PTR	phObject = NULL;
			CK_ULONG			len = 0, maxlen = 0;

			printf("Processing: C_FindObjects\n");

			sessionId = d->unpackInt();
			maxlen = d->unpackInt();
			if (maxlen > 0) {
				phObject = new(CK_OBJECT_HANDLE[maxlen]);
			}
			{
				CK_RV			ret = 0;
				DataMarshalling	*d2 = new DataMarshalling(client);
				/*
				 * Opening session
				 */
				ret = pFunctionList->C_FindObjects(sessionId, phObject, maxlen, &len);
				d2->setMsgType(d->getMsgType());
				d2->packInt((char *)&ret);
				d2->packInt((char *)&len);
				for (int i = 0; i < len && i < maxlen; i ++)
					d2->packInt((char *)&phObject[i]);
				
				d2->sendData();
				delete d2;
			}
		} else if (!strcmp(d->getMsgType(), "C_GetAttributeValue")) {
			CK_SESSION_HANDLE	sessionId = 0;
			CK_OBJECT_HANDLE	hObject = 0;
			CK_ULONG			len = 0;
			CK_ATTRIBUTE_PTR	attr = NULL;

			printf("Processing: C_GetAttributeValue\n");

			sessionId = d->unpackInt();
			hObject = d->unpackInt();
			len = d->unpackInt();
			attr = (CK_ATTRIBUTE_PTR) calloc(len, sizeof(CK_ATTRIBUTE));
			if (!attr) {
				printf("ERROR: NO MEM C_GetAttributeValue\n");
				break;
			}
			for (int i = 0; i < len; i ++) {
				attr[i].type = d->unpackInt();
				attr[i].ulValueLen = d->unpackInt();
				attr[i].pValue = (char *)d->unpackInt();
				if (attr[i].pValue != NULL) {
					attr[i].pValue = (char *)calloc(1, attr[i].ulValueLen);
					if (!attr[i].pValue) {
						printf("ERROR: NO MEM\n");
						exit(-1);
					}
					//d->unpackMem((char *)attr[i].pValue, attr[i].ulValueLen);
				}
			}
			{
				CK_RV			ret = 0;
				DataMarshalling	*d2 = new DataMarshalling(client);
开发者ID:ggonzalez,项目名称:Man-In-Remote,代码行数:66,代码来源:main.cpp

示例4: EstEID_loadCertInfoEntries

int EstEID_loadCertInfoEntries(EstEID_Certs *certs, int index) {
	EstEID_Map cert = certs->certs[index];
	CK_SLOT_ID slotID = certs->slotIDs[index];

	CK_SESSION_HANDLE session;
	FAIL_IF(EstEID_CK_failure("C_OpenSession", fl->C_OpenSession(slotID, CKF_SERIAL_SESSION, NULL_PTR, NULL_PTR, &session)));

	CK_OBJECT_CLASS objectClass = CKO_CERTIFICATE;
	CK_ATTRIBUTE searchAttribute = {CKA_CLASS, &objectClass, sizeof(objectClass)};
	if (EstEID_CK_failure("C_FindObjectsInit", fl->C_FindObjectsInit(session, &searchAttribute, 1))) return FAILURE;

	CK_OBJECT_HANDLE objectHandle;
	CK_ULONG objectCount;
	if (EstEID_CK_failure("C_FindObjects", fl->C_FindObjects(session, &objectHandle, 1, &objectCount))) return FAILURE;

	if (objectCount == 0) return SUCCESS;

	CK_ATTRIBUTE attribute = {CKA_VALUE, NULL_PTR, 0};
	if (EstEID_CK_failure("C_GetAttributeValue", fl->C_GetAttributeValue(session, objectHandle, &attribute, 1))) return FAILURE;

	CK_ULONG certificateLength = attribute.ulValueLen;
	CK_BYTE_PTR certificate = (CK_BYTE_PTR)malloc(certificateLength);
	attribute.pValue = certificate;
	if (EstEID_CK_failure("C_GetAttributeValue", fl->C_GetAttributeValue(session, objectHandle, &attribute, 1))) return FAILURE;

	EstEID_mapPutNoAlloc(cert, strdup("certificateAsHex"), EstEID_bin2hex((char *)certificate, certificateLength));

	const unsigned char *p = certificate;
	X509 *x509 = d2i_X509(NULL, &p, certificateLength);
	
	char *certMD5;
	certMD5 = EstEID_getCertHash((char*)certificate);
	FAIL_IF(EstEID_md5_failure(certMD5));
	EstEID_mapPutNoAlloc(cert, strdup("certHash"), certMD5);
	free(certificate);
// todo: error handling of all openssl functions

	EstEID_mapPutNoAlloc(cert, strdup("validTo"), EstEID_ASN1_TIME_toString(X509_get_notAfter(x509)));
	EstEID_mapPutNoAlloc(cert, strdup("validFrom"), EstEID_ASN1_TIME_toString(X509_get_notBefore(x509)));

	unsigned long keyUsage;
	ASN1_BIT_STRING *usage = (ASN1_BIT_STRING *)X509_get_ext_d2i(x509, NID_key_usage, NULL, NULL);
	if (usage->length > 0) keyUsage = usage->data[0];
	ASN1_BIT_STRING_free(usage);

	if (keyUsage & X509v3_KU_DIGITAL_SIGNATURE) EstEID_mapPut(cert, "usageDigitalSignature", "TRUE");
	if (keyUsage & X509v3_KU_NON_REPUDIATION) {
		EstEID_mapPut(cert, "usageNonRepudiation", "TRUE");
		EstEID_mapPut(cert, "keyUsage", "Non-Repudiation");  // for compatibility with older plugin
	}

	EstEID_loadCertEntries(cert, "", X509_get_subject_name(x509));

	char *certSerialNumber = (char*)malloc(33);
	snprintf(certSerialNumber, 32, "%lX", ASN1_INTEGER_get(X509_get_serialNumber(x509)));
	EstEID_mapPutNoAlloc(cert, strdup("certSerialNumber"), certSerialNumber);
	EstEID_loadCertEntries(cert, "issuer.", X509_get_issuer_name(x509));

	BIO *bio = BIO_new(BIO_s_mem());
	if (!PEM_write_bio_X509(bio, x509)) printf("Cannot create PEM\n");
	char *b;
	int len = BIO_get_mem_data(bio, &b);
	char *pem = (char *)malloc(len + 1);
	strncpy(pem, b, len);
	pem[len] = 0;
	BIO_free(bio);
	EstEID_mapPutNoAlloc(cert, strdup("certificateAsPEM"), pem);

	FAIL_IF(EstEID_CK_failure("C_CloseSession", fl->C_CloseSession(session)));
	return SUCCESS;
}
开发者ID:Krabi,项目名称:idkaart_public,代码行数:71,代码来源:esteid_certinfo.c


注:本文中的CK_FUNCTION_LIST_PTR::C_GetAttributeValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。