1
/* -*- Mode: C; tab-width: 8 -*-*/
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape security libraries.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1994-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
* This file will contain all routines dealing with creating a
40
* CMMFCertRepContent structure through Create/Set functions.
51
CMMF_CreateCertRepContent(void)
53
CMMFCertRepContent *retCertRep;
56
poolp = PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE);
60
retCertRep = PORT_ArenaZNew(poolp, CMMFCertRepContent);
61
if (retCertRep == NULL) {
64
retCertRep->poolp = poolp;
68
PORT_FreeArena(poolp, PR_FALSE);
74
cmmf_CertOrEncCertSetCertificate(CMMFCertOrEncCert *certOrEncCert,
76
CERTCertificate *inCert)
78
SECItem *derDest = NULL;
79
SECStatus rv = SECFailure;
81
if (inCert->derCert.data == NULL) {
82
derDest = SEC_ASN1EncodeItem(NULL, NULL, inCert,
83
CMMFCertOrEncCertCertificateTemplate);
84
if (derDest == NULL) {
88
derDest = SECITEM_DupItem(&inCert->derCert);
89
if (derDest == NULL) {
93
PORT_Assert(certOrEncCert->cert.certificate == NULL);
94
certOrEncCert->cert.certificate = CERT_DupCertificate(inCert);
95
certOrEncCert->choice = cmmfCertificate;
97
rv = SECITEM_CopyItem(poolp, &certOrEncCert->derValue, derDest);
98
if (rv != SECSuccess) {
102
certOrEncCert->derValue = *derDest;
107
if (derDest != NULL) {
108
SECITEM_FreeItem(derDest, PR_TRUE);
114
cmmf_ExtractCertsFromList(CERTCertList *inCertList,
116
CERTCertificate ***certArray)
118
CERTCertificate **arrayLocalCopy;
119
CERTCertListNode *node;
122
for (node = CERT_LIST_HEAD(inCertList); !CERT_LIST_END(node, inCertList);
123
node = CERT_LIST_NEXT(node)) {
127
arrayLocalCopy = *certArray = (poolp == NULL) ?
128
PORT_NewArray(CERTCertificate*, (numNodes+1)) :
129
PORT_ArenaNewArray(poolp, CERTCertificate*, (numNodes+1));
130
if (arrayLocalCopy == NULL) {
133
for (node = CERT_LIST_HEAD(inCertList), i=0;
134
!CERT_LIST_END(node, inCertList);
135
node = CERT_LIST_NEXT(node), i++) {
136
arrayLocalCopy[i] = CERT_DupCertificate(node->cert);
137
if (arrayLocalCopy[i] == NULL) {
140
for (j=0; j<i; j++) {
141
CERT_DestroyCertificate(arrayLocalCopy[j]);
144
PORT_Free(arrayLocalCopy);
150
arrayLocalCopy[numNodes] = NULL;
155
CMMF_CertRepContentSetCertResponses(CMMFCertRepContent *inCertRepContent,
156
CMMFCertResponse **inCertResponses,
160
CMMFCertResponse **respArr, *newResp;
165
PORT_Assert (inCertRepContent != NULL &&
166
inCertResponses != NULL &&
168
if (inCertRepContent == NULL ||
169
inCertResponses == NULL ||
170
inCertRepContent->response != NULL) {
173
poolp = inCertRepContent->poolp;
174
mark = PORT_ArenaMark(poolp);
175
respArr = inCertRepContent->response =
176
PORT_ArenaZNewArray(poolp, CMMFCertResponse*, (inNumResponses+1));
177
if (respArr == NULL) {
180
for (i=0; i<inNumResponses; i++) {
181
newResp = PORT_ArenaZNew(poolp, CMMFCertResponse);
182
if (newResp == NULL) {
185
rv = cmmf_CopyCertResponse(poolp, newResp, inCertResponses[i]);
186
if (rv != SECSuccess) {
189
respArr[i] = newResp;
191
respArr[inNumResponses] = NULL;
192
PORT_ArenaUnmark(poolp, mark);
196
PORT_ArenaRelease(poolp, mark);
201
CMMF_CreateCertResponse(long inCertReqId)
204
CMMFCertResponse *newResp;
206
newResp = PORT_ZNew(CMMFCertResponse);
207
if (newResp == NULL) {
210
dummy = SEC_ASN1EncodeInteger(NULL, &newResp->certReqId, inCertReqId);
211
if (dummy != &newResp->certReqId) {
217
if (newResp != NULL) {
218
CMMF_DestroyCertResponse(newResp);
224
CMMF_CertResponseSetPKIStatusInfoStatus(CMMFCertResponse *inCertResp,
225
CMMFPKIStatus inPKIStatus)
227
PORT_Assert (inCertResp != NULL && inPKIStatus >= cmmfGranted
228
&& inPKIStatus < cmmfNumPKIStatus);
230
if (inCertResp == NULL) {
233
return cmmf_PKIStatusInfoSetStatus(&inCertResp->status, NULL,
238
CMMF_CertResponseSetCertificate (CMMFCertResponse *inCertResp,
239
CERTCertificate *inCertificate)
241
CMMFCertifiedKeyPair *keyPair = NULL;
242
SECStatus rv = SECFailure;
244
PORT_Assert(inCertResp != NULL && inCertificate != NULL);
245
if (inCertResp == NULL || inCertificate == NULL) {
248
if (inCertResp->certifiedKeyPair == NULL) {
249
keyPair = inCertResp->certifiedKeyPair =
250
PORT_ZNew(CMMFCertifiedKeyPair);
252
keyPair = inCertResp->certifiedKeyPair;
254
if (keyPair == NULL) {
257
rv = cmmf_CertOrEncCertSetCertificate(&keyPair->certOrEncCert, NULL,
259
if (rv != SECSuccess) {
265
if (keyPair->certOrEncCert.derValue.data) {
266
PORT_Free(keyPair->certOrEncCert.derValue.data);
275
CMMF_CertRepContentSetCAPubs(CMMFCertRepContent *inCertRepContent,
276
CERTCertList *inCAPubs)
282
PORT_Assert(inCertRepContent != NULL &&
284
inCertRepContent->caPubs == NULL);
286
if (inCertRepContent == NULL ||
287
inCAPubs == NULL || inCertRepContent == NULL) {
291
poolp = inCertRepContent->poolp;
292
mark = PORT_ArenaMark(poolp);
294
rv = cmmf_ExtractCertsFromList(inCAPubs, poolp,
295
&inCertRepContent->caPubs);
297
if (rv != SECSuccess) {
298
PORT_ArenaRelease(poolp, mark);
300
PORT_ArenaUnmark(poolp, mark);
306
CMMF_CertifiedKeyPairGetCertificate(CMMFCertifiedKeyPair *inCertKeyPair,
307
CERTCertDBHandle *inCertdb)
309
PORT_Assert(inCertKeyPair != NULL);
310
if (inCertKeyPair == NULL) {
313
return cmmf_CertOrEncCertGetCertificate(&inCertKeyPair->certOrEncCert,