modules/libmar/src/mar_cmdline.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef MAR_CMDLINE_H__
     6 #define MAR_CMDLINE_H__
     8 /* We use NSPR here just to import the definition of uint32_t */
    10 #ifdef __cplusplus
    11 extern "C" {
    12 #endif
    14 struct ProductInformationBlock;
    16 /**
    17  * Determines MAR file information.
    18  *
    19  * @param path                   The path of the MAR file to check.
    20  * @param hasSignatureBlock      Optional out parameter specifying if the MAR
    21  *                               file has a signature block or not.
    22  * @param numSignatures          Optional out parameter for storing the number
    23  *                               of signatures in the MAR file.
    24  * @param hasAdditionalBlocks    Optional out parameter specifying if the MAR
    25  *                               file has additional blocks or not.
    26  * @param offsetAdditionalBlocks Optional out parameter for the offset to the 
    27  *                               first additional block. Value is only valid if
    28  *                               hasAdditionalBlocks is not equal to 0.
    29  * @param numAdditionalBlocks    Optional out parameter for the number of
    30  *                               additional blocks.  Value is only valid if
    31  *                               has_additional_blocks is not equal to 0.
    32  * @return 0 on success and non-zero on failure.
    33  */
    34 int get_mar_file_info(const char *path, 
    35                       int *hasSignatureBlock,
    36                       uint32_t *numSignatures,
    37                       int *hasAdditionalBlocks,
    38                       uint32_t *offsetAdditionalBlocks,
    39                       uint32_t *numAdditionalBlocks);
    41 /**
    42  * Verifies a MAR file by verifying each signature with the corresponding
    43  * certificate. That is, the first signature will be verified using the first
    44  * certificate given, the second signature will be verified using the second
    45  * certificate given, etc. The signature count must exactly match the number of
    46  * certificates given, and all signature verifications must succeed.
    47  * This is only used by the signmar program when used with arguments to verify 
    48  * a MAR. This should not be used to verify a MAR that will be extracted in the 
    49  * same operation by updater code. This function prints the error message if 
    50  * verification fails.
    51  * 
    52  * @param pathToMAR     The path of the MAR file whose signature should be
    53  *                      checked
    54  * @param certData      Pointer to the first element in an array of certificate
    55  *                      file data.
    56  * @param certDataSizes Pointer to the first element in an array for size of
    57  *                      the cert data.
    58  * @param certNames     Pointer to the first element in an array of certificate
    59  *                      names.
    60  *                      Used only if compiled with NSS support
    61  * @param certCount     The number of elements in certData, certDataSizes,
    62  *                      and certNames
    63  * @return 0 on success
    64  *         a negative number if there was an error
    65  *         a positive number if the signature does not verify
    66  */
    67 int mar_verify_signatures(const char *pathToMAR,
    68                           const uint8_t * const *certData,
    69                           const uint32_t *certDataSizes,
    70                           const char * const *certNames,
    71                           uint32_t certCount);
    73 /** 
    74  * Reads the product info block from the MAR file's additional block section.
    75  * The caller is responsible for freeing the fields in infoBlock
    76  * if the return is successful.
    77  *
    78  * @param infoBlock Out parameter for where to store the result to
    79  * @return 0 on success, -1 on failure
    80 */
    81 int
    82 read_product_info_block(char *path, 
    83                         struct ProductInformationBlock *infoBlock);
    85 /** 
    86  * Refreshes the product information block with the new information.
    87  * The input MAR must not be signed or the function call will fail.
    88  * 
    89  * @param path             The path to the MAR file whose product info block
    90  *                         should be refreshed.
    91  * @param infoBlock        Out parameter for where to store the result to
    92  * @return 0 on success, -1 on failure
    93 */
    94 int
    95 refresh_product_info_block(const char *path,
    96                            struct ProductInformationBlock *infoBlock);
    98 /**
    99  * Writes out a copy of the MAR at src but with the signature block stripped.
   100  *
   101  * @param  src  The path of the source MAR file
   102  * @param  dest The path of the MAR file to write out that 
   103                 has no signature block
   104  * @return 0 on success
   105  *         -1 on error
   106 */
   107 int
   108 strip_signature_block(const char *src, const char * dest);
   110 /**
   111  * Extracts a signature from a MAR file, base64 encodes it, and writes it out
   112  *
   113  * @param  src       The path of the source MAR file
   114  * @param  sigIndex  The index of the signature to extract
   115  * @param  dest      The path of file to write the signature to
   116  * @return 0 on success
   117  *         -1 on error
   118 */
   119 int
   120 extract_signature(const char *src, uint32_t sigIndex, const char * dest);
   122 /**
   123  * Imports a base64 encoded signature into a MAR file
   124  *
   125  * @param  src           The path of the source MAR file
   126  * @param  sigIndex      The index of the signature to import
   127  * @param  base64SigFile A file which contains the signature to import
   128  * @param  dest          The path of the destination MAR file with replaced signature
   129  * @return 0 on success
   130  *         -1 on error
   131 */
   132 int
   133 import_signature(const char *src,
   134                  uint32_t sigIndex,
   135                  const char * base64SigFile,
   136                  const char *dest);
   138 #ifdef __cplusplus
   139 }
   140 #endif
   142 #endif  /* MAR_CMDLINE_H__ */

mercurial