본문 바로가기

카테고리 없음

with openssl porting guide

- openssl 은 android full source 내에 external 을 보게 되면 openssl 항목이 존재한다 이를 사용해서 컴파일 가능하다.
- 또는 phone 내에 존재하는 libcrypto.so, libssl.so 를 복사해서 사용가능 하다.
- openssl 을 적용하려면 다음과 같이 사용하면 된다.
[code]
# lib 에 so 의 경로를 지정 한다. prefix 는 -L 로 지정 한다.
LOCAL_LDLIBS := \
    -L$(LOCAL_PATH)/../../common-libs \
    -lcrypto -lssl \
[/code]

- compile 을 위해서는 다음을 수정해야 한다.
1. RSA_generate_key 오류
    - 구 버전의 RSA_generate_key 를 사용하기 때문에 Deprecated 된 function 을 add 해야 된다.
    - ngx_event_openssl.c 에 추가 한다.
[code]
// ANDROID
#ifdef ANDROID

#include <stdio.h>
#include <time.h>

#include <openssl/bn.h>
#include <openssl/rsa.h>

RSA *RSA_generate_key(int bits, unsigned long e_value,
         void (*callback)(int,int,void *), void *cb_arg)
    {
    BN_GENCB cb;
    int i;
    RSA *rsa = RSA_new();
    BIGNUM *e = BN_new();

    if(!rsa || !e) goto err;

    /* The problem is when building with 8, 16, or 32 BN_ULONG,
     * unsigned long can be larger */
    for (i=0; i<(int)sizeof(unsigned long)*8; i++)
        {
        if (e_value & (1UL<<i))
            if (BN_set_bit(e,i) == 0)
                goto err;
        }

    BN_GENCB_set_old(&cb, callback, cb_arg);

    if(RSA_generate_key_ex(rsa, bits, e, &cb)) {
        BN_free(e);
        return rsa;
    }
err:
    if(e) BN_free(e);
    if(rsa) RSA_free(rsa);
    return 0;
    }
#endif
[/code]

2. crypt 오류는 define 이 되지 않아서 해당 define 을 추가해줘야 한다.
    - ngx_user.c 를 수정 해야 한다.
[code]
//
// FOR ANDROID
//
#ifdef ANDROID
#include <openssl/des.h>
#define crypt(c,s) (DES_crypt((c),(s)))
#endif
[/code]

3. 추가적으로 crypt 를 사용하고 있기 때문에 이를 컴파일 해줘야 한다.