LibreOffice Module onlineupdate (master) 1
|
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar_cmdline.h>
#include <onlineupdate/mar.h>
#include "cryptox.h"
#include <unistd.h>
#include "nss_secutil.h"
#include "base64.h"
Go to the source code of this file.
Functions | |
int | NSSInitCryptoContext (const char *NSSConfigDir) |
Initializes the NSS context. More... | |
int | NSSSignBegin (const char *certName, SGNContext **ctx, SECKEYPrivateKey **privKey, CERTCertificate **cert, uint32_t *signatureLength) |
Obtains a signing context. More... | |
int | WriteAndUpdateSignatures (FILE *fpDest, void *buffer, uint32_t size, SGNContext **ctxs, uint32_t ctxCount, const char *err) |
Writes the passed buffer to the file fp and updates the signature contexts. More... | |
void | AdjustIndexContentOffsets (char *indexBuf, uint32_t indexLength, uint32_t offsetAmount) |
Adjusts each entry's content offset in the passed in index by the specified amount. More... | |
int | ReadWriteAndUpdateSignatures (FILE *fpSrc, FILE *fpDest, void *buffer, uint32_t size, SGNContext **ctxs, uint32_t ctxCount, const char *err) |
Reads from fpSrc, writes it to fpDest, and updates the signature contexts. More... | |
int | ReadAndWrite (FILE *fpSrc, FILE *fpDest, void *buffer, uint32_t size, const char *err) |
Reads from fpSrc, writes it to fpDest. More... | |
int | strip_signature_block (const char *src, const char *dest) |
Writes out a copy of the MAR at src but with the signature block stripped. More... | |
int | extract_signature (const char *src, uint32_t sigIndex, const char *dest) |
Extracts a signature from a MAR file, base64 encodes it, and writes it out. More... | |
int | import_signature (const char *src, uint32_t sigIndex, const char *base64SigFile, const char *dest) |
Imports a base64 encoded signature into a MAR file. More... | |
int | mar_repackage_and_sign (const char *NSSConfigDir, const char *const *certNames, uint32_t certCount, const char *src, const char *dest) |
Writes out a copy of the MAR at src but with embedded signatures. More... | |
void AdjustIndexContentOffsets | ( | char * | indexBuf, |
uint32_t | indexLength, | ||
uint32_t | offsetAmount | ||
) |
Adjusts each entry's content offset in the passed in index by the specified amount.
indexBuf | A buffer containing the MAR index |
indexLength | The length of the MAR index |
offsetAmount | The amount to adjust each index entry by |
Definition at line 160 of file mar_sign.c.
References htonl(), and ntohl().
Referenced by mar_repackage_and_sign(), and strip_signature_block().
int extract_signature | ( | const char * | src, |
uint32_t | sigIndex, | ||
const char * | dest | ||
) |
Extracts a signature from a MAR file, base64 encodes it, and writes it out.
src | The path of the source MAR file |
sigIndex | The index of the signature to extract |
dest | The path of file to write the signature to |
Definition at line 489 of file mar_sign.c.
References FILE, i, ntohl(), NULL, remove(), and SIGNATURE_BLOCK_OFFSET.
Referenced by main().
int import_signature | ( | const char * | src, |
uint32_t | sigIndex, | ||
const char * | base64SigFile, | ||
const char * | dest | ||
) |
Imports a base64 encoded signature into a MAR file.
src | The path of the source MAR file |
sigIndex | The index of the signature to import |
base64SigFile | A file which contains the signature to import |
dest | The path of the destination MAR file with replaced signature |
Definition at line 605 of file mar_sign.c.
References BLOCKSIZE, FILE, i, MAX_SIGNATURES, ntohl(), NULL, ReadAndWrite(), remove(), and SIGNATURE_BLOCK_OFFSET.
Referenced by main().
int mar_repackage_and_sign | ( | const char * | NSSConfigDir, |
const char *const * | certNames, | ||
uint32_t | certCount, | ||
const char * | src, | ||
const char * | dest | ||
) |
Writes out a copy of the MAR at src but with embedded signatures.
The passed in MAR file must not already be signed or an error will be returned.
NSSConfigDir | The NSS directory containing the private key for signing |
certNames | The nicknames of the certificate to use for signing |
certCount | The number of certificate names contained in certNames. One signature will be produced for each certificate. |
src | The path of the source MAR file to sign |
dest | The path of the MAR file to write out that is signed |
Definition at line 818 of file mar_sign.c.
References AdjustIndexContentOffsets(), BLOCKSIZE, FILE, get_mar_file_info(), HOST_TO_NETWORK64, htonl(), i, MAR_ID_SIZE, MAX_SIGNATURES, MAX_SIZE_OF_MAR_FILE, NETWORK_TO_HOST64, NSSInitCryptoContext(), NSSSignBegin(), ntohl(), NULL, ReadWriteAndUpdateSignatures(), remove(), SECU_GetModulePassword(), and WriteAndUpdateSignatures().
Referenced by main().
int NSSInitCryptoContext | ( | const char * | NSSConfigDir | ) |
Initializes the NSS context.
NSSConfigDir | The config dir containing the private key to use |
Definition at line 35 of file mar_sign.c.
Referenced by main(), and mar_repackage_and_sign().
int NSSSignBegin | ( | const char * | certName, |
SGNContext ** | ctx, | ||
SECKEYPrivateKey ** | privKey, | ||
CERTCertificate ** | cert, | ||
uint32_t * | signatureLength | ||
) |
Obtains a signing context.
ctx | A pointer to the signing context to fill |
Definition at line 55 of file mar_sign.c.
References BLOCKSIZE, ctx, and XP_MIN_SIGNATURE_LEN_IN_BYTES.
Referenced by mar_repackage_and_sign().
int ReadAndWrite | ( | FILE * | fpSrc, |
FILE * | fpDest, | ||
void * | buffer, | ||
uint32_t | size, | ||
const char * | err | ||
) |
Reads from fpSrc, writes it to fpDest.
fpSrc | The file pointer to read from. |
fpDest | The file pointer to write to. |
buffer | The buffer to write. |
size | The size of the buffer to write. |
err | The name of what is being written to in case of error. |
Definition at line 225 of file mar_sign.c.
Referenced by import_signature(), and strip_signature_block().
int ReadWriteAndUpdateSignatures | ( | FILE * | fpSrc, |
FILE * | fpDest, | ||
void * | buffer, | ||
uint32_t | size, | ||
SGNContext ** | ctxs, | ||
uint32_t | ctxCount, | ||
const char * | err | ||
) |
Reads from fpSrc, writes it to fpDest, and updates the signature contexts.
fpSrc | The file pointer to read from. |
fpDest | The file pointer to write to. |
buffer | The buffer to write. |
size | The size of the buffer to write. |
ctxs | Pointer to the first element in an array of signature contexts to update. |
ctxCount | The number of signature contexts pointed to by ctxs |
err | The name of what is being written to in case of error. |
Definition at line 194 of file mar_sign.c.
References err, size, and WriteAndUpdateSignatures().
Referenced by mar_repackage_and_sign().
int strip_signature_block | ( | const char * | src, |
const char * | dest | ||
) |
Writes out a copy of the MAR at src but with the signature block stripped.
src | The path of the source MAR file |
dest | The path of the MAR file to write out that has no signature block |
Definition at line 255 of file mar_sign.c.
References AdjustIndexContentOffsets(), BLOCKSIZE, CryptoX_Error, FILE, get_mar_file_info(), HOST_TO_NETWORK64, htonl(), i, MAR_ID_SIZE, NETWORK_TO_HOST64, ntohl(), NULL, ReadAndWrite(), and remove().
Referenced by main().
int WriteAndUpdateSignatures | ( | FILE * | fpDest, |
void * | buffer, | ||
uint32_t | size, | ||
SGNContext ** | ctxs, | ||
uint32_t | ctxCount, | ||
const char * | err | ||
) |
Writes the passed buffer to the file fp and updates the signature contexts.
fpDest | The file pointer to write to. |
buffer | The buffer to write. |
size | The size of the buffer to write. |
ctxs | Pointer to the first element in an array of signature contexts to update. |
ctxCount | The number of signature contexts pointed to by ctxs |
err | The name of what is being written to in case of error. |
Definition at line 127 of file mar_sign.c.
Referenced by mar_repackage_and_sign(), and ReadWriteAndUpdateSignatures().