Commit afb6b3c6 authored by britoj's avatar britoj
Browse files

Initial Commit

parent 62ba1740
Loading
Loading
Loading
Loading

.gitignore

0 → 100755
+232 −0
Original line number Original line Diff line number Diff line
### Extra ###
*/ssl/*.csr
*/ssl/*.key
*/ssl/*.pem
*/ssl/*.srl

### C ###

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf


### C++ ###

# Compiled Object files
*.slo

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai


### Python ###

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
#   For a library or package, you might want to ignore these files since the code is
#   intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

# poetry
#   Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
#   This is especially recommended for binary packages to ensure reproducibility, and is more
#   commonly ignored for libraries.
#   https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
#   Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
#   pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
#   in version control.
#   https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/


### PyCharm ###
.idea/
cmake-build-*/
+36 −0
Original line number Original line Diff line number Diff line
cmake_minimum_required(VERSION 3.10)
project(etsi-gs-qkd-004 VERSION 2.1.1 LANGUAGES C)

set(CMAKE_C_STANDARD 11)

find_package(OpenSSL REQUIRED)
#find_package(PythonLibs REQUIRED)
include_directories(include
#        ${PYTHON_INCLUDE_DIRS}
        ${UUID_INCLUDE_DIRS}
        )

add_compile_definitions(
        QKD_LOG_INFO
#        QKD_LOG_DEBUG
)

add_library(etsi-gs-qkd-004
        src/qkd/copy.c
        src/qkd/interfaces.c
        src/qkd/serializers.c
        src/qkd/sizes.c
        src/qkd/ssl_socket.c
        src/qkd/ssl_socket_client.c
        src/qkd/ssl_socket_server.c
        src/qkd/utils.c
#        src/qkd/wrapper.c
        )
target_link_libraries(etsi-gs-qkd-004 PUBLIC uuid OpenSSL::SSL explain uuid ${PYTHON_LIBRARIES})


add_executable(client_example src/client_example.c)
target_link_libraries(client_example PUBLIC etsi-gs-qkd-004)

add_executable(server_example src/server_example.c)
target_link_libraries(server_example PUBLIC etsi-gs-qkd-004)
+22 −0
Original line number Original line Diff line number Diff line
#ifndef ETSI_GS_QKD_004_COPY_H
#define ETSI_GS_QKD_004_COPY_H

#include "models.h"

#ifdef __cplusplus__
extern "C" {
#endif

void qkd_copy_str(char **dst, char **src);

void qkd_copy_uri(qkd_uri_t *dst, qkd_uri_t *src);

void qkd_copy_mimetype(qkd_mimetype_t *dst, qkd_mimetype_t *src);

void qkd_copy_qos(qkd_qos_t *dst, qkd_qos_t *src);

#ifdef __cplusplus__
}
#endif

#endif //ETSI_GS_QKD_004_COPY_H
+61 −0
Original line number Original line Diff line number Diff line
#ifndef ETSI_GS_QKD_004_INTERFACES_H
#define ETSI_GS_QKD_004_INTERFACES_H

#include "qkd/models.h"

#ifdef __cplusplus__
extern "C" {
#endif

extern const version_t QKD_004_VERSION;

/**
 * @brief This is the OPEN_CONNECT call of the ETSI QKD 004.
 *
 * @param source        (in) the source identifier for the stream.
 * @param destination   (in) the destination identifier for the stream.
 * @param qos           (in/out) Quality of Service parameters, an empty qos marks end of list.
 * @param key_stream_id (in/out) key stream id.
 * @param status (out) status code of this call (see qkd_status_codes enum).
 * @param app_context_data   (in/out) service shared data (non-standard parameter). Used to share data between different processes.
 */
void
qkd_open_connect(qkd_uri_t source, qkd_uri_t destination, qkd_qos_t *qos, uuid_t *key_stream_id,
                 qkd_status_t *status, void *app_context_data);


/**
 * @brief This is the GET_KEY call of the ETSI QKD 004.
 *
 * @param key_stream_id (in) the key stream id, must be retrieved by a previous qkd_open.
 * @param index         (in/out) the index within the key stream id buffer.
 * @param key_buffer    (out) the key material buffer to be filled.
 * @param metadata      (in/out) the qkd_metadata for the key.
 * @param status        (out) status code of this call (see qkd_status_codes enum).
 * @param app_context_data   (in/out) service shared data (non-standard parameter). Used to share data between different processes.
 */
void qkd_get_key(uuid_t key_stream_id, uint32_t *index, qkd_key_buffer_t *key_buffer, qkd_metadata_t *metadata,
                 qkd_status_t *status, void *app_context_data);

/**
 * @brief This is the CLOSE call of the ETSI QKD 004.
 *
 * @param key_stream_id (in) the key stream to close.
 * @param status        (out) status code of this call (see qkd_status_codes enum).
 * @param app_context_data   (in/out) service shared data (non-standard parameter). Used to share data between different processes.
 */
void qkd_close(uuid_t key_stream_id, qkd_status_t *status, void *app_context_data);


qkd_open_connect_response_t qkd_open_connect_struct(qkd_open_connect_request_t open_connect_request,
                                                    void *app_context_data);

qkd_get_key_response_t qkd_get_key_struct(qkd_get_key_request_t get_key_request, void *app_context_data);

qkd_close_response_t qkd_close_struct(qkd_close_request_t close_request, void *app_context_data);

#ifdef __cplusplus__
}
#endif

#endif //ETSI_GS_QKD_004_INTERFACES_H
+138 −0
Original line number Original line Diff line number Diff line
#ifndef ETSI_GS_QKD_004_MODELS_H
#define ETSI_GS_QKD_004_MODELS_H

#include <stdint.h>
#include <uuid/uuid.h>

#ifdef __cplusplus__
extern "C" {
#endif

typedef struct qkd_bytes {
    uint32_t size;
    void *data;
} qkd_bytes_t;

/**
 * @brief ETSI SG QKD 004 status codes.
 */
typedef enum qkd_status_code {
    qkd_status_code_successful = 0,                    /**< @brief Successful. */
    qkd_status_code_peer_not_connected = 1,            /**< @brief Successful connection, but peer not connected. */
    qkd_status_code_gk_insufficient_key_available = 2, /**< @brief GET_KEY failed because insufficient key available. */
    qkd_status_code_gk_peer_not_connected = 3,         /**< @brief GET_KEY failed because peer application is not yet connected. */
    qkd_status_code_no_qkd_connection_available = 4,   /**< @brief No QKD connection available. */
    qkd_status_code_oc_ksid_already_in_use = 5,        /**< @brief OPEN_CONNECT failed because the "KSID" is already in use. */
    qkd_status_code_timeout_error = 6,                 /**< @brief TIMEOUT_ERROR The call failed because the specified TIMEOUT. */
    qkd_status_code_oc_qos_not_satisfiable = 7,        /**< @brief OPEN_CONNECT failed because requested QoS settings could not be met, counter proposal included in returnhas occurred. */
    qkd_status_code_gk_metadata_insufficient_size = 8, /**< @brief GET_KEY failed because metadata field payload_size insufficient. Returned Metadata_size value holds minimum needed payload_size of metadata. */
} qkd_status_code_t;


/**
 * @brief All status codes are 32 bits unsigned integers.
 */
typedef uint32_t qkd_status_t;

/**
 * @brief A qkd_uri is a sized string.
 */
typedef char *qkd_uri_t;

#define MIMETYPE_MAX 256

/**
 * @brief A mimetype is a string with a maximum payload_size of 255 char + '\0'.
 */
typedef char *qkd_mimetype_t;


/**
 * @brief QoS parameters.
 */
typedef struct qkd_qos {
    uint32_t key_chunk_size;
    uint32_t max_bps;
    uint32_t min_bps;
    uint32_t jitter;
    uint32_t priority;
    uint32_t timeout;
    uint32_t ttl;
    qkd_mimetype_t metadata_mimetype;
} qkd_qos_t;


/**
 * @brief The qkd_metadata value buffer.
 */
typedef qkd_bytes_t qkd_metadata_t;


/**
 * @brief   A key buffer.
 */
typedef qkd_bytes_t qkd_key_buffer_t;


typedef struct qkd_open_connect_request {
    qkd_uri_t source;
    qkd_uri_t destination;
    qkd_qos_t qos;
    uuid_t key_stream_id;
} qkd_open_connect_request_t;

typedef struct qkd_open_connect_response {
    qkd_status_t status;
    qkd_qos_t qos;
    uuid_t key_stream_id;
} qkd_open_connect_response_t;

typedef struct qkd_get_key_request {
    uuid_t key_stream_id;
    uint32_t index;
    qkd_metadata_t metadata;
} qkd_get_key_request_t;

typedef struct qkd_get_key_response {
    qkd_status_t status;
    uint32_t index;
    qkd_key_buffer_t key_buffer;
    qkd_metadata_t metadata;
} qkd_get_key_response_t;

typedef struct qkd_close_request {
    uuid_t key_stream_id;
} qkd_close_request_t;

typedef struct qkd_close_response {
    qkd_status_t status;
} qkd_close_response_t;

enum qkd_service {
    QKD_SERVICE_ERROR = 0x00,
    QKD_SERVICE_OPEN_CONNECT_REQUEST = 0b10,
    QKD_SERVICE_OPEN_CONNECT_RESPONSE = 0b11,
    QKD_SERVICE_GET_KEY_REQUEST = 0b100,
    QKD_SERVICE_GET_KEY_RESPONSE = 0b101,
    QKD_SERVICE_CLOSE_REQUEST = 0b1000,
    QKD_SERVICE_CLOSE_RESPONSE = 0b1001,
    QKD_SERVICE_CLOSE_SERVER = 0xFF,
};

typedef struct version {
    uint8_t major;
    uint8_t minor;
    uint8_t micro;
} version_t;

typedef struct qkd_header {
    version_t version;
    uint8_t service;
    uint32_t payload_size;
} qkd_header_t;

#ifdef __cplusplus__
}
#endif

#endif //ETSI_GS_QKD_004_MODELS_H
Loading