security/nss/lib/crmf/respcli.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C; tab-width: 8 -*-*/
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6
michael@0 7 /*
michael@0 8 * This file will contain all routines needed by a client that has
michael@0 9 * to parse a CMMFCertRepContent structure and retirieve the appropriate
michael@0 10 * data.
michael@0 11 */
michael@0 12
michael@0 13 #include "cmmf.h"
michael@0 14 #include "cmmfi.h"
michael@0 15 #include "crmf.h"
michael@0 16 #include "crmfi.h"
michael@0 17 #include "secitem.h"
michael@0 18 #include "secder.h"
michael@0 19 #include "secasn1.h"
michael@0 20
michael@0 21 CMMFCertRepContent*
michael@0 22 CMMF_CreateCertRepContentFromDER(CERTCertDBHandle *db, const char *buf,
michael@0 23 long len)
michael@0 24 {
michael@0 25 PLArenaPool *poolp;
michael@0 26 CMMFCertRepContent *certRepContent;
michael@0 27 SECStatus rv;
michael@0 28 int i;
michael@0 29
michael@0 30 poolp = PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE);
michael@0 31 if (poolp == NULL) {
michael@0 32 return NULL;
michael@0 33 }
michael@0 34 certRepContent = PORT_ArenaZNew(poolp, CMMFCertRepContent);
michael@0 35 if (certRepContent == NULL) {
michael@0 36 goto loser;
michael@0 37 }
michael@0 38 certRepContent->poolp = poolp;
michael@0 39 rv = SEC_ASN1Decode(poolp, certRepContent, CMMFCertRepContentTemplate,
michael@0 40 buf, len);
michael@0 41 if (rv != SECSuccess) {
michael@0 42 goto loser;
michael@0 43 }
michael@0 44 if (certRepContent->response != NULL) {
michael@0 45 for (i=0; certRepContent->response[i] != NULL; i++) {
michael@0 46 rv = cmmf_decode_process_cert_response(poolp, db,
michael@0 47 certRepContent->response[i]);
michael@0 48 if (rv != SECSuccess) {
michael@0 49 goto loser;
michael@0 50 }
michael@0 51 }
michael@0 52 }
michael@0 53 certRepContent->isDecoded = PR_TRUE;
michael@0 54 return certRepContent;
michael@0 55 loser:
michael@0 56 PORT_FreeArena(poolp, PR_FALSE);
michael@0 57 return NULL;
michael@0 58 }
michael@0 59
michael@0 60 long
michael@0 61 CMMF_CertResponseGetCertReqId(CMMFCertResponse *inCertResp)
michael@0 62 {
michael@0 63 PORT_Assert(inCertResp != NULL);
michael@0 64 if (inCertResp == NULL) {
michael@0 65 return -1;
michael@0 66 }
michael@0 67 return DER_GetInteger(&inCertResp->certReqId);
michael@0 68 }
michael@0 69
michael@0 70 PRBool
michael@0 71 cmmf_CertRepContentIsIndexValid(CMMFCertRepContent *inCertRepContent,
michael@0 72 int inIndex)
michael@0 73 {
michael@0 74 int numResponses;
michael@0 75
michael@0 76 PORT_Assert(inCertRepContent != NULL);
michael@0 77 numResponses = CMMF_CertRepContentGetNumResponses(inCertRepContent);
michael@0 78 return (PRBool)(inIndex >= 0 && inIndex < numResponses);
michael@0 79 }
michael@0 80
michael@0 81 CMMFCertResponse*
michael@0 82 CMMF_CertRepContentGetResponseAtIndex(CMMFCertRepContent *inCertRepContent,
michael@0 83 int inIndex)
michael@0 84 {
michael@0 85 CMMFCertResponse *certResponse;
michael@0 86 SECStatus rv;
michael@0 87
michael@0 88 PORT_Assert(inCertRepContent != NULL &&
michael@0 89 cmmf_CertRepContentIsIndexValid(inCertRepContent, inIndex));
michael@0 90 if (inCertRepContent == NULL ||
michael@0 91 !cmmf_CertRepContentIsIndexValid(inCertRepContent, inIndex)) {
michael@0 92 return NULL;
michael@0 93 }
michael@0 94 certResponse = PORT_ZNew(CMMFCertResponse);
michael@0 95 rv = cmmf_CopyCertResponse(NULL, certResponse,
michael@0 96 inCertRepContent->response[inIndex]);
michael@0 97 if (rv != SECSuccess) {
michael@0 98 CMMF_DestroyCertResponse(certResponse);
michael@0 99 certResponse = NULL;
michael@0 100 }
michael@0 101 return certResponse;
michael@0 102 }
michael@0 103
michael@0 104 CMMFPKIStatus
michael@0 105 CMMF_CertResponseGetPKIStatusInfoStatus(CMMFCertResponse *inCertResp)
michael@0 106 {
michael@0 107 PORT_Assert(inCertResp != NULL);
michael@0 108 if (inCertResp == NULL) {
michael@0 109 return cmmfNoPKIStatus;
michael@0 110 }
michael@0 111 return cmmf_PKIStatusInfoGetStatus(&inCertResp->status);
michael@0 112 }
michael@0 113
michael@0 114 CERTCertificate*
michael@0 115 CMMF_CertResponseGetCertificate(CMMFCertResponse *inCertResp,
michael@0 116 CERTCertDBHandle *inCertdb)
michael@0 117 {
michael@0 118 PORT_Assert(inCertResp != NULL);
michael@0 119 if (inCertResp == NULL || inCertResp->certifiedKeyPair == NULL) {
michael@0 120 return NULL;
michael@0 121 }
michael@0 122
michael@0 123 return cmmf_CertOrEncCertGetCertificate(
michael@0 124 &inCertResp->certifiedKeyPair->certOrEncCert, inCertdb);
michael@0 125
michael@0 126 }
michael@0 127
michael@0 128 CERTCertList*
michael@0 129 CMMF_CertRepContentGetCAPubs (CMMFCertRepContent *inCertRepContent)
michael@0 130 {
michael@0 131 PORT_Assert (inCertRepContent != NULL);
michael@0 132 if (inCertRepContent == NULL || inCertRepContent->caPubs == NULL) {
michael@0 133 return NULL;
michael@0 134 }
michael@0 135 return cmmf_MakeCertList(inCertRepContent->caPubs);
michael@0 136 }
michael@0 137

mercurial