Se vuoi convertire il tuo sito web da HTTP a HTTPS, devi ottenere un certificato SSL da un'organizzazione valida come Verisign o Thawte. Puoi anche generare un certificato SSL autofirmato a scopo di test.
In questo articolo, esaminiamo come generare il file di chiave privata (server.key), il file di richiesta di firma del certificato (server.csr) e il file di certificato del server web (server.crt) che possono essere utilizzati sul server Apache con mod_ssl .
Convenzione di denominazione dei file di chiavi, CSR e CRT
In genere mi piace nominare i file con il nome di dominio dell'URL HTTPS che utilizzerà questo certificato. Ciò semplifica l'identificazione e la manutenzione.
- Invece di server.key, utilizzo www.thegeekstuff.com.key
- Invece di server.csr, utilizzo www.thegeekstuff.com.csr
- Invece di server.crt, utilizzo www.thegeekstuff.com.crt
1. Genera chiave privata sul server che esegue Apache + mod_ssl
Innanzitutto, genera una chiave privata sul server Linux che esegue il server Web Apache utilizzando il comando openssl come mostrato di seguito.
# openssl genrsa -des3 -out www.thegeekstuff.com.key 1024 Generating RSA private key, 1024 bit long modulus .......................................++++++ ...................................................++++++ e is 73547 (0x01001) Enter pass phrase for www.thegeekstuff.com.key: Verifying - Enter pass phrase for www.thegeekstuff.com.key: # ls -ltr www.thegeekstuff.* -rw-r--r-- 1 root root 963 Jun 13 20:26 www.thegeekstuff.com.key
La chiave privata generata è simile alla seguente.
# cat www.thegeekstuff.com.key -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,485B3C6371C9916E ymehJu/RowzrclMcixAyxdbfzQphfUAk9oK9kK2 jadfoiyqthakLKNqw9z1MoaqkPyqeHevUm26no AJKIETHKJADFS2BGb0n61/Ksk8isp7evLM4+QY KAQETKjdiahteksMJOjXLq+vf5Ra299fZPON7yr -----END RSA PRIVATE KEY-----
2. Genera una richiesta di firma del certificato (CSR)
Usando la chiave generata sopra, dovresti generare un file di richiesta di certificato (csr) usando openssl come mostrato di seguito.
# openssl req -new -key www.thegeekstuff.com.key -out www.thegeekstuff.com.csr Enter pass phrase for www.thegeekstuff.com.key: You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [GB]:US State or Province Name (full name) [Berkshire]:California Locality Name (eg, city) [Newbury]:Los Angeles Organization Name (eg, company) [My Company Ltd]:The Geek Stuff Organizational Unit Name (eg, section) []:IT Common Name (eg, your name or your server's hostname) []: thegeekstuff Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: # ls -ltr www.thegeekstuff.* -rw-r--r-- 1 root root 963 Jun 13 20:26 www.thegeekstuff.com.key -rw-r--r-- 1 root root 664 Jun 13 20:35 www.thegeekstuff.com.csr
3. Genera un certificato SSL autofirmato
A scopo di test, puoi generare un certificato SSL autofirmato valido per 1 anno utilizzando il comando openssl come mostrato di seguito.
# openssl x509 -req -days 365 -in www.thegeekstuff.com.csr -signkey www.thegeekstuff.com.key -out www.thegeekstuff.com.crt Signature ok subject=/C=US/ST=California/L=Los Angeles/O=thegeekstuff/OU=IT/CN=www.thegeekstuff.com Getting Private key Enter pass phrase for www.thegeekstuff.com.key: # ls -l www.thegeekstuff* -rw-r--r-- 1 root root 963 Jun 13 20:26 www.thegeekstuff.com.key -rw-r--r-- 1 root root 664 Jun 13 20:35 www.thegeekstuff.com.csr -rw-r--r-- 1 root root 879 Jun 13 20:43 www.thegeekstuff.com.crt # cat www.thegeekstuff.com.crt -----BEGIN CERTIFICATE----- haidfshoaihsdfAKDJFAISHTEIHkjasdjadf9w0BAQUFADCB kjadfijadfhWQIOUQERUNcMNasdkjfakljasdBgEFBQcDAQ kjdghkjhfortoieriqqeurNZXCVMNCMN.MCNaGF3dGUuY29 -----END CERTIFICATE-----
Puoi utilizzare questo metodo per generare chiavi SSL Apache, file CSR e CRT nella maggior parte dei sistemi Linux e Unix inclusi Ubuntu, Debian, CentOS, Fedora e Red Hat.
4. Ottieni un certificato SSL di prova valido (opzionale)
Invece di firmarlo tu stesso, puoi anche generare un certificato SSL di prova valido da thawte. vale a dire prima di spendere soldi per l'acquisto di un certificato, puoi anche ottenere certificati SSL di prova validi di 21 giorni completamente funzionanti da Thawte. Una volta che questo certificato valido funziona, puoi decidere di acquistarlo da Thawte o da qualsiasi altra organizzazione di firma SSL.
Questo passaggio è facoltativo e non realmente necessario. A scopo di test, puoi sempre utilizzare il certificato autofirmato generato dal passaggio precedente.
Vai alla pagina di richiesta del certificato di prova Thwate e procedi come segue:
- Seleziona "Certificato server Web SSL (tutti i server)" sotto "seleziona il certificato di prova".
- Non selezionare la casella di controllo PKCS #7 sotto "configura certificato"
- Copia/incolla il file *.csr che hai generato sopra nella casella di testo sotto "Richiesta di firma del certificato (CSR)"
- Fai clic su Avanti in basso, che ti darà un certificato di prova gratuito di 21 giorni.
Copia/incolla il certificato di prova nel file www.thegeekstuff.com.crt come mostrato di seguito.
# cat www.thegeekstuff.com.crt -----BEGIN CERTIFICATE----- haidfshoaihsdfAKDJFAISHTEIHkjasdjadf9w0BAQUFADCB kjadfijadfhWQIOUQERUNcMNasdkjfakljasdBgEFBQcDAQ kjdghkjhfortoieriqqeurNZXCVMNCMN.MCNaGF3dGUuY29 -----END CERTIFICATE-----