菜鸟学Linux 第044篇笔记 算法和私有CA

简介:

菜鸟学Linux 第044篇笔记 算法和私有CA



证书吊销列表CRL(Certificate Revocation List ) 

如何解决私钥丢失



PKI: Public Key Infrastructure

CA: Cretificate Authority


证书存储格式 x509, pkcs12

x509

公钥及其有效期限

证书的合法拥有者

证书该如何被使用

CA的信息

CA签名的校验码


PKI的实现架构

PKI: TLS/SSL:x509

PKI: OpenGPG

SSL (Secure Socket Layer)公司开发的

SSLv2, SSLv3

TLS (Transport Layer Security) v1=SSLv3 国际标准化组织ISO



对称加密算法

DES: Data Encryption Standard, 56bit

3DES: 上边的3次加密

AES:Advanced Encryption Standard

AES192, AES256, AES512 越长加密性越高,速度也越慢

Blowfish

实现对称加密的工具openssl gpg

单向加密

MD4

MD5 128bit

SHA1 160bit

SHA192, SHA256, SHA384

CRC-32不是加密算法,是一种校验码的计算机制,所以不提供任何安全性

非对称加密(公钥加密):

功能:

身份认证(数字签名)

数据加密

密钥交换

加密算法

RSA 加密、签名

DSA 只可签名

ElGamal

OpenSSL: SSL的开源实现(软件) www.openssl.org

libcrypto 通用加密库

libssl TLS/SSL的实现

基于会话、实现了身份认证、数据机密性和会话完整性的TLS/SSL库

openssl 多用途命令行工具

实现私有证书颁发机构

/etc/pki/tls/openssl.cnf 该配置文件是用来让openssl工作为私有CA的时候使用

子命令:(简单讲解)注意前边都得加父命令openssl

speed des3 用户测试加密数据所需要用的时间

(注意后边最好写一个具体的算法,不然每一种算法都会测试一次)、

enc

-ciphername

-in filename

           the input filename, standard input by default.

-out filename

           the output filename, standard output by default.

-salt

           use a salt in the key derivation routines. This option should ALWAYS be

           used unless compatibility with previous versions of OpenSSL or SSLeay is

           required. This option is only present on OpenSSL versions 0.9.5 or above.

-e  encrypt the input data: this is the default.

        -d  decrypt the input data.

e.g. 加密文件 openssl enc -des3 -in inittab -out inittab.enc -a -e

 加密文件 openssl enc -des3 -in inittab.enc -out inittab.d -d -a

 (注意如果加了salt解密时也需要加上salt)

dgst

(dgst, md5, md4, md2, sha1, sha, mdc2, ripemd160 - message digests)

format : openssl dgst -algorithm

e.g. openssl dgst -shal inittab

 openssl dgst -md5 inittab

passwd

-crypt

           Use the crypt algorithm (default).

-1  Use the MD5 based BSD password algorithm 1.

-salt string

           Use the specified salt.  When reading a password from the terminal, this

           implies -noverify.

e.g.  openssl passwd -1  输入一个密码即可制作出该密码的md5特征码

rand (random number generator)  

openssl子命令帮助获取

首先先用whatis查询一下子命令,然后看提示再使用man

md5sum filename 计算文件的md5特征码

sha1sum filename 计算文件的sha1特征码

openssl实现私有CA:

1、先生成一对密钥

genrsa (generate an RSA private key)

numbits

           the size of the private key to generate in bits. This must be the last

           option specified. The default is 512.

rsa (RSA key processing tool)

-in filename

           This specifies the input filename to read a key from or standard input if

           this option is not specified. If the key is encrypted a pass phrase will

           be prompted for.

-pubout

           by default a private key is output: with this option a public key will be

           output instead. This option is automatically set if the input is a public

           key.

-out the same like before.

e.g. openssl genrsa 生成私钥

 openssl genrsa 512 生成512位私钥

 openssl genrsa > server.key  注意密钥的权限

 (umask 077; openssl genrsa -out server1024.key 1024)修改密钥权限

 openssl rsa -in server.key -pubout

 

2、生成自签署证书

req (PKCS#10 certificate request and certificate generating utility.)

-new

           this option generates a new certificate request. It will prompt the

           user for the relevant field values. The actual fields prompted for and

           their maximum and minimum sizes are specified in the configuration

           file and any requested extensions.

-x509

           this option outputs a self signed certificate instead of a certificate

           request. This is typically used to generate a test certificate or a

           self signed root CA. The extensions added to the certificate (if any)

           are specified in the configuration file. Unless specified using the

           set_serial option 0 will be used for the serial number.

-key filename

           This specifies the file to read the private key from. It also accepts

           PKCS#8 format private keys for PEM format files.

-out filename

           This specifies the output filename to write to or standard output by

           default.

-days n

           when the -x509 option is being used this specifies the number of days

           to certify the certificate for. The default is 30 days.    

生成自签署证书

openssl req -new -x509 -key server.key -out server.crt -days 365

x509 (Certificate display and signing utility)

-text

           prints out the certificate in text form. Full details are output

           including the public key, signature algorithms, issuer and subject

           names, serial number any extensions present and any trust settings.

-in filename

           This specifies the input filename to read a certificate from or stan-

           dard input if this option is not specified.

查看自签署证书

openssl x509 -text -in server.crt

1.在/etc/pki/CA/private/目录下生成CA私钥命名为cakey.pem

  在/etc/pki/CA/目录下生成CA的证书命名为cacert.pem

  在/etc/pki/CA/创建目录certs  crl  newcerts

  在/etc/pki/CA/创建文件index.txt serial并在serial输入序号01

 

2.模拟申请证书颁发请求

mkdir /etc/http

cd /etc/http

mkdir ssl

cd ssl

(umask 077; openssl genrsa -out httpd.key 1024) 生成私钥

openssl req -new -key httpd.key -out httpd.csr 生成证书请求

openssl ca -in httpd.csr -out httpd.crt  签署该证书请求,生成证书

脚本完成CA的建立,并生成自签证书(高手的话可以练习一下,目前我没做以后我会试试呵呵 )

本文转自Winthcloud博客51CTO博客,原文链接http://blog.51cto.com/winthcloud/1881913如需转载请自行联系原作者


Winthcloud

相关文章
|
3天前
|
Linux
Linux(5)WIFI/BT调试笔记
Linux(5)WIFI/BT调试笔记
17 0
|
4天前
|
Linux 编译器 Android开发
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
在Linux环境下,本文指导如何交叉编译x265的so库以适应Android。首先,需安装cmake和下载android-ndk-r21e。接着,下载x265源码,修改crosscompile.cmake的编译器设置。配置x265源码,使用指定的NDK路径,并在配置界面修改相关选项。随后,修改编译规则,编译并安装x265,调整pc描述文件并更新PKG_CONFIG_PATH。最后,修改FFmpeg配置脚本启用x265支持,编译安装FFmpeg,将生成的so文件导入Android工程,调整gradle配置以确保顺利运行。
24 1
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
|
26天前
|
JSON Kubernetes Linux
Linux环境签发CA证书和K8s需要的证书
Linux环境签发CA证书和K8s需要的证书
26 0
|
1月前
|
算法 搜索推荐 Java
数据结构与算法(Java篇)笔记--希尔排序
数据结构与算法(Java篇)笔记--希尔排序
|
1月前
|
机器学习/深度学习 存储 算法
【算法沉淀】刷题笔记:并查集 带权并查集+实战讲解
【算法沉淀】刷题笔记:并查集 带权并查集+实战讲解
|
3天前
|
Linux Android开发
Linux(6)CH9434 SPI调试笔记
Linux(6)CH9434 SPI调试笔记
12 0
|
20天前
|
Linux API C语言
FFmpeg开发笔记(一)搭建Linux系统的开发环境
本文指导初学者如何在Linux上搭建FFmpeg开发环境。首先,由于FFmpeg依赖第三方库,可以免去编译源码的复杂过程,直接安装预编译的FFmpeg动态库。推荐网站<https://github.com/BtbN/FFmpeg-Builds/releases>提供适用于不同系统的FFmpeg包。但在安装前,需确保系统有不低于2.22版本的glibc库。详细步骤包括下载glibc-2.23源码,配置、编译和安装。接着,下载Linux版FFmpeg安装包,解压至/usr/local/ffmpeg,并设置环境变量。最后编写和编译简单的C或C++测试程序验证FFmpeg环境是否正确配置。
37 8
FFmpeg开发笔记(一)搭建Linux系统的开发环境
|
1月前
|
算法 搜索推荐 Java
数据结构与算法(Java篇)笔记--快速排序
数据结构与算法(Java篇)笔记--快速排序
|
1月前
|
机器学习/深度学习 算法 搜索推荐
数据结构与算法(Java篇)笔记--归并排序
数据结构与算法(Java篇)笔记--归并排序
|
1月前
|
算法 搜索推荐 Java
数据结构与算法(Java篇)笔记--选择排序
数据结构与算法(Java篇)笔记--选择排序