How to use the Nodejs C + + module correctly to link to openssl_node.js

Source: Internet
Author: User
Tags openssl openssl lib openssl library joyent

The cause is this, for some reason, recently in the Write Nodejs C + + module, and then called in JS here. Network communication is naturally inseparable from SSL, so need to link to OpenSSL library.

Our original expectation was that the user would be required to install a OpenSSL runtime, and then our C + + module would dynamically link to OpenSSL's so library to run.

At first everything looked good until we found that the OpenSSL function was not working:

Pkcs7_sign ()
Pkcs7_sign ()
We found that:

If our C + + module and OpenSSL library dynamic Link, the compilation is no problem. But the run will appear: An error that the pkcs7_sign symbol cannot find.
If our C + + module and OpenSSL library static link, compile also no problem, but the runtime, call this function where there is no effect, this function return value is 0. The error is indicated by the document, but it is also 0 to get the error code with the OpenSSL function Err_get_error. Indicates no error code.
On Linux, what about the Mac? Try it with a Mac and find the Mac is fine. So, think of this may be a bug of Nodejs. Then he went to Nodejs and reported a bug to it: [Https://github.com/joyent/node/issues/8026][1]

At the same time, Google searched for Nodejs linking to OpenSSL similar keywords.

Find such a few articles:

Https://github.com/TooTallNate/node-gyp/wiki/Linking-to-OpenSSL

https://github.com/joyent/node/issues/3915

Http://serverfault.com/questions/338092/how-can-i-build-node-js-using-static-libssl-and-crypto-libraries

Https://github.com/robhawkes/node-extension/issues/1

Through the search, we found that the original Nodejs himself also used the OpenSSL library, speculated that Nodejs's own crypto module is also implemented using OpenSSL lib. This point from the source of Nodejs can be found, it contains the latest OpenSSL all the source code.

One of the first articles written above: Https://github.com/TooTallNate/node-gyp/wiki/Linking-to-OpenSSL's handsome man is a nodejs developer.

Basic conclusion:

Nodejs himself used OpenSSL.
Before Nodejs 0.6, Nodejs was dynamically linked to the Openssl library. and later versions are statically linked.
At this point I found that the Node has replied to my bug: https://github.com/joyent/node/issues/8026

Reason for Node explanation:

Node compiles itself and clears the symbols it doesn't use, so we can't find the symbol at run time. So they got rid of the bug. All symbols are preserved. This causes Node to be of a large volume of 400k.

Thanks to node's quick response, I have to admire node's active level. Praise.

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.