Skip to content
Open
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
73 changes: 48 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,58 @@ if(WIN32 AND BUILD_SHARED_LIBS)
add_definitions(-Dlibnfs_EXPORTS)
endif()


#
# Check if we're on Azure Linux and skip TLS if so
#
function(is_azure_linux RESULT_VAR)
set(${RESULT_VAR} FALSE PARENT_SCOPE)

if(EXISTS "/etc/os-release")
file(READ "/etc/os-release" OS_CONTENT)
if(OS_CONTENT MATCHES "ID=ubuntu")
set(${RESULT_VAR} TRUE PARENT_SCOPE)
endif()
endif()
endfunction()

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
add_definitions("-D_U_=__attribute__((unused))")
#
# Currently RPC-with-TLS support is only available on Linux since it depends on kTLS support
# on Linux.
#
# TODO: BSD also has kTLS support, but that will need separate validation.
#
find_package(GnuTLS "3.4.6")
if(GNUTLS_FOUND)

# Detect if running on Azure Linux
is_azure_linux(RUNNING_ON_AZURE_LINUX)

if(RUNNING_ON_AZURE_LINUX)
message(STATUS "Azure Linux detected - skipping TLS support")
else()
#
# Make sure the two most important header files are present before we enable TLS support,
# to avoid running into issues later during build. GnuTLS package found but gnutls/gnutls.h
# not found is a serious issue while if linux/tls.h is not found it would likely mean that
# user is using a kernel not supporting kTLS so we simply don't turn on TLS support.
# Currently RPC-with-TLS support is only available on Linux since it depends on kTLS support
# on Linux.
#
check_include_file("gnutls/gnutls.h" HAVE_GNUTLS_H)
if(NOT HAVE_GNUTLS_H EQUAL "1")
message(FATAL_ERROR "GnuTLS found but gnutls/gnutls.h not found, GNUTLS_INCLUDE_DIR is ${GNUTLS_INCLUDE_DIR}")
endif()

check_include_file("linux/tls.h" HAVE_LINUX_TLS_H)
if(NOT HAVE_LINUX_TLS_H EQUAL "1")
message(STATUS "GnuTLS found but linux/tls.h not found, likely a kernel w/o kTLS support, can't enable TLS support")
else()
message(STATUS "Using ${GNUTLS_LIBRARIES}")
add_definitions(-DHAVE_TLS)
list(APPEND SYSTEM_LIBRARIES ${GNUTLS_LIBRARIES})
add_subdirectory(tls)
# TODO: BSD also has kTLS support, but that will need separate validation.
#
find_package(GnuTLS "3.4.6")
if(GNUTLS_FOUND)
#
# Make sure the two most important header files are present before we enable TLS support,
# to avoid running into issues later during build. GnuTLS package found but gnutls/gnutls.h
# not found is a serious issue while if linux/tls.h is not found it would likely mean that
# user is using a kernel not supporting kTLS so we simply don't turn on TLS support.
#
check_include_file("gnutls/gnutls.h" HAVE_GNUTLS_H)
if(NOT HAVE_GNUTLS_H EQUAL "1")
message(FATAL_ERROR "GnuTLS found but gnutls/gnutls.h not found, GNUTLS_INCLUDE_DIR is ${GNUTLS_INCLUDE_DIR}")
endif()

check_include_file("linux/tls.h" HAVE_LINUX_TLS_H)
if(NOT HAVE_LINUX_TLS_H EQUAL "1")
message(STATUS "GnuTLS found but linux/tls.h not found, likely a kernel w/o kTLS support, can't enable TLS support")
else()
message(STATUS "Using ${GNUTLS_LIBRARIES}")
add_definitions(-DHAVE_TLS)
list(APPEND SYSTEM_LIBRARIES ${GNUTLS_LIBRARIES})
add_subdirectory(tls)
endif()
endif()
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL WindowsStore)
Expand Down
3 changes: 2 additions & 1 deletion include/libnfs-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ struct rpc_context {
/* Context used for performing TLS handshake with the server */
struct tls_context tls_context;

#endif /* HAVE_TLS */

/*
* Do we need to perform auth on connect/reconnect?
* This starts as FALSE and is set to TRUE if user calls
Expand All @@ -532,7 +534,6 @@ struct rpc_context {
*/
bool_t use_azauth;
struct auth_context auth_context;
#endif /* HAVE_TLS */

#ifdef HAVE_LIBKRB5
const char *username;
Expand Down
4 changes: 4 additions & 0 deletions lib/libnfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@ void free_tls_cb_data(struct tls_cb_data *data)
assert(data->magic == TLS_CB_DATA_MAGIC);
free(data);
}
#endif /* HAVE_TLS */

/*
* Callback function called when we get a response for an AZAUTH RPC from the
Expand Down Expand Up @@ -967,6 +968,7 @@ rpc_connect_program_4_2_cb(struct rpc_context *rpc, int status,
free_azauth_cb_data(data);
}

#ifdef HAVE_TLS
/*
* Callback function called when we get a response for an AUTH_TLS NULL RPC
* that we sent to the server.
Expand Down Expand Up @@ -1083,6 +1085,7 @@ rpc_connect_program_5_cb(struct rpc_context *rpc, int status,
free_rpc_cb_data(data);
}

#ifdef HAVE_TLS
static void
rpc_connect_program_5_0_cb(struct rpc_context *rpc, int status,
void *command_data, void *private_data)
Expand Down Expand Up @@ -1123,6 +1126,7 @@ rpc_connect_program_5_0_cb(struct rpc_context *rpc, int status,
return;
}
}
#endif /* HAVE_TLS */

static void
rpc_connect_program_4_cb(struct rpc_context *rpc, int status,
Expand Down
4 changes: 2 additions & 2 deletions lib/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,6 @@ rpc_disconnect(struct rpc_context *rpc, const char *error)
return 0;
}

#ifdef HAVE_TLS

/*
* During TCP reconnection, for secure transport, we need to re-perform auth.
Expand Down Expand Up @@ -1989,6 +1988,7 @@ reconnect_cb_azauth(struct rpc_context *rpc, int status,
RPC_LOG(rpc, 2, "reconnect_cb_azauth: AzAuth completed successfully!");
}

#ifdef HAVE_TLS
/*
* During TCP reconnection (either server or client closes connection) for secure
* transport we need to perform the TLS handshake. This is the callback function
Expand Down Expand Up @@ -2096,7 +2096,7 @@ reconnect_cb(struct rpc_context *rpc, int status, void *data,
#endif /* HAVE_TLS */

#ifdef ENABLE_INSECURE_AUTH_FOR_DEVTEST
else if (rpc->use_azauth) {
if (rpc->use_azauth) {
/*
* Insecure connection, if azauth is enabled perform auth.
*
Expand Down