אנדרואיד

אבטחה מאובטחת באמצעות הצפנה ב- centos 7

תוכן עניינים:

Anonim

Let's Encrypt היא רשות אישורים חינמית, אוטומטית ופתוחה שפותחה על ידי קבוצת המחקר בנושא אבטחה באינטרנט (ISRG). אישורים שהונפקו על ידי Let's Encrypt תקפים למשך 90 יום ממועד ההנפקה והם מהימנים על ידי כל הדפדפנים הגדולים כיום.

במדריך זה, נסקור את הצעדים הדרושים להתקנת תעודת SSL SSL בחינם בשרת CentOS 7 המריץ את Apache כשרת אינטרנט. אנו נשתמש בכלי השירות certbot בכדי להשיג ולחדש אישורים של Let's Encrypt.

תנאים מוקדמים

ודא כי עמדת בתנאים המוקדמים הבאים לפני שתמשיך במדריך זה:

  • ציין שם דומיין שמצביע על IP השרת הציבורי שלך. נשתמש ב- example.com Apache מותקן ופועל בשרת שלך. יש מארח וירטואלי של Apache עבור התחום שלך. היציאות 80 ו- 443 פתוחות בחומת האש שלך.

התקן את החבילות הבאות הדרושות לשרת אינטרנט מוצפן SSL:

yum install mod_ssl openssl

התקן את Certbot

Certbot הוא כלי שמפשט את התהליך לקבלת אישורי SSL מ- Let's Encrypt והפעלה אוטומטית של HTTPS בשרת שלך.

ניתן לקבל את החבילה certbot להתקנה מ- EPEL. אם מאגר ה- EPEL אינו מותקן במערכת שלך, אתה יכול להתקין אותו באמצעות הפקודה הבאה:

sudo yum install epel-release

לאחר מאגר ה- EPEL מופעל, התקן את חבילת certbot על ידי הקלדה:

sudo yum install certbot

צור קבוצת Dh (דיפי-הלמן) חזקה

החלפת מפתחות Diffie – Hellman (DH) היא שיטה להחלפה מאובטחת של מפתחות קריפטוגרפיים דרך ערוץ תקשורת לא מאובטח. צור מערכת חדשה של פרמטרים DH של 2048 ביט לחיזוק האבטחה:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048 אתה יכול לשנות את הגודל עד 4096 ביטים, אך במקרה זה, הדור עשוי לארוך יותר מ -30 דקות, תלוי באנטרופיה של המערכת.

קבלת אישור בואו להצפין SSL

כדי להשיג אישור SSL לתחום שלנו, אנו נשתמש בתוסף Webroot שעובד על ידי יצירת קובץ זמני לאימות הדומיין המבוקש בספרייה ${webroot-path}/.well-known/acme-challenge . שרת בואו להצפין מבצע בקשות HTTP לקובץ הזמני כדי לאמת כי הדומיין המבוקש פותר לשרת בו פועל certbot.

כדי להפוך את זה פשוט יותר אנו למפות את כל בקשות ה- HTTP עבור. .well-known/acme-challenge לספריה יחידה, /var/lib/letsencrypt .

הפעל את הפקודות הבאות כדי ליצור את הספרייה ולהפיכתה לשרת Apache:

sudo mkdir -p /var/lib/letsencrypt/.well-known sudo chgrp apache /var/lib/letsencrypt sudo chmod g+s /var/lib/letsencrypt

כדי למנוע כפילויות של קוד, צור את שני קטעי התצורה הבאים:

/etc/httpd/conf.d/letsencrypt.conf

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS /etc/httpd/conf.d/ssl-params.conf

SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff # Requires Apache >= 2.4 SSLCompression off SSLUseStapling on SSLStaplingCache "shmcb:logs/stapling-cache(150000)" # Requires Apache >= 2.4.11 SSLSessionTickets Off

הקטע שלמעלה משתמש בשבבים המומלצים על ידי Cipherli.st, מאפשר סיכות OCSP, HTTP Strict Transport Security (HSTS) ואכיפת מעט כותרות HTTP ממוקדות אבטחה.

טען מחדש את תצורת Apache כדי שינויים ייכנסו לתוקף:

sudo systemctl reload

כעת נוכל להפעיל את הכלי Certbot עם התוסף webroot ולקבל את קבצי אישור ה- SSL על ידי הקלדה:

sudo certbot certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com

אם אישור ה- SSL מתקבל בהצלחה, certbot ידפיס את ההודעה הבאה:

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2018-12-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF:

CentOS 7 נשלח עם גרסת Apache גרסה 2.4.6, שאינה כוללת את הנחיית SSLOpenSSLConfCmd . הנחיה זו זמינה רק ב- Apache 2.4.8 מאוחר יותר והיא משמשת לתצורה של פרמטרים של OpenSSL כמו החלפת מפתחות Diffie – Hellman (DH).

נצטרך ליצור קובץ משולב חדש באמצעות אישור Let's Encrypt SSL וקובץ DH שנוצר. לשם כך, הקלד:

cat /etc/letsencrypt/live/example.com/cert.pem /etc/ssl/certs/dhparam.pem >/etc/letsencrypt/live/example.com/cert.dh.pem

כעת, כשהכל מוגדר, ערוך את תצורת המארח הווירטואלי של הדומיין שלך באופן הבא:

/etc/httpd/conf.d/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/cert.dh.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem # Other Apache Configuration

עם התצורה שלמעלה, אנו מכריחים HTTPS ומפנים מחדש מגירסת www לגירסה שאינה www. אל תהסס להתאים את התצורה בהתאם לצרכים שלך.

הפעל מחדש את שירות Apache כדי שינויים ייכנסו לתוקף:

sudo systemctl restart

כעת תוכל לפתוח את האתר שלך באמצעות https:// ותבחין בסמל נעילה ירוקה.

חידוש אוטומטי של בואו להצפין אישור SSL

תעודות בואו להצפין תקפות למשך 90 יום. כדי לחדש אוטומטית את האישורים לפני שפג תוקפם, אנו ניצור עבודת תופת שתפעל פעמיים ביום ונחדש אוטומטית כל אישור 30 יום לפני פקיעתו.

הפעל את הפקודה crontab כדי ליצור cronjob חדש שיחדש את האישור, ליצור קובץ משולב חדש הכולל את מקש DH ולהפעיל מחדש את האפאצ 'י

sudo crontab -e

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload

שמור וסגור את הקובץ.

כדי לבדוק את תהליך החידוש, אתה יכול להשתמש בפקודה certbot ולאחריהם מתג --dry-run :

sudo certbot renew --dry-run

אם אין שגיאות, פירוש הדבר שתהליך החידוש היה מוצלח.

סיכום

במדריך זה השתמשת בלקוח ה- Encrypt client certbot כדי להוריד תעודות SSL עבור התחום שלך. יצרת גם קטעי Apache כדי למנוע כפילות של קוד והגדרת את Apache לשימוש בתעודות. בסוף ההדרכה, הגדרת עבודת גמילה לחידוש אישורים אוטומטית.

בואו להצפין את certbot ssl

פוסט זה הוא חלק מסדרת התקנת LAMP ב- CentOS 7.

פוסטים אחרים בסדרה זו:

כיצד להתקין Apache ב- CentOS 7 • להתקין את MySQL ב- CentOS 7 • כיצד להתקין מארחים וירטואליים של Apache ב- CentOS 7 • Apache מאובטח עם Encrypt בואו ב- CentOS 7