Back to index

lightning-sunbird  0.9+nobinonly
crmfi.h
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 
00039 #ifndef _CRMFI_H_
00040 #define _CRMFI_H_
00041 /* This file will contain all declarations common to both 
00042  * encoding and decoding of CRMF Cert Requests.  This header 
00043  * file should only be included internally by CRMF implementation
00044  * files.
00045  */
00046 #include "secasn1.h"
00047 #include "crmfit.h"
00048 #include "secerr.h"
00049 
00050 #define CRMF_DEFAULT_ARENA_SIZE   1024
00051 #define MAX_WRAPPED_KEY_LEN       2048
00052 
00053 
00054 #define CRMF_BITS_TO_BYTES(bits) (((bits)+7)/8)
00055 #define CRMF_BYTES_TO_BITS(bytes) ((bytes)*8)
00056 
00057 struct crmfEncoderArg {
00058     SECItem *buffer;
00059     long     allocatedLen;
00060 };
00061 
00062 struct crmfEncoderOutput {
00063     CRMFEncoderOutputCallback fn;
00064     void *outputArg;
00065 };
00066 
00067 /*
00068  * This funciton is used by the API for encoding functions that are 
00069  * exposed through the API, ie all of the CMMF_Encode* and CRMF_Encode*
00070  * functions.
00071  */
00072 extern void
00073        crmf_encoder_out(void *arg, const char *buf, unsigned long len,
00074                         int depth, SEC_ASN1EncodingPart data_kind);
00075 
00076 /*
00077  * This function is used when we want to encode something locally within
00078  * the library, ie the CertRequest so that we can produce its signature.
00079  */
00080 extern SECStatus 
00081        crmf_init_encoder_callback_arg (struct crmfEncoderArg *encoderArg,
00082                                    SECItem               *derDest);
00083 
00084 /*
00085  * This is the callback function we feed to the ASN1 encoder when doing
00086  * internal DER-encodings.  ie, encoding the cert request so we can 
00087  * produce a signature.
00088  */
00089 extern void
00090 crmf_generic_encoder_callback(void *arg, const char* buf, unsigned long len,
00091                            int depth, SEC_ASN1EncodingPart data_kind);
00092 
00093 /* The ASN1 templates that need to be seen by internal files
00094  * in order to implement CRMF.
00095  */
00096 extern const SEC_ASN1Template CRMFCertReqMsgTemplate[];
00097 extern const SEC_ASN1Template CRMFRAVerifiedTemplate[];
00098 extern const SEC_ASN1Template CRMFPOPOSigningKeyTemplate[];
00099 extern const SEC_ASN1Template CRMFPOPOKeyEnciphermentTemplate[];
00100 extern const SEC_ASN1Template CRMFPOPOKeyAgreementTemplate[];
00101 extern const SEC_ASN1Template CRMFThisMessageTemplate[];
00102 extern const SEC_ASN1Template CRMFSubsequentMessageTemplate[];
00103 extern const SEC_ASN1Template CRMFDHMACTemplate[];
00104 extern const SEC_ASN1Template CRMFEncryptedKeyWithEncryptedValueTemplate[];
00105 extern const SEC_ASN1Template CRMFEncryptedValueTemplate[];
00106 
00107 /*
00108  * Use these two values for encoding Boolean values.
00109  */
00110 extern const unsigned char hexTrue;
00111 extern const unsigned char hexFalse;
00112 /*
00113  * Prototypes for helper routines used internally by multiple files.
00114  */
00115 extern SECStatus crmf_encode_integer(PRArenaPool *poolp, SECItem *dest, 
00116                                  long value);
00117 extern SECStatus crmf_make_bitstring_copy(PRArenaPool *arena, SECItem *dest, 
00118                                      SECItem *src);
00119 
00120 extern SECStatus crmf_copy_pkiarchiveoptions(PRArenaPool           *poolp, 
00121                                         CRMFPKIArchiveOptions *destOpt,
00122                                         CRMFPKIArchiveOptions *srcOpt);
00123 extern SECStatus  
00124        crmf_destroy_pkiarchiveoptions(CRMFPKIArchiveOptions *inArchOptions,
00125                                   PRBool                 freeit);
00126 extern const SEC_ASN1Template*
00127        crmf_get_pkiarchiveoptions_subtemplate(CRMFControl *inControl);
00128 
00129 extern SECStatus crmf_copy_encryptedkey(PRArenaPool       *poolp,
00130                                    CRMFEncryptedKey  *srcEncrKey,
00131                                    CRMFEncryptedKey  *destEncrKey);
00132 extern SECStatus
00133 crmf_copy_encryptedvalue(PRArenaPool        *poolp,
00134                       CRMFEncryptedValue *srcValue,
00135                       CRMFEncryptedValue *destValue);
00136 
00137 extern SECStatus
00138 crmf_copy_encryptedvalue_secalg(PRArenaPool     *poolp,
00139                             SECAlgorithmID  *srcAlgId,
00140                             SECAlgorithmID **destAlgId);
00141 
00142 extern SECStatus crmf_template_copy_secalg(PRArenaPool *poolp, 
00143                                       SECAlgorithmID **dest,
00144                                       SECAlgorithmID *src);
00145 
00146 extern SECStatus crmf_copy_cert_name(PRArenaPool *poolp, CERTName **dest, 
00147                                  CERTName *src);
00148 
00149 extern SECStatus crmf_template_add_public_key(PRArenaPool               *poolp,
00150                                          CERTSubjectPublicKeyInfo **dest,
00151                                          CERTSubjectPublicKeyInfo  *pubKey);
00152 
00153 extern CRMFCertExtension* crmf_create_cert_extension(PRArenaPool *poolp, 
00154                                                SECOidTag    tag, 
00155                                                PRBool       isCritical,
00156                                                SECItem     *data);
00157 extern CRMFCertRequest*
00158 crmf_copy_cert_request(PRArenaPool *poolp, CRMFCertRequest *srcReq);
00159 
00160 extern SECStatus crmf_destroy_encrypted_value(CRMFEncryptedValue *inEncrValue, 
00161                                          PRBool freeit);
00162 
00163 extern CRMFEncryptedValue *
00164 crmf_create_encrypted_value_wrapped_privkey(SECKEYPrivateKey   *inPrivKey,
00165                                        SECKEYPublicKey    *inPubKey,
00166                                        CRMFEncryptedValue *destValue);
00167 
00168 extern CK_MECHANISM_TYPE 
00169        crmf_get_mechanism_from_public_key(SECKEYPublicKey *inPubKey);
00170 
00171 extern SECStatus
00172 crmf_encrypted_value_unwrap_priv_key(PRArenaPool        *poolp,
00173                                  CRMFEncryptedValue *encValue,
00174                                  SECKEYPrivateKey   *privKey,
00175                                  SECKEYPublicKey    *newPubKey,
00176                                  SECItem            *nickname,
00177                                  PK11SlotInfo       *slot,
00178                                  unsigned char       keyUsage,
00179                                  SECKEYPrivateKey  **unWrappedKey,
00180                                  void               *wincx);
00181 
00182 extern SECItem*
00183 crmf_get_public_value(SECKEYPublicKey *pubKey, SECItem *dest);
00184 
00185 extern CRMFCertExtension*
00186 crmf_copy_cert_extension(PRArenaPool *poolp, CRMFCertExtension *inExtension);
00187 
00188 extern SECStatus
00189 crmf_create_prtime(SECItem *src, PRTime **dest);
00190 #endif /*_CRMFI_H_*/