Skip to contentSkip to conversation

package/sqlcipher: add OpenSSL 1.1.x compatibility

PATCH New Matt Weber 3 participants 5 messages Feb 6, 2019 – Feb 12, 2019

lore
Share & tools
lore

Matt Weber

author
#0 lore raw

PATCH 1/1 package/sqlcipher: add OpenSSL 1.1.x compatibility

Fixes
http://autobuild.buildroot.net/results/5e2/5e2c3178d8a6e11b1af1c37144737097730ba222/

---
Tested using autobuilder failure setup for libopenssl.

For libressl the build fails. The sqlcipher pkg version really should be bumped before investigating the build failure as there are a number of commits that should be picked up.
Currently the pkg build won't pass the configure stage. Should I open a bug for this or send something for "next"?

---
 .../0001-Support-OpenSSL-1.1.0-and-prior.patch     | 97 ++++++++++++++++++++++
 ...SL-init-and-cleanup-routines-on-versions-.patch | 42 ++++++++++
 ...3-correct-compliation-under-openssl-1.1.x.patch | 48 +++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 package/sqlcipher/0001-Support-OpenSSL-1.1.0-and-prior.patch
 create mode 100644 package/sqlcipher/0002-Guard-OpenSSL-init-and-cleanup-routines-on-versions-.patch
 create mode 100644 package/sqlcipher/0003-correct-compliation-under-openssl-1.1.x.patch
package/sqlcipher/0001-Support-OpenSSL-1.1.0-and-prior.patch new file +97 -0
new file mode 100644
index 0000000..32a16a8
@@ -0,0 +1,97 @@
+From 43f71fa7b4c6a20f4078b9098369abb8d38a5617 Mon Sep 17 00:00:00 2001
+From: Nick Parker <[email protected]>
+Date: Fri, 9 Dec 2016 11:47:39 -0600
+Subject: [PATCH 1/3] Support OpenSSL 1.1.0 and prior
+
+(cherry picked from commit 939c83a007e4724436c3955ae2afd8b11b92d867)
+Signed-off-by: Matt Weber <[email protected]>
+---
+ src/crypto_openssl.c | 53 +++++++++++++++++++++++++++++++++++++---------------
+ 1 file changed, 38 insertions(+), 15 deletions(-)
+
+diff --git a/src/crypto_openssl.c b/src/crypto_openssl.c
+index 150ab92..6822325 100644
+--- a/src/crypto_openssl.c
++++ b/src/crypto_openssl.c
+@@ -47,6 +47,29 @@ static unsigned int openssl_external_init = 0;
+ static unsigned int openssl_init_count = 0;
+ static sqlite3_mutex* openssl_rand_mutex = NULL;
+ 
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++static HMAC_CTX *HMAC_CTX_new(void)
++{
++  HMAC_CTX *ctx = OPENSSL_malloc(sizeof(*ctx));
++  if (ctx != NULL) {
++    HMAC_CTX_init(ctx);
++  }
++  return ctx;
++}
++
++// Per 1.1.0 (https://wiki.openssl.org/index.php/1.1_API_Changes)
++// HMAC_CTX_free should call HMAC_CTX_cleanup, then EVP_MD_CTX_Cleanup.
++// HMAC_CTX_cleanup internally calls EVP_MD_CTX_cleanup so these
++// calls are not needed.
++static void HMAC_CTX_free(HMAC_CTX *ctx)
++{
++  if (ctx != NULL) {
++    HMAC_CTX_cleanup(ctx);
++    OPENSSL_free(ctx);
++  }
++}
++#endif
++
+ static int sqlcipher_openssl_add_random(void *ctx, void *buffer, int length) {
+ #ifndef SQLCIPHER_OPENSSL_NO_MUTEX_RAND
+   sqlite3_mutex_enter(openssl_rand_mutex);
+@@ -143,14 +166,14 @@ static int sqlcipher_openssl_random (void *ctx, void *buffer, int length) {
+ }
+ 
+ static int sqlcipher_openssl_hmac(void *ctx, unsigned char *hmac_key, int key_sz, unsigned char *in, int in_sz, unsigned char *in2, int in2_sz, unsigned char *out) {
+-  HMAC_CTX hctx;
+   unsigned int outlen;
+-  HMAC_CTX_init(&hctx);
+-  HMAC_Init_ex(&hctx, hmac_key, key_sz, EVP_sha1(), NULL);
+-  HMAC_Update(&hctx, in, in_sz);
+-  HMAC_Update(&hctx, in2, in2_sz);
+-  HMAC_Final(&hctx, out, &outlen);
+-  HMAC_CTX_cleanup(&hctx);
++  HMAC_CTX* hctx = HMAC_CTX_new();
++  if(hctx == NULL) return SQLITE_ERROR;
++  HMAC_Init_ex(hctx, hmac_key, key_sz, EVP_sha1(), NULL);
++  HMAC_Update(hctx, in, in_sz);
++  HMAC_Update(hctx, in2, in2_sz);
++  HMAC_Final(hctx, out, &outlen);
++  HMAC_CTX_free(hctx);
+   return SQLITE_OK; 
+ }
+ 
+@@ -160,18 +183,18 @@ static int sqlcipher_openssl_kdf(void *ctx, const unsigned char *pass, int pass_
+ }
+ 
+ static int sqlcipher_openssl_cipher(void *ctx, int mode, unsigned char *key, int key_sz, unsigned char *iv, unsigned char *in, int in_sz, unsigned char *out) {
+-  EVP_CIPHER_CTX ectx;
+   int tmp_csz, csz;
+- 
+-  EVP_CipherInit(&ectx, ((openssl_ctx *)ctx)->evp_cipher, NULL, NULL, mode);
+-  EVP_CIPHER_CTX_set_padding(&ectx, 0); // no padding
+-  EVP_CipherInit(&ectx, NULL, key, iv, mode);
+-  EVP_CipherUpdate(&ectx, out, &tmp_csz, in, in_sz);
++  EVP_CIPHER_CTX* ectx = EVP_CIPHER_CTX_new();
++  if(ectx == NULL) return SQLITE_ERROR;
++  EVP_CipherInit_ex(ectx, ((openssl_ctx *)ctx)->evp_cipher, NULL, NULL, NULL, mode);
++  EVP_CIPHER_CTX_set_padding(ectx, 0); // no padding
++  EVP_CipherInit_ex(ectx, NULL, NULL, key, iv, mode);
++  EVP_CipherUpdate(ectx, out, &tmp_csz, in, in_sz);
+   csz = tmp_csz;  
+   out += tmp_csz;
+-  EVP_CipherFinal(&ectx, out, &tmp_csz);
++  EVP_CipherFinal_ex(ectx, out, &tmp_csz);
+   csz += tmp_csz;
+-  EVP_CIPHER_CTX_cleanup(&ectx);
++  EVP_CIPHER_CTX_free(ectx);
+   assert(in_sz == csz);
+   return SQLITE_OK; 
+ }
+-- 
+1.9.1
+
package/sqlcipher/0002-Guard-OpenSSL-init-and-cleanup-routines-on-versions-.patch new file +42 -0

42 lines not on this page · raw message

package/sqlcipher/0003-correct-compliation-under-openssl-1.1.x.patch new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 package/sqlcipher: add OpenSSL 1.1.x compatibility

Hello Matt,

Quoted 6 lines · On Wed, 6 Feb 2019 06:09:18 -0600 Matt Weber…

Fixes
http://autobuild.buildroot.net/results/5e2/5e2c3178d8a6e11b1af1c37144737097730ba222/

---
Tested using autobuilder failure setup for libopenssl.

Applied to master, thanks. Please remember to use "git format-patch -N" to format the patches, this removes the numbering inside the patch titles.

Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 package/sqlcipher: add OpenSSL 1.1.x compatibility

In reply to Matt Weber
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matt" == Matt Weber <[email protected]> writes:

Fixes
http://autobuild.buildroot.net/results/5e2/5e2c3178d8a6e11b1af1c37144737097730ba222/

Quoted 8 lines

---
Tested using autobuilder failure setup for libopenssl.

For libressl the build fails. The sqlcipher pkg version really should be bumped before investigating the build failure as there are a number of commits that should be picked up.
Currently the pkg build won't pass the configure stage. Should I open a bug for this or send something for "next"?

What do we do about the libressl issue for 2019.02? Just select BR2_PACKAGE_OPENSSL_FORCE_LIBOPENSSL?

Signature · 1 line
Bye, Peter Korsgaard
#3 lore raw

PATCH 1/1 package/sqlcipher: add OpenSSL 1.1.x compatibility

Peter,

Quoted 10 lines · Peter Korsgaard
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Matt" == Matt Weber <[email protected]> writes:

Fixes
http://autobuild.buildroot.net/results/5e2/5e2c3178d8a6e11b1af1c37144737097730ba222/

---
Tested using autobuilder failure setup for libopenssl.

Quoted 9 lines
Quoted 5 lines

For libressl the build fails. The sqlcipher pkg version really should be bumped before investigating the build failure as there are a number of commits that should be picked up.
Currently the pkg build won't pass the configure stage. Should I open a bug for this or send something for "next"?

What do we do about the libressl issue for 2019.02? Just select BR2_PACKAGE_OPENSSL_FORCE_LIBOPENSSL?

I did some builds and this libressl compatibility was broken before the openssl bump but never found. (Tested with 2018.02.x and tip)

I can add that force dependency for this release cycle. Would it make sense to open a bug capturing the notes and suggesting a bump or just leave this limitation in until someone maintains the package (currently we're at a ~2014 version with commits by Gustavo and Maxime)?

Matt

#4 lore raw

PATCH 1/1 package/sqlcipher: add OpenSSL 1.1.x compatibility

Quoted 20 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Matthew" == Matthew Weber <[email protected]> writes:

Peter,

Quoted 16 lines · Peter Korsgaard
Quoted 15 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Matt" == Matt Weber <[email protected]> writes:

Fixes
http://autobuild.buildroot.net/results/5e2/5e2c3178d8a6e11b1af1c37144737097730ba222/

---
Tested using autobuilder failure setup for libopenssl.

For libressl the build fails. The sqlcipher pkg version really should be bumped before investigating the build failure as there are a number of commits that should be picked up.
Currently the pkg build won't pass the configure stage. Should I open a bug for this or send something for "next"?

Quoted 6 lines
Quoted 3 lines

What do we do about the libressl issue for 2019.02? Just select BR2_PACKAGE_OPENSSL_FORCE_LIBOPENSSL?

I did some builds and this libressl compatibility was broken before the openssl bump but never found. (Tested with 2018.02.x and tip)

Ahh, ok.

Quoted 5 lines

I can add that force dependency for this release cycle. Would it make sense to open a bug capturing the notes and suggesting a bump or just leave this limitation in until someone maintains the package (currently we're at a ~2014 version with commits by Gustavo and Maxime)?

Either that or just explain it in the commit message that adds the select. I guess both will be visible for someone wanting to use sqlcipher with libressl.

Signature · 1 line
Bye, Peter Korsgaard