简单搭建一下证书透明度服务(certificate transparency)

发布于:2024-04-29 ⋅ 阅读:(26) ⋅ 点赞:(0)

ct服务搭建流程参照官网: https://github.com/google/certificate-transparency-go/blob/master/trillian/docs/ManualDeployment.md

1. 创建数据库(mysql)

  • 需要数据库支持用户无密码登录(因为启动参数上面没有找到设置数据库 密码的参数)
  • 设置无密码登录
    • 进入mysql mysql -uroot -p 输入密码
    • use mysql
    • 查看root的密码是否为空,以及是否支持远程登录select host,user,plugin,authentication_string from mysql.user;
    • 修改密码为空ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '';
    • 刷新权限FLUSH PRIVILEGES;
    • 测试, 先执行exit退出mysql,在输入mysql 是否直接进入mysql
  • 创建数据库testDb, 执行sql脚本https://github.com/google/trillian/blob/master/storage/mysql/schema/storage.sql

2. 搭建go编译环境

  • 下载安装包https://golang.google.cn/ 版本为 1.21

  • linux搭建

    • 解压下载的安装包到自己的安装位置例如tar -zxvf go1.21.9.linux-amd64.tar.gz -C /opt

    • 配置环境变量

      • 执行脚本
      echo -e "export GOHOME=/home/go\nexport PATH=$PATH:$GOHOME/bin\nexport GOPATH=$HOME/golang/gopath\n" >> /etc/profile
      
      source /etc/profile
      
      
    • 测试环境

      • go version

3. 下载项目代码git clone https://github.com/google/certificate-transparency-go.git

4. 进入项目目录cd certificate-transparency-go

5. 启动 trillian_log_server

  • 执行go run github.com/google/trillian/cmd/trillian_log_server --mysql_uri="root@tcp(数据库ip:3306)/testDb" --rpc_endpoint=:8080 --http_endpoint=:8081 --logtostderr
  • 第一次执行的时候会下载依赖,下载不了的可能需要使用魔法
  • 启动参数中没有找到设置数据库密码的,如果数据库有密码此处执行会失败

6. 启动trillian_log_signer

  • 执行go run github.com/google/trillian/cmd/trillian_log_signer --mysql_uri="root@tcp(数据库ip:3306)/testDb" --force_master --rpc_endpoint=:8090 --http_endpoint=:8091 --logtostderr
  • 同trillian_log_server

7. 创建树

  • 执行go run github.com/google/trillian/cmd/createtree --admin_server=:8080
  • 此处会返回一个treeID需要记录下来,后面会用到

8. 生成密钥对(openssl)

  • openssl ecparam -name prime256v1 > privkey.pem

  • openssl ecparam -in privkey.pem -genkey -noout >> privkey.pem

  • openssl ec -in privkey.pem -pubout -out pubkey.pem

  • 检查密钥对

    • openssl ec -in privkey.pem -noout -text

    • openssl pkey -pubin -in pubkey.pem -text -noout

9. 安装ctclient

  • go install github.com/google/certificate-transparency-go/client/ctclient

10. 生成根证书

- centos : 
  - `sudo yum install -qy ca-certificates`
  - `sudo update-ca-trust`
  - `cat /etc/ssl/certs/* > ca-roots.pem`
-  debian: 
  - `sudo apt-get install -qy ca-certificates`
  -  `sudo update-ca-certificates`
  - `cat /etc/ssl/certs/* > ca-roots.pem`
- 添加自己的根证书
  - 在`ca-roots.pem`中的证书列表中添加pem的根证书

11. 创建ctfe-config配置文件

- 创建文件ctfe-config `vi ctfe-config`

- 编辑配置 

  - 将私钥和公钥的数据转成hex编码

  - ```
    config {
    	log_id:  213214321432141 # 此处填写上面记录的treeID
    	prefix: "athos" # 此处填写访问路径前缀
    	roots_pem_file: "ca-roots.pem" # 此次填写步骤10生成的根证书路径
    	public_key: {
    		der: "hex编码的公钥数据(例如'\x30\x59\x30\x13\x06\x07\x2a\x86\x48\xce\x3d\x02\x01\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07\x03\x42\x00\x04\x05\x4d\xc0\x61\x7d\x19\x0d\xce\x89\xff\xe4\x78\x1f\x1c\xdc\xe2\x1f\x49\xc3\x84\x5a\x01\xe9\xc3\x08\x92\xe1\xb9\x29\x92\x16\xcb\xb5\x32\xa9\x35\xf4\xf0\x31\x87\x7e\xc7\x46\x05\x5a\xd6\x12\x55\x14\x30\x1d\x4f\xcd\x6e\x3c\xf3\x5f\xd1\xee\xa5\x67\x52\xd2\xfa')"
    	}
    	private_key: {
    		[type.googleapis.com/keyspb.PrivateKey] {
    			der: "hex编码的私钥数据(例如:\x30\x77\x02\x01\x01\x04\x20\x1e\x32\xe1\x14\x58\xd9\x46\x11\x69\x32\xf6\x95\x42\x59\x77\xd8\x14\x5b\x17\xe7\xae\x9a\xbb\xcc\x2b\xce\x3b\x93\x4d\x89\xa8\x1a\xa0\x0a\x06\x08\x2a\x86\x48\xce\x3d\x03\x01\x07\xa1\x44\x03\x42\x00\x04\x05\x4d\xc0\x61\x7d\x19\x0d\xce\x89\xff\xe4\x78\x1f\x1c\xdc\xe2\x1f\x49\xc3\x84\x5a\x01\xe9\xc3\x08\x92\xe1\xb9\x29\x92\x16\xcb\xb5\x32\xa9\x35\xf4\xf0\x31\x87\x7e\xc7\x46\x05\x5a\xd6\x12\x55\x14\x30\x1d\x4f\xcd\x6e\x3c\xf3\x5f\xd1\xee\xa5\x67\x52\xd2\xfa)"
    		}
    	}
    	max_merge_delay_sec: 86400 
    	expected_merge_delay_sec: 7200 
    }
    ```

12. 启动服务

- `go run github.com/google/certificate-transparency-go/trillian/ctfe/ct_server --log_config ./ctfe-config --http_endpoint=服务ip:6966 --log_rpc_server 服务ip:8080--logtostderr`