Mir

Merge lp:~mir-team/mir/160-bit-finally into lp:~mir-team/mir/public-cookie-api

Proposed by Brandon Schaefer
Status: Superseded
Proposed branch: lp:~mir-team/mir/160-bit-finally
Merge into: lp:~mir-team/mir/public-cookie-api
Diff against target: 136 lines (+18/-14)
5 files modified
debian/control (+1/-0)
src/cookie/CMakeLists.txt (+3/-0)
src/cookie/authority.cpp (+13/-12)
src/include/cookie/mir/cookie/blob.h (+1/-1)
src/server/input/default_event_builder.cpp (+0/-1)
To merge this branch: bzr merge lp:~mir-team/mir/160-bit-finally
Reviewer Review Type Date Requested Status
Mir development team Pending
Review via email: mp+283742@code.launchpad.net

This proposal has been superseded by a proposal from 2016-01-24.

Commit message

Use libsodium to do a const memcmp on the 160bits.

Use 160 bits vs 64bits.

Depends on libsodium now!

Description of the change

Use libsodium to do a const memcmp on the 160bits.

Use 160 bits vs 64bits.

Depends on libsodium now!

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-01-22 06:01:36 +0000
3+++ debian/control 2016-01-24 17:35:31 +0000
4@@ -45,6 +45,7 @@
5 python3:any,
6 dh-python,
7 nettle-dev,
8+ libsodium-dev,
9 Standards-Version: 3.9.4
10 Homepage: https://launchpad.net/mir
11 # If you aren't a member of ~mir-team but need to upload packaging changes,
12
13=== modified file 'src/cookie/CMakeLists.txt'
14--- src/cookie/CMakeLists.txt 2016-01-22 06:01:36 +0000
15+++ src/cookie/CMakeLists.txt 2016-01-24 17:35:31 +0000
16@@ -1,4 +1,5 @@
17 pkg_check_modules(NETTLE REQUIRED nettle)
18+pkg_check_modules(SODIUM REQUIRED libsodium)
19
20 set(PREFIX "${CMAKE_INSTALL_PREFIX}")
21 set(EXEC_PREFIX "${CMAKE_INSTALL_PREFIX}")
22@@ -15,6 +16,7 @@
23 ${PROJECT_SOURCE_DIR}/src/include/cookie
24 ${PROJECT_SOURCE_DIR}/include/cookie
25 ${NETTLE_INCLUDE_DIRS}
26+ ${SODIUM_INCLUDE_DIRS}
27 )
28
29 set(MIRCOOKIE_ABI 2)
30@@ -35,6 +37,7 @@
31
32 target_link_libraries(mircookie
33 ${NETTLE_LDFLAGS} ${NETTLE_LIBS}
34+ ${SODIUM_LDFLAGS} ${SODIUM_LIBS}
35 )
36
37 install(
38
39=== modified file 'src/cookie/authority.cpp'
40--- src/cookie/authority.cpp 2016-01-23 02:39:31 +0000
41+++ src/cookie/authority.cpp 2016-01-24 17:35:31 +0000
42@@ -28,6 +28,8 @@
43 #include <system_error>
44
45 #include <nettle/hmac.h>
46+#include <sodium/utils.h>
47+
48 #include <linux/random.h>
49 #include <sys/types.h>
50 #include <sys/stat.h>
51@@ -41,7 +43,8 @@
52 {
53 std::string const random_device_path{"/dev/random"};
54 std::string const urandom_device_path{"/dev/urandom"};
55-int const wait_seconds{30};
56+uint32_t const wait_seconds{30};
57+uint32_t const mac_byte_size{20};
58
59 size_t cookie_size_from_format(mir::cookie::Format const& format)
60 {
61@@ -141,9 +144,9 @@
62 {
63 /*
64 SHA_1 Format:
65- 1 byte = FORMAT
66- 8 btyes = TIMESTAMP
67- 8 BYTES = MAC
68+ 1 byte = FORMAT
69+ 8 bytes = TIMESTAMP
70+ 20 bytes = MAC
71 */
72
73 if (raw_cookie.size() != cookie_size_from_format(mir::cookie::Format::hmac_sha_1_8))
74@@ -162,11 +165,10 @@
75 auto ptr = raw_cookie.data();
76 ptr++;
77
78- memcpy(&timestamp, ptr, 8);
79+ memcpy(&timestamp, ptr, sizeof(uint64_t));
80 ptr += sizeof(timestamp);
81
82- // FIXME Soon to be 20 bytes
83- std::vector<uint8_t> mac(8);
84+ std::vector<uint8_t> mac(mac_byte_size);
85 memcpy(mac.data(), ptr, mac.size());
86
87 std::unique_ptr<mir::cookie::Cookie> cookie =
88@@ -183,10 +185,9 @@
89 private:
90 std::vector<uint8_t> calculate_cookie(uint64_t const& timestamp)
91 {
92- // FIXME Soon to change to 160bits, for now uint64_t
93- std::vector<uint8_t> mac(sizeof(uint64_t));
94+ std::vector<uint8_t> mac(mac_byte_size);
95 hmac_sha1_update(&ctx, sizeof(timestamp), reinterpret_cast<uint8_t const*>(&timestamp));
96- hmac_sha1_digest(&ctx, sizeof(uint64_t), reinterpret_cast<uint8_t*>(mac.data()));
97+ hmac_sha1_digest(&ctx, mac.size(), mac.data());
98
99 return mac;
100 }
101@@ -198,8 +199,8 @@
102 auto const this_stream = cookie->serialize();
103 auto const other_stream = calculated_cookie->serialize();
104
105- // FIXME Need to do a constant memcmp here!
106- return std::equal(std::begin(this_stream), std::end(this_stream), std::begin(other_stream));
107+ return this_stream.size() == other_stream.size() &&
108+ sodium_memcmp(this_stream.data(), other_stream.data(), this_stream.size()) == 0;
109 }
110
111 struct hmac_sha1_ctx ctx;
112
113=== modified file 'src/include/cookie/mir/cookie/blob.h'
114--- src/include/cookie/mir/cookie/blob.h 2016-01-22 04:38:07 +0000
115+++ src/include/cookie/mir/cookie/blob.h 2016-01-24 17:35:31 +0000
116@@ -25,7 +25,7 @@
117 {
118 namespace cookie
119 {
120-size_t const default_blob_size = 17;
121+size_t const default_blob_size = 29;
122 using Blob = std::array<uint8_t, default_blob_size>;
123 }
124 }
125
126=== modified file 'src/server/input/default_event_builder.cpp'
127--- src/server/input/default_event_builder.cpp 2016-01-22 06:01:36 +0000
128+++ src/server/input/default_event_builder.cpp 2016-01-24 17:35:31 +0000
129@@ -69,7 +69,6 @@
130 const float x_axis_value = 0;
131 const float y_axis_value = 0;
132 std::vector<uint8_t> vec_cookie{};
133- // FIXME Moving to 160bits soon
134 if (action == mir_pointer_action_button_up || action == mir_pointer_action_button_down)
135 {
136 auto const cookie = cookie_authority->make_cookie(timestamp.count());

Subscribers

People subscribed via source and target branches

to all changes: