resin-security.xtp
来自「RESIN 3.2 最新源码」· XTP 代码 · 共 1,899 行 · 第 1/5 页
XTP
1,899 行
<var>private key</var>.</glossary><p>SSL also provides the ability for a client to verify the identity of a server.This is used to protect against identity theft, where for example a maliciousperson imitates your server or redirects client traffic to a different serverwhile pretending to be you.</p><glossary title="signing authority" type="sidebar-left">A company that is trusted to sign certificates. Browsers includecertificates of signing authorities that they trust.</glossary><p>Server authentication uses the signature aspect of public key cryptography.The private key is used to sign messages, and the public key is used to verifythe signature. With SSL, the validity of signatures depends upon signingauthorities. Signing authorites (also called certificate authorities) arecompanies who have generated public keys that are included with browsersoftware. The browser knows it can trust the signing authority, and thesigning authority signs your SSL certificate, putting its stamp of approval onthe information in your certificate.</p><glossary title="certificate authority">Another name for <var>signing authority</var>. A company that is trusted tosign certificates. Browsers include certificates of signing authorities thatthey trust.</glossary><p>For example, after you generate your public and private key, you thengenerate a signing request and send it to a signing authority. This signingrequest contains information about your identity, this identity information isconfirmed by the signing authority and ultimately displayed to the user of thebrowser. The signing authority validates the identity information you haveprovided and uses their private key to sign, and then returns a<var>certificate</var> to you. This certificate contains the identity informationand your public key, verified by the signing authority, and is provided to thebrowser. Since the browser has the public key of the signing authority, it canrecognize the signature and know that the identity information has beenprovided by someone that can be trusted.</p></s2> <!-- aboutssl/Server Authentication --></s1> <!-- aboutssl --><s1 name="openssl" title="OpenSSL"><p>OpenSSL is the same SSL implementation that Apache's mod_ssluses. Since OpenSSL uses the same certificate as Apache, you can getsigned certificates using the same method as for Apache's mod_ssl orfollowing the OpenSSL instructions.</p><s2 title="Linking to the OpenSSL Libraries on Unix"><p>On Unix systems, Resin's libexec/libresinssl.so JNI librarysupports SSL using the<a href="http://www.openssl.org">OpenSSL</a> libraries.Although the ./configure script will detect many configurations,you can specify the openssl location directly:</p><example>resin> ./configure --with-openssl=/usr/local/ssl</example></s2><s2 title="Obtaining the OpenSSL Libraries on Windows"><p>On Windows systems, the resinssl.dll includes JNI code to useOpenSSL libraries (it was in resin.dll in versions before 3.0). Allyou need to do is to obtain an OpenSSL binary distribution and installit. </p> <p>Resin on Windows is compiled against the GnuWin32 binary, you can obtain aninstallation package <a href="http://gnuwin32.sourceforge.net/packages/openssl.htm">here</a>.</p><p>Once you have run the installation package, you can copy the necessarydll libraries into <code>$RESIN_HOME</code>:</p><example title="Copying the Windows SSL libraries into $RESIN_HOME">C:\> cd %RESIN_HOME%C:\resin-3.0> copy "C:\Program Files\GnuWin32\bin\libssl32.dll" .\libssl32.dllC:\resin-3.0> copy "C:\Program Files\GnuWin32\bin\libeay32.dll" .\libeay32.dll</example></s2><s2 title="Preparing to use OpenSSL for making keys"><p>You can make a <code>keys/</code> subdirectory of $RESIN_HOME to doyour work from and as a place to store your generated keys.</p><example title="$RESIN_HOME/keys">unix> cd $RESIN_HOMEunix> mkdir keysunix> cd keyswin> cd %RESIN_HOME%win> mkdir keyswin> cd keys</example><p>Using OpenSSL requires a configuration file. Unix users might findthe default configuration file in <code>/usr/ssl/openssl.cnf</code>or <code>/usr/share/ssl/openssl.cnf</code>. Windows users may nothave received one with their package.</p><p>Either way, it can be valuable to make your own<code>openssl.cnf</code> that is used just for generating the keys touse with Resin. You can use the following as a template for a file<code>$RESIN_HOME/keys/openssl.cnf</code>. You may want to fill inthe <code>_default</code> values so you don't have to type them inevery time.</p><example title="$RESIN_HOME/keys/openssl.cnf">[ req ] default_bits = 1024 distinguished_name = req_distinguished_name[ req_distinguished_name ] C = 2 letter Country Code, for example US C_default = ST = State or Province ST_default = L = City L_default = O = Organization Name O_default = OU = Organizational Unit Name, for example 'Marketing' OU_default = CN = your domain name, for example www.hogwarts.com CN_default = emailAddress = an email address emailAddress_default =</example></s2><s2 title="Creating a private key"><p>Create a private key for the server. You will be asked for apassword - don't forget it! You will need this password anytime youwant to do anything with this private key. But don't pick somethingyou need to keep secret, you will need to put this password in theResin configuration file.</p><example title="creating the private key gryffindor.key">unix> openssl genrsa -des3 -out gryffindor.key 1024win> "C:\Program Files\GnuWin32\bin\openssl.exe" \ genrsa -des3 -out gryffindor.key 1024</example></s2><s2 title="Creating a certificate"><p>OpenSSL works by having a signed public key that corresponds to yourprivate key. This signed public key is called a <var>certificate</var>. Acertificate is what is sent to the browser.</p><p>You can create a self-signed certificate, or get a certificate thatis signed by a certificate signer (CA).</p><s3 title="Creating a self-signed certificate"><p>You can create a certificate that is self-signed, which is good fortesting or for saving you money. Since it is self-signed, browsers will notrecognize the signature and will pop up a warning to browser users. Other thanthis warning, self-signed certificates work well. The browser cannot confirmthat the server is who it says it is, but the data between the browser and theclient is still encrypted.</p><example title="creating a self-signed certificate gryffindor.crt">unix> openssl req -config ./openssl.cnf -new -key gryffindor.key \ -x509 -out gryffindor.crtwin> "C:\Program Files\GnuWin32\bin\openssl.exe" req -config ./openssl.cnf \ -new -key gryffindor.key -x509 -out gryffindor.crt</example><p>You will be asked to provide some information about the identity ofyour server, such as the name of your Organization etc. Common Name(CN) is your domain name, like: "www.gryffindor.com".</p></s3><s3 title="Creating a certificate request"><p>To get a certificate that is signed by a CA, first you generate a<var>certificate signing request</var> (CSR).</p><example title="creating a certificate request gryffindor.csr">unix> openssl req -new -config ./openssl.cnf -key gryffindor.key \ -out gryffindor.csrwin> "C:\Program Files\GnuWin32\bin\openssl.exe" req -new \ -config ./openssl.cnf -key gryffindor.key -out gryffindor.csr</example><p>You will be asked to provide some information about the identity ofyour server, such as the name of your Organization etc. Common Name(CN) is your domain name, like: "www.gryffindor.com".</p><p>Send the CSR to a certificate signer (CA). You'll use the CA'sinstructions for Apache because the certificates are identical. Somecommercial signers include:</p><ul><li><a href="http://digitalid.verisign.com/server/apacheNotice.htm">Verisign</a></li><li><a href="http://www.thawte.com/certs/server/request.html">Thawte Consulting</a></li></ul><p>You'll receive a <em>gryffindor.crt</em> file.</p><p>Most browsers are configured to recognize the signature of signingauthorities. Since they recognize the signature, they will not pop up awarning message the way they will with self-signed certificates. The browsercan confirm that the server is who it says it is, and the data between thebrowser and the client is encrypted.</p></s3></s2><s2 title="resin.xml - Configuring Resin to use your private key and certificate"><p>The OpenSSL configuration has two tags <a config-tag="certificate-file"/> and<a config-tag="certificate-key-file"/>. These correspond exactly to mod_ssl'sSSLCertificateFile and SSLCertificateKeyFile. So you can use the samecertificates (and documentation) from mod_ssl for Resin.</p><p>The full set of parameters is in the port configuration.</p> <example>...<http port="443"> <openssl> <certificate-file>keys/gryffindor.crt</certificate-file> <certificate-key-file>keys/gryffindor.key</certificate-key-file> <password>my-password</password> </openssl></http></example></s2><s2 title="Testing"><s3 title="Testing with the browser"><!--<p><jsp:scriptlet>if (request.isSecure()) {</jsp:scriptlet></p><p><code>request.isSecure()</code> is reporting true, so it looks likeyou have SSL working and are viewing this page over an SSL encryptedconnection.</p><jsp:scriptlet>} else {</jsp:scriptlet><p>Once you have SSL configured, you can come back to this page usingan <code>https://</code> style URL instead of an <code>http://</code>url and you will get a message telling that SSL is working.<jsp:scriptlet>}</jsp:scriptlet></p>--><p>A quick test is the following JSP.</p><example>Secure? <%= request.isSecure() %></example></s3><s3 title="Using openssl to test the server"><p>The openssl tool can be used as a client, showing some interesting informationabout the conversation between the client and the server:</p><example>unix$ openssl s_client -connect www.some.host:443 -prexit</example></s3></s2> <!-- testing --><s2 title="Certificate Chains"><p>A <var>certificate chain</var> is used when the signing authority is not anauthority trusted by the browser. In this case, the signing authority uses acertificate which is in turn signed by a trusted authority, giving a chain of<code>[your certificate] <--- signed by ---- [untrusted signer] <---- signed by ---- [trusted signer]</code>.</p><p>The Resin config parameter <a config-tag="certificate-chain-file"/> is used tospecify a certificate chain. It is used to reference a file that is aconcatenation of:</p><ol><li>your certificate file</li><li>the intermediate (untrusted) certificate</li><li>the root (trusted) certificate.</li></ol><p>The certificates must be in that order, and must be in PEM format.</p><s3 title="Example certificate chain for Instant SSL"><p><a href="http://instantssl.com">Comodo (http://instantssl.com)</a> is a signingauthority that is untrusted by most browsers. Comodo has their certificatesigned by GTECyberTrust.</p><p>Comodo gives you three certificates:</p><ol><li><code>your_domain.crt</code> (signed by Comodo)</li><li><code>ComodoSecurityServicesCA.crt</code> (signed by GTE CyberTrust)</li><li><code>GTECyberTrustRoot.crt</code> (universally known root)</li></ol><p>In addition to this, you have your key, <code>your_domain.key</code>.The contents of the file referred to by <a config-tag="certificate-chain-file"/> is a concatenation of the threecertificates, in the correct order.</p><example title="Creating a certificate chain file">$ cat your_domain.crt ComodoSecurityServicesCA.crt GTECyberTrustRoot.crt > chain.txt</example><example title="resin.xml using a certificate chain file"><http port="443"> <openssl> <certificate-key-file>keys/your_domain.key</certificate-key-file> <certificate-file>keys/your_domain.crt</certificate-file> <certificate-chain-file>keys/chain.txt</certificate-chain-file> <password>test123</password> </openssl></http></example></s3> <!-- example certificate chain --></s2> <!-- certificate chain --></s1> <!-- OpenSSL --><s1 name="jsse" title="JSSE"><p>We recommend avoiding JSSE if possible. It is slower than usingResin's OpenSSL support and does not appear to be as stable as Apacheor IIS (or Netscape/Zeus) for SSL support. In addition, JSSE is farmore complicated to configure. While we've never received any problemswith Resin using OpenSSL, or SSL from Apache or IIS, JSSE issues arefairly frequent.</p><s2 title="Install JSSE from Sun"><p>This section gives a quick guide to installing a test SSLconfiguration using Sun's JSSE. It avoids as many complications aspossible and uses Sun's keytool to create a server certificate.</p><p>Resin's SSL support is provided by Sun's<a href="http://java.sun.com/products/jsse">JSSE</a>. Because ofexport restrictions, patents, etc, you'll need to download the JSSEdistribution from Sun or get a commercial JSSE implementation.</p><p>More complete JSSE installation instructions for JSSE are at<a href="http://java.sun.com/products/jsse/install.html">http://java.sun.com/products/jsse/install.html</a>.</p><ol><li>First download Sun's <a href="http://java.sun.com/products/jsse">JSSE</a>.</li><li>Uncompress and extract the downloaded file.</li><li>Install the JSSE jar files: jsse.jar, jnet.jar, and jcert.jar. You caneither put them into the CLASSPATH or you can put them into $JAVA_HOME/jre/lib/ext. Since you will use "keytool" with the new jars, you need to make t
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?