summarylogtreecommitdiffstats
path: root/0006-mbedtls-3.patch
blob: 3dcdc0351d552cbde5afd2e0cbb531b7e9a10300 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,6 @@ src/dislocker-metadata
 src/libdislocker.so*
 
 # Configured files
-include/dislocker/ssl_bindings.h
 src/dislocker-find.rb
 
 # Unit test files

--- a/cmake/FindPolarSSL.cmake
+++ /dev/null
@@ -1,113 +0,0 @@
-# Try to find PolarSSL/mbedtls library
-#
-# Returns
-# POLARSSL_FOUND
-# POLARSSL_INCLUDE_DIRS
-# POLARSSL_LIBRARIES
-# POLARSSL_VERSION_MAJOR
-# POLARSSL_VERSION_MINOR
-# POLARSSL_VERSION_PATCH
-# POLARSSL_VERSION_STRING
-# POLARSSL_INC_FOLDER
-# POLARSSL_REAL_NAME
-
-include(FindPackageHandleStandardArgs)
-
-find_path(POLARSSL_INCLUDE_DIRS NAMES mbedtls/ssl.h HINTS /usr/local/include)
-set(POLARSSL_REAL_NAME MBEDTLS)
-if( "${POLARSSL_INCLUDE_DIRS}" STREQUAL "POLARSSL_INCLUDE_DIRS-NOTFOUND")
-  find_path(POLARSSL_INCLUDE_DIRS NAMES polarssl/ssl.h)
-  set(POLARSSL_REAL_NAME POLARSSL)
-endif()
-
-string(TOLOWER "${POLARSSL_REAL_NAME}" POLARSSL_INC_FOLDER)
-
-#
-# polarssl -> mbedtls
-# Try to find first libmbedcrypto.a, then libmbedtls.a, and if this fails tries
-# to find polarssl.
-# Only because mbed is separating ssl/tls functions from crypto (aes/sha)
-# functions and some distrib (like osx or fedora) do not symbolically link
-# libmbedtls to polarssl for compat
-#
-find_library(POLARSSL_LIBRARIES NAMES mbedcrypto)
-set(POLARSSL_USED_LIBRARY mbedcrypto)
-if( "${POLARSSL_LIBRARIES}" STREQUAL "POLARSSL_LIBRARIES-NOTFOUND" )
-  find_library(POLARSSL_LIBRARIES NAMES mbedtls)
-  set(POLARSSL_USED_LIBRARY mbedtls)
-  if( "${POLARSSL_LIBRARIES}" STREQUAL "POLARSSL_LIBRARIES-NOTFOUND" )
-    find_library(POLARSSL_LIBRARIES NAMES polarssl)
-    set(POLARSSL_USED_LIBRARY polarssl)
-  endif()
-endif()
-
-find_package_handle_standard_args(POLARSSL REQUIRED_VARS POLARSSL_INCLUDE_DIRS POLARSSL_LIBRARIES)
-
-if( ${POLARSSL_LIBRARIES-NOTFOUND} )
-  message(FATAL_ERROR "Failed to get info from PolarSSL library, check your PolarSSL installation")
-  set(POLARSSL_FOUND False)
-  return()
-endif()
-
-if( "${CMAKE_C_COMPILER}" STREQUAL "/Library/Developer/CommandLineTools/usr/bin/cc" )
-  set(CMAKE_C_COMPILER cc)
-endif()
-
-if(APPLE)
-  execute_process(
-    COMMAND xcrun --sdk macosx --show-sdk-path
-    OUTPUT_VARIABLE envSdkRoot
-    OUTPUT_STRIP_TRAILING_WHITESPACE
-  )
-  set(ENV{SDKROOT} "${envSdkRoot}")
-endif()
-
-if( NOT CMAKE_CROSSCOMPILING )
-  execute_process(
-    COMMAND echo "#include <${POLARSSL_INC_FOLDER}/version.h>\n#include <stdio.h>\nint main(){printf(${POLARSSL_REAL_NAME}_VERSION_STRING);return 0;}"
-    OUTPUT_FILE a.c
-  )
-  execute_process(
-    COMMAND ${CMAKE_C_COMPILER} a.c -I${POLARSSL_INCLUDE_DIRS} ${POLARSSL_LIBRARIES}
-  )
-  execute_process(
-    COMMAND ./a.out
-    OUTPUT_VARIABLE POLARSSL_VERSION_STRING
-  )
-  execute_process(
-    COMMAND ${CMAKE_COMMAND} -E remove a.c a.out
-  )
-else()
-  execute_process(
-    COMMAND grep -w "MBEDTLS_VERSION_STRING" ${POLARSSL_INCLUDE_DIRS}/${POLARSSL_INC_FOLDER}/version.h
-    COMMAND sed -e "s@\s\+@ @g"
-    COMMAND cut -d\  -f3
-    COMMAND sed -e "s@\"@@g"
-    OUTPUT_VARIABLE POLARSSL_VERSION_STRING
-  )
-endif()
-
-message("PolarSSL/mbedTLS version: " ${POLARSSL_VERSION_STRING})
-
-if( "${POLARSSL_VERSION_STRING}" STREQUAL "2.0.0" AND NOT "${POLARSSL_USED_LIBRARY}" STREQUAL "mbedcrypto" )
-  message("*** WARNING *** Your mbedTLS version is 2.0.0, it's possible the `make' command doesn't work.\nPlease refer to the INSTALL.md's \"mbedTLS 2.0.0\" section if you have any problem.\n")
-endif()
-
-string(REPLACE "." ";" POLARSSL_VERSION_LIST ${POLARSSL_VERSION_STRING})
-
-list(GET ${POLARSSL_VERSION_LIST} 0 POLARSSL_VERSION_MAJOR)
-list(GET ${POLARSSL_VERSION_LIST} 1 POLARSSL_VERSION_MINOR)
-list(GET ${POLARSSL_VERSION_LIST} 2 POLARSSL_VERSION_PATCH)
-
-set(POLARSSL_FOUND True)
-mark_as_advanced(
-  POLARSSL_FOUND
-  POLARSSL_INCLUDE_DIRS
-  POLARSSL_LIBRARIES
-  POLARSSL_VERSION_MAJOR
-  POLARSSL_VERSION_MINOR
-  POLARSSL_VERSION_PATCH
-  POLARSSL_VERSION_STRING
-  POLARSSL_INC_FOLDER
-  POLARSSL_REAL_NAME
-  )

--- a/include/dislocker/ssl_bindings.h.in
+++ b/include/dislocker/ssl_bindings.h
@@ -24,43 +24,12 @@
 #define SSL_BINDINGS_H
 
 /*
- * Here stand the bindings for polarssl SHA256/SHA2/SHA-2 function for dislocker
+ * Here stand the bindings for MbedTLS SHA256/SHA2/SHA-2 function for dislocker
  */
-#include "@POLARSSL_INC_FOLDER@/version.h"
-#if MBEDTLS_VERSION_MAJOR >= 3
-#include "@POLARSSL_INC_FOLDER@/mbedtls_config.h"
-#include "@POLARSSL_INC_FOLDER@/compat-2.x.h"
-#else
-#include "@POLARSSL_INC_FOLDER@/config.h"
-#endif
-#include "@POLARSSL_INC_FOLDER@/aes.h"
-
-// Function's name changed
-#if defined(MBEDTLS_SHA256_C)
-#  include "mbedtls/sha256.h"
-#  if MBEDTLS_VERSION_NUMBER >= 0x02070000
-#    define SHA256(input, len, output)         mbedtls_sha256_ret(input, len, output, 0)
-#  else
-#    define SHA256(input, len, output)         mbedtls_sha256(input, len, output, 0)
-#  endif /* POLARSSL_VERSION_NUMBER >= 0x02070000 */
-#else /* defined(MBEDTLS_SHA256_C) */
-
-#  if defined(POLARSSL_SHA256_C)
-#    include "polarssl/sha256.h"
-#    define SHA256(input, len, output)       sha256(input, len, output, 0)
-#  else /* defined(POLARSSL_SHA256_C) */
-#    include "polarssl/sha2.h"
-
-// 0x00630500 = version 0.99.5, argument's type changed in this release
-#    if POLARSSL_VERSION_NUMBER >= 0x00630500
-#     define SHA256(input, len, output)       sha2(input, len, output, 0)
-#    else
-#     define SHA256(input, len, output)       sha2(input, (int)len, output, 0)
-#    endif /* POLARSSL_VERSION_NUMBER >= 0x00630500 */
-
-#  endif /* defined(POLARSSL_SHA256_C) */
-#endif /* defined(MBEDTLS_SHA256_C) */
+#include "mbedtls/aes.h"
+#include "mbedtls/sha256.h"
 
+#define SHA256(input, len, output)        mbedtls_sha256(input, len, output, 0)
 
 /* Here stand the bindings for AES functions and contexts */
 #if defined(MBEDTLS_AES_H)

--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -116,14 +116,10 @@ endif()
 # Libraries
 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
 
-find_package (PolarSSL REQUIRED)
-if(POLARSSL_FOUND  AND  POLARSSL_INCLUDE_DIRS  AND  POLARSSL_LIBRARIES)
-	include_directories (${POLARSSL_INCLUDE_DIRS})
-	set (LIB ${LIB} ${POLARSSL_LIBRARIES})
-	configure_file (${PROJECT_SOURCE_DIR}/include/dislocker/ssl_bindings.h.in ${PROJECT_SOURCE_DIR}/include/dislocker/ssl_bindings.h ESCAPE_QUOTES @ONLY)
-else()
-	return ()
-endif()
+find_package (MbedTLS 3 REQUIRED)
+set (LIB ${LIB} MbedTLS::mbedcrypto)
+# Avoid moving or deleting original source files: +file(RENAME ${PROJECT_SOURCE_DIR}/include/dislocker/ssl_bindings.h.in ${PROJECT_SOURCE_DIR}/include/dislocker/ssl_bindings.h)
+configure_file(${PROJECT_SOURCE_DIR}/include/dislocker/ssl_bindings.h.in ${PROJECT_SOURCE_DIR}/include/dislocker/ssl_bindings.h COPYONLY)
 
 # Ruby bindings
 set(WITH_RUBY "AUTO" CACHE STRING "Enable Ruby bindings. Valid values are ON, OFF, or AUTO")

--- a/INSTALL.md
+++ b/INSTALL.md
@@ -11,24 +11,20 @@ You need:
 - make (or gmake, for FreeBSD);
 - pkg-config;
 - Headers for FUSE3;
-- Headers for mbedTLS (previously known as PolarSSL);
+- Headers for mbedTLS 3;
 - A partition encrypted with BitLocker, from Windows Vista, 7 or 8.
 
 
 If you have Ruby headers, the library will compile with some Ruby bindings and
 another program - see the NOTE section below - will be available.
 
-For Debian-like distros based on Debian Jessie or Ubuntu 14.04 or older:
-
-- `aptitude install gcc cmake make libfuse-dev libpolarssl-dev ruby-dev`
-
-For Debian-like distros based on Debian Stretch or Ubuntu 16.04 or later:
+For Debian-like distros:
 
 - `aptitude install gcc cmake make libfuse-dev libmbedtls-dev ruby-dev pkgconf`
 
 For Fedora-like:
 
-- `dnf install gcc cmake make fuse-devel mbedtls-devel ruby-devel rubypick`
+- `dnf install gcc cmake make fuse-devel mbedtls3.6-devel ruby-devel rubypick`
 
 Alternatively, running `dnf install dislocker fuse-dislocker` to use the
 already existing RPM packages in Fedora could be a clever idea.
@@ -42,7 +38,7 @@ already existing RPM packages in EPEL co
 
 For FreeBSD:
 
-- `pkg install cmake gmake fusefs-libs mbedtls`
+- `pkg install cmake gmake fusefs-libs mbedtls3`
 
 For OSX: Follow the instructions in the next section.
 
@@ -101,33 +97,6 @@ Once installed, see `dislocker(1)` for d
 I'm sure you don't want to do that. But if you're really forced by someone, just
 type `make uninstall` as super-user.
 
-# mbedTLS 2.0.0
-
-Since the version 2.0.0 of mbedTLS, the build moves "crypto" functions such
-as AES and SHA256 into a separate, libmbedcrypto, library. However, a typo
-didn't installed this library, resulting in some packagers not providing this
-library, thus breaking the dislocker compilation.
-If you have this problem, it's recommended to run the following commands (they
-have been put in the src/mbed_install.sh script, if you don't want to
-copy/paste from here):
-```
-git clone https://github.com/ARMmbed/mbedtls.git
-cd mbedtls
-git checkout mbedtls-2.0.0
-```
-Then apply the patch given by the following command:
-```
-git show 6f42417b library/CMakeLists.txt
-```
-And compile/install the library:
-```
-cmake .
-make
-sudo make install
-```
-
-You can then resume the installation where you have left it.
-
 # PORTABILITY
 
 Globally, this was successfully tested on Linux x86/x86_64, MacOSX and FreeBSD.