Commit 729bc313 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen
Browse files

Add cpp-jwt lib for OAuth2 authorization

parent 463ea1a6
......@@ -265,6 +265,56 @@ install_nghttp2_from_git() {
return 0
}
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_cpp_jwt_from_git() {
if [ $1 -eq 0 ]; then
read -p "Do you want to install Cpp-jwt ? <y/N> " prompt
OPTION=""
else
prompt='y'
OPTION="-y"
fi
if [ $2 -eq 0 ]; then
debug=0
else
debug=1
fi
if [[ $prompt =~ [yY](es)* ]]
then
$SUDO apt-get install $OPTION \
libgtest-dev \
libssl-dev
ret=$?;[[ $ret -ne 0 ]] && return $ret
GIT_URL=https://github.com/arun11299/cpp-jwt.git
echo "Install Cpp-jwt from $GIT_URL"
pushd $OPENAIRCN_DIR/build/ext
echo "Downloading Cpp-jwt"
if [[ $OPTION =~ [yY](es)* ]]
then
$SUDO rm -rf cpp-jwt
fi
git clone $GIT_URL
cd cpp-jwt && git checkout master
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
mkdir _build && cd _build
cmake ..
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
make
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
$SUDO make install
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
popd
fi
return 0
}
#-------------------------------------------------------------------------------
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
......@@ -402,7 +452,10 @@ check_install_nrf_deps() {
install_nghttp2_from_git $1 $2
ret=$?;[[ $ret -ne 0 ]] && return $ret
install_cpp_jwt_from_git $1 $2
ret=$?;[[ $ret -ne 0 ]] && return $ret
return 0
}
#-------------------------------------------------------------------------------
......
......@@ -20,6 +20,7 @@
################################################################################
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/../build/ext/cpp-jwt)
include_directories(${SRC_TOP_DIR}/api-server/api)
include_directories(${SRC_TOP_DIR}/api-server/impl)
include_directories(${SRC_TOP_DIR}/api-server/model)
......@@ -33,6 +34,7 @@ add_library (NRF STATIC
nrf_subscription.cpp
nrf_client.cpp
nrf_search_result.cpp
nrf_jwt.cpp
task_manager.cpp
nrf_event.cpp
)
......
......@@ -41,6 +41,7 @@
#include "nrf_client.hpp"
#include "nrf_config.hpp"
#include "nrf_search_result.hpp"
#include "nrf_jwt.hpp"
using namespace oai::nrf::app;
using namespace oai::nrf::model;
......@@ -49,6 +50,7 @@ using namespace std::chrono;
extern nrf_app *nrf_app_inst;
extern nrf_config nrf_cfg;
nrf_client *nrf_client_inst = nullptr;
nrf_jwt *nrf_jwt_inst = nullptr;
//------------------------------------------------------------------------------
nrf_app::nrf_app(const std::string &config_file, nrf_event &ev)
......@@ -60,6 +62,7 @@ nrf_app::nrf_app(const std::string &config_file, nrf_event &ev)
try {
nrf_client_inst = new nrf_client();
nrf_jwt_inst = new nrf_jwt();
} catch (std::exception &e) {
Logger::nrf_app().error("Cannot create NRF_APP: %s", e.what());
throw;
......@@ -1004,3 +1007,4 @@ bool nrf_app::find_search_result(const std::string &search_id,
return false;
}
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file nrf_jwt.cpp
\brief
\author Tien-Thinh NGUYEN
\company Eurecom
\date 2020
\email: tien-thinh.nguyen@eurecom.fr
*/
#include "nrf_jwt.hpp"
#include <iostream>
#include "jwt/jwt.hpp"
using namespace oai::nrf::app;
void nrf_jwt::test_jwt(){
using namespace jwt::params;
auto key = "secret"; //Secret to use for the algorithm
//Create JWT object
jwt::jwt_object obj{algorithm("HS256"), payload({{"some", "payload"}}), secret(key)};
//Get the encoded string/assertion
auto enc_str = obj.signature();
std::cout << enc_str << std::endl;
//Decode
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret(key));
std::cout << dec_obj.header() << std::endl;
std::cout << dec_obj.payload() << std::endl;
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file nrf_jwt.hpp
* \brief
\author Tien-Thinh NGUYEN
\company Eurecom
\date 2020
\email: tien-thinh.nguyen@eurecom.fr
*/
#ifndef FILE_NRF_JWT_HPP_SEEN
#define FILE_NRF_JWT_HPP_SEEN
namespace oai {
namespace nrf {
namespace app {
class nrf_jwt {
private:
public:
void test_jwt();
};
} // namespace app
} // namespace nrf
} // namespace oai
#endif /* FILE_NRF_JWT_HPP_SEEN */
......@@ -209,7 +209,6 @@ if(GIT_FOUND)
)
endif()
add_definitions("-DPACKAGE_VERSION=\"Branch: ${GIT_BRANCH} Abrev. Hash: ${GIT_COMMIT_HASH} Date: ${GIT_COMMIT_DATE}\"")
add_definitions("-DPACKAGE_BUGREPORT=\"openaircn-user@lists.eurecom.fr\"")
......@@ -233,7 +232,6 @@ include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckTypeSize)
###############################################################################
# Debug and build related options
###############################################################################
......@@ -241,7 +239,6 @@ include(CheckTypeSize)
add_boolean_option( DISPLAY_LICENCE_INFO False "If a module has a licence banner to show")
add_boolean_option( LOG_OAI False "Thread safe logging utility")
# System packages that are required
# We use either the cmake buildin, in ubuntu are in: /usr/share/cmake*/Modules/
# or cmake provide a generic interface to pkg-config that widely used
......@@ -264,13 +261,7 @@ endif(STATIC_LINKING)
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/common ${CMAKE_CURRENT_BINARY_DIR}/common)
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/common/utils ${CMAKE_CURRENT_BINARY_DIR}/utils)
#ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/pfcp ${CMAKE_CURRENT_BINARY_DIR}/pfcp)
#ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/udp ${CMAKE_CURRENT_BINARY_DIR}/udp)
ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/api-server ${CMAKE_CURRENT_BINARY_DIR}/api-server)
#ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/nas ${CMAKE_CURRENT_BINARY_DIR}/nas)
#ENABLE_TESTING()
#ADD_SUBDIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src/test ${CMAKE_CURRENT_BINARY_DIR}/test)
################################################################################
# Specific part for oai_nrf folder
......@@ -280,30 +271,16 @@ include_directories(${SRC_TOP_DIR}/nrf_app)
include_directories(${SRC_TOP_DIR}/oai_nrf)
include_directories(${SRC_TOP_DIR}/common)
include_directories(${SRC_TOP_DIR}/common/utils)
#include_directories(${SRC_TOP_DIR}/common/utils/bstr)
#include_directories(${SRC_TOP_DIR}/pfcp)
#include_directories(${SRC_TOP_DIR}/udp)
include_directories(${SRC_TOP_DIR}/../build/ext/spdlog/include)
include_directories(${SRC_TOP_DIR}/../build/ext/cpp-jwt)
include_directories(${SRC_TOP_DIR}/api-server)
include_directories(${SRC_TOP_DIR}/api-server/api)
include_directories(${SRC_TOP_DIR}/api-server/impl)
include_directories(${SRC_TOP_DIR}/api-server/model)
#include_directories(${SRC_TOP_DIR}/nas)
#include_directories(${SRC_TOP_DIR}/nas/ies)
#include_directories(${SRC_TOP_DIR}/nas/mm)
#include_directories(${SRC_TOP_DIR}/nas/mm/msg)
#include_directories(${SRC_TOP_DIR}/nas/sm)
#include_directories(${SRC_TOP_DIR}/nas/sm/msg)
#include_directories(${SRC_TOP_DIR}/nas/security)
#include_directories(${SRC_TOP_DIR}/ngap)
#include_directories(${SRC_TOP_DIR}/ngap/asn1c)
#include_directories(${SRC_TOP_DIR}/ngap/ies)
add_executable(nrf
${SRC_TOP_DIR}/oai-nrf/main.cpp
${SRC_TOP_DIR}/oai-nrf/options.cpp
# ${SRC_TOP_DIR}/itti/itti.cpp
# ${SRC_TOP_DIR}/itti/itti_msg.cpp
)
IF(STATIC_LINKING)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment