thunderbird/SOURCES/backport-rnp-0.16.2-to-esr1...

263 lines
8.5 KiB
Diff

# HG changeset patch
# User Rob Lemley <rob@thunderbird.net>
# Date 1663866557 14400
# Thu Sep 22 13:09:17 2022 -0400
# Node ID 121afb4ed9b0e282cf6690736ffadf1498578434
# Parent 0798506e89ab0ad98d5826effe2087c2e2560d0b
Bug 1790116 - mozbuild changes for RNP v0.16.2. r=kaie
hash_sha1cd.cpp moved up to its parent directory.
ENABLE_IDEA needs to be set to keep support enabled.
https://github.com/rnpgp/rnp/commit/17972d0238919d4abf88b04debce95844be4716d
Update rnp_symbols.py to not include deprecated functions.
Added new symbols to rnp.symbols for export.
Differential Revision: https://phabricator.services.mozilla.com/D157012
diff --git a/comm/python/thirdroc/thirdroc/rnp_symbols.py b/python/thirdroc/thirdroc/rnp_symb/commols.py
--- a/comm/python/thirdroc/thirdroc/rnp_symbols.py
+++ b/comm/python/thirdroc/thirdroc/rnp_symbols.py
@@ -14,30 +14,75 @@ the third_party/rnp/include/rnp/rnp.h fo
Also note that APIs that are marked deprecated are not checked for.
Dependencies: Only Python 3
Running:
- python3 rnp_symbols.py
+ python3 rnp_symbols.py [-h] [rnp.h path] [rnp.symbols path]
-Output will be on stdout, this is to give the developer the opportunity to compare the old and
-new versions and check for accuracy.
+Both file path arguments are optional. By default, the header file will be
+read from "comm/third_party/rnp/include/rnp/rnp.h" and the symbols file will
+be written to "comm/third_party/rnp/rnp.symbols".
+
+Path arguments are relative to the current working directory, the defaults
+will be determined based on the location of this script.
+
+Either path argument can be '-' to use stdin or stdout respectively.
"""
-from __future__ import absolute_import, print_function
-
+import argparse
import sys
import os
import re
HERE = os.path.dirname(__file__)
TOPSRCDIR = os.path.abspath(os.path.join(HERE, "../../../../"))
-RNPSRCDIR = os.path.join(TOPSRCDIR, "comm/third_party/rnp")
+THIRD_SRCDIR = os.path.join(TOPSRCDIR, "comm/third_party")
+HEADER_FILE_REL = "rnp/include/rnp/rnp.h"
+HEADER_FILE = os.path.join(THIRD_SRCDIR, HEADER_FILE_REL)
+SYMBOLS_FILE_REL = "rnp/rnp.symbols"
+SYMBOLS_FILE = os.path.join(THIRD_SRCDIR, SYMBOLS_FILE_REL)
FUNC_DECL_RE = re.compile(r"^RNP_API\s+.*?([a-zA-Z0-9_]+)\(.*$")
+class FileArg:
+ """Based on argparse.FileType from the Python standard library.
+ Modified to not open the filehandles until the open() method is
+ called.
+ """
+
+ def __init__(self, mode="r"):
+ self._mode = mode
+ self._fp = None
+ self._file = None
+
+ def __call__(self, string):
+ # the special argument "-" means sys.std{in,out}
+ if string == "-":
+ if "r" in self._mode:
+ self._fp = sys.stdin.buffer if "b" in self._mode else sys.stdin
+ elif "w" in self._mode:
+ self._fp = sys.stdout.buffer if "b" in self._mode else sys.stdout
+ else:
+ raise ValueError(f"Invalid mode {self._mode} for stdin/stdout")
+ else:
+ if "r" in self._mode:
+ if not os.path.isfile(string):
+ raise ValueError(f"Cannot read file {string}, does not exist.")
+ elif "w" in self._mode:
+ if not os.access(string, os.W_OK):
+ raise ValueError(f"Cannot write file {string}, permission denied.")
+ self._file = string
+ return self
+
+ def open(self):
+ if self._fp:
+ return self._fp
+ return open(self._file, self._mode)
+
+
def get_func_name(line):
"""
Extract the function name from a RNP_API function declaration.
Examples:
RNP_API rnp_result_t rnp_enable_debug(const char *file);
@@ -46,24 +91,41 @@ def get_func_name(line):
"""
m = FUNC_DECL_RE.match(line)
return m.group(1)
-def extract_func_defs(filename):
+def extract_func_defs(filearg):
"""
Look for RNP_API in the header file to find the names of the symbols that should be exported
"""
- with open(filename) as fp:
+ with filearg.open() as fp:
for line in fp:
- if line.startswith("RNP_API"):
+ if line.startswith("RNP_API") and "RNP_DEPRECATED" not in line:
func_name = get_func_name(line)
yield func_name
if __name__ == "__main__":
- if len(sys.argv) > 1:
- FILENAME = sys.argv[1]
- else:
- FILENAME = os.path.join(RNPSRCDIR, "include/rnp/rnp.h")
+ parser = argparse.ArgumentParser(
+ description="Update rnp.symbols file from rnp.h",
+ epilog="To use stdin or stdout pass '-' for the argument.",
+ )
+ parser.add_argument(
+ "header_file",
+ default=HEADER_FILE,
+ type=FileArg("r"),
+ nargs="?",
+ help=f"input path to rnp.h header file (default: {HEADER_FILE_REL})",
+ )
+ parser.add_argument(
+ "symbols_file",
+ default=SYMBOLS_FILE,
+ type=FileArg("w"),
+ nargs="?",
+ help=f"output path to symbols file (default: {SYMBOLS_FILE_REL})",
+ )
- for f in sorted(list(extract_func_defs(FILENAME))):
- print(f)
+ args = parser.parse_args()
+
+ with args.symbols_file.open() as out_fp:
+ for symbol in sorted(list(extract_func_defs(args.header_file))):
+ out_fp.write(f"{symbol}\n")
diff --git a/comm/third_party/rnp/moz.build b/third_party/rnp/moz.b/commuild
--- a/comm/third_party/rnp/moz.build
+++ b/comm/third_party/rnp/moz.build
@@ -41,10 +41,11 @@ rnp_defines = {
"HAVE_ZLIB_H": True,
"CRYPTO_BACKEND_BOTAN": True,
"ENABLE_AEAD": True,
"ENABLE_TWOFISH": True,
"ENABLE_BRAINPOOL": True,
+ "ENABLE_IDEA": True,
"PACKAGE_BUGREPORT": '"https://bugzilla.mozilla.org/enter_bug.cgi?product=Thunderbird"',
"PACKAGE_STRING": '"rnp {}"'.format(CONFIG["MZLA_LIBRNP_FULL_VERSION"])
}
GeneratedFile(
"src/lib/config.h",
@@ -119,16 +120,16 @@ SOURCES += [
"src/lib/crypto/ecdsa.cpp",
"src/lib/crypto/eddsa.cpp",
"src/lib/crypto/elgamal.cpp",
"src/lib/crypto/hash.cpp",
"src/lib/crypto/hash_common.cpp",
+ "src/lib/crypto/hash_sha1cd.cpp",
"src/lib/crypto/mem.cpp",
"src/lib/crypto/mpi.cpp",
"src/lib/crypto/rng.cpp",
"src/lib/crypto/rsa.cpp",
"src/lib/crypto/s2k.cpp",
- "src/lib/crypto/sha1cd/hash_sha1cd.cpp",
"src/lib/crypto/sha1cd/sha1.c",
"src/lib/crypto/sha1cd/ubc_check.c",
"src/lib/crypto/signatures.cpp",
"src/lib/crypto/symmetric.cpp",
"src/lib/fingerprint.cpp",
diff --git a/comm/third_party/rnp/rnp.symbols b/third_party/rnp/rnp.symb/commols
--- a/comm/third_party/rnp/rnp.symbols
+++ b/comm/third_party/rnp/rnp.symbols
@@ -37,10 +37,11 @@ rnp_import_keys
rnp_import_signatures
rnp_input_destroy
rnp_input_from_callback
rnp_input_from_memory
rnp_input_from_path
+rnp_input_from_stdin
rnp_key_25519_bits_tweak
rnp_key_25519_bits_tweaked
rnp_key_add_uid
rnp_key_allows_usage
rnp_key_export
@@ -75,10 +76,11 @@ rnp_key_get_uid_count
rnp_key_get_uid_handle_at
rnp_key_handle_destroy
rnp_key_have_public
rnp_key_have_secret
rnp_key_is_compromised
+rnp_key_is_expired
rnp_key_is_locked
rnp_key_is_primary
rnp_key_is_protected
rnp_key_is_retired
rnp_key_is_revoked
@@ -112,10 +114,11 @@ rnp_op_encrypt_set_cipher
rnp_op_encrypt_set_compression
rnp_op_encrypt_set_creation_time
rnp_op_encrypt_set_expiration_time
rnp_op_encrypt_set_file_mtime
rnp_op_encrypt_set_file_name
+rnp_op_encrypt_set_flags
rnp_op_encrypt_set_hash
rnp_op_generate_add_pref_cipher
rnp_op_generate_add_pref_compression
rnp_op_generate_add_pref_hash
rnp_op_generate_add_usage
@@ -169,10 +172,11 @@ rnp_op_verify_get_signature_at
rnp_op_verify_get_signature_count
rnp_op_verify_get_symenc_at
rnp_op_verify_get_symenc_count
rnp_op_verify_get_used_recipient
rnp_op_verify_get_used_symenc
+rnp_op_verify_set_flags
rnp_op_verify_signature_get_handle
rnp_op_verify_signature_get_hash
rnp_op_verify_signature_get_key
rnp_op_verify_signature_get_status
rnp_op_verify_signature_get_times
@@ -185,21 +189,24 @@ rnp_output_to_armor
rnp_output_to_callback
rnp_output_to_file
rnp_output_to_memory
rnp_output_to_null
rnp_output_to_path
+rnp_output_to_stdout
rnp_output_write
rnp_recipient_get_alg
rnp_recipient_get_keyid
rnp_remove_security_rule
rnp_request_password
rnp_result_to_string
rnp_save_keys
+rnp_set_timestamp
rnp_signature_get_alg
rnp_signature_get_creation
rnp_signature_get_expiration
rnp_signature_get_hash_alg
+rnp_signature_get_key_fprint
rnp_signature_get_keyid
rnp_signature_get_signer
rnp_signature_get_type
rnp_signature_handle_destroy
rnp_signature_is_valid