Skip to content

Commit 048c3f8

Browse files
committed
Support TLS listeners
Added ===== - TLS configuration in broker config - Helper script for generating test certs and CAs - TLS options for NtcChannel - Loading certificates and authority data specified from bmqbrkrcfg.json - SessionOptions to bmq package for configuring client sessions - --tls-authority and --tls-version options to bmqtool to configure session options - Client sessions will now require broker TLS sessions when TLS protocol versions are specified - Create CertificateStore component for bmqio - Integration tests for TLS Changed ======= - Update ntf-core and bde dependencies Signed-off-by: Taylor Foxhall <tfoxhall@bloomberg.net> Signed-off-by: Evgeny Malygin <emalygin@bloomberg.net>
1 parent c0e9830 commit 048c3f8

100 files changed

Lines changed: 5780 additions & 1680 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-ubuntu.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jobs:
105105
libfl-dev \
106106
libbenchmark-dev \
107107
libgmock-dev \
108+
libgtest-dev \
108109
libz-dev
109110
- name: Install cached non packaged dependencies
110111
if: steps.build-cache-restore-step.outputs.cache-hit != 'true' # Variable type is string, thus using quotes

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ jobs:
320320
libfl-dev \
321321
libbenchmark-dev \
322322
libgmock-dev \
323+
libgtest-dev \
323324
libz-dev \
324325
autoconf \
325326
libtool

.github/workflows/dependencies.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
libfl-dev \
6060
libbenchmark-dev \
6161
libgmock-dev \
62+
libgtest-dev \
6263
libz-dev
6364
6465
- name: Fetch & build non packaged dependencies

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,3 @@ settings.json
4040

4141
# Symlink from 'src/applications/bmqbrkr/run'
4242
src/applications/bmqbrkr/etc/etc
43-
44-
# 'sim_cpp11_features.pl' backups
45-
*.bak

bin/build-darwin.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fi
6969

7070
# :: Optionally install prerequisites :::::::::::::::::::::::::::::::::::::::::
7171

72-
REQ_PKGS=(cmake flex bison google-benchmark googletest ninja pkg-config zlib)
72+
REQ_PKGS=(cmake flex bison google-benchmark googletest ninja openssl pkg-config zlib)
7373

7474
if $INSTALL_DEPS; then
7575
if ! command -v brew >/dev/null 2>&1; then
@@ -91,7 +91,7 @@ mkdir -p "${DIR_THIRDPARTY}"
9191
DIR_BUILD="${DIR_BUILD:-${DIR_ROOT}/build}"
9292
mkdir -p "${DIR_BUILD}"
9393

94-
DIR_INSTALL="${DIR_INSTALL:-${DIR_ROOT}}"
94+
DIR_INSTALL="${DIR_INSTALL:-${DIR_ROOT}/install}"
9595
mkdir -p "${DIR_INSTALL}"
9696

9797

bin/build-ubuntu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ echo -e "Before running this script, install the following prerequisites, if not
66
"by executing the following commands:\n" \
77
"sudo apt update && sudo apt -y install ca-certificates\n" \
88
"sudo apt install -y --no-install-recommends" \
9-
"autoconf automake build-essential gdb cmake ninja-build pkg-config bison libfl-dev libbenchmark-dev libgmock-dev libtool libz-dev"
9+
"autoconf automake build-essential gdb cmake ninja-build pkg-config bison libfl-dev libbenchmark-dev libgmock-dev libgtest-dev libtool libz-dev"
1010

1111
# :: Parse and validate arguments :::::::::::::::::::::::::::::::::::::::::::::
1212
print_usage_and_exit_with_error() {
@@ -59,7 +59,7 @@ mkdir -p "${DIR_THIRDPARTY}"
5959
DIR_BUILD="${DIR_BUILD:-${DIR_ROOT}/build}"
6060
mkdir -p "${DIR_BUILD}"
6161

62-
DIR_INSTALL="${DIR_INSTALL:-${DIR_ROOT}}"
62+
DIR_INSTALL="${DIR_INSTALL:-${DIR_ROOT}/install}"
6363
mkdir -p "${DIR_INSTALL}"
6464

6565
# :: Clone dependencies :::::::::::::::::::::::::::::::::::::::::::::::::::::::

bin/codegen.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# This script is not able to be run by non-Bloomberg developers as it relies on internal tooling.
55

6-
COPYRIGHT="// Copyright 2025 Bloomberg Finance L.P.
6+
readonly COPYRIGHT="// Copyright 2025 Bloomberg Finance L.P.
77
// SPDX-License-Identifier: Apache-2.0
88
//
99
// Licensed under the Apache License, Version 2.0 (the \"License\");
@@ -18,6 +18,7 @@ COPYRIGHT="// Copyright 2025 Bloomberg Finance L.P.
1818
// See the License for the specific language governing permissions and
1919
// limitations under the License.
2020
"
21+
readonly CODEGEN="${CODEGEN:-}"
2122

2223
codegen() {
2324
local dir=$1
@@ -49,17 +50,27 @@ codegen() {
4950
done
5051
}
5152

53+
usage() {
54+
echo "Usage: codegen.sh <schema-name>\
55+
Valid schema names include: [ m_bmqtool, bmqp_ctrlmsg, bmqstm, mqbcfg, mqbcmd, mqbconf ]"\ >&2
56+
}
57+
5258
main() {
5359
set -eux
5460

55-
if [[ -z "${CODEGEN+}" ]]; then
61+
if [[ -z "${CODEGEN}" ]]; then
5662
echo "This script is not able to be run by non-Bloomberg developers as it relies on \
5763
internal tooling. Please open an issue if you are an open-source contributor \
5864
in need of code generation. If you are a Bloomberg developer, please rerun this \
5965
script with the CODEGEN enviornment variable set to the internal codegen tool." >&2
6066
exit 1
6167
fi
6268

69+
if [[ -z "${1+x}" ]]; then
70+
usage
71+
exit 1
72+
fi
73+
6374
case "$1" in
6475
m_bmqtool)
6576
codegen ./src/applications/bmqtool bmqtoolcmd.xsd m_bmqtool messages
@@ -80,7 +91,7 @@ script with the CODEGEN enviornment variable set to the internal codegen tool."
8091
codegen ./src/groups/mqb/mqbconfm mqbconf.xsd messages
8192
;;
8293
*)
83-
echo "Unrecognized/missing codegen target" >&2
94+
usage
8495
exit 1
8596
;;
8697
esac

bin/gen-tls-certs.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
#
3+
#
4+
# This scripts generates:
5+
# - root CA certificate
6+
# - server certificate and keystore
7+
# - client keys
8+
#
9+
# Based off of
10+
# https://github.com/confluentinc/librdkafka/blob/master/tests/gen-ssl-certs.sh
11+
12+
OP="$1"
13+
CA_CERT="$2"
14+
PFX="$3"
15+
HOST="$4"
16+
17+
C=NN
18+
ST=NN
19+
L=NN
20+
O=NN
21+
OU=NN
22+
CN="$HOST"
23+
24+
25+
# Password
26+
PASS="secret"
27+
28+
# Cert validity, in days
29+
VALIDITY=10000
30+
31+
set -e
32+
33+
export LC_ALL=C
34+
35+
if [[ $OP == "ca" && -n "$CA_CERT" && -n "$3" ]]; then
36+
CN="$3"
37+
openssl req -new -x509 -keyout "${CA_CERT}.key" -out "${CA_CERT}" -days $VALIDITY -passin "pass:$PASS" -passout "pass:$PASS" <<EOF
38+
${C}
39+
${ST}
40+
${L}
41+
${O}
42+
${OU}
43+
${CN}
44+
$USER@${CN}
45+
.
46+
.
47+
EOF
48+
49+
50+
51+
elif [[ $OP == "server" && -n "$CA_CERT" && -n "$PFX" && -n "$CN" ]]; then
52+
HOST_CERT_CONFIG_PATH="${PFX}host_cert.cnf"
53+
HOST_PRIVATE_RSA_KEY_PATH="${PFX}host_private_key_rsa.pem"
54+
HOST_PRIVATE_KEY_PATH="${PFX}private_key.pem"
55+
HOST_CSR_PATH="${PFX}host_csr.pem"
56+
HOST_CERT_PATH="${PFX}host_cert.pem"
57+
HOST_CERT_CHAIN_PATH="${PFX}client_${CN}.pem"
58+
59+
# Create the CA cert config file
60+
echo "Setting up host certs..."
61+
62+
cat <<EOF > "${HOST_CERT_CONFIG_PATH}"
63+
[req]
64+
default_bits = 2048
65+
distinguished_name = req_distinguished_name
66+
req_extensions = v3_req
67+
prompt = no
68+
[req_distinguished_name]
69+
C = ${C}
70+
ST = ${ST}
71+
L = ${L}
72+
O = ${O}
73+
CN = ${CN}
74+
[v3_req]
75+
subjectAltName = @alt_names
76+
[alt_names]
77+
DNS.1 = ${CN}
78+
DNS.2 = localhost.
79+
EOF
80+
81+
#Step 1
82+
echo "############ Generating key"
83+
openssl genrsa -out "${HOST_PRIVATE_RSA_KEY_PATH}" 2048
84+
openssl pkcs8 -nocrypt -topk8 -v1 PBE-SHA1-RC4-128 -inform pem -outform pem -in "${HOST_PRIVATE_RSA_KEY_PATH}" -out "${HOST_PRIVATE_KEY_PATH}"
85+
86+
#Step 2
87+
echo "############ Generate the CSR"
88+
openssl req -nodes -new -extensions v3_req -sha256 -config "${HOST_CERT_CONFIG_PATH}" -key "${HOST_PRIVATE_KEY_PATH}" -out "${HOST_CSR_PATH}"
89+
90+
#Step 3
91+
echo "############ Generate the cert"
92+
openssl x509 -req -in "${HOST_CSR_PATH}" -CA "${CA_CERT}" -CAkey "${CA_CERT}.key" -CAcreateserial -out "${HOST_CERT_PATH}" -days ${VALIDITY} -sha256 -extensions v3_req -extfile "${HOST_CERT_CONFIG_PATH}" -passin "pass:${PASS}"
93+
94+
cat "${HOST_CERT_PATH}" > "${HOST_CERT_CHAIN_PATH}"
95+
96+
97+
elif [[ $OP == "client" && -n "$CA_CERT" && -n "$PFX" && -n "$CN" ]]; then
98+
99+
# Standard OpenSSL keys
100+
echo "############ Generating key"
101+
openssl genrsa -nodes -passout "pass:${PASS}" -out "${PFX}client.key" 2048
102+
103+
echo "############ Generating request"
104+
openssl req -passin "pass:${PASS}" -passout "pass:${PASS}" -key "${PFX}client.key" -new -out "${PFX}client.req" \
105+
<<EOF
106+
$C
107+
$ST
108+
$L
109+
$O
110+
$OU
111+
$CN
112+
.
113+
$PASS
114+
.
115+
EOF
116+
117+
echo "########### Signing key"
118+
openssl x509 -req -passin "pass:${PASS}" -in "${PFX}client.req" -CA "${CA_CERT}" -CAkey "${CA_CERT}.key" -CAcreateserial -out "${PFX}client.pem" -days ${VALIDITY}
119+
120+
121+
else
122+
echo "Usage: $0 ca <ca-cert-file> <CN>"
123+
echo " $0 server|client <ca-cert-file> <file_prefix> <hostname>"
124+
echo ""
125+
exit 1
126+
fi
127+

docker/Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ RUN apt-get update && \
1515
libfl-dev \
1616
libbenchmark-dev \
1717
libgmock-dev \
18+
libgtest-dev \
19+
liblz4-dev \
20+
libssl-dev \
1821
libz-dev \
1922
libssl-dev \
2023
&& apt clean \
@@ -51,10 +54,19 @@ FROM docker.io/ubuntu:24.04
5154

5255
COPY --from=builder /bmq /usr/local
5356

57+
RUN apt-get update && \
58+
apt-get install -y --no-install-recommends \
59+
openssl
60+
5461
RUN groupadd bmq \
5562
&& useradd bmq --home /var/local/bmq --system --gid bmq --shell /usr/bin/bash
5663
USER bmq
5764
WORKDIR /var/local/bmq
58-
RUN mkdir -p logs storage/archive
65+
COPY bin/gen-tls-certs.sh gen-tls-certs.sh
66+
67+
RUN mkdir -p logs storage/archive certs && \
68+
cd certs && \
69+
../gen-tls-certs.sh ca ca-cert dummy && \
70+
../gen-tls-certs.sh server ca-cert broker_ dummy
5971

6072
CMD [ "/bin/bash" ]

docker/cluster/config/bmqbrkrcfg.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,27 @@
8686
"highWatermark": 1073741824,
8787
"nodeLowWatermark": 5242880,
8888
"nodeHighWatermark": 10485760,
89-
"heartbeatIntervalMs": 3000
89+
"heartbeatIntervalMs": 3000,
90+
"listeners": [
91+
{
92+
"name": "TCPListener",
93+
"port": 30114,
94+
"tls": false
95+
},
96+
{
97+
"name": "TLSListener",
98+
"port": 30115,
99+
"tls": true
100+
}
90101
}
91102
},
92103
"bmqconfConfig": {
93104
"cacheTTLSeconds": 30
105+
},
106+
"tlsConfig": {
107+
"certificateAuthority": "/var/local/bmq/certs/ca-cert",
108+
"certificate": "/var/local/bmq/certs/broker_host_cert.pem",
109+
"key": "/var/local/bmq/certs/broker_private_key.pem"
94110
}
95111
}
96112
}

0 commit comments

Comments
 (0)