Back to index

lightning-sunbird  0.9+nobinonly
p12.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 
00038 #ifndef _P12_H_
00039 #define _P12_H_
00040 
00041 #include "secoid.h"
00042 #include "key.h"
00043 #include "secpkcs7.h"
00044 #include "p12t.h"
00045 
00046 typedef int (PR_CALLBACK * PKCS12OpenFunction)(void *arg);
00047 typedef int (PR_CALLBACK * PKCS12ReadFunction)(void *arg,
00048                                                unsigned char *buffer, 
00049                                                unsigned int *lenRead,
00050                                                unsigned int maxLen);
00051 typedef int (PR_CALLBACK * PKCS12WriteFunction)(void *arg,
00052                                                 unsigned char *buffer, 
00053                                                 unsigned int *bufLen,
00054                                                 unsigned int *lenWritten);
00055 typedef int (PR_CALLBACK * PKCS12CloseFunction)(void *arg);
00056 typedef SECStatus (PR_CALLBACK * PKCS12UnicodeConvertFunction)(
00057                                  PRArenaPool *arena,
00058                                  SECItem *dest, SECItem *src,
00059                                  PRBool toUnicode,
00060                                  PRBool swapBytes);
00061 typedef void (PR_CALLBACK * SEC_PKCS12EncoderOutputCallback)(
00062                             void *arg, const char *buf,
00063                             unsigned long len);
00064 typedef void (PR_CALLBACK * SEC_PKCS12DecoderOutputCallback)(
00065                             void *arg, const char *buf,
00066                             unsigned long len);
00067 typedef SECItem * (PR_CALLBACK * SEC_PKCS12NicknameCollisionCallback)(
00068                                  SECItem *old_nickname,
00069                                  PRBool *cancel,
00070                                  void *arg);
00071 
00072 
00073 
00074 
00075 typedef SECStatus (PR_CALLBACK *digestOpenFn)(void *arg, PRBool readData);
00076 typedef SECStatus (PR_CALLBACK *digestCloseFn)(void *arg, PRBool removeFile);
00077 typedef int (PR_CALLBACK *digestIOFn)(void *arg, unsigned char *buf, 
00078                                       unsigned long len);
00079 
00080 typedef struct SEC_PKCS12ExportContextStr SEC_PKCS12ExportContext;
00081 typedef struct SEC_PKCS12SafeInfoStr SEC_PKCS12SafeInfo;
00082 typedef struct SEC_PKCS12DecoderContextStr SEC_PKCS12DecoderContext;
00083 typedef struct SEC_PKCS12DecoderItemStr SEC_PKCS12DecoderItem;
00084 
00085 struct sec_PKCS12PasswordModeInfo {
00086     SECItem   *password;
00087     SECOidTag algorithm;
00088 };
00089 
00090 struct sec_PKCS12PublicKeyModeInfo {
00091     CERTCertificate  *cert;
00092     CERTCertDBHandle *certDb;
00093     SECOidTag algorithm;
00094     int keySize;
00095 };
00096 
00097 struct SEC_PKCS12DecoderItemStr {
00098     SECItem *der;
00099     SECOidTag type;
00100     PRBool hasKey;
00101     SECItem *friendlyName;      /* UTF-8 string */
00102 };
00103     
00104 
00105 SEC_BEGIN_PROTOS
00106 
00107 SEC_PKCS12SafeInfo *
00108 SEC_PKCS12CreatePubKeyEncryptedSafe(SEC_PKCS12ExportContext *p12ctxt,
00109                                 CERTCertDBHandle *certDb,
00110                                 CERTCertificate *signer,
00111                                 CERTCertificate **recipients,
00112                                 SECOidTag algorithm, int keysize);
00113 
00114 extern SEC_PKCS12SafeInfo *
00115 SEC_PKCS12CreatePasswordPrivSafe(SEC_PKCS12ExportContext *p12ctxt, 
00116                              SECItem *pwitem, SECOidTag privAlg);
00117 
00118 extern SEC_PKCS12SafeInfo *
00119 SEC_PKCS12CreateUnencryptedSafe(SEC_PKCS12ExportContext *p12ctxt);
00120 
00121 extern SECStatus
00122 SEC_PKCS12AddPasswordIntegrity(SEC_PKCS12ExportContext *p12ctxt,
00123                             SECItem *pwitem, SECOidTag integAlg);
00124 extern SECStatus
00125 SEC_PKCS12AddPublicKeyIntegrity(SEC_PKCS12ExportContext *p12ctxt,
00126                             CERTCertificate *cert, CERTCertDBHandle *certDb,
00127                             SECOidTag algorithm, int keySize);
00128 
00129 extern SEC_PKCS12ExportContext *
00130 SEC_PKCS12CreateExportContext(SECKEYGetPasswordKey pwfn, void *pwfnarg,  
00131                            PK11SlotInfo *slot, void *wincx);
00132 
00133 extern SECStatus
00134 SEC_PKCS12AddCert(SEC_PKCS12ExportContext *p12ctxt, 
00135                 SEC_PKCS12SafeInfo *safe, void *nestedDest,
00136                 CERTCertificate *cert, CERTCertDBHandle *certDb,
00137                 SECItem *keyId, PRBool includeCertChain);
00138 
00139 extern SECStatus
00140 SEC_PKCS12AddKeyForCert(SEC_PKCS12ExportContext *p12ctxt, 
00141                      SEC_PKCS12SafeInfo *safe, 
00142                      void *nestedDest, CERTCertificate *cert,
00143                      PRBool shroudKey, SECOidTag algorithm, SECItem *pwitem,
00144                      SECItem *keyId, SECItem *nickName);
00145 
00146 extern SECStatus
00147 SEC_PKCS12AddCertAndKey(SEC_PKCS12ExportContext *p12ctxt, 
00148                      void *certSafe, void *certNestedDest, 
00149                      CERTCertificate *cert, CERTCertDBHandle *certDb,
00150                      void *keySafe, void *keyNestedDest, 
00151                      PRBool shroudKey, SECItem *pwitem, SECOidTag algorithm);
00152 
00153 extern SECStatus
00154 SEC_PKCS12AddDERCertAndEncryptedKey(SEC_PKCS12ExportContext *p12ctxt, 
00155                      void *certSafe, void *certNestedDest, SECItem *derCert,
00156                      void *keySafe, void *keyNestedDest, 
00157                      SECKEYEncryptedPrivateKeyInfo *epki, char *nickname);
00158 
00159 extern void *
00160 SEC_PKCS12CreateNestedSafeContents(SEC_PKCS12ExportContext *p12ctxt,
00161                                void *baseSafe, void *nestedDest);
00162 
00163 extern SECStatus
00164 SEC_PKCS12Encode(SEC_PKCS12ExportContext *p12exp, 
00165                SEC_PKCS12EncoderOutputCallback output, void *outputarg);
00166 
00167 extern void
00168 SEC_PKCS12DestroyExportContext(SEC_PKCS12ExportContext *p12exp);
00169 
00170 extern SEC_PKCS12DecoderContext *
00171 SEC_PKCS12DecoderStart(SECItem *pwitem, PK11SlotInfo *slot, void *wincx,
00172                      digestOpenFn dOpen, digestCloseFn dClose,
00173                      digestIOFn dRead, digestIOFn dWrite, void *dArg);
00174 
00175 extern SECStatus
00176 SEC_PKCS12DecoderSetTargetTokenCAs(SEC_PKCS12DecoderContext *p12dcx,
00177                                SECPKCS12TargetTokenCAs tokenCAs);
00178 
00179 extern SECStatus
00180 SEC_PKCS12DecoderUpdate(SEC_PKCS12DecoderContext *p12dcx, unsigned char *data,
00181                      unsigned long len);
00182 
00183 extern void
00184 SEC_PKCS12DecoderFinish(SEC_PKCS12DecoderContext *p12dcx);
00185 
00186 extern SECStatus
00187 SEC_PKCS12DecoderVerify(SEC_PKCS12DecoderContext *p12dcx);
00188 
00189 extern SECStatus
00190 SEC_PKCS12DecoderValidateBags(SEC_PKCS12DecoderContext *p12dcx,
00191                            SEC_PKCS12NicknameCollisionCallback nicknameCb);
00192 
00193 extern SECStatus
00194 SEC_PKCS12DecoderImportBags(SEC_PKCS12DecoderContext *p12dcx);
00195 
00196 CERTCertList *
00197 SEC_PKCS12DecoderGetCerts(SEC_PKCS12DecoderContext *p12dcx);
00198 
00199 SECStatus
00200 SEC_PKCS12DecoderIterateInit(SEC_PKCS12DecoderContext *p12dcx);
00201 
00202 SECStatus
00203 SEC_PKCS12DecoderIterateNext(SEC_PKCS12DecoderContext *p12dcx,
00204                              const SEC_PKCS12DecoderItem **ipp);
00205 
00206 SEC_END_PROTOS
00207 
00208 #endif