Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenVPN TLS Crypt V2 Plugins
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Emily Ehlert
OpenVPN TLS Crypt V2 Plugins
Commits
3f737f54
Commit
3f737f54
authored
2 years ago
by
Emily Ehlert
Browse files
Options
Downloads
Patches
Plain Diff
Update benchmarking tool
parent
4832a7a1
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Benchmark/main.cpp
+146
-25
146 additions, 25 deletions
Benchmark/main.cpp
with
146 additions
and
25 deletions
Benchmark/main.cpp
+
146
−
25
View file @
3f737f54
...
...
@@ -3,6 +3,9 @@
#include
<openssl/evp.h>
#include
<vector>
#include
<chrono>
#include
<cmath>
#include
<csignal>
#include
<fstream>
#include
"openvpn-plugin.h"
...
...
@@ -13,21 +16,37 @@
#define YUBIKEY_PATH "./plugins/libYubikeyKeyManagementLib.so"
#define SOFTHSM_PATH "./plugins/libPKCS11KeyWrappingLibrary.so"
#define SOFTHSM_WKC "
kTkvfenmeqP7LR3uCgR3dZBt/E2XKVwEd8ZpUlpMqwdY0wx1iND6Yv2021y1VODpM0Z8y6gebW6Syf0Ye/EDjKr/Xv/qSos6l/U+mVeU+iizCr9844qx5iDyQI5VAducK9daf7nTdkZmeQVK80CvhtxbOsGUDcmoPQb6mHsbJXwmyoyLsxM2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koo7MiJu0mZ7hpuLo4E8j9ClObvbqYvBDyjuH2S250pANCxykuW/tk+rNcVdTKzNpJtBUvvH3YDAbGOTtcHvK3txeLyy7e3SYzLxBsoOEVMk1FMcXODjiLyTw8Y3eX7DfAk92vcqR6eXv9gDCLZhCGyUOaZh/aBHliOP2Twzb3FUhE5sgA
ASs="
#define SMARTCARD_KEY_DERIVATION_WKC "KW9RjSfhyM6JBgfvs7/SDcFD9eFwO/5FiDOChWE1PZ31pfNhhYl5Iytg7Y6VDGuWNyhYq47koVuXdLSpva5qNSt1uRcqaY1nNbWwBMCgSIjcNJb3+t0FxtbZeYP4w78v18Ad8j3Qf2e3T2NN4VvEebffsihPf0vlvqGaRJvn7W8NXh3Y28/vPb4tXLSalpR5+lZrXHLwn+pl03sH3+nSYIO4Fk+DbSA0aVTKXDulVtNYugMy2P9XqQRtlM1lOuMBqxbyc2FB7oqFvrLTHVZnWqGFimvwasIaktKfkxXT+X1uaoUYzsFNbvs8s/Xul+9NF4YXMZpffMbA5ah5629zG8HW9L1tI9crd5GOKdH5QSThtSZinnSXhmhYCvAzhNdjDQc/oCpIicpeASs="
#define NS_PER_SECOND 1000000000
extern
"C"
{
#include
"base64.h"
}
static
std
::
vector
<
float
>
cipher_duration
;
static
std
::
vector
<
float
>
auth_duration
;
void
vlog_func
(
openvpn_plugin_log_flags_t
flags
,
const
char
*
plugin_name
,
const
char
*
format
,
va_list
arglist
)
{
(
void
)
plugin_name
;
// Ignore notes and debug messages
vprintf
(
format
,
arglist
);
puts
(
""
);
if
(
strcmp
(
format
,
"cipher_duration: %f"
)
==
0
)
{
float
duration
=
va_arg
(
arglist
,
double
);
cipher_duration
.
push_back
(
duration
);
}
else
if
(
strcmp
(
format
,
"auth_duration: %f"
)
==
0
)
{
float
duration
=
va_arg
(
arglist
,
double
);
auth_duration
.
push_back
(
duration
);
}
else
{
vprintf
(
format
,
arglist
);
puts
(
""
);
}
}
void
plugin_secure_memzero
(
void
*
data
,
size_t
len
)
{
...
...
@@ -150,6 +169,8 @@ void Plugin::open_plugin(int num, ...) {
openvpn_plugin_open_v3
(
STRUCT_VERSION
,
&
args_open
,
&
ret_open
);
this
->
handle
=
ret_open
.
handle
;
if
(
!
this
->
handle
)
throw
std
::
invalid_argument
(
""
);
free_stringlist
(
ret_open
.
return_list
);
ret_open
.
return_list
=
nullptr
;
...
...
@@ -241,19 +262,16 @@ Plugin createPlugin(int type) {
plugin
=
new
Plugin
(
SMARTCARD_KEY_WRAPPING_PATH
);
plugin
->
open_plugin
(
0
);
break
;
case
SMARTCARD_KEY_DERIVATION
:
plugin
=
new
Plugin
(
SMARTCARD_KEY_DERIVATION_PATH
);
plugin
->
open_plugin
(
0
,
"/usr/lib/pkcs11/libsofthsm2.so"
);
break
;
case
YUBIKEY
:
plugin
=
new
Plugin
(
YUBIKEY_PATH
);
// Slot: 2; Access_Code: 0
plugin
->
open_plugin
(
2
,
"2"
,
"0"
);
plugin
->
up_plugin
();
plugin
->
open_plugin
(
2
,
"3"
,
"0"
);
if
(
plugin
->
up_plugin
()
!=
OPENVPN_PLUGIN_FUNC_SUCCESS
)
throw
std
::
exception
();
break
;
case
SOFTHSM
:
plugin
=
new
Plugin
(
SOFTHSM_PATH
);
plugin
->
open_plugin
(
2
,
"/
usr/lib
/pkcs11/libs
ofthsm2
.so"
,
"1234"
);
plugin
->
open_plugin
(
2
,
"/
home/triton/Development/sc-hsm-embedded/src
/pkcs11/
.
libs
/libsc-hsm-pkcs11
.so"
,
"1234
56
"
);
break
;
default:
throw
std
::
invalid_argument
(
"Plugin type not implemented!"
);
...
...
@@ -262,28 +280,131 @@ Plugin createPlugin(int type) {
return
*
plugin
;
}
int
main
()
{
Plugin
plugin
=
createPlugin
(
SMARTCARD_KEY_DERIVATION
);
void
sub_timespec
(
struct
timespec
t1
,
struct
timespec
t2
,
struct
timespec
*
td
)
{
td
->
tv_nsec
=
t2
.
tv_nsec
-
t1
.
tv_nsec
;
td
->
tv_sec
=
t2
.
tv_sec
-
t1
.
tv_sec
;
if
(
td
->
tv_sec
>
0
&&
td
->
tv_nsec
<
0
)
{
td
->
tv_nsec
+=
NS_PER_SECOND
;
td
->
tv_sec
--
;
}
else
if
(
td
->
tv_sec
<
0
&&
td
->
tv_nsec
>
0
)
{
td
->
tv_nsec
-=
NS_PER_SECOND
;
td
->
tv_sec
++
;
}
}
float
calculate_standard_deviation
(
const
std
::
vector
<
float
>&
values
)
{
float
sum
=
0
;
for
(
float
e
:
values
)
{
sum
+=
e
;
}
int
iterations
=
10
;
std
::
string
WKc
=
SMARTCARD_KEY_DERIVATION_WKC
;
auto
begin
=
std
::
chrono
::
high_resolution_clock
::
now
();
float
average
=
sum
/
(
float
)
values
.
size
();
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
// Standard Deviation
float
standard_deviation
=
0
;
for
(
float
e
:
values
)
{
standard_deviation
+=
powf
((
e
-
average
),
2.
f
);
}
standard_deviation
=
sqrtf
(
standard_deviation
/
(
float
)
(
values
.
size
()
-
1
));
return
standard_deviation
;
}
int
main
()
{
Plugin
plugin
=
createPlugin
(
YUBIKEY
);
std
::
string
WKc
=
YUBIKEY_WKC
;
timespec
start_c
{},
end_c
{},
diff_c
{};
clock_gettime
(
CLOCK_MONOTONIC
,
&
start_c
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
end_c
);
sub_timespec
(
start_c
,
end_c
,
&
diff_c
);
float
duration_c
=
(
float
)
diff_c
.
tv_sec
*
1000.
+
(
float
)
diff_c
.
tv_nsec
/
1000000.
;
setuid
(
65534
);
setgid
(
65534
);
int
iterations
=
100
;
std
::
vector
<
float
>
duration_lists
;
for
(
int
i
=
0
;
i
<
iterations
;
i
++
)
{
auto
start
=
std
::
chrono
::
steady_clock
::
now
();
plugin
.
execute_plugin
(
OPENVPN_PLUGIN_CLIENT_KEY_WRAPPING
,
2
,
"unwrap"
,
WKc
.
c_str
());
auto
end
=
std
::
chrono
::
steady_clock
::
now
();
float
duration_ms
=
(
static_cast
<
float
>
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
end
-
start
).
count
())
/
1000000
);
duration_lists
.
push_back
(
duration_ms
);
std
::
cout
<<
"
\r
"
<<
i
+
1
<<
" / "
<<
iterations
<<
" completed"
;
fflush
(
stdout
);
sleep
(
1
);
}
std
::
cout
<<
"
\r
"
<<
i
+
1
<<
" / "
<<
iterations
<<
" completed"
;
std
::
cout
.
flush
();
float
sum
=
0
;
for
(
float
e
:
duration_lists
)
{
sum
+=
e
;
}
float
average
=
sum
/
(
float
)
iterations
;
float
standard_deviation
=
calculate_standard_deviation
(
duration_lists
);
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
sum
<<
"ms total, average : "
<<
average
<<
"ms. With std dev of "
<<
standard_deviation
<<
std
::
endl
;
float
cipher_sum
=
0
;
for
(
auto
e
:
cipher_duration
)
{
cipher_sum
+=
e
;
}
float
cipher_mean
=
cipher_sum
/
cipher_duration
.
size
();
float
cipher_deviation
=
calculate_standard_deviation
(
cipher_duration
);
std
::
cout
<<
cipher_sum
<<
"ms cipher total, average : "
<<
cipher_mean
<<
"ms. With std dev of "
<<
cipher_deviation
<<
std
::
endl
;
float
auth_sum
=
0
;
for
(
auto
e
:
auth_duration
)
{
auth_sum
+=
e
;
}
float
auth_mean
=
auth_sum
/
auth_duration
.
size
();
float
auth_deviation
=
calculate_standard_deviation
(
auth_duration
);
std
::
cout
<<
auth_sum
<<
"ms auth total, average : "
<<
auth_mean
<<
"ms. With std dev of "
<<
auth_deviation
<<
std
::
endl
;
std
::
ofstream
results_file
(
"results.csv"
);
results_file
<<
"cipher, auth, total"
<<
std
::
endl
;
auto
cipher_iter
=
cipher_duration
.
cbegin
();
auto
auth_iter
=
auth_duration
.
cbegin
();
auto
total_iter
=
duration_lists
.
cbegin
();
while
(
cipher_iter
!=
cipher_duration
.
end
()
||
auth_iter
!=
auth_duration
.
end
()
||
total_iter
!=
duration_lists
.
end
())
{
if
(
cipher_iter
!=
cipher_duration
.
end
())
{
results_file
<<
*
cipher_iter
;
cipher_iter
++
;
}
results_file
<<
","
;
if
(
auth_iter
!=
auth_duration
.
end
())
{
results_file
<<
*
auth_iter
;
auth_iter
++
;
}
results_file
<<
","
;
if
(
total_iter
!=
duration_lists
.
end
())
{
results_file
<<
*
total_iter
;
total_iter
++
;
}
results_file
<<
std
::
endl
;
}
results_file
.
close
();
auto
end
=
std
::
chrono
::
high_resolution_clock
::
now
();
float
duration
=
(
static_cast
<
float
>
(
std
::
chrono
::
duration_cast
<
std
::
chrono
::
nanoseconds
>
(
end
-
begin
).
count
())
/
1000000
);
std
::
cout
<<
duration
<<
"ms total, average : "
<<
duration
/
iterations
<<
"ms."
<<
std
::
endl
;
std
::
string
result
=
plugin
.
execute_plugin
(
OPENVPN_PLUGIN_CLIENT_KEY_WRAPPING
,
2
,
"unwrap"
,
WKc
.
c_str
());
//
std::string result = plugin.execute_plugin(OPENVPN_PLUGIN_CLIENT_KEY_WRAPPING, 2, "unwrap", WKc.c_str());
/*
if(result != "1298789D57618EC2FEF4936C6DD96CB56BCDF804816E02286F14B4156D13BED63279101A4FFAEE654A3FE6F990428061A1F9DE83ABB1B1347B865BC3A68A4ED57446BC0B6206B45640C50A3CA776DA195FD38126A471EBE296E1F77BB4581EA605DA37EDF4946843B7ABAD840A08EB1F3C53F818D6C4D1664CF7A14412ED79D329ED22B66D7771350397B4EE8B6D9D94E666809D8B8C5E7ACF1E536D78DC07ABA147E73FDA4F0E527FD87B8B28CF425047B128890975F156EC48237D8D4BCEA8EA361573BC187B61984764344AA5C778972E249F8AA08097C0FCE9DB0C69C1A36A01BF71C73E3425B9B66F241990A423DCFF9642CD97E11D4B90A2E7CF0732BF010000000063920AA4")
throw std::exception();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment