Skip to content

Commit e931837

Browse files
Willy Zhangwillyzha
authored andcommitted
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 0ed2d13 commit e931837

File tree

19 files changed

+1645
-239
lines changed

19 files changed

+1645
-239
lines changed

MODULE.bazel

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ module(name = "lowrisc_opentitan_provisioning")
88
# Standard Libraries & Utilities
99
# -------------------------------------------------------------------------
1010

11-
bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "com_google_absl")
11+
bazel_dep(name = "abseil-cpp", version = "20240722.0.bcr.1", repo_name = "com_google_absl")
1212
bazel_dep(name = "bazel_skylib", version = "1.7.1")
13-
bazel_dep(name = "googletest", version = "1.14.0.bcr.1", repo_name = "com_google_googletest")
13+
bazel_dep(name = "googletest", version = "1.15.2", repo_name = "com_google_googletest")
1414
bazel_dep(name = "platforms", version = "0.0.11")
15-
bazel_dep(name = "re2", version = "2023-09-01", repo_name = "com_googlesource_code_re2")
15+
bazel_dep(name = "re2", version = "2024-07-02", repo_name = "com_googlesource_code_re2")
1616
bazel_dep(name = "upb", version = "0.0.0-20230907-e7430e6")
1717

1818
# -------------------------------------------------------------------------
1919
# Build Rules
2020
# -------------------------------------------------------------------------
2121

2222
bazel_dep(name = "rules_apple", version = "3.16.1")
23+
bazel_dep(name = "rules_swift", version = "2.1.1", repo_name = "build_bazel_rules_swift")
2324
bazel_dep(name = "rules_cc", version = "0.1.2")
2425
bazel_dep(name = "rules_pkg", version = "1.0.1")
2526
bazel_dep(name = "rules_proto", version = "7.0.2")
2627

28+
bazel_dep(name = "aspect_rules_lint", version = "1.0.8")
29+
2730
bazel_dep(name = "rules_foreign_cc", version = "0.9.0")
2831
single_version_override(
2932
module_name = "rules_foreign_cc",
@@ -35,17 +38,30 @@ single_version_override(
3538
# -------------------------------------------------------------------------
3639

3740
bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf")
41+
bazel_dep(name = "protoc-gen-validate", version = "1.0.4.bcr.2")
3842

39-
bazel_dep(name = "grpc", version = "1.66.0.bcr.3", repo_name = "com_github_grpc_grpc")
43+
# Use a modern gRPC (compatible with Protobuf 27+)
44+
bazel_dep(name = "grpc", version = "1.68.0", repo_name = "com_github_grpc_grpc")
4045
single_version_override(
4146
module_name = "grpc",
4247
patch_strip = 0,
4348
patches = [
4449
"third_party/google/grpc_windows_config_setting.patch",
4550
"third_party/google/grpc_windows_endpoint_fix.patch",
51+
"third_party/google/grpc_force_mlkem.patch",
4652
],
4753
)
4854

55+
bazel_dep(name = "boringssl")
56+
archive_override(
57+
module_name = "boringssl",
58+
integrity = "sha256-dHR3G61xqu8ZpYuovGGINHZ7VxPMPEean1AquU74k5E=",
59+
patch_strip = 0,
60+
patches = ["third_party/google/boringssl_mingw_fix.patch"],
61+
strip_prefix = "boringssl-0.20241024.0",
62+
urls = ["https://github.com/google/boringssl/releases/download/0.20241024.0/boringssl-0.20241024.0.tar.gz"],
63+
)
64+
4965
# -------------------------------------------------------------------------
5066
# OpenTitan Project
5167
# -------------------------------------------------------------------------

MODULE.bazel.lock

Lines changed: 1427 additions & 211 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)