update.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. OPENSSL=openssl
  3. mkdir -p test-ca/newcerts
  4. echo
  5. echo "---[ Update server certificates ]---------------------------------------"
  6. echo
  7. cat openssl2.cnf |
  8. sed "s/#@CN@/commonName_default = server.w1.fi/" |
  9. sed "s/#@ALTNAME@/subjectAltName=DNS:server.w1.fi/" \
  10. > openssl.cnf.tmp
  11. $OPENSSL ca -config $PWD/openssl.cnf.tmp -batch -in server.csr -out server.pem -extensions ext_server
  12. $OPENSSL pkcs12 -export -out server.pkcs12 -in server.pem -inkey server.key -passout pass:
  13. $OPENSSL pkcs12 -export -out server-extra.pkcs12 -in server.pem -inkey server.key -descert -certfile user.pem -passout pass:whatever -name server
  14. cat openssl2.cnf |
  15. sed "s/#@CN@/commonName_default = server3.w1.fi/" \
  16. > openssl.cnf.tmp
  17. $OPENSSL ca -config $PWD/openssl.cnf.tmp -batch -in server-no-dnsname.csr -out server-no-dnsname.pem -extensions ext_server
  18. cat openssl2.cnf |
  19. sed "s/#@CN@/commonName_default = server5.w1.fi/" \
  20. > openssl.cnf.tmp
  21. $OPENSSL ca -config $PWD/openssl.cnf.tmp -batch -in server-eku-client.csr -out server-eku-client.pem -extensions ext_client
  22. cat openssl2.cnf |
  23. sed "s/#@CN@/commonName_default = server6.w1.fi/" \
  24. > openssl.cnf.tmp
  25. $OPENSSL ca -config $PWD/openssl.cnf.tmp -batch -in server-eku-client-server.csr -out server-eku-client-server.pem -extensions ext_client_server
  26. echo
  27. echo "---[ Update user certificates ]-----------------------------------------"
  28. echo
  29. cat openssl2.cnf | sed "s/#@CN@/commonName_default = User/" > openssl.cnf.tmp
  30. $OPENSSL ca -config $PWD/openssl.cnf.tmp -batch -in user.csr -out user.pem -extensions ext_client
  31. rm openssl.cnf.tmp
  32. $OPENSSL pkcs12 -export -out user.pkcs12 -in user.pem -inkey user.key -descert -passout pass:whatever
  33. $OPENSSL pkcs12 -export -out user2.pkcs12 -in user.pem -inkey user.key -descert -name Test -certfile server.pem -passout pass:whatever
  34. $OPENSSL pkcs12 -export -out user3.pkcs12 -in user.pem -inkey user.key -descert -name "my certificates" -certfile ca.pem -passout pass:whatever
  35. echo
  36. echo "---[ Update OCSP ]------------------------------------------------------"
  37. echo
  38. $OPENSSL ocsp -CAfile test-ca/cacert.pem -issuer test-ca/cacert.pem -cert server.pem -reqout ocsp-req.der -no_nonce
  39. $OPENSSL ocsp -index test-ca/index.txt -rsigner test-ca/cacert.pem -rkey test-ca/private/cakey.pem -CA test-ca/cacert.pem -resp_no_certs -reqin ocsp-req.der -respout ocsp-server-cache.der
  40. echo
  41. echo "---[ Additional steps ]-------------------------------------------------"
  42. echo
  43. echo "test_ap_eap.py: ap_wpa2_eap_ttls_server_cert_hash srv_cert_hash"
  44. $OPENSSL x509 -in server.pem -out server.der -outform DER
  45. HASH=`sha256sum server.der | cut -f1 -d' '`
  46. rm server.der
  47. sed -i "s/srv_cert_hash =.*/srv_cert_hash = \"$HASH\"/" ../test_ap_eap.py
  48. echo "index.txt: server time+serial"
  49. grep -v CN=server.w1.fi index.txt > index.txt.new
  50. grep CN=server.w1.fi test-ca/index.txt | tail -1 >> index.txt.new
  51. mv index.txt.new index.txt
  52. echo "start.sh: openssl ocsp -reqout serial"
  53. SERIAL=`grep CN=server.w1.fi test-ca/index.txt | tail -1 | cut -f4`
  54. sed -i "s/serial 0x[^ ]* -no_nonce/serial 0x$SERIAL -no_nonce/" ../start.sh