security/nss/lib/crmf/respcli.c

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

mercurial