Ubuntu 14.04 安装 Ejbca (Install Ejbca on Ubuntu 14.04)

[warning]首先,如果不是万不得已,请不要使用 EJBCA,请不要阅读本文章!这个软件真的不是正常人可以驾驭的!如果只是个人兴趣(比如我就是装着好玩),那么请千万不要尝试使用 EJBCA!非常蛋疼!千万不要用!而且这玩意的搭建特别看脸,说不定啥时候就成功了。本文的成功方法并无法复制。[/warning]

这个玩意毕竟是一个商业软件的社区免费版,功能先不说,Bug一定是比商业版多一大堆的。而且官方给的文档也基本都很老了,并且不全,大部分你遇到的问题官方文档都不会说的。官方文档似乎最喜欢教你怎么配置,当然反正按照那个配一样成功不了。。。官方这么做当然另一个目的就是卖收费服务,不然免费的随便配置下就成功了谁还买呢。。。

至于官方的 Quick Start,直接无视吧。如果你按照官方的 Quick Start 成功的把服务搭起来了,那我只能佩服你了。。。反正我一开始一直遵照官方的教程死活也没有成功过一次。直到我找到一篇第三方的教程,才终于成功了一次。原教程地址:http://ejbcacentos.blogspot.hk/2014/04/how-to-install-ejbca-611-on-centos-65.html 因为是全英文的而且需要科学上网来访问,所以我在这里参考这篇教程把我配置的过程写一下。如果按照教程配置不成功请不要提问!我也不知道为什么!我自己配十次能成功一次就很开心了!


介绍

EJBCA 是一个用 Java 编写的可以在网页上完成所有操作的全功能 CA 服务器,只要是 CA 应该支持的功能这个软件全都支持。但是!这个软件的安装完全不像官方说的那么简单!如果你只是想玩玩,建议直接下载官方的虚拟机镜像玩吧。

准备

首先要安装相关依赖。因为我在后端数据库的选择上使用的是 Mysql,所以我需要装这么些东西:
sudo apt-get install openjdk-7-jdk ant ant-optional unzip ntp mysql-server libmysql-java
那篇教程里说 Java 7 会有问题,实际上似乎已经修复了,所以可以直接用。源里 ant 的版本是 1.8.2,满足最低的版本要求,所以也可以直接用,不用下载最新的。libmysql-java 是 Java 连接 Mysql 数据库所需要的必须的组建,因为我使用 Mysql 作为后端,所以需要安装。然后防火墙什么的就不管他了,建议你在确定配置成功的情况下再去搞别的,不然纯属浪费时间。。。

配置 Mysql

mysql 主要是要更改一下默认的编码,确保一直使用 UTF-8 作为编码方式,防止乱码。在 my.cnf 中加入这一段:
#UTF-8
character-set-server=utf8
collation-server=utf8_unicode_ci
init-connect='SET NAMES utf8'
#character-set-client = utf8

然后使用 root 账号登陆,新建数据库和账号:
service mysqld start
mysql_secure_installation
mysql -u root -p
create database ejbcadb;
grant all privileges on ejbcadb.* to 'ejbcadbuser'@'localhost' identified by 'password';
flush privileges;
exit

然后确认一下你刚刚创建的账号可以正常的访问数据库:
mysql -u ejbcadbuser -p
use ejbcadb;
show grants for ejbcadbuser@localhost;
exit

创建用户

建议不要直接使用 root 用户来安装 EJBCA,而是分配专门的账户。所以我们使用 adduser ejbca 添加一个用户。然后执行 su – ejbca,切换到 ejbca 用户下操作。

下载 Ejbca 和 Jboss

wget http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip
wget http://downloads.sourceforge.net/project/ejbca/ejbca6/ejbca_6_2_0/ejbca_ce_6_2_0.zip
unzip *.zip
ln -s ejbca_ca_6_2_0 ejbca
ln -s jboss-as-7.1.1.Final jboss

配置 Jboss

cd /opt/jboss/modules/sun/jdk/main
vi module.xml

在适当位置添加下面几行:(注释不要加进去)
### Start module.xml Delta ###

### End module.xml Delta ###

安装 Mysql 连接组件

cd ~
mkdir -p jboss/modules/com/mysql/main/
ln -s /usr/share/java/mysql.jar
vi module.xml

新建 module.xml 文件,写入如下内容:
### Start module.xml ###










### End module.xml ###
现在可以启动 Jboss 了。打开一个新的终端或者使用 screen 执行 ~/jboss/bin/standalone.sh。日志会写入 ~/jboss/standalone/log/
如果你看到这样的日志,说明 Jboss 应该是启动成功了:
22:51:40,482 INFO [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-2) Starting Coyote HTTP/1.1 on http--127.0.0.1-8080
22:51:40,688 INFO [org.jboss.as.remoting] (MSC service thread 1-3) JBAS017100: Listening on /127.0.0.1:4447
22:51:40,690 INFO [org.jboss.as.remoting] (MSC service thread 1-2) JBAS017100: Listening on /127.0.0.1:9999
22:51:40,699 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) JBAS015012: Started FileSystemDeploymentService for directory /opt/jboss/standalone/deployments
22:51:40,773 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
22:51:40,774 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 1528ms - Started 130 of 204 services (74 services are passive or on-demand)

接下来给 Jboss 添加 Mysql 连接器:
cd ~/jboss/bin
sh jboss-cli.sh
connect
/subsystem=datasources/jdbc-driver=com.mysql.jdbc.Driver:add(driver-name=com.mysql.jdbc.Driver,driver-module-name=com.mysql,driver-xa-datasource-class-name=com.mysql.jdbc.jdbc.jdbc2.optional.MysqlXADataSource)
:reload
exit

这句话在 ~/jboss/standalone/configuration/standalone.xml 中定义了 Mysql Driver ,然后重启 Jboss。
接下来修改 Jboss 的配置文件,删掉自带的 h2 数据库:
### Start standalone.xml Delta ###

删除这一段:


jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
h2

sa sa

还有这一段:


org.h2.jdbcx.JdbcDataSource

### End standalone.xml Delta ###
好了!现在可以开始配置 Ejbca 了。

配置 Ejbca

Ejbca 的配置文件在这个文件夹里:
~/ejbca/conf/
默认配置文件都以 .sample 结尾。需要修改的话删除 .sample 然后进行相应的修改即可。
cd ~/ejbca/conf
cp certstore.properties.sample certstore.properties
cp cesecore.properties.sample cesecore.properties
cp crlstore.properties.sample crlstore.properties
cp database.properties.sample database.properties
cp ejbca.properties.sample ejbca.properties
cp install.properties.sample install.properties
cp mail.properties.sample mail.properties
cp web.properties.sample web.properties

接下来是要改的配置。这里只放出需要修改的行:
certstore.properties

### Start certstore.properties ###

certstore.enabled=true

certstore.contextroot=/certificates

### End certstore.properties ###

cesecore.properties

### Start cesecore.properties ###

ca.toolateexpiredate=80000000

securityeventsaudit.implementation.X=org.cesecore.audit.impl.log4j.Log4jDevice
securityeventsaudit.implementation.X=org.cesecore.audit.impl.integrityprotected.IntegrityProtectedDevice

securityeventsaudit.implementation.0=org.cesecore.audit.impl.log4j.Log4jDevice
securityeventsaudit.implementation.1=org.cesecore.audit.impl.integrityprotected.IntegrityProtectedDevice
securityeventsaudit.exporter.1=org.cesecore.audit.impl.AuditExporterXml

### End cesecore.properties ###

crlstore.properties

### Start crlstore.properties ###

crlstore.enabled=true
crlstore.contextroot=/crls

### End crlstore.properties ###

database.properties

### Start database.properties ###

datasource.jndi-name=EjbcaDS

database.name=mysql

database.url=jdbc:mysql://127.0.0.1:3306/ejbcadb?characterEncoding=UTF-8
database.driver=com.mysql.jdbc.Driver

database.username=ejbcadbuser

# Change this to your mysql user password:
database.password=pumpkin

### End database.properties ###

ejbca.properties

### Start ejbca.properties ###

appserver.home=/home/ejbca/jboss
appserver.type=jboss

ejbca.productionmode=false

approval.defaultrequestvalidity=28800
approval.defaultapprovalvalidity=28800

healthcheck.amountfreemem=32
healthcheck.dbquery=Select 1 From CertificateData where fingerprint='XX'
healthcheck.authorizedips=127.0.0.1
healthcheck.catokensigntest=true
healthcheck.publisherconnections=true
healthcheck.okmessage=ALLOK
healthcheck.sendservererror=true

ejbca.passwordlogrounds=8

### End ejbca.properties ###

install.properties

### Start install.properties ###

ca.name=mgmtca
ca.dn=CN=mgmtca,O=Your Company,C=US
ca.tokentype=soft
ca.tokenpassword=null

ca.keyspec=4096

ca.keytype=RSA

ca.signaturealgorithm=SHA256WithRSA

ca.validity=3652
ca.policy=null
ca.certificateprofile=ROOTCA

### End install.properties ###

mail.properties

### Start mail.properties ###

mail.jndi-name=java:/EjbcaMail
mail.user=ejbca
mail.password=honeybunny
mail.smtp.host=localhost
mail.smtp.port=25
#mail.smtp.auth=false
#mail.smtp.starttls.enable=false
mail.from=ejbca@yourcompany.net
#mail.debug=false
mail.contentencoding=UTF-8

### End mail.properties ###

web.properties

### Start web.properties ###

superadmin.cn=superadmin
superadmin.dn=CN=${superadmin.cn},O=Your Company,C=US

superadmin.batch=true

httpsserver.hostname=rootca.yourdomain.net
httpsserver.dn=CN=${httpsserver.hostname},O=Your Company,C=US

httpserver.pubhttp=8080

httpserver.pubhttps=8442

httpserver.privhttps=8443
#httpserver.external.privhttps=443

#httpserver.external.fqdn=
#httpserver.external.fqdn=${httpsserver.hostname}

#httpsserver.bindaddress.pubhttp=0.0.0.0
#httpsserver.bindaddress.pubhttps=0.0.0.0
#httpsserver.bindaddress.privhttps=0.0.0.0

web.contentencoding=UTF-8

web.selfreg.enabled=false
web.selfreg.defaultcerttype=1
web.selfreg.certtypes.1.description=User certificate
web.selfreg.certtypes.1.eeprofile=user
web.selfreg.certtypes.1.certprofile=user
web.renewalenabled=false
web.errorpage.notification=An exception has occurred.
web.errorpage.stacktrace=true

web.log.adminremoteip=true

### End web.properties ###
好了!下面可以开始尝试编译了。
cd ~/ejbca
ant deploy

部署的过程中可能会出这么几个问题:
06:05:16,848 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) JBAS014612: Operation ("composite") failed - address: ([]): java.lang.IllegalArgumentException

06:05:39,477 ERROR [org.hibernate.internal.util.xml.ErrorLogger] (MSC service thread 1-4) HHH000196: Error parsing XML (21) : cvc-complex-type.3.1: Value '1.0' of attribute 'version' of element 'entity-mappings' is not valid with respect to the corresponding attribute use. Attribute 'version' has a fixed value of '2.0'.

15:29:58,915 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (MSC service thread 1-2) JSF1051: Service entry 'org.jboss.as.web.deployment.jsf.JsfInjectionProvider' does not extend DiscoverableInjectionProvider. Entry will be ignored.
这些问题可以直接无视,这是因为 Jboss 的 Bug。当然,这些问题可能会导致部署失败。那就多试几次吧。。。
如果你在 Jboss 的日志中看到了这个,说明你可能部署成功了:
01:38:38,724 INFO [org.jboss.as] (MSC service thread 1-1) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 7761ms - Started 2855 of 2968 services (111 services are passive or on-demand)
01:38:38,769 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "ejbca.ear"

顺便一说,部署的过程中你会看到大量的:
appserver.error.message:
[echo] jndi.properties.file: /home/ejbca/ejbca_ce_6_2_0/conf/jndi.properties.jboss7

没关系,这个我可以确定是完全正常,丝毫不影响后续的。。。

接下来重启 Jboss ,到之前打开的另一个终端或者 screen , Ctrl+C 结束掉 Jboss ,然后重新启动。
之后,回到 ~/ejbca ,执行 ant install
当你看到:

[echo] Initializing CA with 'mgmtCA' 'CN=mgmtca,O=Your Company,C=US' 'soft'

说明你的配置文件没有问题了,至于各种证书和存储库能不能正常生成,还是看脸。

如果你在终端看到 ant 返回 BUILD SUCCESS ,并且重启 Jboss 后能看到这样的日志,恭喜你,配置成功了!
06:20:59,482 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /${app.name}/publicweb/status
06:20:59,484 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/publicweb/apply
06:20:59,491 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/publicweb/webdist
06:20:59,506 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/publicweb
06:20:59,516 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/publicweb/healthcheck
06:20:59,521 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/clearcache
06:20:59,521 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/ejbcaws
06:20:59,571 INFO [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /ejbca
06:20:59,727 INFO [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /crls
06:20:59,728 INFO [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /certificates
06:21:00,141 INFO [org.jboss.web] (MSC service thread 1-3) JBAS018210: Registering web context: /ejbca/adminweb
06:21:16,576 INFO [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /ejbca/doc

WSDL published to: file:/opt/jboss-as-7.1.1.Final/standalone/data/wsdl/ejbca.ear/ejbca-ws-ejb.jar/EjbcaWSService.wsdl

接下来从服务器上将 superadmin.p12 拷贝出来,导入浏览器,就可以访问管理页面了!

当然,按照我的经验,看到这里的人 99% 都是要被坑的,你应该是无法正常安装的。如果没成功的话,不要灰心,多试几次。我将上述过程整整重新执行了一天,才最终装好一个。然后因为要修改一些配置,又挂了。所以说,这玩意能不碰就不碰,我已经在开头警告过了。。。

CC BY-NC-SA 4.0 Ubuntu 14.04 安装 Ejbca (Install Ejbca on Ubuntu 14.04) by 桔子小窝 is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

发表回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据