michael@0: /* -*- Mode: C; tab-width: 8 -*-*/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /* michael@0: * This file will contain all routines needed by a client that has michael@0: * to parse a CMMFCertRepContent structure and retirieve the appropriate michael@0: * data. michael@0: */ michael@0: michael@0: #include "cmmf.h" michael@0: #include "cmmfi.h" michael@0: #include "crmf.h" michael@0: #include "crmfi.h" michael@0: #include "secitem.h" michael@0: #include "secder.h" michael@0: #include "secasn1.h" michael@0: michael@0: CMMFCertRepContent* michael@0: CMMF_CreateCertRepContentFromDER(CERTCertDBHandle *db, const char *buf, michael@0: long len) michael@0: { michael@0: PLArenaPool *poolp; michael@0: CMMFCertRepContent *certRepContent; michael@0: SECStatus rv; michael@0: int i; michael@0: michael@0: poolp = PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE); michael@0: if (poolp == NULL) { michael@0: return NULL; michael@0: } michael@0: certRepContent = PORT_ArenaZNew(poolp, CMMFCertRepContent); michael@0: if (certRepContent == NULL) { michael@0: goto loser; michael@0: } michael@0: certRepContent->poolp = poolp; michael@0: rv = SEC_ASN1Decode(poolp, certRepContent, CMMFCertRepContentTemplate, michael@0: buf, len); michael@0: if (rv != SECSuccess) { michael@0: goto loser; michael@0: } michael@0: if (certRepContent->response != NULL) { michael@0: for (i=0; certRepContent->response[i] != NULL; i++) { michael@0: rv = cmmf_decode_process_cert_response(poolp, db, michael@0: certRepContent->response[i]); michael@0: if (rv != SECSuccess) { michael@0: goto loser; michael@0: } michael@0: } michael@0: } michael@0: certRepContent->isDecoded = PR_TRUE; michael@0: return certRepContent; michael@0: loser: michael@0: PORT_FreeArena(poolp, PR_FALSE); michael@0: return NULL; michael@0: } michael@0: michael@0: long michael@0: CMMF_CertResponseGetCertReqId(CMMFCertResponse *inCertResp) michael@0: { michael@0: PORT_Assert(inCertResp != NULL); michael@0: if (inCertResp == NULL) { michael@0: return -1; michael@0: } michael@0: return DER_GetInteger(&inCertResp->certReqId); michael@0: } michael@0: michael@0: PRBool michael@0: cmmf_CertRepContentIsIndexValid(CMMFCertRepContent *inCertRepContent, michael@0: int inIndex) michael@0: { michael@0: int numResponses; michael@0: michael@0: PORT_Assert(inCertRepContent != NULL); michael@0: numResponses = CMMF_CertRepContentGetNumResponses(inCertRepContent); michael@0: return (PRBool)(inIndex >= 0 && inIndex < numResponses); michael@0: } michael@0: michael@0: CMMFCertResponse* michael@0: CMMF_CertRepContentGetResponseAtIndex(CMMFCertRepContent *inCertRepContent, michael@0: int inIndex) michael@0: { michael@0: CMMFCertResponse *certResponse; michael@0: SECStatus rv; michael@0: michael@0: PORT_Assert(inCertRepContent != NULL && michael@0: cmmf_CertRepContentIsIndexValid(inCertRepContent, inIndex)); michael@0: if (inCertRepContent == NULL || michael@0: !cmmf_CertRepContentIsIndexValid(inCertRepContent, inIndex)) { michael@0: return NULL; michael@0: } michael@0: certResponse = PORT_ZNew(CMMFCertResponse); michael@0: rv = cmmf_CopyCertResponse(NULL, certResponse, michael@0: inCertRepContent->response[inIndex]); michael@0: if (rv != SECSuccess) { michael@0: CMMF_DestroyCertResponse(certResponse); michael@0: certResponse = NULL; michael@0: } michael@0: return certResponse; michael@0: } michael@0: michael@0: CMMFPKIStatus michael@0: CMMF_CertResponseGetPKIStatusInfoStatus(CMMFCertResponse *inCertResp) michael@0: { michael@0: PORT_Assert(inCertResp != NULL); michael@0: if (inCertResp == NULL) { michael@0: return cmmfNoPKIStatus; michael@0: } michael@0: return cmmf_PKIStatusInfoGetStatus(&inCertResp->status); michael@0: } michael@0: michael@0: CERTCertificate* michael@0: CMMF_CertResponseGetCertificate(CMMFCertResponse *inCertResp, michael@0: CERTCertDBHandle *inCertdb) michael@0: { michael@0: PORT_Assert(inCertResp != NULL); michael@0: if (inCertResp == NULL || inCertResp->certifiedKeyPair == NULL) { michael@0: return NULL; michael@0: } michael@0: michael@0: return cmmf_CertOrEncCertGetCertificate( michael@0: &inCertResp->certifiedKeyPair->certOrEncCert, inCertdb); michael@0: michael@0: } michael@0: michael@0: CERTCertList* michael@0: CMMF_CertRepContentGetCAPubs (CMMFCertRepContent *inCertRepContent) michael@0: { michael@0: PORT_Assert (inCertRepContent != NULL); michael@0: if (inCertRepContent == NULL || inCertRepContent->caPubs == NULL) { michael@0: return NULL; michael@0: } michael@0: return cmmf_MakeCertList(inCertRepContent->caPubs); michael@0: } michael@0: