LibreOffice Module onlineupdate (master) 1
Classes | Macros | Typedefs | Functions
mar.h File Reference
#include "mozilla/Assertions.h"
#include <stdint.h>
Include dependency graph for mar.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ProductInformationBlock
 
struct  MarItem_
 The MAR item data structure. More...
 
struct  MarFile_
 

Macros

#define MAX_SIGNATURES   8
 
#define TABLESIZE   256
 
#define MAR_MAX_CERT_SIZE   (16*1024)
 

Typedefs

typedef struct MarItem_ MarItem
 The MAR item data structure. More...
 
typedef struct MarFile_ MarFile
 
typedef int(* MarItemCallback) (MarFile *mar, const MarItem *item, void *data)
 Signature of callback function passed to mar_enum_items. More...
 

Functions

 MOZ_STATIC_ASSERT (MAX_SIGNATURES<=9, "too many signatures")
 
MarFilemar_open (const char *path)
 Open a MAR file for reading. More...
 
void mar_close (MarFile *mar)
 Close a MAR file that was opened using mar_open. More...
 
const MarItemmar_find_item (MarFile *mar, const char *item)
 Find an item in the MAR file by name. More...
 
int mar_enum_items (MarFile *mar, MarItemCallback callback, void *data)
 Enumerate all MAR items via callback function. More...
 
int mar_read (MarFile *mar, const MarItem *item, int offset, char *buf, int bufsize)
 Read from MAR item at given offset up to bufsize bytes. More...
 
int mar_create (const char *dest, int numfiles, char **files, struct ProductInformationBlock *infoBlock)
 Create a MAR file from a set of files. More...
 
int mar_extract (const char *path)
 Extract a MAR file to the current working directory. More...
 
int mar_read_entire_file (const char *filePath, uint32_t maxSize, const uint8_t **data, uint32_t *size)
 
int mar_verify_signatures (MarFile *mar, const uint8_t *const *certData, const uint32_t *certDataSizes, uint32_t certCount)
 Verifies a MAR file by verifying each signature with the corresponding certificate. More...
 
int mar_read_product_info_block (MarFile *mar, struct ProductInformationBlock *infoBlock)
 Reads the product info block from the MAR file's additional block section. More...
 

Macro Definition Documentation

◆ MAR_MAX_CERT_SIZE

#define MAR_MAX_CERT_SIZE   (16*1024)

Definition at line 137 of file mar.h.

◆ MAX_SIGNATURES

#define MAX_SIGNATURES   8

Definition at line 23 of file mar.h.

◆ TABLESIZE

#define TABLESIZE   256

Definition at line 46 of file mar.h.

Typedef Documentation

◆ MarFile

typedef struct MarFile_ MarFile

Definition at line 53 of file mar.h.

◆ MarItem

typedef struct MarItem_ MarItem

The MAR item data structure.

◆ MarItemCallback

typedef int(* MarItemCallback) (MarFile *mar, const MarItem *item, void *data)

Signature of callback function passed to mar_enum_items.

Parameters
marThe MAR file being visited.
itemThe MAR item being visited.
dataThe data parameter passed by the caller of mar_enum_items.
Returns
A non-zero value to stop enumerating.

Definition at line 62 of file mar.h.

Function Documentation

◆ mar_close()

void mar_close ( MarFile mar)

Close a MAR file that was opened using mar_open.

Parameters
marThe MarFile object to close.

Definition at line 195 of file mar_read.c.

References MarFile_::fp, i, MarFile_::item_table, MarItem_::next, and TABLESIZE.

Referenced by ArchiveReader::Close(), main(), mar_extract(), mar_fpopen(), and mar_test().

◆ mar_create()

int mar_create ( const char *  dest,
int  num_files,
char **  files,
struct ProductInformationBlock infoBlock 
)

Create a MAR file from a set of files.

Parameters
destThe path to the file to create. This path must be compatible with fopen.
numfilesThe number of files to store in the archive.
filesThe list of null-terminated file paths. Each file path must be compatible with fopen.
infoBlockThe information to store in the product information block.
Returns
A non-zero value if an error occurs.

Definition at line 293 of file mar_create.c.

References FILE, MarItemStack::head, HOST_TO_NETWORK64, htonl(), i, MarItemStack::last_offset, mar_concat_file(), mar_concat_product_info_block(), MAR_ID, MAR_ID_SIZE, mar_push(), MAX_SIZE_OF_MAR_FILE, NETWORK_TO_HOST64, ntohl(), remove(), and MarItemStack::size_used.

Referenced by main().

◆ mar_enum_items()

int mar_enum_items ( MarFile mar,
MarItemCallback  callback,
void *  data 
)

Enumerate all MAR items via callback function.

Parameters
marThe MAR file to enumerate.
callbackThe function to call for each MAR item.
dataA caller specified value that is passed along to the callback function.
Returns
0 if the enumeration ran to completion. Otherwise, any non-zero return value from the callback is returned.

Definition at line 497 of file mar_read.c.

References i, MarFile_::item_table, MarItem_::next, and TABLESIZE.

Referenced by mar_extract(), and mar_test().

◆ mar_extract()

int mar_extract ( const char *  path)

Extract a MAR file to the current working directory.

Parameters
pathThe path to the MAR file to extract. This path must be compatible with fopen.
Returns
A non-zero value if an error occurs.

Definition at line 73 of file mar_extract.c.

References mar_close(), mar_enum_items(), mar_open(), mar_test_callback(), and NULL.

Referenced by main().

◆ mar_find_item()

const MarItem * mar_find_item ( MarFile mar,
const char *  item 
)

Find an item in the MAR file by name.

Parameters
marThe MarFile object to query.
itemThe name of the item to query.
Returns
A const reference to a MAR item or NULL if not found.

Definition at line 484 of file mar_read.c.

References MarFile_::item_table, mar_hash_name(), name, MarItem_::name, and MarItem_::next.

Referenced by ArchiveReader::ExtractFile(), and ArchiveReader::ExtractFileToStream().

◆ mar_open()

MarFile * mar_open ( const char *  path)

Open a MAR file for reading.

Parameters
pathSpecifies the path to the MAR file to open. This path must be compatible with fopen.
Returns
NULL if an error occurs.

Definition at line 167 of file mar_read.c.

References FILE, mar_fpopen(), and NULL.

Referenced by main(), mar_extract(), mar_test(), and ArchiveReader::Open().

◆ mar_read()

int mar_read ( MarFile mar,
const MarItem item,
int  offset,
char *  buf,
int  bufsize 
)

Read from MAR item at given offset up to bufsize bytes.

Parameters
marThe MAR file to read.
itemThe MAR item to read.
offsetThe byte offset relative to the start of the item.
bufA pointer to a buffer to copy the data into.
bufsizeThe length of the buffer to copy the data into.
Returns
The number of bytes written or a negative value if an error occurs.

Definition at line 514 of file mar_read.c.

References MarFile_::fp, MarItem_::length, and MarItem_::offset.

Referenced by ArchiveReader::ExtractItemToStream(), and mar_test_callback().

◆ mar_read_entire_file()

int mar_read_entire_file ( const char *  filePath,
uint32_t  maxSize,
const uint8_t **  data,
uint32_t *  size 
)

Definition at line 22 of file mar_verify.c.

References FILE, filePath, result, and size.

Referenced by main().

◆ mar_read_product_info_block()

int mar_read_product_info_block ( MarFile mar,
struct ProductInformationBlock infoBlock 
)

Reads the product info block from the MAR file's additional block section.

The caller is responsible for freeing the fields in infoBlock if the return is successful.

Parameters
infoBlockOut parameter for where to store the result to
Returns
0 on success, -1 on failure

Definition at line 394 of file mar_read.c.

References MarFile_::fp, get_mar_file_info_fp(), i, ProductInformationBlock::MARChannelID, ntohl(), NULL, PRODUCT_INFO_BLOCK_ID, and ProductInformationBlock::productVersion.

Referenced by read_product_info_block(), and ArchiveReader::VerifyProductInformation().

◆ mar_verify_signatures()

int mar_verify_signatures ( MarFile mar,
const uint8_t *const *  certData,
const uint32_t *  certDataSizes,
uint32_t  certCount 
)

Verifies a MAR file by verifying each signature with the corresponding certificate.

That is, the first signature will be verified using the first certificate given, the second signature will be verified using the second certificate given, etc. The signature count must exactly match the number of certificates given, and all signature verifications must succeed. We do not check that the certificate was issued by any trusted authority. We assume it to be self-signed. We do not check whether the certificate is valid for this usage.

Parameters
marThe already opened MAR file.
certDataPointer to the first element in an array of certificate file data.
certDataSizesPointer to the first element in an array for size of the cert data.
certCountThe number of elements in certData and certDataSizes
Returns
0 on success a negative number if there was an error a positive number if the signature does not verify

That is, the first signature will be verified using the first certificate given, the second signature will be verified using the second certificate given, etc. The signature count must exactly match the number of certificates given, and all signature verifications must succeed.

Parameters
marThe file who's signature should be calculated
certDataPointer to the first element in an array of certificate data
certDataSizesPointer to the first element in an array for size of the data stored
certCountThe number of elements in certData and certDataSizes
Returns
0 on success

Definition at line 136 of file mar_verify.c.

References CryptoX_Failed, CryptoX_FreePublicKey, CryptoX_InitCryptoProvider, CryptoX_InvalidHandleValue, CryptoX_LoadPublicKey, CryptoX_ProviderHandle, CryptoX_PublicKey, MarFile_::fp, mar_extract_and_verify_signatures_fp(), and MAX_SIGNATURES.

Referenced by main(), and VerifyLoadedCert().

◆ MOZ_STATIC_ASSERT()

MOZ_STATIC_ASSERT ( MAX_SIGNATURES<=  9,
"too many signatures"   
)