-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.c
74 lines (64 loc) · 1.81 KB
/
driver.c
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
#include <openssl/conf.h>
#include <openssl/pem.h>
#include <openssl/x509_vfy.h>
#ifndef FROMAGER_NATIVE
# include <fromager.h>
#else
# include <stdio.h>
# include <stdint.h>
static void __cc_trace_exec(const char* s,
uintptr_t arg0, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3) {
fprintf(stderr, "[FUNC] %s(%lx, %lx, %lx, %lx)\n", s, arg0, arg1, arg2, arg3);
}
static void __cc_trace(const char* s) {
fprintf(stderr, "TRACESTR %s\n", s);
}
#endif
extern const uint8_t secret_certificate[512];
extern const size_t secret_certificate_len;
int main() {
int ret;
// Disable automatic config file loading
OPENSSL_no_config();
// Load certificate from a buffer:
const unsigned char* buf_ptr = secret_certificate;
X509* cert = d2i_X509(NULL, &buf_ptr, secret_certificate_len);
if (!cert) {
return 1;
}
X509_VERIFY_PARAM* param = X509_VERIFY_PARAM_new();
if (!param) {
return 2;
}
// Skip expiration time check to avoid unsupported syscalls
ret = X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_NO_CHECK_TIME);
if (!ret) {
return 3;
}
X509_STORE* store = X509_STORE_new();
if (!store) {
return 4;
}
ret = X509_STORE_set1_param(store, param);
if (!ret) {
return 5;
}
X509_STORE_CTX* ctx = X509_STORE_CTX_new();
if (!ctx) {
return 6;
}
ret = X509_STORE_CTX_init(ctx, store, cert, NULL);
if (!ret) {
return 7;
}
ret = X509_verify_cert(ctx);
if (!ret) {
//int err = X509_STORE_CTX_get_error(ctx);
//int depth = X509_STORE_CTX_get_error_depth(ctx);
//__cc_trace_exec("verify_cert error", err, depth, 0, 0);
//const char* err_str = X509_verify_cert_error_string(err);
//__cc_trace(err_str);
return 8;
}
return 0;
}