-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathcreate_cert.sh
More file actions
executable file
·82 lines (69 loc) · 2.56 KB
/
Copy pathcreate_cert.sh
File metadata and controls
executable file
·82 lines (69 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
set -e
# Limpeza
rm -f exampleca.* example.* cert.h private_key.h
#------------------------------------------------------------------------------
# 1. Criar uma CA (Autoridade Certificadora) válida
#------------------------------------------------------------------------------
openssl genrsa -out exampleca.key 2048 # Usar 2048 bits para maior segurança
cat > exampleca.cnf << EOF
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
prompt = no
[ req_distinguished_name ]
C = DE
ST = BE
L = Berlin
O = MyCompany
CN = myca.local
[ v3_ca ]
basicConstraints = critical, CA:TRUE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer:always
EOF
# Gerar certificado autoassinado da CA (válido por 10 anos)
openssl req -x509 -new -nodes -key exampleca.key -sha256 -days 3650 -out exampleca.crt -config exampleca.cnf
#------------------------------------------------------------------------------
# 2. Criar certificado para o ESP32
#------------------------------------------------------------------------------
openssl genrsa -out example.key 2048
cat > example.csr.cnf << EOF
[ req ]
distinguished_name = req_distinguished_name
prompt = no
[ req_distinguished_name ]
C = DE
ST = BE
L = Berlin
O = MyCompany
CN = esp32.local
EOF
# Gerar CSR (Certificate Signing Request)
openssl req -new -key example.key -out example.csr -config example.csr.cnf
# Criar arquivo de extensão para o certificado do ESP32
cat > example.ext << EOF
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment
subjectAltName = DNS:esp32.local
EOF
# Assinar o certificado com a CA (adicionando extensões)
openssl x509 -req -in example.csr -CA exampleca.crt -CAkey exampleca.key -CAcreateserial \
-out example.crt -days 3650 -sha256 -extfile example.ext
# Verificar (agora deve funcionar)
openssl verify -CAfile exampleca.crt example.crt
#------------------------------------------------------------------------------
# 3. Converter para DER e gerar arquivos .h
#------------------------------------------------------------------------------
openssl rsa -in example.key -outform DER -out example.key.DER
openssl x509 -in example.crt -outform DER -out example.crt.DER
# Gerar cert.h e private_key.h
xxd -i example.crt.DER > cert.h
xxd -i example.key.DER > private_key.h
echo ""
echo "✅ Certificados criados com sucesso!"
echo "-----------------------------------"
echo "Arquivos gerados:"
echo " - cert.h"
echo " - private_key.h"