Nodejs TLS is only encrypted, not authorized, further perfected

Source: Internet
Author: User

Const TLS = require (' TLS '); const FS = require (' FS '); const options = {    Key:fs.readFileSync (' My_key.pem '),    cert:f S.readfilesync (' My_cert.pem '),    //This was necessary only if using the client certificate authentication.    Requestcert:false,    //This was necessary only if the client uses the self-signed certificate.    CA: [Fs.readfilesync (' User_cert.pem ')]};const server = Tls.createserver (options, (socket) + = {    Console.log (' Server Connected ',        socket.authorized? ' Authorized ': ' Unauthorized ');    Socket.write (' welcome!\n ');    Socket.setencoding (' UTF8 ');    Socket.pipe (socket);}); Server.listen (8000, () = {    Console.log (' server Bound ');});

  

Const TLS = require (' TLS '); const FS = require (' FS '); const OPTIONS = {    //necessary only if using the client Certificat E Authentication    key:fs.readFileSync (' User_key.pem '),    cert:fs.readFileSync (' User_cert.pem '),    Rejectunauthorized:false,    //necessary only if the server uses the self-signed certificate    CA: [Fs.readfilesync ( ' My_cert.pem ')]};const socket = tls.connect (8000, options, () = {    Console.log (' Client Connected ',        Socket.authorized? ' Authorized ': ' Unauthorized ');    Process.stdin.pipe (socket);    Process.stdin.resume ();}); Socket.setencoding (' UTF8 '); Socket.on (' Data ', (data) = {    Console.log (data);}); Socket.on (' End ', () = {    server.close ();});

Key: Excerpted from Nodejs official documentation

-out ryans-key.pem 2048;
-new -sha256 -key ryans-key.pem -out ryans-csr.pem;
-req -in ryans-csr.pem -signkey ryans-key.pem -out ryans-cert.pem
 

Nodejs TLS is only encrypted, not authorized, further perfected

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.