-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqseed.cc
More file actions
76 lines (64 loc) · 2.19 KB
/
qseed.cc
File metadata and controls
76 lines (64 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "inc/pkcs11.h"
#include "eaas.h"
#include <dlfcn.h>
#include <iostream>
int main() {
// Load the PKCS#11 library dynamically
void* pkcs11Lib = dlopen(SOFTHSM2_LIBRARY_PATH, RTLD_NOW);
if (!pkcs11Lib) {
std::cerr << "Error loading PKCS#11 library: " << dlerror() << std::endl;
return 1;
}
// Get a pointer to the PKCS#11 function list
CK_FUNCTION_LIST_PTR pFunctionList;
CK_RV (*C_GetFunctionList)(CK_FUNCTION_LIST_PTR_PTR) =
(CK_RV(*)(CK_FUNCTION_LIST_PTR_PTR))dlsym(pkcs11Lib, "C_GetFunctionList");
if (!C_GetFunctionList) {
std::cerr << "Error getting function pointer: " << dlerror() << std::endl;
dlclose(pkcs11Lib);
return 1;
}
CK_RV rv = C_GetFunctionList(&pFunctionList);
if (rv != CKR_OK) {
std::cerr << "Error getting function list: " << rv << std::endl;
dlclose(pkcs11Lib);
return 1;
}
// Initialize the library
rv = pFunctionList->C_Initialize(NULL);
if (rv != CKR_OK) {
std::cerr << "Error initializing PKCS#11 library: " << rv << std::endl;
dlclose(pkcs11Lib);
return 1;
}
// Open a session
CK_SESSION_HANDLE hSession;
rv = pFunctionList->C_OpenSession(0, CKF_SERIAL_SESSION, NULL, NULL, &hSession);
if (rv != CKR_OK) {
std::cerr << "Error opening session: " << rv << std::endl;
dlclose(pkcs11Lib);
return 1;
}
// Get random from Qrypt
std::string token = "abcdefg";
EaaS eaasClient("");
std::string response = eaasClient.requestEntropy(1);
// Seed random number generator
CK_BYTE seedData[] = {0x01, 0x02, 0x03, 0x04}; // Replace with your seed data
rv = pFunctionList->C_SeedRandom(hSession, seedData, sizeof(seedData));
if (rv != CKR_OK) {
std::cerr << "Error seeding random number generator: " << rv << std::endl;
dlclose(pkcs11Lib);
return 1;
}
// Finalize the library
rv = pFunctionList->C_Finalize(NULL);
if (rv != CKR_OK) {
std::cerr << "Error finalizing PKCS#11 library: " << rv << std::endl;
dlclose(pkcs11Lib);
return 1;
}
// Close the library
dlclose(pkcs11Lib);
return 0;
}