سؤال

I have downloaded the latest source from OpenSSL Page (released on April 7th, 2014), and created a libcrypto.a library using Tutorial Where i have followed the steps in which i run ./build-openssl.sh script file to generate libcrypto.a file for all environments (armv7s, armv7, i386) on Mac OS X having version 10.9.2.

I am able to encrypt / decrypt the date using EVP_aes_256_cbc encryption but my code gets failed when i try to get RAND_byte. The code gets crashed on RAND_byte call.

Below are the codes, which i am trying to get the RAND_byte seeds:

// Code 1

unsigned char seed[32];
RAND_bytes(seed, 32);

// Code 2

int count = 24;
unsigned char *buffer = (unsigned char *)calloc(count, sizeof(unsigned char));
RAND_bytes(buffer, count);

// Code 3

int count = 24;
unsigned char *buffer = (unsigned char *)malloc(sizeof(int)*count);
RAND_bytes(buffer, count);

// Code 4

int count = 24;
unsigned char *buffer = OPENSSL_malloc(count);
RAND_bytes(buffer, count);

When I run above code on iOS 6.0/6.1 Simulator, It gets crashed on RAND_byte call and I get “_interposition_vtable_unimplemented” on Thread 1 and no message get displayed on console.

When I run the same code on iOS 7.0+ Simulator, It gets crashed on RAND_byte call and I get “__pthread_kill” on Thread 1 and “Detected an attempt to call a symbol in system libraries that is not present on the iPhone: open$UNIX2003 called from function RAND_poll in image CryptographyTest.” on Console.

But WHEN I run the same code on iPad with iOS 7.0.4, All above codes runs perfectly. Where i get the return value from RAND_byte is 1.

I don’t understand the behavior that some of the functions does not work on iOS simulator but everything works with iOS devices.

Any help highly appreciated! Many thanks in advance.

هل كانت مفيدة؟

المحلول

... using Tutorial where i have followed the steps in which i
run ./build-openssl.sh script file to generate libcrypto.a file
for all environments (armv7s, armv7, i386) 
...
I don’t understand the behavior that some of the functions does
not work on iOS simulator but everything works with iOS devices.

The script is wrong for your usage:

enter image description here

Its not building for the simulator. Its building for the desktop. This:

ARCHS=("armv7s" "armv7" "i386")
SDKS=("iphoneos" "iphoneos" "macosx")

Probably needs to be changed to:

ARCHS=("armv7s" "armv7" "i386")
SDKS=("iphoneos" "iphoneos" "iPhoneSimulator")

With iPhoneSimulator, the proper SDK will be used:

$ ls /Applications/Xcode.app/Contents/Developer/Platforms/
MacOSX.platform         iPhoneSimulator.platform
iPhoneOS.platform

Does the project you are using claim its multi-arch and for the iPhone and iPhone Simulator? Or does it claim its multi-arch and for iPhone and OS X?

نصائح أخرى

and created a libcrypto.a library for iOS use using Tutorial.

I don't know about that Tutorial, but OpenSSL has procedures to build the library for iOS. You can find it in the FIPS User Guide 2.0, Appendix E.

You can fetch a prebuilt version of OpenSSL for iOS at Github. It was built using the OpenSSL procedures. Its a fat library, and it has i386, ARMv7, ARMv7s and ARM64 architectures.


“__pthread_kill” on Thread 1 and “Detected an attempt to call a symbol in system libraries that is not present on the iPhone: open$UNIX2003 called from function RAND_poll in image CryptographyTest.” on Console.

I believe this indicates the OpenSSL library was not built properly for the simulator or devices.


int count = 24;
unsigned char *buffer = OPENSSL_malloc(count);
RAND_bytes(buffer, count);

Just bike shedding here, but you ignored the return value from RAND_bytes. According to the docs on RAND_bytes:

RAND_bytes() returns 1 on success, 0 otherwise. The error code can be obtained by ERR_get_error(3).

Silent failures are a kiss of death to high integrity software.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top