Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: support openssl 3.1.0-3.1.4 and 3.0.9-3.0.12 #469

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions user/module/probe_openssl_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
LinuxDefauleFilename_1_1_0 = "linux_default_1_1_0"
LinuxDefauleFilename_1_1_1 = "linux_default_1_1_1"
LinuxDefauleFilename_3_0 = "linux_default_3_0"
LinuxDefauleFilename_3_1 = "linux_default_3_0"
AndroidDefauleFilename = "android_default"

OpenSslVersionLen = 30 // openssl version string length
Expand All @@ -37,7 +38,8 @@ const (
MaxSupportedOpenSSL102Version = 'u'
MaxSupportedOpenSSL110Version = 'l'
MaxSupportedOpenSSL111Version = 'u'
MaxSupportedOpenSSL30Version = '9'
MaxSupportedOpenSSL30Version = 12
MaxSupportedOpenSSL31Version = 4
)

// initOpensslOffset initial BpfMap
Expand All @@ -52,7 +54,7 @@ func (m *MOpenSSLProbe) initOpensslOffset() {
// openssl 1.1.1*
LinuxDefauleFilename_1_1_1: "openssl_1_1_1j_kern.o",

// openssl 3.0.*
// openssl 3.0.* and openssl 3.1.*
LinuxDefauleFilename_3_0: "openssl_3_0_0_kern.o",

// boringssl
Expand Down Expand Up @@ -80,9 +82,14 @@ func (m *MOpenSSLProbe) initOpensslOffset() {
m.sslVersionBpfMap["openssl 1.1.1"+string(ch)] = "openssl_1_1_1j_kern.o"
}

// openssl 3.0.0 - 3.0.7
for ch := '0'; ch <= MaxSupportedOpenSSL30Version; ch++ {
m.sslVersionBpfMap["openssl 3.0."+string(ch)] = "openssl_3_0_0_kern.o"
// openssl 3.0.0 - 3.0.12
for ch := 0; ch <= MaxSupportedOpenSSL30Version; ch++ {
m.sslVersionBpfMap[fmt.Sprintf("openssl 3.0.%d", ch)] = "openssl_3_0_0_kern.o"
}

// openssl 3.1.0 - 3.1.4
for ch := 0; ch <= MaxSupportedOpenSSL31Version; ch++ {
m.sslVersionBpfMap[fmt.Sprintf("openssl 3.1.%d", ch)] = "openssl_3_0_0_kern.o"
}

// openssl 1.1.0a - 1.1.0l
Expand Down
3 changes: 3 additions & 0 deletions utils/openssl_offset_1.0.2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ if [[ ! -f "go.mod" ]]; then
fi

# skip cloning if the header file of the max supported version is already generated
echo "check file exists: ${OPENSSL_DIR}/.git"
if [[ ! -f "${OPENSSL_DIR}/.git" ]]; then
# skip cloning if the openssl directory already exists
echo "check directory exists: ${OPENSSL_DIR}"
if [[ ! -d "${OPENSSL_DIR}" ]]; then
echo "git clone openssl to ${OPENSSL_DIR}"
git clone https://github.com/openssl/openssl.git ${OPENSSL_DIR}
fi
fi
Expand Down
11 changes: 9 additions & 2 deletions utils/openssl_offset_3.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ if [[ ! -f "go.mod" ]]; then
exit 1
fi

echo "check file exists: ${OPENSSL_DIR}/.git"
# skip cloning if the header file of the max supported version is already generated
if [[ ! -f "${OUTPUT_DIR}/openssl_3_0_0_kern.c" ]]; then
if [[ ! -f "${OPENSSL_DIR}/.git" ]]; then
echo "check directory exists: ${OPENSSL_DIR}"
# skip cloning if the openssl directory already exists
if [[ ! -d "${OPENSSL_DIR}" ]]; then
echo "git clone openssl to ${OPENSSL_DIR}"
git clone https://github.com/openssl/openssl.git ${OPENSSL_DIR}
fi
fi
Expand All @@ -32,6 +35,9 @@ function run() {
sslVerMap["7"]="0"
sslVerMap["8"]="0"
sslVerMap["9"]="0"
sslVerMap["10"]="0"
sslVerMap["11"]="0"
sslVerMap["12"]="0"

# shellcheck disable=SC2068
for ver in ${!sslVerMap[@]}; do
Expand All @@ -44,7 +50,7 @@ function run() {
echo "Skip ${header_file}"
continue
fi

echo "git checkout ${tag}"
git checkout ${tag}
echo "Generating ${header_file}"

Expand Down Expand Up @@ -76,6 +82,7 @@ function run() {
rm offset.c
}

# TODO Check if the directory for OpenSSL exists
pushd ${OPENSSL_DIR}
(run)
[[ "$?" != 0 ]] && popd
Expand Down
82 changes: 82 additions & 0 deletions utils/openssl_offset_3.1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash
set -e

PROJECT_ROOT_DIR=$(pwd)
OPENSSL_DIR="${PROJECT_ROOT_DIR}/deps/openssl"
OUTPUT_DIR="${PROJECT_ROOT_DIR}/kern"

if [[ ! -f "go.mod" ]]; then
echo "Run the script from the project root directory"
exit 1
fi

echo "check file exists: ${OPENSSL_DIR}/.git"
# skip cloning if the header file of the max supported version is already generated
if [[ ! -f "${OPENSSL_DIR}/.git" ]]; then
echo "check directory exists: ${OPENSSL_DIR}"
# skip cloning if the openssl directory already exists
if [[ ! -d "${OPENSSL_DIR}" ]]; then
echo "git clone openssl to ${OPENSSL_DIR}"
git clone https://github.com/openssl/openssl.git ${OPENSSL_DIR}
fi
fi

function run() {
git fetch --tags
cp -f ${PROJECT_ROOT_DIR}/utils/openssl_3_0_offset.c ${OPENSSL_DIR}/offset.c
declare -A sslVerMap=()
sslVerMap["0"]="0"
sslVerMap["1"]="0"
sslVerMap["2"]="0"
sslVerMap["3"]="0"
sslVerMap["4"]="0"

# shellcheck disable=SC2068
for ver in ${!sslVerMap[@]}; do
tag="openssl-3.1.${ver}"
val=${sslVerMap[$ver]}
# 3.1.X and 3.0.X OFFSET is the same, use the same for the time being
header_file="${OUTPUT_DIR}/openssl_3_0_${val}_kern.c"
header_define="OPENSSL_3_0_$(echo ${val} | tr "[:lower:]" "[:upper:]")_KERN_H"

if [[ -f ${header_file} ]]; then
echo "Skip ${header_file}"
continue
fi
echo "git checkout ${tag}"
git checkout ${tag}
echo "Generating ${header_file}"


# config and make openssl/opensslconf.h
./config

# make reconfigure reconf
make clean
make include/openssl/opensslconf.h
make include/openssl/configuration.h
make build_generated


clang -I include/ -I . offset.c -o offset

echo -e "#ifndef ECAPTURE_${header_define}" >${header_file}
echo -e "#define ECAPTURE_${header_define}\n" >>${header_file}
./offset >>${header_file}
echo -e "#include \"openssl.h\"" >>${header_file}
echo -e "#include \"openssl_masterkey_3.0.h\"" >>${header_file}
echo -e "\n#endif" >>${header_file}

# clean up
make clean

done

rm offset.c
}

# TODO Check if the directory for OpenSSL exists
pushd ${OPENSSL_DIR}
(run)
[[ "$?" != 0 ]] && popd
popd
Loading