credman.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
29 #include <unistd.h>
30 #include <stdint.h>
31 #include "modules.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
45 #ifndef CONFIG_CREDMAN_MAX_CREDENTIALS
46 #define CONFIG_CREDMAN_MAX_CREDENTIALS (2)
47 #endif
48 
52 #ifndef CONFIG_CREDMAN_MAX_ASN1_OBJ
53 #define CONFIG_CREDMAN_MAX_ASN1_OBJ (8)
54 #endif
60 typedef struct {
61  const void *s;
62  size_t len;
64 
68 typedef struct {
72 } psk_params_t;
73 
77 typedef struct {
78  const void *x;
79  const void *y;
81 
85 typedef struct {
86  const void *private_key;
91 
95 typedef uint16_t credman_tag_t;
96 
100 #define CREDMAN_TAG_EMPTY (0)
101 
105 typedef enum {
115 
119 typedef struct {
122  union {
125  } params;
127 
131 enum {
139 };
140 
160 int credman_add(const credman_credential_t *credential);
161 
174  credman_type_t type);
175 
185 
194 
195 #if IS_USED(MODULE_CREDMAN_LOAD) || DOXYGEN
216 int credman_load_public_key(const void *buf, size_t buf_len, ecdsa_public_key_t *out);
217 
240 int credman_load_private_key(const void *buf, size_t buf_len, credman_credential_t *cred);
241 
262 int credman_load_private_ecc_key(const void *buf, size_t buf_len, credman_credential_t *cred);
263 #endif /* MODULE_CREDMAN_LOAD || DOXYGEN */
264 
265 #ifdef TEST_SUITES
269 void credman_reset(void);
270 #endif /*TEST_SUITES */
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 
int credman_load_public_key(const void *buf, size_t buf_len, ecdsa_public_key_t *out)
Load a public key from a buffer, as a SubjectPublicKeyInfo sequence, according to RFC5280.
void credman_delete(credman_tag_t tag, credman_type_t type)
Delete a credential from the credential pool.
int credman_get_used_count(void)
Gets the number of credentials currently in the credential pool.
int credman_add(const credman_credential_t *credential)
Adds a credential to the credential pool.
int credman_load_private_key(const void *buf, size_t buf_len, credman_credential_t *cred)
Load a private key from a buffer, as a OneAsymmetricKey sequence, according to RFC5958.
int credman_load_private_ecc_key(const void *buf, size_t buf_len, credman_credential_t *cred)
Load an ECC private key from a buffer, as an ECPrivateKey sequence, according to RFC5915.
uint16_t credman_tag_t
Tag of the credential.
Definition: credman.h:95
credman_type_t
Credential types.
Definition: credman.h:105
int credman_get(credman_credential_t *credential, credman_tag_t tag, credman_type_t type)
Gets a credential from credential pool.
void credman_reset(void)
Empties the credential pool.
@ CREDMAN_TYPE_EMPTY
Empty type.
Definition: credman.h:111
@ CREDMAN_TYPE_ECDSA
ECDSA credential type.
Definition: credman.h:113
@ CREDMAN_TYPE_PSK
PSK credential type.
Definition: credman.h:112
@ CREDMAN_EXIST
Credential already exist in system pool.
Definition: credman.h:133
@ CREDMAN_NOT_FOUND
Credential not found in the system pool.
Definition: credman.h:135
@ CREDMAN_ERROR
Other errors.
Definition: credman.h:138
@ CREDMAN_INVALID
Invalid input parameter(s)
Definition: credman.h:136
@ CREDMAN_OK
No error.
Definition: credman.h:132
@ CREDMAN_NO_SPACE
No space in system pool for new credential.
Definition: credman.h:134
@ CREDMAN_TYPE_UNKNOWN
Unknown credential type.
Definition: credman.h:137
Common macros and compiler attributes/pragmas configuration.
Buffer of the credential.
Definition: credman.h:60
size_t len
Length of credman_buffer_t::s.
Definition: credman.h:62
const void * s
Pointer to the buffer.
Definition: credman.h:61
Credential information.
Definition: credman.h:119
psk_params_t psk
PSK credential parameters.
Definition: credman.h:123
credman_type_t type
Type of the credential.
Definition: credman.h:120
ecdsa_params_t ecdsa
ECDSA credential parameters.
Definition: credman.h:124
credman_tag_t tag
Tag of the credential.
Definition: credman.h:121
ECDSA parameters.
Definition: credman.h:85
const void * private_key
Pointer to the private key.
Definition: credman.h:86
size_t client_keys_size
Size of ecdsa_params_t::clients_keys.
Definition: credman.h:89
ecdsa_public_key_t public_key
Public key.
Definition: credman.h:87
ecdsa_public_key_t * client_keys
Array of clients public keys.
Definition: credman.h:88
ECDSA public keys.
Definition: credman.h:77
const void * x
X part of the public key.
Definition: credman.h:78
const void * y
Y part of the public key.
Definition: credman.h:79
PSK parameters.
Definition: credman.h:68
credman_buffer_t hint
Hint buffer.
Definition: credman.h:71
credman_buffer_t key
Key buffer.
Definition: credman.h:69
credman_buffer_t id
ID buffer.
Definition: credman.h:70