All pastes #1583678 Raw Edit

Tor binary on Android Patch

public text v1 · immutable
#1583678 ·published 2009-09-29 03:37 UTC
rendered paste body
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 4a61d3f..7925a2c 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -50,9 +50,9 @@
 
 #define CRYPTO_PRIVATE
 #include "crypto.h"
-#include "log.h"
+#include "../common/log.h"
 #include "aes.h"
-#include "util.h"
+#include "../common/util.h"
 #include "container.h"
 #include "compat.h"
 
@@ -178,6 +178,12 @@ crypto_log_errors(int severity, const char *doing)
 static void
 log_engine(const char *fn, ENGINE *e)
 {
+  #ifdef ANDROID
+  //use default implementation for Android
+    log(LOG_INFO, LD_CRYPTO, "Using default implementation for %s", fn);
+  #endif
+
+  #ifndef ANDROID
   if (e) {
     const char *name, *id;
     name = ENGINE_get_name(e);
@@ -187,6 +193,7 @@ log_engine(const char *fn, ENGINE *e)
   } else {
     log(LOG_INFO, LD_CRYPTO, "Using default implementation for %s", fn);
   }
+  #endif
 }
 
 /** Try to load an engine in a shared library via fully qualified path.
@@ -194,6 +201,7 @@ log_engine(const char *fn, ENGINE *e)
 static ENGINE *
 try_load_engine(const char *path, const char *engine)
 {
+  #ifndef ANDROID
   ENGINE *e = ENGINE_by_id("dynamic");
   if (e) {
     if (!ENGINE_ctrl_cmd_string(e, "ID", engine, 0) ||
@@ -205,6 +213,7 @@ try_load_engine(const char *path, const char *engine)
     }
   }
   return e;
+  #endif
 }
 
 /** Initialize the crypto library.  Return 0 on success, -1 on failure.
@@ -219,18 +228,24 @@ crypto_global_init(int useAccel, const char *accelName, const char *accelDir)
     setup_openssl_threading();
     if (useAccel > 0) {
       ENGINE *e = NULL;
+
+      #ifndef ANDROID
       log_info(LD_CRYPTO, "Initializing OpenSSL engine support.");
       ENGINE_load_builtin_engines();
       ENGINE_register_all_complete();
+      #endif
+
       if (accelName) {
         if (accelDir) {
           log_info(LD_CRYPTO, "Trying to load dynamic OpenSSL engine \"%s\""
                    " via path \"%s\".", accelName, accelDir);
           e = try_load_engine(accelName, accelDir);
         } else {
+          #ifndef ANDROID
           log_info(LD_CRYPTO, "Initializing dynamic OpenSSL engine \"%s\""
                    " acceleration support.", accelName);
           e = ENGINE_by_id(accelName);
+         #endif
         }
         if (!e) {
           log_warn(LD_CRYPTO, "Unable to load dynamic OpenSSL engine \"%s\".",
@@ -240,6 +255,7 @@ crypto_global_init(int useAccel, const char *accelName, const char *accelDir)
                    accelName);
         }
       }
+      #ifndef ANDROID
       if (e) {
         log_info(LD_CRYPTO, "Loaded OpenSSL hardware acceleration engine,"
                  " setting default ciphers.");
@@ -251,6 +267,7 @@ crypto_global_init(int useAccel, const char *accelName, const char *accelDir)
       log_engine("SHA1", ENGINE_get_digest_engine(NID_sha1));
       log_engine("3DES", ENGINE_get_cipher_engine(NID_des_ede3_ecb));
       log_engine("AES", ENGINE_get_cipher_engine(NID_aes_128_ecb));
+      #endif
     } else {
       log_info(LD_CRYPTO, "NOT using OpenSSL engine support.");
     }
@@ -274,7 +291,11 @@ crypto_global_cleanup(void)
   EVP_cleanup();
   ERR_remove_state(0);
   ERR_free_strings();
-  ENGINE_cleanup();
+
+  #ifndef ANDROID
+  ENGINE_cleanup(); 
+  #endif
+
   CONF_modules_unload(1);
   CRYPTO_cleanup_all_ex_data();
 #ifdef TOR_IS_MULTITHREADED
diff --git a/src/or/buffers.c b/src/or/buffers.c
index e512373..1a1b207 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -12,6 +12,8 @@
  **/
 #define BUFFERS_PRIVATE
 #include "or.h"
+#include "../common/util.h"
+#include "../common/log.h"
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
diff --git a/src/or/eventdns.c b/src/or/eventdns.c
index edccb4b..83bff67 100644
--- a/src/or/eventdns.c
+++ b/src/or/eventdns.c
@@ -31,6 +31,7 @@
  */
 
 #include "eventdns_tor.h"
+#include "../common/util.h"
 #include <sys/types.h>
 /* #define NDEBUG */
 
diff --git a/src/or/or.h b/src/or/or.h
index 0162e31..613de1a 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -82,7 +82,7 @@
 
 #include "crypto.h"
 #include "tortls.h"
-#include "log.h"
+#include "../common/log.h"
 #include "compat.h"
 #include "container.h"
 #include "util.h"
diff --git a/src/tools/tor-checkkey.c b/src/tools/tor-checkkey.c
index 6416dbf..739f733 100644
--- a/src/tools/tor-checkkey.c
+++ b/src/tools/tor-checkkey.c
@@ -7,7 +7,7 @@
 #include <stdlib.h>
 #include "crypto.h"
 #include "log.h"
-#include "util.h"
+#include "../common/util.h"
 #include "compat.h"
 #include <openssl/bn.h>
 #include <openssl/rsa.h>
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c
index 2ae4cc2..77f64ab 100644
--- a/src/tools/tor-gencert.c
+++ b/src/tools/tor-gencert.c
@@ -27,8 +27,8 @@
 #define CRYPTO_PRIVATE
 
 #include "compat.h"
-#include "util.h"
-#include "log.h"
+#include "../common/util.h"
+#include "../common/log.h"
 #include "crypto.h"
 #include "address.h"
 
@@ -238,7 +238,7 @@ load_identity_key(void)
     }
     log_notice(LD_GENERAL, "Generating %d-bit RSA identity key.",
                IDENTITY_KEY_BITS);
-    if (!(key = RSA_generate_key(IDENTITY_KEY_BITS, 65537, NULL, NULL))) {
+    if (!(key = RSA_generate_key_ex(IDENTITY_KEY_BITS, 65537, NULL, NULL))) {
       log_err(LD_GENERAL, "Couldn't generate identity key.");
       crypto_log_errors(LOG_ERR, "Generating identity key");
       return 1;
@@ -323,7 +323,7 @@ generate_signing_key(void)
   RSA *key;
   log_notice(LD_GENERAL, "Generating %d-bit RSA signing key.",
              SIGNING_KEY_BITS);
-  if (!(key = RSA_generate_key(SIGNING_KEY_BITS, 65537, NULL, NULL))) {
+  if (!(key = RSA_generate_key_ex(SIGNING_KEY_BITS, 65537, NULL, NULL))) {
     log_err(LD_GENERAL, "Couldn't generate signing key.");
     crypto_log_errors(LOG_ERR, "Generating signing key");
     return 1;
diff --git a/src/tools/tor-resolve.c b/src/tools/tor-resolve.c
index f12c3d8..fe7f793 100644
--- a/src/tools/tor-resolve.c
+++ b/src/tools/tor-resolve.c
@@ -6,9 +6,9 @@
 #include "orconfig.h"
 
 #include "compat.h"
-#include "util.h"
+#include "../common/util.h"
 #include "address.h"
-#include "log.h"
+#include "../common/log.h"
 
 #include <stdio.h>
 #include <stdlib.h>