OPENSSL-X509(1ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

✨ NAME ✨

openssl-x509 β€” Certificate display and signing command. The manpage itself is OPENSSL-X509(1ossl), but we’re just gonna call it openssl-x509, bestie πŸ’…


🌈 SYNOPSIS 🌈

openssl x509 [-help] [-in filename|uri] [-passin arg] [-new]
[-x509toreq] [-req] [-copy_extensions arg] [-inform DER|PEM] [-vfyopt
nm:v] [-key filename|uri] [-keyform DER|PEM|P12|ENGINE] [-signkey
filename|uri] [-out filename] [-outform DER|PEM] [-nocert] [-noout]
[-dateopt] [-text] [-certopt option] [-fingerprint] [-alias] [-serial]
[-startdate] [-enddate] [-dates] [-subject] [-issuer] [-nameopt option]
[-email] [-hash] [-subject_hash] [-subject_hash_old] [-issuer_hash]
[-issuer_hash_old] [-ext extensions] [-ocspid] [-ocsp_uri] [-purpose]
[-pubkey] [-modulus] [-checkend num] [-checkhost host] [-checkemail
host] [-checkip ipaddr] [-set_serial n] [-next_serial] [-not_before
date] [-not_after date] [-days arg] [-preserve_dates] [-set_issuer arg]
[-set_subject arg] [-subj arg] [-force_pubkey filename] [-clrext]
[-extfile filename] [-extensions section] [-sigopt nm:v] [-badsig]
[-digest] [-CA filename|uri] [-CAform DER|PEM|P12] [-CAkey filename|uri]
[-CAkeyform DER|PEM|P12|ENGINE] [-CAserial filename] [-CAcreateserial]
[-trustout] [-setalias arg] [-clrtrust] [-addtrust arg] [-clrreject]
[-addreject arg] [-rand files] [-writerand file] [-engine id] [-provider
name] [-provider-path path] [-provparam [name:]key=value] [-propquery
propq]

πŸ’– DESCRIPTION πŸ’–

Okay so this command is the ultimate multi-purpose certificate-handling bestie. It can print certificate info, convert certs into various forms, edit certificate trust settings, generate certificates from scratch or from certification requests, and then self-sign them or sign them like a tiny β€œmicro CA”. Iconic, honestly πŸ‘‘

Generated certificates bear X.509 version 3. Unless specified otherwise, key identifier extensions are included as described in x509v3_config(5).

Because there are so many options, they’re split up into various sections. Buckle up, babe πŸŽ€


πŸ› οΈ OPTIONS πŸ› οΈ

🧰 Input, Output, and General Purpose Options 🧰

  • -help β€” Print out a usage message. Your little β€œwhat do I even do” lifeline 🫢
  • -in filename|uri β€” This specifies the input to read a certificate from, or the input file for reading a certificate request if the -req flag is used. In both cases this defaults to standard input.
Watch out: this option cannot be combined with the -new flag.
  • -passin arg β€” The key and certificate file password source. For more information about the format of arg, see openssl-passphrase-options(1).
  • -new β€” Generate a certificate from scratch, not using an input certificate or certificate request. So this excludes the -in and -req options. Instead, the -set_subject option needs to be given. The public key to include can be given with the -force_pubkey option and defaults to the key given with the -key (or -signkey) option, which implies self-signature. Fresh cert, no input drama ✨
  • -x509toreq β€” Output a PKCS#10 certificate request (rather than a certificate). The -key (or -signkey) option must be used to provide the private key for self-signing; the corresponding public key is placed in the subjectPKInfo field.

X.509 extensions included in a certificate input are not copied by default. X.509 extensions to be added can be specified using the -extfile option.

  • -req β€” By default a certificate is expected on input. With this option a PKCS#10 certificate request is expected instead, which must be correctly self-signed.

X.509 extensions included in the request are not copied by default. X.509 extensions to be added can be specified using the -extfile option.

  • -copy_extensions arg β€” Determines how to handle X.509 extensions when converting from a certificate to a request using the -x509toreq option, or converting from a request to a certificate using the -req option. If arg is none or this option is not present, then extensions are ignored. If arg is copy or copyall, then all extensions are copied, except that subject identifier and authority key identifier extensions are not taken over when producing a certificate request.

The -ext option can be used to further restrict which extensions to copy.

  • -inform DER|PEM β€” The input file format to use; by default PEM is tried first. See openssl-format-options(1) for details.
  • -vfyopt nm:v β€” Pass options to the signature algorithm during verify operations. Names and values of these options are algorithm-specific.
  • -key filename|uri β€” This option provides the private key for signing a new certificate or certificate request. Unless -force_pubkey is given, the corresponding public key is placed in the new certificate or certificate request, resulting in a self-signature.
No cap: this option cannot be used in conjunction with the -CA option.

It sets the issuer name to the subject name (i.e., makes it self-issued). Unless the -preserve_dates option is supplied, it sets the validity start date to the current time and the end date to a value determined by the -days option. Start date and end date can also be explicitly supplied with options -not_before and -not_after.

  • -signkey filename|uri β€” This option is an alias of -key. Same vibe, different name πŸ’«
  • -keyform DER|PEM|P12|ENGINE β€” The key input format; unspecified by default. See openssl-format-options(1) for details.
  • -out filename β€” This specifies the output filename to write to, or standard output by default.
  • -outform DER|PEM β€” The output format; the default is PEM. See openssl-format-options(1) for details.
  • -nocert β€” Do not output a certificate (except for printing as requested by below options).
  • -noout β€” This option prevents output except for printing as requested by below options.

πŸ–¨οΈ Certificate Printing Options πŸ–¨οΈ

Note: the -alias and -purpose options are also printing options but are described in the β€œTrust Settings” section.
  • -dateopt β€” Specify the date output format. Values are: rfc_822 and iso_8601. Defaults to rfc_822.
  • -text β€” Prints out the certificate in text form. Full details are printed, including the public key, signature algorithms, issuer and subject names, serial number, any extensions present, and any trust settings. It’s giving β€œtell me everything” πŸ”
  • -certopt option β€” Customise the print format used with -text. The option argument can be a single option or multiple options separated by commas. The -certopt switch may also be used more than once to set multiple options. See the β€œText Printing Flags” section for more information.
  • -fingerprint β€” Calculates and prints the digest of the DER encoded version of the entire certificate (see digest options). This is commonly called a β€œfingerprint”. Because of the nature of message digests, the fingerprint of a certificate is unique to that certificate, and two certificates with the same fingerprint can be considered to be the same.
  • -alias β€” Prints the certificate β€œalias” (nickname), if any.
  • -serial β€” Prints the certificate serial number.
  • -startdate β€” Prints out the start date of the certificate, that is the notBefore date.
  • -enddate β€” Prints out the expiry date of the certificate, that is the notAfter date.
  • -dates β€” Prints out the start and expiry dates of a certificate.
  • -subject β€” Prints the subject name.
  • -issuer β€” Prints the issuer name.
  • -nameopt option β€” This specifies how the subject or issuer names are displayed. See openssl-namedisplay-options(1) for details.
  • -email β€” Prints the email address(es) if any.
  • -hash β€” Synonym for -subject_hash for backward compatibility reasons.
  • -subject_hash β€” Prints the β€œhash” of the certificate subject name. This is used in OpenSSL to form an index to allow certificates in a directory to be looked up by subject name.
  • -subject_hash_old β€” Prints the β€œhash” of the certificate subject name using the older algorithm as used by OpenSSL before version 1.0.0.
  • -issuer_hash β€” Prints the β€œhash” of the certificate issuer name.
  • -issuer_hash_old β€” Prints the β€œhash” of the certificate issuer name using the older algorithm as used by OpenSSL before version 1.0.0.
  • -ext extensions β€” Prints out the certificate extensions in text form. Can also be used to restrict which extensions to copy. Extensions are specified with a comma separated string, e.g., "subjectAltName, subjectKeyIdentifier". See the x509v3_config(5) manual page for the extension names.
  • -ocspid β€” Prints the OCSP hash values for the subject name and public key.
  • -ocsp_uri β€” Prints the OCSP responder address(es) if any.
  • -purpose β€” This option performs tests on the certificate extensions and outputs the results. For a more complete description see β€œCertificate Extensions” in openssl-verification-options(1).
  • -pubkey β€” Prints the certificate’s SubjectPublicKeyInfo block in PEM format.
  • -modulus β€” This option prints out the value of the modulus of the public key contained in the certificate.

πŸ”Ž Certificate Checking Options πŸ”Ž

  • -checkend arg β€” Checks if the certificate expires within the next arg seconds and exits nonzero if yes it will expire or zero if not.
  • -checkhost host β€” Check that the certificate matches the specified host.
  • -checkemail email β€” Check that the certificate matches the specified email address.
  • -checkip ipaddr β€” Check that the certificate matches the specified IP address.

πŸ“ Certificate Output Options πŸ“

  • -set_serial n β€” Specifies the serial number to use. This option can be used with the -key, -signkey, or -CA options. If used in conjunction with the -CA option, the serial number file (as specified by the -CAserial option) is not used.

The serial number can be decimal or hex (if preceded by 0x).

  • -next_serial β€” Set the serial to be one more than the number in the certificate.
  • -not_before date β€” This allows the start date to be explicitly set. The format of the date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure), or YYYYMMDDHHMMSSZ (the same as an ASN1 GeneralizedTime structure). In both formats, seconds SS and timezone Z must be present. Alternatively, you can also use "today".
Do not use this together with the -preserve_dates option.
  • -not_after date β€” okay so this one lets you hard-set the expiry date yourself, no defaulting, no vibes-based guessing πŸ’… The date format is YYMMDDHHMMSSZ (same shape as an ASN1 UTCTime structure) or YYYYMMDDHHMMSSZ (same shape as an ASN1 GeneralizedTime structure). In both formats the seconds SS and the timezone Z must be present β€” no skipping them, bestie, they're not optional. You can also literally just write "today" and it slays.
Heads up: you cannot use this together with the -preserve_dates option. Also, this one overrides the -days option. So don't be out here setting both and acting surprised πŸ™ˆ
  • -days arg β€” sets how many days from today a freshly generated certificate stays valid before it expires. Default is 30 πŸŽ€
Cannot be used together with the -preserve_dates option. And if -not_after is set, that explicit expiry date wins. Periodt.
  • -preserve_dates β€” when you're signing a certificate, this keeps the notBefore and notAfter dates from any input certificate exactly as they are, instead of shifting them to the current time and duration. Iconic for when the original dates matter. Cannot be used together with the options -days, -not_before and -not_after 🚫
  • -set_issuer arg β€” when a certificate gets created, this sets its issuer name to whatever value you give it.

For how the arg has to be formatted, go look at -set_subject below β€” same rules, iykyk.

  • -set_subject arg β€” when a certificate is created, this sets its subject name to the value you give. And when the certificate is self-signed, the issuer name gets set to that same value too β€” unless you've also passed -set_issuer, which overrides it.

The arg must be formatted like this:

/type0=value0/type1=value1/type2=...

Special characters can be escaped with \ (backslash), and whitespace is retained (yes, really, it's kept 🌸). Empty values are permitted, but then the corresponding type just won't be included in the certificate. Giving a single / gives you an empty sequence of RDNs (a NULL-DN). Multi-valued RDNs get formed by putting a + character instead of a / between the AttributeValueAssertions (AVAs) that specify the members of the set. Example, bestie:

"/DC=org/DC=OpenSSL/DC=users/UID=123456+CN=John Doe"

This option can be used with the -new and -force_pubkey options to create a brand new certificate without providing an input certificate or certificate request. Main character energy: making something out of nothing ✨

  • -subj arg β€” this is just an alias of -set_subject. Same thing, shorter name, we love convenience πŸ’…
  • -force_pubkey filename β€” when a new certificate or certificate request is created, this sets its public key to the given key instead of the key sitting in the input or the one given with the -key (or -signkey) option. And if the input contains no public key but does contain a private key, its public part gets used.

This option can be used in conjunction with -new and -set_subject to directly generate a certificate containing literally any public key you want πŸ‘‘

It's also super useful for creating self-issued certificates that are not self-signed β€” for instance when the key can't be used for signing, such as DH.

  • -clrext β€” when you're transforming a certificate into a new certificate, by default all certificate extensions are retained. This option stops that.

When transforming a certificate or certificate request, -clrext prevents taking over any extensions from the source. And in any case, when producing a certificate request, neither the subject identifier nor the authority key identifier extensions are included. FYI, no cap 🫢

  • -extfile filename β€” the configuration file that holds the certificate and request X.509 extensions you want to add.
  • -extensions section β€” the section inside the extfile to pull the X.509 extensions from. If you don't specify this option, then the extensions should either be in the unnamed (default) section, or the default section should contain a variable called "extensions" that holds the name of the section to use.

For the details of what the extension section format looks like, see the x509v3_config(5) manual page πŸ“–

Unless specified otherwise, key identifier extensions are included as described in x509v3_config(5).

  • -sigopt nm:v β€” passes options to the signature algorithm during sign operations. You can give this option multiple times, no problem πŸ’œ Names and values you provide here are algorithm-specific.
  • -badsig β€” literally corrupts the signature before writing it out. This is useful for testing πŸ§ͺ (yes, deliberately breaking things, on purpose, for science).
  • -digest β€” the digest to use. This affects any signing or printing option that uses a message digest, such as the -fingerprint, -key, and -CA options. Any digest supported by the openssl-dgst(1) command works here. If you don't specify it, then SHA1 is used with -fingerprint, or the default digest for the signing algorithm is used β€” typically SHA256 ⭐

πŸŽ€ Micro-CA Options πŸŽ€

  • -CA filename|uri β€” specifies the "CA" certificate used for signing. When it's present, this behaves like a "micro CA", like so: the subject name of the "CA" certificate gets placed as the issuer name in the new certificate, which is then signed using the "CA" key given as detailed below πŸ‘‘
This option cannot be used in conjunction with -key (or -signkey). Not a vibe, don't do it.

This option is normally combined with the -req option referencing a CSR. Without the -req option, the input must be an existing certificate β€” unless the -new option is given, which generates a certificate from scratch 🌱

  • -CAform DER|PEM|P12, β€” the format for the CA certificate; unspecified by default. See openssl-format-options(1) for the details.
  • -CAkey filename|uri β€” sets the CA private key to sign a certificate with. This private key must match the public key of the certificate given with -CA. If you don't provide this option, then the key must already be present in the -CA input.
  • -CAkeyform DER|PEM|P12|ENGINE β€” the format for the CA key; unspecified by default. See openssl-format-options(1) for details.
  • -CAserial filename β€” sets the CA serial number file to use πŸ“„

When creating a certificate with this option and with the -CA option, the certificate serial number gets stored in the given file. This file consists of one line containing an even number of hex digits with the serial number used last time. After reading that number, it's incremented and used, and the file gets updated.

The default filename is the CA certificate file's base name with .srl appended. For example, if the CA certificate file is called mycacert.pem it expects to find a serial number file called mycacert.srl.

If the -CA option is specified and neither -CAserial nor -CAcreateserial is given, and the default serial number file doesn't exist, then a random number is generated β€” and this is the recommended practice ✨

  • -CAcreateserial β€” with this option and the -CA option, the CA serial number file gets created if it doesn't already exist. A random number is generated, used for the certificate, and saved into the serial number file determined as described above 🎲

πŸ’– Trust Settings πŸ’–

A trusted certificate is just an ordinary certificate that has several extra pieces of information attached to it β€” stuff like the permitted and prohibited uses of the certificate, and possibly an "alias" (a nickname).

Normally, when a certificate is being verified, at least one certificate must be "trusted". By default a trusted certificate must be stored locally and must be a root CA: any certificate chain ending in this CA is then usable for any purpose 🌈

Trust settings currently are only used with a root CA. They allow finer control over what purposes the root CA can be used for. For example, a CA may be trusted for SSL client but not SSL server use.

See openssl-verification-options(1) for more info on what trust settings actually mean πŸ‘€

Future versions of OpenSSL will recognize trust settings on any certificate β€” not just root CAs. Big changes coming, bestie.
  • -trustout β€” marks any certificate PEM output as a <trusted> certificate rather than ordinary. An ordinary or trusted certificate can both be input, but by default an ordinary certificate is output and any trust settings get discarded. With the -trustout option, a trusted certificate is output. Oh, and a trusted certificate is automatically output if any trust settings are modified πŸ’…
  • -setalias arg β€” sets the "alias" of the certificate. This lets the certificate be referred to using a nickname, for example "Steve's Certificate" πŸŽ€
  • -clrtrust β€” clears all the permitted or trusted uses of the certificate 🧹
  • -addtrust arg β€” adds a trusted certificate use. Any object name can go here, but currently only clientAuth, serverAuth, emailProtection, and anyExtendedKeyUsage are defined. As of OpenSSL 1.1.0, that last one blocks all purposes when rejected, or enables all purposes when trusted. Other OpenSSL applications may define additional uses πŸ‘‘
  • -clrreject β€” clears all the prohibited or rejected uses of the certificate 🧼
  • -addreject arg β€” adds a prohibited trust anchor purpose. It accepts the same values as the -addtrust option.

🌸 Generic options 🌸

  • -rand files, -writerand file β€” see "Random State Options" in openssl(1) for details 🎲
  • -engine id β€” see "Engine Options" in openssl(1). This option is deprecated ⚠️ (yes, we're retiring it, no drama).
  • -provider name
  • -provider-path path
  • -provparam [name:]key=value
  • -propquery propq

All four of those: see "Provider Options" in openssl(1), provider(7), and property(7) πŸ’œ


✨ Text Printing Flags ✨

As well as customising the name printing format, you can also customise the actual fields printed using the certopt option when the text option is present. Default behaviour is to print all the fields.

  • compatible β€” use the old format. This is equivalent to specifying no printing options at all.
  • no_header β€” don't print header information, i.e. the lines saying "Certificate" and "Data".
  • no_version β€” don't print out the version number.
  • no_serial β€” don't print out the serial number.
  • no_signame β€” don't print out the signature algorithm used.
  • no_validity β€” don't print the validity, that is the notBefore and notAfter fields.
  • no_subject β€” don't print out the subject name.
  • no_issuer β€” don't print out the issuer name.
  • no_pubkey β€” don't print out the public key.
  • no_sigdump β€” don't give a hexadecimal dump of the certificate signature.
  • no_aux β€” don't print out certificate trust information.
  • no_extensions β€” don't print out any X509V3 extensions.
  • ext_default β€” retain default extension behaviour: attempt to print out unsupported certificate extensions.
  • ext_error β€” print an error message for unsupported certificate extensions 🚨
  • ext_parse β€” ASN1 parse unsupported extensions.
  • ext_dump β€” hex dump unsupported extensions 🧚
  • ca_default β€” the value used by openssl-ca(1), equivalent to no_issuer, no_pubkey, no_header, and no_version.

✨ EXAMPLES ✨

Okay bestie, examples time β€” this is where it gets practical πŸ’– Tiny but crucial note: in these examples, the \ means the example should be all on one line.

Print the contents of a certificate:

openssl x509 -in cert.pem -noout -text

Print the β€œSubject Alternative Name” extension of a certificate:

openssl x509 -in cert.pem -noout -ext subjectAltName

Print more extensions of a certificate:

openssl x509 -in cert.pem -noout -ext subjectAltName,nsCertType

Print the certificate serial number:

openssl x509 -in cert.pem -noout -serial

Print the certificate subject name:

openssl x509 -in cert.pem -noout -subject

Print the certificate subject name in RFC2253 form:

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

Print the certificate subject name in oneline form on a terminal supporting UTF8:

openssl x509 -in cert.pem -noout -subject -nameopt oneline,-esc_msb

Print the certificate SHA1 fingerprint:

openssl x509 -sha1 -in cert.pem -noout -fingerprint

Convert a certificate from PEM to DER format:

openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER

Convert a certificate to a certificate request:

openssl x509 -x509toreq -in cert.pem -out req.pem -key key.pem

Convert a certificate request into a self-signed certificate using extensions for a CA:

openssl x509 -req -in careq.pem -extfile openssl.cnf -extensions v3_ca \
       -key key.pem -out cacert.pem

Sign a certificate request using the CA certificate above and add user certificate extensions:

openssl x509 -req -in req.pem -extfile openssl.cnf -extensions v3_usr \
       -CA cacert.pem -CAkey key.pem -CAcreateserial

Set a certificate to be trusted for SSL client use and change set its alias to β€œSteve's Class 1 CA”

openssl x509 -in cert.pem -addtrust clientAuth \
       -setalias "Steve's Class 1 CA" -out trust.pem

🌸 NOTES 🌸

The conversion to UTF8 format used with the name options assumes that T61Strings use the ISO8859-1 character set. This is wrong but Netscape and MSIE do this as do many certificates. So although this is incorrect it is more likely to print the majority of certificates correctly. Lowkey iconic mess, ngl 😭

The -email option searches the subject name and the subject alternative name extension. Only unique email addresses will be printed out: it will not print the same address more than once. No duplicates, periodt πŸ’…

πŸ’€ BUGS πŸ’€

It is possible to produce invalid certificates or requests by specifying the wrong private key, using unsuitable X.509 extensions, or using inconsistent options in some cases: these should be checked. Do not just send it and pray bestie, fr fr 😭

There should be options to explicitly set such things as start and end dates rather than an offset from the current time.

πŸ‘‘ SEE ALSO πŸ‘‘

πŸ¦‹ HISTORY πŸ¦‹

The hash algorithm used in the -subject_hash and -issuer_hash options before OpenSSL 1.0.0 was based on the deprecated MD5 algorithm and the encoding of the distinguished name. In OpenSSL 1.0.0 and later it is based on a canonical version of the DN using SHA1. This means that any directories using the old form must have their links rebuilt using openssl-rehash(1) or similar. Glow-up with consequences, honestly ✨

The -signkey option has been renamed to -key in OpenSSL 3.0, keeping the old name as an alias.

The -engine option was deprecated in OpenSSL 3.0.

The -C option was removed in OpenSSL 3.0.

Since OpenSSL 3.2, generated certificates bear X.509 version 3, and key identifier extensions are included by default.

Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the β€œLicense”). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at https://www.openssl.org/source/license.html.


That’s the whole page, bestie 🫢 This was OPENSSL-X509(1ossl), version 3.5.0, dated 2026-09-25 β€” slay and stay certified πŸ’…πŸŽ€

πŸ“¦ where this page comes from