NAME
openssl — OpenSSL command line toolSYNOPSIS
openssl | command [command_opts] [command_args] |
openssl | list-standard-commands | list-message-digest-commands | list-cipher-commands | list-cipher-algorithms | list-message-digest-algorithms | list-public-key-algorithms |
openssl | no-XXX [arbitrary options] |
DESCRIPTION
OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL v3) and Transport Layer Security (TLS v1) network protocols and related cryptography standards required by them.'s
crypto library from the shell. It can be used for- Creation and management of private keys, public keys, and parameters
- Public key cryptographic operations
- Creation of X.509 certificates, CSRs and CRLs
- Calculation of Message Digests
- Encryption and Decryption with Ciphers
- SSL/TLS Client and Server Tests
- Handling of S/MIME signed or encrypted mail
- Time stamp requests, generation, and verification
COMMAND SUMMARY
The openssl program provides a rich variety of commands (command in the SYNOPSIS above), each of which often has a wealth of options and arguments (command_opts and command_args in the SYNOPSIS).from => to
STANDARD COMMANDS
- asn1parse
- Parse an ASN.1 sequence.
- ca
- Certificate Authority (CA) management.
- ciphers
- Cipher suite description determination.
- crl
- Certificate Revocation List (CRL) management.
- crl2pkcs7
- CRL to PKCS#7 conversion.
- dgst
- Message digest calculation.
- dh
- Diffie-Hellman parameter management. Obsoleted by dhparam.
- dhparam
- Generation and management of Diffie-Hellman parameters. Superseded by genpkey and pkeyparam.
- dsa
- DSA data management.
- dsaparam
- DSA parameter generation and management. Superseded by genpkey and pkeyparam.
- ec
- Elliptic curve (EC) key processing.
- ecparam
- EC parameter manipulation and generation.
- enc
- Encoding with ciphers.
- errstr
- Error number to error string conversion.
- gendh
- Generation of Diffie-Hellman parameters. Obsoleted by dhparam.
- gendsa
- Generation of DSA private key from parameters. Superseded by genpkey and pkey.
- genpkey
- Generation of private keys or parameters.
- genrsa
- Generation of RSA private key. Superseded by genpkey.
- nseq
- Create or examine a Netscape certificate sequence.
- ocsp
- Online Certificate Status Protocol utility.
- passwd
- Generation of hashed passwords.
- pkcs7
- PKCS#7 data management.
- pkcs8
- PKCS#8 data management.
- pkcs12
- PKCS#12 data management.
- pkey
- Public and private key management.
- pkeyparam
- Public key algorithm parameter management.
- pkeyutl
- Public key algorithm cryptographic operation utility.
- prime
- Generate prime numbers or test numbers for primality.
- rand
- Generate pseudo-random bytes.
- req
- PKCS#10 X.509 Certificate Signing Request (CSR) management.
- rsa
- RSA key management.
- rsautl
- RSA utility for signing, verification, encryption, and decryption. Superseded by pkeyutl.
- s_client
- This implements a generic SSL/TLS client which can establish a transparent connection to a remote server speaking SSL/TLS. It's intended for testing purposes only and provides only rudimentary interface functionality but internally uses mostly all functionality of the OpenSSL ssl library.
- s_server
- This implements a generic SSL/TLS server which accepts connections from remote clients speaking SSL/TLS. It's intended for testing purposes only and provides only rudimentary interface functionality but internally uses mostly all functionality of the OpenSSL ssl library. It provides both an own command line oriented protocol for testing SSL functions and a simple HTTP response facility to emulate an SSL/TLS-aware webserver.
- s_time
- SSL connection timer.
- sess_id
- SSL session data management.
- smime
- S/MIME mail processing.
- speed
- Algorithm speed measurement.
- spkac
- SPKAC printing and generating utility.
- ts
- Time stamping authority tool (client/server).
- verify
- X.509 certificate verification.
- version
- OpenSSL version information.
- x509
- X.509 certificate data management.
MESSAGE DIGEST COMMANDS
- gost-mac
- GOST-MAC digest.
- streebog256
- Streebog-256 digest.
- streebog512
- Streebog-512 digest.
- md_gost94
- GOST R 34.11-94 digest.
- md4
- MD4 digest.
- md5
- MD5 digest.
- ripemd160
- RIPEMD-160 digest.
- sha
- SHA digest.
- sha1
- SHA-1 digest.
- sha224
- SHA-224 digest.
- sha256
- SHA-256 digest.
- sha384
- SHA-384 digest.
- sha512
- SHA-512 digest.
- whirlpool
- Whirlpool digest.
ENCODING AND CIPHER COMMANDS
- aes-128-cbc | aes-128-ecb | aes-192-cbc | aes-192-ecb
- aes-256-cbc | aes-256-ecb
-
AES cipher.
- base64
-
Base64 encoding.
- bf | bf-cbc | bf-cfb | bf-ecb | bf-ofb
-
Blowfish cipher.
- cast | cast-cbc
-
CAST cipher.
- cast5-cbc | cast5-cfb | cast5-ecb | cast5-ofb
-
CAST5 cipher.
- des | des-cbc | des-cfb | des-ecb | des-ede | des-ede-cbc
- des-ede-cfb | des-ede-ofb | des-ofb
-
DES cipher.
- des3 | desx | des-ede3 | des-ede3-cbc | des-ede3-cfb | des-ede3-ofb
-
Triple DES cipher.
- rc2 | rc2-40-cbc | rc2-64-cbc | rc2-cbc | rc2-cfb | rc2-ecb | rc2-ofb
-
RC2 cipher.
- rc4 | rc4-40
- RC4 cipher.
PASS PHRASE ARGUMENTS
Several commands accept password arguments, typically using -passin and -passout for input and output passwords, respectively. These allow the password to be obtained from a variety of sources. Both of these options take a single argument whose format is described below. If no password argument is given and a password is required, then the user is prompted to enter one: this will typically be read from the current terminal with echoing turned off.- pass:password
- The actual password is password. Since the password is visible to utilities (like ps(1) under UNIX) this form should only be used where security is not important.
- env:var
- Obtain the password from the environment variable var. Since the environment of other processes is visible on certain platforms (e.g. ps(1) under certain UNIX OSes) this option should be used with caution.
- file:path
- The first line of path is the password. If the same path argument is supplied to -passin and -passout, then the first line will be used for the input password and the next line for the output password. path need not refer to a regular file: it could, for example, refer to a device or named pipe.
- fd:number
- Read the password from the file descriptor number. This can be used to send the data via a pipe for example.
- stdin
- Read the password from standard input.
ASN1PARSE
openssl asn1parse | [-i] [-dlimit number] [-dump] [-genconf file] [-genstr str] [-in file] [-inform DER | PEM | TXT] [-length number] [-noout] [-offset number] [-oid file] [-out file] [-strparse offset] |
- -dlimit number
- Dump the first number bytes of unknown data in hex form.
- -dump
- Dump unknown data in hex form.
- -genconf file, -genstr str
- Generate encoded data based on string str, file file, or both using ASN1_generate_nconf(3) format. If only file is present then the string is obtained from the default section using the name “asn1”. The encoded data is passed through the ASN1 parser and printed out as though it came from a file; the contents can thus be examined and written to a file using the -out option.
- -i
- Indents the output according to the “depth” of the structures.
- -in file
- The input file; default is standard input.
- -inform DER | PEM | TXT
- The input format. DER (Distinguished Encoding Rules) is binary format and PEM (Privacy Enhanced Mail), the default, is base64-encoded. TXT is plain text.
- -length number
- Number of bytes to parse; default is until end of file.
- -noout
- Don't output the parsed version of the input file.
- -offset number
- Starting offset to begin parsing; default is start of file.
- -oid file
- A file containing additional object identifiers (OIDs). The format of this file is described in the ASN1PARSE NOTES section below.
- -out file
- Output file to place the DER-encoded data into. If this option is not present, no encoded data will be output. This is most useful when combined with the -strparse option.
- -strparse offset
- Parse the content octets of the ASN.1 object starting at offset. This option can be used multiple times to “drill down” into a nested structure.
ASN1PARSE OUTPUT
The output will typically contain lines like this:0:d=0 hl=4 l= 681 cons: SEQUENCE ..... 229:d=3 hl=3 l= 141 prim: BIT STRING 373:d=2 hl=3 l= 162 cons: cont [ 3 ] 376:d=3 hl=3 l= 159 cons: SEQUENCE 379:d=4 hl=2 l= 29 cons: SEQUENCE 381:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Subject Key Identifier 386:d=5 hl=2 l= 22 prim: OCTET STRING 410:d=4 hl=2 l= 112 cons: SEQUENCE 412:d=5 hl=2 l= 3 prim: OBJECT :X509v3 Authority Key Identifier 417:d=5 hl=2 l= 105 prim: OCTET STRING 524:d=4 hl=2 l= 12 cons: SEQUENCE .....
0:d=0 hl=3 l= 137 cons: SEQUENCE 3:d=1 hl=3 l= 129 prim: INTEGER :E5D21E1F5C8D208EA7A2166C7FA F9F6BDF2059669C60876DDB70840F1A5AAFA59699FE471F379F1DD6A487E7D5409AB6A88D4A 9746E24B91D8CF55DB3521015460C8EDE44EE8A4189F7A7BE77D6CD3A9AF2696F486855CF58 BF0EDF2B4068058C7A947F52548DDF7E15E96B385F86422BEA9064A3EE9 135:d=1 hl=2 l= 3 prim: INTEGER :010001
ASN1PARSE NOTES
If an OID (object identifier) is not part of OpenSSL's
internal table it will be represented in numerical form (for example 1.2.3.4). The file passed to the -oid option allows additional OIDs to be included. Each line consists of three columns: the first column is the OID in numerical format and should be followed by whitespace. The second column is the “short name” which is a single word followed by whitespace. The final column is the rest of the line and is the “long name”. asn1parse displays the long name. Example:"1.2.3.4 shortname A long name"
ASN1 EXAMPLES
Parse a file:$ openssl asn1parse -in file.pem
$ openssl asn1parse -inform DER -in file.der
ASN1PARSE BUGS
There should be options to change the format of output lines. The output of some ASN.1 types is not well handled (if at all).CA
openssl ca | [-batch] [-cert file] [-config file] [-crl_CA_compromise time] [-crl_compromise time] [-crl_hold instruction] [-crl_reason reason] [-crldays days] [-crlexts section] [-crlhours hours] [-days arg] [-enddate date] [-extensions section] [-extfile section] [-gencrl] [-in file] [-infiles] [-key keyfile] [-keyfile arg] [-keyform PEM] [-md arg] [-msie_hack] [-name section] [-noemailDN] [-notext] [-out file] [-outdir dir] [-passin arg] [-policy arg] [-preserveDN] [-revoke file] [-spkac file] [-ss_cert file] [-startdate date] [-status serial] [-subj arg] [-updatedb] [-verbose] |
CA OPTIONS
- -batch
- This sets the batch mode. In this mode no questions will be asked and all certificates will be certified automatically.
- -cert file
- The CA certificate file.
- -config file
- Specifies the configuration file to use.
- -days arg
- The number of days to certify the certificate for.
- -enddate date
- This allows the expiry date to be explicitly set. The format of the date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
- -extensions section
- The section of the configuration file containing certificate extensions to be added when a certificate is issued (defaults to x509_extensions unless the -extfile option is used). If no extension section is present, a V1 certificate is created. If the extension section is present (even if it is empty), then a V3 certificate is created.
- -extfile file
- An additional configuration file to read certificate extensions from (using the default section unless the -extensions option is also used).
- -in file
- An input file containing a single certificate request to be signed by the CA.
- -infiles
- If present, this should be the last option; all subsequent arguments are assumed to be the names of files containing certificate requests.
- -key keyfile
- The password used to encrypt the private key. Since on some systems the command line arguments are visible (e.g. UNIX with the ps(1) utility) this option should be used with caution.
- -keyfile file
- The private key to sign requests with.
- -keyform PEM
- Private key file format.
- -md alg
- The message digest to use. Possible values include md5 and sha1. This option also applies to CRLs.
- -msie_hack
- This is a legacy option to make ca work with very old versions of the IE certificate enrollment control “certenr3”. It used UniversalStrings for almost everything. Since the old control has various security bugs, its use is strongly discouraged. The newer control “Xenroll” does not need this option.
- -name section
- Specifies the configuration file section to use (overrides default_ca in the ca section).
- -noemailDN
- The DN of a certificate can contain the EMAIL field if present in the request DN, however it is good policy just having the e-mail set into the altName extension of the certificate. When this option is set, the EMAIL field is removed from the certificate's subject and set only in the, eventually present, extensions. The email_in_dn keyword can be used in the configuration file to enable this behaviour.
- -notext
- Don't output the text form of a certificate to the output file.
- -out file
- The output file to output certificates to. The default is standard output. The certificate details will also be printed out to this file.
- -outdir directory
- The directory to output certificates to. The certificate will be written to a file consisting of the serial number in hex with “.pem” appended.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -policy arg
- This option defines the CA “policy” to use. This is a section in the configuration file which decides which fields should be mandatory or match the CA certificate. Check out the CA POLICY FORMAT section for more information.
- -preserveDN
- Normally, the DN order of a certificate is the same as the order of the fields in the relevant policy section. When this option is set, the order is the same as the request. This is largely for compatibility with the older IE enrollment control which would only accept certificates if their DNs matched the order of the request. This is not needed for Xenroll.
- -spkac file
- A file containing a single Netscape signed public key and challenge, and additional field values to be signed by the CA. See the SPKAC FORMAT section for information on the required format.
- -ss_cert file
- A single self-signed certificate to be signed by the CA.
- -startdate date
- This allows the start date to be explicitly set. The format of the date is YYMMDDHHMMSSZ (the same as an ASN1 UTCTime structure).
- -status serial
- Show status of certificate with serial number serial.
- -updatedb
- Update database for expired certificates.
- -verbose
- This prints extra details about the operations being performed.
CRL OPTIONS
- -crl_CA_compromise time
- This is the same as -crl_compromise, except the revocation reason is set to CACompromise.
- -crl_compromise time
- This sets the revocation reason to keyCompromise and the compromise time to time. time should be in GeneralizedTime format, i.e. YYYYMMDDHHMMSSZ.
- -crl_hold instruction
- This sets the CRL revocation reason code to certificateHold and the hold instruction to instruction which must be an OID. Although any OID can be used, only holdInstructionNone (the use of which is discouraged by RFC 2459), holdInstructionCallIssuer or holdInstructionReject will normally be used.
- -crl_reason reason
- Revocation reason, where reason is one of: unspecified, keyCompromise, CACompromise, affiliationChanged, superseded, cessationOfOperation, certificateHold or removeFromCRL. The matching of reason is case insensitive. Setting any revocation reason will make the CRL v2. In practice, removeFromCRL is not particularly useful because it is only used in delta CRLs which are not currently implemented.
- -crldays num
- The number of days before the next CRL is due. This is the days from now to place in the CRL nextUpdate field.
- -crlexts section
- The section of the configuration file containing CRL extensions to include. If no CRL extension section is present then a V1 CRL is created; if the CRL extension section is present (even if it is empty) then a V2 CRL is created. The CRL extensions specified are CRL extensions and not CRL entry extensions. It should be noted that some software (for example Netscape) can't handle V2 CRLs.
- -crlhours num
- The number of hours before the next CRL is due.
- -gencrl
- This option generates a CRL based on information in the index file.
- -revoke file
- A file containing a certificate to revoke.
- -subj arg
- Supersedes the subject name given in the request. The arg must be formatted as /type0=value0/type1=value1/type2=...; characters may be escaped by ‘\’ (backslash), no spaces are skipped.
CA CONFIGURATION FILE OPTIONS
The section of the configuration file containing options for ca is found as follows: If the -name command line option is used, then it names the section to be used. Otherwise the section to be used must be named in the default_ca option of the ca section of the configuration file (or in the default section of the configuration file). Besides default_ca, the following options are read directly from the ca section:- preserve
- msie_hack
- certificate
- The same as -cert. It gives the file containing the CA certificate. Mandatory.
- copy_extensions
-
Determines how extensions in certificate requests should be handled. If set to none or this option is not present, then extensions are ignored and not copied to the certificate. If set to copy, then any extensions present in the request that are not already present are copied to the certificate. If set to copyall, then all extensions in the request are copied to the certificate: if the extension is already present in the certificate it is deleted first. See the CA WARNINGS section before using this option.
- crl_extensions
- The same as -crlexts.
- crlnumber
- A text file containing the next CRL number to use in hex. The CRL number will be inserted in the CRLs only if this file exists. If this file is present, it must contain a valid CRL number.
- database
- The text database file to use. Mandatory. This file must be present, though initially it will be empty.
- default_crl_hours, default_crl_days
- The same as the -crlhours and -crldays options. These will only be used if neither command line option is present. At least one of these must be present to generate a CRL.
- default_days
- The same as the -days option. The number of days to certify a certificate for.
- default_enddate
- The same as the -enddate option. Either this option or default_days (or the command line equivalents) must be present.
- default_md
- The same as the -md option. The message digest to use. Mandatory.
- default_startdate
- The same as the -startdate option. The start date to certify a certificate for. If not set, the current time is used.
- email_in_dn
- The same as -noemailDN. If the EMAIL field is to be removed from the DN of the certificate, simply set this to “no”. If not present, the default is to allow for the EMAIL field in the certificate's DN.
- msie_hack
- The same as -msie_hack.
- name_opt, cert_opt
-
These options allow the format used to display the certificate details when asking the user to confirm signing. All the options supported by the x509 utilities' -nameopt and -certopt switches can be used here, except that no_signame and no_sigdump are permanently set and cannot be disabled (this is because the certificate signature cannot be displayed because the certificate has not been signed at this point).
- new_certs_dir
- The same as the -outdir command line option. It specifies the directory where new certificates will be placed. Mandatory.
- oid_file
- This specifies a file containing additional object identifiers. Each line of the file should consist of the numerical form of the object identifier followed by whitespace, then the short name followed by whitespace and finally the long name.
- oid_section
- This specifies a section in the configuration file containing extra object identifiers. Each line should consist of the short name of the object identifier followed by ‘=’ and the numerical form. The short and long names are the same when this option is used.
- policy
- The same as -policy. Mandatory. See the CA POLICY FORMAT section for more information.
- preserve
- The same as -preserveDN.
- private_key
- Same as the -keyfile option. The file containing the CA private key. Mandatory.
- serial
- A text file containing the next serial number to use in hex. Mandatory. This file must be present and contain a valid serial number.
- unique_subject
- If the value yes is given, the valid certificate entries in the database must have unique subjects. If the value no is given, several valid certificate entries may have the exact same subject. The default value is yes.
- x509_extensions
- The same as -extensions.
CA POLICY FORMAT
The policy section consists of a set of variables corresponding to certificate DN fields. If the value is “match”, then the field value must match the same field in the CA certificate. If the value is “supplied”, then it must be present. If the value is “optional”, then it may be present. Any fields not mentioned in the policy section are silently deleted, unless the -preserveDN option is set, but this can be regarded more of a quirk than intended behaviour.SPKAC FORMAT
The input to the -spkac command line option is a Netscape signed public key and challenge. This will usually come from the KEYGEN tag in an HTML form to create a new private key. It is, however, possible to create SPKACs using the spkac utility.CA EXAMPLES
Note: these examples assume that the ca directory structure is already set up and the relevant files already exist. This usually involves creating a CA certificate and private key with req, a serial number file and an empty index file and placing them in the relevant directories.$ openssl ca -in req.pem -out newcert.pem
$ openssl ca -in req.pem -extensions v3_ca -out newcert.pem
$ openssl ca -gencrl -out crl.pem
$ openssl ca -infiles req1.pem req2.pem req3.pem
$ openssl ca -spkac spkac.txt
SPKAC=MIG0MGAwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAn7PDhCeV/xIxUg8V70YRxK CN=Steve Test emailAddress=steve@openssl.org 0.OU=OpenSSL Group 1.OU=Another Group
[ ca ] default_ca = CA_default # The default ca section [ CA_default ] dir = ./demoCA # top dir database = $dir/index.txt # index file new_certs_dir = $dir/newcerts # new certs dir certificate = $dir/cacert.pem # The CA cert serial = $dir/serial # serial no file private_key = $dir/private/cakey.pem# CA private key default_days = 365 # how long to certify for default_crl_days= 30 # how long before next CRL default_md = md5 # md to use policy = policy_any # default policy email_in_dn = no # Don't add the email into cert DN name_opt = ca_default # Subject name display option cert_opt = ca_default # Certificate display option copy_extensions = none #Don't copy extensions from request [ policy_any ] countryName = supplied stateOrProvinceName = optional organizationName = optional organizationalUnitName = optional commonName = supplied emailAddress = optional
CA FILES
Note: the location of all files can change either by compile time options, configuration file entries, environment variables, or command line options. The values below reflect the default values./etc/ssl/openssl.cnf - master configuration file ./demoCA - main CA directory ./demoCA/cacert.pem - CA certificate ./demoCA/private/cakey.pem - CA private key ./demoCA/serial - CA serial number file ./demoCA/serial.old - CA serial number backup file ./demoCA/index.txt - CA text database file ./demoCA/index.txt.old - CA text database backup file ./demoCA/certs - certificate output file
CA ENVIRONMENT VARIABLES
OPENSSL_CONF reflects the location of the master configuration file; it can be overridden by the -config command line option.CA RESTRICTIONS
The text database index file is a critical part of the process, and if corrupted it can be difficult to fix. It is theoretically possible to rebuild the index file from all the issued certificates and a current CRL; however there is no option to do this.CA BUGS
The use of an in-memory text database can cause problems when large numbers of certificates are present because, as the name implies, the database has to be kept in memory.CA WARNINGS
The ca command is quirky and at times downright unfriendly.basicConstraints = CA:TRUE, pathlen:0
CIPHERS
openssl ciphers [-hVv] [-tls1] [cipherlist]- -h, -?
- Print a brief usage message.
- -tls1
- Only include TLS v1 ciphers.
- -V
- Like -v, but include cipher suite codes in output (hex format).
- -v
- Verbose option. List ciphers with a complete description of protocol version, key exchange, authentication, encryption and mac algorithms used along with any key size restrictions. Note that without the -v option, ciphers may seem to appear twice in a cipher list.
- cipherlist
- A cipher list to convert to a cipher preference list. If it is not included, the default cipher list will be used. The format is described below.
CIPHERS LIST FORMAT
The cipher list consists of one or more cipher strings separated by colons. Commas or spaces are also acceptable separators, but colons are normally used.CIPHERS STRINGS
The following is a list of all permitted cipher strings and their meanings.- DEFAULT
- The default cipher list. This is determined at compile time and is currently ALL:!aNULL:!eNULL:!SSLv2. This must be the first cipher string specified.
- COMPLEMENTOFDEFAULT
- The ciphers included in ALL, but not enabled by default. Currently this is ADH. Note that this rule does not cover eNULL, which is not included by ALL (use COMPLEMENTOFALL if necessary).
- ALL
- All cipher suites except the eNULL ciphers which must be explicitly enabled.
- COMPLEMENTOFALL
- The cipher suites not enabled by ALL, currently being eNULL.
- HIGH
- “High” encryption cipher suites. This currently means those with key lengths larger than 128 bits.
- MEDIUM
- “Medium” encryption cipher suites, currently those using 128-bit encryption.
- LOW
- “Low” encryption cipher suites, currently those using 64- or 56-bit encryption algorithms.
- eNULL, NULL
- The “NULL” ciphers; that is, those offering no encryption. Because these offer no encryption at all and are a security risk, they are disabled unless explicitly included.
- aNULL
- The cipher suites offering no authentication. This is currently the anonymous DH algorithms. These cipher suites are vulnerable to a “man in the middle” attack, so their use is normally discouraged.
- kRSA, RSA
- Cipher suites using RSA key exchange.
- kEDH
- Cipher suites using ephemeral DH key agreement.
- aRSA
- Cipher suites using RSA authentication, i.e. the certificates carry RSA keys.
- aDSS, DSS
- Cipher suites using DSS authentication, i.e. the certificates carry DSS keys.
- TLSv1
- TLS v1.0 cipher suites.
- DH
- Cipher suites using DH, including anonymous DH.
- ADH
- Anonymous DH cipher suites.
- AES
- Cipher suites using AES.
- 3DES
- Cipher suites using triple DES.
- DES
- Cipher suites using DES (not triple DES).
- RC4
- Cipher suites using RC4.
- CAMELLIA
- Cipher suites using Camellia.
- CHACHA20
- Cipher suites using ChaCha20.
- IDEA
- Cipher suites using IDEA.
- MD5
- Cipher suites using MD5.
- SHA1, SHA
- Cipher suites using SHA1.
CIPHERS EXAMPLES
Verbose listing of all OpenSSL ciphers including NULL ciphers:$ openssl ciphers -v 'ALL:eNULL'
$ openssl ciphers -v 'ALL:!ADH:@STRENGTH'
$ openssl ciphers -v '3DES:+RSA'
$ openssl ciphers -v 'RC4:!COMPLEMENTOFDEFAULT'
$ openssl ciphers -v 'RSA:!COMPLEMENTOFALL'
CRL
openssl crl | [-CAfile file] [-CApath dir] [-fingerprint] [-hash] [-in file] [-inform DER | PEM] [-issuer] [-lastupdate] [-nextupdate] [-noout] [-out file] [-outform DER | PEM] [-text] |
- -CAfile file
- Verify the signature on a CRL by looking up the issuing certificate in file.
- -CApath directory
- Verify the signature on a CRL by looking up the issuing certificate in dir. This directory must be a standard certificate directory, i.e. a hash of each subject name (using x509 -hash) should be linked to each certificate.
- -fingerprint
- Print the CRL fingerprint.
- -hash
- Output a hash of the issuer name. This can be used to look up CRLs in a directory by issuer name.
- -in file
- This specifies the input file to read from, or standard input if this option is not specified.
- -inform DER | PEM
- This specifies the input format. DER format is a DER-encoded CRL structure. PEM (the default) is a base64-encoded version of the DER form with header and footer lines.
- -issuer
- Output the issuer name.
- -lastupdate
- Output the lastUpdate field.
- -nextupdate
- Output the nextUpdate field.
- -noout
- Don't output the encoded version of the CRL.
- -out file
- Specifies the output file to write to, or standard output by default.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -text
- Print out the CRL in text form.
CRL NOTES
The PEM CRL format uses the header and footer lines:-----BEGIN X509 CRL----- -----END X509 CRL-----
CRL EXAMPLES
Convert a CRL file from PEM to DER:$ openssl crl -in crl.pem -outform DER -out crl.der
$ openssl crl -in crl.der -inform DER -text -noout
CRL BUGS
Ideally, it should be possible to create a CRL using appropriate options and files too.CRL2PKCS7
openssl crl2pkcs7 | [-certfile file] [-in file] [-inform DER | PEM] [-nocrl] [-out file] [-outform DER | PEM] |
- -certfile file
- Specifies a file containing one or more certificates in PEM format. All certificates in the file will be added to the PKCS#7 structure. This option can be used more than once to read certificates from multiple files.
- -in file
- This specifies the input file to read a CRL from, or standard input if this option is not specified.
- -inform DER | PEM
- This specifies the CRL input format. DER format is a DER-encoded CRL structure. PEM (the default) is a base64-encoded version of the DER form with header and footer lines.
- -nocrl
- Normally, a CRL is included in the output file. With this option, no CRL is included in the output file and a CRL is not read from the input file.
- -out file
- Specifies the output file to write the PKCS#7 structure to, or standard output by default.
- -outform DER | PEM
- This specifies the PKCS#7 structure output format. DER format is a DER-encoded PKCS#7 structure. PEM (the default) is a base64-encoded version of the DER form with header and footer lines.
CRL2PKCS7 EXAMPLES
Create a PKCS#7 structure from a certificate and CRL:$ openssl crl2pkcs7 -in crl.pem -certfile cert.pem -out p7.pem
$ openssl crl2pkcs7 -nocrl -certfile newcert.pem \ -certfile demoCA/cacert.pem -outform DER -out p7.der
CRL2PKCS7 NOTES
The output file is a PKCS#7 signed data structure containing no signers and just certificates and an optional CRL.DGST
openssl dgst | [-gost-mac | -streebog256 | -streebog512 | -md_gost94 | -md4 | -md5 | -ripemd160 | -sha1 | -sha224 | -sha256 | -sha384 | -sha512 | -whirlpool] [-binary] [-cd] [-hex] [-hmac key] [-keyform PEM] [-mac algorithm] [-macopt nm:v] [-out file] [-passin arg] [-prverify file] [-sign file] [-signature file] [-sigopt nm:v] [-verify file] [file ...] |
- -binary
- Output the digest or signature in binary form.
- -c
- Print out the digest in two-digit groups separated by colons; only relevant if hex format output is used.
- -d
- Print out BIO debugging information.
- -hex
- Digest is to be output as a hex dump. This is the default case for a “normal” digest as opposed to a digital signature.
- -hmac key
- Create a hashed MAC using key.
- -keyform PEM
- Specifies the key format to sign the digest with.
- -mac algorithm
- Create a keyed Message Authentication Code (MAC). The most popular MAC algorithm is HMAC (hash-based MAC), but there are other MAC algorithms which are not based on hash. MAC keys and other options should be set via the -macopt parameter.
- -macopt nm:v
-
Passes options to the MAC algorithm, specified by -mac. The following options are supported by HMAC:
- key:string
- Specifies the MAC key as an alphanumeric string (use if the key contain printable characters only). String length must conform to any restrictions of the MAC algorithm.
- hexkey:string
- Specifies the MAC key in hexadecimal form (two hex digits per byte). Key length must conform to any restrictions of the MAC algorithm.
- -out file
- The file to output to, or standard output by default.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -prverify file
- Verify the signature using the private key in file. The output is either “Verification OK” or “Verification Failure”.
- -sign file
- Digitally sign the digest using the private key in file.
- -signature file
- The actual signature to verify.
- -sigopt nm:v
- Pass options to the signature algorithm during sign or verify operations. The names and values of these options are algorithm-specific.
- -verify file
- Verify the signature using the public key in file. The output is either “Verification OK” or “Verification Failure”.
- file ...
- File or files to digest. If no files are specified then standard input is used.
DGST NOTES
The digest of choice for all new applications is SHA1. Other digests are, however, still widely used.DH
Diffie-Hellman Parameter Management. The dh command has been replaced by dhparam. See DHPARAM below.DHPARAM
openssl dhparam | [-2 | -5] [-C] [-check] [-dsaparam] [-in file] [-inform DER | PEM] [-noout] [-out file] [-outform DER | PEM] [-text] [numbits] |
- -2, -5
- The generator to use, either 2 or 5. 2 is the default. If present, the input file is ignored and parameters are generated instead.
- -C
-
This option converts the parameters into C code. The parameters can then be loaded by calling the get_dhnumbits
()
function. - -check
- Check the DH parameters.
- -dsaparam
-
If this option is used, DSA rather than DH parameters are read or created; they are converted to DH format. Otherwise, “strong” primes (such that (p-1)/2 is also prime) will be used for DH parameter generation.
- -in file
- This specifies the input file to read parameters from, or standard input if this option is not specified.
- -inform DER | PEM
- This specifies the input format. The argument DER uses an ASN1 DER-encoded form compatible with the PKCS#3 DHparameter structure. The PEM form is the default format: it consists of the DER format base64-encoded with additional header and footer lines.
- -noout
- This option inhibits the output of the encoded version of the parameters.
- numbits
- This argument specifies that a parameter set should be generated of size numbits. It must be the last option. If not present, a value of 2048 is used. If this value is present, the input file is ignored and parameters are generated instead.
- -out file
- This specifies the output file to write parameters to. Standard output is used if this option is not present. The output filename should not be the same as the input filename.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -text
- This option prints out the DH parameters in human readable form.
DHPARAM WARNINGS
The program dhparam combines the functionality of the programs dh and gendh in previous versions of OpenSSL and SSLeay. The dh and gendh programs are retained for now, but may have different purposes in future versions of OpenSSL.DHPARAM NOTES
PEM format DH parameters use the header and footer lines:-----BEGIN DH PARAMETERS----- -----END DH PARAMETERS-----
DHPARAM BUGS
There should be a way to generate and manipulate DH keys.DHPARAM HISTORY
The dhparam command was added in OpenSSL 0.9.5. The -dsaparam option was added in OpenSSL 0.9.6.DSA
openssl dsa | [-aes128 | -aes192 | -aes256 | -des | -des3] [-in file] [-inform DER | PEM] [-modulus] [-noout] [-out file] [-outform DER | PEM] [-passin arg] [-passout arg] [-pubin] [-pubout] [-text] |
- -aes128 | -aes192 | -aes256 | -des | -des3
- These options encrypt the private key with the AES, DES, or the triple DES ciphers, respectively, before outputting it. A pass phrase is prompted for. If none of these options is specified, the key is written in plain text. This means that using the dsa utility to read in an encrypted key with no encryption option can be used to remove the pass phrase from a key, or by setting the encryption options it can be use to add or change the pass phrase. These options can only be used with PEM format output files.
- -in file
- This specifies the input file to read a key from, or standard input if this option is not specified. If the key is encrypted, a pass phrase will be prompted for.
- -inform DER | PEM
-
This specifies the input format. The DER argument with a private key uses an ASN1 DER-encoded form of an ASN.1 SEQUENCE consisting of the values of version (currently zero), P, Q, G, and the public and private key components, respectively, as ASN.1 INTEGERs. When used with a public key it uses a SubjectPublicKeyInfo structure: it is an error if the key is not DSA.
- -modulus
- This option prints out the value of the public key component of the key.
- -noout
- This option prevents output of the encoded version of the key.
- -out file
- This specifies the output file to write a key to, or standard output if not specified. If any encryption options are set then a pass phrase will be prompted for. The output filename should not be the same as the input filename.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -pubin
- By default, a private key is read from the input file. With this option a public key is read instead.
- -pubout
- By default, a private key is output. With this option a public key will be output instead. This option is automatically set if the input is a public key.
- -text
- Prints out the public/private key components and parameters.
DSA NOTES
The PEM private key format uses the header and footer lines:-----BEGIN DSA PRIVATE KEY----- -----END DSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY----- -----END PUBLIC KEY-----
DSA EXAMPLES
To remove the pass phrase on a DSA private key:$ openssl dsa -in key.pem -out keyout.pem
$ openssl dsa -in key.pem -des3 -out keyout.pem
$ openssl dsa -in key.pem -outform DER -out keyout.der
$ openssl dsa -in key.pem -text -noout
$ openssl dsa -in key.pem -pubout -out pubkey.pem
DSAPARAM
openssl dsaparam | [-C] [-genkey] [-in file] [-inform DER | PEM] [-noout] [-out file] [-outform DER | PEM] [-text] [numbits] |
- -C
-
This option converts the parameters into C code. The parameters can then be loaded by calling the get_dsaXXX
()
function. - -genkey
- This option will generate a DSA either using the specified or generated parameters.
- -in file
- This specifies the input file to read parameters from, or standard input if this option is not specified. If the numbits parameter is included, then this option will be ignored.
- -inform DER | PEM
- This specifies the input format. The DER argument uses an ASN1 DER-encoded form compatible with RFC 2459 (PKIX) DSS-Parms that is a SEQUENCE consisting of p, q and g, respectively. The PEM form is the default format: it consists of the DER format base64-encoded with additional header and footer lines.
- -noout
- This option inhibits the output of the encoded version of the parameters.
- numbits
- This option specifies that a parameter set should be generated of size numbits. If this option is included, the input file (if any) is ignored.
- -out file
- This specifies the output file to write parameters to. Standard output is used if this option is not present. The output filename should not be the same as the input filename.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -text
- This option prints out the DSA parameters in human readable form.
DSAPARAM NOTES
PEM format DSA parameters use the header and footer lines:-----BEGIN DSA PARAMETERS----- -----END DSA PARAMETERS-----
EC
openssl ec | [-conv_form arg] [-des] [-des3] [-in file] [-inform DER | PEM] [-noout] [-out file] [-outform DER | PEM] [-param_enc arg] [-param_out] [-passin arg] [-passout arg] [-pubin] [-pubout] [-text] |
- -conv_form arg
- This specifies how the points on the elliptic curve are converted into octet strings. Possible values are: compressed (the default value), uncompressed, and hybrid. For more information regarding the point conversion forms please read the X9.62 standard. Note: Due to patent issues the compressed option is disabled by default for binary curves and can be enabled by defining the preprocessor macro OPENSSL_EC_BIN_PT_COMP at compile time.
- -des | -des3
- These options encrypt the private key with the DES, triple DES, or any other cipher supported by OpenSSL before outputting it. A pass phrase is prompted for. If none of these options is specified the key is written in plain text. This means that using the ec utility to read in an encrypted key with no encryption option can be used to remove the pass phrase from a key, or by setting the encryption options it can be use to add or change the pass phrase. These options can only be used with PEM format output files.
- -in file
- This specifies the input filename to read a key from, or standard input if this option is not specified. If the key is encrypted a pass phrase will be prompted for.
- -inform DER | PEM
- This specifies the input format. DER with a private key uses an ASN.1 DER-encoded SEC1 private key. When used with a public key it uses the SubjectPublicKeyInfo structure as specified in RFC 3280. PEM is the default format: it consists of the DER format base64 encoded with additional header and footer lines. In the case of a private key PKCS#8 format is also accepted.
- -noout
- Prevents output of the encoded version of the key.
- -out file
- Specifies the output filename to write a key to, or standard output if none is specified. If any encryption options are set then a pass phrase will be prompted for. The output filename should not be the same as the input filename.
- -outform DER | PEM
- This specifies the output format. The options have the same meaning as the -inform option.
- -param_enc arg
- This specifies how the elliptic curve parameters are encoded. Possible value are: named_curve, i.e. the EC parameters are specified by an OID; or explicit, where the EC parameters are explicitly given (see RFC 3279 for the definition of the EC parameter structures). The default value is named_curve. Note: the implicitlyCA alternative, as specified in RFC 3279, is currently not implemented in OpenSSL.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -pubin
- By default a private key is read from the input file; with this option a public key is read instead.
- -pubout
- By default a private key is output; with this option a public key is output instead. This option is automatically set if the input is a public key.
- -text
- Prints out the public/private key components and parameters.
EC NOTES
The PEM private key format uses the header and footer lines:-----BEGIN EC PRIVATE KEY----- -----END EC PRIVATE KEY-----
-----BEGIN PUBLIC KEY----- -----END PUBLIC KEY-----
EC EXAMPLES
To encrypt a private key using triple DES:$ openssl ec -in key.pem -des3 -out keyout.pem
$ openssl ec -in key.pem -outform DER -out keyout.der
$ openssl ec -in key.pem -text -noout
$ openssl ec -in key.pem -pubout -out pubkey.pem
$ openssl ec -in key.pem -param_enc explicit -out keyout.pem
$ openssl ec -in key.pem -conv_form compressed -out keyout.pem
EC HISTORY
The ec command was first introduced in OpenSSL 0.9.8.ECPARAM
openssl ecparam | [-C] [-check] [-conv_form arg] [-genkey] [-in file] [-inform DER | PEM] [-list_curves] [-name arg] [-no_seed] [-noout] [-out file] [-outform DER | PEM] [-param_enc arg] [-text] |
- -C
- Convert the EC parameters into C code. The parameters can then be loaded by calling the get_ec_group_XXX() function.
- -check
- Validate the elliptic curve parameters.
- -conv_form arg
- Specify how the points on the elliptic curve are converted into octet strings. Possible values are: compressed (the default value), uncompressed, and hybrid. For more information regarding the point conversion forms please read the X9.62 standard. Note: Due to patent issues the compressed option is disabled by default for binary curves and can be enabled by defining the preprocessor macro OPENSSL_EC_BIN_PT_COMP at compile time.
- -genkey
- Generate an EC private key using the specified parameters.
- -in file
- Specify the input filename to read parameters from or standard input if this option is not specified.
- -inform DER | PEM
- Specify the input format. DER uses an ASN.1 DER-encoded form compatible with RFC 3279 EcpkParameters. PEM is the default format: it consists of the DER format base64 encoded with additional header and footer lines.
- -list_curves
- Print out a list of all currently implemented EC parameter names and exit.
- -name arg
- Use the EC parameters with the specified 'short' name. Use -list_curves to get a list of all currently implemented EC parameters.
- -no_seed
- Inhibit that the 'seed' for the parameter generation is included in the ECParameters structure (see RFC 3279).
- -noout
- Inhibit the output of the encoded version of the parameters.
- -out file
- Specify the output filename parameters are written to. Standard output is used if this option is not present. The output filename should not be the same as the input filename.
- -outform DER | PEM
- Specify the output format; the parameters have the same meaning as the -inform option.
- -param_enc arg
- This specifies how the elliptic curve parameters are encoded. Possible value are: named_curve, i.e. the EC parameters are specified by an OID, or explicit, where the EC parameters are explicitly given (see RFC 3279 for the definition of the EC parameter structures). The default value is named_curve. Note: the implicitlyCA alternative, as specified in RFC 3279, is currently not implemented in OpenSSL.
- -text
- Print out the EC parameters in human readable form.
ECPARAM NOTES
PEM format EC parameters use the header and footer lines:-----BEGIN EC PARAMETERS----- -----END EC PARAMETERS-----
ECPARAM EXAMPLES
To create EC parameters with the group 'prime192v1':$ openssl ecparam -out ec_param.pem -name prime192v1
$ openssl ecparam -out ec_param.pem -name prime192v1 \ -param_enc explicit
$ openssl ecparam -in ec_param.pem -check
$ openssl ecparam -out ec_key.pem -name prime192v1 -genkey
$ openssl ecparam -in ec_in.pem -out ec_out.pem \ -conv_form compressed
$ openssl ecparam -in ec_param.pem -noout -text
ECPARAM HISTORY
The ecparam command was first introduced in OpenSSL 0.9.8.ENC
openssl enc | -ciphername [-AadePp] [-base64] [-bufsize number] [-debug] [-in file] [-iv IV] [-K key] [-k password] [-kfile file] [-md digest] [-none] [-nopad] [-nosalt] [-out file] [-pass arg] [-S salt] [-salt] |
- -A
- If the -a option is set, then base64 process the data on one line.
- -a, -base64
- Base64 process the data. This means that if encryption is taking place, the data is base64-encoded after encryption. If decryption is set, the input data is base64 decoded before being decrypted.
- -bufsize number
- Set the buffer size for I/O.
- -d
- Decrypt the input data.
- -debug
- Debug the BIOs used for I/O.
- -e
- Encrypt the input data: this is the default.
- -in file
- The input file; standard input by default.
- -iv IV
- The actual IV (initialisation vector) to use: this must be represented as a string comprised only of hex digits. When only the key is specified using the -K option, the IV must explicitly be defined. When a password is being specified using one of the other options, the IV is generated from this password.
- -K key
- The actual key to use: this must be represented as a string comprised only of hex digits. If only the key is specified, the IV must be additionally specified using the -iv option. When both a key and a password are specified, the key given with the -K option will be used and the IV generated from the password will be taken. It probably does not make much sense to specify both key and password.
- -k password
- The password to derive the key from. This is for compatibility with previous versions of OpenSSL. Superseded by the -pass option.
- -kfile file
- Read the password to derive the key from the first line of file. This is for compatibility with previous versions of OpenSSL. Superseded by the -pass option.
- -md digest
- Use digest to create a key from a pass phrase. digest may be one of “md5” or “sha1”.
- -none
- Use NULL cipher (no encryption or decryption of input).
- -nopad
- Disable standard block padding.
- -nosalt
- Don't use a salt in the key derivation routines. This option should NEVER be used unless compatibility with previous versions of OpenSSL or SSLeay is required.
- -out file
- The output file, standard output by default.
- -P
- Print out the salt, key, and IV used, then immediately exit; don't do any encryption or decryption.
- -p
- Print out the salt, key, and IV used.
- -pass arg
- The password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -S salt
- The actual salt to use: this must be represented as a string comprised only of hex digits.
- -salt
- Use a salt in the key derivation routines. This is the default.
ENC NOTES
The program can be called either as openssl ciphername or openssl enc -ciphername.ENC SUPPORTED CIPHERS
aes-[128|192|256]-cbc 128/192/256 bit AES in CBC mode aes-[128|192|256] Alias for aes-[128|192|256]-cbc aes-[128|192|256]-cfb 128/192/256 bit AES in 128 bit CFB mode aes-[128|192|256]-cfb1 128/192/256 bit AES in 1 bit CFB mode aes-[128|192|256]-cfb8 128/192/256 bit AES in 8 bit CFB mode aes-[128|192|256]-ecb 128/192/256 bit AES in ECB mode aes-[128|192|256]-ofb 128/192/256 bit AES in OFB mode base64 Base 64 bf Alias for bf-cbc bf-cbc Blowfish in CBC mode bf-cfb Blowfish in CFB mode bf-ecb Blowfish in ECB mode bf-ofb Blowfish in OFB mode cast Alias for cast-cbc cast-cbc CAST in CBC mode cast5-cbc CAST5 in CBC mode cast5-cfb CAST5 in CFB mode cast5-ecb CAST5 in ECB mode cast5-ofb CAST5 in OFB mode des Alias for des-cbc des-cbc DES in CBC mode des-cfb DES in CBC mode des-ecb DES in ECB mode des-ofb DES in OFB mode des-ede Two key triple DES EDE in ECB mode des-ede-cbc Two key triple DES EDE in CBC mode des-ede-cfb Two key triple DES EDE in CFB mode des-ede-ofb Two key triple DES EDE in OFB mode des3 Alias for des-ede3-cbc des-ede3 Three key triple DES EDE in ECB mode des-ede3-cbc Three key triple DES EDE in CBC mode des-ede3-cfb Three key triple DES EDE CFB mode des-ede3-ofb Three key triple DES EDE in OFB mode desx DESX algorithm rc2 Alias for rc2-cbc rc2-cbc 128-bit RC2 in CBC mode rc2-cfb 128-bit RC2 in CFB mode rc2-ecb 128-bit RC2 in ECB mode rc2-ofb 128-bit RC2 in OFB mode rc2-64-cbc 64-bit RC2 in CBC mode rc2-40-cbc 40-bit RC2 in CBC mode rc4 128-bit RC4 rc4-40 40-bit RC4
ENC EXAMPLES
Just base64 encode a binary file:$ openssl base64 -in file.bin -out file.b64
$ openssl base64 -d -in file.b64 -out file.bin
$ openssl des3 -salt -in file.txt -out file.des3
$ openssl des3 -d -in file.des3 -out file.txt -k mypassword
$ openssl bf -a -salt -in file.txt -out file.bf
$ openssl bf -d -a -in file.bf -out file.txt
ENC BUGS
The -A option when used with large files doesn't work properly.ERRSTR
openssl errstr [-stats] errno ...error:[error code]:[library name]:[function name]:[reason string]
- -stats
- Print debugging statistics about various aspects of the hash table.
ERRSTR EXAMPLES
The following error code:27594:error:2006D080:lib(32):func(109):reason(128):bss_file.c:107:
$ openssl errstr 2006D080
error:2006D080:BIO routines:BIO_new_file:no such file
GENDSA
openssl gendsa | [-aes128 | -aes192 | -aes256 | -des | -des3] [-out file] [paramfile] |
- -aes128 | -aes192 | -aes256 | -des | -des3
- These options encrypt the private key with the AES, DES, or the triple DES ciphers, respectively, before outputting it. A pass phrase is prompted for. If none of these options are specified, no encryption is used.
- -out file
- The output file. If this argument is not specified, standard output is used.
- paramfile
- This option specifies the DSA parameter file to use. The parameters in this file determine the size of the private key. DSA parameters can be generated and examined using the openssl dsaparam command.
GENDSA NOTES
DSA key generation is little more than random number generation so it is much quicker than RSA key generation, for example.GENPKEY
openssl genpkey | [-algorithm alg] [cipher] [-genparam] [-out file] [-outform DER | PEM] [-paramfile file] [-pass arg] [-pkeyopt opt:value] [-text] |
- -algorithm alg
- The public key algorithm to use, such as RSA, DSA, or DH. If used this option must precede any -pkeyopt options. The options -paramfile and -algorithm are mutually exclusive.
- cipher
- Encrypt the private key with the supplied cipher. Any algorithm name accepted by EVP_get_cipherbyname() is acceptable, such as des3.
- -genparam
- Generate a set of parameters instead of a private key. If used this option must precede any -algorithm, -paramfile, or -pkeyopt options.
- -out file
- The output filename. If this argument is not specified then standard output is used.
- -outform DER | PEM
- This specifies the output format, DER or PEM.
- -paramfile file
- Some public key algorithms generate a private key based on a set of parameters. They can be supplied using this option. If this option is used the public key algorithm used is determined by the parameters. If used this option must precede any -pkeyopt options. The options -paramfile and -algorithm are mutually exclusive.
- -pass arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -pkeyopt opt:value
- Set the public key algorithm option opt to value. The precise set of options supported depends on the public key algorithm used and its implementation. See GENPKEY KEY GENERATION OPTIONS below for more details.
- -text
- Print an (unencrypted) text representation of private and public keys and parameters along with the DER or PEM structure.
GENPKEY KEY GENERATION OPTIONS
The options supported by each algorithm and indeed each implementation of an algorithm can vary. The options for the OpenSSL implementations are detailed below.- rsa_keygen_bits:numbits
- (RSA) The number of bits in the generated key. If not specified 2048 is used.
- rsa_keygen_pubexp:value
- (RSA) The RSA public exponent value. This can be a large decimal or hexadecimal value if preceded by 0x. The default value is 65537.
- dsa_paramgen_bits:numbits
- (DSA) The number of bits in the generated parameters. If not specified 1024 is used.
- dh_paramgen_prime_len:numbits
- (DH) The number of bits in the prime parameter p.
- dh_paramgen_generator:value
- (DH) The value to use for the generator g.
- ec_paramgen_curve:curve
- (EC) The EC curve to use.
GENPKEY EXAMPLES
Generate an RSA private key using default parameters:$ openssl genpkey -algorithm RSA -out key.pem
$ openssl genpkey -algorithm RSA -out key.pem \ -aes-128-cbc -pass pass:hello
$ openssl genpkey -algorithm RSA -out key.pem \ -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:3
$ openssl genpkey -genparam -algorithm DSA \ -out dsap.pem -pkeyopt dsa_paramgen_bits:1024
$ openssl genpkey -paramfile dsap.pem -out dsakey.pem
$ openssl genpkey -genparam -algorithm DH \ -out dhp.pem -pkeyopt dh_paramgen_prime_len:1024
$ openssl genpkey -paramfile dhp.pem -out dhkey.pem
GENRSA
openssl genrsa | [-3 | -f4] [-aes128 | -aes192 | -aes256 | -des | -des3] [-out file] [-passout arg] [numbits] |
- -3 | -f4
- The public exponent to use, either 3 or 65537. The default is 65537.
- -aes128 | -aes192 | -aes256 | -des | -des3
- These options encrypt the private key with the AES, DES, or the triple DES ciphers, respectively, before outputting it. If none of these options are specified, no encryption is used. If encryption is used, a pass phrase is prompted for, if it is not supplied via the -passout option.
- -out file
- The output file. If this argument is not specified, standard output is used.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- numbits
- The size of the private key to generate in bits. This must be the last option specified. The default is 2048.
GENRSA NOTES
RSA private key generation essentially involves the generation of two prime numbers. When generating a private key, various symbols will be output to indicate the progress of the generation. A ‘.’ represents each number which has passed an initial sieve test; ‘+’ means a number has passed a single round of the Miller-Rabin primality test. A newline means that the number has passed all the prime tests (the actual number depends on the key size).GENRSA BUGS
A quirk of the prime generation algorithm is that it cannot generate small primes. Therefore the number of bits should not be less that 64. For typical private keys this will not matter because for security reasons they will be much larger (typically 2048 bits).NSEQ
openssl nseq [-in file] [-out file] [-toseq]- -in file
- This specifies the input file to read, or standard input if this option is not specified.
- -out file
- Specifies the output file, or standard output by default.
- -toseq
- Normally, a Netscape certificate sequence will be input and the output is the certificates contained in it. With the -toseq option the situation is reversed: a Netscape certificate sequence is created from a file of certificates.
NSEQ EXAMPLES
Output the certificates in a Netscape certificate sequence:$ openssl nseq -in nseq.pem -out certs.pem
$ openssl nseq -in certs.pem -toseq -out nseq.pem
NSEQ NOTES
The PEM-encoded form uses the same headers and footers as a certificate:-----BEGIN CERTIFICATE----- -----END CERTIFICATE-----
NSEQ BUGS
This program needs a few more options, like allowing DER or PEM input and output files and allowing multiple certificate files to be used.OCSP
openssl ocsp | [-CA file] [-CAfile file] [-CApath directory] [-cert file] [-dgst alg] [-host hostname:port] [-index indexfile] [-issuer file] [-ndays days] [-nmin minutes] [-no_cert_checks] [-no_cert_verify] [-no_certs] [-no_chain] [-no_intern] [-no_nonce] [-no_signature_verify] [-nonce] [-noverify] [-nrequest number] [-out file] [-path path] [-port portnum] [-req_text] [-reqin file] [-reqout file] [-resp_key_id] [-resp_no_certs] [-resp_text] [-respin file] [-respout file] [-rkey file] [-rother file] [-rsigner file] [-serial number] [-sign_other file] [-signer file] [-signkey file] [-status_age age] [-text] [-trust_other] [-url responder_url] [-VAfile file] [-validity_period nsec] [-verify_other file] |
- -CAfile file, -CApath directory
- file or path containing trusted CA certificates. These are used to verify the signature on the OCSP response.
- -cert file
- Add the certificate file to the request. The issuer certificate is taken from the previous -issuer option, or an error occurs if no issuer certificate is specified.
- -dgst alg
- Sets the digest algorithm to use for certificate identification in the OCSP request. By default SHA-1 is used.
- -host hostname:port, -path path
- If the -host option is present, then the OCSP request is sent to the host hostname on port port. -path specifies the HTTP path name to use, or ‘/’ by default.
- -issuer file
- This specifies the current issuer certificate. This option can be used multiple times. The certificate specified in file must be in PEM format. This option must come before any -cert options.
- -no_cert_checks
- Don't perform any additional checks on the OCSP response signer's certificate. That is, do not make any checks to see if the signer's certificate is authorised to provide the necessary status information: as a result this option should only be used for testing purposes.
- -no_cert_verify
- Don't verify the OCSP response signer's certificate at all. Since this option allows the OCSP response to be signed by any certificate, it should only be used for testing purposes.
- -no_certs
- Don't include any certificates in signed request.
- -no_chain
- Do not use certificates in the response as additional untrusted CA certificates.
- -no_intern
- Ignore certificates contained in the OCSP response when searching for the signer's certificate. With this option, the signer's certificate must be specified with either the -verify_other or -VAfile options.
- -no_signature_verify
- Don't check the signature on the OCSP response. Since this option tolerates invalid signatures on OCSP responses, it will normally only be used for testing purposes.
- -nonce, -no_nonce
- Add an OCSP nonce extension to a request or disable an OCSP nonce addition. Normally, if an OCSP request is input using the -respin option no nonce is added: using the -nonce option will force addition of a nonce. If an OCSP request is being created (using the -cert and -serial options) a nonce is automatically added; specifying -no_nonce overrides this.
- -noverify
- Don't attempt to verify the OCSP response signature or the nonce values. This option will normally only be used for debugging since it disables all verification of the responder's certificate.
- -out file
- Specify output file; default is standard output.
- -req_text, -resp_text, -text
- Print out the text form of the OCSP request, response, or both, respectively.
- -reqin file, -respin file
- Read an OCSP request or response file from file. These options are ignored if an OCSP request or response creation is implied by other options (for example with the -serial, -cert, and -host options).
- -reqout file, -respout file
- Write out the DER-encoded certificate request or response to file.
- -serial num
- Same as the -cert option except the certificate with serial number num is added to the request. The serial number is interpreted as a decimal integer unless preceded by ‘0x’. Negative integers can also be specified by preceding the value with a ‘-’ sign.
- -sign_other file
- Additional certificates to include in the signed request.
- -signer file, -signkey file
- Sign the OCSP request using the certificate specified in the -signer option and the private key specified by the -signkey option. If the -signkey option is not present, then the private key is read from the same file as the certificate. If neither option is specified, the OCSP request is not signed.
- -trust_other
- The certificates specified by the -verify_other option should be explicitly trusted and no additional checks will be performed on them. This is useful when the complete responder certificate chain is not available or trusting a root CA is not appropriate.
- -url responder_url
- Specify the responder URL. Both HTTP and HTTPS (SSL/TLS) URLs can be specified.
- -VAfile file
- file containing explicitly trusted responder certificates. Equivalent to the -verify_other and -trust_other options.
- -validity_period nsec, -status_age age
-
These options specify the range of times, in seconds, which will be tolerated in an OCSP response. Each certificate status response includes a notBefore time and an optional notAfter time. The current time should fall between these two values, but the interval between the two times may be only a few seconds. In practice the OCSP responder and clients' clocks may not be precisely synchronised and so such a check may fail. To avoid this the -validity_period option can be used to specify an acceptable error range in seconds, the default value is 5 minutes.
- -verify_other file
- file containing additional certificates to search when attempting to locate the OCSP response signing certificate. Some responders omit the actual signer's certificate from the response; this option can be used to supply the necessary certificate in such cases.
OCSP SERVER OPTIONS
- -CA file
- CA certificate corresponding to the revocation information in indexfile.
- -index indexfile
-
indexfile is a text index file in ca format containing certificate revocation information.
- -nmin minutes, -ndays days
- Number of minutes or days when fresh revocation information is available: used in the nextUpdate field. If neither option is present, the nextUpdate field is omitted, meaning fresh revocation information is immediately available.
- -nrequest number
- The OCSP server will exit after receiving number requests, default unlimited.
- -port portnum
- Port to listen for OCSP requests on. The port may also be specified using the -url option.
- -resp_key_id
- Identify the signer certificate using the key ID; default is to use the subject name.
- -resp_no_certs
- Don't include any certificates in the OCSP response.
- -rkey file
- The private key to sign OCSP responses with; if not present, the file specified in the -rsigner option is used.
- -rother file
- Additional certificates to include in the OCSP response.
- -rsigner file
- The certificate to sign OCSP responses with.
OCSP RESPONSE VERIFICATION
OCSP Response follows the rules specified in RFC 2560.$ openssl x509 -in ocspCA.pem -addtrust OCSPSigning \ -out trustedCA.pem
OCSP NOTES
As noted, most of the verify options are for testing or debugging purposes. Normally, only the -CApath, -CAfile and (if the responder is a `global VA') -VAfile options need to be used.OCSP EXAMPLES
Create an OCSP request and write it to a file:$ openssl ocsp -issuer issuer.pem -cert c1.pem -cert c2.pem \ -reqout req.der
$ openssl ocsp -issuer issuer.pem -cert c1.pem -cert c2.pem \ -url http://ocsp.myhost.com/ -resp_text -respout resp.der
$ openssl ocsp -respin resp.der -text
$ openssl ocsp -index demoCA/index.txt -port 8888 -rsigner \ rcert.pem -CA demoCA/cacert.pem -text -out log.txt
$ openssl ocsp -index demoCA/index.txt -port 8888 -rsigner \ rcert.pem -CA demoCA/cacert.pem -nrequest 1
$ openssl ocsp -index demoCA/index.txt -rsigner rcert.pem -CA \ demoCA/cacert.pem -issuer demoCA/cacert.pem -serial 1
$ openssl ocsp -index demoCA/index.txt -rsigner rcert.pem -CA \ demoCA/cacert.pem -reqin req.der -respout resp.der
PASSWD
openssl passwd | [-1 | -apr1 | -crypt] [-in file] [-noverify] [-quiet] [-reverse] [-salt string] [-stdin] [-table] [password] |
- -1
- Use the MD5 based BSD password algorithm 1.
- -apr1
- Use the apr1 algorithm (Apache variant of the) BSD algorithm.
- -crypt
- Use the crypt algorithm (default).
- -in file
- Read passwords from file.
- -noverify
- Don't verify when reading a password from the terminal.
- -quiet
- Don't output warnings when passwords given on the command line are truncated.
- -reverse
- Switch table columns. This only makes sense in conjunction with the -table option.
- -salt string
- Use the specified salt. When reading a password from the terminal, this implies -noverify.
- -stdin
- Read passwords from stdin.
- -table
- In the output list, prepend the cleartext password and a TAB character to each password hash.
PASSWD EXAMPLES
prints “xxj31ZMTZzkVA”.$ openssl passwd -crypt -salt xx password
prints “$1$xxxxxxxx$UYCIxa628.9qXjpQCjM4a.”.$ openssl passwd -1 -salt xxxxxxxx password
prints “$apr1$xxxxxxxx$dxHfLAsjHkDRmG83UXe8K0”.$ openssl passwd -apr1 -salt xxxxxxxx password
PKCS7
openssl pkcs7 | [-in file] [-inform DER | PEM] [-noout] [-out file] [-outform DER | PEM] [-print_certs] [-text] |
- -in file
- This specifies the input file to read from, or standard input if this option is not specified.
- -inform DER | PEM
- This specifies the input format. DER format is a DER-encoded PKCS#7 v1.5 structure. PEM (the default) is a base64-encoded version of the DER form with header and footer lines.
- -noout
- Don't output the encoded version of the PKCS#7 structure (or certificates if -print_certs is set).
- -out file
- Specifies the output file to write to, or standard output by default.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -print_certs
- Prints out any certificates or CRLs contained in the file. They are preceded by their subject and issuer names in a one-line format.
- -text
- Prints out certificate details in full rather than just subject and issuer names.
PKCS7 EXAMPLES
Convert a PKCS#7 file from PEM to DER:$ openssl pkcs7 -in file.pem -outform DER -out file.der
$ openssl pkcs7 -in file.pem -print_certs -out certs.pem
PKCS7 NOTES
The PEM PKCS#7 format uses the header and footer lines:-----BEGIN PKCS7----- -----END PKCS7-----
-----BEGIN CERTIFICATE----- -----END CERTIFICATE-----
PKCS7 RESTRICTIONS
There is no option to print out all the fields of a PKCS#7 file.PKCS8
openssl pkcs8 | [-embed] [-in file] [-inform DER | PEM] [-nocrypt] [-noiter] [-nooct] [-nsdb] [-out file] [-outform DER | PEM] [-passin arg] [-passout arg] [-topk8] [-v1 alg] [-v2 alg] |
- -embed
- This option generates DSA keys in a broken format. The DSA parameters are embedded inside the PrivateKey structure. In this form the OCTET STRING contains an ASN1 SEQUENCE consisting of two structures: a SEQUENCE containing the parameters and an ASN1 INTEGER containing the private key.
- -in file
- This specifies the input file to read a key from, or standard input if this option is not specified. If the key is encrypted, a pass phrase will be prompted for.
- -inform DER | PEM
- This specifies the input format. If a PKCS#8 format key is expected on input, then either a DER- or PEM-encoded version of a PKCS#8 key will be expected. Otherwise the DER or PEM format of the traditional format private key is used.
- -nocrypt
- PKCS#8 keys generated or input are normally PKCS#8 EncryptedPrivateKeyInfo structures using an appropriate password-based encryption algorithm. With this option, an unencrypted PrivateKeyInfo structure is expected or output. This option does not encrypt private keys at all and should only be used when absolutely necessary. Certain software such as some versions of Java code signing software use unencrypted private keys.
- -noiter
- Use an iteration count of 1. See the PKCS12 section below for a detailed explanation of this option.
- -nooct
- This option generates RSA private keys in a broken format that some software uses. Specifically the private key should be enclosed in an OCTET STRING, but some software just includes the structure itself without the surrounding OCTET STRING.
- -nsdb
- This option generates DSA keys in a broken format compatible with Netscape private key databases. The PrivateKey contains a SEQUENCE consisting of the public and private keys, respectively.
- -out file
- This specifies the output file to write a key to, or standard output by default. If any encryption options are set, a pass phrase will be prompted for. The output filename should not be the same as the input filename.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -topk8
- Normally, a PKCS#8 private key is expected on input and a traditional format private key will be written. With the -topk8 option the situation is reversed: it reads a traditional format private key and writes a PKCS#8 format key.
- -v1 alg
- This option specifies a PKCS#5 v1.5 or PKCS#12 algorithm to use. A complete list of possible algorithms is included below.
- -v2 alg
-
This option enables the use of PKCS#5 v2.0 algorithms. Normally, PKCS#8 private keys are encrypted with the password-based encryption algorithm called pbeWithMD5AndDES-CBC; this uses 56-bit DES encryption but it was the strongest encryption algorithm supported in PKCS#5 v1.5. Using the -v2 option PKCS#5 v2.0 algorithms are used which can use any encryption algorithm such as 168-bit triple DES or 128-bit RC2, however not many implementations support PKCS#5 v2.0 yet. If using private keys with OpenSSL then this doesn't matter.
PKCS8 NOTES
The encrypted form of a PEM-encoded PKCS#8 file uses the following headers and footers:-----BEGIN ENCRYPTED PRIVATE KEY----- -----END ENCRYPTED PRIVATE KEY-----
-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----
PKCS#5 V1.5 AND PKCS#12 ALGORITHMS
Various algorithms can be used with the -v1 command line option, including PKCS#5 v1.5 and PKCS#12. These are described in more detail below.- PBE-MD5-DES
-
These algorithms were included in the original PKCS#5 v1.5 specification. They only offer 56 bits of protection since they both use DES.
- PBE-SHA1-RC2-64 | PBE-MD5-RC2-64 | PBE-SHA1-DES
-
These algorithms are not mentioned in the original PKCS#5 v1.5 specification but they use the same key derivation algorithm and are supported by some software. They are mentioned in PKCS#5 v2.0. They use either 64-bit RC2 or 56-bit DES.
- PBE-SHA1-RC4-128 | PBE-SHA1-RC4-40 | PBE-SHA1-3DES | PBE-SHA1-2DES
- PBE-SHA1-RC2-128 | PBE-SHA1-RC2-40
- These algorithms use the PKCS#12 password-based encryption algorithm and allow strong encryption algorithms like triple DES or 128-bit RC2 to be used.
PKCS8 EXAMPLES
Convert a private key from traditional to PKCS#5 v2.0 format using triple DES:$ openssl pkcs8 -in key.pem -topk8 -v2 des3 -out enckey.pem
$ openssl pkcs8 -in key.pem -topk8 -out enckey.pem
$ openssl pkcs8 -in key.pem -topk8 -out enckey.pem \ -v1 PBE-SHA1-3DES
$ openssl pkcs8 -inform DER -nocrypt -in key.der -out key.pem
$ openssl pkcs8 -in pk8.pem -out key.pem
PKCS8 STANDARDS
Test vectors from this PKCS#5 v2.0 implementation were posted to the pkcs-tng mailing list using triple DES, DES and RC2 with high iteration counts; several people confirmed that they could decrypt the private keys produced and therefore it can be assumed that the PKCS#5 v2.0 implementation is reasonably accurate at least as far as these algorithms are concerned.'s
default DSA PKCS#8 private key format complies with this standard.PKCS8 BUGS
There should be an option that prints out the encryption algorithm in use and other details such as the iteration count.PKCS12
openssl pkcs12 | [-aes128 | -aes192 | -aes256 | -des | -des3] [-cacerts] [-CAfile file] [-caname name] [-CApath directory] [-certfile file] [-certpbe alg] [-chain] [-clcerts] [-CSP name] [-descert] [-export] [-in file] [-info] [-inkey file] [-keyex] [-keypbe alg] [-keysig] [-macalg alg] [-maciter] [-name name] [-nocerts] [-nodes] [-noiter] [-nokeys] [-nomac] [-nomaciter] [-nomacver] [-noout] [-out file] [-passin arg] [-passout arg] [-twopass] |
PKCS12 PARSING OPTIONS
- -aes128 | -aes192 | -aes256 | -des | -des3
- Use AES, DES, or triple DES, respectively, to encrypt private keys before outputting. The default is triple DES.
- -cacerts
- Only output CA certificates (not client certificates).
- -clcerts
- Only output client certificates (not CA certificates).
- -in file
- This specifies the file of the PKCS#12 file to be parsed. Standard input is used by default.
- -info
- Output additional information about the PKCS#12 file structure, algorithms used, and iteration counts.
- -nocerts
- No certificates at all will be output.
- -nodes
- Don't encrypt the private keys at all.
- -nokeys
- No private keys will be output.
- -nomacver
- Don't attempt to verify the integrity MAC before reading the file.
- -noout
- This option inhibits output of the keys and certificates to the output file version of the PKCS#12 file.
- -out file
- The file to write certificates and private keys to, standard output by default. They are all written in PEM format.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -twopass
- Prompt for separate integrity and encryption passwords: most software always assumes these are the same so this option will render such PKCS#12 files unreadable.
PKCS12 FILE CREATION OPTIONS
- -CAfile file
- CA storage as a file.
- -CApath directory
- CA storage as a directory. This directory must be a standard certificate directory: that is, a hash of each subject name (using x509 -hash) should be linked to each certificate.
- -caname name
- This specifies the “friendly name” for other certificates. This option may be used multiple times to specify names for all certificates in the order they appear. Netscape ignores friendly names on other certificates, whereas MSIE displays them.
- -certfile file
- A file to read additional certificates from.
- -certpbe alg, -keypbe alg
- These options allow the algorithm used to encrypt the private key and certificates to be selected. Any PKCS#5 v1.5 or PKCS#12 PBE algorithm name can be used (see the PKCS12 NOTES section for more information). If a cipher name (as output by the list-cipher-algorithms command) is specified then it is used with PKCS#5 v2.0. For interoperability reasons it is advisable to only use PKCS#12 algorithms.
- -chain
- If this option is present, an attempt is made to include the entire certificate chain of the user certificate. The standard CA store is used for this search. If the search fails, it is considered a fatal error.
- -CSP name
- Write name as a Microsoft CSP name.
- -descert
- Encrypt the certificate using triple DES; this may render the PKCS#12 file unreadable by some “export grade” software. By default, the private key is encrypted using triple DES and the certificate using 40-bit RC2.
- -export
- This option specifies that a PKCS#12 file will be created rather than parsed.
- -in file
- The file to read certificates and private keys from, standard input by default. They must all be in PEM format. The order doesn't matter but one private key and its corresponding certificate should be present. If additional certificates are present, they will also be included in the PKCS#12 file.
- -inkey file
- File to read private key from. If not present, a private key must be present in the input file.
- -keyex | -keysig
- Specifies that the private key is to be used for key exchange or just signing. This option is only interpreted by MSIE and similar MS software. Normally, “export grade” software will only allow 512-bit RSA keys to be used for encryption purposes, but arbitrary length keys for signing. The -keysig option marks the key for signing only. Signing only keys can be used for S/MIME signing, authenticode (ActiveX control signing) and SSL client authentication; however, due to a bug only MSIE 5.0 and later support the use of signing only keys for SSL client authentication.
- -macalg alg
- Specify the MAC digest algorithm. If not included then SHA1 is used.
- -maciter
- This option is included for compatibility with previous versions; it used to be needed to use MAC iterations counts but they are now used by default.
- -name name
- This specifies the “friendly name” for the certificate and private key. This name is typically displayed in list boxes by software importing the file.
- -nomac
- Don't attempt to provide the MAC integrity.
- -nomaciter, -noiter
-
These options affect the iteration counts on the MAC and key algorithms. Unless you wish to produce files compatible with MSIE 4.0, you should leave these options alone.
- -out file
- This specifies file to write the PKCS#12 file to. Standard output is used by default.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
PKCS12 NOTES
Although there are a large number of options, most of them are very rarely used. For PKCS#12 file parsing, only -in and -out need to be used for PKCS#12 file creation. -export and -name are also used.PKCS12 EXAMPLES
Parse a PKCS#12 file and output it to a file:$ openssl pkcs12 -in file.p12 -out file.pem
$ openssl pkcs12 -in file.p12 -clcerts -out file.pem
$ openssl pkcs12 -in file.p12 -out file.pem -nodes
$ openssl pkcs12 -in file.p12 -info -noout
$ openssl pkcs12 -export -in file.pem -out file.p12 \ -name "My Certificate"
$ openssl pkcs12 -export -in file.pem -out file.p12 \ -name "My Certificate" -certfile othercerts.pem
PKCS12 BUGS
Some would argue that the PKCS#12 standard is one big bug :-)$ old-openssl -in bad.p12 -out keycerts.pem $ openssl -in keycerts.pem -export -name "My PKCS#12 file" \ -out fixed.p12
PKEY
openssl pkey | [cipher] [-in file] [-inform DER | PEM] [-noout] [-out file] [-outform DER | PEM] [-passin arg] [-passout arg] [-pubin] [-pubout] [-text] [-text_pub] |
- cipher
- These options encrypt the private key with the supplied cipher. Any algorithm name accepted by EVP_get_cipherbyname() is acceptable, such as des3.
- -in file
- This specifies the input filename to read a key from, or standard input if this option is not specified. If the key is encrypted a pass phrase will be prompted for.
- -inform DER | PEM
- This specifies the input format, DER or PEM.
- -noout
- Do not output the encoded version of the key.
- -out file
- This specifies the output filename to write a key to, or standard output if this option is not specified. If any encryption options are set then a pass phrase will be prompted for. The output filename should not be the same as the input filename.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg see the PASS PHRASE ARGUMENTS section above.
- -pubin
- By default a private key is read from the input file: with this option a public key is read instead.
- -pubout
- By default a private key is output: with this option a public key will be output instead. This option is automatically set if the input is a public key.
- -text
- Print out the various public or private key components in plain text in addition to the encoded version.
- -text_pub
- Print out only public key components even if a private key is being processed.
PKEY EXAMPLES
To remove the pass phrase on an RSA private key:$ openssl pkey -in key.pem -out keyout.pem
$ openssl pkey -in key.pem -des3 -out keyout.pem
$ openssl pkey -in key.pem -outform DER -out keyout.der
$ openssl pkey -in key.pem -text -noout
$ openssl pkey -in key.pem -text_pub -noout
$ openssl pkey -in key.pem -pubout -out pubkey.pem
PKEYPARAM
openssl pkeyparam [-in file] [-noout] [-out file] [-text]- -in file
- This specifies the input filename to read parameters from, or standard input if this option is not specified.
- -noout
- Do not output the encoded version of the parameters.
- -out file
- This specifies the output filename to write parameters to, or standard output if this option is not specified.
- -text
- Prints out the parameters in plain text in addition to the encoded version.
PKEYPARAM NOTES
There are no -inform or -outform options for this command because only PEM format is supported because the key type is determined by the PEM headers.PKEYUTL
openssl pkeyutl | [-asn1parse] [-certin] [-decrypt] [-derive] [-encrypt] [-hexdump] [-in file] [-inkey file] [-keyform DER | PEM] [-out file] [-passin arg] [-peerform DER | PEM] [-peerkey file] [-pkeyopt opt:value] [-pubin] [-rev] [-sigfile file] [-sign] [-verify] [-verifyrecover] |
- -asn1parse
- ASN1parse the output data. This is useful when combined with the -verifyrecover option when an ASN1 structure is signed.
- -certin
- The input is a certificate containing a public key.
- -decrypt
- Decrypt the input data using a private key.
- -derive
- Derive a shared secret using the peer key.
- -encrypt
- Encrypt the input data using a public key.
- -hexdump
- Hex dump the output data.
- -in file
- Specify the input filename to read data from, or standard input if this option is not specified.
- -inkey file
- The input key file. By default it should be a private key.
- -keyform DER | PEM
- The key format DER or PEM.
- -out file
- Specify the output filename to write to, or standard output by default.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -peerform DER | PEM
- The peer key format DER or PEM.
- -peerkey file
- The peer key file, used by key derivation (agreement) operations.
- -pkeyopt opt:value
- Public key options.
- -pubin
- The input file is a public key.
- -rev
- Reverse the order of the input buffer. This is useful for some libraries (such as CryptoAPI) which represent the buffer in little endian format.
- -sigfile file
- Signature file (verify operation only).
- -sign
- Sign the input data and output the signed result. This requires a private key.
- -verify
- Verify the input data against the signature file and indicate if the verification succeeded or failed.
- -verifyrecover
- Verify the input data and output the recovered data.
PKEYUTL NOTES
The operations and options supported vary according to the key algorithm and its implementation. The OpenSSL operations and options are indicated below.RSA algorithm
The RSA algorithm supports the encrypt, decrypt, sign, verify, and verifyrecover operations in general. Some padding modes only support some of these operations however.- rsa_padding_mode:mode
-
This sets the RSA padding mode. Acceptable values for mode are pkcs1 for PKCS#1 padding; none for no padding; oaep for OAEP mode; x931 for X9.31 mode; and pss for PSS.
- rsa_pss_saltlen:len
- For pss mode only this option specifies the salt length. Two special values are supported: -1 sets the salt length to the digest length. When signing -2 sets the salt length to the maximum permissible value. When verifying -2 causes the salt length to be automatically determined based on the PSS block structure.
DSA algorithm
The DSA algorithm supports the sign and verify operations. Currently there are no additional options other than digest. Only the SHA1 digest can be used and this digest is assumed by default.DH algorithm
The DH algorithm supports the derive operation and no additional options.EC algorithm
The EC algorithm supports the sign, verify, and derive operations. The sign and verify operations use ECDSA and derive uses ECDH. Currently there are no additional options other than digest. Only the SHA1 digest can be used and this digest is assumed by default.PKEYUTL EXAMPLES
Sign some data using a private key:$ openssl pkeyutl -sign -in file -inkey key.pem -out sig
$ openssl pkeyutl -verifyrecover -in sig -inkey key.pem
$ openssl pkeyutl -verify -in file -sigfile sig \ -inkey key.pem
$ openssl pkeyutl -sign -in file -inkey key.pem \ -out sig -pkeyopt digest:sha256
$ openssl pkeyutl -derive -inkey key.pem \ -peerkey pubkey.pem -out secret
PRIME
openssl prime [-bits n] [-checks n] [-generate] [-hex] [-safe] p- -bits n
- Specify the number of bits in the generated prime number. Must be used in conjunction with -generate.
- -checks n
- Perform a Miller-Rabin probabilistic primality test with n iterations. The default is 20.
- -generate
- Generate a pseudo-random prime number. Must be used in conjunction with -bits.
- -hex
- Output in hex format.
- -safe
- Generate only “safe” prime numbers (i.e. a prime p so that (p-1)/2 is also prime).
- p
- Test if number p is prime.
RAND
openssl rand | [-base64] [-hex] [-out file] num |
- -base64
- Perform base64 encoding on the output.
- -hex
- Specify hexadecimal output.
- -out file
- Write to file instead of standard output.
REQ
openssl req | [-asn1-kludge] [-batch] [-config file] [-days n] [-extensions section] [-in file] [-inform DER | PEM] [-key keyfile] [-keyform DER | PEM] [-keyout file] [-md4 | -md5 | -sha1] [-modulus] [-nameopt option] [-new] [-newhdr] [-newkey arg] [-no-asn1-kludge] [-nodes] [-noout] [-out file] [-outform DER | PEM] [-passin arg] [-passout arg] [-pubkey] [-reqexts section] [-reqopt option] [-set_serial n] [-subj arg] [-subject] [-text] [-utf8] [-verbose] [-verify] [-x509] |
- -asn1-kludge
-
By default, the req command outputs certificate requests containing no attributes in the correct PKCS#10 format. However certain CAs will only accept requests containing no attributes in an invalid form: this option produces this invalid format.
- -batch
- Non-interactive mode.
- -config file
- This allows an alternative configuration file to be specified; this overrides the compile time filename or any specified in the OPENSSL_CONF environment variable.
- -days n
- When the -x509 option is being used, this specifies the number of days to certify the certificate for. The default is 30 days.
- -extensions section, -reqexts section
- These options specify alternative sections to include certificate extensions (if the -x509 option is present) or certificate request extensions. This allows several different sections to be used in the same configuration file to specify requests for a variety of purposes.
- -in file
- This specifies the input file to read a request from, or standard input if this option is not specified. A request is only read if the creation options -new and -newkey are not specified.
- -inform DER | PEM
- This specifies the input format. The DER argument uses an ASN1 DER-encoded form compatible with the PKCS#10. The PEM form is the default format: it consists of the DER format base64-encoded with additional header and footer lines.
- -key keyfile
- This specifies the file to read the private key from. It also accepts PKCS#8 format private keys for PEM format files.
- -keyform DER | PEM
- The format of the private key file specified in the -key argument. PEM is the default.
- -keyout file
- This gives the file to write the newly created private key to. If this option is not specified, the filename present in the configuration file is used.
- -md5 | -sha1 | -sha256
-
This specifies the message digest to sign the request with. This overrides the digest algorithm specified in the configuration file.
- -modulus
- This option prints out the value of the modulus of the public key contained in the request.
- -nameopt option, -reqopt option
- These options determine how the subject or issuer names are displayed. The option argument can be a single option or multiple options separated by commas. Alternatively, these options may be used more than once to set multiple options. See the X509 section below for details.
- -new
-
This option generates a new certificate request. It will prompt the user for the relevant field values. The actual fields prompted for and their maximum and minimum sizes are specified in the configuration file and any requested extensions.
- -newhdr
- Adds the word NEW to the PEM file header and footer lines on the outputed request. Some software (Netscape certificate server) and some CAs need this.
- -newkey arg
-
This option creates a new certificate request and a new private key. The argument takes one of several forms. rsa:nbits, where nbits is the number of bits, generates an RSA key nbits in size. If nbits is omitted, i.e. -newkey rsa specified, the default key size, specified in the configuration file, is used.
- -no-asn1-kludge
- Reverses the effect of -asn1-kludge.
- -nodes
- If this option is specified and a private key is created, it will not be encrypted.
- -noout
- This option prevents output of the encoded version of the request.
- -out file
- This specifies the output file to write to, or standard output by default.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -pubkey
- Outputs the public key.
- -reqopt option
-
Customise the output format used with -text. The option argument can be a single option or multiple options separated by commas.
- -set_serial n
- Serial number to use when outputting a self-signed certificate. This may be specified as a decimal value or a hex value if preceded by ‘0x’. It is possible to use negative serial numbers but this is not recommended.
- -subj arg
- Replaces subject field of input request with specified data and outputs modified request. The arg must be formatted as /type0=value0/type1=value1/type2=...; characters may be escaped by ‘\’ (backslash); no spaces are skipped.
- -subject
- Prints out the request subject (or certificate subject if -x509 is specified.
- -text
- Prints out the certificate request in text form.
- -utf8
- This option causes field values to be interpreted as UTF8 strings; by default they are interpreted as ASCII. This means that the field values, whether prompted from a terminal or obtained from a configuration file, must be valid UTF8 strings.
- -verbose
- Print extra details about the operations being performed.
- -verify
- Verifies the signature on the request.
- -x509
- This option outputs a self-signed certificate instead of a certificate request. This is typically used to generate a test certificate or a self-signed root CA. The extensions added to the certificate (if any) are specified in the configuration file. Unless specified using the -set_serial option, 0 will be used for the serial number.
REQ CONFIGURATION FILE FORMAT
The configuration options are specified in the req section of the configuration file. As with all configuration files, if no value is specified in the specific section (i.e. req) then the initial unnamed or default section is searched too.- attributes
-
This specifies the section containing any request attributes: its format is the same as distinguished_name. Typically these may contain the challengePassword or unstructuredName types. They are currently ignored by OpenSSL
's
request signing utilities, but some CAs might want them. - default_bits
- This specifies the default key size in bits. If not specified, 2048 is used. It is used if the -new option is used. It can be overridden by using the -newkey option.
- default_keyfile
- This is the default file to write a private key to. If not specified, the key is written to standard output. This can be overridden by the -keyout option.
- default_md
- This option specifies the digest algorithm to use. Possible values include md5, sha1 and sha256. If not present, SHA256 is used. This option can be overridden on the command line.
- distinguished_name
- This specifies the section containing the distinguished name fields to prompt for when generating a certificate or certificate request. The format is described in the next section.
- encrypt_key
- If this is set to no and a private key is generated, it is not encrypted. This is equivalent to the -nodes command line option. For compatibility, encrypt_rsa_key is an equivalent option.
- input_password | output_password
- The passwords for the input private key file (if present) and the output private key file (if one will be created). The command line options -passin and -passout override the configuration file values.
- oid_file
- This specifies a file containing additional OBJECT IDENTIFIERS. Each line of the file should consist of the numerical form of the object identifier, followed by whitespace, then the short name followed by whitespace and finally the long name.
- oid_section
- This specifies a section in the configuration file containing extra object identifiers. Each line should consist of the short name of the object identifier followed by ‘=’ and the numerical form. The short and long names are the same when this option is used.
- prompt
- If set to the value no, this disables prompting of certificate fields and just takes values from the config file directly. It also changes the expected format of the distinguished_name and attributes sections.
- req_extensions
- This specifies the configuration file section containing a list of extensions to add to the certificate request. It can be overridden by the -reqexts command line switch.
- string_mask
-
This option limits the string types for encoding certain fields. The following values may be used, limiting strings to the indicated types:
- utf8only
- UTF8String. This is the default, as recommended by PKIX in RFC 2459.
- default
- PrintableString, IA5String, T61String, BMPString, UTF8String.
- pkix
- PrintableString, IA5String, BMPString, UTF8String. This was inspired by the PKIX recommendation in RFC 2459 for certificates generated before 2004, but differs by also permitting IA5String.
- nombstr
- PrintableString, IA5String, T61String, UniversalString. This was a workaround for some ancient software that had problems with the variable-sized BMPString and UTF8String types.
- MASK:number
- This is an explicit bitmask of permitted types, where number is a C-style hex, decimal, or octal number that's a bit-wise OR of B_ASN1_* values from <openssl/asn1.h>.
- utf8
- If set to the value yes, then field values are interpreted as UTF8 strings; by default they are interpreted as ASCII. This means that the field values, whether prompted from a terminal or obtained from a configuration file, must be valid UTF8 strings.
- x509_extensions
- This specifies the configuration file section containing a list of extensions to add to a certificate generated when the -x509 switch is used. It can be overridden by the -extensions command line switch.
REQ DISTINGUISHED NAME AND ATTRIBUTE SECTION FORMAT
There are two separate formats for the distinguished name and attribute sections. If the -prompt option is set to no, then these sections just consist of field names and values: for example,CN=My Name OU=My Organization emailAddress=someone@somewhere.org
fieldName="prompt" fieldName_default="default field value" fieldName_min= 2 fieldName_max= 4
REQ EXAMPLES
Examine and verify a certificate request:$ openssl req -in req.pem -text -verify -noout
$ openssl genrsa -out key.pem 2048 $ openssl req -new -key key.pem -out req.pem
$ openssl req -newkey rsa:2048 -keyout key.pem -out req.pem
$ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out req.pem
1.2.3.4 shortName A longer Name 1.2.3.6 otherName Other longer Name
testoid1=1.2.3.5 testoid2=${testoid1}.6
[ req ] default_bits = 1024 default_keyfile = privkey.pem distinguished_name = req_distinguished_name attributes = req_attributes x509_extensions = v3_ca dirstring_type = nobmp [ req_distinguished_name ] countryName = Country Name (2 letter code) countryName_default = AU countryName_min = 2 countryName_max = 2 localityName = Locality Name (eg, city) organizationalUnitName = Organizational Unit Name (eg, section) commonName = Common Name (eg, YOUR name) commonName_max = 64 emailAddress = Email Address emailAddress_max = 40 [ req_attributes ] challengePassword = A challenge password challengePassword_min = 4 challengePassword_max = 20 [ v3_ca ] subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer:always basicConstraints = CA:true
[ req ] default_bits = 1024 default_keyfile = keyfile.pem distinguished_name = req_distinguished_name attributes = req_attributes prompt = no output_password = mypass [ req_distinguished_name ] C = GB ST = Test State or Province L = Test Locality O = Organization Name OU = Organizational Unit Name CN = Common Name emailAddress = test@email.address [ req_attributes ] challengePassword = A challenge password
REQ NOTES
The header and footer lines in the PEM format are normally:-----BEGIN CERTIFICATE REQUEST----- -----END CERTIFICATE REQUEST-----
-----BEGIN NEW CERTIFICATE REQUEST----- -----END NEW CERTIFICATE REQUEST-----
REQ DIAGNOSTICS
The following messages are frequently asked about:Using configuration from /some/path/openssl.cnf Unable to load config info
unable to find 'distinguished_name' in config problems making Certificate Request
Attributes: a0:00
Attributes:
REQ ENVIRONMENT VARIABLES
The variable OPENSSL_CONF, if defined, allows an alternative configuration file location to be specified; it will be overridden by the -config command line switch if it is present.REQ BUGS
OpenSSL's
handling of T61Strings (aka TeletexStrings) is broken: it effectively treats them as ISO 8859-1 (Latin 1); Netscape and MSIE have similar behaviour. This can cause problems if you need characters that aren't available in PrintableStrings and you don't want to or can't use BMPStrings.RSA
openssl rsa | [-aes128 | -aes192 | -aes256 | -des | -des3] [-check] [-in file] [-inform DER | NET | PEM] [-modulus] [-noout] [-out file] [-outform DER | NET | PEM] [-passin arg] [-passout arg] [-pubin] [-pubout] [-sgckey] [-text] |
- -aes128 | -aes192 | -aes256 | -des | -des3
- These options encrypt the private key with the AES, DES, or the triple DES ciphers, respectively, before outputting it. A pass phrase is prompted for. If none of these options are specified, the key is written in plain text. This means that using the rsa utility to read in an encrypted key with no encryption option can be used to remove the pass phrase from a key, or by setting the encryption options it can be used to add or change the pass phrase. These options can only be used with PEM format output files.
- -check
- This option checks the consistency of an RSA private key.
- -in file
- This specifies the input file to read a key from, or standard input if this option is not specified. If the key is encrypted, a pass phrase will be prompted for.
- -inform DER | NET | PEM
- This specifies the input format. The DER argument uses an ASN1 DER-encoded form compatible with the PKCS#1 RSAPrivateKey or SubjectPublicKeyInfo format. The PEM form is the default format: it consists of the DER format base64-encoded with additional header and footer lines. On input PKCS#8 format private keys are also accepted. The NET form is a format described in the RSA NOTES section.
- -noout
- This option prevents output of the encoded version of the key.
- -modulus
- This option prints out the value of the modulus of the key.
- -out file
- This specifies the output file to write a key to, or standard output if this option is not specified. If any encryption options are set, a pass phrase will be prompted for. The output filename should not be the same as the input filename.
- -outform DER | NET | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -passout arg
- The output file password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -pubin
- By default, a private key is read from the input file; with this option a public key is read instead.
- -pubout
- By default, a private key is output; with this option a public key will be output instead. This option is automatically set if the input is a public key.
- -sgckey
- Use the modified NET algorithm used with some versions of Microsoft IIS and SGC keys.
- -text
- Prints out the various public or private key components in plain text, in addition to the encoded version.
RSA NOTES
The PEM private key format uses the header and footer lines:-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY----- -----END PUBLIC KEY-----
RSA EXAMPLES
To remove the pass phrase on an RSA private key:$ openssl rsa -in key.pem -out keyout.pem
$ openssl rsa -in key.pem -des3 -out keyout.pem
$ openssl rsa -in key.pem -outform DER -out keyout.der
$ openssl rsa -in key.pem -text -noout
$ openssl rsa -in key.pem -pubout -out pubkey.pem
RSA BUGS
The command line password arguments don't currently work with NET format.RSAUTL
openssl rsautl | [-asn1parse] [-certin] [-decrypt] [-encrypt] [-hexdump] [-in file] [-inkey file] [-keyform DER | PEM] [-oaep | -pkcs | -raw | -ssl] [-out file] [-pubin] [-sign] [-verify] |
- -asn1parse
- Asn1parse the output data; this is useful when combined with the -verify option.
- -certin
- The input is a certificate containing an RSA public key.
- -decrypt
- Decrypt the input data using an RSA private key.
- -encrypt
- Encrypt the input data using an RSA public key.
- -hexdump
- Hex dump the output data.
- -in file
- This specifies the input file to read data from, or standard input if this option is not specified.
- -inkey file
- The input key file, by default it should be an RSA private key.
- -keyform DER | PEM
- Private ket format. Default is PEM.
- -oaep | -pkcs | -raw | -ssl
- The padding to use: PKCS#1 OAEP, PKCS#1 v1.5 (the default), or no padding, respectively. For signatures, only -pkcs and -raw can be used.
- -out file
- Specifies the output file to write to, or standard output by default.
- -pubin
- The input file is an RSA public key.
- -sign
- Sign the input data and output the signed result. This requires an RSA private key.
- -verify
- Verify the input data and output the recovered data.
RSAUTL NOTES
rsautl, because it uses the RSA algorithm directly, can only be used to sign or verify small pieces of data.RSAUTL EXAMPLES
Sign some data using a private key:$ openssl rsautl -sign -in file -inkey key.pem -out sig
$ openssl rsautl -verify -in sig -inkey key.pem
$ openssl rsautl -verify -in file -inkey key.pem -raw -hexdump
0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0040 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0050 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0060 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff ................ 0070 - ff ff ff ff 00 68 65 6c-6c 6f 20 77 6f 72 6c 64 .....hello world
$ openssl asn1parse -in pca-cert.pem
0:d=0 hl=4 l= 742 cons: SEQUENCE 4:d=1 hl=4 l= 591 cons: SEQUENCE 8:d=2 hl=2 l= 3 cons: cont [ 0 ] 10:d=3 hl=2 l= 1 prim: INTEGER :02 13:d=2 hl=2 l= 1 prim: INTEGER :00 16:d=2 hl=2 l= 13 cons: SEQUENCE 18:d=3 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption 29:d=3 hl=2 l= 0 prim: NULL 31:d=2 hl=2 l= 92 cons: SEQUENCE 33:d=3 hl=2 l= 11 cons: SET 35:d=4 hl=2 l= 9 cons: SEQUENCE 37:d=5 hl=2 l= 3 prim: OBJECT :countryName 42:d=5 hl=2 l= 2 prim: PRINTABLESTRING :AU .... 599:d=1 hl=2 l= 13 cons: SEQUENCE 601:d=2 hl=2 l= 9 prim: OBJECT :md5WithRSAEncryption 612:d=2 hl=2 l= 0 prim: NULL 614:d=1 hl=3 l= 129 prim: BIT STRING
$ openssl asn1parse -in pca-cert.pem -out sig -noout -strparse 614
$ openssl x509 -in test/testx509.pem -pubkey -noout >pubkey.pem
$ openssl rsautl -in sig -verify -asn1parse -inkey pubkey.pem -pubin
0:d=0 hl=2 l= 32 cons: SEQUENCE 2:d=1 hl=2 l= 12 cons: SEQUENCE 4:d=2 hl=2 l= 8 prim: OBJECT :md5 14:d=2 hl=2 l= 0 prim: NULL 16:d=1 hl=2 l= 16 prim: OCTET STRING 0000 - f3 46 9e aa 1a 4a 73 c9-37 ea 93 00 48 25 08 b5 .F...Js.7...H%..
$ openssl asn1parse -in pca-cert.pem -out tbs -noout -strparse 4
$ openssl md5 -c tbs
MD5(tbs)= f3:46:9e:aa:1a:4a:73:c9:37:ea:93:00:48:25:08:b5
S_CLIENT
openssl s_client | [-4 | -6] [-bugs] [-CAfile file] [-CApath directory] [-cert file] [-check_ss_sig] [-cipher cipherlist] [-connect host:port | host/port] [-crl_check] [-crl_check_all] [-crlf] [-debug] [-extended_crl] [-ign_eof] [-ignore_critical] [-issuer_checks] [-key keyfile] [-msg] [-nbio] [-nbio_test] [-no_ticket] [-no_tls1] [-no_tls1_1] [-no_tls1_2] [-pause] [-policy_check] [-prexit] [-proxy host:port] [-psk key] [-psk_identity identity] [-quiet] [-reconnect] [-servername name] [-showcerts] [-starttls protocol] [-state] [-tls1] [-tlsextdebug] [-verify depth] [-x509_strict] [-xmpphost host] |
- -4
- Specify that s_client should attempt connections using IPv4 only.
- -6
- Specify that s_client should attempt connections using IPv6 only.
- -bugs
- There are several known bugs in SSL and TLS implementations. Adding this option enables various workarounds.
- -CAfile file
- A file containing trusted certificates to use during server authentication and to use when attempting to build the client certificate chain.
- -CApath directory
- The directory to use for server certificate verification. This directory must be in “hash format”; see -verify for more information. These are also used when building the client certificate chain.
- -cert file
- The certificate to use, if one is requested by the server. The default is not to use a certificate.
- -check_ss_sig, -crl_check, -crl_check_all, -extended_crl, -ignore_critical, -issuer_checks, -policy_check, -x509_strict
- Set various certificate chain validation options. See the VERIFY command for details.
- -cipher cipherlist
- This allows the cipher list sent by the client to be modified. Although the server determines which cipher suite is used, it should take the first supported cipher in the list sent by the client. See the CIPHERS section above for more information.
- -connect host:port | host/port
- This specifies the host and optional port to connect to. If not specified, an attempt is made to connect to the local host on port 4433. Alternatively, the host and port pair may be separated using a forward-slash character. This form is useful for numeric IPv6 addresses.
- -crlf
- This option translates a line feed from the terminal into CR+LF as required by some servers.
- -debug
- Print extensive debugging information including a hex dump of all traffic.
- -ign_eof
- Inhibit shutting down the connection when end of file is reached in the input.
- -key keyfile
- The private key to use. If not specified, the certificate file will be used.
- -msg
- Show all protocol messages with hex dump.
- -nbio
- Turns on non-blocking I/O.
- -nbio_test
- Tests non-blocking I/O.
- -no_tls1 | -no_tls1_1 | -no_tls1_2 | -tls1
-
These options disable the use of certain SSL or TLS protocols. By default, the initial handshake uses a method which should be compatible with all servers and permit them to use SSL v3 or TLS as appropriate.
- -no_ticket
- Disable RFC 4507 session ticket support.
- -pause
- Pauses 1 second between each read and write call.
- -prexit
- Print session information when the program exits. This will always attempt to print out information even if the connection fails. Normally, information will only be printed out once if the connection succeeds. This option is useful because the cipher in use may be renegotiated or the connection may fail because a client certificate is required or is requested only after an attempt is made to access a certain URL. Note: the output produced by this option is not always accurate because a connection might never have been established.
- -proxy host:port
- Use the HTTP proxy at host and port. The connection to the proxy is done in cleartext and the -connect argument is given to the proxy. If not specified, localhost is used as final destination. After that, switch the connection through the proxy to the destination to TLS.
- -psk key
- Use the PSK key key when using a PSK cipher suite. The key is given as a hexadecimal number without the leading 0x, for example -psk 1a2b3c4d.
- -psk_identity identity
- Use the PSK identity identity when using a PSK cipher suite.
- -quiet
- Inhibit printing of session and certificate information. This implicitly turns on -ign_eof as well.
- -reconnect
- Reconnects to the same server 5 times using the same session ID; this can be used as a test that session caching is working.
- -servername name
- Include the TLS Server Name Indication (SNI) extension in the ClientHello message, using the specified server name.
- -showcerts
- Display the whole server certificate chain: normally only the server certificate itself is displayed.
- -starttls protocol
- Send the protocol-specific message(s) to switch to TLS for communication. protocol is a keyword for the intended protocol. Currently, the supported keywords are “ftp”, “imap”, “smtp”, “pop3”, and “xmpp”.
- -state
- Prints out the SSL session states.
- -tlsextdebug
- Print out a hex dump of any TLS extensions received from the server.
- -verify depth
- The verify depth to use. This specifies the maximum length of the server certificate chain and turns on server certificate verification. Currently the verify operation continues after errors so all the problems with a certificate chain can be seen. As a side effect the connection will never fail due to a server certificate verify failure.
- -xmpphost hostname
- This option, when used with -starttls xmpp, specifies the host for the "to" attribute of the stream element. If this option is not specified then the host specified with -connect will be used.
S_CLIENT CONNECTED COMMANDS
If a connection is established with an SSL server, any data received from the server is displayed and any key presses will be sent to the server. When used interactively (which means neither -quiet nor -ign_eof have been given), the session will be renegotiated if the line begins with an R; if the line begins with a Q or if end of file is reached, the connection will be closed down.S_CLIENT NOTES
s_client can be used to debug SSL servers. To connect to an SSL HTTP server the command:$ openssl s_client -connect servername:443
S_CLIENT BUGS
Because this program has a lot of options and also because some of the techniques used are rather old, the C source of s_client is rather hard to read and not a model of how things should be done. A typical SSL client program would be much simpler.S_SERVER
openssl s_server | [-accept port] [-bugs] [-CAfile file] [-CApath directory] [-cert file] [-cipher cipherlist] [-context id] [-crl_check] [-crl_check_all] [-crlf] [-dcert file] [-debug] [-dhparam file] [-dkey file] [-hack] [-HTTP] [-id_prefix arg] [-key keyfile] [-msg] [-nbio] [-nbio_test] [-no_dhe] [-no_tls1] [-no_tls1_1] [-no_tls1_2] [-no_tmp_rsa] [-nocert] [-psk key] [-psk_hint hint] [-quiet] [-serverpref] [-state] [-tls1] [-Verify depth] [-verify depth] [-WWW] [-www] |
- -accept port
- The TCP port to listen on for connections. If not specified, 4433 is used.
- -bugs
- There are several known bugs in SSL and TLS implementations. Adding this option enables various workarounds.
- -CAfile file
- A file containing trusted certificates to use during client authentication and to use when attempting to build the server certificate chain. The list is also used in the list of acceptable client CAs passed to the client when a certificate is requested.
- -CApath directory
- The directory to use for client certificate verification. This directory must be in “hash format”; see -verify for more information. These are also used when building the server certificate chain.
- -cert file
- The certificate to use; most server's cipher suites require the use of a certificate and some require a certificate with a certain public key type: for example the DSS cipher suites require a certificate containing a DSS (DSA) key. If not specified, the file server.pem will be used.
- -cipher cipherlist
- This allows the cipher list used by the server to be modified. When the client sends a list of supported ciphers, the first client cipher also included in the server list is used. Because the client specifies the preference order, the order of the server cipherlist is irrelevant. See the CIPHERS section for more information.
- -context id
- Sets the SSL context ID. It can be given any string value. If this option is not present, a default value will be used.
- -crl_check, -crl_check_all
- Check the peer certificate has not been revoked by its CA. The CRLs are appended to the certificate file. With the -crl_check_all option, all CRLs of all CAs in the chain are checked.
- -crlf
- This option translates a line feed from the terminal into CR+LF.
- -dcert file, -dkey file
- Specify an additional certificate and private key; these behave in the same manner as the -cert and -key options except there is no default if they are not specified (no additional certificate or key is used). As noted above some cipher suites require a certificate containing a key of a certain type. Some cipher suites need a certificate carrying an RSA key and some a DSS (DSA) key. By using RSA and DSS certificates and keys, a server can support clients which only support RSA or DSS cipher suites by using an appropriate certificate.
- -debug
- Print extensive debugging information including a hex dump of all traffic.
- -dhparam file
- The DH parameter file to use. The ephemeral DH cipher suites generate keys using a set of DH parameters. If not specified, an attempt is made to load the parameters from the server certificate file. If this fails, a static set of parameters hard coded into the s_server program will be used.
- -hack
- This option enables a further workaround for some early Netscape SSL code (?).
- -HTTP
- Emulates a simple web server. Pages will be resolved relative to the current directory; for example if the URL https://myhost/page.html is requested, the file ./page.html will be loaded. The files loaded are assumed to contain a complete and correct HTTP response (lines that are part of the HTTP response line and headers must end with CRLF).
- -id_prefix arg
- Generate SSL/TLS session IDs prefixed by arg. This is mostly useful for testing any SSL/TLS code (e.g. proxies) that wish to deal with multiple servers, when each of which might be generating a unique range of session IDs (e.g. with a certain prefix).
- -key keyfile
- The private key to use. If not specified, the certificate file will be used.
- -msg
- Show all protocol messages with hex dump.
- -nbio
- Turns on non-blocking I/O.
- -nbio_test
- Tests non-blocking I/O.
- -no_dhe
- If this option is set, no DH parameters will be loaded, effectively disabling the ephemeral DH cipher suites.
- -no_tls1 | -no_tls1_1 | -no_tls1_2 | -tls1
- These options disable the use of certain SSL or TLS protocols. By default, the initial handshake uses a method which should be compatible with all servers and permit them to use SSL v3 or TLS as appropriate.
- -no_tmp_rsa
- Certain export cipher suites sometimes use a temporary RSA key; this option disables temporary RSA key generation.
- -nocert
- If this option is set, no certificate is used. This restricts the cipher suites available to the anonymous ones (currently just anonymous DH).
- -psk key
- Use the PSK key key when using a PSK cipher suite. The key is given as a hexadecimal number without the leading 0x, for example -psk 1a2b3c4d.
- -psk_hint hint
- Use the PSK identity hint hint when using a PSK cipher suite.
- -quiet
- Inhibit printing of session and certificate information.
- -serverpref
- Use server's cipher preferences.
- -state
- Prints out the SSL session states.
- -WWW
- Emulates a simple web server. Pages will be resolved relative to the current directory; for example if the URL https://myhost/page.html is requested, the file ./page.html will be loaded.
- -www
- Sends a status message back to the client when it connects. This includes lots of information about the ciphers used and various session parameters. The output is in HTML format so this option will normally be used with a web browser.
- -Verify depth, -verify depth
- The verify depth to use. This specifies the maximum length of the client certificate chain and makes the server request a certificate from the client. With the -Verify option, the client must supply a certificate or an error occurs. With the -verify option, a certificate is requested but the client does not have to send one.
S_SERVER CONNECTED COMMANDS
If a connection request is established with an SSL client and neither the -www nor the -WWW option has been used, then normally any data received from the client is displayed and any key presses will be sent to the client.- P
- Send some plain text down the underlying TCP connection: this should cause the client to disconnect due to a protocol violation.
- Q
- End the current SSL connection and exit.
- q
- End the current SSL connection, but still accept new connections.
- R
- Renegotiate the SSL session and request a client certificate.
- r
- Renegotiate the SSL session.
- S
- Print out some session cache status information.
S_SERVER NOTES
s_server can be used to debug SSL clients. To accept connections from a web browser the command:$ openssl s_server -accept 443 -www
S_SERVER BUGS
Because this program has a lot of options and also because some of the techniques used are rather old, the C source of s_server is rather hard to read and not a model of how things should be done. A typical SSL server program would be much simpler.S_TIME
openssl s_time | [-bugs] [-CAfile file] [-CApath directory] [-cert file] [-cipher cipherlist] [-connect host:port] [-key keyfile] [-nbio] [-new] [-no_shutdown] [-reuse] [-time seconds] [-verify depth] [-www page] |
- -bugs
- There are several known bugs in SSL and TLS implementations. Adding this option enables various workarounds.
- -CAfile file
- A file containing trusted certificates to use during server authentication and to use when attempting to build the client certificate chain.
- -CApath directory
- The directory to use for server certificate verification. This directory must be in “hash format”; see verify for more information. These are also used when building the client certificate chain.
- -cert file
- The certificate to use, if one is requested by the server. The default is not to use a certificate. The file is in PEM format.
- -cipher cipherlist
- This allows the cipher list sent by the client to be modified. Although the server determines which cipher suite is used, it should take the first supported cipher in the list sent by the client. See the ciphers command for more information.
- -connect host:port
- This specifies the host and optional port to connect to.
- -key keyfile
- The private key to use. If not specified, the certificate file will be used. The file is in PEM format.
- -nbio
- Turns on non-blocking I/O.
- -new
- Performs the timing test using a new session ID for each connection. If neither -new nor -reuse are specified, they are both on by default and executed in sequence.
- -no_shutdown
- Shut down the connection without sending a “close notify” shutdown alert to the server.
- -reuse
- Performs the timing test using the same session ID; this can be used as a test that session caching is working. If neither -new nor -reuse are specified, they are both on by default and executed in sequence.
- -time seconds
- Specifies how long (in seconds) s_time should establish connections and optionally transfer payload data from a server. The default is 30 seconds. Server and client performance and the link speed determine how many connections s_time can establish.
- -verify depth
- The verify depth to use. This specifies the maximum length of the server certificate chain and turns on server certificate verification. Currently the verify operation continues after errors, so all the problems with a certificate chain can be seen. As a side effect, the connection will never fail due to a server certificate verify failure.
- -www page
- This specifies the page to GET from the server. A value of ‘/’ gets the index.htm[l] page. If this parameter is not specified, s_time will only perform the handshake to establish SSL connections but not transfer any payload data.
S_TIME NOTES
s_client can be used to measure the performance of an SSL connection. To connect to an SSL HTTP server and get the default page the command$ openssl s_time -connect servername:443 -www / -CApath yourdir \ -CAfile yourfile.pem -cipher commoncipher
S_TIME BUGS
Because this program does not have all the options of the s_client program to turn protocols on and off, you may not be able to measure the performance of all protocols with all servers.SESS_ID
openssl sess_id | [-cert] [-context ID] [-in file] [-inform DER | PEM] [-noout] [-out file] [-outform DER | PEM] [-text] |
- -cert
- If a certificate is present in the session, it will be output using this option; if the -text option is also present, then it will be printed out in text form.
- -context ID
- This option can set the session ID so the output session information uses the supplied ID. The ID can be any string of characters. This option won't normally be used.
- -in file
- This specifies the input file to read session information from, or standard input by default.
- -inform DER | PEM
- This specifies the input format. The DER argument uses an ASN1 DER-encoded format containing session details. The precise format can vary from one version to the next. The PEM form is the default format: it consists of the DER format base64-encoded with additional header and footer lines.
- -noout
- This option prevents output of the encoded version of the session.
- -out file
- This specifies the output file to write session information to, or standard output if this option is not specified.
- -outform DER | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -text
- Prints out the various public or private key components in plain text in addition to the encoded version.
SESS_ID OUTPUT
Typical output:SSL-Session: Protocol : TLSv1 Cipher : 0016 Session-ID: 871E62626C554CE95488823752CBD5F3673A3EF3DCE9C67BD916C809914B40ED Session-ID-ctx: 01000000 Master-Key: A7CEFC571974BE02CAC305269DC59F76EA9F0B180CB6642697A68251F2D2BB57E51DBBB4C7885573192AE9AEE220FACD Key-Arg : None Start Time: 948459261 Timeout : 300 (sec) Verify return code 0 (ok)
- Protocol
- This is the protocol in use.
- Cipher
- The cipher used is the actual raw SSL or TLS cipher code; see the SSL or TLS specifications for more information.
- Session-ID
- The SSL session ID in hex format.
- Session-ID-ctx
- The session ID context in hex format.
- Master-Key
- This is the SSL session master key.
- Key-Arg
- The key argument; this is only used in SSL v2.
- Start Time
- This is the session start time, represented as an integer in standard UNIX format.
- Timeout
- The timeout in seconds.
- Verify return code
- This is the return code when an SSL client certificate is verified.
SESS_ID NOTES
The PEM-encoded session format uses the header and footer lines:-----BEGIN SSL SESSION PARAMETERS----- -----END SSL SESSION PARAMETERS-----
SESS_ID BUGS
The cipher and start time should be printed out in human readable form.SMIME
openssl smime | [-aes128 | -aes192 | -aes256 | -des | -des3 | -rc2-40 | -rc2-64 | -rc2-128] [-binary] [-CAfile file] [-CApath directory] [-certfile file] [-check_ss_sig] [-content file] [-crl_check] [-crl_check_all] [-decrypt] [-encrypt] [-extended_crl] [-from addr] [-ignore_critical] [-in file] [-indef] [-inform DER | PEM | SMIME] [-inkey file] [-issuer_checks] [-keyform PEM] [-md digest] [-noattr] [-nocerts] [-nochain] [-nodetach] [-noindef] [-nointern] [-nosigs] [-noverify] [-out file] [-outform DER | PEM | SMIME] [-passin arg] [-pk7out] [-policy_check] [-recip file] [-resign] [-sign] [-signer file] [-stream] [-subject s] [-text] [-to addr] [-verify] [-x509_strict] [cert.pem ...] |
- -decrypt
- Decrypt mail using the supplied certificate and private key. Expects an encrypted mail message in MIME format for the input file. The decrypted mail is written to the output file.
- -encrypt
- Encrypt mail for the given recipient certificates. Input file is the message to be encrypted. The output file is the encrypted mail in MIME format.
- -pk7out
- Takes an input message and writes out a PEM-encoded PKCS#7 structure.
- -resign
- Resign a message: take an existing message and one or more new signers.
- -sign
- Sign mail using the supplied certificate and private key. Input file is the message to be signed. The signed message in MIME format is written to the output file.
- -verify
- Verify signed mail. Expects a signed mail message on input and outputs the signed data. Both clear text and opaque signing is supported.
- -aes128 | -aes192 | -aes256 | -des | -des3 | -rc2-40 | -rc2-64 | -rc2-128
- The encryption algorithm to use. 128-, 192-, or 256-bit AES, DES (56 bits), triple DES (168 bits), or 40-, 64-, or 128-bit RC2, respectively; if not specified, 40-bit RC2 is used. Only used with -encrypt.
- -binary
- Normally, the input message is converted to “canonical” format which is effectively using CR and LF as end of line - as required by the S/MIME specification. When this option is present no translation occurs. This is useful when handling binary data which may not be in MIME format.
- -CAfile file
- A file containing trusted CA certificates; only used with -verify.
- -CApath directory
- A directory containing trusted CA certificates; only used with -verify. This directory must be a standard certificate directory: that is, a hash of each subject name (using x509 -hash) should be linked to each certificate.
- cert.pem ...
- One or more certificates of message recipients: used when encrypting a message.
- -certfile file
- Allows additional certificates to be specified. When signing, these will be included with the message. When verifying, these will be searched for the signers' certificates. The certificates should be in PEM format.
- -check_ss_sig, -crl_check, -crl_check_all, -extended_crl, -ignore_critical, -issuer_checks, -policy_check, -x509_strict
- Set various certificate chain validation options. See the VERIFY command for details.
- -content file
- This specifies a file containing the detached content. This is only useful with the -verify command. This is only usable if the PKCS#7 structure is using the detached signature form where the content is not included. This option will override any content if the input format is S/MIME and it uses the multipart/signed MIME content type.
- -from addr, -subject s, -to addr
- The relevant mail headers. These are included outside the signed portion of a message so they may be included manually. When signing, many S/MIME mail clients check that the signer's certificate email address matches the From: address.
- -in file
- The input message to be encrypted or signed or the MIME message to be decrypted or verified.
- -indef
- Enable streaming I/O for encoding operations. This permits single pass processing of data without the need to hold the entire contents in memory, potentially supporting very large files. Streaming is automatically set for S/MIME signing with detached data if the output format is SMIME; it is currently off by default for all other operations.
- -inform DER | PEM | SMIME
- This specifies the input format for the PKCS#7 structure. The default is SMIME, which reads an S/MIME format message. PEM and DER format change this to expect PEM and DER format PKCS#7 structures instead. This currently only affects the input format of the PKCS#7 structure; if no PKCS#7 structure is being input (for example with -encrypt or -sign), this option has no effect.
- -inkey file
- The private key to use when signing or decrypting. This must match the corresponding certificate. If this option is not specified, the private key must be included in the certificate file specified with the -recip or -signer file. When signing, this option can be used multiple times to specify successive keys.
- -keyform PEM
- Input private key format.
- -md digest
- The digest algorithm to use when signing or resigning. If not present then the default digest algorithm for the signing key is used (usually SHA1).
- -noattr
- Normally, when a message is signed a set of attributes are included which include the signing time and supported symmetric algorithms. With this option they are not included.
- -nocerts
- When signing a message, the signer's certificate is normally included; with this option it is excluded. This will reduce the size of the signed message but the verifier must have a copy of the signer's certificate available locally (passed using the -certfile option, for example).
- -nochain
- Do not do chain verification of signers' certificates: that is, don't use the certificates in the signed message as untrusted CAs.
- -nodetach
- When signing a message use opaque signing: this form is more resistant to translation by mail relays but it cannot be read by mail agents that do not support S/MIME. Without this option cleartext signing with the MIME type multipart/signed is used.
- -noindef
- Disable streaming I/O where it would produce an encoding of indefinite length. This option currently has no effect. In future streaming will be enabled by default on all relevant operations and this option will disable it.
- -nointern
- When verifying a message, normally certificates (if any) included in the message are searched for the signing certificate. With this option, only the certificates specified in the -certfile option are used. The supplied certificates can still be used as untrusted CAs however.
- -nosigs
- Don't try to verify the signatures on the message.
- -noverify
- Do not verify the signer's certificate of a signed message.
- -out file
- The message text that has been decrypted or verified, or the output MIME format message that has been signed or verified.
- -outform DER | PEM | SMIME
- This specifies the output format for the PKCS#7 structure. The default is SMIME, which writes an S/MIME format message. PEM and DER format change this to write PEM and DER format PKCS#7 structures instead. This currently only affects the output format of the PKCS#7 structure; if no PKCS#7 structure is being output (for example with -verify or -decrypt) this option has no effect.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -recip file
- The recipients certificate when decrypting a message. This certificate must match one of the recipients of the message or an error occurs.
- -signer file
- A signing certificate when signing or resigning a message; this option can be used multiple times if more than one signer is required. If a message is being verified, the signer's certificates will be written to this file if the verification was successful.
- -stream
- The same as -indef.
- -text
- This option adds plain text (text/plain) MIME headers to the supplied message if encrypting or signing. If decrypting or verifying, it strips off text headers: if the decrypted or verified message is not of MIME type text/plain then an error occurs.
SMIME NOTES
The MIME message must be sent without any blank lines between the headers and the output. Some mail programs will automatically add a blank line. Piping the mail directly to an MTA is one way to achieve the correct format.SMIME EXIT CODES
- 0
- The operation was completely successful.
- 1
- An error occurred parsing the command options.
- 2
- One of the input files could not be read.
- 3
- An error occurred creating the PKCS#7 file or when reading the MIME message.
- 4
- An error occurred decrypting or verifying the message.
- 5
- The message was verified correctly, but an error occurred writing out the signer's certificates.
SMIME EXAMPLES
Create a cleartext signed message:$ openssl smime -sign -in message.txt -text -out mail.msg \ -signer mycert.pem
$ openssl smime -sign -in message.txt -text -out mail.msg \ -nodetach -signer mycert.pem
$ openssl smime -sign -in in.txt -text -out mail.msg \ -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
openssl smime -sign -in message.txt -text -out mail.msg \ -signer mycert.pem -signer othercert.pem
$ openssl smime -sign -in in.txt -text -signer mycert.pem \ -from steve@openssl.org -to someone@somewhere \ -subject "Signed message" | sendmail someone@somewhere
$ openssl smime -verify -in mail.msg -signer user.pem \ -out signedtext.txt
$ openssl smime -encrypt -in in.txt -from steve@openssl.org \ -to someone@somewhere -subject "Encrypted message" \ -des3 -out mail.msg user.pem
$ openssl smime -sign -in ml.txt -signer my.pem -text | \ openssl smime -encrypt -out mail.msg \ -from steve@openssl.org -to someone@somewhere \ -subject "Signed and Encrypted message" -des3 user.pem
$ openssl smime -decrypt -in mail.msg -recip mycert.pem \ -inkey key.pem"
-----BEGIN PKCS7----- -----END PKCS7-----
$ openssl smime -verify -inform PEM -in signature.pem \ -content content.txt
$ openssl smime -verify -inform DER -in signature.der \ -content content.txt
openssl smime -encrypt -in plain.txt -aes128 \ -out mail.msg cert.pem
openssl smime -resign -in mail.msg -signer newsign.pem \ -out mail2.msg
SMIME BUGS
The MIME parser isn't very clever: it seems to handle most messages that I've thrown at it, but it may choke on others.SMIME HISTORY
The use of multiple -signer options and the -resign command were first added in OpenSSL 1.0.0.SPEED
openssl speed | [aes] [aes-128-cbc] [aes-192-cbc] [aes-256-cbc] [aes-128-gcm] [aes-256-gcm] [blowfish] [bf-cbc] [cast] [cast-cbc] [chacha20-poly1305] [des] [des-cbc] [des-ede3] [dsa] [dsa512] [dsa1024] [dsa2048] [hmac] [md4] [md5] [rc2] [rc2-cbc] [rc4] [rmd160] [rsa] [rsa512] [rsa1024] [rsa2048] [rsa4096] [sha1] [-decrypt] [-elapsed] [-evp e] [-mr] [-multi number] |
TS
openssl ts | -query [-md4 | -md5 | -ripemd160 | -sha1] [-cert] [-config configfile] [-data file_to_hash] [-digest digest_bytes] [-in request.tsq] [-no_nonce] [-out request.tsq] [-policy object_id] [-text] |
openssl ts | -reply [-chain certs_file.pem] [-config configfile] [-in response.tsr] [-inkey private.pem] [-out response.tsr] [-passin arg] [-policy object_id] [-queryfile request.tsq] [-section tsa_section] [-signer tsa_cert.pem] [-text] [-token_in] [-token_out] |
openssl ts | -verify [-CAfile trusted_certs.pem] [-CApath trusted_cert_path] [-data file_to_hash] [-digest digest_bytes] [-in response.tsr] [-queryfile request.tsq] [-token_in] [-untrusted cert_file.pem] |
- -cert
- The TSA is expected to include its signing certificate in the response.
- -config configfile
- The configuration file to use. This option overrides the OPENSSL_CONF environment variable. Only the OID section of the config file is used with the -query command.
- -data file_to_hash
- The data file for which the time stamp request needs to be created. stdin is the default if neither the -data nor the -digest option is specified.
- -digest digest_bytes
- It is possible to specify the message imprint explicitly without the data file. The imprint must be specified in a hexadecimal format, two characters per byte, the bytes optionally separated by colons (e.g. 1A:F6:01:... or 1AF601...). The number of bytes must match the message digest algorithm in use.
- -in request.tsq
- This option specifies a previously created time stamp request in DER format that will be printed into the output file. Useful when you need to examine the content of a request in human-readable format.
- -md4|md5|ripemd160|sha|sha1
- The message digest to apply to the data file. It supports all the message digest algorithms that are supported by the dgst command. The default is SHA-1.
- -no_nonce
- No nonce is specified in the request if this option is given. Otherwise a 64-bit long pseudo-random none is included in the request. It is recommended to use nonce to protect against replay-attacks.
- -out request.tsq
- Name of the output file to which the request will be written. The default is stdout.
- -policy object_id
- The policy that the client expects the TSA to use for creating the time stamp token. Either the dotted OID notation or OID names defined in the config file can be used. If no policy is requested the TSA will use its own default policy.
- -text
- If this option is specified the output is in human-readable text format instead of DER.
- -chain certs_file.pem
- The collection of certificates, in PEM format, that will be included in the response in addition to the signer certificate if the -cert option was used for the request. This file is supposed to contain the certificate chain for the signer certificate from its issuer upwards. The -reply command does not build a certificate chain automatically.
- -config configfile
- The configuration file to use. This option overrides the OPENSSL_CONF environment variable. See TS CONFIGURATION FILE OPTIONS for configurable variables.
- -in response.tsr
- Specifies a previously created time stamp response or time stamp token, if -token_in is also specified, in DER format that will be written to the output file. This option does not require a request; it is useful, for example, when you need to examine the content of a response or token or you want to extract the time stamp token from a response. If the input is a token and the output is a time stamp response a default “granted” status info is added to the token.
- -inkey private.pem
- The signer private key of the TSA in PEM format. Overrides the signer_key config file option.
- -out response.tsr
- The response is written to this file. The format and content of the file depends on other options (see -text and -token_out). The default is stdout.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -policy object_id
- The default policy to use for the response unless the client explicitly requires a particular TSA policy. The OID can be specified either in dotted notation or with its name. Overrides the default_policy config file option.
- -queryfile request.tsq
- The name of the file containing a DER-encoded time stamp request.
- -section tsa_section
- The name of the config file section containing the settings for the response generation. If not specified the default TSA section is used; see TS CONFIGURATION FILE OPTIONS for details.
- -signer tsa_cert.pem
- The signer certificate of the TSA in PEM format. The TSA signing certificate must have exactly one extended key usage assigned to it: timeStamping. The extended key usage must also be critical, otherwise the certificate is going to be refused. Overrides the signer_cert variable of the config file.
- -text
- If this option is specified the output is human-readable text format instead of DER.
- -token_in
- This flag can be used together with the -in option and indicates that the input is a DER-encoded time stamp token (ContentInfo) instead of a time stamp response (TimeStampResp).
- -token_out
- The output is a time stamp token (ContentInfo) instead of time stamp response (TimeStampResp).
- -CAfile trusted_certs.pem
- The name of the file containing a set of trusted self-signed CA certificates in PEM format. See the similar option of verify for additional details. Either this option or -CApath must be specified.
- -CApath trusted_cert_path
- The name of the directory containing the trused CA certificates of the client. See the similar option of verify for additional details. Either this option or -CAfile must be specified.
- -data file_to_hash
- The response or token must be verified against file_to_hash. The file is hashed with the message digest algorithm specified in the token. The -digest and -queryfile options must not be specified with this one.
- -digest digest_bytes
- The response or token must be verified against the message digest specified with this option. The number of bytes must match the message digest algorithm specified in the token. The -data and -queryfile options must not be specified with this one.
- -in response.tsr
- The time stamp response that needs to be verified, in DER format. This option in mandatory.
- -queryfile request.tsq
- The original time stamp request, in DER format. The -data and -digest options must not be specified with this one.
- -token_in
- This flag can be used together with the -in option and indicates that the input is a DER-encoded time stamp token (ContentInfo) instead of a time stamp response (TimeStampResp).
- -untrusted cert_file.pem
- Set of additional untrusted certificates in PEM format which may be needed when building the certificate chain for the TSA's signing certificate. This file must contain the TSA signing certificate and all intermediate CA certificates unless the response includes them.
TS CONFIGURATION FILE OPTIONS
The -query and -reply options make use of a configuration file defined by the OPENSSL_CONF environment variable. The -query option uses only the symbolic OID names section and it can work without it. However, the -reply option needs the config file for its operation.- tsa section, default_tsa
- This is the main section and it specifies the name of another section that contains all the options for the -reply option. This default section can be overridden with the -section command line switch.
- oid_file
- See ca for a description.
- oid_section
- See ca for a description.
- serial
- The name of the file containing the hexadecimal serial number of the last time stamp response created. This number is incremented by 1 for each response. If the file does not exist at the time of response generation a new file is created with serial number 1. This parameter is mandatory.
- signer_cert
- TSA signing certificate, in PEM format. The same as the -signer command line option.
- certs
- A file containing a set of PEM-encoded certificates that need to be included in the response. The same as the -chain command line option.
- signer_key
- The private key of the TSA, in PEM format. The same as the -inkey command line option.
- default_policy
- The default policy to use when the request does not mandate any policy. The same as the -policy command line option.
- other_policies
- Comma separated list of policies that are also acceptable by the TSA and used only if the request explicitly specifies one of them.
- digests
- The list of message digest algorithms that the TSA accepts. At least one algorithm must be specified. This parameter is mandatory.
- accuracy
- The accuracy of the time source of the TSA in seconds, milliseconds and microseconds. For example, secs:1, millisecs:500, microsecs:100. If any of the components is missing, zero is assumed for that field.
- clock_precision_digits
- Specifies the maximum number of digits, which represent the fraction of seconds, that need to be included in the time field. The trailing zeroes must be removed from the time, so there might actually be fewer digits, or no fraction of seconds at all. The maximum value is 6; the default is 0.
- ordering
- If this option is yes, the responses generated by this TSA can always be ordered, even if the time difference between two responses is less than the sum of their accuracies. The default is no.
- tsa_name
- Set this option to yes if the subject name of the TSA must be included in the TSA name field of the response. The default is no.
- ess_cert_id_chain
- The SignedData objects created by the TSA always contain the certificate identifier of the signing certificate in a signed attribute (see RFC 2634, Enhanced Security Services). If this option is set to yes and either the certs variable or the -chain option is specified then the certificate identifiers of the chain will also be included in the SigningCertificate signed attribute. If this variable is set to no, only the signing certificate identifier is included. The default is no.
TS ENVIRONMENT VARIABLES
OPENSSL_CONF contains the path of the configuration file and can be overridden by the -config command line option.TS EXAMPLES
All the examples below presume that OPENSSL_CONF is set to a proper configuration file, e.g. the example configuration file openssl/apps/openssl.cnf will do.$ openssl ts -query -data design1.txt -no_nonce \ -out design1.tsq
$ openssl ts -query \ -digest b7e5d3f93198b38379852f2c04e78d73abdd0f4b \ -no_nonce -out design1.tsq
$ openssl ts -query -in design1.tsq -text
$ openssl ts -query -data design2.txt -md5 \ -policy tsa_policy1 -cert -out design2.tsq
$ openssl ts -reply -queryfile design1.tsq -inkey tsakey.pem \ -signer tsacert.pem -out design1.tsr
$ openssl ts -reply -queryfile design1.tsq -out design1.tsr
$ openssl ts -reply -in design1.tsr -text
$ openssl ts -reply -queryfile design1.tsq \ -out design1_token.der -token_out
$ openssl ts -reply -in design1_token.der -token_in \ -text -token_out
$ openssl ts -reply -in design1.tsr -out design1_token.der \ -token_out
$ openssl ts -reply -in design1_token.der \ -token_in -out design1.tsr
$ openssl ts -verify -queryfile design1.tsq -in design1.tsr \ -CAfile cacert.pem -untrusted tsacert.pem
$ openssl ts -verify -queryfile design2.tsq -in design2.tsr \ -CAfile cacert.pem
$ openssl ts -verify -data design2.txt -in design2.tsr \ -CAfile cacert.pem
$ openssl ts -verify \ -digest b7e5d3f93198b38379852f2c04e78d73abdd0f4b \ -in design2.tsr -CAfile cacert.pem
TS BUGS
No support for time stamps over SMTP, though it is quite easy to implement an automatic email-based TSA with procmail and perl(1). Pure TCP/IP is not supported.SPKAC
openssl spkac | [-challenge string] [-in file] [-key keyfile] [-noout] [-out file] [-passin arg] [-pubkey] [-spkac spkacname] [-spksect section] [-verify] |
- -challenge string
- Specifies the challenge string if an SPKAC is being created.
- -in file
- This specifies the input file to read from, or standard input if this option is not specified. Ignored if the -key option is used.
- -key keyfile
- Create an SPKAC file using the private key in keyfile. The -in, -noout, -spksect, and -verify options are ignored if present.
- -noout
- Don't output the text version of the SPKAC (not used if an SPKAC is being created).
- -out file
- Specifies the output file to write to, or standard output by default.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
- -pubkey
- Output the public key of an SPKAC (not used if an SPKAC is being created).
- -spkac spkacname
- Allows an alternative name for the variable containing the SPKAC. The default is "SPKAC". This option affects both generated and input SPKAC files.
- -spksect section
- Allows an alternative name for the section containing the SPKAC. The default is the default section.
- -verify
- Verifies the digital signature on the supplied SPKAC.
SPKAC EXAMPLES
Print out the contents of an SPKAC:$ openssl spkac -in spkac.cnf
$ openssl spkac -in spkac.cnf -noout -verify
$ openssl spkac -key key.pem -challenge hello -out spkac.cnf
SPKAC=MIG5MGUwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA1cCoq2Wa3Ixs47uI7F\ PVwHVIPDx5yso105Y6zpozam135a8R0CpoRvkkigIyXfcCjiVi5oWk+6FfPaD03u\ PFoQIDAQABFgVoZWxsbzANBgkqhkiG9w0BAQQFAANBAFpQtY/FojdwkJh1bEIYuc\ 2EeM2KHTWPEepWYeawvHD0gQ3DngSC75YCWnnDdq+NQ3F+X4deMx9AaEglZtULwV\ 4=
SPKAC NOTES
A created SPKAC with suitable DN components appended can be fed into the ca utility.VERIFY
openssl verify | [-CAfile file] [-CApath directory] [-check_ss_sig] [-crl_check] [-crl_check_all] [-explicit_policy] [-extended_crl] [-help] [-ignore_critical] [-inhibit_any] [-inhibit_map] [-issuer_checks] [-policy_check] [-purpose purpose] [-untrusted file] [-verbose] [-x509_strict] [-] [certificates] |
- -check_ss_sig
- Verify the signature on the self-signed root CA. This is disabled by default because it doesn't add any security.
- -CAfile file
- A file of trusted certificates. The file should contain multiple certificates in PEM format, concatenated together.
- -CApath directory
- A directory of trusted certificates. The certificates should have names of the form hash.0, or have symbolic links to them of this form ("hash" is the hashed certificate subject name: see the -hash option of the x509 utility). The c_rehash script distributed with OpenSSL will automatically create symbolic links to a directory of certificates.
- -crl_check
- Checks end entity certificate validity by attempting to look up a valid CRL. If a valid CRL cannot be found an error occurs.
- -crl_check_all
- Checks the validity of all certificates in the chain by attempting to look up valid CRLs.
- -explicit_policy
- Set policy variable require-explicit-policy (see RFC 3280 et al).
- -extended_crl
- Enable extended CRL features such as indirect CRLs and alternate CRL signing keys.
- -help
- Prints out a usage message.
- -ignore_critical
- Normally if an unhandled critical extension is present which is not supported by OpenSSL, the certificate is rejected (as required by RFC 3280 et al). If this option is set, critical extensions are ignored.
- -inhibit_any
- Set policy variable inhibit-any-policy (see RFC 3280 et al).
- -inhibit_map
- Set policy variable inhibit-policy-mapping (see RFC 3280 et al).
- -issuer_checks
- Print out diagnostics relating to searches for the issuer certificate of the current certificate. This shows why each candidate issuer certificate was rejected. However the presence of rejection messages does not itself imply that anything is wrong: during the normal verify process several rejections may take place.
- -policy_check
- Enables certificate policy processing.
- -purpose purpose
- The intended use for the certificate. Without this option no chain verification will be done. Currently accepted uses are sslclient, sslserver, nssslserver, smimesign, smimeencrypt, crlsign, any, and ocsphelper. See the VERIFY OPERATION section for more information.
- -untrusted file
- A file of untrusted certificates. The file should contain multiple certificates.
- -verbose
- Print extra information about the operations being performed.
- -x509_strict
- Disable workarounds for broken certificates which have to be disabled for strict X.509 compliance.
- -
- Marks the last option. All arguments following this are assumed to be certificate files. This is useful if the first certificate filename begins with a ‘-’.
- certificates
- One or more certificates to verify. If no certificate files are included, an attempt is made to read a certificate from standard input. They should all be in PEM format.
VERIFY OPERATION
The verify program uses the same functions as the internal SSL and S/MIME verification, therefore this description applies to these verify operations too.VERIFY DIAGNOSTICS
When a verify operation fails, the output messages can be somewhat cryptic. The general form of the error message is:server.pem: /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024-bit) error 24 at 1 depth lookup:invalid CA certificate
- 0 X509_V_OK: ok
- The operation was successful.
- 2 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate
- The issuer certificate could not be found: this occurs if the issuer certificate of an untrusted certificate cannot be found.
- 3 X509_V_ERR_UNABLE_TO_GET_CRL: unable to get certificate CRL
- The CRL of a certificate could not be found.
- 4 X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: unable to decrypt certificate's signature
- The certificate signature could not be decrypted. This means that the actual signature value could not be determined rather than it not matching the expected value. This is only meaningful for RSA keys.
- 5 X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: unable to decrypt CRL's signature
- The CRL signature could not be decrypted: this means that the actual signature value could not be determined rather than it not matching the expected value. Unused.
- 6 X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: unable to decode issuer public key
- The public key in the certificate SubjectPublicKeyInfo could not be read.
- 7 X509_V_ERR_CERT_SIGNATURE_FAILURE: certificate signature failure
- The signature of the certificate is invalid.
- 8 X509_V_ERR_CRL_SIGNATURE_FAILURE: CRL signature failure
- The signature of the certificate is invalid.
- 9 X509_V_ERR_CERT_NOT_YET_VALID: certificate is not yet valid
- The certificate is not yet valid: the notBefore date is after the current time.
- 10 X509_V_ERR_CERT_HAS_EXPIRED: certificate has expired
- The certificate has expired; that is, the notAfter date is before the current time.
- 11 X509_V_ERR_CRL_NOT_YET_VALID: CRL is not yet valid
- The CRL is not yet valid.
- 12 X509_V_ERR_CRL_HAS_EXPIRED: CRL has expired
- The CRL has expired.
- 13 X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: format error in certificate's notBefore field
- The certificate notBefore field contains an invalid time.
- 14 X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: format error in certificate's notAfter field
- The certificate notAfter field contains an invalid time.
- 15 X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: format error in CRL's lastUpdate field
- The CRL lastUpdate field contains an invalid time.
- 16 X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: format error in CRL's nextUpdate field
- The CRL nextUpdate field contains an invalid time.
- 17 X509_V_ERR_OUT_OF_MEM: out of memory
- An error occurred trying to allocate memory. This should never happen.
- 18 X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: self signed certificate
- The passed certificate is self-signed and the same certificate cannot be found in the list of trusted certificates.
- 19 X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: self signed certificate in certificate chain
- The certificate chain could be built up using the untrusted certificates but the root could not be found locally.
- 20 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: unable to get local issuer certificate
- The issuer certificate of a locally looked up certificate could not be found. This normally means the list of trusted certificates is not complete.
- 21 X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the first certificate
- No signatures could be verified because the chain contains only one certificate and it is not self-signed.
- 22 X509_V_ERR_CERT_CHAIN_TOO_LONG: certificate chain too long
- The certificate chain length is greater than the supplied maximum depth. Unused.
- 23 X509_V_ERR_CERT_REVOKED: certificate revoked
- The certificate has been revoked.
- 24 X509_V_ERR_INVALID_CA: invalid CA certificate
- A CA certificate is invalid. Either it is not a CA or its extensions are not consistent with the supplied purpose.
- 25 X509_V_ERR_PATH_LENGTH_EXCEEDED: path length constraint exceeded
- The basicConstraints pathlength parameter has been exceeded.
- 26 X509_V_ERR_INVALID_PURPOSE: unsupported certificate purpose
- The supplied certificate cannot be used for the specified purpose.
- 27 X509_V_ERR_CERT_UNTRUSTED: certificate not trusted
- The root CA is not marked as trusted for the specified purpose.
- 28 X509_V_ERR_CERT_REJECTED: certificate rejected
- The root CA is marked to reject the specified purpose.
- 29 X509_V_ERR_SUBJECT_ISSUER_MISMATCH: subject issuer mismatch
- The current candidate issuer certificate was rejected because its subject name did not match the issuer name of the current certificate. Only displayed when the -issuer_checks option is set.
- 30 X509_V_ERR_AKID_SKID_MISMATCH: authority and subject key identifier mismatch
- The current candidate issuer certificate was rejected because its subject key identifier was present and did not match the authority key identifier current certificate. Only displayed when the -issuer_checks option is set.
- 31 X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: authority and issuer serial number mismatch
- The current candidate issuer certificate was rejected because its issuer name and serial number were present and did not match the authority key identifier of the current certificate. Only displayed when the -issuer_checks option is set.
- 32 X509_V_ERR_KEYUSAGE_NO_CERTSIGN:key usage does not include certificate signing
- The current candidate issuer certificate was rejected because its keyUsage extension does not permit certificate signing.
- 50 X509_V_ERR_APPLICATION_VERIFICATION: application verification failure
- An application specific error. Unused.
VERIFY BUGS
Although the issuer checks are a considerable improvement over the old technique, they still suffer from limitations in the underlying X509_LOOKUP API. One consequence of this is that trusted certificates with matching subject name must either appear in a file (as specified by the -CAfile option) or a directory (as specified by -CApath). If they occur in both, only the certificates in the file will be recognised.VERSION
openssl version [-abdfopv]- -a
- All information: this is the same as setting all the other flags.
- -b
- The date the current version of OpenSSL was built.
- -d
- OPENSSLDIR setting.
- -f
- Compilation flags.
- -o
- Option information: various options set when the library was built.
- -p
- Platform setting.
- -v
- The current OpenSSL version.
VERSION NOTES
The output of openssl version -a would typically be used when sending in a bug report.VERSION HISTORY
The -d option was added in OpenSSL 0.9.7.X509
openssl x509 | [-C] [-addreject arg] [-addtrust arg] [-alias] [-CA file] [-CAcreateserial] [-CAform DER | PEM] [-CAkey file] [-CAkeyform DER | PEM] [-CAserial file] [-certopt option] [-checkend arg] [-clrext] [-clrreject] [-clrtrust] [-dates] [-days arg] [-email] [-enddate] [-extensions section] [-extfile file] [-fingerprint] [-hash] [-in file] [-inform DER | NET | PEM] [-issuer] [-issuer_hash] [-issuer_hash_old] [-keyform DER | PEM] [-md5 | -sha1] [-modulus] [-nameopt option] [-noout] [-ocsp_uri] [-ocspid] [-out file] [-outform DER | NET | PEM] [-passin arg] [-pubkey] [-purpose] [-req] [-serial] [-set_serial n] [-setalias arg] [-signkey file] [-startdate] [-subject] [-subject_hash] [-subject_hash_old] [-text] [-trustout] [-x509toreq] |
X509 INPUT, OUTPUT, AND GENERAL PURPOSE OPTIONS
- -in file
- This specifies the input file to read a certificate from, or standard input if this option is not specified.
- -inform DER | NET | PEM
- This specifies the input format. Normally, the command will expect an X.509 certificate, but this can change if other options such as -req are present. The DER format is the DER encoding of the certificate and PEM is the base64 encoding of the DER encoding with header and footer lines added. The NET option is an obscure Netscape server format that is now obsolete.
- -md5 | -sha1
- The digest to use. This affects any signing or display option that uses a message digest, such as the -fingerprint, -signkey, and -CA options. If not specified, MD5 is used. If the key being used to sign with is a DSA key, this option has no effect: SHA1 is always used with DSA keys.
- -out file
- This specifies the output file to write to, or standard output by default.
- -outform DER | NET | PEM
- This specifies the output format; the options have the same meaning as the -inform option.
- -passin arg
- The key password source. For more information about the format of arg, see the PASS PHRASE ARGUMENTS section above.
X509 DISPLAY OPTIONS
Note: The -alias and -purpose options are also display options but are described in the X509 TRUST SETTINGS section.- -C
- This outputs the certificate in the form of a C source file.
- -certopt option
- Customise the output 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 X509 TEXT OPTIONS section for more information.
- -dates
- Prints out the start and expiry dates of a certificate.
- Outputs the email address(es), if any.
- -enddate
- Prints out the expiry date of the certificate; that is, the notAfter date.
- -fingerprint
- Prints out the digest of the DER-encoded version of the whole certificate (see DIGEST OPTIONS).
- -hash
- A synonym for -subject_hash, for backwards compatibility.
- -issuer
- Outputs the issuer name.
- -issuer_hash
- Outputs the “hash” of the certificate issuer name.
- -issuer_hash_old
- Outputs the “hash” of the certificate issuer name using the older algorithm as used by OpenSSL versions before 1.0.0.
- -modulus
- This option prints out the value of the modulus of the public key contained in the certificate.
- -nameopt option
- Option which determines how the subject or issuer names are displayed. The option argument can be a single option or multiple options separated by commas. Alternatively, the -nameopt switch may be used more than once to set multiple options. See the X509 NAME OPTIONS section for more information.
- -noout
- This option prevents output of the encoded version of the request.
- -ocsp_uri
- Outputs the OCSP responder addresses, if any.
- -ocspid
- Print OCSP hash values for the subject name and public key.
- -pubkey
- Output the public key.
- -serial
- Outputs the certificate serial number.
- -startdate
- Prints out the start date of the certificate; that is, the notBefore date.
- -subject
- Outputs the subject name.
- -subject_hash
- Outputs 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
- Outputs the “hash” of the certificate subject name using the older algorithm as used by OpenSSL versions before 1.0.0.
- -text
- Prints out the certificate in text form. Full details are output including the public key, signature algorithms, issuer and subject names, serial number, any extensions present, and any trust settings.
X509 TRUST SETTINGS
Please note these options are currently experimental and may well change.- -addreject arg
- Adds a prohibited use. It accepts the same values as the -addtrust option.
- -addtrust arg
- Adds a trusted certificate use. Any object name can be used here, but currently only clientAuth (SSL client use), serverAuth (SSL server use), and emailProtection (S/MIME email) are used. Other OpenSSL applications may define additional uses.
- -alias
- Outputs the certificate alias, if any.
- -clrreject
- Clears all the prohibited or rejected uses of the certificate.
- -clrtrust
- Clears all the permitted or trusted uses of the certificate.
- -purpose
- This option performs tests on the certificate extensions and outputs the results. For a more complete description, see the X.509 CERTIFICATE EXTENSIONS section.
- -setalias arg
- Sets the alias of the certificate. This will allow the certificate to be referred to using a nickname, for example “Steve's Certificate”.
- -trustout
- This causes x509 to output a trusted certificate. An ordinary or trusted certificate can be input, but by default an ordinary certificate is output and any trust settings are discarded. With the -trustout option a trusted certificate is output. A trusted certificate is automatically output if any trust settings are modified.
X509 SIGNING OPTIONS
The x509 utility can be used to sign certificates and requests: it can thus behave like a “mini CA”.- -CA file
-
Specifies the CA certificate to be used for signing. When this option is present, x509 behaves like a “mini CA”. The input file is signed by the CA using this option; that is, its issuer name is set to the subject name of the CA and it is digitally signed using the CA's private key.
- -CAcreateserial
- With this option the CA serial number file is created if it does not exist: it will contain the serial number ‘02’ and the certificate being signed will have ‘1’ as its serial number. Normally, if the -CA option is specified and the serial number file does not exist, it is an error.
- -CAform DER | PEM
- The format of the CA certificate file. The default is PEM.
- -CAkey file
- Sets the CA private key to sign a certificate with. If this option is not specified, it is assumed that the CA private key is present in the CA certificate file.
- -CAkeyform DER | PEM
- The format of the CA private key. The default is PEM.
- -CAserial file
-
Sets the CA serial number file to use.
- -checkend arg
- Check whether the certificate expires in the next arg seconds. If so, exit with return value 1; otherwise exit with return value 0.
- -clrext
- Delete any extensions from a certificate. This option is used when a certificate is being created from another certificate (for example with the -signkey or the -CA options). Normally, all extensions are retained.
- -days arg
- Specifies the number of days to make a certificate valid for. The default is 30 days.
- -extensions section
- The section to add certificate extensions from. If this option is not specified, 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.
- -extfile file
- File containing certificate extensions to use. If not specified, no extensions are added to the certificate.
- -keyform DER | PEM
- Specifies the format (DER or PEM) of the private key file used in the -signkey option.
- -req
- By default, a certificate is expected on input. With this option a certificate request is expected instead.
- -set_serial n
-
Specifies the serial number to use. This option can be used with either the -signkey or -CA options. If used in conjunction with the -CA option, the serial number file (as specified by the -CAserial or -CAcreateserial options) is not used.
- -signkey file
-
This option causes the input file to be self-signed using the supplied private key.
- -x509toreq
- Converts a certificate into a certificate request. The -signkey option is used to pass the required private key.
X509 NAME OPTIONS
The -nameopt command line switch determines how the subject and issuer names are displayed. If no -nameopt switch is present, the default “oneline” format is used which is compatible with previous versions of OpenSSL. Each option is described in detail below; all options can be preceded by a ‘-’ to turn the option off. Only compat, RFC2253, oneline, and multiline will normally be used.- align
- Align field values for a more readable output. Only usable with sep_multiline.
- compat
- Use the old format. This is equivalent to specifying no name options at all.
- dn_rev
- Reverse the fields of the DN. This is required by RFC 2253. As a side effect, this also reverses the order of multiple AVAs but this is permissible.
- dump_all
- Dump all fields. This option, when used with dump_der, allows the DER encoding of the structure to be unambiguously determined.
- dump_der
- When this option is set, any fields that need to be hexdumped will be dumped using the DER encoding of the field. Otherwise just the content octets will be displayed. Both options use the RFC 2253 #XXXX... format.
- dump_nostr
- Dump non-character string types (for example OCTET STRING); if this option is not set, non-character string types will be displayed as though each content octet represents a single character.
- dump_unknown
- Dump any field whose OID is not recognised by OpenSSL.
- esc_2253
- Escape the “special” characters required by RFC 2253 in a field that is “ ,+"<>;”. Additionally, ‘#’ is escaped at the beginning of a string and a space character at the beginning or end of a string.
- esc_ctrl
- Escape control characters. That is, those with ASCII values less than 0x20 (space) and the delete (0x7f) character. They are escaped using the RFC 2253 \XX notation (where XX are two hex digits representing the character value).
- esc_msb
- Escape characters with the MSB set; that is, with ASCII values larger than 127.
- multiline
- A multiline format. It is equivalent to esc_ctrl, esc_msb, sep_multiline, space_eq, lname, and align.
- no_type
- This option does not attempt to interpret multibyte characters in any way. That is, their content octets are merely dumped as though one octet represents each character. This is useful for diagnostic purposes but will result in rather odd looking output.
- nofname, sname, lname, oid
- These options alter how the field name is displayed. nofname does not display the field at all. sname uses the “short name” form (CN for commonName, for example). lname uses the long form. oid represents the OID in numerical form and is useful for diagnostic purpose.
- oneline
- A oneline format which is more readable than RFC2253. It is equivalent to specifying the esc_2253, esc_ctrl, esc_msb, utf8, dump_nostr, dump_der, use_quote, sep_comma_plus_spc, space_eq, and sname options.
- RFC2253
- Displays names compatible with RFC 2253; equivalent to esc_2253, esc_ctrl, esc_msb, utf8, dump_nostr, dump_unknown, dump_der, sep_comma_plus, dn_rev, and sname.
- sep_comma_plus, sep_comma_plus_space, sep_semi_plus_space, sep_multiline
- These options determine the field separators. The first character is between RDNs and the second between multiple AVAs (multiple AVAs are very rare and their use is discouraged). The options ending in “space” additionally place a space after the separator to make it more readable. The sep_multiline uses a linefeed character for the RDN separator and a spaced ‘+’ for the AVA separator. It also indents the fields by four characters.
- show_type
- Show the type of the ASN1 character string. The type precedes the field contents. For example “BMPSTRING: Hello World”.
- space_eq
- Places spaces round the ‘=’ character which follows the field name.
- use_quote
- Escapes some characters by surrounding the whole string with ‘"’ characters. Without the option, all escaping is done with the ‘\’ character.
- utf8
- Convert all strings to UTF8 format first. This is required by RFC 2253. If you are lucky enough to have a UTF8 compatible terminal, the use of this option (and not setting esc_msb) may result in the correct display of multibyte (international) characters. If this option is not present, multibyte characters larger than 0xff will be represented using the format \UXXXX for 16 bits and \WXXXXXXXX for 32 bits. Also, if this option is off, any UTF8Strings will be converted to their character form first.
X509 TEXT OPTIONS
As well as customising the name output format, it is also possible to customise the actual fields printed using the -certopt options when the -text option is present. The default behaviour is to print all fields.- ca_default
- The value used by the ca utility; equivalent to no_issuer, no_pubkey, no_header, no_version, no_sigdump, and no_signame.
- compatible
- Use the old format. This is equivalent to specifying no output options at all.
- ext_default
- Retain default extension behaviour: attempt to print out unsupported certificate extensions.
- ext_dump
- Hex dump unsupported extensions.
- ext_error
- Print an error message for unsupported certificate extensions.
- ext_parse
- ASN1 parse unsupported extensions.
- no_aux
- Don't print out certificate trust information.
- no_extensions
- Don't print out any X509V3 extensions.
- no_header
- Don't print header information: that is, the lines saying “Certificate” and “Data”.
- no_issuer
- Don't print out the issuer name.
- no_pubkey
- Don't print out the public key.
- no_serial
- Don't print out the serial number.
- no_sigdump
- Don't give a hexadecimal dump of the certificate signature.
- no_signame
- Don't print out the signature algorithm used.
- no_subject
- Don't print out the subject name.
- no_validity
- Don't print the validity; that is, the notBefore and notAfter fields.
- no_version
- Don't print out the version number.
X509 EXAMPLES
Display the contents of a certificate:$ openssl x509 -in cert.pem -noout -text
$ openssl x509 -in cert.pem -noout -serial
$ openssl x509 -in cert.pem -noout -subject
$ openssl x509 -in cert.pem -noout -subject -nameopt RFC2253
$ openssl x509 -in cert.pem -noout -subject \ -nameopt oneline,-esc_msb
$ openssl x509 -in cert.pem -noout -fingerprint
$ openssl x509 -sha1 -in cert.pem -noout -fingerprint
$ openssl x509 -in cert.pem -inform PEM -out cert.der -outform DER
$ openssl x509 -x509toreq -in cert.pem -out req.pem \ -signkey key.pem
$ openssl x509 -req -in careq.pem -extfile openssl.cnf -extensions \ v3_ca -signkey key.pem -out cacert.pem
$ openssl x509 -req -in req.pem -extfile openssl.cnf -extensions \ v3_usr -CA cacert.pem -CAkey key.pem -CAcreateserial
$ openssl x509 -in cert.pem -addtrust clientAuth \ -setalias "Steve's Class 1 CA" -out trust.pem
X509 NOTES
The PEM format uses the header and footer lines:-----BEGIN CERTIFICATE----- -----END CERTIFICATE-----
-----BEGIN X509 CERTIFICATE----- -----END X509 CERTIFICATE-----
-----BEGIN TRUSTED CERTIFICATE----- -----END TRUSTED CERTIFICATE-----
X.509 CERTIFICATE EXTENSIONS
The -purpose option checks the certificate extensions and determines what the certificate can be used for. The actual checks done are rather complex and include various hacks and workarounds to handle broken certificates and software.- SSL Client
- The extended key usage extension must be absent or include the “web client authentication” OID. keyUsage must be absent or it must have the digitalSignature bit set. Netscape certificate type must be absent or it must have the SSL client bit set.
- SSL Client CA
- The extended key usage extension must be absent or include the “web client authentication” OID. Netscape certificate type must be absent or it must have the SSL CA bit set: this is used as a work around if the basicConstraints extension is absent.
- SSL Server
- The extended key usage extension must be absent or include the “web server authentication” and/or one of the SGC OIDs. keyUsage must be absent or it must have the digitalSignature set, the keyEncipherment set, or both bits set. Netscape certificate type must be absent or have the SSL server bit set.
- SSL Server CA
- The extended key usage extension must be absent or include the “web server authentication” and/or one of the SGC OIDs. Netscape certificate type must be absent or the SSL CA bit must be set: this is used as a work around if the basicConstraints extension is absent.
- Netscape SSL Server
- For Netscape SSL clients to connect to an SSL server; it must have the keyEncipherment bit set if the keyUsage extension is present. This isn't always valid because some cipher suites use the key for digital signing. Otherwise it is the same as a normal SSL server.
- Common S/MIME Client Tests
- The extended key usage extension must be absent or include the “email protection” OID. Netscape certificate type must be absent or should have the S/MIME bit set. If the S/MIME bit is not set in Netscape certificate type, then the SSL client bit is tolerated as an alternative but a warning is shown: this is because some Verisign certificates don't set the S/MIME bit.
- S/MIME Signing
- In addition to the common S/MIME client tests, the digitalSignature bit must be set if the keyUsage extension is present.
- S/MIME Encryption
- In addition to the common S/MIME tests, the keyEncipherment bit must be set if the keyUsage extension is present.
- S/MIME CA
- The extended key usage extension must be absent or include the “email protection” OID. Netscape certificate type must be absent or must have the S/MIME CA bit set: this is used as a work around if the basicConstraints extension is absent.
- CRL Signing
- The keyUsage extension must be absent or it must have the CRL signing bit set.
- CRL Signing CA
- The normal CA tests apply. Except in this case the basicConstraints extension must be present.
X509 BUGS
Extensions in certificates are not transferred to certificate requests and vice versa.X509 HISTORY
Before OpenSSL 0.9.8, the default digest for RSA keys was MD5.FILES
- /etc/ssl/
- Default config directory for openssl.
- /etc/ssl/lib/
- Unused.
- /etc/ssl/private/
- Default private key directory.
- /etc/ssl/openssl.cnf
- Default configuration file for openssl.
- /etc/ssl/x509v3.cnf
- Default configuration file for x509 certificates.