Skip to content

Commit b612e2b

Browse files
author
Willy Zhang
committed
Add support for MLKEM in grpc client and host libs
Update grpc to v1.68.0 and boringssl to support MLKEM. Add flags for enable MLKEM TLS for clients and servers. Patch gRPC to force MLKEM key exchange when enabled. Signed-off-by: Willy Zhang <[email protected]>
1 parent 8140c88 commit b612e2b

File tree

19 files changed

+2258
-180
lines changed

19 files changed

+2258
-180
lines changed

MODULE.bazel

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ register_toolchains("@llvm_toolchain_host//:all")
2727
# Dependencies
2828
# -------------------------------------------------------------------------
2929

30-
bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "com_google_absl")
30+
bazel_dep(name = "abseil-cpp", version = "20240722.0.bcr.1", repo_name = "com_google_absl")
3131
bazel_dep(name = "bazel_skylib", version = "1.7.1")
32-
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", repo_name = "com_google_googletest")
33-
bazel_dep(name = "re2", version = "2023-09-01", repo_name = "com_googlesource_code_re2")
32+
bazel_dep(name = "googletest", version = "1.15.2", repo_name = "com_google_googletest")
33+
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_googlesource_code_re2")
3434
bazel_dep(name = "platforms", version = "0.0.11")
3535
bazel_dep(name = "rules_cc", version = "0.1.2")
3636
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
3737
bazel_dep(name = "rules_pkg", version = "1.0.1")
38-
bazel_dep(name = "rules_proto", version = "6.0.2")
38+
bazel_dep(name = "rules_proto", version = "7.0.2")
3939
bazel_dep(name = "aspect_rules_lint", version = "1.0.8")
4040
bazel_dep(name = "rules_rust", version = "0.59.2")
4141

@@ -73,19 +73,33 @@ http_archive(
7373
urls = ["https://github.com/inazarenko/protobuf-matchers/archive/7c8e15741bcea83db7819cc472c3e96301a95158.zip"],
7474
)
7575

76+
bazel_dep(name = "protoc-gen-validate", version = "1.0.4.bcr.2")
77+
7678
# Use a modern gRPC (compatible with Protobuf 27+)
77-
bazel_dep(name = "grpc", version = "1.66.0.bcr.3", repo_name = "com_github_grpc_grpc")
79+
bazel_dep(name = "grpc", version = "1.68.0", repo_name = "com_github_grpc_grpc")
80+
81+
bazel_dep(name = "boringssl")
82+
archive_override(
83+
module_name = "boringssl",
84+
integrity = "sha256-dHR3G61xqu8ZpYuovGGINHZ7VxPMPEean1AquU74k5E=",
85+
patch_strip = 0,
86+
patches = ["third_party/google/boringssl_mingw_fix.patch"],
87+
strip_prefix = "boringssl-0.20241024.0",
88+
urls = ["https://github.com/google/boringssl/releases/download/0.20241024.0/boringssl-0.20241024.0.tar.gz"],
89+
)
90+
7891
single_version_override(
7992
module_name = "grpc",
8093
patch_strip = 0,
8194
patches = [
8295
"third_party/google/grpc_windows_config_setting.patch",
8396
"third_party/google/grpc_windows_endpoint_fix.patch",
97+
"third_party/google/grpc_force_mlkem.patch",
8498
],
8599
)
86100

87101
# Pin Protobuf explicitly to ensure sync
88-
bazel_dep(name = "protobuf", version = "27.3", repo_name = "com_google_protobuf")
102+
bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf")
89103

90104
# Explicitly add upb (required by gRPC 1.66+ in Bzlmod)
91105
bazel_dep(name = "upb", version = "0.0.0-20230907-e7430e6")
@@ -95,8 +109,8 @@ single_version_override(
95109
version = "0.9.0",
96110
)
97111

98-
bazel_dep(name = "rules_apple", version = "3.5.1", repo_name = "build_bazel_rules_apple")
99-
bazel_dep(name = "rules_swift", version = "1.18.0", repo_name = "build_bazel_rules_swift")
112+
bazel_dep(name = "rules_apple", version = "3.13.0", repo_name = "build_bazel_rules_apple")
113+
bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift")
100114

101115
# Go Toolchain: Used for Go code
102116
bazel_dep(name = "rules_go", version = "0.52.0", repo_name = "io_bazel_rules_go")

MODULE.bazel.lock

Lines changed: 2038 additions & 148 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/containers/provapp.yml.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spec:
1515
- name: paserver-1
1616
args:
1717
- --enable_tls=true
18+
- --enable_mlkem=${ENABLE_MLKEM}
1819
- --service_key=/var/lib/opentitan/config/certs/out/pa-service-key.pem
1920
- --service_cert=/var/lib/opentitan/config/certs/out/pa-service-cert.pem
2021
- --ca_root_certs=/var/lib/opentitan/config/certs/out/ca-cert.pem
@@ -39,6 +40,7 @@ spec:
3940
- name: paserver-2
4041
args:
4142
- --enable_tls=true
43+
- --enable_mlkem=${ENABLE_MLKEM}
4244
- --service_key=/var/lib/opentitan/config/certs/out/pa-service-key.pem
4345
- --service_cert=/var/lib/opentitan/config/certs/out/pa-service-cert.pem
4446
- --ca_root_certs=/var/lib/opentitan/config/certs/out/ca-cert.pem
@@ -63,6 +65,7 @@ spec:
6365
- name: paserver-3
6466
args:
6567
- --enable_tls=true
68+
- --enable_mlkem=${ENABLE_MLKEM}
6669
- --service_key=/var/lib/opentitan/config/certs/out/pa-service-key.pem
6770
- --service_cert=/var/lib/opentitan/config/certs/out/pa-service-cert.pem
6871
- --ca_root_certs=/var/lib/opentitan/config/certs/out/ca-cert.pem
@@ -87,6 +90,7 @@ spec:
8790
- name: pbserver
8891
args:
8992
- --enable_tls=true
93+
- --enable_mlkem=${ENABLE_MLKEM}
9094
- --service_key=/var/lib/opentitan/config/certs/out/pb-service-key.pem
9195
- --service_cert=/var/lib/opentitan/config/certs/out/pb-service-cert.pem
9296
- --ca_root_certs=/var/lib/opentitan/config/certs/out/ca-cert.pem

integration/run_client_tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ set -e
99
# in the background and still be able to run other commands in parallel.
1010
set -m
1111

12+
export ENABLE_MLKEM="true"
13+
1214
# Ensure we are running from the repository root
1315
cd "$(dirname "$0")/.."
1416

integration/run_tls_test.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ set -e
99
# in the background and still be able to run other commands in parallel.
1010
set -m
1111

12+
export ENABLE_MLKEM="true"
13+
1214
# Ensure we are running from the repository root
1315
cd "$(dirname "$0")/.."
1416

1517
# Build and deploy the provisioning infrastructure.
1618
source util/integration_test_setup.sh
1719

20+
# Dump PA logs on failure
21+
dump_pa_logs() {
22+
echo "----------------------------------------------------------------"
23+
echo "Dumping PA logs (provapp-paserver-1)..."
24+
podman logs provapp-paserver-1
25+
echo "----------------------------------------------------------------"
26+
}
27+
trap dump_pa_logs ERR
28+
1829
# Run the TLS connection test.
1930
echo "Running TLS connection test ..."
2031
bazelisk run //src/ate/test_programs:tls_test -- \

src/ate/test_programs/tls_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int main(int argc, char **argv) {
113113
LOG(ERROR) << "InitSession with PA failed.";
114114
return -1;
115115
}
116-
116+
117117
LOG(INFO) << "TLS Connection to PA established successfully.";
118118

119119
// Close session with PA.

src/pa/loadtest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
clientKey = flag.String("client_key", "", "File path to the PEM encoding of the client's private key")
4747
configDir = flag.String("spm_config_dir", "", "Path to the SKU configuration directory.")
4848
enableTLS = flag.Bool("enable_tls", false, "Enable mTLS secure channel; optional")
49+
enableMLKEM = flag.Bool("enable_mlkem", false, "Enable MLKEM TLS configuration; optional")
4950
hsmSOLibPath = flag.String("hsm_so", "", "File path to the HSM's PKCS#11 shared library.")
5051
paAddress = flag.String("pa_address", "", "the PA server address to connect to; required")
5152
parallelClients = flag.Int("parallel_clients", 1, "The total number of clients to run concurrently")
@@ -89,7 +90,7 @@ type clientGroup struct {
8990
func (c *clientTask) setup(ctx context.Context, skuName string) error {
9091
opts := []grpc.DialOption{grpc.WithBlock()}
9192
if *enableTLS {
92-
credentials, err := grpconn.LoadClientCredentials(*caRootCerts, *clientCert, *clientKey)
93+
credentials, err := (&grpconn.Config{EnableMLKEMTLS: *enableMLKEM}).LoadClientCredentials(*caRootCerts, *clientCert, *clientKey)
9394
if err != nil {
9495
return err
9596
}

src/pa/pa_server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
enableRegistry = flag.Bool("enable_registry", false, "Enable connectivity to the Registry server; optional")
2929
registryAddress = flag.String("registry_address", "", "the Registry (Buffer) server address to connect to; required")
3030
enableTLS = flag.Bool("enable_tls", false, "Enable mTLS secure channel; optional")
31+
enableMLKEM = flag.Bool("enable_mlkem", false, "Enable MLKEM TLS configuration; optional")
3132
serviceKey = flag.String("service_key", "", "File path to the PEM encoding of the server's private key")
3233
serviceCert = flag.String("service_cert", "", "File path to the PEM encoding of the server's certificate chain")
3334
caRootCerts = flag.String("ca_root_certs", "", "File path to the PEM encoding of the CA root certificates")
@@ -38,7 +39,7 @@ func startPAServer(spmClient pbs.SpmServiceClient) (*grpc.Server, error) {
3839
opts := []grpc.ServerOption{}
3940
auth_service.NewAuthControllerInstance(*enableTLS)
4041
if *enableTLS {
41-
credentials, err := grpconn.LoadServerCredentials(*caRootCerts, *serviceCert, *serviceKey)
42+
credentials, err := (&grpconn.Config{EnableMLKEMTLS: *enableMLKEM}).LoadServerCredentials(*caRootCerts, *serviceCert, *serviceKey)
4243
if err != nil {
4344
return nil, err
4445
}
@@ -55,7 +56,7 @@ func startPAServer(spmClient pbs.SpmServiceClient) (*grpc.Server, error) {
5556
func startSPMClient() (pbs.SpmServiceClient, error) {
5657
opts := grpc.WithInsecure()
5758
if *enableTLS {
58-
credentials, err := grpconn.LoadClientCredentials(*caRootCerts, *serviceCert, *serviceKey)
59+
credentials, err := (&grpconn.Config{EnableMLKEMTLS: *enableMLKEM}).LoadClientCredentials(*caRootCerts, *serviceCert, *serviceKey)
5960
if err != nil {
6061
return nil, err
6162
}
@@ -102,7 +103,7 @@ func main() {
102103
log.Fatalf("`registry_address` parameter missing")
103104
}
104105
log.Printf("starting Registry client at address: %q", *registryAddress)
105-
err = rs.StartRegistryBuffer(*registryAddress, *enableTLS, *caRootCerts, *serviceCert, *serviceKey)
106+
err = rs.StartRegistryBuffer(*registryAddress, *enableTLS, *enableMLKEM, *caRootCerts, *serviceCert, *serviceKey)
106107
if err != nil {
107108
log.Fatalf("failed to initialize Registry client: %v", err)
108109
}

src/pa/services/registry_shim/registry_shim.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626

2727
var registryClient proxybuffer.Registry
2828

29-
func StartRegistryBuffer(registryBufferAddress string, enableTLS bool, caRootCerts string, serviceCert string, serviceKey string) error {
29+
func StartRegistryBuffer(registryBufferAddress string, enableTLS bool, enableMLKEM bool, caRootCerts string, serviceCert string, serviceKey string) error {
3030
opts := grpc.WithInsecure()
3131
if enableTLS {
32-
credentials, err := grpconn.LoadClientCredentials(caRootCerts, serviceCert, serviceKey)
32+
credentials, err := (&grpconn.Config{EnableMLKEMTLS: enableMLKEM}).LoadClientCredentials(caRootCerts, serviceCert, serviceKey)
3333
if err != nil {
3434
return err
3535
}

src/proxy_buffer/pb_server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
syncerMaxRetriesPerRecord = flag.Int("syncer_max_retries_per_record", 5, "Number of times a record can be retried before it stops pb_server. Anything less than zero will not stop the service. Defaults to 5.")
3939
// gRPC server
4040
enableTLS = flag.Bool("enable_tls", false, "Enable mTLS secure channel; optional")
41+
enableMLKEM = flag.Bool("enable_mlkem", false, "Enable MLKEM TLS configuration; optional")
4142
serviceKey = flag.String("service_key", "", "File path to the PEM encoding of the server's private key")
4243
serviceCert = flag.String("service_cert", "", "File path to the PEM encoding of the server's certificate chain")
4344
caRootCerts = flag.String("ca_root_certs", "", "File path to the PEM encoding of the CA root certificates")
@@ -94,7 +95,7 @@ func main() {
9495

9596
opts := []grpc.ServerOption{}
9697
if *enableTLS {
97-
credentials, err := grpconn.LoadServerCredentials(*caRootCerts, *serviceCert, *serviceKey)
98+
credentials, err := (&grpconn.Config{EnableMLKEMTLS: *enableMLKEM}).LoadServerCredentials(*caRootCerts, *serviceCert, *serviceKey)
9899
if err != nil {
99100
log.Fatalf("Failed to load server credentials: %v", err)
100101
}

0 commit comments

Comments
 (0)