Coder Social home page Coder Social logo

brski's Introduction

GitHub release (latest stable SemVer) Build Passing GitHub license CMake C11

Bootstrapping Remote Secure Key Infrastructure - reference implementation

The Bootstrapping Remote Secure Key Infrastructure (BRSKI) protocol provides a solution for secure zero-touch (automated) bootstrap of new (unconfigured) devices that are called "pledges". Pledges have an Initial Device Identifier (IDevID) installed in them at the factory.

For more information on the BRSKI protocol, please check the RFC8995.

This repo provides a reference implementation for the BRSKI protocol in C language.

Features

  1. Voucher artifact implementation as per RFC8366,
  2. Pledge-Registrar voucher request implementation with CMS signatures,
  3. Registrar-MASA voucher request implementation with CMS signatures,
  4. MASA-Pledge voucher request implementation with CMS signatures and
  5. CMS signatures dependency on OpenSSL or WolfSSL libraries.

Compile & Build

Compiling the BRSKI voucher library is done with CMake.

Dependencies

The BRSKI voucher library requires OpenSSL3. You can either:

  • Install OpenSSL3 yourself (on Ubuntu 22.04 (Jammy) or Debian 12 (Bookworm) or later, you can just run sudo apt install libssl-dev)
  • The BRSKI CMake config file allows also downloading and compiling the OpenSSL library from source. Change the option BUILD_OPENSSL3_LIB to ON in CMakeLists.txt file to force CMake to download and compile the OpenSSL library.

Configure

If you have CMake v3.22+, you can use the following cmake-presets to compile BRSKI voucher libray and demo pledge, registrar, and masa tools:

cmake --list-presets # list all available presets
cmake --preset linux # configure the BRSKI voucher library for Linux
cmake --build --preset linux -j4 # build BRSKI for Linux using 4 threads
ctest --preset linux # test BRSKI for Linux

For older versions of CMake, or for manual configuration, please see the next headings for more details.

Configure cmake in the build/ directory by running the following:

# or for old versions of cmake, do: mkdir build/ && cd build/ && cmake ..
cmake -S . -B build

The configure stage will download some of the BRSKI dependencies, so this may take a while.

Building

To build, you can then run:

# or for old versions of cmake, do: cd build/ && make
cmake --build build/

or to built on multiple core run:

cmake --build build/ -j4

-j4 means 4 jobs/threads, replace 4 with the amount of cores you want to use, equivalent to make -j4.

After succesful compilation the binary will be located in ./build/src folder.

Running

To run the BRSKI binary with the configuration file dev-config.ini located in ./build folder use:

./build/src/brski -c ./build/dev-config.ini command

To enable verbose debug mode use:

./build/src/brski -c ./build/dev-config.ini command -ddddd

where command is one of the commands to execute. For more details see examples.

You can also look at Running with test examples for examples that use pregenerated test certificates.

Installing

To install the library and the BRSKI binary, and config use:

cmake --build --preset linux --target install

To install in a custom folder one needs to set the install prefix before running the above command with:

cmake -DCMAKE_INSTALL_PREFIX:PATH=/custom_folder_path --preset linux

The cmake installs the following artifacts:

  • /../bin/brksi - BRSKI tool
  • /../etc/brski/config.ini - BRSKI tool config file
  • /../lib/libvoucher.a - voucher static library
  • /../include/voucher/array.h - the array helper include file
  • /../include/voucher/voucher.h - the voucher API include file

Testing

To compile the tests use:

cmake -B build/ -S . # configure CMAKE
cmake --build build/ -j4 # or make -j4
cmake --build build/ --target test -j4 # or 'make test'

To run each test individually, the test binaries are located in ./build/preset_name/tests folder.

Running with test examples

Additionally, you can manually setup a MASA and registrar server on localhost using some test certificates.

  1. Run the tests once using ctest --preset linux (or equivalent). This will create some example test certificates using the generate_test_certs test.

  2. Start the MASA server using: ./build/linux/src/brski/brski -c ./build/linux/tests/brski/test-config.ini masa

  3. Start the registrar server using: ./build/linux/src/brski/brski -c ./build/linux/tests/brski/test-config.ini registrar

  4. Send a pledge request to the registrar server using:

    user@pc:~/brski (main)$ ./build/linux/src/brski/brski -c ./build/linux/tests/brski/test-config.ini preq
    Pledge voucher request to 127.0.0.1:12345
    2023-06-13 14:25:17.642  INFO  pledge_request.cpp:68: Request pledge voucher from /.well-known/brski/requestvoucher
    2023-06-13 14:25:17.645  INFO  httplib_wrapper.cpp:245: Post request to 127.0.0.1:12345/.well-known/brski/requestvoucher
    MIIBRjCB7aADAgECAgEBMAoGCCqGSM49BAMCMCExCzAJBgNVBAYTAklFMRIwEAYDVQQDDAlsZGV2aWQtY2EwHhcNMjMwNjEzMTMyNTE3WhcNMjMwNjI3MjAyMTI0WjAqMQswCQYDVQQGEwJJRTEbMBkGA1UEAwwScGlubmVkLWRvbWFpbi1tZXRhMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7BCjjmrshoAmneAJd8/D2iIPCkBbbcGoSX0fcvoxUAjCNIUyC9mhHAe8pAV2MFiJdngshvaXyhpYHm0iC4Qi36MNMAswCQYDVR0TBAIwADAKBggqhkjOPQQDAgNIADBFAiEA1gT++JfiP522ddkCTKtzOyU8MOFa8+u4owvWPK+O2nkCIG/hDl1nFzDWQMIthyXxOUinL7crA9w2ZCW/6pwnhYX2

    If successful, the returned ASN1 pinned-domain-cert in the voucher will be printed in base64 to stdout.

Developer Documentation

  1. Voucher artifact API.
  2. BRSKI voucher request API.
  3. Array helpers API.
  4. Usage examples.

brski's People

Contributors

aloisklink avatar ionut-cmd avatar mereacre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

svieg

brski's Issues

Readme file not reflecting the actual repo structure+impossible to run brski command using the dev-config.ini

Problem

According to the tutorial, I should be supposed to be able to run the brski command with a configuration file with the command:

./build/src/brski -c ./build/dev-config.ini

However there are a couple of issue with this:

  1. The path described in this line are not the same as the ones that actually appears after the building process if using the presets. Specifically, the sturcutre will look as follow:
tree -d ./
./
├── build
│   ├── dl
│   └── linux

There are two additional folders. It is not a big deal, just confusing and a little fix that can make the user experience a little more smooth.

  1. Still on this command ./build/src/brski -c ./build/dev-config.ini, although is changed the paths to the correct one there is a discrepanncy. Specifically the dev-config.ini is not present in the build direcotry:
    image

What I tried to do

Although in the wrong places, I was able to locate the dev-config.ini file in the path …/build/linux/src/brski
Then, from the same brski folder I tried to run the command: brski -c ./dev-config.ini.
This created the following output:

└─$ brski -c ./dev-config.ini 
Command-line usage error: Unrecognized command "(null)"

I even tried from different locations and using the correct path, however I got always the same error.
Is there a reason why this happens? the building and installation process went fine.
Is there anything that I missed during the installation process?

Thanks in advance for your time

Setup

Kali linux with zsh terminal
Same problem even in bash

Replacing `brski` http library with one with better logs/error handling

The brski CLI is extremely difficult to debug if anything goes wrong.

For example, I've encountered errors like:

2023-06-20 01:38:04.961  ERROR httplib_wrapper.cpp:251: httplib::Client fail with "Success"

I've also encountered times where the brski CLI seems to crash, but there are no logs, and brski returns 0 (aka SUCCESS) instead of an error exit code.

It seems like most of these issues are caused by the lack of error handling/logging capabilities in the HTTP library that brski uses: cpp-httplib.

cpp-httplib seems like a simple and easy-to-use library, but it doesn't have good error handling capabilities. In my opinion, we need to replace the http library used by brski to a different library, or even spin up our own HTTP handling.

Potential HTTP library replacements

Server-side

Client-side

Cmocka installation problem while following the presets tutorial

Problem

Unable to complete the installation process following the steps provided with the cmake presets. Most of the problems I had revolved around cmocka.
At first I tried to build the stable 0.20 release. However I was not able to build it.
Then I cloned the repository as per its latest update, and I was able to build. However, I keep stumbling accross cmocka errors when running make --build --preset linux -j4
I followed the steps illustrated form the repo.

Thanks in advance for your time and consideration

LOG

[ 62%] Building C object _deps/cmocka-build/src/CMakeFiles/cmocka.dir/cmocka.c.o

/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c: In function ‘_assert_ptr_equal’:

/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2116:10: error: ‘a’ may be used uninitialized [-Werror=maybe-uninitialized]

 2116 |     if (!ptr_values_equal_display_error(a, b)) {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2111:36: note: accessing argument 1 of a function declared with attribute ‘access (none, 1)’
 2111 | void _assert_ptr_equal(const void *a,
      |                        ~~~~~~~~~~~~^

/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2116:10: error: ‘b’ may be used uninitialized [-Werror=maybe-uninitialized]
 2116 |     if (!ptr_values_equal_display_error(a, b)) {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2112:36: note: accessing argument 2 of a function declared with attribute ‘access (none, 2)’
 2112 |                        const void *b,
      |                        ~~~~~~~~~~~~^
/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c: In function ‘_assert_ptr_not_equal’:
/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2126:10: error: ‘a’ may be used uninitialized [-Werror=maybe-uninitialized]
 2126 |     if (!ptr_values_not_equal_display_error(a, b)) {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2121:40: note: accessing argument 1 of a function declared with attribute ‘access (none, 1)’
 2121 | void _assert_ptr_not_equal(const void *a,
      |                            ~~~~~~~~~~~~^
/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2126:10: error: ‘b’ may be used uninitialized [-Werror=maybe-uninitialized]
 2126 |     if (!ptr_values_not_equal_display_error(a, b)) {
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/marco/Desktop/brski/build/linux/_deps/cmocka-src/src/cmocka.c:2122:40: note: accessing argument 2 of a function declared with attribute ‘access (none, 2)’
 2122 |                            const void *b,
      |                            ~~~~~~~~~~~~^
cc1: some warnings being treated as errors

System

Kali linux distro

Not possible to install also in WSL

Problem

After failing to install on Kali, I decided to do it also to give a try on WSL running Debian.
However, when I try to build this time I cannot let cmake understand that I have openssl3 installed, and that openssl1.1 is not even in my pc.

Log of Cmake

CMake Error at /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR: Found unsuitable version "1.1.1n", but required is at least "3" (found /usr/lib/x86_64-linux-gnu/libcrypto.so, found components: Crypto SSL) Call Stack (most recent call first): /usr/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:598 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.25/Modules/FindOpenSSL.cmake:613 (find_package_handle_standard_args) lib/openssl3.cmake:85 (find_package) CMakeLists.txt:168 (include)

My SSL

openssl version -a OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022) built on: Wed May 17 09:51:47 2023 UTC platform: linux-x86_64 options: bn(64,64) compiler: gcc -fPIC -pthread -m64 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BUILDING_OPENSSL -DZLIB -DNDEBUG OPENSSLDIR: "/usr/local/ssl" ENGINESDIR: "/usr/local/ssl/lib64/engines-3" MODULESDIR: "/usr/local/ssl/lib64/ossl-modules" Seeding source: os-specific CPUINFO: OPENSSL_ia32cap=0xfffab2235f8bffff:0x18405fc6f1bf27ab

Also the libraries are in the correct place:

which openssl /usr/local/ssl/bin/openssl

I have no iedea how to solve this problem, given also by the fact that I am not familiar with cmake.
Thanks in advance for all your support

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.