Back to index

lightning-sunbird  0.9+nobinonly
crmftmpl.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape security libraries.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "crmf.h"
00039 #include "crmfi.h"
00040 #include "secoid.h"
00041 #include "secasn1.h"
00042 
00043 SEC_ASN1_MKSUB(SECOID_AlgorithmIDTemplate)
00044 SEC_ASN1_MKSUB(SEC_AnyTemplate)
00045 SEC_ASN1_MKSUB(SEC_NullTemplate)
00046 SEC_ASN1_MKSUB(SEC_BitStringTemplate)
00047 SEC_ASN1_MKSUB(SEC_IntegerTemplate)
00048 SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
00049 SEC_ASN1_MKSUB(CERT_TimeChoiceTemplate)
00050 SEC_ASN1_MKSUB(CERT_SubjectPublicKeyInfoTemplate)
00051 SEC_ASN1_MKSUB(CERT_NameTemplate)
00052 
00053 /* 
00054  * It's all implicit tagging.
00055  */
00056 
00057 const SEC_ASN1Template CRMFControlTemplate[] = {
00058     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFControl)},
00059     { SEC_ASN1_OBJECT_ID, offsetof(CRMFControl, derTag)},
00060     { SEC_ASN1_ANY, offsetof(CRMFControl, derValue) },
00061     { 0 }
00062 };
00063 
00064 static const SEC_ASN1Template CRMFCertExtensionTemplate[] = {
00065     { SEC_ASN1_SEQUENCE,
00066          0, NULL, sizeof(CRMFCertExtension) },
00067     { SEC_ASN1_OBJECT_ID,
00068          offsetof(CRMFCertExtension,id) },
00069     { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN,
00070          offsetof(CRMFCertExtension,critical) },
00071     { SEC_ASN1_OCTET_STRING,
00072          offsetof(CRMFCertExtension,value) },
00073     { 0, }
00074 };
00075 
00076 static const SEC_ASN1Template CRMFSequenceOfCertExtensionTemplate[] = {
00077     { SEC_ASN1_SEQUENCE_OF, 0, CRMFCertExtensionTemplate }
00078 };
00079 
00080 static const SEC_ASN1Template CRMFOptionalValidityTemplate[] = {
00081     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFOptionalValidity) },
00082     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_NO_STREAM |
00083       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 0, 
00084       offsetof (CRMFOptionalValidity, notBefore),
00085       SEC_ASN1_SUB(CERT_TimeChoiceTemplate) },
00086     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | SEC_ASN1_NO_STREAM |
00087       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 1, 
00088       offsetof (CRMFOptionalValidity, notAfter),
00089       SEC_ASN1_SUB(CERT_TimeChoiceTemplate) },
00090     { 0 }
00091 };
00092 
00093 static const SEC_ASN1Template crmfPointerToNameTemplate[] = {
00094     { SEC_ASN1_POINTER | SEC_ASN1_XTRN, 0, SEC_ASN1_SUB(CERT_NameTemplate)},
00095     { 0 }
00096 };
00097 
00098 static const SEC_ASN1Template CRMFCertTemplateTemplate[] = {
00099    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertTemplate) },
00100    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0, 
00101      offsetof(CRMFCertTemplate, version), 
00102      SEC_ASN1_SUB(SEC_IntegerTemplate) },
00103    { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | SEC_ASN1_XTRN | 1 ,
00104      offsetof (CRMFCertTemplate, serialNumber), 
00105      SEC_ASN1_SUB(SEC_IntegerTemplate) },
00106    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 
00107      SEC_ASN1_XTRN | 2, 
00108      offsetof (CRMFCertTemplate, signingAlg), 
00109      SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
00110    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 
00111      SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 3, 
00112      offsetof (CRMFCertTemplate, issuer), crmfPointerToNameTemplate },
00113    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 4, 
00114      offsetof (CRMFCertTemplate, validity), 
00115      CRMFOptionalValidityTemplate },
00116    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 
00117      SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 5, 
00118      offsetof (CRMFCertTemplate, subject), crmfPointerToNameTemplate },
00119    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 
00120      SEC_ASN1_XTRN | 6, 
00121      offsetof (CRMFCertTemplate, publicKey), 
00122      SEC_ASN1_SUB(CERT_SubjectPublicKeyInfoTemplate) }, 
00123    { SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 
00124      SEC_ASN1_XTRN | 7,
00125      offsetof (CRMFCertTemplate, issuerUID), 
00126      SEC_ASN1_SUB(SEC_BitStringTemplate) },
00127    { SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL |
00128      SEC_ASN1_XTRN | 8,
00129      offsetof (CRMFCertTemplate, subjectUID), 
00130      SEC_ASN1_SUB(SEC_BitStringTemplate) },
00131    { SEC_ASN1_CONSTRUCTED | SEC_ASN1_OPTIONAL | 
00132      SEC_ASN1_CONTEXT_SPECIFIC | 9, 
00133      offsetof (CRMFCertTemplate, extensions), 
00134      CRMFSequenceOfCertExtensionTemplate },
00135    { 0 }
00136 };
00137 
00138 static const SEC_ASN1Template CRMFAttributeTemplate[] = {
00139     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFAttribute)},
00140     { SEC_ASN1_OBJECT_ID, offsetof(CRMFAttribute, derTag)},
00141     { SEC_ASN1_ANY, offsetof(CRMFAttribute, derValue) },
00142     { 0 }
00143 };
00144 
00145 const SEC_ASN1Template CRMFCertRequestTemplate[] = {
00146     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFCertRequest) },
00147     { SEC_ASN1_INTEGER, offsetof(CRMFCertRequest, certReqId)},
00148     { SEC_ASN1_INLINE, offsetof(CRMFCertRequest, certTemplate), 
00149       CRMFCertTemplateTemplate},
00150     { SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
00151       offsetof(CRMFCertRequest,controls), 
00152       CRMFControlTemplate}, /* SEQUENCE SIZE (1...MAX)*/
00153     { 0 }
00154 };
00155 
00156 const SEC_ASN1Template CRMFCertReqMsgTemplate[] = {
00157     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertReqMsg) },
00158     { SEC_ASN1_POINTER, offsetof(CRMFCertReqMsg, certReq),
00159       CRMFCertRequestTemplate },
00160     { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL,
00161       offsetof(CRMFCertReqMsg, derPOP) },
00162     { SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
00163       offsetof(CRMFCertReqMsg, regInfo), 
00164       CRMFAttributeTemplate}, /* SEQUENCE SIZE (1...MAX)*/
00165     { 0 }
00166 };
00167 
00168 const SEC_ASN1Template CRMFCertReqMessagesTemplate[] = {
00169     { SEC_ASN1_SEQUENCE_OF, offsetof(CRMFCertReqMessages, messages), 
00170       CRMFCertReqMsgTemplate, sizeof (CRMFCertReqMessages)}
00171 };
00172 
00173 static const SEC_ASN1Template CRMFPOPOSigningKeyInputTemplate[] = {
00174     { SEC_ASN1_SEQUENCE, 0, NULL,sizeof(CRMFPOPOSigningKeyInput) },
00175     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | 
00176       SEC_ASN1_CONTEXT_SPECIFIC | 0,
00177       offsetof(CRMFPOPOSigningKeyInput, authInfo.sender) },
00178     { SEC_ASN1_BIT_STRING | SEC_ASN1_OPTIONAL | 1,
00179       offsetof (CRMFPOPOSigningKeyInput, authInfo.publicKeyMAC) },
00180     { SEC_ASN1_INLINE | SEC_ASN1_XTRN, 
00181       offsetof(CRMFPOPOSigningKeyInput, publicKey), 
00182       SEC_ASN1_SUB(CERT_SubjectPublicKeyInfoTemplate) },
00183     { 0 }
00184 };
00185 
00186 const SEC_ASN1Template CRMFRAVerifiedTemplate[] = {
00187     { SEC_ASN1_CONTEXT_SPECIFIC | 0 | SEC_ASN1_XTRN, 
00188       0,
00189       SEC_ASN1_SUB(SEC_NullTemplate) },
00190     { 0 }
00191 };
00192 
00193 
00194 /* This template will need to add POPOSigningKeyInput eventually, maybe*/
00195 static const SEC_ASN1Template crmfPOPOSigningKeyTemplate[] = {
00196     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPOPOSigningKey) },
00197     { SEC_ASN1_NO_STREAM | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 
00198       SEC_ASN1_XTRN | 0,
00199       offsetof(CRMFPOPOSigningKey, derInput), 
00200       SEC_ASN1_SUB(SEC_AnyTemplate) },
00201     { SEC_ASN1_POINTER | SEC_ASN1_XTRN, 
00202       offsetof(CRMFPOPOSigningKey, algorithmIdentifier),
00203       SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
00204     { SEC_ASN1_BIT_STRING | SEC_ASN1_XTRN, 
00205       offsetof(CRMFPOPOSigningKey, signature),
00206       SEC_ASN1_SUB(SEC_BitStringTemplate) },
00207     { 0 }
00208 };
00209 
00210 const SEC_ASN1Template CRMFPOPOSigningKeyTemplate[] = {
00211     { SEC_ASN1_CONTEXT_SPECIFIC | 1,
00212       0,
00213       crmfPOPOSigningKeyTemplate},
00214     { 0 }
00215 };
00216 
00217 const SEC_ASN1Template CRMFThisMessageTemplate[] = {
00218     { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
00219       0,
00220       SEC_ASN1_SUB(SEC_BitStringTemplate) },
00221     { 0 }
00222 };
00223 
00224 const SEC_ASN1Template CRMFSubsequentMessageTemplate[] = {
00225     { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 1,
00226       0, 
00227       SEC_ASN1_SUB(SEC_IntegerTemplate) },
00228     { 0 }
00229 };
00230 
00231 const SEC_ASN1Template CRMFDHMACTemplate[] = {
00232     { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
00233       0,
00234       SEC_ASN1_SUB(SEC_BitStringTemplate) },
00235     { 0 }
00236 };
00237 
00238 const SEC_ASN1Template CRMFPOPOKeyEnciphermentTemplate[] = {
00239     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
00240       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
00241       0,
00242       SEC_ASN1_SUB(SEC_AnyTemplate) },
00243     { 0 }
00244 };
00245 
00246 const SEC_ASN1Template CRMFPOPOKeyAgreementTemplate[] = {
00247     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
00248       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 3,
00249       0,
00250       SEC_ASN1_SUB(SEC_AnyTemplate)},
00251     { 0 }
00252 };
00253 
00254 const SEC_ASN1Template CRMFEncryptedValueTemplate[] = {
00255     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFEncryptedValue)},
00256     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 
00257       SEC_ASN1_XTRN | 0,
00258       offsetof(CRMFEncryptedValue, intendedAlg), 
00259       SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
00260     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 
00261       SEC_ASN1_XTRN | 1,
00262       offsetof (CRMFEncryptedValue, symmAlg), 
00263       SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
00264     { SEC_ASN1_NO_STREAM | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 
00265       SEC_ASN1_XTRN | 2, 
00266       offsetof(CRMFEncryptedValue, encSymmKey), 
00267       SEC_ASN1_SUB(SEC_BitStringTemplate) },
00268     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 
00269       SEC_ASN1_XTRN | 3,
00270       offsetof(CRMFEncryptedValue, keyAlg), 
00271       SEC_ASN1_SUB(SECOID_AlgorithmIDTemplate) },
00272     { SEC_ASN1_NO_STREAM | SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 
00273       SEC_ASN1_XTRN | 4,
00274       offsetof(CRMFEncryptedValue, valueHint),
00275       SEC_ASN1_SUB(SEC_OctetStringTemplate) },
00276     { SEC_ASN1_BIT_STRING, offsetof(CRMFEncryptedValue, encValue) },
00277     { 0 }
00278 };
00279 
00280 const SEC_ASN1Template CRMFEncryptedKeyWithEncryptedValueTemplate [] = {
00281     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
00282       SEC_ASN1_CONTEXT_SPECIFIC | 0,
00283       0,
00284       CRMFEncryptedValueTemplate},
00285     { 0 }
00286 };
00287 
00288 static const SEC_ASN1Template CRMFSinglePubInfoTemplate[] = {
00289     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFSinglePubInfo)},
00290     { SEC_ASN1_INTEGER, offsetof(CRMFSinglePubInfo, pubMethod) },
00291     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC,
00292       offsetof(CRMFSinglePubInfo, pubLocation) },
00293     { 0 }
00294 };
00295 
00296 static const SEC_ASN1Template CRMFPublicationInfoTemplate[] ={ 
00297     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPKIPublicationInfo) },
00298     { SEC_ASN1_INTEGER, offsetof(CRMFPKIPublicationInfo, action) },
00299     { SEC_ASN1_POINTER, offsetof(CRMFPKIPublicationInfo, pubInfos),
00300       CRMFSinglePubInfoTemplate},
00301     { 0 }
00302 };