summaryrefslogtreecommitdiff
path: root/nss/lib/crmf/respcmn.c
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-01-04 14:24:24 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-01-04 14:24:24 +0000
commitdc1565216a5d20ae0d75872151523252309a1292 (patch)
treed57454ba9a40386552179eddf60d28bd1e8f3d54 /nss/lib/crmf/respcmn.c
parent26c046fbc57d53136b4fb3b5e0d18298318125d4 (diff)
downloadnss-822b884019ac3b4a984e5d3b33b2cd07bc1518c1.tar.gz
nss-3.28.1nss-3.28.1
Diffstat (limited to 'nss/lib/crmf/respcmn.c')
-rw-r--r--nss/lib/crmf/respcmn.c329
1 files changed, 161 insertions, 168 deletions
diff --git a/nss/lib/crmf/respcmn.c b/nss/lib/crmf/respcmn.c
index 1353d36..f9e4155 100644
--- a/nss/lib/crmf/respcmn.c
+++ b/nss/lib/crmf/respcmn.c
@@ -8,8 +8,8 @@
#include "secitem.h"
#include "secder.h"
-SECStatus
-cmmf_DestroyPKIStatusInfo (CMMFPKIStatusInfo *info, PRBool freeit)
+SECStatus
+cmmf_DestroyPKIStatusInfo(CMMFPKIStatusInfo *info, PRBool freeit)
{
if (info->status.data != NULL) {
PORT_Free(info->status.data);
@@ -35,13 +35,13 @@ CMMF_DestroyCertResponse(CMMFCertResponse *inCertResp)
PORT_Assert(inCertResp != NULL);
if (inCertResp != NULL) {
if (inCertResp->certReqId.data != NULL) {
- PORT_Free(inCertResp->certReqId.data);
- }
- cmmf_DestroyPKIStatusInfo(&inCertResp->status, PR_FALSE);
- if (inCertResp->certifiedKeyPair != NULL) {
- CMMF_DestroyCertifiedKeyPair(inCertResp->certifiedKeyPair);
- }
- PORT_Free(inCertResp);
+ PORT_Free(inCertResp->certReqId.data);
+ }
+ cmmf_DestroyPKIStatusInfo(&inCertResp->status, PR_FALSE);
+ if (inCertResp->certifiedKeyPair != NULL) {
+ CMMF_DestroyCertifiedKeyPair(inCertResp->certifiedKeyPair);
+ }
+ PORT_Free(inCertResp);
}
return SECSuccess;
}
@@ -51,32 +51,31 @@ CMMF_DestroyCertRepContent(CMMFCertRepContent *inCertRepContent)
{
PORT_Assert(inCertRepContent != NULL);
if (inCertRepContent != NULL) {
- CMMFCertResponse **pResponse = inCertRepContent->response;
+ CMMFCertResponse **pResponse = inCertRepContent->response;
if (pResponse != NULL) {
for (; *pResponse != NULL; pResponse++) {
- CMMFCertifiedKeyPair *certKeyPair = (*pResponse)->certifiedKeyPair;
- /* XXX Why not call CMMF_DestroyCertifiedKeyPair or
- ** XXX cmmf_DestroyCertOrEncCert ?
- */
- if (certKeyPair != NULL &&
+ CMMFCertifiedKeyPair *certKeyPair = (*pResponse)->certifiedKeyPair;
+ /* XXX Why not call CMMF_DestroyCertifiedKeyPair or
+ ** XXX cmmf_DestroyCertOrEncCert ?
+ */
+ if (certKeyPair != NULL &&
certKeyPair->certOrEncCert.choice == cmmfCertificate &&
certKeyPair->certOrEncCert.cert.certificate != NULL) {
- CERT_DestroyCertificate
- (certKeyPair->certOrEncCert.cert.certificate);
- certKeyPair->certOrEncCert.cert.certificate = NULL;
+ CERT_DestroyCertificate(certKeyPair->certOrEncCert.cert.certificate);
+ certKeyPair->certOrEncCert.cert.certificate = NULL;
}
}
}
- if (inCertRepContent->caPubs) {
- CERTCertificate **caPubs = inCertRepContent->caPubs;
- for (; *caPubs; ++caPubs) {
- CERT_DestroyCertificate(*caPubs);
- *caPubs = NULL;
- }
- }
- if (inCertRepContent->poolp != NULL) {
- PORT_FreeArena(inCertRepContent->poolp, PR_TRUE);
- }
+ if (inCertRepContent->caPubs) {
+ CERTCertificate **caPubs = inCertRepContent->caPubs;
+ for (; *caPubs; ++caPubs) {
+ CERT_DestroyCertificate(*caPubs);
+ *caPubs = NULL;
+ }
+ }
+ if (inCertRepContent->poolp != NULL) {
+ PORT_FreeArena(inCertRepContent->poolp, PR_TRUE);
+ }
}
return SECSuccess;
}
@@ -94,73 +93,73 @@ CMMF_DestroyPOPODecKeyChallContent(CMMFPOPODecKeyChallContent *inDecKeyCont)
SECStatus
crmf_create_prtime(SECItem *src, PRTime **dest)
{
- *dest = PORT_ZNew(PRTime);
+ *dest = PORT_ZNew(PRTime);
return DER_DecodeTimeChoice(*dest, src);
}
-CRMFCertExtension*
+CRMFCertExtension *
crmf_copy_cert_extension(PLArenaPool *poolp, CRMFCertExtension *inExtension)
{
- PRBool isCritical;
- SECOidTag id;
- SECItem *data;
+ PRBool isCritical;
+ SECOidTag id;
+ SECItem *data;
CRMFCertExtension *newExt;
PORT_Assert(inExtension != NULL);
if (inExtension == NULL) {
return NULL;
}
- id = CRMF_CertExtensionGetOidTag(inExtension);
+ id = CRMF_CertExtensionGetOidTag(inExtension);
isCritical = CRMF_CertExtensionGetIsCritical(inExtension);
- data = CRMF_CertExtensionGetValue(inExtension);
- newExt = crmf_create_cert_extension(poolp, id,
- isCritical,
- data);
+ data = CRMF_CertExtensionGetValue(inExtension);
+ newExt = crmf_create_cert_extension(poolp, id,
+ isCritical,
+ data);
SECITEM_FreeItem(data, PR_TRUE);
- return newExt;
+ return newExt;
}
-static SECItem*
+static SECItem *
cmmf_encode_certificate(CERTCertificate *inCert)
{
- return SEC_ASN1EncodeItem(NULL, NULL, inCert,
- SEC_ASN1_GET(SEC_SignedCertificateTemplate));
+ return SEC_ASN1EncodeItem(NULL, NULL, inCert,
+ SEC_ASN1_GET(SEC_SignedCertificateTemplate));
}
-CERTCertList*
+CERTCertList *
cmmf_MakeCertList(CERTCertificate **inCerts)
{
- CERTCertList *certList;
+ CERTCertList *certList;
CERTCertificate *currCert;
- SECItem *derCert, *freeCert = NULL;
- SECStatus rv;
- int i;
+ SECItem *derCert, *freeCert = NULL;
+ SECStatus rv;
+ int i;
certList = CERT_NewCertList();
if (certList == NULL) {
return NULL;
}
- for (i=0; inCerts[i] != NULL; i++) {
+ for (i = 0; inCerts[i] != NULL; i++) {
derCert = &inCerts[i]->derCert;
- if (derCert->data == NULL) {
- derCert = freeCert = cmmf_encode_certificate(inCerts[i]);
- }
- currCert=CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
- derCert, NULL, PR_FALSE, PR_TRUE);
- if (freeCert != NULL) {
- SECITEM_FreeItem(freeCert, PR_TRUE);
- freeCert = NULL;
- }
- if (currCert == NULL) {
- goto loser;
- }
- rv = CERT_AddCertToListTail(certList, currCert);
- if (rv != SECSuccess) {
- goto loser;
- }
+ if (derCert->data == NULL) {
+ derCert = freeCert = cmmf_encode_certificate(inCerts[i]);
+ }
+ currCert = CERT_NewTempCertificate(CERT_GetDefaultCertDB(),
+ derCert, NULL, PR_FALSE, PR_TRUE);
+ if (freeCert != NULL) {
+ SECITEM_FreeItem(freeCert, PR_TRUE);
+ freeCert = NULL;
+ }
+ if (currCert == NULL) {
+ goto loser;
+ }
+ rv = CERT_AddCertToListTail(certList, currCert);
+ if (rv != SECSuccess) {
+ goto loser;
+ }
}
return certList;
- loser:
+loser:
CERT_DestroyCertList(certList);
return NULL;
}
@@ -181,31 +180,30 @@ int
CMMF_CertRepContentGetNumResponses(CMMFCertRepContent *inCertRepContent)
{
int numResponses = 0;
- PORT_Assert (inCertRepContent != NULL);
+ PORT_Assert(inCertRepContent != NULL);
if (inCertRepContent != NULL && inCertRepContent->response != NULL) {
while (inCertRepContent->response[numResponses] != NULL) {
- numResponses++;
- }
+ numResponses++;
+ }
}
return numResponses;
}
-
SECStatus
cmmf_DestroyCertOrEncCert(CMMFCertOrEncCert *certOrEncCert, PRBool freeit)
{
switch (certOrEncCert->choice) {
- case cmmfCertificate:
- CERT_DestroyCertificate(certOrEncCert->cert.certificate);
- certOrEncCert->cert.certificate = NULL;
- break;
- case cmmfEncryptedCert:
- crmf_destroy_encrypted_value(certOrEncCert->cert.encryptedCert,
- PR_TRUE);
- certOrEncCert->cert.encryptedCert = NULL;
- break;
- default:
- break;
+ case cmmfCertificate:
+ CERT_DestroyCertificate(certOrEncCert->cert.certificate);
+ certOrEncCert->cert.certificate = NULL;
+ break;
+ case cmmfEncryptedCert:
+ crmf_destroy_encrypted_value(certOrEncCert->cert.encryptedCert,
+ PR_TRUE);
+ certOrEncCert->cert.encryptedCert = NULL;
+ break;
+ default:
+ break;
}
if (freeit) {
PORT_Free(certOrEncCert);
@@ -214,7 +212,7 @@ cmmf_DestroyCertOrEncCert(CMMFCertOrEncCert *certOrEncCert, PRBool freeit)
}
SECStatus
-cmmf_copy_secitem (PLArenaPool *poolp, SECItem *dest, SECItem *src)
+cmmf_copy_secitem(PLArenaPool *poolp, SECItem *dest, SECItem *src)
{
SECStatus rv;
@@ -222,8 +220,8 @@ cmmf_copy_secitem (PLArenaPool *poolp, SECItem *dest, SECItem *src)
rv = SECITEM_CopyItem(poolp, dest, src);
} else {
dest->data = NULL;
- dest->len = 0;
- rv = SECSuccess;
+ dest->len = 0;
+ rv = SECSuccess;
}
return rv;
}
@@ -246,161 +244,156 @@ CMMF_DestroyCertifiedKeyPair(CMMFCertifiedKeyPair *inCertKeyPair)
}
SECStatus
-cmmf_CopyCertResponse(PLArenaPool *poolp,
- CMMFCertResponse *dest,
- CMMFCertResponse *src)
+cmmf_CopyCertResponse(PLArenaPool *poolp,
+ CMMFCertResponse *dest,
+ CMMFCertResponse *src)
{
SECStatus rv;
if (src->certReqId.data != NULL) {
rv = SECITEM_CopyItem(poolp, &dest->certReqId, &src->certReqId);
- if (rv != SECSuccess) {
- return rv;
- }
+ if (rv != SECSuccess) {
+ return rv;
+ }
}
rv = cmmf_CopyPKIStatusInfo(poolp, &dest->status, &src->status);
if (rv != SECSuccess) {
return rv;
}
if (src->certifiedKeyPair != NULL) {
- CMMFCertifiedKeyPair *destKeyPair;
-
- destKeyPair = (poolp == NULL) ? PORT_ZNew(CMMFCertifiedKeyPair) :
- PORT_ArenaZNew(poolp, CMMFCertifiedKeyPair);
- if (!destKeyPair) {
- return SECFailure;
- }
- rv = cmmf_CopyCertifiedKeyPair(poolp, destKeyPair,
- src->certifiedKeyPair);
- if (rv != SECSuccess) {
- if (!poolp) {
- CMMF_DestroyCertifiedKeyPair(destKeyPair);
- }
- return rv;
- }
- dest->certifiedKeyPair = destKeyPair;
+ CMMFCertifiedKeyPair *destKeyPair;
+
+ destKeyPair = (poolp == NULL) ? PORT_ZNew(CMMFCertifiedKeyPair) : PORT_ArenaZNew(poolp, CMMFCertifiedKeyPair);
+ if (!destKeyPair) {
+ return SECFailure;
+ }
+ rv = cmmf_CopyCertifiedKeyPair(poolp, destKeyPair,
+ src->certifiedKeyPair);
+ if (rv != SECSuccess) {
+ if (!poolp) {
+ CMMF_DestroyCertifiedKeyPair(destKeyPair);
+ }
+ return rv;
+ }
+ dest->certifiedKeyPair = destKeyPair;
}
return SECSuccess;
}
static SECStatus
cmmf_CopyCertOrEncCert(PLArenaPool *poolp, CMMFCertOrEncCert *dest,
- CMMFCertOrEncCert *src)
+ CMMFCertOrEncCert *src)
{
- SECStatus rv = SECSuccess;
+ SECStatus rv = SECSuccess;
CRMFEncryptedValue *encVal;
dest->choice = src->choice;
rv = cmmf_copy_secitem(poolp, &dest->derValue, &src->derValue);
switch (src->choice) {
- case cmmfCertificate:
- dest->cert.certificate = CERT_DupCertificate(src->cert.certificate);
- break;
- case cmmfEncryptedCert:
- encVal = (poolp == NULL) ? PORT_ZNew(CRMFEncryptedValue) :
- PORT_ArenaZNew(poolp, CRMFEncryptedValue);
- if (encVal == NULL) {
- return SECFailure;
- }
- rv = crmf_copy_encryptedvalue(poolp, src->cert.encryptedCert, encVal);
- if (rv != SECSuccess) {
- if (!poolp) {
- crmf_destroy_encrypted_value(encVal, PR_TRUE);
- }
- return rv;
- }
- dest->cert.encryptedCert = encVal;
- break;
- default:
- rv = SECFailure;
+ case cmmfCertificate:
+ dest->cert.certificate = CERT_DupCertificate(src->cert.certificate);
+ break;
+ case cmmfEncryptedCert:
+ encVal = (poolp == NULL) ? PORT_ZNew(CRMFEncryptedValue) : PORT_ArenaZNew(poolp, CRMFEncryptedValue);
+ if (encVal == NULL) {
+ return SECFailure;
+ }
+ rv = crmf_copy_encryptedvalue(poolp, src->cert.encryptedCert, encVal);
+ if (rv != SECSuccess) {
+ if (!poolp) {
+ crmf_destroy_encrypted_value(encVal, PR_TRUE);
+ }
+ return rv;
+ }
+ dest->cert.encryptedCert = encVal;
+ break;
+ default:
+ rv = SECFailure;
}
return rv;
}
SECStatus
cmmf_CopyCertifiedKeyPair(PLArenaPool *poolp, CMMFCertifiedKeyPair *dest,
- CMMFCertifiedKeyPair *src)
+ CMMFCertifiedKeyPair *src)
{
SECStatus rv;
- rv = cmmf_CopyCertOrEncCert(poolp, &dest->certOrEncCert,
- &src->certOrEncCert);
+ rv = cmmf_CopyCertOrEncCert(poolp, &dest->certOrEncCert,
+ &src->certOrEncCert);
if (rv != SECSuccess) {
return rv;
}
if (src->privateKey != NULL) {
- CRMFEncryptedValue *encVal;
-
- encVal = (poolp == NULL) ? PORT_ZNew(CRMFEncryptedValue) :
- PORT_ArenaZNew(poolp, CRMFEncryptedValue);
- if (encVal == NULL) {
- return SECFailure;
- }
- rv = crmf_copy_encryptedvalue(poolp, src->privateKey,
- encVal);
- if (rv != SECSuccess) {
- if (!poolp) {
- crmf_destroy_encrypted_value(encVal, PR_TRUE);
- }
- return rv;
- }
- dest->privateKey = encVal;
+ CRMFEncryptedValue *encVal;
+
+ encVal = (poolp == NULL) ? PORT_ZNew(CRMFEncryptedValue) : PORT_ArenaZNew(poolp, CRMFEncryptedValue);
+ if (encVal == NULL) {
+ return SECFailure;
+ }
+ rv = crmf_copy_encryptedvalue(poolp, src->privateKey,
+ encVal);
+ if (rv != SECSuccess) {
+ if (!poolp) {
+ crmf_destroy_encrypted_value(encVal, PR_TRUE);
+ }
+ return rv;
+ }
+ dest->privateKey = encVal;
}
- rv = cmmf_copy_secitem(poolp, &dest->derPublicationInfo,
- &src->derPublicationInfo);
+ rv = cmmf_copy_secitem(poolp, &dest->derPublicationInfo,
+ &src->derPublicationInfo);
return rv;
}
SECStatus
cmmf_CopyPKIStatusInfo(PLArenaPool *poolp, CMMFPKIStatusInfo *dest,
- CMMFPKIStatusInfo *src)
+ CMMFPKIStatusInfo *src)
{
SECStatus rv;
- rv = cmmf_copy_secitem (poolp, &dest->status, &src->status);
+ rv = cmmf_copy_secitem(poolp, &dest->status, &src->status);
if (rv != SECSuccess) {
return rv;
}
- rv = cmmf_copy_secitem (poolp, &dest->statusString, &src->statusString);
+ rv = cmmf_copy_secitem(poolp, &dest->statusString, &src->statusString);
if (rv != SECSuccess) {
return rv;
}
- rv = cmmf_copy_secitem (poolp, &dest->failInfo, &src->failInfo);
+ rv = cmmf_copy_secitem(poolp, &dest->failInfo, &src->failInfo);
return rv;
}
-CERTCertificate*
+CERTCertificate *
cmmf_CertOrEncCertGetCertificate(CMMFCertOrEncCert *certOrEncCert,
- CERTCertDBHandle *certdb)
+ CERTCertDBHandle *certdb)
{
- if (certOrEncCert->choice != cmmfCertificate ||
- certOrEncCert->cert.certificate == NULL) {
+ if (certOrEncCert->choice != cmmfCertificate ||
+ certOrEncCert->cert.certificate == NULL) {
return NULL;
}
return CERT_NewTempCertificate(certdb,
- &certOrEncCert->cert.certificate->derCert,
- NULL, PR_FALSE, PR_TRUE);
+ &certOrEncCert->cert.certificate->derCert,
+ NULL, PR_FALSE, PR_TRUE);
}
-SECStatus
-cmmf_PKIStatusInfoSetStatus(CMMFPKIStatusInfo *statusInfo,
- PLArenaPool *poolp,
- CMMFPKIStatus inStatus)
+SECStatus
+cmmf_PKIStatusInfoSetStatus(CMMFPKIStatusInfo *statusInfo,
+ PLArenaPool *poolp,
+ CMMFPKIStatus inStatus)
{
SECItem *dummy;
-
- if (inStatus <cmmfGranted || inStatus >= cmmfNumPKIStatus) {
+
+ if (inStatus < cmmfGranted || inStatus >= cmmfNumPKIStatus) {
return SECFailure;
}
- dummy = SEC_ASN1EncodeInteger(poolp, &statusInfo->status, inStatus);
+ dummy = SEC_ASN1EncodeInteger(poolp, &statusInfo->status, inStatus);
PORT_Assert(dummy == &statusInfo->status);
if (dummy != &statusInfo->status) {
SECITEM_FreeItem(dummy, PR_TRUE);
- return SECFailure;
+ return SECFailure;
}
return SECSuccess;
}
-
-