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 ***** */
43 SEC_ASN1_MKSUB(SEC_SignedCertificateTemplate
)
45 static const SEC_ASN1Template CMMFSequenceOfCertifiedKeyPairsTemplate
[] = {
46 { SEC_ASN1_SEQUENCE_OF
, 0, CMMFCertifiedKeyPairTemplate
}
49 static const SEC_ASN1Template CMMFKeyRecRepContentTemplate
[] = {
50 { SEC_ASN1_SEQUENCE
, 0, NULL
, sizeof(CMMFKeyRecRepContent
)},
51 { SEC_ASN1_INLINE
, offsetof(CMMFKeyRecRepContent
, status
),
52 CMMFPKIStatusInfoTemplate
},
53 { SEC_ASN1_OPTIONAL
| SEC_ASN1_CONTEXT_SPECIFIC
| SEC_ASN1_POINTER
|
55 offsetof(CMMFKeyRecRepContent
, newSigCert
),
56 SEC_ASN1_SUB(SEC_SignedCertificateTemplate
)},
57 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_OPTIONAL
| SEC_ASN1_CONTEXT_SPECIFIC
| 1,
58 offsetof(CMMFKeyRecRepContent
, caCerts
),
59 CMMFSequenceOfCertsTemplate
},
60 { SEC_ASN1_CONSTRUCTED
| SEC_ASN1_OPTIONAL
| SEC_ASN1_CONTEXT_SPECIFIC
| 2,
61 offsetof(CMMFKeyRecRepContent
, keyPairHist
),
62 CMMFSequenceOfCertifiedKeyPairsTemplate
},
67 CMMF_EncodeCertRepContent (CMMFCertRepContent
*inCertRepContent
,
68 CRMFEncoderOutputCallback inCallback
,
71 return cmmf_user_encode(inCertRepContent
, inCallback
, inArg
,
72 CMMFCertRepContentTemplate
);
76 CMMF_EncodePOPODecKeyChallContent(CMMFPOPODecKeyChallContent
*inDecKeyChall
,
77 CRMFEncoderOutputCallback inCallback
,
80 return cmmf_user_encode(inDecKeyChall
, inCallback
, inArg
,
81 CMMFPOPODecKeyChallContentTemplate
);
84 CMMFPOPODecKeyRespContent
*
85 CMMF_CreatePOPODecKeyRespContentFromDER(const char *buf
, long len
)
88 CMMFPOPODecKeyRespContent
*decKeyResp
;
91 poolp
= PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE
);
95 decKeyResp
= PORT_ArenaZNew(poolp
, CMMFPOPODecKeyRespContent
);
96 if (decKeyResp
== NULL
) {
99 decKeyResp
->poolp
= poolp
;
100 rv
= SEC_ASN1Decode(poolp
, decKeyResp
, CMMFPOPODecKeyRespContentTemplate
,
102 if (rv
!= SECSuccess
) {
109 PORT_FreeArena(poolp
, PR_FALSE
);
115 CMMF_EncodeKeyRecRepContent(CMMFKeyRecRepContent
*inKeyRecRep
,
116 CRMFEncoderOutputCallback inCallback
,
119 return cmmf_user_encode(inKeyRecRep
, inCallback
, inArg
,
120 CMMFKeyRecRepContentTemplate
);
123 CMMFKeyRecRepContent
*
124 CMMF_CreateKeyRecRepContentFromDER(CERTCertDBHandle
*db
, const char *buf
,
128 CMMFKeyRecRepContent
*keyRecContent
;
131 poolp
= PORT_NewArena(CRMF_DEFAULT_ARENA_SIZE
);
135 keyRecContent
= PORT_ArenaZNew(poolp
, CMMFKeyRecRepContent
);
136 if (keyRecContent
== NULL
) {
139 keyRecContent
->poolp
= poolp
;
140 rv
= SEC_ASN1Decode(poolp
, keyRecContent
, CMMFKeyRecRepContentTemplate
,
142 if (rv
!= SECSuccess
) {
145 if (keyRecContent
->keyPairHist
!= NULL
) {
146 while(keyRecContent
->keyPairHist
[keyRecContent
->numKeyPairs
] != NULL
) {
147 rv
= cmmf_decode_process_certified_key_pair(poolp
, db
,
148 keyRecContent
->keyPairHist
[keyRecContent
->numKeyPairs
]);
149 if (rv
!= SECSuccess
) {
152 keyRecContent
->numKeyPairs
++;
154 keyRecContent
->allocKeyPairs
= keyRecContent
->numKeyPairs
;
156 keyRecContent
->isDecoded
= PR_TRUE
;
157 return keyRecContent
;
160 PORT_FreeArena(poolp
, PR_FALSE
);