makefile.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # * Redistributions in binary form must reproduce the above copyright
  2. # notice, this list of conditions and the following disclaimer in the
  3. # documentation and/or other materials provided with the distribution.
  4. #
  5. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  9. # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  11. # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  13. # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  14. # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  15. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. #
  17. #
  18. # Generate the certificates and keys for testing.
  19. #
  20. PROJECT_NAME="Nodemcu Project"
  21. # Generate the openssl configuration files.
  22. cat > ca_cert.conf << EOF
  23. [ req ]
  24. distinguished_name = req_distinguished_name
  25. prompt = no
  26. [ req_distinguished_name ]
  27. O = $PROJECT_NAME Dodgy Certificate Authority
  28. EOF
  29. cat > certs.conf << EOF
  30. [ req ]
  31. distinguished_name = req_distinguished_name
  32. prompt = no
  33. [ req_distinguished_name ]
  34. O = $PROJECT_NAME
  35. CN = Nodemcu Client cert
  36. EOF
  37. cat > device_cert.conf << EOF
  38. [ req ]
  39. distinguished_name = req_distinguished_name
  40. prompt = no
  41. [ req_distinguished_name ]
  42. O = $PROJECT_NAME Device Certificate
  43. EOF
  44. # private key generation
  45. openssl genrsa -out TLS.ca_key.pem 2048
  46. openssl genrsa -out TLS.key_2048.pem 2048
  47. # convert private keys into DER format
  48. openssl rsa -in TLS.key_2048.pem -out TLS.key_2048 -outform DER
  49. # cert requests
  50. openssl req -out TLS.ca_x509.req -sha256 -key TLS.ca_key.pem -new \
  51. -config ./ca_cert.conf
  52. openssl req -out TLS.x509_2048.req -sha256 -key TLS.key_2048.pem -new \
  53. -config ./certs.conf
  54. # generate the actual certs.
  55. openssl x509 -req -in TLS.ca_x509.req -sha256 -out TLS.ca_x509.pem \
  56. -sha1 -days 5000 -signkey TLS.ca_key.pem
  57. openssl x509 -req -in TLS.x509_2048.req -sha256 -out TLS.x509_2048.pem \
  58. -sha1 -CAcreateserial -days 5000 \
  59. -CA TLS.ca_x509.pem -CAkey TLS.ca_key.pem
  60. # some cleanup
  61. rm TLS*.req
  62. rm *.conf
  63. openssl x509 -in TLS.ca_x509.pem -outform DER -out TLS.ca_x509.cer
  64. openssl x509 -in TLS.x509_2048.pem -outform DER -out TLS.x509_2048.cer
  65. #
  66. # Generate the certificates and keys for encrypt.
  67. #
  68. # set default cert for use in the client
  69. xxd -i TLS.x509_2048.cer | sed -e \
  70. "s/TLS_x509_2048_cer/default_certificate/" > cert.h
  71. # set default key for use in the server
  72. xxd -i TLS.key_2048 | sed -e \
  73. "s/TLS_key_2048/default_private_key/" > private_key.h