本文整理汇总了C++中SEC_ASN1EncodeItem函数的典型用法代码示例。如果您正苦于以下问题:C++ SEC_ASN1EncodeItem函数的具体用法?C++ SEC_ASN1EncodeItem怎么用?C++ SEC_ASN1EncodeItem使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SEC_ASN1EncodeItem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PublicDhKeyToSpki
nsresult
PublicDhKeyToSpki(SECKEYPublicKey* aPubKey,
CERTSubjectPublicKeyInfo* aSpki)
{
SECItem* params = ::SECITEM_AllocItem(aSpki->arena, nullptr, 0);
if (!params) {
return NS_ERROR_DOM_OPERATION_ERR;
}
SECItem* rvItem = SEC_ASN1EncodeItem(aSpki->arena, params, aPubKey,
SECKEY_DHParamKeyTemplate);
if (!rvItem) {
return NS_ERROR_DOM_OPERATION_ERR;
}
SECStatus rv = SECOID_SetAlgorithmID(aSpki->arena, &aSpki->algorithm,
SEC_OID_X942_DIFFIE_HELMAN_KEY, params);
if (rv != SECSuccess) {
return NS_ERROR_DOM_OPERATION_ERR;
}
rvItem = SEC_ASN1EncodeItem(aSpki->arena, &aSpki->subjectPublicKey, aPubKey,
SECKEY_DHPublicKeyTemplate);
if (!rvItem) {
return NS_ERROR_DOM_OPERATION_ERR;
}
// The public value is a BIT_STRING encoded as an INTEGER. After encoding
// an INT we need to adjust the length to reflect the number of bits.
aSpki->subjectPublicKey.len <<= 3;
return NS_OK;
}
示例2: sslEncodeRsaBlob
/*
* Given a raw modulus and exponent, cook up a
* BER-encoded RSA public key blob.
*/
OSStatus sslEncodeRsaBlob(
const SSLBuffer *modulus,
const SSLBuffer *exponent,
SSLBuffer *blob) /* data mallocd and RETURNED */
{
PLArenaPool *pool;
OSStatus srtn;
SECItem *encBlob, dest = {};
NSS_RSAPublicKeyPKCS1 nssPubKey;
assert((modulus != NULL) && (exponent != NULL));
/* convert to NSS_RSAPublicKeyPKCS1 */
SSLBUF_TO_SECITEM(modulus, &nssPubKey.modulus);
SSLBUF_TO_SECITEM(exponent, &nssPubKey.publicExponent);
/* DER encode */
pool = PORT_NewArena(CHUNKSIZE_DEF);
encBlob = SEC_ASN1EncodeItem(pool, &dest, &nssPubKey,
kSecAsn1RSAPublicKeyPKCS1Template);
if (!encBlob)
srtn = memFullErr;
else {
/* copy out to caller */
srtn = SSLCopyBufferFromData(encBlob->Data, encBlob->Length, blob);
}
PORT_FreeArena(pool, PR_TRUE);
return srtn;
}
示例3: sslEncodeDhParams
/*
* Given a prime and generator, cook up a BER-encoded DHParameter blob.
*/
OSStatus sslEncodeDhParams(
const SSLBuffer *prime,
const SSLBuffer *generator,
SSLBuffer *blob) /* data mallocd and RETURNED */
{
PLArenaPool *pool;
OSStatus srtn;
SECItem *encBlob, dest = {};
NSS_DHParameter dhParams;
assert((prime != NULL) && (generator != NULL));
/* convert to NSS_DHParameter */
SSLBUF_TO_SECITEM(prime, &dhParams.prime);
SSLBUF_TO_SECITEM(generator, &dhParams.base);
dhParams.privateValueLength.Data = NULL;
dhParams.privateValueLength.Length = 0;
/* DER encode */
pool = PORT_NewArena(CHUNKSIZE_DEF);
encBlob = SEC_ASN1EncodeItem(pool, &dest, &dhParams,
kSecAsn1DHParameterTemplate);
if (!encBlob)
srtn = memFullErr;
else {
/* copy out to caller */
srtn = SSLCopyBufferFromData(encBlob->Data, encBlob->Length, blob);
}
PORT_FreeArena(pool, PR_TRUE);
return srtn;
}
示例4: generate_spc_indirect_data_content
static int
generate_spc_indirect_data_content(cms_context *cms, SECItem *idcp)
{
SpcIndirectDataContent idc;
memset(&idc, '\0', sizeof (idc));
int rc;
rc = generate_spc_attribute_yadda_yadda(cms, &idc.data);
if (rc < 0)
return rc;
rc = generate_spc_digest_info(cms, &idc.messageDigest);
if (rc < 0) {
SECITEM_FreeItem(&idc.data, PR_FALSE);
return rc;
}
if (SEC_ASN1EncodeItem(cms->arena, idcp, &idc,
SpcIndirectDataContentTemplate) == NULL) {
cms->log(cms, LOG_ERR, "could not encode "
"SpcIndirectDataContent: %s",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
return 0;
}
示例5: NSS_SMIMEUtil_CreateMSSMIMEEncKeyPrefs
/*
* NSS_SMIMEUtil_CreateSMIMEEncKeyPrefs - create S/MIME encryption key preferences attr value using MS oid
*
* "poolp" - arena pool to create the attr value on
* "dest" - SECItem to put the data in
* "cert" - certificate that should be marked as preferred encryption key
* cert is expected to have been verified for EmailRecipient usage.
*/
SECStatus
NSS_SMIMEUtil_CreateMSSMIMEEncKeyPrefs(PLArenaPool *poolp, SECItem *dest, CERTCertificate *cert)
{
SECItem *dummy = NULL;
PLArenaPool *tmppoolp = NULL;
CERTIssuerAndSN *isn;
if (cert == NULL)
goto loser;
tmppoolp = PORT_NewArena(1024);
if (tmppoolp == NULL)
goto loser;
isn = CERT_GetCertIssuerAndSN(tmppoolp, cert);
if (isn == NULL)
goto loser;
dummy = SEC_ASN1EncodeItem(poolp, dest, isn, SEC_ASN1_GET(CERT_IssuerAndSNTemplate));
loser:
if (tmppoolp) PORT_FreeArena(tmppoolp, PR_FALSE);
return (dummy == NULL) ? SECFailure : SECSuccess;
}
示例6: generate_spc_indirect_data_content
static int
generate_spc_indirect_data_content(PRArenaPool *arena, SECItem *idcp,
cms_context *ctx)
{
SpcIndirectDataContent idc;
memset(&idc, '\0', sizeof (idc));
if (generate_spc_attribute_yadda_yadda(arena, &idc.data) < 0) {
fprintf(stderr, "got here %s:%d\n",__func__,__LINE__);
return -1;
}
if (generate_spc_digest_info(arena, &idc.messageDigest, ctx) < 0) {
fprintf(stderr, "got here %s:%d\n",__func__,__LINE__);
return -1;
}
if (SEC_ASN1EncodeItem(arena, idcp, &idc,
SpcIndirectDataContentTemplate) == NULL) {
fprintf(stderr,
"Could not encode SpcIndirectDataContent: %s\n",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
return 0;
}
示例7: generate_spc_attribute_yadda_yadda
/* Generate DER for SpcAttributeTypeAndValue, which is basically just
* a DER_SEQUENCE containing the OID 1.3.6.1.4.1.311.2.1.15
* (SPC_PE_IMAGE_DATA_OBJID) and the SpcPeImageData.
*/
static int
generate_spc_attribute_yadda_yadda(cms_context *cms, SECItem *ataovp)
{
SpcAttributeTypeAndOptionalValue ataov;
memset(&ataov, '\0', sizeof (ataov));
int rc;
rc = get_ms_oid_secitem(SPC_PE_IMAGE_DATA_OBJID, &ataov.contentType);
if (rc < 0) {
cms->log(cms, LOG_ERR, "could not get SPC_PE_IMAGE_DATA_OBJID");
return -1;
}
rc = generate_spc_pe_image_data(cms, &ataov.value);
if (rc < 0)
return rc;
if (SEC_ASN1EncodeItem(cms->arena, ataovp, &ataov,
SpcAttributeTypeAndOptionalValueTemplate) == NULL) {
cms->log(cms, LOG_ERR, "could not encode "
"SpcAttributeTypeAndOptionalValue: %s",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
return 0;
}
示例8: generate_spc_digest_info
static int
generate_spc_digest_info(cms_context *cms, SECItem *dip)
{
DigestInfo di;
memset(&di, '\0', sizeof (di));
if (generate_algorithm_id(cms, &di.digestAlgorithm,
digest_get_digest_oid(cms)) < 0)
return -1;
int i = cms->selected_digest;
memcpy(&di.digest, cms->digests[i].pe_digest, sizeof (di.digest));
if (content_is_empty(di.digest.data, di.digest.len)) {
cms->log(cms, LOG_ERR, "got empty digest");
return -1;
}
if (SEC_ASN1EncodeItem(cms->arena, dip, &di,
DigestInfoTemplate) == NULL) {
cms->log(cms, LOG_ERR, "could not encode DigestInfo: %s",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
return 0;
}
示例9: NSS_SMIMEUtil_CreateSMIMECapabilities
/*
* NSS_SMIMEUtil_CreateSMIMECapabilities - get S/MIME capabilities for this instance of NSS
*
* scans the list of allowed and enabled ciphers and construct a PKCS9-compliant
* S/MIME capabilities attribute value.
*
* XXX Please note that, in contradiction to RFC2633 2.5.2, the capabilities only include
* symmetric ciphers, NO signature algorithms or key encipherment algorithms.
*
* "poolp" - arena pool to create the S/MIME capabilities data on
* "dest" - SECItem to put the data in
*/
SECStatus
NSS_SMIMEUtil_CreateSMIMECapabilities(PLArenaPool *poolp, SECItem *dest)
{
NSSSMIMECapability *cap;
NSSSMIMECapability **smime_capabilities;
smime_cipher_map_entry *map;
SECOidData *oiddata;
SECItem *dummy;
int i, capIndex;
/* if we have an old NSSSMIMECapability array, we'll reuse it (has the right size) */
/* smime_cipher_map_count + 1 is an upper bound - we might end up with less */
smime_capabilities = (NSSSMIMECapability **)PORT_ZAlloc((smime_cipher_map_count + 1)
* sizeof(NSSSMIMECapability *));
if (smime_capabilities == NULL)
return SECFailure;
capIndex = 0;
/* Add all the symmetric ciphers
* We walk the cipher list backwards, as it is ordered by increasing strength,
* we prefer the stronger cipher over a weaker one, and we have to list the
* preferred algorithm first */
for (i = smime_cipher_map_count - 1; i >= 0; i--) {
/* Find the corresponding entry in the cipher map. */
map = &(smime_cipher_map[i]);
if (!map->enabled)
continue;
/* get next SMIME capability */
cap = (NSSSMIMECapability *)PORT_ZAlloc(sizeof(NSSSMIMECapability));
if (cap == NULL)
break;
smime_capabilities[capIndex++] = cap;
oiddata = SECOID_FindOIDByTag(map->algtag);
if (oiddata == NULL)
break;
cap->capabilityID.data = oiddata->oid.data;
cap->capabilityID.len = oiddata->oid.len;
cap->parameters.data = map->parms ? map->parms->data : NULL;
cap->parameters.len = map->parms ? map->parms->len : 0;
cap->cipher = smime_cipher_map[i].cipher;
}
/* XXX add signature algorithms */
/* XXX add key encipherment algorithms */
smime_capabilities[capIndex] = NULL; /* last one - now encode */
dummy = SEC_ASN1EncodeItem(poolp, dest, &smime_capabilities, NSSSMIMECapabilitiesTemplate);
/* now that we have the proper encoded SMIMECapabilities (or not),
* free the work data */
for (i = 0; smime_capabilities[i] != NULL; i++)
PORT_Free(smime_capabilities[i]);
PORT_Free(smime_capabilities);
return (dummy == NULL) ? SECFailure : SECSuccess;
}
示例10: spki
nsresult
CryptoKey::PublicKeyToSpki(SECKEYPublicKey* aPubKey,
CryptoBuffer& aRetVal,
const nsNSSShutDownPreventionLock& /*proofOfLock*/)
{
ScopedCERTSubjectPublicKeyInfo spki(SECKEY_CreateSubjectPublicKeyInfo(aPubKey));
if (!spki) {
return NS_ERROR_DOM_OPERATION_ERR;
}
// Per WebCrypto spec we must export ECDH SPKIs with the algorithm OID
// id-ecDH (1.3.132.112). NSS doesn't know about that OID and there is
// no way to specify the algorithm to use when exporting a public key.
if (aPubKey->keyType == ecKey) {
SECStatus rv = SECITEM_CopyItem(spki->arena, &spki->algorithm.algorithm,
&SEC_OID_DATA_EC_DH);
if (rv != SECSuccess) {
return NS_ERROR_DOM_OPERATION_ERR;
}
}
const SEC_ASN1Template* tpl = SEC_ASN1_GET(CERT_SubjectPublicKeyInfoTemplate);
ScopedSECItem spkiItem(SEC_ASN1EncodeItem(nullptr, nullptr, spki, tpl));
aRetVal.Assign(spkiItem.get());
return NS_OK;
}
示例11: CERT_FindCertByNameString
/*
* Lookup a certificate in the database by name
*/
CERTCertificate *
CERT_FindCertByNameString(CERTCertDBHandle *handle, char *nameStr)
{
CERTName *name;
SECItem *nameItem;
CERTCertificate *cert = NULL;
PRArenaPool *arena = NULL;
arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
if ( arena == NULL ) {
goto loser;
}
name = CERT_AsciiToName(nameStr);
if ( name ) {
nameItem = SEC_ASN1EncodeItem (arena, NULL, (void *)name,
CERT_NameTemplate);
if ( nameItem != NULL ) {
cert = CERT_FindCertByName(handle, nameItem);
}
CERT_DestroyName(name);
}
loser:
if ( arena ) {
PORT_FreeArena(arena, PR_FALSE);
}
return(cert);
}
示例12: NSS_SMIMEUtil_CreateSMIMEEncKeyPrefs
/*
* NSS_SMIMEUtil_CreateSMIMEEncKeyPrefs - create S/MIME encryption key preferences attr value
*
* "poolp" - arena pool to create the attr value on
* "dest" - SECItem to put the data in
* "cert" - certificate that should be marked as preferred encryption key
* cert is expected to have been verified for EmailRecipient usage.
*/
SECStatus
NSS_SMIMEUtil_CreateSMIMEEncKeyPrefs(PLArenaPool *poolp, SECItem *dest, CERTCertificate *cert)
{
NSSSMIMEEncryptionKeyPreference ekp;
SECItem *dummy = NULL;
PLArenaPool *tmppoolp = NULL;
if (cert == NULL)
goto loser;
tmppoolp = PORT_NewArena(1024);
if (tmppoolp == NULL)
goto loser;
/* XXX hardcoded IssuerSN choice for now */
ekp.selector = NSSSMIMEEncryptionKeyPref_IssuerSN;
ekp.id.issuerAndSN = CERT_GetCertIssuerAndSN(tmppoolp, cert);
if (ekp.id.issuerAndSN == NULL)
goto loser;
dummy = SEC_ASN1EncodeItem(poolp, dest, &ekp, smime_encryptionkeypref_template);
loser:
if (tmppoolp) PORT_FreeArena(tmppoolp, PR_FALSE);
return (dummy == NULL) ? SECFailure : SECSuccess;
}
示例13: generate_spc_pe_image_data
static int
generate_spc_pe_image_data(cms_context *cms, SECItem *spidp)
{
SpcPeImageData spid;
SECITEM_AllocItem(cms->arena, &spid.flags, 1);
if (!spid.flags.data)
return -1;
spid.flags.data[0] = 0;
char obsolete[28] = "";
int rc;
rc = generate_spc_link(cms, &spid.link, SpcLinkTypeFile, obsolete, 0);
if (rc < 0)
return rc;
if (SEC_ASN1EncodeItem(cms->arena, spidp, &spid,
SpcPeImageDataTemplate) == NULL) {
cms->log(cms, LOG_ERR, "could not encode SpcPeImageData: %s",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
/* XXX OMG FIX THIS */
/* manually bang it from NULL to BIT STRING because I can't figure out
* how to make the fucking templates work right for the bitstring size
*/
spidp->data[2] = DER_BIT_STRING;
return 0;
}
示例14: generate_spc_pe_image_data
static int
generate_spc_pe_image_data(PRArenaPool *arena, SECItem *spidp)
{
SpcPeImageData spid;
SECITEM_AllocItem(arena, &spid.flags, 1);
if (!spid.flags.data)
return -1;
spid.flags.data[0] = 0;
char obsolete[28] = "\0<\0<\0<\0O\0b\0s\0o\0l\0e\0t\0e\0>\0>\0>";
if (generate_spc_link(arena, &spid.link, SpcLinkTypeFile, obsolete,
28) < 0) {
fprintf(stderr, "got here %s:%d\n",__func__,__LINE__);
return -1;
}
if (SEC_ASN1EncodeItem(arena, spidp, &spid,
SpcPeImageDataTemplate) == NULL) {
fprintf(stderr, "Could not encode SpcPeImageData: %s\n",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
/* XXX OMG FIX THIS */
/* manually bang it from NULL to BIT STRING because I can't figure out
* how to make the fucking templates work right for the bitstring size
*/
spidp->data[2] = DER_BIT_STRING;
return 0;
}
示例15: generate_spc_attribute_yadda_yadda
/* Generate DER for SpcAttributeTypeAndValue, which is basically just
* a DER_SEQUENCE containing the OID 1.3.6.1.4.1.311.2.1.15
* (SPC_PE_IMAGE_DATA_OBJID) and the SpcPeImageData.
*/
static int
generate_spc_attribute_yadda_yadda(PRArenaPool *arena, SECItem *ataovp)
{
SpcAttributeTypeAndOptionalValue ataov;
memset(&ataov, '\0', sizeof (ataov));
if (get_ms_oid_secitem(SPC_PE_IMAGE_DATA_OBJID, &ataov.contentType) < 0){
fprintf(stderr, "got here %s:%d\n",__func__,__LINE__);
return -1;
}
if (generate_spc_pe_image_data(arena, &ataov.value) < 0) {
fprintf(stderr, "got here %s:%d\n",__func__,__LINE__);
return -1;
}
if (SEC_ASN1EncodeItem(arena, ataovp, &ataov,
SpcAttributeTypeAndOptionalValueTemplate) == NULL) {
fprintf(stderr,
"Could not encode SpcAttributeTypeAndOptionalValue:"
"%s\n",
PORT_ErrorToString(PORT_GetError()));
return -1;
}
return 0;
}