Skip to main content

OpenSSL 申请证书

SSL 证书会涉及到的几类文件:

privkey.key     the private key for your certificate.
identity.csr     the Certificate Signing Request.
certificate.crt    the certificate file used in most server software.
certificate.pfx   the PKCS#12 format is an archival file that stores both the certificate and the private key.

By default, OpenSSL generates keys and CSRs using the PEM format (the raw).

 

1,Generating a new Private Key

openssl genrsa -out private.key 2048

 

2, Creating Your domain CSR

Creating Your domain CSR for an existing private key

openssl req -new -key private.key -out identity.csr \
    -subj "/C=US/ST=Utah/L=Lehi/O=CREAST, Inc./OU=IT/CN=yourdomain.com"

or Creating CSR with One command:

openssl req --new \
   -newkey rsa:4096 -sha256 –nodes --keyout private.key \
    -out identity.csr \
   -subj "/CN=Bitwarden IdentityServer" -days 10950

Generate a certificate signing request based on an existing certificate

openssl x509 -x509toreq -in CAcertif.crt -out identity.csr -signkey private.key

Verifying CSR info

openssl req -text -in identity.csr -noout --verify

verify OK
Certificate Request:
     Data:
         Version: 1 (0x0)
         Subject: CN = hostone.myners.net
         Subject Public Key Info:
             Public Key Algorithm: rsaEncryption
                 RSA Public-Key: (4096 bit)
                 Modulus:

3, Generate a self-signed certificate

自签名证书主要在内网环境下使用:

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout private.key -out certificate.crt

openssl req -x509 -sha256 -nodes -newkey rsa:4096 -keyout private.key \
    -out certificate.crt -subj "/CN=Bitwarden IdentityServer" -days 10950

 

4, Sending the CSR to the CA

Viewing Certificate Information

openssl x509 -text -in CAcertif.crt -noout

Certificate:
     Data:
         Version: 3 (0x2)
         Serial Number:
             04:be:c0:3c:1a:6e:c2:79:56:f6:3d:a5:26:63:51:fe:68:2c
         Signature Algorithm: sha256WithRSAEncryption
         Issuer: C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3
         Validity
             Not Before: May 22 14:11:15 2020 GMT
             Not After : Aug 20 14:11:15 2020 GMT
         Subject: CN = hostone.myners.net
         Subject Public Key Info:
             Public Key Algorithm: rsaEncryption
                 RSA Public-Key: (2048 bit)
                 Modulus:

 

5,Verifying Your Keys Match

To verify that your public and private keys match, use the -modulus switch to generate a hash of the output for all three files (private key, CSR, and certificate).

Use the following commands to generate a hash of each file's modulus:
 

// Verifying private key

openssl rsa -modulus -in private.key -noout | openssl sha256

(stdin)= 5a07ccd5d1208a7f4e445414b841d100b85ac3138d47554be333fbd18d42a89c

// Verifying CSR

openssl req -modulus -in identify.csr -noout | openssl sha256

(stdin)= 5a07ccd5d1208a7f4e445414b841d100b85ac3138d47554be333fbd18d42a89c

// Verifying certificate
openssl x509 -modulus -in certificate.crt -noout | openssl sha256

(stdin)= 81c6258063b5d2a7403f5ad6d3c490c79261402f9269f6a304e95f1ffde1eb04

 

If the output of each command matches, then the keys for each file are the same.

if there is any mismatch, then the keys are not the same and the certificate cannot be installed.

Key mismatch errors are typically caused by installing a certificate on a machine different from the one used to generate the CSR.

 

6,Converting Certificate Formats

Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)

openssl pkcs12 -export -out certificate.pfx -name "yourdomain-digicert-(expiration date)"  \
-inkey privateKey.key -in certificate.crt -certfile CAcertifi.crt \
-passout pass:IDENTITY_CERT_PASSWORD

 

openssl pkcs12 -export -name "yourdomain-digicert-(expiration date)" \
-out yourdomain.pfx -inkey yourdomain.key -in yourdomain.crt

 

// Verifying PKCS#12 file
openssl pkcs12 -info -in keyStore.pfx

Comments

Popular posts from this blog

Cloudera Hadoop 集群安装(ubuntu + CDH5.10)

前言 CDH是Cloudera公司的Hadoop发行版,基于稳定版本的Apache Hadoop构建,包含Hadoop,Spark,Hive,Hbase和一些工具等,并集成了很多补丁,可直接用于生产环境。通过Cloudera Manager可以简化hadoop各组件的部署和配置过程。 目前CDH对ubuntu支持的最高版本为14.04,因此不建议使用更高版本的ubuntu来部署CDH。 环境准备: 1.配置网络(所有节点) 修改hostname: $ sudo vi /etc/hostname cdh01 修改IP地址: $ sudo vi /etc/network/interfaces auto eth0 iface eth0 inet static         address 172.16.13.11         netmask 255.255.255.0         gateway 172.16.13.254 重启网络服务生效: $ sudo ifdown eth0 && sudo ifup eth0 修改ip与主机名的对应关系: $ sudo vi /etc/hosts 172.16.13.11 cdh01 172.16.13.12 cdh02 172.16.13.13 cdh03 2.配置SSH(所有节点) 启用root登陆(CDH5.10需要进行此步操作) $ sudo vi /etc/ssh/sshd_config #PermitRootLogin without-password PermitRootLogin yes $ sudo service ssh restart $ sudo passwd root 设置ssh无密码登陆 //在主节点上执行一路回车,生成无密码的密钥对 $ ssh-keygen -t rsa //将生成的密钥文件复制到其它节点 $ ssh-copy-id cdh02 $ ssh-copy-id cdh03 测试: 在主节点上ssh hadoop2,正常情况下,不需要密码就能直接登陆进去了。 3.安装Oracle JDK(所有节点) 运行CDH5必须使用Oracle的Jdk,需要Java 7及以上版本支持。 在Oracle的官网下载jdk包,解压到相应目录,例如/usr/java/jdk1.8.0_

Bitwarden 配置 Let’s Encrypt 证书

由于在内网环境部署的Bitwarden,不能通过安装脚本自动申请 Let’s Encrypt 的证书。 起初我用了一个自签名证书,发现特别不好使,虽然在firefox 跟 chrome 内核的浏览器上都能通过插件访问,但必须添加信任才行,特别是用Bitwarden Desktop 客户端连的时候,一直报错,可能是不认自签名证书。 于是琢磨了下怎么手动申请Let’s Encrypt的证书用于内网,对过程简单梳理如下。 自签名证书 | Self-Signed Certificate 如果你在内网环境只需要自签名证书,可以参考Bitwarden的帮助文档( Installing and depoying )进行设置: 1、生成自签名证书: //一条命创建私钥和证书: openssl req -x509 -newkey rsa:4096 -sha256 –nodes -days 10950 \    -keyout privite.key -out identity.crt \    -subj "/C= US /ST= New York /L= New York /O= Company Name /OU= CREAST /CN= bw.creast.win " 将生成的文件放到 /ssl 目录下: privite.key     ~/bwdata/ssl/ bw.creast.win/private.key identity.crt      ~/bwdata/ssl/ bw.creast.win/identity.crt 2、生成.pfx格式证书文件: //一条命令将前面生成的私钥和证书打包成需要的pfx格式文件 openssl pkcs12 -export -out ./ identity.pfx -inkey privite.key \    -in identity.crt -certfile identity.crt -passout pass: IDENTITY_CERT_PASSWORD 注意 IDENTITY_CERT_PASSWORD 跟./env/global.override.e

Tor洋葱路由的设置与使用

先说明一下,这里只是利用Tor来访问被GWF屏蔽的优秀服务(如Wikipedia、Blogger、GG App等),并不侧重于如何匿名访问网络。以下Tor设置方法适用于: MS Windows(2000/XP/Vista/Server)系统 第一步:下载并安装Tor 关于Tor(The Onion Router,洋葱路由)的工作原理,可以参考枪旗工作室的说明 ( http://tcno.net/doc/tor/#para1 )。在Windows下安装配置Tor已经非常容易了,直接下载这样一个Tor的Windows 捆绑软件包( Vidalia-Tor-Privoxy Bundle ),其中已经预先配置好这些软件能够一同工作。 安装前可以看到套件捆绑了哪些软件:Tor、Vidalia(Tor 的一个图形用户界面)和 Privoxy(Web 代理软件)、Torbutton(Firefox浏览器插件)全选这些软件进行安装。 安装完成后会自动运行Vidalia,在弹出的控制面板上可以看到当前的状态,Tor已经运行了,此时不需要再进行其它设置了。 第二步:配置浏览器使用Tor 如果使用 Firefox 浏览器,Bundle里已经附带了 Torbutton 插件 ,打开/重启Firefox就会在右下角显示Tor Enabled/Disabled,单击它可以选择是否开启Tor代理功能。 对于 Internet Explorer 没有现成的插件可用,需要手动配置代理设置,也很容易。 菜单位置 工具 - Internet 选项 - 连接 - 局域网设置 - 代理服务器 - 高级 - 服务器 在代理理服务器地址栏里填入 "localhost",端口为 "8118"(Privoxy不支持FTP代理,填不填都无所谓了);注意套接字SOCKS代理的端口为 "9050",如果有其它选项,请选择Socks5,然后"确定"即可。 对于 Maxthon ,如果对IE设置了Tor可以选择“使用IE代理设置”,或者手动添加一个代理列表,内容与上面填写的一样,然后选择应用就可以了。 这里说明一下 Privoxy 的作用,因为当直接使用 SOCKS 代理时,浏览器会泄露