Openssl_uplink (0098e000, 07): No openssl_applink Error Analysis

Source: Internet
Author: User
Analysis 1: I created a new DLL. DLL, while. DLL needs to call the OpenSSL DLL, and then create a Win32 application B to call the export function in A. At this time, it must include once and only once <install-root>/include/OpenSSL/applink. c To Your B project, rather than include it to. or <install-root>/include/OpenSSL/applink. C is copied to B's project, otherwise it will appear. runtime error openssl_uplink (0098e000, 07): No openssl_applink because OpenSSL source code uplink. c: H = getmodulehandle (null) applink = (void ** (*) () getprocaddress (H, "openssl_applink "); we can see that OpenSSL uses the handle H obtained through getmodulehandle (null) to call the applink () function (applink function is applink. an export function in C). The applink () function is not part of the OpenSSL DLL internal function (this function does not exist through the DLL analyzer), but because getmodulehandle (null) the obtained handle always points to the application handle (for example, Project B in the preceding example) instead of the DLL handle. compile part of the C file application. below are my questions in the OpenSSL-user mail list, and some people give me a reply: From: yangniancai@hotmail.com
To: openssl-users@openssl.org
Subject: Re: openssl_uplink (0099e000, 07): No openssl_applink
Date: Wed, 12 Nov 2008 01:51:11 + 0000

HiGER hobbelt
Thank you soooooooo much.
Your answer 2) solve my problem well.
Because there exists libeay32.dll, ssleay32.dll, my own DLL and my application. My own DLL call libeay32.dll and ssleay32.dll. And my application call my own DLL.
According to ger hobbelt's suggestion 2), firstly I used a tool to analyze the exports functions of libeay32.dll, ssleay32.dll and my own DLL. I found that DLL exports functions don't contain openssl_applink () function. also I look up the source code of uplink. C which call openssl_applink () function. uplink. c use <H = getmodulehandle (null)> to get a handle h, and then use <applink = (void ** (*) () getprocaddress (H, "openssl_applink")> to got the address of openssl_applink ().When I use libeay32.dll, ssleay32.dll in my application, this handle H will point to the application but not my own DLL.
So I shoshould add applink. C to my application as a part of my application source code, never add it to my own DLL source code.
 
Leo Yang

Best regards
 
MSN: yangniancai@hotmail.com

> Date: Tue, 11 Nov 2008 17:35:03 + 0100
> From: ger@hobbelt.com
> To: openssl-users@openssl.org
> Subject: Re: openssl_uplink (0099e000, 07): No openssl_applink
> CC: i-zw@hotmail.com
>
> Hm, never used this openssl_uplink/applink glue before... (I have my
> Own OpenSSL msvc2005 projects, which I always use inside my solutions)
>
> Anyway, a quick check leads me to two possible answers:
>
> 1) somewhere appmacros_only was # define 'd before your actual
>
> Extern "C"
>> {
>># Include <OpenSSL/applink. c>
>>}
>
> Code bit.
>
> A simple change shocould be able to verify if this is actually the matter:
>
> Extern "C"
> {
> # UNDEF appmacros_only
> # Include <OpenSSL/applink. c>
>}
>
> As then the problem shocould be gone.
>
> However, there's a chance:
>
> 2)... that you are compiling this code into a DLL of your own (given
> Your description of the issue, my guess is this is what you are doing.
> Correct ?).
>
> Given that the uplink code looks at the * application module * for
> Applink export, you may not find it when it is actually exported from
> A dll instead of the EXE itself.
>
> Note: The above is 'esswork': I haven't checked.
>
>
> To fix the above, moving
>
> Extern "C"
>> {
>># Include <OpenSSL/applink. c>
>>}
>
> Code snippet to the main application source code shoshould resolve
> Matter, preferrably by placing it in the same source file as your
> Winmain ()/main () function.
>
>
>
> To help you see who exports what and depends on whom, You may search
> The net for a free tool called 'dependency Walker '(
> Http://www.dependencywalker.com/) which is a very handy tool when you
> Need to check what is going regarding dll/EXE dependencies and
> Function/Data Import/exports.
>
>
>
>
>
>
> On Tue, Nov 11,200 8 at AM, Nian Cai Yang <yangniancai@hotmail.com> wrote:
> Hi all
>
> I meet a run time error "openssl_uplink (0099e000, 07): No openssl_applink"
> Which feaze me several days.
> This is my project description:
> I had download openssl-0.9.8i. Then build it and install it correctly
> Following the install. Win32 instruction.
> I use vs2005 to develop my project
> And I had set vs2005 environment such as "multithread debug DLL" etc.
> Because it works well in my other projects.
> This project is a bit different because the below function is called by
> DLL project. But the function is the same in DLL project and Application
> Project.
> [Source Code]
> // "Mycryptlib. cpp"
>># Include "stdafx. H"
>># Include <OpenSSL/SSL. h>
>># Include "mycryptlib. H"
>># Include <iostream>
> Using namespace STD;
> Extern "C"
>> {
>># Include <OpenSSL/applink. c>
>>}
> Conf * Config = NULL;
> Bio * bio_err = NULL;
>>// Encrypt data
>># Define rsa_sign 1
>># Define rsa_verify 2
>># Define rsa_encrypt 3
>># Define rsa_decrypt 4
>># Define key_privkey 1
>># Define key_pubkey 2
>># Define key_cert 3
>>// Int encryptdata ()
> Int encryptdata (unsigned char * indata, unsigned char * outdata, char *
> Pubkeyfile, Int & Len)
>> {
>
>
> Engine * E = NULL;
> Bio * In = NULL, * out = NULL;
> Char * infile = NULL, * OUTFILE = NULL;
>># Ifndef openssl_no_engine
> Char * Engine = NULL;
>># Endif
> Char * Keyfile = NULL;
> Char rsa_mode = rsa_verify, key_type = key_privkey;
> Int keyform = format_pem;
> Char need_priv = 0, badarg = 0, REV = 0;
> Char hexdump = 0, asn1parse = 0;
> X509 * X;
> Evp_pkey * pkey = NULL;
> RSA * RSA = NULL;
> Unsigned char * rsa_in = NULL, * rsa_out = NULL, pad;
> Char * passargin = NULL, * passin = NULL;
> Int rsa_inlen, rsa_outlen = 0;
> Int keysize;
> Int ret = 1;
>
> Crypto_malloc_init ();
> Ssl_library_init ();
> If (! Bio_err) bio_err = bio_new_fp (stderr, bio_noclose );
> If (! Load_config (bio_err, null ))
> Goto end;
> Err_load_crypto_strings ();
> Openssl_add_all_algorithms ();
> Pad = rsa_pkcs1_padding;
>
>
> Rsa_mode = rsa_encrypt;
> Key_type = key_pubkey;
> Keyfile = pubkeyfile;
>>// Infile = "data.txt ";
>>// OUTFILE = "data. SSL ";
>>// Cerr <"just for testing bio_printf/N" <Endl;
>
> If (need_priv & (key_type! = Key_privkey )){
> Bio_printf (bio_err, "a private key is needed for this operation/N ");
> Goto end;
>>}
>># Ifndef openssl_no_engine
> E = setup_engine (bio_err, engine, 0 );
>># Endif
> If (! App_passwd (bio_err, passargin, null, & passin, null )){
> Bio_printf (bio_err, "error getting password/N ");
> Goto end;
>>}
>/* Fixme: Seed PRNG only if needed */
> App_rand_load_file (null, bio_err, 0 );
>
> Switch (key_type ){
> Case key_privkey:
> Pkey = load_key (bio_err, Keyfile, keyform, 0,
> Passin, e, "Private Key ");
> Break;
> Case key_pubkey:
> Pkey = load_pubkey (bio_err, Keyfile, keyform, 0,
> Null, e, "Public Key ");
> Break;
> Case key_cert:
> X = load_cert (bio_err, Keyfile, keyform,
> Null, e, "certificate ");
> If (x ){
> Pkey = x509_get_pubkey (X );
> X509_free (X );
>>}
> Break;
>>}
> If (! Pkey ){
> Return 1;
>>}
> RSA = evp_pkey_get1_rsa (pkey );
> Evp_pkey_free (pkey );
> If (! RSA ){
> Bio_printf (bio_err, "error getting RSA key/N ");
> Err_print_errors (bio_err );
> Goto end;
>>}
>
> If (infile ){
> If (! (IN = bio_new_file (infile, "rb "))){
> Bio_printf (bio_err, "error reading input file/N ");
> Err_print_errors (bio_err );
> Goto end;
>>}
>>} Else in = bio_new_fp (stdin, bio_noclose );
> If (OUTFILE ){
> If (! (Out = bio_new_file (OUTFILE, "WB "))){
> Bio_printf (bio_err, "error reading output file/N ");
> Err_print_errors (bio_err );
> Goto end;
>>}
>>} Else {
> Out = bio_new_fp (stdout, bio_noclose );
>># Ifdef openssl_sys_vms
>> {
> Bio * tmpbio = bio_new (bio_f_linebuffer ());
> Out = bio_push (tmpbio, out );
>>}
>># Endif
>>}
> Keysize = rsa_size (RSA );
> Rsa_in = (unsigned char *) openssl_malloc (keysize * 2 );
> Rsa_out = (unsigned char *) openssl_malloc (keysize );
>/* Read the input data */
> // Rsa_inlen = bio_read (in, rsa_in, keysize * 2 );
> Rsa_inlen = strlen (char *) indata );
> Strcpy (char *) rsa_in, (char *) indata );
> If (rsa_inlen <= 0 ){
> Bio_printf (bio_err, "error reading input data/N ");
> Exit (1 );
>>}
>
> If (REV ){
> Int I;
> Unsigned char CTMP;
> For (I = 0; I <rsa_inlen/2; I ++ ){
> CTMP = rsa_in [I];
> Rsa_in [I] = rsa_in [rsa_inlen-1-I];
> Rsa_in [rsa_inlen-1-I] = CTMP;
>>}
>>}
> Switch (rsa_mode ){
> Case rsa_verify:
> Rsa_outlen = rsa_public_decrypt (rsa_inlen, rsa_in, rsa_out, RSA, pad );
> Break;
> Case rsa_sign:
> Rsa_outlen = rsa_private_encrypt (rsa_inlen, rsa_in, rsa_out, RSA, pad );
> Break;
> Case rsa_encrypt:
> Rsa_outlen = rsa_public_encrypt (rsa_inlen, rsa_in, rsa_out, RSA, pad );
> Break;
> Case rsa_decrypt:
> Rsa_outlen = rsa_private_decrypt (rsa_inlen, rsa_in, rsa_out, RSA, pad );
> Break;
>>}
>
> If (rsa_outlen <= 0 ){
> Bio_printf (bio_err, "RSA operation error/N ");
> Err_print_errors (bio_err );
> Goto end;
>>}
> Memcpy (outdata, rsa_out, rsa_outlen );
> Outdata [rsa_outlen] = 0;
> Len = rsa_outlen;
>>// Cout <"% Len %" <Len <Endl;
> Ret = 0;
> If (asn1parse ){
> If (! Asn1_parse_dump (Out, rsa_out, rsa_outlen, 1,-1 )){
> Err_print_errors (bio_err );
>>}
>>} Else if (hexdump) bio_dump (Out, (char *) rsa_out, rsa_outlen );
> Else bio_write (Out, rsa_out, rsa_outlen );
> End:
> Rsa_free (RSA );
> Bio_free (in );
> Bio_free_all (out );
> If (rsa_in) openssl_free (rsa_in );
> If (rsa_out) openssl_free (rsa_out );
> If (passin) openssl_free (passin );
> Return ret;
>>}
>
> This function uses a pass in a buffer (indata), and implements CT a buffer
> (Outdata) Out. outdata contains encrypted data.
>
> Please help me! Thank you for your kind in advance.
>
> By the way, I wirte abve encryptdata function referring to RSA source code.
>
>
>
>
>
>
>
>> ________________________________
> Invite your mail contacts to join your friends list with Windows Live
> Spaces. It's easy! Try it!
>
>
>
> --
> Met vriendelijke groeten/best regards,
>
> Ger hobbelt
>
> --------------------------------------------------
> Web: http://www.hobbelt.com/
> Http://www.hebbut.net/
> Mail: ger@hobbelt.com
> Mobile: + 31-6-11 120 978

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.