-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlibflute.patch
More file actions
55 lines (48 loc) · 1.87 KB
/
Copy pathlibflute.patch
File metadata and controls
55 lines (48 loc) · 1.87 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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e94b64..ea6fcaf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,7 @@ find_package(PkgConfig REQUIRED)
find_package(OpenSSL REQUIRED)
pkg_check_modules(TINYXML REQUIRED IMPORTED_TARGET tinyxml2)
pkg_check_modules(NETLINK REQUIRED IMPORTED_TARGET libnl-3.0)
+pkg_check_modules(LIBCONFIG REQUIRED IMPORTED_TARGET libconfig++)
add_subdirectory(examples)
diff --git a/src/IpSec.cpp b/src/IpSec.cpp
index de500ab..83361a8 100644
--- a/src/IpSec.cpp
+++ b/src/IpSec.cpp
@@ -94,10 +94,6 @@ namespace LibFlute::IpSec {
xsinfo.family = AF_INET;
xsinfo.mode = XFRM_MODE_TRANSPORT;
- struct {
- struct xfrm_algo xa;
- char buf[512];
- } algo = {};
std::vector<char> binary_key;
for (unsigned int i = 0; i < key.length(); i += 2) {
@@ -106,18 +102,23 @@ namespace LibFlute::IpSec {
if (binary_key.size() > 512) {
throw "Key is too long";
}
- strcpy(algo.xa.alg_name, "aes");
- algo.xa.alg_key_len = binary_key.size() * 8;
- memcpy(algo.buf, &binary_key[0], binary_key.size());
+ size_t algo_size = sizeof(struct xfrm_algo) + binary_key.size();
+ void *algo_mem = std::malloc(algo_size);
+ struct xfrm_algo *algo = new(algo_mem) struct xfrm_algo;
+
+ strcpy(algo->alg_name, "aes");
+ algo->alg_key_len = binary_key.size() * 8;
+ memcpy(algo->alg_key, &binary_key[0], binary_key.size());
msg = nlmsg_alloc_simple(XFRM_MSG_NEWSA, 0);
nlmsg_append(msg, &xsinfo, sizeof(xsinfo), NLMSG_ALIGNTO);
- nla_put(msg, XFRMA_ALG_CRYPT, sizeof(algo), &algo);
+ nla_put(msg, XFRMA_ALG_CRYPT, algo_size, algo);
sk = nl_socket_alloc();
nl_connect(sk, NETLINK_XFRM);
nl_send_auto(sk, msg);
nlmsg_free(msg);
+ std::free(algo);
}
void enable_esp(uint32_t spi, const std::string& dest_address, Direction direction, const std::string& key)