third_party: add boringssl, libtpms, swtpm
This isn't yet used, but will soon be used as the main swtpm
implementation (instead of whatever is provided by the ambient
environment and/or sandbox).
Change-Id: I8c8cc7fd7841f10e14d6390595805a8b905d4f4e
Reviewed-on: https://review.monogon.dev/c/monogon/+/3127
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/third_party/libtpms/patches/0006-bazel-support-implement.patch b/third_party/libtpms/patches/0006-bazel-support-implement.patch
new file mode 100644
index 0000000..8152a55
--- /dev/null
+++ b/third_party/libtpms/patches/0006-bazel-support-implement.patch
@@ -0,0 +1,106 @@
+From fa72e847a7fb503daa25b5007edb28483a0f6e42 Mon Sep 17 00:00:00 2001
+From: Serge Bazanski <serge@monogon.tech>
+Date: Tue, 4 Jun 2024 14:31:54 +0200
+Subject: [PATCH 6/6] bazel support: implement
+
+---
+ BUILD.bazel | 45 ++++++++++++++++++++++++++++++++++++++++
+ WORKSPACE | 0
+ include/libtpms/config.h | 3 +++
+ src/tpm_library.c | 1 +
+ src/tpm_tpm2_interface.c | 1 +
+ 5 files changed, 50 insertions(+)
+ create mode 100644 BUILD.bazel
+ create mode 100644 WORKSPACE
+ create mode 100644 include/libtpms/config.h
+
+diff --git a/BUILD.bazel b/BUILD.bazel
+new file mode 100644
+index 0000000..591942d
+--- /dev/null
++++ b/BUILD.bazel
+@@ -0,0 +1,45 @@
++cc_library(
++ name = "libtpms_tpm2",
++ includes = [
++ "include",
++ ],
++ copts = [
++ "-Iexternal/libtpms/include/libtpms",
++ "-Iexternal/libtpms/src",
++ "-Iexternal/libtpms/src/tpm2",
++ "-Iexternal/libtpms/src/tpm2/crypto",
++ "-Iexternal/libtpms/src/tpm2/crypto/openssl",
++ ],
++ defines = [
++ "TPM_LIBTPMS_CALLBACKS",
++ "TPM_NV_DISK",
++ ],
++ deps = [
++ "@boringssl//:ssl",
++ ],
++ textual_hdrs = [
++ "src/tpm2/EccConstantData.inl",
++ ],
++ srcs = glob([
++ "include/config.h",
++ "include/libtpms/*.h",
++
++ "src/*.h",
++ "src/*.c",
++
++ "src/tpm2/*.h",
++ "src/tpm2/*.c",
++
++ "src/tpm2/crypto/*.h",
++ "src/tpm2/crypto/openssl/*.h",
++ "src/tpm2/crypto/openssl/*.c",
++
++ "src/monogon_unsafe.c",
++ ], [
++ # No TPM1.2 support.
++ "src/tpm_tpm12*",
++ ]),
++ visibility = [
++ "//visibility:public",
++ ],
++)
+diff --git a/WORKSPACE b/WORKSPACE
+new file mode 100644
+index 0000000..e69de29
+diff --git a/include/libtpms/config.h b/include/libtpms/config.h
+new file mode 100644
+index 0000000..bb4316e
+--- /dev/null
++++ b/include/libtpms/config.h
+@@ -0,0 +1,3 @@
++#pragma once
++
++#define WITH_TPM2 1
+diff --git a/src/tpm_library.c b/src/tpm_library.c
+index 20153b7..a3c5694 100644
+--- a/src/tpm_library.c
++++ b/src/tpm_library.c
+@@ -63,6 +63,7 @@
+ #include "tpm_debug.h"
+ #include "tpm_error.h"
+ #include "tpm_library.h"
++#include "tpm_library_conf.h"
+ #include "tpm_library_intern.h"
+ #include "tpm_nvfilename.h"
+ #include "tpm_tis.h"
+diff --git a/src/tpm_tpm2_interface.c b/src/tpm_tpm2_interface.c
+index 4570d78..7e51b5e 100644
+--- a/src/tpm_tpm2_interface.c
++++ b/src/tpm_tpm2_interface.c
+@@ -65,6 +65,7 @@
+ #include "tpm_nvfile.h" // TPM_NVRAM_Loaddata()
+ #include "tpm_error.h"
+ #include "tpm_library_intern.h"
++#include "tpm_library_conf.h"
+ #include "tpm_nvfilename.h"
+
+ extern BOOL g_inFailureMode;
+--
+2.42.0
+