crmftmpl.c
上传用户:lyxiangda
上传日期:2007-01-12
资源大小:3042k
文件大小:10k
源码类别:

CA认证

开发平台:

WINDOWS

  1. /* -*- Mode: C; tab-width: 8 -*- */
  2. /*
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  * 
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  * 
  13.  * The Original Code is the Netscape security libraries.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are 
  17.  * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
  18.  * Rights Reserved.
  19.  * 
  20.  * Contributor(s):
  21.  * 
  22.  * Alternatively, the contents of this file may be used under the
  23.  * terms of the GNU General Public License Version 2 or later (the
  24.  * "GPL"), in which case the provisions of the GPL are applicable 
  25.  * instead of those above.  If you wish to allow use of your 
  26.  * version of this file only under the terms of the GPL and not to
  27.  * allow others to use your version of this file under the MPL,
  28.  * indicate your decision by deleting the provisions above and
  29.  * replace them with the notice and other provisions required by
  30.  * the GPL.  If you do not delete the provisions above, a recipient
  31.  * may use your version of this file under either the MPL or the
  32.  * GPL.
  33.  */
  34. #include "crmf.h"
  35. #include "crmfi.h"
  36. #include "secoid.h"
  37. #include "secasn1.h"
  38. /* 
  39.  * It's all implicit tagging.
  40.  */
  41. const SEC_ASN1Template CRMFControlTemplate[] = {
  42.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFControl)},
  43.     { SEC_ASN1_OBJECT_ID, offsetof(CRMFControl, derTag)},
  44.     { SEC_ASN1_ANY, offsetof(CRMFControl, derValue) },
  45.     { 0 }
  46. };
  47. static const SEC_ASN1Template CRMFCertExtensionTemplate[] = {
  48.     { SEC_ASN1_SEQUENCE,
  49.   0, NULL, sizeof(CRMFCertExtension) },
  50.     { SEC_ASN1_OBJECT_ID,
  51.   offsetof(CRMFCertExtension,id) },
  52.     { SEC_ASN1_OPTIONAL | SEC_ASN1_BOOLEAN,
  53.   offsetof(CRMFCertExtension,critical) },
  54.     { SEC_ASN1_OCTET_STRING,
  55.   offsetof(CRMFCertExtension,value) },
  56.     { 0, }
  57. };
  58. static const SEC_ASN1Template CRMFSequenceOfCertExtensionTemplate[] = {
  59.     { SEC_ASN1_SEQUENCE_OF, 0, CRMFCertExtensionTemplate }
  60. };
  61. static const SEC_ASN1Template CRMFOptionalValidityTemplate[] = {
  62.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFOptionalValidity) },
  63.     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
  64.       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 0, 
  65.       offsetof (CRMFOptionalValidity, notBefore),
  66.       SEC_UTCTimeTemplate},
  67.     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
  68.       SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 1, 
  69.       offsetof (CRMFOptionalValidity, notAfter),
  70.       SEC_UTCTimeTemplate},
  71.     { 0 }
  72. };
  73. static const SEC_ASN1Template crmfPointerToNameTemplate[] = {
  74.     { SEC_ASN1_POINTER, 0, CERT_NameTemplate},
  75.     { 0 }
  76. };
  77. static const SEC_ASN1Template CRMFCertTemplateTemplate[] = {
  78.    { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertTemplate) },
  79.    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 0, 
  80.      offsetof(CRMFCertTemplate, version), SEC_IntegerTemplate },
  81.    { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 1 ,
  82.      offsetof (CRMFCertTemplate, serialNumber), SEC_IntegerTemplate },
  83.    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 2, 
  84.      offsetof (CRMFCertTemplate, signingAlg), SECOID_AlgorithmIDTemplate },
  85.    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 
  86.      SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 3, 
  87.      offsetof (CRMFCertTemplate, issuer), crmfPointerToNameTemplate },
  88.    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 4, 
  89.      offsetof (CRMFCertTemplate, validity), 
  90.      CRMFOptionalValidityTemplate },
  91.    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 
  92.      SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 5, 
  93.      offsetof (CRMFCertTemplate, subject), crmfPointerToNameTemplate },
  94.    { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 6, 
  95.      offsetof (CRMFCertTemplate, publicKey), 
  96.      CERT_SubjectPublicKeyInfoTemplate }, 
  97.    { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 7,
  98.      offsetof (CRMFCertTemplate, issuerUID), SEC_BitStringTemplate },
  99.    { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 8,
  100.      offsetof (CRMFCertTemplate, subjectUID), SEC_BitStringTemplate },
  101.    { SEC_ASN1_CONSTRUCTED | SEC_ASN1_OPTIONAL | 
  102.      SEC_ASN1_CONTEXT_SPECIFIC | 9, 
  103.      offsetof (CRMFCertTemplate, extensions), 
  104.      CRMFSequenceOfCertExtensionTemplate },
  105.    { 0 }
  106. };
  107. static const SEC_ASN1Template CRMFAttributeTemplate[] = {
  108.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFAttribute)},
  109.     { SEC_ASN1_OBJECT_ID, offsetof(CRMFAttribute, derTag)},
  110.     { SEC_ASN1_ANY, offsetof(CRMFAttribute, derValue) },
  111.     { 0 }
  112. };
  113. const SEC_ASN1Template CRMFCertRequestTemplate[] = {
  114.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFCertRequest) },
  115.     { SEC_ASN1_INTEGER, offsetof(CRMFCertRequest, certReqId)},
  116.     { SEC_ASN1_INLINE, offsetof(CRMFCertRequest, certTemplate), 
  117.       CRMFCertTemplateTemplate},
  118.     { SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
  119.       offsetof(CRMFCertRequest,controls), 
  120.       CRMFControlTemplate}, /* SEQUENCE SIZE (1...MAX)*/
  121.     { 0 }
  122. };
  123. const SEC_ASN1Template CRMFCertReqMsgTemplate[] = {
  124.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFCertReqMsg) },
  125.     { SEC_ASN1_POINTER, offsetof(CRMFCertReqMsg, certReq),
  126.       CRMFCertRequestTemplate },
  127.     { SEC_ASN1_ANY | SEC_ASN1_OPTIONAL,
  128.       offsetof(CRMFCertReqMsg, derPOP) },
  129.     { SEC_ASN1_OPTIONAL | SEC_ASN1_SEQUENCE_OF,
  130.       offsetof(CRMFCertReqMsg, regInfo), 
  131.       CRMFAttributeTemplate}, /* SEQUENCE SIZE (1...MAX)*/
  132.     { 0 }
  133. };
  134. const SEC_ASN1Template CRMFCertReqMessagesTemplate[] = {
  135.     { SEC_ASN1_SEQUENCE_OF, offsetof(CRMFCertReqMessages, messages), 
  136.       CRMFCertReqMsgTemplate, sizeof (CRMFCertReqMessages)}
  137. };
  138. static const SEC_ASN1Template CRMFPOPOSigningKeyInputTemplate[] = {
  139.     { SEC_ASN1_SEQUENCE, 0, NULL,sizeof(CRMFPOPOSigningKeyInput) },
  140.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | 
  141.       SEC_ASN1_CONTEXT_SPECIFIC | 0,
  142.       offsetof(CRMFPOPOSigningKeyInput, authInfo.sender) },
  143.     { SEC_ASN1_BIT_STRING | SEC_ASN1_OPTIONAL | 1,
  144.       offsetof (CRMFPOPOSigningKeyInput, authInfo.publicKeyMAC) },
  145.     { SEC_ASN1_INLINE, offsetof(CRMFPOPOSigningKeyInput, publicKey), 
  146.       CERT_SubjectPublicKeyInfoTemplate },
  147.     { 0 }
  148. };
  149. const SEC_ASN1Template CRMFRAVerifiedTemplate[] = {
  150.     { SEC_ASN1_CONTEXT_SPECIFIC | 0, 
  151.       0,
  152.       SEC_NullTemplate },
  153.     { 0 }
  154. };
  155. /* This template will need to add POPOSigningKeyInput eventually, maybe*/
  156. static const SEC_ASN1Template crmfPOPOSigningKeyTemplate[] = {
  157.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPOPOSigningKey) },
  158.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 0,
  159.       offsetof(CRMFPOPOSigningKey, derInput), SEC_AnyTemplate},
  160.     { SEC_ASN1_POINTER, offsetof(CRMFPOPOSigningKey, algorithmIdentifier),
  161.       SECOID_AlgorithmIDTemplate },
  162.     { SEC_ASN1_BIT_STRING, offsetof(CRMFPOPOSigningKey, signature),
  163.       SEC_BitStringTemplate},
  164.     { 0 }
  165. };
  166. const SEC_ASN1Template CRMFPOPOSigningKeyTemplate[] = {
  167.     { SEC_ASN1_CONTEXT_SPECIFIC | 1,
  168.       0,
  169.       crmfPOPOSigningKeyTemplate},
  170.     { 0 }
  171. };
  172. const SEC_ASN1Template CRMFThisMessageTemplate[] = {
  173.     { SEC_ASN1_CONTEXT_SPECIFIC | 0,
  174.       0,
  175.       SEC_BitStringTemplate},
  176.     { 0 }
  177. };
  178. const SEC_ASN1Template CRMFSubsequentMessageTemplate[] = {
  179.     { SEC_ASN1_CONTEXT_SPECIFIC | 1,
  180.       0, 
  181.       SEC_IntegerTemplate},
  182.     { 0 }
  183. };
  184. const SEC_ASN1Template CRMFDHMACTemplate[] = {
  185.     { SEC_ASN1_CONTEXT_SPECIFIC | 0,
  186.       0,
  187.       SEC_BitStringTemplate},
  188.     { 0 }
  189. };
  190. const SEC_ASN1Template CRMFPOPOKeyEnciphermentTemplate[] = {
  191.     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
  192.       SEC_ASN1_CONTEXT_SPECIFIC | 2,
  193.       0,
  194.       SEC_AnyTemplate},
  195.     { 0 }
  196. };
  197. const SEC_ASN1Template CRMFPOPOKeyAgreementTemplate[] = {
  198.     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
  199.       SEC_ASN1_CONTEXT_SPECIFIC | 3,
  200.       0,
  201.       SEC_AnyTemplate},
  202.     { 0 }
  203. };
  204. const SEC_ASN1Template CRMFEncryptedValueTemplate[] = {
  205.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFEncryptedValue)},
  206.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 0,
  207.       offsetof(CRMFEncryptedValue, intendedAlg), 
  208.       SECOID_AlgorithmIDTemplate},
  209.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 1,
  210.       offsetof (CRMFEncryptedValue, symmAlg), 
  211.       SECOID_AlgorithmIDTemplate },
  212.     { SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_OPTIONAL | 2, 
  213.       offsetof(CRMFEncryptedValue, encSymmKey), SEC_BitStringTemplate},
  214.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_POINTER | 3,
  215.       offsetof(CRMFEncryptedValue, keyAlg), 
  216.       SECOID_AlgorithmIDTemplate },
  217.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | 4,
  218.       offsetof(CRMFEncryptedValue, valueHint),
  219.       SEC_OctetStringTemplate},
  220.     { SEC_ASN1_BIT_STRING, offsetof(CRMFEncryptedValue, encValue) },
  221.     { 0 }
  222. };
  223. const SEC_ASN1Template CRMFEncryptedKeyWithEncryptedValueTemplate [] = {
  224.     { SEC_ASN1_EXPLICIT | SEC_ASN1_CONSTRUCTED | 
  225.       SEC_ASN1_CONTEXT_SPECIFIC | 0,
  226.       0,
  227.       CRMFEncryptedValueTemplate},
  228.     { 0 }
  229. };
  230. static const SEC_ASN1Template CRMFSinglePubInfoTemplate[] = {
  231.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof (CRMFSinglePubInfo)},
  232.     { SEC_ASN1_INTEGER, offsetof(CRMFSinglePubInfo, pubMethod) },
  233.     { SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC,
  234.       offsetof(CRMFSinglePubInfo, pubLocation) },
  235.     { 0 }
  236. };
  237. static const SEC_ASN1Template CRMFPublicationInfoTemplate[] ={ 
  238.     { SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CRMFPKIPublicationInfo) },
  239.     { SEC_ASN1_INTEGER, offsetof(CRMFPKIPublicationInfo, action) },
  240.     { SEC_ASN1_POINTER, offsetof(CRMFPKIPublicationInfo, pubInfos),
  241.       CRMFSinglePubInfoTemplate},
  242.     { 0 }
  243. };