mirror of
https://github.com/firebase/firebase-ios-sdk
synced 2026-11-09 22:36:01 +05:45
Embed root certificates into the binary on Apple platforms as well (#4352)
Currently, on iOS Firestore is loading `roots.pem` file from the gRPC bundle. The mechanism has proved to be brittle, so instead we can use the same approach as the CMake build does -- parse the file at build time and embed its contents into the binary. One downside of this approach is that now we would have to periodically update the generated files for embedding manually. Judging from history, `roots.pem` is updated quite often in gRPC repo, and can be expected to be modified on each release. The command to regenerate the certificates is something like: ```sh mkdir build # From the root of the repo cd build cmake .. && make -j 8 generate_grpc_root_certificates ``` TESTED=with Fireeats.
This commit is contained in:
1 parent
9c803fc356
commit
57f8d7d675
8 files changed
+24051
-214
No files matched your search
+23
-12
@@ -48,10 +48,12 @@ import argparse
|
||||
import logging
|
||||
import os
|
||||
|
||||
from lib import git
|
||||
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
|
||||
arg_parser.add_argument("input",
|
||||
help="Input file containing binary data to embed")
|
||||
help="Input file containing binary data to embed.")
|
||||
arg_parser.add_argument("--output_source",
|
||||
help="Output source file, defining the array data.")
|
||||
arg_parser.add_argument("--output_header",
|
||||
@@ -88,7 +90,7 @@ def header(header_guard, namespaces, array_name, array_size_name, fileid):
|
||||
|
||||
data = []
|
||||
data.extend([
|
||||
"// Copyright 2018 Google Inc. All Rights Reserved.",
|
||||
"// Copyright 2019 Google Inc. All Rights Reserved.",
|
||||
"",
|
||||
"#ifndef %s" % header_guard,
|
||||
"#define %s" % header_guard,
|
||||
@@ -135,7 +137,7 @@ def header(header_guard, namespaces, array_name, array_size_name, fileid):
|
||||
|
||||
|
||||
def source(namespaces, array_name, array_size_name, fileid, filename,
|
||||
input_bytes):
|
||||
input_bytes, include_name):
|
||||
"""Return a C/C++ source file for the given array.
|
||||
|
||||
Args:
|
||||
@@ -145,15 +147,18 @@ def source(namespaces, array_name, array_size_name, fileid, filename,
|
||||
fileid: Name of the identifier containing the filename.
|
||||
filename: The original data filename itself.
|
||||
input_bytes: Binary data to put into the array.
|
||||
include_name: Name of the corresponding header file to include.
|
||||
|
||||
Returns:
|
||||
A string containing the C/C++ source file.
|
||||
"""
|
||||
data = []
|
||||
data.extend([
|
||||
"// Copyright 2016 Google Inc. All Rights Reserved.",
|
||||
"// Copyright 2019 Google Inc. All Rights Reserved.",
|
||||
"",
|
||||
"#include <stdlib.h>",
|
||||
"#include <cstdlib>",
|
||||
"",
|
||||
"#include \"%s\"" % include_name,
|
||||
""
|
||||
])
|
||||
if namespaces:
|
||||
@@ -177,7 +182,7 @@ def source(namespaces, array_name, array_size_name, fileid, filename,
|
||||
line = ""
|
||||
for idx in range(0, length):
|
||||
if idx % WIDTH == 0:
|
||||
line += " "
|
||||
line += " "
|
||||
else:
|
||||
line += " "
|
||||
line += "0x%02x," % input_bytes[idx]
|
||||
@@ -185,16 +190,15 @@ def source(namespaces, array_name, array_size_name, fileid, filename,
|
||||
data.append(line)
|
||||
line = ""
|
||||
data.append(line)
|
||||
data.append(" 0x00 // Extra \\0 to make it a C string")
|
||||
data.append(" 0x00 // Extra \\0 to make it a C string")
|
||||
|
||||
data.extend([
|
||||
"};",
|
||||
"",
|
||||
"const size_t %s =" % array_size_name,
|
||||
" sizeof(%s) - 1;" % array_name,
|
||||
" sizeof(%s) - 1;" % array_name,
|
||||
"",
|
||||
"const char %s[] =" % fileid,
|
||||
" \"%s\";" % filename,
|
||||
"const char %s[] = \"%s\";" % (fileid, filename),
|
||||
"",
|
||||
])
|
||||
|
||||
@@ -217,6 +221,8 @@ def source(namespaces, array_name, array_size_name, fileid, filename,
|
||||
def main():
|
||||
"""Read an binary input file and output to a C/C++ source file as an array.
|
||||
"""
|
||||
if not git.is_within_repo():
|
||||
raise ImportError("This script must be run from within a Git repository.")
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
@@ -233,6 +239,10 @@ def main():
|
||||
output_header = input_file_base + ".h"
|
||||
logging.debug("Using default --output_header='%s'", output_header)
|
||||
|
||||
absolute_dir = path.dirname(output_header)
|
||||
relative_dir = path.relpath(absolute_dir, git.get_repo_root())
|
||||
relative_header_path = path.join(relative_dir, path.basename(output_header))
|
||||
|
||||
identifier_base = sub("[^0-9a-zA-Z]+", "_", path.basename(input_file_base))
|
||||
array_name = args.array
|
||||
if not array_name:
|
||||
@@ -256,7 +266,7 @@ def main():
|
||||
|
||||
header_guard = args.header_guard
|
||||
if not header_guard:
|
||||
header_guard = sub("[^0-9a-zA-Z]+", "_", output_header).upper()
|
||||
header_guard = sub("[^0-9a-zA-Z]+", "_", relative_header_path).upper() + '_'
|
||||
# Avoid double underscores to stay compliant with the Standard.
|
||||
header_guard = sub("[_]+", "_", header_guard)
|
||||
logging.debug("Using default --header_guard='%s'", header_guard)
|
||||
@@ -271,7 +281,8 @@ def main():
|
||||
header_text = "\n".join(header(header_guard, namespaces, array_name,
|
||||
array_size_name, fileid))
|
||||
source_text = "\n".join(source(namespaces, array_name, array_size_name,
|
||||
fileid, filename, input_bytes))
|
||||
fileid, filename, input_bytes,
|
||||
relative_header_path))
|
||||
|
||||
with open(output_header, "w") as hdr:
|
||||
hdr.write(header_text)
|
||||
|
||||
Reference in new issue
Block a user