openssl.cnf是openssl命令的配置文件,很多证书签发和管理相关的设定都是在此配置文件中进行的,这篇文章介绍一下此配置文件中req段相关的配置和设定。
文件路径:/etc/pki/tls/openssl.cnf
格式说明格式说明: [ 段1名称 ] key1 = value1 key2 = value2
[ 段2名称 ] key3 = value3 key4 = value4
语法说明- 整体格式类似与脚本文件格式
- 注释使用# 在行首设定
- 在value的设定中可使用多行,\作为多行连接符使用
- 在value的设定中可以识别\n等符号
- 同段的值引用可以直接使用:${key1} 或者$key1
- 跨段的值引用可以使用:${段1名称::key1} 或者 $段1名称:key1
- 可以使用${ENV::环境变量} 方式引用系统环境变量,但系统环境变量不存在会出错
- 段名可以进行自定义
- 在开头的默认段也可以没有段名
- 如果同一段内存在相同的key的设定,后面的会覆盖掉前面的值,openssl命令会使用最后的key的设定值
- 默认内容
[ req ] default_bits = 2048 default_md = sha256 default_keyfile = privkey.pem distinguished_name = req_distinguished_name attributes = req_attributes x509_extensions = v3_ca # The extentions to add to the self signed cert # Passwords for private keys if not present they will be prompted for # input_password = secret # output_password = secret # This sets a mask for permitted string types. There are several options. # default: PrintableString, T61String, BMPString. # pkix : PrintableString, BMPString (PKIX recommendation before 2004) # utf8only: only UTF8Strings (PKIX recommendation after 2004). # nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings). # MASK:XXXX a literal mask value. # WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings. string_mask = utf8only # req_extensions = v3_req # The extensions to add to a certificate request [ req_attributes ] challengePassword = A challenge password challengePassword_min = 4 challengePassword_max = 20 unstructuredName = An optional company name设定项目 设定项目说明 default_bits 生成证书签名请求CSR时所使用到的RSA私钥的长度,与-newkey选项对应 default_md 签名使用的默认消息摘要算法 default_keyfile 默认的密钥文件使用的文件名,比如使用-newkey选项或者-new选项不指定-key时都会自动创建私钥,与-newkey选项对应 distinguished_name 用户DN信息,在req_distinguished_name段展开 attributes 证书请求的属性(在req_attributes段展开),但在openssl证书签发工具中并没有用到此扩展选项 input_password 设定输入密钥的文件密码,对应选项-passin output_password 设定输出密钥的文件密码,对应选项-passout x509_extensions 证书请求的扩展项,通过v3_req段进行扩展 string_mask 定义了证书一些字段的默认字符串类型,比如可设定为utf8only v3_req段
主要用于设定X.509的扩展项信息
- 缺省内容
[ v3_req ] # Extensions to add to a certificate request basicConstraints = CA:FALSE keyUsage = nonRepudiation, digitalSignature, keyEncipherment设定项目 设定项目说明 basicConstraints 基本约束,实际是为了标志当前签发的证书是否为CA证书,CA:FALSE表明为非CA证书,这种证书无法用来签发其他证书 keyUsage 证书的典型用途设定 req_distinguished_name段
设定用户DN信息
- 缺省内容
[ req_distinguished_name ] countryName = Country Name (2 letter code) countryName_default = XX countryName_min = 2 countryName_max = 2 stateOrProvinceName = State or Province Name (full name) #stateOrProvinceName_default = Default Province localityName = Locality Name (eg, city) localityName_default = Default City 0.organizationName = Organization Name (eg, company) 0.organizationName_default = Default Company Ltd # we can do this but it is not needed normally :-) #1.organizationName = Second Organization Name (eg, company) #1.organizationName_default = World Wide Web Pty Ltd organizationalUnitName = Organizational Unit Name (eg, section) #organizationalUnitName_default = commonName = Common Name (eg, your name or your server\'s hostname) commonName_max = 64 emailAddress = Email Address emailAddress_max = 64 # SET-ex3 = SET extension number 3设定项目 设定项目说明 countryName 国家代码,(两个字母的国家代码比如 CN) stateOrProvinceName 州、省份或直辖市名称 localityName 城市名称 organizationName 组织或者公司名称 organizationalUnitName 部门名称 commonName CN内容 commonName_max commonName设定值的最大长度 emailAddress Email地址 emailAddress_max Email地址设定值的最大长度