<HTML ><HEAD ><TITLE >OpenSSL functions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Function Reference" HREF="funcref.html"><LINK REL="PREVIOUS" TITLE="OCIWriteLobToFile" HREF="function.ociwritelobtofile.html"><LINK REL="NEXT" TITLE="openssl_csr_export_to_file" HREF="function.openssl-csr-export-to-file.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="reference" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.ociwritelobtofile.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.openssl-csr-export-to-file.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="reference" ><A NAME="ref.openssl" ></A ><DIV CLASS="TITLEPAGE" ><H1 CLASS="title" >LXXII. OpenSSL functions</H1 ><DIV CLASS="PARTINTRO" ><A NAME="AEN67681" ></A ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.intro" ></A >Introduction</H1 ><P > This module uses the functions of <A HREF="http://www.openssl.org/" TARGET="_top" >OpenSSL</A > for generation and verification of signatures and for sealing (encrypting) and opening (decrypting) data. OpenSSL offers many features that this module currently doesn't support. Some of these may be added in the future. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.requirements" ></A >Requirements</H1 ><P > In order to use the OpenSSL functions you need to install the <A HREF="http://www.openssl.org/" TARGET="_top" >OpenSSL</A > package. PHP-4.0.4pl1 requires OpenSSL >= 0.9.6, but PHP-4.0.5 and greater will also work with OpenSSL >= 0.9.5. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.installation" ></A >Installation</H1 ><P > To use PHP's OpenSSL support you must also compile PHP <TT CLASS="option" >--with-openssl[=DIR]</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note to Win32 Users: </B > In order to enable this module on a Windows environment, you must copy <SPAN CLASS="emphasis" ><I CLASS="emphasis" >libeay32.dll</I ></SPAN > from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32) </P ><P > Additionally, if you are planning to use the key generation and certificate signing functions, you will need to install a valid <TT CLASS="filename" >openssl.cnf</TT > on your system. As of PHP 4.3.0, we include a sample configuration file in the <TT CLASS="filename" >openssl</TT > of our win32 binary distribution. If you are using PHP 4.2.0 or later and are missing the file, you can obtain it from <A HREF="http://www.openssl.org/" TARGET="_top" >the OpenSSL home page</A > or by downloading the PHP 4.3.0 release and using the configuration file from there. </P ><P ><B >Note to Win32 Users: </B > PHP will search for the <TT CLASS="filename" >openssl.cnf</TT > using the following logic: <P ></P ><UL ><LI ><P >the <TT CLASS="literal" >OPENSSL_CONF</TT > environmental variable, if set, will be used as the path (including filename) of the configuration file. </P ></LI ><LI ><P >the <TT CLASS="literal" >SSLEAY_CONF</TT > environmental variable, if set, will be used as the path (including filename) of the configuration file. </P ></LI ><LI ><P >The file <TT CLASS="filename" >openssl.cnf</TT > will be assumed to be found in the default certificate area, as configured at the time that the openssl DLL was compiled. This is usually means that the default filename is <TT CLASS="filename" >c:\usr\local\ssl\openssl.cnf</TT >. </P ></LI ></UL > </P ><P > In your installation, you need to decide whether to install the configuration file at <TT CLASS="filename" >c:\usr\local\ssl\openssl.cnf</TT > or whether to install it someplace else and use environmental variables (possibly on a per-virtual-host basis) to locate the configuration file. Note that it is possible to override the default path from the script using the <TT CLASS="parameter" ><I >configargs</I ></TT > of the functions that require a configuration file. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.configuration" ></A >Runtime Configuration</H1 ><P >This extension has no configuration directives defined in <TT CLASS="filename" >php.ini</TT >.</P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.resources" ></A >Resource Types</H1 ><P > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.certparams" ></A >Key/Certificate parameters</H1 ><P > Quite a few of the openssl functions require a key or a certificate parameter. PHP 4.0.5 and earlier have to use a key or certificate <A HREF="language.types.resource.html" ><B CLASS="type" >resource</B ></A > returned by one of the openssl_get_xxx functions. Later versions may use one of the following methods: <P ></P ><UL ><LI ><P > Certificates <P ></P ><OL TYPE="1" ><LI ><P > An X.509 resource returned from <A HREF="function.openssl-x509-read.html" ><B CLASS="function" >openssl_x509_read()</B ></A > </P ></LI ><LI ><P >A string having the format <TT CLASS="filename" >file://path/to/cert.pem</TT >; the named file must contain a PEM encoded certificate </P ></LI ><LI ><P > A string containing the content of a certificate, PEM encoded </P ></LI ></OL > </P ></LI ><LI ><P > Public/Private Keys <P ></P ><OL TYPE="1" ><LI ><P >A key resource returned from <A HREF="function.openssl-get-publickey.html" ><B CLASS="function" >openssl_get_publickey()</B ></A > or <A HREF="function.openssl-get-privatekey.html" ><B CLASS="function" >openssl_get_privatekey()</B ></A > </P ></LI ><LI ><P >For public keys only: an X.509 resource</P ></LI ><LI ><P >A string having the format <TT CLASS="filename" >file://path/to/file.pem</TT > - the named file must contain a PEM encoded certificate/private key (it may contain both) </P ></LI ><LI ><P > A string containing the content of a certificate/key, PEM encoded </P ></LI ><LI ><P > For private keys, you may also use the syntax <SPAN CLASS="emphasis" ><I CLASS="emphasis" >array($key, $passphrase)</I ></SPAN > where $key represents a key specified using the file:// or textual content notation above, and $passphrase represents a string containing the passphrase for that private key </P ></LI ></OL > </P ></LI ></UL > </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.cert.verification" ></A >Certificate Verification</H1 ><P > When calling a function that will verify a signature/certificate, the <SPAN CLASS="emphasis" ><I CLASS="emphasis" >cainfo</I ></SPAN > parameter is an array containing file and directory names that specify the locations of trusted CA files. If a directory is specified, then it must be a correctly formed hashed directory as the <B CLASS="command" >openssl</B > command would use. </P ></DIV ><DIV CLASS="section" ><H1 CLASS="section" ><A NAME="openssl.constants" ></A >Predefined Constants</H1 ><P > The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime. </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SSL_CLIENT</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SSL_SERVER</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_NS_SSL_SERVER</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SMIME_SIGN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_SMIME_ENCRYPT</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_CRL_SIGN</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >X509_PURPOSE_ANY</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_PKCS1_PADDING</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_SSLV23_PADDING</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_NO_PADDING</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_PKCS1_OAEP_PADDING</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_KEYTYPE_RSA</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_KEYTYPE_DSA</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ><DT ><TT CLASS="constant" ><B >OPENSSL_KEYTYPE_DH</B ></TT > (<A HREF="language.types.integer.html" >integer</A >)</DT ><DD ><P > </P ></DD ></DL ></DIV ><DIV CLASS="section" ><H2 CLASS="section" ><A NAME="openssl.pkcs7.flags" ></A >PKCS7 Flags/Constants</H2 ><P > The S/MIME functions make use of flags which are specified using a bitfield which can include one or more of the following values: <DIV CLASS="table" ><A NAME="AEN67854" ></A ><P ><B >Table 1. PKCS7 CONSTANTS</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><THEAD ><TR ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Constant</TH ><TH ALIGN="LEFT" VALIGN="MIDDLE" >Description</TH ></TR ></THEAD ><TBODY ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_TEXT</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >adds text/plain content type headers to encrypted/signed message. If decrypting or verifying, it strips those headers from the output - if the decrypted or verified message is not of MIME type text/plain then an error will occur.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_BINARY</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >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 options is present, no translation occurs. This is useful when handling binary data which may not be in MIME format.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_NOINTERN</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >when verifying a message, certificates (if any) included in the message are normally searched for the signing certificate. With this option only the certificates specified in the <TT CLASS="parameter" ><I >extracerts</I ></TT > parameter of <A HREF="function.openssl-pkcs7-verify.html" ><B CLASS="function" >openssl_pkcs7_verify()</B ></A > are used. The supplied certificates can still be used as untrusted CAs however. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_NOVERIFY</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >do not verify the signers certificate of a signed message.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_NOCHAIN</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >do not chain verification of signers certificates: that is don't use the certificates in the signed message as untrusted CAs. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_NOCERTS</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >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 signers certificate available locally (passed using the <TT CLASS="parameter" ><I >extracerts</I ></TT > to <A HREF="function.openssl-pkcs7-verify.html" ><B CLASS="function" >openssl_pkcs7_verify()</B ></A > for example. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_NOATTR</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >normally when a message is signed, a set of attributes are included which include the signing time and the supported symmetric algorithms. With this option they are not included. </TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_DETACHED</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >When signing a message, use cleartext signing with the MIME type multipart/signed. This is the default if the <TT CLASS="parameter" ><I >flags</I ></TT > parameter to <A HREF="function.openssl-pkcs7-sign.html" ><B CLASS="function" >openssl_pkcs7_sign()</B ></A > if you do not specify any flags. If you turn this option off, the message will be signed using opaque signing, which is more resistant to translation by mail relays but cannot be read by mail agents that do not support S/MIME.</TD ></TR ><TR ><TD ALIGN="LEFT" VALIGN="MIDDLE" >PKCS7_NOSIGS</TD ><TD ALIGN="LEFT" VALIGN="MIDDLE" >Don't try and verify the signatures on a message</TD ></TR ></TBODY ></TABLE ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B >These constants were added in 4.0.6.</P ></BLOCKQUOTE ></DIV ></DIV ></DIV ></DIV ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT ><A HREF="function.openssl-csr-export-to-file.html" >openssl_csr_export_to_file</A > -- Exports a CSR to a file</DT ><DT ><A HREF="function.openssl-csr-export.html" >openssl_csr_export</A > -- Exports a CSR as a string</DT ><DT ><A HREF="function.openssl-csr-new.html" >openssl_csr_new</A > -- Generates a CSR</DT ><DT ><A HREF="function.openssl-csr-sign.html" >openssl_csr_sign</A > -- Sign a CSR with another certificate (or itself) and generate a certificate</DT ><DT ><A HREF="function.openssl-error-string.html" >openssl_error_string</A > -- Return openSSL error message</DT ><DT ><A HREF="function.openssl-free-key.html" >openssl_free_key</A > -- Free key resource</DT ><DT ><A HREF="function.openssl-get-privatekey.html" >openssl_get_privatekey</A > -- Get a private key</DT ><DT ><A HREF="function.openssl-get-publickey.html" >openssl_get_publickey</A > -- Extract public key from certificate and prepare it for use</DT ><DT ><A HREF="function.openssl-open.html" >openssl_open</A > -- Open sealed data</DT ><DT ><A HREF="function.openssl-pkcs7-decrypt.html" >openssl_pkcs7_decrypt</A > -- Decrypts an S/MIME encrypted message</DT ><DT ><A HREF="function.openssl-pkcs7-encrypt.html" >openssl_pkcs7_encrypt</A > -- Encrypt an S/MIME message</DT ><DT ><A HREF="function.openssl-pkcs7-sign.html" >openssl_pkcs7_sign</A > -- sign an S/MIME message</DT ><DT ><A HREF="function.openssl-pkcs7-verify.html" >openssl_pkcs7_verify</A > -- Verifies the signature of an S/MIME signed message</DT ><DT ><A HREF="function.openssl-pkey-export-to-file.html" >openssl_pkey_export_to_file</A > -- Gets an exportable representation of a key into a file </DT ><DT ><A HREF="function.openssl-pkey-export.html" >openssl_pkey_export</A > -- Gets an exportable representation of a key into a string</DT ><DT ><A HREF="function.openssl-pkey-get-private.html" >openssl_pkey_get_private</A > -- Get a private key</DT ><DT ><A HREF="function.openssl-pkey-get-public.html" >openssl_pkey_get_public</A > -- Extract public key from certificate and prepare it for use</DT ><DT ><A HREF="function.openssl-pkey-new.html" >openssl_pkey_new</A > -- Generates a new private key </DT ><DT ><A HREF="function.openssl-private-decrypt.html" >openssl_private_decrypt</A > -- Decrypts data with private key </DT ><DT ><A HREF="function.openssl-private-encrypt.html" >openssl_private_encrypt</A > -- Encrypts data with private key </DT ><DT ><A HREF="function.openssl-public-decrypt.html" >openssl_public_decrypt</A > -- Decrypts data with public key </DT ><DT ><A HREF="function.openssl-public-encrypt.html" >openssl_public_encrypt</A > -- Encrypts data with public key </DT ><DT ><A HREF="function.openssl-seal.html" >openssl_seal</A > -- Seal (encrypt) data</DT ><DT ><A HREF="function.openssl-sign.html" >openssl_sign</A > -- Generate signature</DT ><DT ><A HREF="function.openssl-verify.html" >openssl_verify</A > -- Verify signature</DT ><DT ><A HREF="function.openssl-x509-check-private-key.html" >openssl_x509_check_private_key</A > -- Checks if a private key corresponds to a certificate</DT ><DT ><A HREF="function.openssl-x509-checkpurpose.html" >openssl_x509_checkpurpose</A > -- Verifies if a certificate can be used for a particular purpose</DT ><DT ><A HREF="function.openssl-x509-export-to-file.html" >openssl_x509_export_to_file</A > -- Exports a certificate to file</DT ><DT ><A HREF="function.openssl-x509-export.html" >openssl_x509_export</A > -- Exports a certificate as a string</DT ><DT ><A HREF="function.openssl-x509-free.html" >openssl_x509_free</A > -- Free certificate resource</DT ><DT ><A HREF="function.openssl-x509-parse.html" >openssl_x509_parse</A > -- Parse an X509 certificate and return the information as an array</DT ><DT ><A HREF="function.openssl-x509-read.html" >openssl_x509_read</A > -- Parse an X.509 certificate and return a resource identifier for it</DT ></DL ></DIV ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.ociwritelobtofile.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.openssl-csr-export-to-file.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >OCIWriteLobToFile</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="funcref.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >openssl_csr_export_to_file</TD ></TR ></TABLE ></DIV ></BODY ></HTML >