首页 > 其他分享 >创建私有CA并进行证书申请

创建私有CA并进行证书申请

时间:2023-10-07 14:58:02浏览次数:33  
标签:Name 证书 私有 CA app1 key root

1、创建CA所需要的证书

#生成证书索引数据库文件
[root@centos8 ~]#mkdir /etc/pki/CA
[root@centos8 ~]#touch /etc/pki/CA/index.txt

#指定第一个颁发证书的序列号
[root@centos8 ~]#echo 01 > /etc/pki/CA/serial

2、生成CA私钥
[ root@centos8 CA]#mkdir private
[ root@centos8 CA]#umask;openssl genrsa -out private/cakey.pem 2048
0022
Generating RSA private key, 2048 bit long modulus (2 primes)
........................+++++
..........+++++
e is 65537 (0x010001)

3、生成CA自己的自签名证书
[ root@centos8 CA]#oopenssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -days 3650 -out     /etc/pki/CA/cacert.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:hubei
Locality Name (eg, city) [Default City]:wuhan
Organization Name (eg, company) [Default Company Ltd]:chuangyi
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:cn.chuangyi.org
Email Address []:[email protected]

#说明:
-new:生成新证书签署请求
-x509:专用于CA生成自签证书
-key:生成请求时用到的私钥文件
-days n:证书的有效期限
-out /PATH/TO/SOMECERTFILE: 证书的保存路径

#查看生成的cacert.pem文件
[ root@centos8 CA]#openssl x509 -in cacert.pem -noout -text
Certificate:
  Data:
      Version: 3 (0x2)
      Serial Number:
           02:c3:ab:17:97:60:56:b8:ef:75:6d:67:a7:f7:b3:91:36:7e:78:c3
      Signature Algorithm: sha256WithRSAEncryption
      Issuer: C = CN, ST = hubei, L = wuhan, O = chuangyi, OU = it, CN = cn.chuangyi.org, emailAddress = [email protected]
      Validity
          Not Before: Oct 27 12:37:21 2021 GMT
          Not After : Oct 25 12:37:21 2031 GMT
      Subject: C = CN, ST = hubei, L = wuhan, O = chuangyi, OU = it, CN = cn.chuangyi.org, emailAddress = [email protected]
......
#如果公司就只有一个服务,没必要搭建CA服务器,可以使用以下命令创建一个给服务用的自签名证书
[ root@centos8 CA]#openssl req -utf8 -newkey rsa:1024 -subj "/CN=www.magedu.org" -keyout app.key -nodes -x509 -out app.crt
Generating a RSA private key
......+++++
.................+++++
writing new private key to 'app.key'
-----
#生成的私钥app.key 自签名证书app.crt


#centos7上才支持的简单的创建自签名证书的方法,可以把centos7上的/etc/pki/tls/certs/MakeFile文件拷贝过来,就可以make创建不同后缀文件名的文件,来做对应的事情

[root@localhost certs]# make /data/httpd.crt
umask 77 ; \
/usr/bin/openssl genrsa -aes128 2048 > /data/httpd.key
Generating RSA private key, 2048 bit long modulus
................................+++
....+++
e is 65537 (0x10001)
Enter pass phrase:
Verifying - Enter pass phrase:
umask 77 ; \
/usr/bin/openssl req -utf8 -new -key /data/httpd.key -x509 -days 365 -out /data/httpd.crt
Enter pass phrase for /data/httpd.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:hubei
Locality Name (eg, city) [Default City]:wuhan
Organization Name (eg, company) [Default Company Ltd]:it
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:www.chuanyi.org
Email Address []:[email protected]

4、为需要使用证书的主机生成私钥
[ root@centos8 CA]#mkdir /data/app1
[ root@centos8 app1]#(umask 066; openssl genrsa -out /data/app1/app1.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.....+++++
.........+++++
e is 65537 (0x010001)

Generating RSA private key, 2048 bit long modulus (2 primes)
...............+++++
..+++++
e is 65537 (0x010001)

5、为需要使用证书的主机生成证书申请文件
[ root@centos8 app1]#openssl req -new -key /data/app1/app1.key -out /data/app1/app1.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:hubei
Locality Name (eg, city) [Default City]:wuhan
Organization Name (eg, company) [Default Company Ltd]:chuangyi
Organizational Unit Name (eg, section) []:sale
Common Name (eg, your name or your server's hostname) []:sale.chuangyi.org
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:


6、颁发证书,放在配置文件规定的certs目录下
[ root@centos8 certs]#openssl ca -in /data/app1/app1.csr -out /etc/pki/CA/certs/app1.crt -days 1000
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
      Serial Number: 1 (0x1)
      Validity
          Not Before: Oct 27 13:46:18 2021 GMT
          Not After : Jul 23 13:46:18 2024 GMT
      Subject:
          countryName               = CN
          stateOrProvinceName       = hubei
          organizationName          = chuangyi
          organizationalUnitName    = sale
          commonName                = sale.chuangyi.org
          emailAddress              = [email protected]
      X509v3 extensions:
          X509v3 Basic Constraints:
              CA:FALSE
          Netscape Comment:
              OpenSSL Generated Certificate
          X509v3 Subject Key Identifier:
               96:D5:F1:07:13:C7:C3:9E:2D:09:46:24:A2:4E:2E:9E:2F:23:44:DF
          X509v3 Authority Key Identifier:
              keyid:7B:9E:BE:0D:B3:71:91:FB:D3:3A:6B:47:98:07:62:34:86:2A:57:9E

Certificate is to be certified until Jul 23 13:46:18 2024 GMT (1000 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

7、颁发证书完成,将生成的证书相关文件发送到客户端使用
[ root@centos8 certs]#cp /etc/pki/CA/certs/app1.crt /data/app1/
[ root@centos8 certs]#tree /data/app1/
/data/app1/
├── app1.crt
├── app1.csr
└── app1.key

8、默认生成的证书,windows十不被信任的,将CA的根证书,cacert.pem改名为cacert.pem.crt使windows可以识别该文件,双击安装cacert.pem.crt文件或者导入到“受信任的根证书颁发机构”。windows再次打开app1.crt就是没问题了。

 

标签:Name,证书,私有,CA,app1,key,root
From: https://www.cnblogs.com/tanll/p/17746287.html

相关文章

  • 钡铼BL124EC:优化工业通信,畅通EtherCAT到Ethernet/IP
    钡铼BL124EC是一种用于工业网络通信的网关设备,专门用于将EtherCAT协议转换成Ethernet/IP协议。它充当一个桥梁,连接了使用不同协议的设备,使它们能够无缝地进行通信和互操作。具体来说,BL124EC通过支持EtherCAT(以太CAT)总线协议的设备与支持Ethernet/IP(以太网/IP)协议的设备之间建立连......
  • Converting Virtual Addresses to Physical Addresses
    ConvertingVirtualAddressestoPhysicalAddresses Mostdebuggercommandsusevirtualaddresses,notphysicaladdresses,astheirinputandoutput.However,therearetimesthathavingthephysicaladdresscanbeuseful.Therearetwowaystoconverta......
  • 导数计算器(Derivative Calculator)
    导数计算器(DerivativeCalculator) https://www.derivative-calculator.net/​a*e^x/(1+abs(x))......
  • A curious case: CLR/COM Interop leak
    Acuriouscase:CLR/COMInterop leakUNCATEGORIZED.NET, COM, INTEROP, PRODUCTIONDEBUGGING, WINDBGLEAVEACOMMENTBackgroundAcustomeraskedmeaquestionlastweek:inCLR-COMinteropcase,whoisresponsibletofreeupastringreturnedfromCO......
  • plt.scatter 中cmap参数详解
    plt.scatter中cmap参数详解 1.首先,cmap参数和c参数配合使用的。参数c可以是一个序列,如:plt.scatter(a,b,c=['b','r','b','r','b'],s=80)此时c的序列是一个颜色序列,除了上述的简洁写法,还可以使用RGB或RBGA:plt.scatter(a,b,c=['#f00','#0f0','#f00�......
  • 前端canvas实现签名功能,可以横屏/竖屏签名
    页面展示效果,点保存后生成图片链接图片链接展示效果这里只展示了竖屏签名效果,横屏自己粘贴代码测试css.box{width:98%;display:flex;flex-direction:column;margin:auto;}.canvasbox{width:100%;border:1pxsolid#bbb;margin:0auto;overflow:hidden;}canvas......
  • 通用解决LocalDateTime转为字符串后中间含“T”
    importcom.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;importorg.springframework.beans.factory.annotation.Value;importorg.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;importorg.springframework.co......
  • Androidstudio中 unable to execute Clang-tidy clazy-standalone is not found or ca
    这个问题可能是因为AndroidStudio不支持clazy,但是在设置菜单中仍然提供了这个选项,并且在这种情况下,它似乎被启用了¹。当通过clangd启用clang-tidy时,没有什么需要做的。当通过clangd禁用clang-tidy时,如果启用了clazy,就会出现这个错误¹。要解决这个问题,你可以尝试以下步骤:1.转......
  • 《CF1824E LuoTianyi and Cartridge》 解题报告
    好题。模拟赛出了这题,抽象。初步化简:由于\(\min(A,C)\)不好处理,我们考虑从大到小加边加点,或者从小到大删边删点。一般题目是考虑加边加点好操作一点,这题是考虑删边删点好操作。然后我们记当前枚举的\(\min(A,C)\)的最小值是多少,记为\(x\)。然后称大于等于\(x\)点权......
  • Cannot find module ‘node:module‘ & "plugins" is not allowed 的解决办法
    在写demo时,装了下t-design-vue2的框架,想做个按需加载,官网这样说但是我运行以后发现报错了Error:Cannotfindmodule'node:module'Requirestack:-D:\ruanjian\nvm\v19.0.0\xiangmu\niu789\niu789\node_modules\[email protected]@mlly\dist\index.cjs摸不着......