JBoss/Tomcat, Certificates and OpenSSL

A fairly basic HOWTO / cookbook that will attempt to cover:

  • Generating certificates (CA, server and client) with OpenSSL
    • Including converting them to PKCS12 format 
  • Generating key and trust stores for use in JBoss 
  • Configuring JBoss for server and client (browser) authentication
  • Some basic notes about client (browser) configuration

 

NOTE: Use decent passwords or all of this is a waste!!

1. Creating Certificates - OpenSSL

Setup

Configure 

Configure OpenSSL openssl.cnf

    export SSLDIR=<where your certificates live>/demoCA

mkdir  ${SSLDIR}

    mkdir ${SSLDIR}/certs
    mkdir ${SSLDIR}/crl
    mkdir ${SSLDIR}/newcerts
    mkdir ${SSLDIR}/private
    touch ${SSLDIR}/index.txt
    echo "0001" > ${SSLDIR}/serial
    echo "0001" > ${SSLDIR}/crlnumber


Usage 

Note: This does not seem to work correctly under cygwin rxvt. Use the default cygwin terminal window!

0. Certification Authority (CA) certificate

0.a Generate a key for the CA certificate - this should have a larger keysize as it secures all other certificates
    openssl genrsa -des3 -out ./demoCA/private/cakey.pem 2048 

0.b Convert the key you generated into a self-signed CA certificate..

The cakey.pem file should reside in the demoCA/private/ directory when it is being used. It must be kept very safe! So perhaps store it on removable media while it is not needed.

@param req Specifies that this produces a Certificate REQuest
@param -new Specifies that this is a NEW request (not a renewal etc...)
@param -x509 Specifies that this produces an x509 Certificate
@param -key <key filename> The file that contains the Key for this request
@returns -out <ca certificate filename> The filename of the CA Certificate

    openssl req -new -x509 -key ./demoCA/private/cakey.pem -out  ./demoCA/cacert.pem

 

1. Generate a key

This is the first step to creating any Certificate (be it CA, Client, Server, etc...). It is used to generate the certificate request. You must generate a separate key for each certificate!

@param genrsa Specifies that this should generate an RSA Key
@param -des3 Specifies that this key needs a password
@param <keysize> Specifies how long the key should be 1024 is probably a minimum these days
@returns -out <certificate key filename> The filename of the keyfile
    openssl genrsa -des3 -out certificate-key.pem 1024 


2. Generate a certificate request

This is a request for a certificate this would be sent to Verisign etc... or used by your own internal CA to generate the certificate 

@param req Specifies that this produces a Certificate REQuest
@param -new Specifies that this is a NEW request (not a renewal etc...)
@param -key <key filename> The file that contains the Key for this request
@returns -out <certificate request filename> The filename of the request
    openssl req -new -key certificate-key.pem -out certificate-req.pem

 

3. Generate and sign a certificate (from certificate request)

This builds the certificate from the request using a specific CA. You can set days of validity or a start and end date here too. Otherwise it takes the defaults from the config file

@param x509 Specifies that this produces an x509 Certificate
@param ca Specifies that this is a CA action
@param -req Specifies that this is from a request
@param -in <Request filename> The certificate request used to create this certificate
@returns -out <certificate filename> The filename of the Certificate
    openssl ca -in
certificate-req.pem -out certificate.pem -notext

3b. Generate and sign a certificate (from certificate request) for a sub CA
Add the extension that this new certificate will be a ca


    openssl ca -extensions v3_ca -in
certificate-req.pem -out sub-ca-cert.pem -notext


4. Convert a certificate into DER format:

@returns x509 Specifies that this produces an x509 certificate
@param -in <Request filename> The certificate request used to create this certificate
@returns -outform der Specifes that this produces x509 der format file
@returns -out <certificate filename> The filename of the Certificate
    openssl x509 -in certificate.pem -outform der -out certificate.der


5. Convert a certificate to pkcs12 format

This procduces a PKCS12 format file that contains both the certificate and the key. This type of file is suitable for installation into the client's browser (eg Microsoft Internet Explorer or Mozilla Firefox etc...) 

@param -in <certificate filename> The input client certificate file
@param -inkey <certificate key filename> The input client key file used to generate the orignal certificate request (@see Generate  Key)
@param -certfile <CA certificate filename> The CA Certificate to attach as  the certificate chain
@param -name "<A nice name for the certificate>" The name displayed in Internet Explorer or other browsers
@returns -out <certificate p12 format output filename>
    openssl pkcs12 -export -in certificate.pem -inkey certificate-key.pem  /
        -certfile ./demoCA/
cacert.pem -out client.p12 -name "Name of Certificate"

6. Create a Certificate Revocation List (CRL)

This command creates the initial (empty) CRL for your CA, valid for 90 days. Once this CRL expires, you can simply create a new one. 

    openssl ca -gencrl -crldays 90 -out ./demoCA/crlFile.pem

To revoke an actual certificate: 

    openssl ca -revoke certificate.pem

You now need to publish this information in a CRL file: 

    openssl ca -gencrl -crldays 90 -out ./demoCA/crlFile.pem 

You can view the list of revoked certificates in a CRL using the following command:

    openssl crl -in ./demoCA/crlFile.pem -text -noout

 

2. Building Trust and Key Stores

This section describes how to build key and trust stores (ie you do not need to keep a copy of each client certificate in the server).

  • Create a CA (see earlier section)
  • Create a server certificate as above, sign it with the CA certificate and convert to PKCS12 format
  • Create any number of client certificates as above, sign them with the CA certificate, convert them to PKCS12 format and send them to the clients and get them to install them in their browsers (see later section on client installation). 

2.2 Trust Store

A trust store contains trusted certificates. These can be individual certificates of specific people, or more likely and more useful CA certificates of Authorities that are trusted. ANY client certificates signed by CA certificates that are in the trust store will be trusted. So make sure that there are no other certificates in the trust store (eg Verisign CA) unless you want people with certificates issued by those other CAs to also be able to access your application.  

Import the PEM format CA certificate into the server truststore:

    keytool -import -v -keystore server.truststore -storepass 123456 -file ca-cert.pem
  

Then copy the server.truststore file to the jboss conf directory  

    cp server.truststore ${jboss.server.home.dir}/conf/ 

 

2.2 Key Store

The key store is where the server keeps its keys (certificates that it will present to the client). The client (browser) will need to trust this certificate explicitly or the CA that signed it so as not to display a warning message about "untrusted certificate". So in this case you can either

A) import a server certificate in PEM format (as decribed in 2.2) into the keystore. The client will then need to trust that certificate explicitly - which IMHO is not neat, esp if the server certificate expires at some time.

B) import the CA signed server certificate with the certificate chain PKCS12 format into the keystore. The client then only needs to trust the CA certificate - which if you have sent them their own PKCS12 certificate - will happen automatically at their end (or at least as part of the installation)

Import server certificate (in PKCS12 format) into the server keystore: 

Unfortunately keytool cannot handle PKCS12 format certificates so a work around is as follows: 

To do this a java class taken from Jetty is used. Download Jetty (if required) and locate the PKCS12Import.java file. This needs to be compiled and then run (from within the jetty-5.1.11RC0/classes/org/mortbay/util directory):

    java -classpath ../../../../lib/org.mortbay.jetty.jar org.mortbay.util.PKCS12Import     server.p12 server.keystore
Enter input keystore passphrase: <this is the passphrase of the p12 file>
Enter output keystore passphrase: <this is the passphrase of the keystore>

The next two steps are not required
but neater if you need to look inside the keystore later. The PKCS12Import class puts the host certificate and key into the keystore with an alias of 1. To rename the alias the following steps are required :
    keytool -keyclone -keystore server.keystore -alias 1 -dest <host_name>

Then delete the alias 1 from the keystore using:

    keytool -delete -keystore server.keystore -alias 1 

To check the content of your keystore
    keytool -list -v -keystore
server.keystore
This should contain the entry of type keyEntry, which is a chain of certificates. 

Then copy the server.keystore file to the conf directory as well

    cp server.keystore ${jboss.server.home.dir}/conf/

 

3. Configuring Tomcat for Authentication

This section describes how to use the key and trust stores created in Section 2.

Where only the CA certificates is stored in the server.truststore (ie you do not need to keep a copy of each client certificate in the server) you need to be able to use Certifcate Revocation Lists (CRLs) see further down for how to implement this. Basically this translates to:

 

3.1  Allow all signed by CA (via the CA certificate in the trust store)

In jboss-3.2.4+ the tomcat-5.0.x container has its configuration in the jbossweb-tomcat50.sar/server.xml descriptor.

Edit jbossweb-tomcat50.sar/server.xml and uncomment the following section and update the keystoreFile and truststoreFile sections to match the ones you have created:

  <!-- SSL/TLS Connector configuration using the admin devl guide keystore-->
    <Connector port="8443" address="${jboss.bind.address}"
        maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"                                emptySessionPath="true"
        scheme="https" secure="true" clientAuth="true"
        sslProtocol = "TLS"
        keystoreFile="${jboss.server.home.dir}/conf/server.keystore"
            keystorePass="123456"
        truststoreFile="${jboss.server.home.dir}/conf/server.truststore"
            truststorePass="123456"
  />

  • Start your JBoss server and attempt to reach it at for example: https://localhost:8443/jmx-console/index.jsp
  • This should fail.
  • Now install a revoked client pkcs12 certificate into your browser.
  • Attempt to connect again. It should also fail. It may show a nice error it may not depending on the browser.
  • Now remove the revoked one and install a good client pkcs12 certificate into your browser
  • Attempt to connect again. It should work this time
    • if you have not signed the server certificate with the CA certificate you will be warned of an untrusted certificate.
    • if you have signed the server certificate you will need to also install the CA certificate into your browser.
    • if it is the same CA as your client certificate it should just be trusted without a warning.  

 

3.2 Deny revoked certificates (via the CRL)

For CRL to work in JBoss/Tomcat the ${jboss.server.home.dir}/deploy/jbossweb-tomcat55.sar/tomcat-util.jar must contain the classes:

  • org.apache.tomcat.util.net.jsse.JSSE15Factory
  • org.apache.tomcat.util.net.jsse.JSSE15SocketFactory

    To arrange this it is necessary to do some recompilation with a JDK1.5 target. If you do not update this jar CRL will NOT work! A copy of the recompiled jar containing the required libraries is here on an as is basis, (I have no idea if this affects other functions, security concerns, performance etc... so use at own risk, don't run with scisors blah blah).

Create a CRL (see earlier on this page) and copy the CRL into the conf directory so that the server can access it.

 

    cp crlFile.pem ${jboss.server.home.dir}/conf/server.crlFile
 
 

Edit jbossweb-tomcat50.sar/server.xml and include the extra line: 

  <!-- SSL/TLS Connector configuration using the admin devl guide keystore-->
    <Connector port="8443" address="${jboss.bind.address}"
        maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"                                emptySessionPath="true"
        scheme="https" secure="true" clientAuth="true"
        sslProtocol = "TLS"
        keystoreFile="${jboss.server.home.dir}/conf/server.keystore"
            keystorePass="123456"
        truststoreFile="${jboss.server.home.dir}/conf/server.truststore"
            truststorePass="123456"
        crlFile="${jboss.server.home.dir}/conf/server.crlFile"  />

Restart your JBoss server and attempt to reach it at for example: https://localhost:8443/jmx-console/index.jsp

  • This should still work.
  • Now remove the good client certificate from your browser and install a revoked client PKCS12 certificate into your browser.
  • Attempt to connect again. It should now fail. It may show a nice error it may not depending on the browser.
  • Now remove the revoked one and install a good client PKCS12 certificate into your browser .
  • Attempt to connect again. It should work again.

 

NOTES:

Some articles imply that the format for the crlFile is independent of the keystore format. This does not appear to be the case.

Broken Example:   Here you have the keystore type set as PKCS12 even though the CRL is a PEM format file (and hence not PKCS12 format). PKCS12 contains the private key as well as the certificate and public key - which is not applicable for the CRL file so this seems to be why it's getting confused.
        <Connector port="8443" maxHttpHeaderSize="8192"
            maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
            enableLookups="false" disableUploadTimeout="true"
            acceptCount="100" scheme="https" secure="true"
            clientAuth="true" sslProtocol="TLS"
            crlFile="/ca/crl/crl.pem"
            keystoreType="PKCS12"                    
                                               keystoreFile="/ca/ssl/idp.p12"
            keystorePass="123456"          />
 
The only way I know of making it work is to remove the keystoreType field and building the keystores as described earlier on this page.

 

5. Client Configuration

There is a good description of the various issues at play here:     http://wiki.mozilla.org/PSM:CertPrompt 

Note this is not an extensive configuration guide (as these are more prevalent on the web), just some notes about either of these two browsers.

In general it is fairly easy to install certificates (both client and CA) in both of these browsers. Most users should be able to accomplish this with a reasonable set of instructions. Getting the browser to present the right certificate can be more challenging.

SSL sends a list of CA certificates that are acceptable for Client Authentication. Most HTTP servers build this list automatically whenever that server has CA Certificates which are configured to validate user certificates. Browsers sometimes use this information to present a certificate to the Server.


5.1 MS Internet Explorer

  • Extras/Tools --> Internet options --> Inhalt / Content --> Certificates
  • Import --> Next --> Certificate Filename --> Password for the certificate
  • Allow it to automatically store the certificate (this way CA and client certificates will end up in the correct place)
  • Finish
  • You will be asked do you trust the CA certificate and do you want to install it. Select Yes. 

Some notes:

  • If you install a client certificate PKCS12 file that contains also a CA Certificate the CA Certificate will be automatically installed under trusted certificates. (This is the last step in which occurs after you push finish above).
  • If there are multiple certificates that are valid for a given domain IE will prompt the user which certificate they would like to use. This can be nice, but if users have revoked or expired certificates they should remove them otherwise these will still appear in the list.
  • After restarting IE, it will always prompt for a certificate, even if no certificate is valid. ?IE lists all the user certificates without reguard to the certificate list presented to it?. Once IE has a cert selected for the site (or the user as selected no certificate for the site), IE will always use that certificate (or lack of certificate) for that site. The only way to change that is to use the button to clear IE's SSL cert cache. IE will prompt the user even if there is no valid certificate available.
  • Tools/Extras --> Internet Options --> Security --> Customise
    • "Don't prompt for client certificate selection when no certificates or only one certificate exists" 
    • Turning this On (dont prompt) may be useful for a basic user where only one certificate is available. 
    • Turning it Off (do prompt) may provide better debugging chances.

5.2 Mozilla Firefox

  • Tools --> Options --> Security --> View Certificates
  • Import --> Certificate Filename --> Password for the certificate
  • Finish
  • The CA certificate will be automatically installed as part of this process.

Some notes:

  • If you install a client certificate PKCS12 file that contains also a CA Certificate the CA Certificate will be automatically installed under trusted certificates.
  • Select one Automatically 
    • If there is only one certificate that is valid this is better as the user is saved an extra selection box.
    • If there are multiple certificates that are valid for a given domain FF will NOT prompt the user which certificate they would like to use. This can be nasty as if users have a revoked or expired certificates as well as a valid one they might not be able to access the site. Users will need to be prompted to remove old certificates properly.
  • Ask me every time 
    • If there are any certificates that are valid for a given domain FF will prompt the user which certificate they would like to use (even if there is only one valid one). This may be a way to see any problems with certificates on the users machine.

 

6. References

http://www.openssl.org/
http://www.gagravarr.org/writing/openssl-certs/ca.shtml
http://www.drh-consultancy.demon.co.uk/pkcs12usg.html
http://churchillobjects.com/c/11201g.html

http://wiki.jboss.org/wiki/Wiki.jsp?page=SSLSetup 

http://wiki.mozilla.org/PSM:CertPrompt 

http://mail-archives.apache.org/mod_mbox/jakarta-tomcat-user/200408.mbox/%3C20040805090009.75478.qmail@web12308.mail.yahoo.com%3E  

深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
【5层】公司办公楼全套设计+++(3156平,含计算书、建筑图,结构图、实习报告,PKPM,答辩PPT) 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值