Generating self-signed certificates (2024)

If you don’t have access to a certificate authority (CA) for your organization and want to use OpenSearch for non-demo purposes, you can generate your own self-signed certificates using OpenSSL.

You can probably find OpenSSL in the package manager for your operating system.

On CentOS, use Yum:

sudo yum install openssl

On macOS, use Homebrew:

brew install openssl

Generate a private key

The first step in this process is to generate a private key using the openssl genrsa command. As the name suggests, you should keep this file private.

Private keys must be of sufficient length to be secure, so specify 2048:

openssl genrsa -out root-ca-key.pem 2048

You can optionally add the -aes256 option to encrypt the key using the AES-256 standard. This option requires a password.

Generate a root certificate

Next, use the private key to generate a self-signed certificate for the root CA:

openssl req -new -x509 -sha256 -key root-ca-key.pem -out root-ca.pem -days 730

The default -days value of 30 is only useful for testing purposes. This sample command specifies 730 (two years) for the certificate expiration date, but use whatever value makes sense for your organization.

  • The -x509 option specifies that you want a self-signed certificate rather than a certificate request.
  • The -sha256 option sets the hash algorithm to SHA-256. SHA-256 is the default in later versions of OpenSSL, but earlier versions might use SHA-1.

Follow the prompts to specify details for your organization. Together, these details form the distinguished name (DN) of your CA.

Generate an admin certificate

To generate an admin certificate, first create a new key:

openssl genrsa -out admin-key-temp.pem 2048

Then convert that key to PKCS#8 format for use in Java using a PKCS#12-compatible algorithm (3DES):

openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pem

Next, create a certificate signing request (CSR). This file acts as an application to a CA for a signed certificate:

openssl req -new -key admin-key.pem -out admin.csr

Follow the prompts to fill in the details. You don’t need to specify a challenge password. As noted in the OpenSSL Cookbook, “Having a challenge password does not increase the security of the CSR in any way.”

If you generate TLS certificates and have enabled hostname verification by setting plugins.security.ssl.transport.enforce_hostname_verification to true (default), be sure to specify a common name (CN) for each certificate signing request (CSR) that matches the corresponding DNS A record of the intended node.

If you want to use the same node certificate on all nodes (not recommended), set hostname verification to false. For more information, see Configure TLS certificates.

Now that the private key and signing request have been created, generate the certificate:

openssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem -days 730

Just like the root certificate, use the -days option to specify an expiration date of longer than 30 days.

(Optional) Generate node and client certificates

Similar to the steps in Generate an admin certificate, you will generate keys and CSRs with new file names for each node and as many client certificates as you need. For example, you might generate one client certificate for OpenSearch Dashboards and another for a Python client. Each certificate should use its own private key and should be generated from a unique CSR with matching SAN extension specific to the intended host. A SAN extension is not needed for the admin cert because that cert is not tied to a specific host.

To generate a node or client certificate, first create a new key:

openssl genrsa -out node1-key-temp.pem 2048

Then convert that key to PKCS#8 format for use in Java using a PKCS#12-compatible algorithm (3DES):

openssl pkcs8 -inform PEM -outform PEM -in node1-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node1-key.pem

Next, create the CSR:

openssl req -new -key node1-key.pem -out node1.csr

For all host and client certificates, you should specify a subject alternative name (SAN) to ensure compliance with RFC 2818 (HTTP Over TLS). The SAN should match the corresponding CN so that both refer to the same DNS A record.

Before generating a signed certificate, create a SAN extension file that describes the DNS A record for the host. If you’re connecting to a host that only has an IP address, either IPv4 or IPv6, use the IP syntax:

No IP

echo 'subjectAltName=DNS:node1.dns.a-record' > node1.ext

With IP

echo subjectAltName=IP:127.0.0.1 > node1.ext

With the DNS A record described, generate the certificate:

openssl x509 -req -in node1.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out node1.pem -days 730 -extfile node1.ext

Sample script to generate self-signed PEM certificates

If you already know the certificate details and don’t want to specify them interactively, use the -subj option in your root-ca.pem and CSR commands. This script creates a root certificate, admin certificate, two node certificates, and a client certificate, all with an expiration dates of two years (730 days):

#!/bin/sh# Root CAopenssl genrsa -out root-ca-key.pem 2048openssl req -new -x509 -sha256 -key root-ca-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=root.dns.a-record" -out root-ca.pem -days 730# Admin certopenssl genrsa -out admin-key-temp.pem 2048openssl pkcs8 -inform PEM -outform PEM -in admin-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out admin-key.pemopenssl req -new -key admin-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=A" -out admin.csropenssl x509 -req -in admin.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out admin.pem -days 730# Node cert 1openssl genrsa -out node1-key-temp.pem 2048openssl pkcs8 -inform PEM -outform PEM -in node1-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node1-key.pemopenssl req -new -key node1-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=node1.dns.a-record" -out node1.csrecho 'subjectAltName=DNS:node1.dns.a-record' > node1.extopenssl x509 -req -in node1.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out node1.pem -days 730 -extfile node1.ext# Node cert 2openssl genrsa -out node2-key-temp.pem 2048openssl pkcs8 -inform PEM -outform PEM -in node2-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out node2-key.pemopenssl req -new -key node2-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=node2.dns.a-record" -out node2.csrecho 'subjectAltName=DNS:node2.dns.a-record' > node2.extopenssl x509 -req -in node2.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out node2.pem -days 730 -extfile node2.ext# Client certopenssl genrsa -out client-key-temp.pem 2048openssl pkcs8 -inform PEM -outform PEM -in client-key-temp.pem -topk8 -nocrypt -v1 PBE-SHA1-3DES -out client-key.pemopenssl req -new -key client-key.pem -subj "/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=client.dns.a-record" -out client.csrecho 'subjectAltName=DNS:client.dns.a-record' > client.extopenssl x509 -req -in client.csr -CA root-ca.pem -CAkey root-ca-key.pem -CAcreateserial -sha256 -out client.pem -days 730 -extfile client.ext# Cleanuprm admin-key-temp.pemrm admin.csrrm node1-key-temp.pemrm node1.csrrm node1.extrm node2-key-temp.pemrm node2.csrrm node2.extrm client-key-temp.pemrm client.csrrm client.ext

Sample script to convert PEM certificates to keystore and truststore files

You can use the following script to generate a keystore and a truststore from the previously generated PEM certificates:

#!/bin/sh# Convert node certificatecat root-ca.pem node1.pem node1-key.pem > combined-node1.pemecho "Enter password for node1-cert.p12"openssl pkcs12 -export -in combined-node1.pem -out node1-cert.p12 -name node1echo "Enter password for keystore.jks"keytool -importkeystore -srckeystore node1-cert.p12 -srcstoretype pkcs12 -destkeystore keystore.jks# Convert admin certificatecat root-ca.pem admin.pem admin-key.pem > combined-admin.pemecho "Enter password for admin-cert.p12"openssl pkcs12 -export -in combined-admin.pem -out admin-cert.p12 -name adminecho "Enter password for keystore.jks"keytool -importkeystore -srckeystore admin-cert.p12 -srcstoretype pkcs12 -destkeystore keystore.jks# Import certificates to truststorekeytool -importcert -keystore truststore.jks -file root-ca.cer -storepass changeit -trustcacerts -deststoretype pkcs12# Cleanuprm combined-admin.pemrm combined-node1.pem

Add distinguished names to opensearch.yml

You must specify the distinguished names (DNs) for all admin and node certificates in opensearch.yml on all nodes. Using the certificates from the sample script above, part of opensearch.yml might look like this:

plugins.security.authcz.admin_dn: - 'CN=A,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'plugins.security.nodes_dn: - 'CN=node1.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA' - 'CN=node2.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'

But if you look at the subject of the certificate after creating it, you might see different formatting:

subject=/C=CA/ST=ONTARIO/L=TORONTO/O=ORG/OU=UNIT/CN=node1.dns.a-record

If you compare this string to the ones above, you can see that you need to invert the order of elements and use commas rather than slashes. Enter this command to get the correct string:

openssl x509 -subject -nameopt RFC2253 -noout -in node.pem

Then copy and paste the output into opensearch.yml.

Add certificate files to opensearch.yml

This process generates many files, but these are the ones you need to add to each node:

  • root-ca.pem
  • (Optional) admin.pem
  • (Optional) admin-key.pem
  • (Optional) node1.pem
  • (Optional) node1-key.pem

For most users, the admin.pem and admin-key.pem files only need to be added to the nodes you plan to run the securityadmin script or reload certificates from. For information about how to use the securityadmin script, see Applying changes to configuration files. If you intend to run the securityadmin script directly from a node, that node will need to have a copy of admin.pem and admin-key.pem on it.

On one node, the security configuration portion of opensearch.yml might look like this:

plugins.security.ssl.transport.pemcert_filepath: node1.pemplugins.security.ssl.transport.pemkey_filepath: node1-key.pemplugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pemplugins.security.ssl.transport.enforce_hostname_verification: falseplugins.security.ssl.http.enabled: trueplugins.security.ssl.http.pemcert_filepath: node1.pemplugins.security.ssl.http.pemkey_filepath: node1-key.pemplugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pemplugins.security.authcz.admin_dn: - 'CN=A,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'plugins.security.nodes_dn: - 'CN=node1.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA' - 'CN=node2.dns.a-record,OU=UNIT,O=ORG,L=TORONTO,ST=ONTARIO,C=CA'

For more information about adding and using these certificates in your own setup, see Configuring basic security settings for Docker, Configure TLS certificates, and Client certificate authentication.

OpenSearch Dashboards

For information on using your root CA and a client certificate to enable TLS for OpenSearch Dashboards, see Configure TLS for OpenSearch Dashboards.

Generating self-signed certificates (2024)

FAQs

Is self-signed certificate enough? ›

Self-signed TLS/SSL certificates are safe in a testing environment, and you can use them while you are waiting for your certificates to be issued by a public CA. But, using them in a production environment will significantly decrease the traffic to your website or application and lead to a lack of trust from users.

What is the problem with self-signed certificates? ›

Self-signed certificates are not inherently trusted by default, as they lack third-party verification and are not recognized by browsers or operating systems as trusted authorities.

How do I get rid of self-signed certificate warning? ›

Purchasing an SSL certificate from a Certificate Authority is the best way to remove the self-signed SSL certificate error/warning. SSL certificates have become very affordable where they can be obtained for as low as US$10.95 per year.

What is the limitation of self-signed certificate? ›

Self-signed certificates are highly risky for transaction or financial-related websites that handle memberships, subscriptions, or anything like that. Users become vulnerable to data theft and other cyberattacks when attackers create self-signed certificates that can be used in man-in-the-middle (MITM) attacks.

What is the alternative to self-signed certificates? ›

Safer Alternatives to Self-Signed Certificates

The safer choice, especially for public-facing services, is to use certificates from trusted CAs like SSL.com.

What is the point of a self-signed certificate? ›

The main advantage of a self-signed SSL certificate is that they are available at no cost and can be requested easily by any developer. They are able to quickly be implemented on your own timetable and are often used in internal testing environments or web servers that are otherwise locked down to external users.

Can self-signed certificate be verified? ›

When the certificate is presented for an entity to validate, they first verify the hash of the certificate matches the reference hash in the white-list, and if they match (indicating the self-signed certificate is the same as the one that was formerly trusted) then the certificate's validity dates can be trusted.

Can self-signed certificates be revoked? ›

Self-signed certificates cannot be revoked, which might allow an attacker to spoof an identity after a private key is compromised. CAs can revoke a compromised certificate, which prevents its further use.

Does a self-signed certificate have a private key? ›

A Self Signed Certificate (SSC) is an X. 509 (or similar) certificate that is not signed by a trusted Certificate Authority but instead is signed with its own private key. The purpose of a certificate is to provide trusted validation of identity or provide public keys for asymmetric encryption.

Can I make my own SSL certificate? ›

Technically, anyone can create their own SSL certificate by generating a public-private key pairing and including all the information mentioned above. Such certificates are called self-signed certificates because the digital signature used, instead of being from a CA, would be the website's own private key.

What is the biggest issue with a self-signed certificate? ›

Not trusted by browsers and users

Self-signed SSL certificates are not trusted by browsers, because they are generated by your servers, and not validated by trusted CAs, like Cloudflare and Go Daddy.

How to bypass a self-signed certificate? ›

Google Chrome

When accessing a page with a self-signed certificate, Chrome displays a warning page. To bypass this warning and proceed to the site, users can use one of two methods: Click on the "Advanced" link and then select the "Proceed to [Website Name] (unsafe)" option.

How do I mitigate SSL self-signed certificate? ›

The self-signed certificate can be mitigated by using a certificate from trusted CA and the certificates can be imported to switch using any of the following CLIs: download ssl ipaddress certificate ssl-cert cert_file. download ssl ipaddress privkey key_file.

Can a self-signed certificate be trusted? ›

Self-signed certificates are safe in a testing environment, and you can use them while you are waiting for your certificates officially signed by CAs. But, using them in a production environment leaves the systems exposed to vulnerabilities and security breaches.

Is self-signed certificate better than HTTP? ›

Self-signed certificates can work just as well as any other certificate, but it usually places the burden of verifying trust on the user. If the user is not going to actually verify that trust (or doesn't know how), using a self signed cert is only slightly better than unencrypted (and not worth the hassle IMHO).

Why should a CA signed certificate be used instead of a self-signed certificate? ›

DIFFERENCE BETWEEN SELF-SIGNED & CA CERTIFICATES:

Both self-signed and CA signed certificates provide encryption for data in motion. A CA-signed certificate also provides authentication - a level of assurance that the site is what it reports to be, and not an impostor website.

Top Articles
Woman's Home Journal · Rare Periodicals · Open Access Repository @ UPD
A Timeline of Blueface and Chrisean Rock's Relationship
Spn 1816 Fmi 9
Byrn Funeral Home Mayfield Kentucky Obituaries
craigslist: south coast jobs, apartments, for sale, services, community, and events
Truist Drive Through Hours
Catsweb Tx State
Moe Gangat Age
Craigslist Boats For Sale Seattle
Summoners War Update Notes
Lax Arrivals Volaris
Hoe kom ik bij mijn medische gegevens van de huisarts? - HKN Huisartsen
Learn2Serve Tabc Answers
Playgirl Magazine Cover Template Free
Mary Kay Lipstick Conversion Chart PDF Form - FormsPal
2016 Ford Fusion Belt Diagram
50 Shades Darker Movie 123Movies
Echat Fr Review Pc Retailer In Qatar Prestige Pc Providers – Alpha Marine Group
Mzinchaleft
Craigslist Mt Pleasant Sc
Barber Gym Quantico Hours
PCM.daily - Discussion Forum: Classique du Grand Duché
Sand Dollar Restaurant Anna Maria Island
Snohomish Hairmasters
Black Panther 2 Showtimes Near Epic Theatres Of Palm Coast
2004 Honda Odyssey Firing Order
Pioneer Library Overdrive
24 Hour Drive Thru Car Wash Near Me
Courtney Roberson Rob Dyrdek
2487872771
Roadtoutopiasweepstakes.con
Human Unitec International Inc (HMNU) Stock Price History Chart & Technical Analysis Graph - TipRanks.com
Texters Wish You Were Here
Scanning the Airwaves
KM to M (Kilometer to Meter) Converter, 1 km is 1000 m
Elizaveta Viktorovna Bout
Mcgiftcardmall.con
One Main Branch Locator
Busted Newspaper Campbell County KY Arrests
World Social Protection Report 2024-26: Universal social protection for climate action and a just transition
Homeloanserv Account Login
Subdomain Finder
VDJdb in 2019: database extension, new analysis infrastructure and a T-cell receptor motif compendium
4k Movie, Streaming, Blu-Ray Disc, and Home Theater Product Reviews & News
About Us
Darkglass Electronics The Exponent 500 Test
The Blackening Showtimes Near Ncg Cinema - Grand Blanc Trillium
The Quiet Girl Showtimes Near Landmark Plaza Frontenac
Is Chanel West Coast Pregnant Due Date
Bones And All Showtimes Near Emagine Canton
Asisn Massage Near Me
Die 10 wichtigsten Sehenswürdigkeiten in NYC, die Sie kennen sollten
Latest Posts
Article information

Author: Tyson Zemlak

Last Updated:

Views: 5816

Rating: 4.2 / 5 (63 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Tyson Zemlak

Birthday: 1992-03-17

Address: Apt. 662 96191 Quigley Dam, Kubview, MA 42013

Phone: +441678032891

Job: Community-Services Orchestrator

Hobby: Coffee roasting, Calligraphy, Metalworking, Fashion, Vehicle restoration, Shopping, Photography

Introduction: My name is Tyson Zemlak, I am a excited, light, sparkling, super, open, fair, magnificent person who loves writing and wants to share my knowledge and understanding with you.