1558604751
The only major differences between this and a regular TCP connection are the private Key and the public certificate that you’ll have to set into an option object.
The first step in this security process is the creation of a private Key. And what is this private key?
Basically, it’s a set of random noise that’s used to encrypt information. In theory, you could create one key, and use it to encrypt whatever you want. But it is best practice to have different keys for specific things. Because if someone steals your private key, it’s similar to having someone steal your house keys. Imagine if you used the same key to lock your car, garage, office, etc.
Private keys can be generated in multiple ways. The example below illustrates use of the OpenSSL command-line interface to generate a 1024-bit RSA private key:
openssl genrsa -out private-key.pem 1024
Once we have our private key, we can create a CSR (certificate signing request), which is our request to have the private key signed by a fancy authority. That is why you have to input information related to your company. This information will be seen by the signing authority, and used to verify you. In our case, it doesn’t matter what you type, since in the next step we’re going to sign our certificate ourselves.
The OpenSSL command-line interface can be used to generate a CSR for a private key:
openssl req -new -key private-key.pem -out csr.pem
Now that we have our paper work filled out, it’s time to pretend that we’re a cool signing authority.
openssl x509 -req -in csr.pem -signkey private-key.pem -out public-cert.pem
Now that you have the private key and the public cert, you can establish a secure connection between two NodeJS apps. And, as you can see in the example code, it is a very simple process. Important!
Since we created the public cert ourselves, in all honesty, our certificate is worthless, because we are nobodies. The NodeJS server won’t trust such a certificate by default, and that is why we need to tell it to actually trust our cert with the following option rejectUnauthorized: false. Very important: never set this variable to true in a production environment.
Here is an example of TLS socket server
'use strict';
var tls = require('tls');
var fs = require('fs');
const PORT = 1337;
const HOST = '127.0.0.1'
var options = {
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('public-cert.pem')
};
var server = tls.createServer(options, function(socket) {
// Send a friendly message
socket.write("I am the server sending you a message.");
// Print the data that we received
socket.on('data', function(data) {
console.log('Received: %s [it is %d bytes long]',
data.toString().replace(/(\n)/gm,""),
data.length); });
// Let us know when the transmission is over
socket.on('end', function() {
console.log('EOT (End Of Transmission)');
});
});
// Start listening on a specific port and address
server.listen(PORT, HOST, function() {
console.log("I'm listening at %s, on port %s", HOST, PORT);
});
// When an error occurs, show it.
server.on('error', function(error) {
console.error(error);
// Close the connection after the error occurred.
server.destroy();
});
Here is an example of TLS socket client
'use strict';
var tls = require('tls');
var fs = require('fs');
const PORT = 1337;
const HOST = '127.0.0.1'
// Pass the certs to the server and let it know to process even unauthorized certs.
var options = {
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('public-cert.pem'),
rejectUnauthorized: false
};
var client = tls.connect(PORT, HOST, options, function() {
// Check if the authorization worked
if (client.authorized) {
console.log("Connection authorized by a Certificate Authority.");
} else {
console.log("Connection not authorized: " + client.authorizationError)
}
// Send a friendly message
client.write("I am the client sending you a message.");
});
client.on("data", function(data) {
console.log('Received: %s [it is %d bytes long]',
data.toString().replace(/(\n)/gm,""),
data.length);
// Close the connection after receiving the message
client.end(); });
client.on('close', function() {
console.log("Connection closed"); });
// When an error ocoures, show it.
client.on('error', function(error) {
console.error(error);
// Close the connection after the error occurred.
client.destroy();
});
original publish on Nodefrost.com
Recommended Courses:
☞ Node.js Absolute Beginners Guide - Learn Node From Scratch
☞ Master Full-Stack Web Development | Node, SQL, React, & More
☞ Memory Based Learning Bootcamp: Node.js
☞ Code with Node: Learn by Doing
The only major differences between this and a regular TCP connection are the private Key and the public certificate that you’ll have to set into an option object.
The first step in this security process is the creation of a private Key. And what is this private key?
Basically, it’s a set of random noise that’s used to encrypt information. In theory, you could create one key, and use it to encrypt whatever you want. But it is best practice to have different keys for specific things. Because if someone steals your private key, it’s similar to having someone steal your house keys. Imagine if you used the same key to lock your car, garage, office, etc.
Private keys can be generated in multiple ways. The example below illustrates use of the OpenSSL command-line interface to generate a 1024-bit RSA private key:
openssl genrsa -out private-key.pem 1024
Once we have our private key, we can create a CSR (certificate signing request), which is our request to have the private key signed by a fancy authority. That is why you have to input information related to your company. This information will be seen by the signing authority, and used to verify you. In our case, it doesn’t matter what you type, since in the next step we’re going to sign our certificate ourselves.
The OpenSSL command-line interface can be used to generate a CSR for a private key:
openssl req -new -key private-key.pem -out csr.pem
Now that we have our paper work filled out, it’s time to pretend that we’re a cool signing authority.
openssl x509 -req -in csr.pem -signkey private-key.pem -out public-cert.pem
Now that you have the private key and the public cert, you can establish a secure connection between two NodeJS apps. And, as you can see in the example code, it is a very simple process. Important!
Since we created the public cert ourselves, in all honesty, our certificate is worthless, because we are nobodies. The NodeJS server won’t trust such a certificate by default, and that is why we need to tell it to actually trust our cert with the following option rejectUnauthorized: false. Very important: never set this variable to true in a production environment.
Here is an example of TLS socket server
'use strict';
var tls = require('tls');
var fs = require('fs');
const PORT = 1337;
const HOST = '127.0.0.1'
var options = {
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('public-cert.pem')
};
var server = tls.createServer(options, function(socket) {
// Send a friendly message
socket.write("I am the server sending you a message.");
// Print the data that we received
socket.on('data', function(data) {
console.log('Received: %s [it is %d bytes long]',
data.toString().replace(/(\n)/gm,""),
data.length); });
// Let us know when the transmission is over
socket.on('end', function() {
console.log('EOT (End Of Transmission)');
});
});
// Start listening on a specific port and address
server.listen(PORT, HOST, function() {
console.log("I'm listening at %s, on port %s", HOST, PORT);
});
// When an error occurs, show it.
server.on('error', function(error) {
console.error(error);
// Close the connection after the error occurred.
server.destroy();
});
Here is an example of TLS socket client
'use strict';
var tls = require('tls');
var fs = require('fs');
const PORT = 1337;
const HOST = '127.0.0.1'
// Pass the certs to the server and let it know to process even unauthorized certs.
var options = {
key: fs.readFileSync('private-key.pem'),
cert: fs.readFileSync('public-cert.pem'),
rejectUnauthorized: false
};
var client = tls.connect(PORT, HOST, options, function() {
// Check if the authorization worked
if (client.authorized) {
console.log("Connection authorized by a Certificate Authority.");
} else {
console.log("Connection not authorized: " + client.authorizationError)
}
// Send a friendly message
client.write("I am the client sending you a message.");
});
client.on("data", function(data) {
console.log('Received: %s [it is %d bytes long]',
data.toString().replace(/(\n)/gm,""),
data.length);
// Close the connection after receiving the message
client.end(); });
client.on('close', function() {
console.log("Connection closed"); });
// When an error ocoures, show it.
client.on('error', function(error) {
console.error(error);
// Close the connection after the error occurred.
client.destroy();
});
original publish on Nodefrost.com
Recommended Courses:
☞ Node.js Absolute Beginners Guide - Learn Node From Scratch
☞ Master Full-Stack Web Development | Node, SQL, React, & More
☞ Memory Based Learning Bootcamp: Node.js
☞ Code with Node: Learn by Doing
#node-js #nodejs #node #javascript
1597736283
Looking to build dynamic, extensively featured, and full-fledged web applications?
Hire NodeJs Developer to create a real-time, faster, and scalable application to accelerate your business. At HourlyDeveloper.io, we have a team of expert Node.JS developers, who have experience in working with Bootstrap, HTML5, & CSS, and also hold the knowledge of the most advanced frameworks and platforms.
Contact our experts: https://bit.ly/3hUdppS
#hire nodejs developer #nodejs developer #nodejs development company #nodejs development services #nodejs development #nodejs
1625843760
When installing Machine Learning Services in SQL Server by default few Python Packages are installed. In this article, we will have a look on how to get those installed python package information.
When we choose Python as Machine Learning Service during installation, the following packages are installed in SQL Server,
#machine learning #sql server #executing python in sql server #machine learning using python #machine learning with sql server #ml in sql server using python #python in sql server ml #python packages #python packages for machine learning services #sql server machine learning services
1596798540
When I was pretty beginners in the programming world and I began building the front-end applications, then constantly I was playing a puzzle in my mind that how I am alone can implement a complete application include client and server both, and if I want to implement that then I need to know the server-side technologies and it was not possible until one day I started developing both front-end and backend/server application.
Then I got to understand that I am going moving to be a full stack developer.
Nevertheless, that’s a really hard story of learning lots of different technologies so now I am going to share the conceptual summary of the client and server-side applications and how they interact with each other.
It is not so challenging for anyone to implement both client and server applications.
Before diving into developing applications immediately we should learn the communication concept within both applications and how to start developing both applications as a full stack developer without any difficulty.
This topic can be explained in several ways but I split it into three modules.
When it comes to the client, That can be any interface with or without UI where a user will be interacting or will perform serval operations and the result of those operations will be either fetching, generating, or **showing **some data.
“let’s not make it complex at all to understand the real-world example and use case.”
“The best case is where you reading this piece of information”
This is a web application and it is an example of a client where a user acts for searching the topic and the result of that is a particular write-up will be shown on the web page.
Let’s see examples of front end applications and what are the programming technologies are available for client-side development.
Client-side Technologies
Users can interact.
Users can request to see the data.
Users can change the data without knowing how it is happening internally.
Users can perform any action that changes shows, changes, or stores data.
“Who considers user understands how it is happening or not”
All the applications have the equivalent nature are client-side
Now there is no point in arguing on the technologies that we should consider Java and Python are client-side or server-side technologies.
If we design UI with them where the user interacts yeah we are using them as client-side languages.
#database #protocol #clients #servers #client-server
1600347600
This is part 3 of “MS SQL Server- Zero to Hero” and in this article, we will be discussing about the SCHEMAS in SQL SERVER. Before getting into this article, please consider to visit previous articles in this series from below,
In part one, we learned the basics of data, database, database management system, and types of DBMS and SQL.
#sql server #benefits of schemas #create schema in sql #database schemas #how to create schema in sql server #schemas #schemas in sql server #sql server schemas #what is schema in sql server
1590057960
Overview
In this tutorial, you will learn how to install Node onto Ubuntu 19.04 Disco Dingo. We will cover installation from the default repositories and, for those wanting more recent releases, how to install from the NodeSource repositories.
Installing from Ubuntu
The Ubuntu 19.04 Disco Dingo repository includes NodeJS version 10.15. Like most packages found here, it certainly is not the most recent release; however, if stability is more important than features, it will be your preferred choice.
#nodejs #nodejs 10.x #nodejs 11.x #nodejs 12.x #nodejs 8.x