DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • How to Implement Two-Factor Authentication in a Spring Boot OAuth Server? Part 1: Configuration
  • Full-Duplex Scalable Client-Server Communication with WebSockets and Spring Boot (Part I)
  • Develop a Secure CRUD Application Using Angular and Spring Boot
  • Strengthening Cybersecurity: The Role of Digital Certificates and PKI in Authentication

Trending

  • Docker Base Images Demystified: A Practical Guide
  • Optimizing Integration Workflows With Spark Structured Streaming and Cloud Services
  • Implementing API Design First in .NET for Efficient Development, Testing, and CI/CD
  • Apple and Anthropic Partner on AI-Powered Vibe-Coding Tool – Public Release TBD
  1. DZone
  2. Coding
  3. Frameworks
  4. Generating a Trusted SSL Certificate (Node Example)

Generating a Trusted SSL Certificate (Node Example)

By 
Dmitry Egorov user avatar
Dmitry Egorov
DZone Core CORE ·
Jan. 21, 20 · Tutorial
Likes (14)
Comment
Save
Tweet
Share
17.0K Views

Join the DZone community and get the full member experience.

Join For Free

An SSL Certificate is a file that helps browsers recognize that a domain name belongs to a server owner (as well as it's information like name, location, company, etc). 

So, if you host your website without certificates, browsers will show users that the site is unsafe and might block the site itself or disable video/audio on it.

Ways to Generate SSL Certificates

1. Self-Signed Certificate

Such a certificate also won't be trusted by browsers. And you would need to ask all users to add that certificate in a trusted list in your browser's settings. It might work only for internal users. Otherwise, users will see something like this:

Connection is not secure

Connection is not secure

2. Generate a Certificate Signed by a Certificate Authority 

The Let's Encrypt Foundation helps generate certificates that will be recognized as trusted in all browsers. In order to simplify certificate generation, you can use a fully automated service called certbot. Here's what you need to do to generate a certificate with cerbot:

  1. Attach your domain name to your server.
  2. Login to your server via ssh as root.
  3. Install certbot on your server and execute a set of commands.
  4. Wait until your certificate being recognized by browser (10 mins or so).
You may also like: Everything About HTTPS and SSL (Java).

Depending on your web server and operating system, you fill find the corresponding set of instructions in certbot's documentation.

Once you install certbot and execute the commands to generate your certificate, you will find certificate files in the /etc/letsencrypt/live/domain folder.

For your HTTPS server, you only need two files: cert.pem and privkey.pem. 

You can then use those files to create a secure server with Node.js with the following script:

JavaScript




x
14


 
1
var nodeStatic = require('node-static');
2
var https = require('https');
3
var file = new (nodeStatic.Server)();
4
const fs = require('fs');
5
 
          
6
const options = {
7
    key: fs.readFileSync('/etc/letsencrypt/live/domain/privkey.pem'),
8
    cert: fs.readFileSync('/etc/letsencrypt/live/domain/cert.pem')
9
};
10
 
          
11
var app  = https.createServer(options, function (req, res) {
12
    file.serve(req, res);
13
}).listen(443);



Save that file as server.js and execute it.

Plain Text




xxxxxxxxxx
1


 
1
node server.js 



Wait until your certificate is synchronized and open your website. Now, your connection should be trusted:

Secure connection

Secure connection


Further Reading

  • DZone Publication: DevSecOps Trend Report.
  • Authentication and Authorization: Mastering Security.
  • Tutorial: Secure Your Java App in 5 Minutes With OAuth 2.0.
  • Spring Boot Security + JWT ''Hello World'' Example.
security Spring Framework Web server Plain text Certificate authority Spring Boot Connection (dance) authentication HTTPS

Opinions expressed by DZone contributors are their own.

Related

  • How to Implement Two-Factor Authentication in a Spring Boot OAuth Server? Part 1: Configuration
  • Full-Duplex Scalable Client-Server Communication with WebSockets and Spring Boot (Part I)
  • Develop a Secure CRUD Application Using Angular and Spring Boot
  • Strengthening Cybersecurity: The Role of Digital Certificates and PKI in Authentication

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!