Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- root@OpenWrt:~#
- root@OpenWrt:~# mkdir -p /tmp/ssl/test
- root@OpenWrt:~# cd /tmp/ssl/test
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# export OPENSSL_CONF="../openssl.cnf"
- root@OpenWrt:/tmp/ssl/test# extfile="../extensions.cnf"
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# openssldir="/etc/ssl"
- root@OpenWrt:/tmp/ssl/test# sed '/^\[ CA_default ]/,/^\[/s/^\(dir[ \t]*=[ \t]*\)[^ \t]\+/\1$ENV::DIR/' "${openssldir:?}/openssl.cnf" > "${OPENSSL_CONF:?}"
- root@OpenWrt:/tmp/ssl/test# cat > "${extfile:?}"
- # subjectAltName
- SAN = email:copy
- # OIDs for IKE
- ipsecIKE = 1.3.6.1.5.5.7.3.17 # RFC 4945
- #iKEIntermediate = 1.3.6.1.5.5.8.2.2 # draft-ietf-ipsec-pki-req (expired)
- [ my_ca ]
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid:always,issuer
- basicConstraints = critical, CA:true
- keyUsage = cRLSign, keyCertSign
- subjectAltName = $ENV::SAN
- [ my_server ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature, keyEncipherment or keyAgreement
- keyUsage = digitalSignature, keyEncipherment
- # extendedKeyUsage for both TLS and IKE
- extendedKeyUsage = serverAuth, $ipsecIKE
- subjectAltName = $ENV::SAN
- [ my_client ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature and/or keyAgreement
- keyUsage = digitalSignature
- # extendedKeyUsage for both TLS and IKE
- extendedKeyUsage = clientAuth, $ipsecIKE
- subjectAltName = $ENV::SAN
- [ my_code ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature
- keyUsage = digitalSignature
- extendedKeyUsage = codeSigning
- subjectAltName = $ENV::SAN
- [ my_email ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature, nonRepudiation, and/or (keyEncipherment or keyAgreement)
- keyUsage = nonRepudiation, digitalSignature, keyEncipherment
- extendedKeyUsage = emailProtection
- subjectAltName = $ENV::SAN
- [ my_ipsec ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature and/or nonRepudiation
- keyUsage = digitalSignature
- # extendedKeyUsage for IKE, defined but NOT RECOMMENDED in RFC 4945
- #extendedKeyUsage = $ipsecIKE
- subjectAltName = $ENV::SAN
- 【Ctrl-D で抜ける】
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# diff -u "${openssldir:?}/openssl.cnf" "${OPENSSL_CONF:?}"
- --- /etc/ssl/openssl.cnf 2013-03-24 01:43:14.000000000 +0900
- +++ ../openssl.cnf 2013-11-07 22:42:50.711171717 +0900
- @@ -39,7 +39,7 @@
- ####################################################################
- [ CA_default ]
- -dir = ./demoCA # Where everything is kept
- +dir = $ENV::DIR # Where everything is kept
- certs = $dir/certs # Where the issued certs are kept
- crl_dir = $dir/crl # Where the issued crl are kept
- database = $dir/index.txt # database index file.
- root@OpenWrt:/tmp/ssl/test# cat "${extfile:?}"
- # subjectAltName
- SAN = email:copy
- # OIDs for IKE
- ipsecIKE = 1.3.6.1.5.5.7.3.17 # RFC 4945
- #iKEIntermediate = 1.3.6.1.5.5.8.2.2 # draft-ietf-ipsec-pki-req (expired)
- [ my_ca ]
- subjectKeyIdentifier = hash
- authorityKeyIdentifier = keyid:always,issuer
- basicConstraints = critical, CA:true
- keyUsage = cRLSign, keyCertSign
- subjectAltName = $ENV::SAN
- [ my_server ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature, keyEncipherment or keyAgreement
- keyUsage = digitalSignature, keyEncipherment
- # extendedKeyUsage for both TLS and IKE
- extendedKeyUsage = serverAuth, $ipsecIKE
- subjectAltName = $ENV::SAN
- [ my_client ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature and/or keyAgreement
- keyUsage = digitalSignature
- # extendedKeyUsage for both TLS and IKE
- extendedKeyUsage = clientAuth, $ipsecIKE
- subjectAltName = $ENV::SAN
- [ my_code ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature
- keyUsage = digitalSignature
- extendedKeyUsage = codeSigning
- subjectAltName = $ENV::SAN
- [ my_email ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature, nonRepudiation, and/or (keyEncipherment or keyAgreement)
- keyUsage = nonRepudiation, digitalSignature, keyEncipherment
- extendedKeyUsage = emailProtection
- subjectAltName = $ENV::SAN
- [ my_ipsec ]
- #basicConstraints=CA:FALSE
- subjectKeyIdentifier=hash
- authorityKeyIdentifier=keyid,issuer
- # keyUsage may be consistent: digitalSignature and/or nonRepudiation
- keyUsage = digitalSignature
- # extendedKeyUsage for IKE, defined but NOT RECOMMENDED in RFC 4945
- #extendedKeyUsage = $ipsecIKE
- subjectAltName = $ENV::SAN
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# prefix="/C=JP/ST=Tokyo/O=Example"
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# export DIR="./myCA"
- root@OpenWrt:/tmp/ssl/test# mkdir -p "${DIR:?}"
- root@OpenWrt:/tmp/ssl/test# mkdir -p "${DIR:?}/certs"
- root@OpenWrt:/tmp/ssl/test# mkdir -p "${DIR:?}/crl"
- root@OpenWrt:/tmp/ssl/test# mkdir -p "${DIR:?}/newcerts"
- root@OpenWrt:/tmp/ssl/test# mkdir -p "${DIR:?}/private"
- root@OpenWrt:/tmp/ssl/test# mkdir -p "${DIR:?}/private/.rand"
- root@OpenWrt:/tmp/ssl/test# touch "${DIR:?}/index.txt"
- root@OpenWrt:/tmp/ssl/test# echo 01 > "${DIR:?}/crlnumber"
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# ca="Test CA"
- root@OpenWrt:/tmp/ssl/test# openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -aes-256-cbc -out "${DIR:?}/private/cakey.pem"
- .........................................+++
- .......+++
- Enter PEM pass phrase:
- Verifying - Enter PEM pass phrase:
- root@OpenWrt:/tmp/ssl/test# openssl req -new -subj "${prefix:?}/CN=${ca:?}/emailAddress=${email:?}" -sha1 -out "${DIR:?}/careq.pem" -key "${DIR:?}/private/cakey.pem"
- Enter pass phrase for ./myCA/private/cakey.pem:
- root@OpenWrt:/tmp/ssl/test# openssl ca -extfile "${extfile:?}" -extensions my_ca -create_serial -days 3652 -md sha1 -out "${DIR:?}/cacert.pem" -batch -keyfile "${DIR:?}/private/cakey.pem" -selfsign -infiles "${DIR:?}/careq.pem"
- Using configuration from ../openssl.cnf
- Enter pass phrase for ./myCA/private/cakey.pem:
- Check that the request matches the signature
- Signature ok
- Certificate Details:
- Serial Number:
- d2:e1:ad:42:a4:49:87:8d
- Validity
- Not Before: Nov 7 13:43:50 2013 GMT
- Not After : Nov 7 13:43:50 2023 GMT
- Subject:
- countryName = JP
- stateOrProvinceName = Tokyo
- organizationName = Example
- commonName = Test CA
- emailAddress = test@example.net
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- 22:E0:FC:E9:D4:B3:CD:F8:F8:9C:87:20:CA:7D:92:11:CE:B7:94:8E
- X509v3 Authority Key Identifier:
- keyid:22:E0:FC:E9:D4:B3:CD:F8:F8:9C:87:20:CA:7D:92:11:CE:B7:94:8E
- X509v3 Basic Constraints: critical
- CA:TRUE
- X509v3 Key Usage:
- Certificate Sign, CRL Sign
- X509v3 Subject Alternative Name:
- email:test@example.net
- Certificate is to be certified until Nov 7 13:43:50 2023 GMT (3652 days)
- Write out database with 1 new entries
- Data Base Updated
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# cn="server.example.net"
- root@OpenWrt:/tmp/ssl/test# openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out "${cn:?}.key"
- ...................................................................................................+++
- ............+++
- root@OpenWrt:/tmp/ssl/test# openssl req -new -subj "${prefix:?}/CN=${cn:?}/emailAddress=${email:?}" -sha1 -out newreq.pem -key "${cn:?}.key"
- root@OpenWrt:/tmp/ssl/test# env SAN="DNS:${cn:?}" openssl ca -extfile "${extfile:?}" -extensions my_server -days 3652 -md sha1 -out "${cn:?}.crt" -infiles newreq.pem
- Using configuration from ../openssl.cnf
- Enter pass phrase for ./myCA/private/cakey.pem:
- Check that the request matches the signature
- Signature ok
- Certificate Details:
- Serial Number:
- d2:e1:ad:42:a4:49:87:8e
- Validity
- Not Before: Nov 7 13:44:27 2013 GMT
- Not After : Nov 7 13:44:27 2023 GMT
- Subject:
- countryName = JP
- stateOrProvinceName = Tokyo
- organizationName = Example
- commonName = server.example.net
- emailAddress = test@example.net
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- EF:89:66:88:5A:98:F1:66:C5:E0:82:5C:43:26:84:9B:E8:64:06:D9
- X509v3 Authority Key Identifier:
- keyid:22:E0:FC:E9:D4:B3:CD:F8:F8:9C:87:20:CA:7D:92:11:CE:B7:94:8E
- X509v3 Key Usage:
- Digital Signature, Key Encipherment
- X509v3 Extended Key Usage:
- TLS Web Server Authentication, 1.3.6.1.5.5.7.3.17
- X509v3 Subject Alternative Name:
- DNS:server.example.net
- Certificate is to be certified until Nov 7 13:44:27 2023 GMT (3652 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
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# cn="client.example.net"
- root@OpenWrt:/tmp/ssl/test# openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -aes-256-cbc -out "${cn:?}.key"
- ......................................+++
- ....+++
- Enter PEM pass phrase:
- Verifying - Enter PEM pass phrase:
- root@OpenWrt:/tmp/ssl/test# openssl req -new -subj "${prefix:?}/CN=${cn:?}/emailAddress=${email:?}" -sha1 -out newreq.pem -key "${cn:?}.key"
- Enter pass phrase for client.example.net.key:
- root@OpenWrt:/tmp/ssl/test# env SAN="DNS:${cn:?}" openssl ca -extfile "${extfile:?}" -extensions my_client -days 3652 -md sha1 -out "${cn:?}.crt" -infiles newreq.pem
- Using configuration from ../openssl.cnf
- Enter pass phrase for ./myCA/private/cakey.pem:
- Check that the request matches the signature
- Signature ok
- Certificate Details:
- Serial Number:
- d2:e1:ad:42:a4:49:87:8f
- Validity
- Not Before: Nov 7 13:45:05 2013 GMT
- Not After : Nov 7 13:45:05 2023 GMT
- Subject:
- countryName = JP
- stateOrProvinceName = Tokyo
- organizationName = Example
- commonName = client.example.net
- emailAddress = test@example.net
- X509v3 extensions:
- X509v3 Subject Key Identifier:
- AD:81:69:86:57:82:41:90:BC:34:27:9C:26:BD:1F:DE:7C:08:89:D5
- X509v3 Authority Key Identifier:
- keyid:22:E0:FC:E9:D4:B3:CD:F8:F8:9C:87:20:CA:7D:92:11:CE:B7:94:8E
- X509v3 Key Usage:
- Digital Signature
- X509v3 Extended Key Usage:
- TLS Web Client Authentication, 1.3.6.1.5.5.7.3.17
- X509v3 Subject Alternative Name:
- DNS:client.example.net
- Certificate is to be certified until Nov 7 13:45:05 2023 GMT (3652 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
- root@OpenWrt:/tmp/ssl/test# openssl pkcs12 -in "${cn:?}.crt" -inkey "${cn:?}.key" -certfile "${DIR:?}/cacert.pem" -export -name "${cn:?}" -caname "${ca:?}" -aes256 -out "${cn:?}.p12"
- Enter pass phrase for client.example.net.key:
- Enter Export Password:
- Verifying - Enter Export Password:
- root@OpenWrt:/tmp/ssl/test#
- root@OpenWrt:/tmp/ssl/test# ls -AFl . .. ./myCA
- .:
- -rw-r--r-- 1 root root 4687 Nov 7 22:45 client.example.net.crt
- -rw-r--r-- 1 root root 1858 Nov 7 22:44 client.example.net.key
- -rw-r--r-- 1 root root 3754 Nov 7 22:45 client.example.net.p12
- drwxr-xr-x 6 root root 300 Nov 7 22:45 myCA/
- -rw-r--r-- 1 root root 1013 Nov 7 22:44 newreq.pem
- -rw-r--r-- 1 root root 4705 Nov 7 22:44 server.example.net.crt
- -rw-r--r-- 1 root root 1708 Nov 7 22:44 server.example.net.key
- ..:
- -rw-r--r-- 1 root root 1887 Nov 7 22:42 extensions.cnf
- -rw-r--r-- 1 root root 10836 Nov 7 22:42 openssl.cnf
- drwxr-xr-x 3 root root 180 Nov 7 22:45 test/
- ./myCA:
- -rw-r--r-- 1 root root 4610 Nov 7 22:43 cacert.pem
- -rw-r--r-- 1 root root 997 Nov 7 22:43 careq.pem
- drwxr-xr-x 2 root root 40 Nov 7 22:43 certs/
- drwxr-xr-x 2 root root 40 Nov 7 22:43 crl/
- -rw-r--r-- 1 root root 3 Nov 7 22:43 crlnumber
- -rw-r--r-- 1 root root 346 Nov 7 22:45 index.txt
- -rw-r--r-- 1 root root 21 Nov 7 22:45 index.txt.attr
- -rw-r--r-- 1 root root 21 Nov 7 22:44 index.txt.attr.old
- -rw-r--r-- 1 root root 227 Nov 7 22:44 index.txt.old
- drwxr-xr-x 2 root root 100 Nov 7 22:45 newcerts/
- drwxr-xr-x 3 root root 80 Nov 7 22:43 private/
- -rw-r--r-- 1 root root 17 Nov 7 22:45 serial
- -rw-r--r-- 1 root root 17 Nov 7 22:44 serial.old
- root@OpenWrt:/tmp/ssl/test#
Advertisement
Add Comment
Please, Sign In to add comment