LibreOffice Module onlineupdate (master) 1
Functions
mar_verify.c File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <onlineupdate/mar_private.h>
#include <onlineupdate/mar.h>
#include "cryptox.h"
Include dependency graph for mar_verify.c:

Go to the source code of this file.

Functions

int mar_read_entire_file (const char *filePath, uint32_t maxSize, const uint8_t **data, uint32_t *size)
 
int mar_extract_and_verify_signatures_fp (FILE *fp, CryptoX_ProviderHandle provider, CryptoX_PublicKey *keys, uint32_t keyCount)
 Extracts each signature from the specified MAR file, then calls mar_verify_signatures_for_fp to verify each signature. More...
 
int mar_verify_signatures_for_fp (FILE *fp, CryptoX_ProviderHandle provider, CryptoX_PublicKey *keys, const uint8_t *const *extractedSignatures, uint32_t signatureCount, uint32_t *numVerified)
 Verifies a MAR file by verifying each signature with the corresponding certificate. More...
 
int ReadAndUpdateVerifyContext (FILE *fp, void *buffer, uint32_t size, CryptoX_SignatureHandle *ctxs, uint32_t count, const char *err)
 Reads the specified number of bytes from the file pointer and stores them in the passed buffer. More...
 
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...
 

Function Documentation

◆ mar_extract_and_verify_signatures_fp()

int mar_extract_and_verify_signatures_fp ( FILE *  fp,
CryptoX_ProviderHandle  provider,
CryptoX_PublicKey keys,
uint32_t  keyCount 
)

Extracts each signature from the specified MAR file, then calls mar_verify_signatures_for_fp to verify each signature.

Parameters
fpAn opened MAR file handle
providerA library provider
keysThe public keys to use to verify the MAR
keyCountThe number of keys pointed to by keys
Returns
0 on success

Definition at line 194 of file mar_verify.c.

References CryptoX_Error, CryptoX_Success, i, mar_verify_signatures_for_fp(), MAX_SIGNATURE_LENGTH, MAX_SIGNATURES, MAX_SIZE_OF_MAR_FILE, ntohl(), and SIGNATURE_BLOCK_OFFSET.

Referenced by mar_verify_signatures().

◆ 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_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.

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().

◆ mar_verify_signatures_for_fp()

int mar_verify_signatures_for_fp ( FILE *  fp,
CryptoX_ProviderHandle  provider,
CryptoX_PublicKey keys,
const uint8_t *const *  extractedSignatures,
uint32_t  signatureCount,
uint32_t *  numVerified 
)

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.

Parameters
fpAn opened MAR file handle
providerA library provider
keysA pointer to the first element in an array of keys.
extractedSignaturesPointer to the first element in an array of extracted signatures.
signatureCountThe number of signatures in the MAR file
numVerifiedOut parameter which will be filled with the number of verified signatures. This information can be useful for printing error messages.
Returns
0 on success, *numVerified == signatureCount.

Definition at line 335 of file mar_verify.c.

References BLOCKSIZE, CryptoX_Error, CryptoX_Failed, CryptoX_FreeSignatureHandle, CryptoX_SignatureHandle, CryptoX_Success, CryptoX_VerifyBegin, CryptoX_VerifySignature, CryptoX_VerifyUpdate, i, MAX_SIGNATURE_LENGTH, MAX_SIGNATURES, ntohl(), ReadAndUpdateVerifyContext(), and SIGNATURE_BLOCK_OFFSET.

Referenced by mar_extract_and_verify_signatures_fp().

◆ ReadAndUpdateVerifyContext()

int ReadAndUpdateVerifyContext ( FILE *  fp,
void *  buffer,
uint32_t  size,
CryptoX_SignatureHandle ctxs,
uint32_t  count,
const char *  err 
)

Reads the specified number of bytes from the file pointer and stores them in the passed buffer.

Parameters
fpThe file pointer to read from.
bufferThe buffer to store the read results.
sizeThe number of bytes to read, buffer must be at least of this size.
ctxsPointer to the first element in an array of verify context.
countThe number of elements in ctxs
errThe name of what is being written to in case of error.
Returns
0 on success -1 on read error -2 on verify update error

Definition at line 89 of file mar_verify.c.

References count, CryptoX_Error, CryptoX_Failed, CryptoX_Success, CryptoX_VerifyUpdate, err, and size.

Referenced by mar_verify_signatures_for_fp().