OPENSSL-X509(1ossl)
๐ธ OPENSSL-X509(1ossl) ๐ธ
okay bestie, welcome to the certificate command. this is openssl-x509 from the OpenSSL fam โ it's giving "swiss army knife but make it a manpage" energy, and honestly? iconic. let's get into it ๐
โจ NAME โจ
openssl-x509 โ certificate display and signing command. that's the whole vibe. it shows you certs, it signs certs, it's a whole multihyphenate ๐
๐ฆ 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]
like yeah it's a lot. we'll get through it together ๐ซถ
๐ DESCRIPTION ๐
so this command is a multi-purpose certificate handling situation. it does so many things, and it does them well, no cap. here's the rundown:
- it prints certificate information ๐
- it converts certificates into various forms ๐
- it edits certificate trust settings ๐ ๏ธ
- it generates certificates from scratch, or from certification requests โ and then either self-signs them or signs them like a little "micro CA" ๐
certificates it generates bear X.509 version 3. periodt. and unless you say otherwise, key identifier extensions get included exactly as described in x509v3_config(5) โ that's just the default behaviour, iykyk.
and because there are soooo many options (like, an unhinged number), they're split up into various sections below so your brain doesn't melt ๐
๐ OPTIONS ๐
๐ Input, Output, and General Purpose Options
-helpโ prints out a usage message. tiny helpful king ๐-in filename|uriโ this picks the input to read a certificate from, or the input file to read a certificate request from if the-reqflag is being used. in both cases, this defaults to standard input.
heads up bestie: this option cannot be combined with the -new flag. they do not coexist, fr fr ๐
-passin argโ the key and certificate file password source. for the full tea on howargis formatted, go peek atopenssl-passphrase-options(1)๐-newโ generates a certificate from scratch, not using an input certificate or certificate request. so yes, this excludes the-inand-reqoptions entirely. instead, you need to give the-set_subjectoption. the public key that goes into it can be handed over with the-force_pubkeyoption, and it defaults to the key given with the-key(or-signkey) option โ which implies a self-signature โจ-x509toreqโ outputs a PKCS#10 certificate request instead of a certificate. the-key(or-signkey) option is required here to give the private key for self-signing; the corresponding public key gets placed in thesubjectPKInfofield. X.509 extensions that were in the certificate input are not copied by default. any X.509 extensions you actually want added can be specified using the-extfileoption.-reqโ by default a certificate is expected on input. with this option, a PKCS#10 certificate request is expected instead, and it must be correctly self-signed. X.509 extensions that were in the request are not copied by default. any X.509 extensions you want added can be specified using the-extfileoption.-copy_extensions argโ decides how X.509 extensions get handled when you're converting from a certificate to a request with the-x509toreqoption, or converting from a request to a certificate with the-reqoption. ifargisnone, or this option just isn't present, then extensions get ignored. ifargiscopyorcopyall, then all extensions are copied โ except that the subject identifier and authority key identifier extensions are not taken over when producing a certificate request. the-extoption can be used to further restrict which extensions actually get copied ๐ฏ-inform DER|PEMโ the input file format to use; by defaultPEMis tried first. seeopenssl-format-options(1)for the details.-vfyopt nm:vโ passes options along to the signature algorithm during verify operations. the names and values of these options are algorithm-specific, so it's giving "you'll know if you know" ๐คทโโ๏ธ-key filename|uriโ this one provides the private key for signing a new certificate or certificate request. unless-force_pubkeyis given, the corresponding public key gets placed in the new certificate or certificate request, which results in a self-signature.
this option cannot be used together with the -CA option. that's a hard no ๐
it sets the issuer name to the subject name (i.e., it makes the thing self-issued). and 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 the -not_before and -not_after options.
-signkey filename|uriโ this option is an alias of-key. same thing, different name, we love a rebrand ๐-keyform DER|PEM|P12|ENGINEโ the key input format; unspecified by default. seeopenssl-format-options(1)for details.-out filenameโ specifies the output filename to write to, or standard output by default.-outform DER|PEMโ the output format; the default isPEM. seeopenssl-format-options(1)for details.-nocertโ do not output a certificate (except for printing as requested by the options below). so it's a "print only, no cert" mood.-nooutโ this option prevents output, except for printing as requested by the options below. same energy, different flag ๐
๐ฆ Certificate Printing Options
note, bestie: the-aliasand-purposeoptions are also printing options, but they get described down in the "Trust Settings" section. just so you don't go looking for them here and get confused ๐ซถ
-dateoptโ specify the date output format. the values are:rfc_822andiso_8601. defaults torfc_822. ๐-textโ prints out the certificate in text form. full details get printed, including the public key, signature algorithms, issuer and subject names, serial number, any extensions present, and any trust settings. it's the full unboxing video, no skips โจ-certopt optionโ customises the print format used with-text. the option argument can be a single option, or multiple options separated by commas. the-certoptswitch may also be used more than once to set multiple options. see the "Text Printing Flags" section for more info.-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. it's basically the cert's government name ๐ซก-aliasโ prints the certificate"alias"(nickname), if any. cute.-serialโ prints the certificate serial number.-startdateโ prints out the start date of the certificate, that is thenotBeforedate.-enddateโ prints out the expiry date of the certificate, that is thenotAfterdate.-datesโ prints out the start and expiry dates of a certificate. two for one, we love efficiency ๐-subjectโ prints the subject name.-issuerโ prints the issuer name.-nameopt optionโ specifies how the subject or issuer names get displayed. seeopenssl-namedisplay-options(1)for the details.-emailโ prints the email address(es), if any.-hashโ synonym for-subject_hash, kept around for backward compatibility reasons. legacy queen ๐-subject_hashโ prints the"hash"of the certificate subject name. this is used in OpenSSL to form an index so certificates sitting in a directory can be looked up by subject name. very "let me find your file for you" of it ๐-subject_hash_oldโ prints the"hash"of the certificate subject name using the older algorithm, as used by OpenSSL before version1.0.0. throwback ๐ฐ๏ธ-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 version1.0.0.-ext extensionsโ prints out the certificate extensions in text form. can also be used to restrict which extensions get copied. extensions are specified with a comma separated string, e.g.,"subjectAltName, subjectKeyIdentifier". see thex509v3_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"inopenssl-verification-options(1). it's the vibe check for your cert ๐-pubkeyโ prints the certificate'sSubjectPublicKeyInfoblock in PEM format.-modulusโ 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 nextargseconds, and exits nonzero if yes, it will expire โ or zero if not. binary answer, no nuance, love that for us ๐-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-CAoptions. if used in conjunction with the-CAoption, the serial number file (as specified by the-CAserialoption) is not used. the serial number can be decimal, or hex if it's preceded by"0x". ๐ข-next_serialโ set the serial to be one more than the number in the certificate. math but make it certificate ๐-not_before dateโ lets the start date be explicitly set. the format of the date isYYMMDDHHMMSSZ(the same as an ASN1UTCTimestructure), orYYYYMMDDHHMMSSZ(the same as an ASN1GeneralizedTimestructure). in both formats, secondsSSand timezoneZmust be present. alternatively, you can also use"today". ๐
cannot be used together with the -preserve_dates option. pick a lane, bestie ๐
-not_afterdate โ okay so this one lets you literally just say when the cert expires โจ. The date format isYYMMDDHHMMSSZ(same shape as an ASN1 UTCTime structure) orYYYYMMDDHHMMSSZ(same shape as an ASN1 GeneralizedTime structure). In both formats the secondsSSand the timezoneZhave to be there โ no skipping them, bestie ๐ซถ. You can also just write"today"and call it a day.
๐ซ Cannot be used together with the-preserve_datesoption. Also heads up: this overrides the-daysoption.
-daysarg โ tells it how many days from today until a newly generated certificate expires. Default is30, cutie ๐.
๐ซ Cannot be used together with the-preserve_datesoption. And if the-not_afteroption is set, that explicit expiry date takes precedence โ it wins, periodt.
-preserve_datesโ when signing a certificate, this keeps the"notBefore"and"notAfter"dates of whatever input certificate you handed over, instead of adjusting them to current time and duration. Like, it respects the original vibe ๐ .
๐ซ Cannot be used together with the-days,-not_beforeand-not_afteroptions.
-set_issuerarg โ when a certificate is created, this sets its issuer name to the given value.
Peep -set_subject below for how the arg has to be formatted โ same rules, no cap.
-set_subjectarg โ when a certificate is created, this sets its subject name to the given value. And when the certificate is self-signed, the issuer name gets set to the same value too โ unless you also give-set_issuer, bestie ๐
The arg must be formatted as "/type0=value0/type1=value1/type2=...". Special characters can be escaped with "\" (backslash), and whitespace is retained. Empty values are permitted, but then that type just won't be included in the certificate. Giving a single "/" leads to an empty sequence of RDNs (a NULL-DN) โ iconic little edge case ๐. Multi-valued RDNs can be formed by putting a "+" character instead of a "/" between the AttributeValueAssertions (AVAs) that specify the members of the set. Example:
"/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 new certificate without providing an input certificate or certificate request. Slay, no input needed ๐.
-subjarg โ this one's just an alias of-set_subject. Same thing, shorter name, we love a nickname ๐.-force_pubkeyfilename โ when a new certificate or certificate request is created, this sets its public key to the given key instead of the key contained in the input or given with the-key(or-signkey) option. And if the input contains no public key but a private key, its public part is used ๐ฆ.
This option can be used in conjunction with -new and -set_subject to directly generate a certificate containing any desired public key. So good.
It's also 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. Big fan of a cert that knows what it is ๐ .
-clrextโ when transforming a certificate to 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 subject identifier nor authority key identifier extensions are included. Not up for discussion ๐ธ.
-extfilefilename โ configuration file containing certificate and request X.509 extensions to add โจ.-extensionssection โ the section in the extfile to add X.509 extensions from. If this option isn't specified, then the extensions should either be contained in the unnamed (default) section, or the default section should contain a variable called"extensions"which contains the section to use. Sneaky, but it works ๐ง.
See the x509v3_config(5) manual page for the details of the extension section format.
Unless specified otherwise, key identifier extensions are included as described in x509v3_config(5).
-sigoptnm:v โ passes options to the signature algorithm during sign operations. This option may be given multiple times ๐ฅ, and the names and values you provide using it are algorithm-specific.-badsigโ corrupts the signature before writing it; this can be useful for testing. Yes bestie, it's on purpose ๐.-digestโ the digest to use. This affects any signing or printing option that uses a message digest, such as the-fingerprint,-key, and-CAoptions. Any digest supported by theopenssl-dgst(1)command can be used. If you don't specify one, thenSHA1is used with-fingerprint, or the default digest for the signing algorithm is used โ typicallySHA256. Defaults doing their thing, we respect it ๐
๐ Micro-CA Options ๐
-CAfilename|uri โ specifies the"CA"certificate to be used for signing. When present, this behaves like a"micro CA"as follows: the subject name of the"CA"certificate is placed as issuer name in the new certificate, which is then signed using the"CA"key given as detailed below. Tiny CA, huge main character energy ๐โจ.
๐ซ This option cannot be used in conjunction with-key(or-signkey). This option is normally combined with the-reqoption referencing a CSR. Without the-reqoption, the input must be an existing certificate โ unless the-newoption is given, which generates a certificate from scratch. Fresh start, baby ๐ฆ.
-CAformDER|PEM|P12 โ the format for the CA certificate; unspecified by default. Seeopenssl-format-options(1)for details.-CAkeyfilename|uri โ sets the CA private key to sign a certificate with. The private key must match the public key of the certificate given with-CA. If this option isn't provided, then the key must be present in the-CAinput. No mismatches allowed, ngl ๐.-CAkeyformDER|PEM|P12|ENGINE โ the format for the CA key; unspecified by default. Seeopenssl-format-options(1)for details.-CAserialfilename โ sets the CA serial number file to use.
When creating a certificate with this option and with the -CA option, the certificate serial number is 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 this number, it's incremented and used, and the file is updated. Little counter that keeps on counting ๐ข.
The default filename consists of the CA certificate file 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 does not exist, a random number is generated โ and this is the recommended practice โจ.
-CAcreateserialโ with this option and the-CAoption, the CA serial number file is created if it doesn't exist. A random number is generated, used for the certificate, and saved into the serial number file determined as described above. Creation station ๐.
๐ธ Trust Settings ๐ธ
A trusted certificate is an ordinary certificate which has several additional pieces of information attached to it โ stuff like the permitted and prohibited uses of the certificate and possibly an "alias" (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. Root CA = the final boss ๐.
Trust settings currently are only used with a root CA. They allow finer control over the purposes the root CA can be used for. For example, a CA may be trusted for SSL client but not SSL server use. Selective trust, we love to see it ๐ .
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. Manifesting this fr fr.
-trustoutโ marks any certificate PEM output as a<trusted>certificate rather than ordinary. An ordinary or trusted certificate can be input, but by default an ordinary certificate is output and any trust settings are discarded. With the-trustoutoption, a trusted certificate is output. And a trusted certificate is automatically output if any trust settings are modified โ it just knows โจ.-setaliasarg โ 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. Reset button, go ๐ .-addtrustarg โ adds a trusted certificate use. Any object name can be used here, but currently onlyclientAuth,serverAuth,emailProtection, andanyExtendedKeyUsageare 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.-addrejectarg โ adds a prohibited trust anchor purpose. It accepts the same values as the-addtrustoption. Symmetry, bestie ๐ฆ.
โญ Generic options โญ
-randfiles,-writerandfile โ see"Random State Options"inopenssl(1)for details ๐ฒ.-engineid โ see"Engine Options"inopenssl(1).
๐ This option is deprecated. Like, old news.
-providername-provider-pathpath-provparam[name:]key=value-propquerypropq
See "Provider Options" in openssl(1), provider(7), and property(7). Provider gang ๐.
๐ 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. The default behaviour is to print all fields. Everything on, by default โจ.
compatibleโ use the old format. This is equivalent to specifying no printing options at all. Throwback vibes ๐ฆ.no_headerโ don't print header information: that is, 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 thenotBeforeandnotAfterfields.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 thatopenssl-ca(1)uses, and it's literally the same as settingno_issuer,no_pubkey,no_header, andno_versionall at once. slay ๐
๐ธ EXAMPLES ๐ธ
๐ Note: in these examples the '\' means the example should be all on one line. no cap, that's just the rule ๐
Print the contents of a certificate โ the classic "show me everything" move:
openssl x509 -in cert.pem -noout -text
Print the "Subject Alternative Name" extension of a certificate โ just the SAN, nothing extra:
openssl x509 -in cert.pem -noout -ext subjectAltName
Print more extensions of a certificate โ okay bestie, now we're asking for multiple:
openssl x509 -in cert.pem -noout -ext subjectAltName,nsCertType
Print the certificate serial number โ the cert's little ID number:
openssl x509 -in cert.pem -noout -serial
Print the certificate subject name โ who even is she:
openssl x509 -in cert.pem -noout -subject
Print the certificate subject name in RFC2253 form โ fancy formatting unlocked:
openssl x509 -in cert.pem -noout -subject -nameopt RFC2253
Print the certificate subject name in oneline form on a terminal supporting UTF8 โ cute little one-liner, UTF8-friendly:
openssl x509 -in cert.pem -noout -subject -nameopt oneline,-esc_msb
Print the certificate SHA1 fingerprint โ a whole SHA1 moment:
openssl x509 -sha1 -in cert.pem -noout -fingerprint
Convert a certificate from PEM to DER format โ glow-up from text to binary:
openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
Convert a certificate to a certificate request โ reverse uno card:
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 โ main character CA energy:
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 โ yes, we're signing with the CA we just made:
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" โ trust fall but make it certificate:
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. yeah, it's a whole legacy vibe ๐ญ
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. periodt, no duplicates ๐
๐ 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. bestie please double-check your flags, this is not a drill ๐
There should be options to explicitly set such things as start and end dates rather than an offset from the current time. lowkey yes, we deserve that ๐ค
๐ SEE ALSO ๐
openssl(1)openssl-req(1)openssl-ca(1)openssl-genrsa(1)openssl-gendsa(1)openssl-verify(1)x509v3_config(5)
๐ 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 gone right โจ
The -signkey option has been renamed to -key in OpenSSL 3.0, keeping the old name as an alias. iconic rebrand ngl ๐
The -engine option was deprecated in OpenSSL 3.0. rip bozo ๐ซถ
The -C option was removed in OpenSSL 3.0. gone, reduced to atoms ๐
Since OpenSSL 3.2, generated certificates bear X.509 version 3, and key identifier extensions are included by default. newer, shinier, very version-3 of them ๐
๐ COPYRIGHT ๐
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>. legal bestie stuff, but make it official ๐
okay bestie, that's the whole OPENSSL-X509(1ossl) page โ brought to you by OpenSSL 3.5.6, dated 2026-04-07 ๐โจ go forth and inspect those certs, ily ๐ซถ
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms