19#ifdef VERIFY_MAR_SIGNATURE
21#include "../xpcshellCert.h"
23#include "onlineupdate/primaryCert.h"
24#include "onlineupdate/secondaryCert.h"
29#define UPDATER_NO_STRING_GLUE_STL
32#undef UPDATER_NO_STRING_GLUE_STL
35# include <sys/types.h>
53template<u
int32_t SIZE>
60#ifdef VERIFY_MAR_SIGNATURE
62 const uint8_t*
const data = &certData[0];
88#ifndef VERIFY_MAR_SIGNATURE
127 const char *appVersion)
144 if (MARChannelID && strlen(MARChannelID))
147 const char *delimiter =
" ,\t";
150 char channelCopy[512] = { 0 };
151 strncpy(channelCopy, MARChannelID,
sizeof(channelCopy) - 1);
152 char *channel = strtok(channelCopy, delimiter);
161 channel = strtok(
nullptr, delimiter);
176 int versionCompareResult =
178 if (1 == versionCompareResult)
262 FILE* fp = _wfopen(dest, L
"wb+");
264 int fd = creat(dest, item->
flags);
268 FILE *fp = fdopen(fd,
"wb");
295 int offset, inlen, ret =
OK;
297 memset(&strm, 0,
sizeof(strm));
298 if (BZ2_bzDecompressInit(&strm, 0, 0) != BZ_OK)
310 if (offset < (
int) item->
length && strm.avail_in == 0)
316 strm.next_in =
inbuf;
317 strm.avail_in = inlen;
323 ret = BZ2_bzDecompress(&strm);
324 if (ret != BZ_OK && ret != BZ_STREAM_END)
333 if (fwrite(
outbuf, outlen, 1, fp) != 1)
340 if (ret == BZ_STREAM_END)
347 BZ2_bzDecompressEnd(&strm);
int VerifyLoadedCert(MarFile *archive, const uint8_t(&certData)[SIZE])
Performs a verification on the opened MAR file with the passed in certificate name ID and type ID.
int Open(const NS_tchar *path)
int ExtractFile(const char *item, const NS_tchar *destination)
int VerifySignature()
Performs a verification on the opened MAR file.
int ExtractItemToStream(const MarItem *item, FILE *fp)
int ExtractFileToStream(const char *item, FILE *fp)
int VerifyProductInformation(const char *MARChannelID, const char *appVersion)
Verifies that the MAR file matches the current product, channel, and version.
#define UNEXPECTED_MAR_ERROR
#define CERT_VERIFY_ERROR
#define ARCHIVE_READER_MEM_ERROR
#define WRITE_ERROR_EXTRACT
#define UNEXPECTED_BZIP_ERROR
#define MAR_CHANNEL_MISMATCH_ERROR
#define VERSION_DOWNGRADE_ERROR
#define COULD_NOT_READ_PRODUCT_INFO_BLOCK_ERROR
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.
void mar_close(MarFile *mar)
Close a MAR file that was opened using mar_open.
MarFile * mar_open(const char *path)
Open a MAR file for reading.
const MarItem * mar_find_item(MarFile *mar, const char *name)
Find an item in the MAR file by name.
int mar_read_product_info_block(MarFile *mar, struct ProductInformationBlock *infoBlock)
Reads the product info block from the MAR file's additional block section.
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.
int32_t CompareVersions(const char *aStrA, const char *aStrB)
constexpr tools::Long SIZE
The MAR item data structure.