Chinaunix首页 | 论坛 | 博客
  • 博客访问: 43008
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 165
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-19 15:23
个人简介

转身撞上猪

文章分类

全部博文(18)

文章存档

2017年(18)

我的朋友

分类: LINUX

2017-11-30 23:32:14


点击(此处)折叠或打开

  1. #!/bin/bash
  2. opensslversion=`/bin/rpm -q openssl`
  3. [ "$?" != "0" ] && echo "openssl is not install." && exit 1
  4. echo "openssl version: $opensslversion"
  5. [ ! -f /etc/pki/tls/openssl.cnf ] && echo "/etc/pki/tls/openssl.cnf not exist." && exit 1
  6. [ -f /etc/pki/tls/openssl.cnf.orig.unique ] && read -p "run again?[y/n]" run_again && [ "$run_again" != "y" ] && exit 1
  7. [ -f /etc/pki/tls/openssl.cnf.orig.unique ] && /bin/cp /etc/pki/tls/openssl.cnf.orig.unique /etc/pki/tls/openssl.cnf || /bin/cp /etc/pki/tls/openssl.cnf /etc/pki/tls/openssl.cnf.orig.unique
  8. [ "$?" != "0" ] && echo "can not cp /etc/pki/tls/openssl.cnf " && exit 1
  9. countryName_default="CN"
  10. stateOrProvinceName_default="GD"
  11. localityName_default="SZ"
  12. organizationName_default="mycompany"
  13. organizationalUnitName_default="Tech"
  14. commonName="ca.my.com"
  15. emailAddress="caadmin@my.com"
  16. #read -p "input default countryName: " countryName_default
  17. #read -p "input default stateOrProvinceName: " stateOrProvinceName_default
  18. #read -p "input default localityName: " localityName_default
  19. #read -p "input default organizationName: " organizationName_default
  20. #read -p "input default organizationalUnitName: " organizationalUnitName_default
  21. #read -p "input commonName: " commonName
  22. #read -p "input emailAddress: " emailAddress
  23. [ -z $countryName_default ] && echo "default countryName no input." && exit 1
  24. [ -z $stateOrProvinceName_default ] && echo "default stateOrProvinceName no input." && exit 1
  25. [ -z $localityName_default ] && echo "default localityName no input." && exit 1
  26. [ -z $organizationName_default ] && echo "default organizationName no input." && exit 1
  27. [ -z $organizationalUnitName_default ] && echo "default organizationalUnitName no input." && exit 1
  28. [ -z $commonName ] && echo "default commonName no input." && exit 1
  29. [ -z $emailAddress ] && echo "default emailAddress no input." && exit 1
  30. /bin/sed -i "s/^countryName_default.*$/countryName_default = $countryName_default/" /etc/pki/tls/openssl.cnf
  31. [ "$?" != "0" ] && echo "fail to modify /etc/pki/tls/openssl.cnf " && exit 1
  32. /bin/sed -i "s/^#stateOrProvinceName_default.*$/stateOrProvinceName_default = $stateOrProvinceName_default/" /etc/pki/tls/openssl.cnf
  33. [ "$?" != "0" ] && echo "fail to modify /etc/pki/tls/openssl.cnf " && exit 1
  34. /bin/sed -i "s/^localityName_default.*$/localityName_default = $localityName_default/" /etc/pki/tls/openssl.cnf
  35. [ "$?" != "0" ] && echo "fail to modify /etc/pki/tls/openssl.cnf " && exit 1
  36. /bin/sed -i "s/^0.organizationName_default.*$/0.organizationName_default = $organizationName_default/" /etc/pki/tls/openssl.cnf
  37. [ "$?" != "0" ] && echo "fail to modify /etc/pki/tls/openssl.cnf " && exit 1
  38. /bin/sed -i "s/^#organizationalUnitName_default.*$/organizationalUnitName_default = $organizationalUnitName_default/" /etc/pki/tls/openssl.cnf
  39. [ "$?" != "0" ] && echo "fail to modify /etc/pki/tls/openssl.cnf " && exit 1
  40. [ ! -d /etc/pki/CA/certs ] && mkdir /etc/pki/CA/certs
  41. [ ! -d /etc/pki/CA/crl ] && mkdir /etc/pki/CA/crl
  42. [ ! -d /etc/pki/CA/newcerts ] && mkdir /etc/pki/CA/newcerts
  43. [ ! -d /etc/pki/CA/private ] && mkdir /etc/pki/CA/private
  44. touch /etc/pki/CA/index.txt
  45. touch /etc/pki/CA/serial
  46. serialfilesize=`ls -l /etc/pki/CA/serial | awk '{print $5}'`
  47. [ "$serialfilesize" == "0" ] && echo "01" >/etc/pki/CA/serial
  48. [ ! -f /etc/pki/CA/private/cakey.pem.orig.unique ] && /bin/cp /etc/pki/CA/private/cakey.pem /etc/pki/CA/private/cakey.pem.orig.unique
  49. [ ! -f /etc/pki/CA/cacert.pem.orig.unique ] && /bin/cp /etc/pki/CA/cacert.pem /etc/pki/CA/cacert.pem.orig.unique
  50. /usr/bin/openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048 1>/dev/null 2>&1
  51. /bin/echo -e "\n\n\n\n\n$commonName\n$emailAddress\n" | /usr/bin/openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem 1>/dev/null 2>&1
  52. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  53. echo "The CA certificate: "
  54. ls -l /etc/pki/CA/cacert.pem
  55. echo ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  56. /usr/bin/openssl x509 -in /etc/pki/CA/cacert.pem -text


阅读(1472) | 评论(0) | 转发(0) |
0

上一篇:?Linux开机启动流程

下一篇:没有了

给主人留下些什么吧!~~