Difference between revisions of "Letsencrypt/openssl"

From Hackerspace.gr
Jump to: navigation, search
(Date Expiration)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
== Useful Commands ==
  
<p>
+
=== OpenSSL ===
 
+
'''Useful Commands'''
+
</p>
+
  
 
notes based on '''CentOS''' 6.7
 
notes based on '''CentOS''' 6.7
 
 
 
  
 
Τα πιστοποιητικά (certificates) ονομάζονται x509
 
Τα πιστοποιητικά (certificates) ονομάζονται x509
  
 +
==== View a x509 ====
  
 
Πως μπορούμε να δούμε το πιστοποιητικό ενός site
 
Πως μπορούμε να δούμε το πιστοποιητικό ενός site
Line 20: Line 16:
  
 
</pre>
 
</pre>
 
  
 
Το πιστοποιητικό είναι μεταξύ του  
 
Το πιστοποιητικό είναι μεταξύ του  
Line 30: Line 25:
 
</pre>
 
</pre>
  
 +
==== Text Output ====
  
 
Μπορούμε να μετατρέψουμε το πιστοποιητικό σε text output για να πάρουμε περισσότερες πληροφορίες, όπως πότε λήγει:
 
Μπορούμε να μετατρέψουμε το πιστοποιητικό σε text output για να πάρουμε περισσότερες πληροφορίες, όπως πότε λήγει:
Line 37: Line 33:
 
</pre>
 
</pre>
  
 
+
==== Date Expiration ====
ή
+
  
 
<pre>
 
<pre>
$ openssl x509 -text -in <(openssl s_client -connect hackerspace.gr:443) | grep -E 'Not Before|Not After'
+
$ export CN='hackerspace.gr';
 +
$ openssl x509 -text -in <(openssl s_client -connect ${CN}:443) | grep -E 'Not Before|Not After'
  
 
             Not Before: Jun 12 17:55:50 2015 GMT
 
             Not Before: Jun 12 17:55:50 2015 GMT
 
             Not After : Jun 13 05:21:51 2017 GMT
 
             Not After : Jun 13 05:21:51 2017 GMT
 
 
</pre>
 
</pre>
  
 +
==== Chain ====
  
 
Πως μπορούμε να δούμε, ποιος έχει εκδόσει το πιστοποιητικό και ποιοι οργανισμοί έχουν υπογράψει
 
Πως μπορούμε να δούμε, ποιος έχει εκδόσει το πιστοποιητικό και ποιοι οργανισμοί έχουν υπογράψει
Line 53: Line 49:
 
<pre>
 
<pre>
 
$ openssl s_client -connect hackerspace.gr:443  </dev/null  | grep ^depth
 
$ openssl s_client -connect hackerspace.gr:443  </dev/null  | grep ^depth
 
 
  
 
depth=2 C = IL, O = StartCom Ltd., OU = Secure Digital Certificate Signing, CN = StartCom Certification Authority
 
depth=2 C = IL, O = StartCom Ltd., OU = Secure Digital Certificate Signing, CN = StartCom Certification Authority
Line 63: Line 57:
  
 
DONE
 
DONE
 
 
  
 
Το depth=0 είναι το πιστοποιητικό μας,  
 
Το depth=0 είναι το πιστοποιητικό μας,  
Line 70: Line 62:
 
το depth=2 είναι o root Certificate Authority
 
το depth=2 είναι o root Certificate Authority
  
 +
</pre>
  
 +
==== intermediates ====
 +
 +
Πως βλέπουμε όλα τα πιστοποιητικά από ένα site (δλδ το δικό του και των intermediates):
 +
 +
<pre>
 +
 +
$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null
  
 
</pre>
 
</pre>
  
 +
save them all to a file:
  
 +
<pre>
  
 +
$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null | sed -n '/BEGIN/,/END/p' > /tmp/certs
  
Πως βλέπουμε όλα τα πιστοποιητικά από ένα site (δλδ το δικό του και των intermediates):
+
</pre>
  
 +
save the first certificate (site certificate) to a file:
  
 
<pre>
 
<pre>
 +
$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null | sed -n '/BEGIN/,/END/p;/END/q'  > /tmp/hackerspace.crt
 +
</pre>
  
$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null
+
verify it:
 +
 
 +
<pre>
 +
 
 +
$ openssl x509 -text -in /tmp/hackerspace.crt
  
 
</pre>
 
</pre>
  
 +
verify chain
  
save them all to a file:
+
<pre>
 +
 
 +
$ openssl verify -CAfile <(cat /etc/pki/tls/certs/ca-bundle.crt /tmp/certs ) /tmp/hackerspace.crt
 +
 
 +
/tmp/hackerspace.crt: OK
 +
 
 +
</pre>
 +
 
 +
----
 +
 
 +
=== Let's Encrypt ===
 +
 
 +
==== Διευκρίνηση ====
 +
 
 +
Το '''letsencrypt''' είναι πρόγραμμα -client- που αυτόματα εκδίδει πιστοποιητικά ασφαλείας (x509 certificates) με έναν εντελώς αυτόματο τρόπο υλοποιώντας το πρωτόκολλο Automated Certificate Management Environment (ACME). To ACME είναι ένας τρόπος αυθεντικοποίησης ενός domain με ένα web server.
 +
 
 +
 
 +
O client του Let's Encrypt θέλει python 2.7
 +
 
 +
κι όπως είπαμε η διαδικασία έκδοσης πιστοποιητικών γίνεται εντελώς αυτόματα.
 +
 
 +
==== Installation ====
 +
===== CentOS 7 =====
  
 
<pre>
 
<pre>
 +
# cat /etc/redhat-release
 +
CentOS Linux release 7.2.1511 (Core)
 +
</pre>
  
$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null | sed -n '/BEGIN/,/END/p' > /tmp/certs
+
<pre>
 +
# yum -y install letsencrypt
 +
</pre>
  
 +
===== an example =====
 +
 +
 +
<pre>
 +
 +
# yum -y install letsencrypt
 +
# letsencrypt certonly \
 +
-t --agree-tos \
 +
-d librebit.net \
 +
--email testuser@librebit.net \
 +
--webroot -w /var/www/html /
 +
--dry-run
 +
 +
remove “--dry-run” to activate your Certs
  
 
</pre>
 
</pre>
  
  
 +
<pre>
  
save the first certificate (site certificate) to a file:
+
ls -l /etc/letsencrypt/live/librebit.net
 +
total 0
 +
lrwxrwxrwx 1 root root 36 May 28 06:57 cert.pem -> ../../archive/librebit.net/cert1.pem
 +
lrwxrwxrwx 1 root root 37 May 28 06:57 chain.pem -> ../../archive/librebit.net/chain1.pem
 +
lrwxrwxrwx 1 root root 41 May 28 06:57 fullchain.pem -> ../../archive/librebit.net/fullchain1.pem
 +
lrwxrwxrwx 1 root root 39 May 28 06:57 privkey.pem -> ../../archive/librebit.net/privkey1.pem
 +
 
 +
</pre>
 +
 
 +
==== CentOS 6 ====
 +
 
 +
Σε CentOS 6 έχει by default python 2.6
 +
 
 +
Οπότε ο προτεινόμενος τρόπος είναι ο παρακάτω:
  
 
<pre>
 
<pre>
$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null | sed -n '/BEGIN/,/END/p;/END/q'  > /tmp/hackerspace.crt
+
# git clone https://github.com/letsencrypt/letsencrypt
 +
# cd letsencrypt
 
</pre>
 
</pre>
  
 +
Θα χρειαστεί να "στήσουμε" το περιβάλλον:
  
verify it:
+
<pre>
 +
# ./letsencrypt-auto-source/letsencrypt-auto --os-packages-only
 +
</pre>
 +
 
 +
ώστε να εγκατασταθούν όλα τα προγράμματα που χρειάζεται ο client.
 +
 
 +
Υπενθυμίζω πως τίποτα από όλα αυτά δεν χρειάζονται, εάν η διανομή σας
 +
 
 +
 
 +
=== Renew ===
 +
 
 +
==== Lets Encrypt Client: certbot on Centos 6.8 ====
 +
 
 +
Let’s Encrypt client: '''certbot''' is been written in python and as it’s predecessor needs at least Python 2.7.
 +
 
 +
But (still) in CentOS series 6 (currently 6.8) there is no natively support for python27.
 +
 
 +
So I did this thing below, quick & dirty:
  
  
 
<pre>
 
<pre>
  
$ openssl x509 -text -in /tmp/hackerspace.crt
+
# cd /usr/local/src/
 +
# wget -c https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
 +
# tar xf Python-2.7.11.tgz
 +
# cd Python-2.7.11
 +
# ./configure
 +
# make
 +
# make install
  
 
</pre>
 
</pre>
 +
 +
 +
and these are my notes for renew certificates :
 +
 +
<pre>
 +
 +
# ln -s /opt/Python-2.7/bin/python2.7 /usr/local/bin/python2
 +
 +
[root@1 certbot]# source venv/bin/activate
 +
(venv)[root@1 certbot]#
 +
 +
# cd venv/bin/
 +
 +
# ./certbot renew --dry-run
 +
 +
# ./certbot renew
 +
 +
# rm /usr/local/bin/python2
 +
 +
</pre>
 +
 +
[[Category:Documentation]]

Latest revision as of 09:52, 2 November 2017

Useful Commands

OpenSSL

notes based on CentOS 6.7

Τα πιστοποιητικά (certificates) ονομάζονται x509

View a x509

Πως μπορούμε να δούμε το πιστοποιητικό ενός site


$ openssl s_client -connect hackerspace.gr:443  </dev/null

Το πιστοποιητικό είναι μεταξύ του

-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

Text Output

Μπορούμε να μετατρέψουμε το πιστοποιητικό σε text output για να πάρουμε περισσότερες πληροφορίες, όπως πότε λήγει:

$ openssl x509 -text -in <(openssl s_client -connect hackerspace.gr:443)

Date Expiration

$ export CN='hackerspace.gr';
$ openssl x509 -text -in <(openssl s_client -connect ${CN}:443) | grep -E 'Not Before|Not After'

            Not Before: Jun 12 17:55:50 2015 GMT
            Not After : Jun 13 05:21:51 2017 GMT

Chain

Πως μπορούμε να δούμε, ποιος έχει εκδόσει το πιστοποιητικό και ποιοι οργανισμοί έχουν υπογράψει

$ openssl s_client -connect hackerspace.gr:443  </dev/null  | grep ^depth

depth=2 C = IL, O = StartCom Ltd., OU = Secure Digital Certificate Signing, CN = StartCom Certification Authority

depth=1 C = IL, O = StartCom Ltd., OU = Secure Digital Certificate Signing, CN = StartCom Class 2 Primary Intermediate Server CA

depth=0 C = GR, ST = Attica, L = Filadelfeia, O = Pierros Papadeas, CN = *.hackerspace.gr, emailAddress = postmaster@hackerspace.gr

DONE

Το depth=0 είναι το πιστοποιητικό μας, 
το depth=1 είναι ο intermediate 
το depth=2 είναι o root Certificate Authority

intermediates

Πως βλέπουμε όλα τα πιστοποιητικά από ένα site (δλδ το δικό του και των intermediates):


$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null

save them all to a file:


$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null | sed -n '/BEGIN/,/END/p' > /tmp/certs

save the first certificate (site certificate) to a file:

$ openssl s_client -showcerts -connect hackerspace.gr:443 </dev/null | sed -n '/BEGIN/,/END/p;/END/q'  > /tmp/hackerspace.crt

verify it:


$ openssl x509 -text -in /tmp/hackerspace.crt

verify chain


$ openssl verify -CAfile <(cat /etc/pki/tls/certs/ca-bundle.crt /tmp/certs ) /tmp/hackerspace.crt 

/tmp/hackerspace.crt: OK


Let's Encrypt

Διευκρίνηση

Το letsencrypt είναι πρόγραμμα -client- που αυτόματα εκδίδει πιστοποιητικά ασφαλείας (x509 certificates) με έναν εντελώς αυτόματο τρόπο υλοποιώντας το πρωτόκολλο Automated Certificate Management Environment (ACME). To ACME είναι ένας τρόπος αυθεντικοποίησης ενός domain με ένα web server.


O client του Let's Encrypt θέλει python 2.7

κι όπως είπαμε η διαδικασία έκδοσης πιστοποιητικών γίνεται εντελώς αυτόματα.

Installation

CentOS 7
# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
# yum -y install letsencrypt 
an example

# yum -y install letsencrypt
# letsencrypt certonly \
 -t --agree-tos \
 -d librebit.net \
 --email testuser@librebit.net \
 --webroot -w /var/www/html /
 --dry-run

remove “--dry-run” to activate your Certs



 ls -l /etc/letsencrypt/live/librebit.net
total 0
lrwxrwxrwx 1 root root 36 May 28 06:57 cert.pem -> ../../archive/librebit.net/cert1.pem
lrwxrwxrwx 1 root root 37 May 28 06:57 chain.pem -> ../../archive/librebit.net/chain1.pem
lrwxrwxrwx 1 root root 41 May 28 06:57 fullchain.pem -> ../../archive/librebit.net/fullchain1.pem
lrwxrwxrwx 1 root root 39 May 28 06:57 privkey.pem -> ../../archive/librebit.net/privkey1.pem

CentOS 6

Σε CentOS 6 έχει by default python 2.6

Οπότε ο προτεινόμενος τρόπος είναι ο παρακάτω:

# git clone https://github.com/letsencrypt/letsencrypt
# cd letsencrypt

Θα χρειαστεί να "στήσουμε" το περιβάλλον:

# ./letsencrypt-auto-source/letsencrypt-auto --os-packages-only

ώστε να εγκατασταθούν όλα τα προγράμματα που χρειάζεται ο client.

Υπενθυμίζω πως τίποτα από όλα αυτά δεν χρειάζονται, εάν η διανομή σας


Renew

Lets Encrypt Client: certbot on Centos 6.8

Let’s Encrypt client: certbot is been written in python and as it’s predecessor needs at least Python 2.7.

But (still) in CentOS series 6 (currently 6.8) there is no natively support for python27.

So I did this thing below, quick & dirty:



# cd /usr/local/src/
# wget -c https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
# tar xf Python-2.7.11.tgz
# cd Python-2.7.11
# ./configure
# make
# make install


and these are my notes for renew certificates :


# ln -s /opt/Python-2.7/bin/python2.7 /usr/local/bin/python2

[root@1 certbot]# source venv/bin/activate
(venv)[root@1 certbot]#

# cd venv/bin/

# ./certbot renew --dry-run

# ./certbot renew

# rm /usr/local/bin/python2