Back to index

lightning-sunbird  0.9+nobinonly
mimemsig.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
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 of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 #ifndef _MIMEMSIG_H_
00039 #define _MIMEMSIG_H_
00040 
00041 #include "mimemult.h"
00042 #include "mimepbuf.h"
00043 #include "modmimee.h"
00044 
00045 /* The MimeMultipartSigned class implements the multipart/signed MIME
00046    container, which provides a general method of associating a cryptographic
00047    signature to an arbitrary MIME object.
00048 
00049    The MimeMultipartSigned class provides the following methods:
00050 
00051    void *crypto_init (MimeObject *multipart_object)
00052 
00053      This is called with the object, the object->headers of which should be
00054         used to initialize the dexlateion engine.  NULL indicates failure;
00055         otherwise, an opaque closure object should be returned.
00056 
00057    int crypto_data_hash (char *data, PRInt32 data_size, 
00058                                            void *crypto_closure)
00059 
00060      This is called with the raw data, for which a signature has been computed.
00061         The crypto module should examine this, and compute a signature for it.
00062 
00063    int crypto_data_eof (void *crypto_closure, PRBool abort_p)
00064 
00065      This is called when no more data remains.  If `abort_p' is true, then the
00066         crypto module may choose to discard any data rather than processing it,
00067         as we're terminating abnormally.
00068 
00069    int crypto_signature_init (void *crypto_closure,
00070                               MimeObject *multipart_object,
00071                                                    MimeHeaders *signature_hdrs)
00072 
00073      This is called after crypto_data_eof() and just before the first call to
00074         crypto_signature_hash().  The crypto module may wish to do some
00075         initialization here, or may wish to examine the actual headers of the
00076         signature object itself.
00077 
00078    int crypto_signature_hash (char *data, PRInt32 data_size,
00079                                                    void *crypto_closure)
00080 
00081      This is called with the raw data of the detached signature block.  It will
00082         be called after crypto_data_eof() has been called to signify the end of
00083         the data which is signed.  This data is the data of the signature itself.
00084 
00085    int crypto_signature_eof (void *crypto_closure, PRBool abort_p)
00086 
00087      This is called when no more signature data remains.  If `abort_p' is true,
00088         then the crypto module may choose to discard any data rather than
00089         processing it, as we're terminating abnormally.
00090 
00091    char * crypto_generate_html (void *crypto_closure)
00092 
00093      This is called after `crypto_signature_eof' but before `crypto_free'.
00094         The crypto module should return a newly-allocated string of HTML code
00095         which explains the status of the dexlateion to the user (whether the
00096         signature checks out, etc.)
00097 
00098    void crypto_free (void *crypto_closure)
00099 
00100      This will be called when we're all done, after `crypto_signature_eof' and
00101         `crypto_emit_html'.  It is intended to free any data represented by the
00102         crypto_closure.
00103  */
00104 
00105 typedef struct MimeMultipartSignedClass MimeMultipartSignedClass;
00106 typedef struct MimeMultipartSigned      MimeMultipartSigned;
00107 
00108 typedef enum {
00109   MimeMultipartSignedPreamble,
00110   MimeMultipartSignedBodyFirstHeader,
00111   MimeMultipartSignedBodyHeaders,
00112   MimeMultipartSignedBodyFirstLine,
00113   MimeMultipartSignedBodyLine,
00114   MimeMultipartSignedSignatureHeaders,
00115   MimeMultipartSignedSignatureFirstLine,
00116   MimeMultipartSignedSignatureLine,
00117   MimeMultipartSignedEpilogue
00118 } MimeMultipartSignedParseState;
00119 
00120 struct MimeMultipartSignedClass {
00121   MimeMultipartClass multipart;
00122 
00123   /* Callbacks used by dexlateion (really, signature verification) module. */
00124   void * (*crypto_init) (MimeObject *multipart_object);
00125 
00126   int (*crypto_data_hash)      (char *data, PRInt32 data_size,
00127                                                         void *crypto_closure);
00128   int (*crypto_signature_hash) (char *data, PRInt32 data_size,
00129                                                         void *crypto_closure);
00130 
00131   int (*crypto_data_eof)      (void *crypto_closure, PRBool abort_p);
00132   int (*crypto_signature_eof) (void *crypto_closure, PRBool abort_p);
00133 
00134   int (*crypto_signature_init) (void *crypto_closure,
00135                                                         MimeObject *multipart_object,
00136                                                         MimeHeaders *signature_hdrs);
00137 
00138   char * (*crypto_generate_html) (void *crypto_closure);
00139 
00140   void (*crypto_free) (void *crypto_closure);
00141 };
00142 
00143 extern "C" MimeMultipartSignedClass mimeMultipartSignedClass;
00144 
00145 struct MimeMultipartSigned {
00146   MimeMultipart multipart;
00147   MimeMultipartSignedParseState state;    /* State of parser */
00148 
00149   void *crypto_closure;                                 /* Opaque data used by signature
00150                                                                              verification module. */
00151 
00152   MimeHeaders *body_hdrs;                        /* The headers of the signed object. */
00153   MimeHeaders *sig_hdrs;                         /* The headers of the signature. */
00154 
00155   MimePartBufferData *part_buffer;     /* The buffered body of the signed
00156                                                                          object (see mimepbuf.h) */
00157 
00158   MimeDecoderData *sig_decoder_data;      /* The signature is probably base64
00159                                                                          encoded; this is the decoder used
00160                                                                          to get raw bits out of it. */
00161 };
00162 
00163 #endif /* _MIMEMSIG_H_ */