Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
import_authkey.c File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <yubihsm.h>
Include dependency graph for import_authkey.c:

Go to the source code of this file.

Macros

#define DEFAULT_CONNECTOR_URL   "http://127.0.0.1:12345"
 

Functions

int main (void)
 

Variables

const char * key_label = "label"
 
const uint8_t password1 [] = "password"
 
const uint8_t password2 [] = "letmein!"
 

Macro Definition Documentation

◆ DEFAULT_CONNECTOR_URL

#define DEFAULT_CONNECTOR_URL   "http://127.0.0.1:12345"

Definition at line 30 of file import_authkey.c.

Function Documentation

◆ main()

int main ( void )

Definition at line 37 of file import_authkey.c.

37 {
38 yh_connector *connector = NULL;
39 yh_session *session = NULL;
41
42 uint16_t authkey = 1;
43
44 const char *connector_url;
45
46 connector_url = getenv("DEFAULT_CONNECTOR_URL");
47 if (connector_url == NULL) {
48 connector_url = DEFAULT_CONNECTOR_URL;
49 }
50
51 yrc = yh_init();
52 assert(yrc == YHR_SUCCESS);
53
54 yrc = yh_init_connector(connector_url, &connector);
55 assert(yrc == YHR_SUCCESS);
56
57 yrc = yh_connect(connector, 0);
58 assert(yrc == YHR_SUCCESS);
59
60 yrc = yh_create_session_derived(connector, authkey, password1,
61 sizeof(password1), false, &session);
62 assert(yrc == YHR_SUCCESS);
63
65 assert(yrc == YHR_SUCCESS);
66
67 uint8_t session_id;
68 yrc = yh_get_session_id(session, &session_id);
69 assert(yrc == YHR_SUCCESS);
70
71 printf("Successfully established session %02d using Authentication Keys "
72 "%04x\n",
73 session_id, authkey);
74
76 yrc = yh_string_to_capabilities("get-log-entries", &capabilities);
77 assert(yrc == YHR_SUCCESS);
78
79 uint16_t domain_five = 0;
80 yrc = yh_string_to_domains("5", &domain_five);
81 assert(yrc == YHR_SUCCESS);
82
83 uint16_t key_id = 0; // ID 0 lets the device generate an ID
85 domain_five, &capabilities,
87 sizeof(password2));
88 assert(yrc == YHR_SUCCESS);
89
90 printf("Imported Authentication Key with ID %04x\n", key_id);
91
93 assert(yrc == YHR_SUCCESS);
94
96 assert(yrc == YHR_SUCCESS);
97
98 printf("Closed session %02d\n", session_id);
99
101 sizeof(password2), false, &session);
102 assert(yrc == YHR_SUCCESS);
103
105 assert(yrc == YHR_SUCCESS);
106
107 yrc = yh_get_session_id(session, &session_id);
108 assert(yrc == YHR_SUCCESS);
109
110 printf("Successfully established session %02d using Authentication Key "
111 "%04x\n",
112 session_id, key_id);
113
114 printf("Trying to get 16 bytes of random data\n");
115
116 uint8_t data[16];
117 size_t data_len = sizeof(data);
118 yrc = yh_util_get_pseudo_random(session, 16, data, &data_len);
120
121 printf("Unable to get random data: %s\n", yh_strerror(yrc));
122
124 assert(yrc == YHR_SUCCESS);
125
127 assert(yrc == YHR_SUCCESS);
128
129 yh_disconnect(connector);
130 assert(yrc == YHR_SUCCESS);
131
132 yrc = yh_exit();
133 assert(yrc == YHR_SUCCESS);
134
135 return 0;
136}
CK_SESSION_HANDLE session
const uint8_t password2[]
#define DEFAULT_CONNECTOR_URL
const uint8_t password1[]
const char * key_label
const char * yh_strerror(yh_rc err)
Definition error.c:65
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
unsigned short uint16_t
Definition stdint.h:125
unsigned char uint8_t
Definition stdint.h:124
Capabilities representation.
Definition yubihsm.h:162
yh_rc yh_destroy_session(yh_session **session)
Definition yubihsm.c:890
yh_rc yh_exit(void)
Definition yubihsm.c:3910
yh_rc yh_create_session_derived(yh_connector *connector, uint16_t authkey_id, const uint8_t *password, size_t password_len, bool recreate, yh_session **session)
Definition yubihsm.c:593
yh_rc yh_init(void)
Definition yubihsm.c:3857
yh_rc yh_util_close_session(yh_session *session)
Definition yubihsm.c:1257
yh_rc yh_authenticate_session(yh_session *session)
Definition yubihsm.c:2927
yh_rc yh_util_import_authentication_key_derived(yh_session *session, uint16_t *key_id, const char *label, uint16_t domains, const yh_capabilities *capabilities, const yh_capabilities *delegated_capabilities, const uint8_t *password, size_t password_len)
Definition yubihsm.c:3064
yh_rc yh_string_to_domains(const char *domains, uint16_t *result)
Definition yubihsm.c:4535
yh_rc yh_init_connector(const char *url, yh_connector **connector)
Definition yubihsm.c:4024
yh_rc yh_connect(yh_connector *connector, int timeout)
Definition yubihsm.c:4079
yh_rc yh_string_to_capabilities(const char *capability, yh_capabilities *result)
Definition yubihsm.c:4115
yh_rc yh_disconnect(yh_connector *connector)
Definition yubihsm.c:4097
yh_rc yh_get_session_id(yh_session *session, uint8_t *sid)
Definition yubihsm.c:2915
yh_rc yh_util_get_pseudo_random(yh_session *session, size_t len, uint8_t *out, size_t *out_len)
Definition yubihsm.c:1560
yh_rc
Definition yubihsm.h:170
@ YHR_DEVICE_INSUFFICIENT_PERMISSIONS
Return value when the permissions to perform the operation are wrong.
Definition yubihsm.h:214
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
Definition yubihsm.h:228
@ YHR_SUCCESS
Returned value when function was successful.
Definition yubihsm.h:172
yh_capabilities capabilities
yh_rc yrc
uint16_t key_id
Here is the call graph for this function:

Variable Documentation

◆ key_label

const char* key_label = "label"

Definition at line 33 of file import_authkey.c.

◆ password1

const uint8_t password1[] = "password"

Definition at line 34 of file import_authkey.c.

◆ password2

const uint8_t password2[] = "letmein!"

Definition at line 35 of file import_authkey.c.