From 019daab72104c2f66cd66a2ffaa03beb0d1a9f6c Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 5 May 2017 13:56:24 +0200 Subject: generate the certificate verification data as part of the build Change-Id: I30186f76302e7666c833933b059931e8b1b7b78c --- onlineupdate/CustomTarget_generated.mk | 30 ++++++++++++++++++++ onlineupdate/Executable_updater.mk | 2 ++ onlineupdate/Module_onlineupdate.mk | 1 + .../source/update/updater/archivereader.cxx | 4 +-- .../source/update/updater/gen_cert_header.py | 33 +++++++++------------- 5 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 onlineupdate/CustomTarget_generated.mk diff --git a/onlineupdate/CustomTarget_generated.mk b/onlineupdate/CustomTarget_generated.mk new file mode 100644 index 000000000000..0c0f230387a8 --- /dev/null +++ b/onlineupdate/CustomTarget_generated.mk @@ -0,0 +1,30 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_CustomTarget_CustomTarget,onlineupdate/generated)) + +onlineupdate_INC := $(call gb_CustomTarget_get_workdir,onlineupdate/generated)/onlineupdate + +$(onlineupdate_INC)/primaryCert.h : \ + $(SRCDIR)/onlineupdate/source/update/updater/gen_cert_header.py + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,,1) + mkdir -p $(dir $@) + $(call gb_ExternalExecutable_get_command,python) $(SRCDIR)/onlineupdate/source/update/updater/gen_cert_header.py "primaryCertData" /lo/users/moggi/NSSDBDir/master-daily.der > $(onlineupdate_INC)/primaryCert.h #"$(UPDATE_CONFIG)" + +$(onlineupdate_INC)/secondaryCert.h : \ + $(SRCDIR)/onlineupdate/source/update/updater/gen_cert_header.py + $(call gb_Output_announce,$(subst $(WORKDIR)/,,$@),build,,1) + mkdir -p $(dir $@) + $(call gb_ExternalExecutable_get_command,python) $(SRCDIR)/onlineupdate/source/update/updater/gen_cert_header.py "secondaryCertData" /lo/users/moggi/NSSDBDir/master-daily.der > $(onlineupdate_INC)/secondaryCert.h #"$(UPDATE_CONFIG)" + +$(call gb_CustomTarget_get_target,onlineupdate/generated) : \ + $(onlineupdate_INC)/primaryCert.h \ + $(onlineupdate_INC)/secondaryCert.h \ + +# vim: set noet sw=4 ts=4: diff --git a/onlineupdate/Executable_updater.mk b/onlineupdate/Executable_updater.mk index 8d1b9be81ff2..ed20b19410d4 100644 --- a/onlineupdate/Executable_updater.mk +++ b/onlineupdate/Executable_updater.mk @@ -16,6 +16,8 @@ $(eval $(call gb_Executable_set_include,updater,\ $$(INCLUDE) \ )) +$(eval $(call gb_Executable_use_custom_headers,updater,onlineupdate/generated)) + $(eval $(call gb_Executable_use_static_libraries,updater,\ libmar \ updatehelper \ diff --git a/onlineupdate/Module_onlineupdate.mk b/onlineupdate/Module_onlineupdate.mk index dfb8d54ef70c..8222be7a4ea6 100644 --- a/onlineupdate/Module_onlineupdate.mk +++ b/onlineupdate/Module_onlineupdate.mk @@ -21,6 +21,7 @@ $(eval $(call gb_Module_add_targets,onlineupdate,\ Executable_mar \ Executable_updater \ Executable_mbsdiff \ + CustomTarget_generated \ )) endif diff --git a/onlineupdate/source/update/updater/archivereader.cxx b/onlineupdate/source/update/updater/archivereader.cxx index b0395d14094e..ec043680c27e 100644 --- a/onlineupdate/source/update/updater/archivereader.cxx +++ b/onlineupdate/source/update/updater/archivereader.cxx @@ -20,8 +20,8 @@ #ifdef TEST_UPDATER #include "../xpcshellCert.h" #else -#include "primaryCert.h" -#include "secondaryCert.h" +#include "onlineupdate/primaryCert.h" +#include "onlineupdate/secondaryCert.h" #endif #endif diff --git a/onlineupdate/source/update/updater/gen_cert_header.py b/onlineupdate/source/update/updater/gen_cert_header.py index 5fff9be79084..5b70758db3f2 100755 --- a/onlineupdate/source/update/updater/gen_cert_header.py +++ b/onlineupdate/source/update/updater/gen_cert_header.py @@ -1,27 +1,22 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import sys import binascii -def file_byte_generator(filename, block_size = 512): - with open(filename, "rb") as f: - while True: - block = f.read(block_size) - if block: - for byte in block: - yield byte - else: - break +def file_byte_generator(filename): + with open(filename, "rb") as f: + block = f.read() + return block def create_header(array_name, in_filename): - hexified = ["0x" + binascii.hexlify(byte) for byte in file_byte_generator(in_filename)] - print("const uint8_t " + array_name + "[] = {") - print(", ".join(hexified)) - print("};") - return 0 + hexified = ["0x" + binascii.hexlify(bytes([inp])).decode('ascii') for inp in file_byte_generator(in_filename)] + print("const uint8_t " + array_name + "[] = {") + print(", ".join(hexified)) + print("};") + return 0 if __name__ == '__main__': - if len(sys.argv) < 3: - print('ERROR: usage: gen_cert_header.py array_name in_filename') - sys.exit(1); - sys.exit(create_header(sys.argv[1], sys.argv[2])) + if len(sys.argv) < 3: + print('ERROR: usage: gen_cert_header.py array_name in_filename') + sys.exit(1); + sys.exit(create_header(sys.argv[1], sys.argv[2])) -- cgit