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 
27 #ifndef NET_CREDMAN_H
28 #define NET_CREDMAN_H
29 
30 #include <unistd.h>
31 #include <stdint.h>
32 #include "modules.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
46 #ifndef CONFIG_CREDMAN_MAX_CREDENTIALS
47 #define CONFIG_CREDMAN_MAX_CREDENTIALS (2)
48 #endif
49 
53 #ifndef CONFIG_CREDMAN_MAX_ASN1_OBJ
54 #define CONFIG_CREDMAN_MAX_ASN1_OBJ (8)
55 #endif
61 typedef struct {
62  const void *s;
63  size_t len;
65 
69 typedef struct {
73 } psk_params_t;
74 
78 typedef struct {
79  const void *x;
80  const void *y;
82 
86 typedef struct {
87  const void *private_key;
92 
96 typedef uint16_t credman_tag_t;
97 
101 #define CREDMAN_TAG_EMPTY (0)
102 
106 typedef enum {
116 
120 typedef struct {
123  union {
126  } params;
128 
132 enum {
140 };
141 
161 int credman_add(const credman_credential_t *credential);
162 
175  credman_type_t type);
176 
186 
195 
196 #if IS_USED(MODULE_CREDMAN_LOAD) || DOXYGEN
217 int credman_load_public_key(const void *buf, size_t buf_len, ecdsa_public_key_t *out);
218 
241 int credman_load_private_key(const void *buf, size_t buf_len, credman_credential_t *cred);
242 
263 int credman_load_private_ecc_key(const void *buf, size_t buf_len, credman_credential_t *cred);
264 #endif /* MODULE_CREDMAN_LOAD || DOXYGEN */
265 
266 #ifdef TEST_SUITES
270 void credman_reset(void);
271 #endif /*TEST_SUITES */
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 
277 #endif /* NET_CREDMAN_H */
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:96
credman_type_t
Credential types.
Definition: credman.h:106
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:112
@ CREDMAN_TYPE_ECDSA
ECDSA credential type.
Definition: credman.h:114
@ CREDMAN_TYPE_PSK
PSK credential type.
Definition: credman.h:113
@ CREDMAN_EXIST
Credential already exist in system pool.
Definition: credman.h:134
@ CREDMAN_NOT_FOUND
Credential not found in the system pool.
Definition: credman.h:136
@ CREDMAN_ERROR
Other errors.
Definition: credman.h:139
@ CREDMAN_INVALID
Invalid input parameter(s)
Definition: credman.h:137
@ CREDMAN_OK
No error.
Definition: credman.h:133
@ CREDMAN_NO_SPACE
No space in system pool for new credential.
Definition: credman.h:135
@ CREDMAN_TYPE_UNKNOWN
Unknown credential type.
Definition: credman.h:138
Common macros and compiler attributes/pragmas configuration.
Buffer of the credential.
Definition: credman.h:61
size_t len
Length of credman_buffer_t::s.
Definition: credman.h:63
const void * s
Pointer to the buffer.
Definition: credman.h:62
Credential information.
Definition: credman.h:120
psk_params_t psk
PSK credential parameters.
Definition: credman.h:124
credman_type_t type
Type of the credential.
Definition: credman.h:121
ecdsa_params_t ecdsa
ECDSA credential parameters.
Definition: credman.h:125
credman_tag_t tag
Tag of the credential.
Definition: credman.h:122
ECDSA parameters.
Definition: credman.h:86
const void * private_key
Pointer to the private key.
Definition: credman.h:87
size_t client_keys_size
Size of ecdsa_params_t::clients_keys.
Definition: credman.h:90
ecdsa_public_key_t public_key
Public key.
Definition: credman.h:88
ecdsa_public_key_t * client_keys
Array of clients public keys.
Definition: credman.h:89
ECDSA public keys.
Definition: credman.h:78
const void * x
X part of the public key.
Definition: credman.h:79
const void * y
Y part of the public key.
Definition: credman.h:80
PSK parameters.
Definition: credman.h:69
credman_buffer_t hint
Hint buffer.
Definition: credman.h:72
credman_buffer_t key
Key buffer.
Definition: credman.h:70
credman_buffer_t id
ID buffer.
Definition: credman.h:71