Skip to content

Commit

Permalink
corret bpf obj (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuweizzz authored Oct 24, 2024
1 parent 93cfff4 commit 03a9409
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 13 deletions.
13 changes: 7 additions & 6 deletions kern/openssl_3_3_0_kern.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef ECAPTURE_OPENSSL_3_2_0_KERN_H
#define ECAPTURE_OPENSSL_3_2_0_KERN_H
#ifndef ECAPTURE_OPENSSL_3_3_0_KERN_H
#define ECAPTURE_OPENSSL_3_3_0_KERN_H

/* OPENSSL_VERSION_TEXT: OpenSSL 3.3.2 3 Sep 2024 */
/* OPENSSL_VERSION_NUMBER: 808452128 */
/* OPENSSL_VERSION_TEXT: OpenSSL 3.3.1 4 Jun 2024 */
/* OPENSSL_VERSION_NUMBER: 808452112 */

// ssl_st->type
#define SSL_ST_TYPE 0x0
Expand Down Expand Up @@ -32,10 +32,10 @@
#define SSL_CONNECTION_ST_S3_CLIENT_RANDOM 0x140

// ssl_session_st->cipher
#define SSL_SESSION_ST_CIPHER 0x2f8
#define SSL_SESSION_ST_CIPHER 0x300

// ssl_session_st->cipher_id
#define SSL_SESSION_ST_CIPHER_ID 0x300
#define SSL_SESSION_ST_CIPHER_ID 0x308

// ssl_cipher_st->id
#define SSL_CIPHER_ST_ID 0x18
Expand Down Expand Up @@ -73,6 +73,7 @@

#define SSL_ST_RBIO SSL_CONNECTION_ST_RBIO


#include "openssl.h"
#include "openssl_masterkey_3.2.h"

Expand Down
80 changes: 80 additions & 0 deletions kern/openssl_3_3_2_kern.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#ifndef ECAPTURE_OPENSSL_3_3_2_KERN_H
#define ECAPTURE_OPENSSL_3_3_2_KERN_H

/* OPENSSL_VERSION_TEXT: OpenSSL 3.3.2 3 Sep 2024 */
/* OPENSSL_VERSION_NUMBER: 808452128 */

// ssl_st->type
#define SSL_ST_TYPE 0x0

// ssl_connection_st->version
#define SSL_CONNECTION_ST_VERSION 0x40

// ssl_connection_st->session
#define SSL_CONNECTION_ST_SESSION 0x880

// ssl_connection_st->s3
#define SSL_CONNECTION_ST_S3 0x118

// ssl_connection_st->rbio
#define SSL_CONNECTION_ST_RBIO 0x48

// ssl_connection_st->wbio
#define SSL_CONNECTION_ST_WBIO 0x50

// ssl_connection_st->server
#define SSL_CONNECTION_ST_SERVER 0x70

// ssl_session_st->master_key
#define SSL_SESSION_ST_MASTER_KEY 0x50

// ssl_connection_st->s3.client_random
#define SSL_CONNECTION_ST_S3_CLIENT_RANDOM 0x140

// ssl_session_st->cipher
#define SSL_SESSION_ST_CIPHER 0x2f8

// ssl_session_st->cipher_id
#define SSL_SESSION_ST_CIPHER_ID 0x300

// ssl_cipher_st->id
#define SSL_CIPHER_ST_ID 0x18

// ssl_connection_st->handshake_secret
#define SSL_CONNECTION_ST_HANDSHAKE_SECRET 0x53c

// ssl_connection_st->handshake_traffic_hash
#define SSL_CONNECTION_ST_HANDSHAKE_TRAFFIC_HASH 0x6bc

// ssl_connection_st->client_app_traffic_secret
#define SSL_CONNECTION_ST_CLIENT_APP_TRAFFIC_SECRET 0x6fc

// ssl_connection_st->server_app_traffic_secret
#define SSL_CONNECTION_ST_SERVER_APP_TRAFFIC_SECRET 0x73c

// ssl_connection_st->exporter_master_secret
#define SSL_CONNECTION_ST_EXPORTER_MASTER_SECRET 0x77c

// bio_st->num
#define BIO_ST_NUM 0x38

// bio_st->method
#define BIO_ST_METHOD 0x8

// bio_method_st->type
#define BIO_METHOD_ST_TYPE 0x0

// quic_conn_st->tls
#define QUIC_CONN_ST_TLS 0x40

#define SSL_ST_VERSION SSL_CONNECTION_ST_VERSION

#define SSL_ST_WBIO SSL_CONNECTION_ST_WBIO

#define SSL_ST_RBIO SSL_CONNECTION_ST_RBIO


#include "openssl.h"
#include "openssl_masterkey_3.2.h"

#endif
13 changes: 9 additions & 4 deletions user/module/probe_openssl_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const (
MaxSupportedOpenSSL31Version = 7
SupportedOpenSSL32Version2 = 2 // openssl 3.2.0 ~ 3.2.2
MaxSupportedOpenSSL32Version = 3 // openssl 3.2.3 ~ newer
MaxSupportedOpenSSL33Version = 2
SupportedOpenSSL33Version1 = 1 // openssl 3.3.0 ~ 3.3.1
MaxSupportedOpenSSL33Version = 2 // openssl 3.3.2
)

// initOpensslOffset initial BpfMap
Expand Down Expand Up @@ -117,12 +118,16 @@ func (m *MOpenSSLProbe) initOpensslOffset() {
m.sslVersionBpfMap[fmt.Sprintf("openssl 3.2.%d", ch)] = "openssl_3_2_3_kern.o"
}

// openssl 3.3.0 - newer
for ch := 0; ch <= MaxSupportedOpenSSL33Version; ch++ {
// The OpenSSL 3.3.* series is the same as the 3.2.* series of offsets
// openssl 3.3.0 - 3.3.1
for ch := 0; ch <= SupportedOpenSSL33Version1; ch++ {
m.sslVersionBpfMap[fmt.Sprintf("openssl 3.3.%d", ch)] = "openssl_3_3_0_kern.o"
}

// openssl 3.3.2
for ch := 2; ch <= MaxSupportedOpenSSL33Version; ch++ {
m.sslVersionBpfMap[fmt.Sprintf("openssl 3.3.%d", ch)] = "openssl_3_3_2_kern.o"
}

// openssl 1.1.0a - 1.1.0l
for ch := 'a'; ch <= MaxSupportedOpenSSL110Version; ch++ {
m.sslVersionBpfMap["openssl 1.1.0"+string(ch)] = "openssl_1_1_0a_kern.o"
Expand Down
6 changes: 3 additions & 3 deletions utils/openssl_offset_3.3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ function run() {
declare -A sslVerMap=()
sslVerMap["0"]="0"
sslVerMap["1"]="0"
sslVerMap["2"]="0"
sslVerMap["2"]="2"

# shellcheck disable=SC2068
for ver in ${!sslVerMap[@]}; do
tag="openssl-3.3.${ver}"
val=${sslVerMap[$ver]}
header_file="${OUTPUT_DIR}/openssl_3_3_${val}_kern.c"
header_define="OPENSSL_3_2_$(echo ${val} | tr "[:lower:]" "[:upper:]")_KERN_H"
header_define="OPENSSL_3_3_$(echo ${val} | tr "[:lower:]" "[:upper:]")_KERN_H"

if [[ -f ${header_file} ]]; then
echo "Skip ${header_file}"
Expand All @@ -61,7 +61,7 @@ function run() {
echo -e "#define SSL_ST_WBIO SSL_CONNECTION_ST_WBIO\n" >>${header_file}
echo -e "#define SSL_ST_RBIO SSL_CONNECTION_ST_RBIO\n" >>${header_file}
echo -e "\n#include \"openssl.h\"" >>${header_file}
echo -e "#include \"openssl_masterkey_3.3.h\"" >>${header_file}
echo -e "#include \"openssl_masterkey_3.2.h\"" >>${header_file}
echo -e "\n#endif" >>${header_file}

# clean up
Expand Down
3 changes: 3 additions & 0 deletions variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ TARGETS += kern/openssl_1_1_0a
TARGETS += kern/openssl_1_0_2a
TARGETS += kern/openssl_3_0_0
TARGETS += kern/openssl_3_2_0
TARGETS += kern/openssl_3_2_3
TARGETS += kern/openssl_3_3_0
TARGETS += kern/openssl_3_3_2
TARGETS += kern/gotls

ifeq ($(ANDROID),0)
Expand Down

0 comments on commit 03a9409

Please sign in to comment.