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

Aerobridge Guardian (trusted flight module) : JWT verification for flights / vehicle arming #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
[submodule "modules/CrashDebug"]
path = modules/CrashDebug
url = https://github.com/adamgreen/CrashDebug
[submodule "modules/libguardian"]
path = modules/libguardian
url = https://github.com/Thalhammer/jwt-cpp.git
27 changes: 27 additions & 0 deletions ArduCopter/AP_Arming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ void AP_Arming_Copter::update(void)
display_fail = true;
pre_arm_display_counter = 0;
}
//a sample verification token
std::string rsa_pub_key = R"(-----BEGIN PUBLIC KEY-----

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not have even test tokens in committed changes. Should move this out to an env file how Kapil did for QGC

MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuGbXWiK3dQTyCbX5xdE4
yCuYp0AF2d15Qq1JSXT/lx8CEcXb9RbDddl8jGDv+spi5qPa8qEHiK7FwV2KpRE9
83wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVs
WXI9C+yjHztqyL2h8P6mlThPY9E9ue2fCqdgixfTFIF9Dm4SLHbphUS2iw7w1JgT
69s7of9+I9l5lsJ9cozf1rxrXX4V1u/SotUuNB3Fp8oB4C1fLBEhSlMcUJirz1E8
AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
YwIDAQAB
-----END PUBLIC KEY-----)";

std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-"
"IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
"uc2z5c05CCXqVSpfCjWbh9gQ";

auto verify =
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", "")).with_issuer("auth0");

auto decoded = jwt::decode(token);

verify.verify(decoded);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does verify failure block arming? Doesn't look like it. This just seems like a call to verify and an unused retval.


pre_arm_checks(display_fail);
}
Expand Down
6 changes: 6 additions & 0 deletions ArduCopter/AP_Arming.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#pragma once

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC disgnostic pop

#include <AP_Arming/AP_Arming.h>
#include <jwt-cpp/jwt.h>

class AP_Arming_Copter : public AP_Arming
{
Expand Down
11 changes: 10 additions & 1 deletion Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,17 @@ def configure_env(self, cfg, env):
cfg.srcnode.find_dir('modules/uavcan/libuavcan/include').abspath()
]

env.INCLUDES += [
cfg.srcnode.find_dir('modules/libguardian/include/').abspath()
]
env.CXXFLAGS += [
'-fexceptions'
]
if cfg.options.build_dates:
env.build_dates = True

# We always want to use PRI format macros
cfg.define('__STDC_FORMAT_MACROS', 1)
cfg.define('__STDC_FORMAT_MACROS_', 1)

if cfg.options.disable_ekf2:
env.CXXFLAGS += ['-DHAL_NAVEKF2_AVAILABLE=0']
Expand Down Expand Up @@ -548,6 +554,9 @@ def configure_env(self, cfg, env):

env.LIB += [
'm',
'ssl',
'crypto',
'dl'
]

cfg.check_librt(env)
Expand Down
2 changes: 1 addition & 1 deletion libraries/SITL/picojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extern "C" {

// experimental support for int64_t (see README.mkdn for detail)
#ifdef PICOJSON_USE_INT64
#define __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS_
#include <cerrno>
#if __cplusplus >= 201103L
#include <cinttypes>
Expand Down
1 change: 1 addition & 0 deletions modules/libguardian
Submodule libguardian added at 5c9787