菜鸟学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

相关文章
|
2天前
|
NoSQL Java Linux
linux笔记
linux笔记
8 0
|
7天前
|
存储 运维 Java
Linux笔记02 —— Shell补充
Linux笔记02 —— Shell补充
31 2
|
7天前
|
安全 Linux Shell
Linux笔记01 —— Linux初识与Shell汇总(请配合另一篇《Linux笔记02》一起使用)
Linux笔记01 —— Linux初识与Shell汇总(请配合另一篇《Linux笔记02》一起使用)
19 1
|
7天前
|
安全 Linux Android开发
FFmpeg开发笔记(十六)Linux交叉编译Android的OpenSSL库
该文介绍了如何在Linux服务器上交叉编译Android的FFmpeg库以支持HTTPS视频播放。首先,从GitHub下载openssl源码,解压后通过编译脚本`build_openssl.sh`生成64位静态库。接着,更新环境变量加载openssl,并编辑FFmpeg配置脚本`config_ffmpeg_openssl.sh`启用openssl支持。然后,编译安装FFmpeg。最后,将编译好的库文件导入App工程的相应目录,修改视频链接为HTTPS,App即可播放HTTPS在线视频。
FFmpeg开发笔记(十六)Linux交叉编译Android的OpenSSL库
|
16天前
|
编解码 Linux
FFmpeg开发笔记(十二)Linux环境给FFmpeg集成libopus和libvpx
在《FFmpeg开发实战》一书中,介绍了如何在Linux环境下为FFmpeg集成libopus和libvpx,以支持WebM格式的Opus和VP8/VP9编码。首先,下载并安装libopus。接着,下载并安装libvpx。最后,在FFmpeg源码目录下,重新配置FFmpeg,启用libopus和libvpx,编译并安装。通过`ffmpeg -version`检查版本信息,确认libopus和libvpx已启用。
FFmpeg开发笔记(十二)Linux环境给FFmpeg集成libopus和libvpx
|
16天前
|
编解码 Linux
FFmpeg开发笔记(十)Linux环境给FFmpeg集成vorbis和amr
在Linux环境下,为FFmpeg添加对AAC、MP3、OGG和AMR音频格式的支持,需安装libogg、libvorbis和opencore-amr库。首先,从官方源下载各库的最新源码,如libogg-1.3.5、libvorbis-1.3.7和opencore-amr-0.1.6,然后解压并依次执行`./configure`、`make`和`make install`进行编译安装。接着,在FFmpeg源码目录中,使用`./configure`命令重新配置,并重新编译安装FFmpeg。最后,验证FFmpeg版本信息确认已启用ogg和amr支持。
FFmpeg开发笔记(十)Linux环境给FFmpeg集成vorbis和amr
|
16天前
|
Linux 开发工具
【Linux笔记】文件查看和编辑
【Linux笔记】文件查看和编辑
|
16天前
|
Linux
【Linux笔记】文件和目录操作
【Linux笔记】文件和目录操作
|
16天前
|
运维 监控 Linux
【Linux笔记】系统信息
【Linux笔记】系统信息
|
16天前
|
安全 Linux 网络安全
【Linux笔记】网络操作命令详细介绍
【Linux笔记】网络操作命令详细介绍