How to correctly use the c ++ module of Nodejs to link to OpenSSL and nodejsopenssl

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

How to correctly use the c ++ module of Nodejs to link to OpenSSL and nodejsopenssl

This is the reason. For some reason, I recently wrote the c ++ module of Nodejs and then called it on the js side. Network Communication is inseparable from ssl, so you need to link to the Openssl library.

We originally expected that the user needs to install the Openssl Runtime library, and then our c ++ module dynamically links to the so library of Openssl for running.

Everything looks good at first until we find that this openssl function cannot work:

PKCS7_sign ()
PKCS7_sign ()
We found that:

If our c ++ module is dynamically linked to the Openssl library, compilation is fine, but the error PKCS7_sign cannot be found during running.
If our c ++ module is statically linked to the Openssl library, compilation is fine, but the calling of this function does not work during runtime. the return value of this function is 0. an error occurs according to the document, but the error code obtained using the Openssl function ERR_get_error is also 0. indicates no error code.
In linux, what about Mac? I tried it on Mac and found that there was no problem with Mac. So I thought it could be a bug in Nodejs. Then I went to Nodejs and reported a bug to it: [https://github.com/joyent/node/issues/80268241]

At the same time, google searched for key words similar to nodejs linking to openssl.

Find the following 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

By searching, we found that Nodejs used the Openssl library itself, and it is assumed that nodejs's crypto module was also implemented using Openssl lib. this can be found from the node. js source code that contains all the latest Openssl source code.

Write the first article above: https://github.com/TooTallNate/node-gyp/wiki/Linking-to-OpenSSL that handsome guy is Nodejs developers.

Conclusion:

Nodejs uses Openssl
Before Nodejs 0.6, Nodejs was dynamically linked to the Openssl library. Later versions were static links.
Now I found that Node has replied to my bug: https://github.com/joyent/node/issues/8026

Node:

After the Node is compiled by itself, it clears unused symbols, so we cannot find the symbols at runtime. so they fixed the bug. all symbols are retained. this results in a Node size of 400 k.

Thanks to Node's quick response, I have to admire Node's activity level.


Are you using nodejs in your project? Windows

Node. js will be used in a new project. Windows client also intends to use node. js, the communication between the C-S by socket. io, almost similar to the tcp approach, basically not B/S application.

It is correct to open html directly, but the image is not displayed when it is opened with nodejs.

.. Images also belong to resources. You also need to map the image url to the route, read it through fs, and write the response.

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.