Sie sind auf Seite 1von 33

PROIECT RETELE DE CALCULATOARE

LINUX HTTPS server-client,


with SSL encryption , port
443 requests
Informațiile sunt securizate corespunzător, iar site-ul web al companiei suporta o comunicare
SSL securizată. Chiar dacă nu au fost expuse informații despre carduri și date de identificare
personală.
where we will put the certificates (in /etc/apache2/ssl)

sudo mkdir /etc/apache2/ssl

now we generate the certicates, for 3 years (1095 days) under the folder we created above.

sudo openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -out
/etc/apache2/ssl/server.crt -keyout /etc/apache2/ssl/server.key

that will show the following, and ask you some questions.

Generating a 2048 bit RSA private key


............................................+++
.....................+++
writing new private key to '/etc/apache2/ssl/server.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) [AU]:FR
State or Province Name (full name) [Some-State]:Poitou
Locality Name (eg, city) []:Montamise
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Internet Self CA
Organizational Unit Name (eg, section) []:IT
Common Name (e.g. server FQDN or YOUR name) []:demo.hallard.me
Email Address []:mydummy@email.com

Common Name, it should match the internet name FQDN (here demo.hallard.me)

Now we install the SSL mod for apache, this instruction pre configure the file
/etc/apache2/ports.conf with some line and the important one that say Listen 443

sudo a2enmod ssl

We put the default-ssl site available creating a symbolic link

sudo ln -s /etc/apache2/sites-available/default-ssl /etc/apache2/sites-


enabled/000-default-ssl

Now we edit the file default-ssl (or default-ssl.conf for new version) we have just enabled

sudo nano /etc/apache2/sites-enabled/000-default-ssl.conf

Edit October 2014 : on new apache2 version, configuration files need to have .conf
extension, so in this case the two previous commands are now :

sudo ln -s /etc/apache2/sites-available/default-ssl.conf
/etc/apache2/sites-enabled/000-default-ssl.conf
sudo nano /etc/apache2/sites-enabled/000-default-ssl.conf

End of Edit

and we change the two lines relative to SSLCertificate as follow :

SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key

Now restart apache server

sudo /etc/init.d/apache2 restart

now you can go with your favorite browser, in my example https://demo.hallard.me, the
browser will warn you because it is a self signed certificate, but if you accept it you will now
have the same famous “It works!” but with encryption. To avoid warning by browser, you can
add the certificate to Trusted Root Certificate Authority of your computer. The procedure to
to this depends on browser and operating system, so google is your friend.

Now it is safe that you force SSL encryption on each page that require authentication.

For example, for WordPress, add the following two lines (just after the other existing define
lines in the file wp-config.php (located in wordpress installation dir)

Introduction

TLS, or transport layer security, and its predecessor SSL, which stands for secure sockets
layer, are web protocols used to wrap normal traffic in a protected, encrypted wrapper.

Using this technology, servers can send traffic safely between servers and clients without the
possibility of messages being intercepted by outside parties. The certificate system also assists
users in verifying the identity of the sites that they are connecting with.

SSL certificate for use with an Apache web server on Ubuntu

A self-signed certificate will encrypt communication between your server and any clients.
However, because it is not signed by any of the trusted certificate authorities included with
web browsers, users cannot use the certificate to validate the identity of your server
automatically.

A self-signed certificate may be appropriate if you do not have a domain name associated
with your server and for instances where an encrypted web interface is not user-facing. If you
do have a domain name, in many cases it is better to use a CA-signed certificate.

Step 1 – Creating the SSL Certificate

TLS/SSL works by using a combination of a public certificate and a private key. The SSL key
is kept secret on the server. It is used to encrypt content sent to clients. The SSL certificate is
publicly shared with anyone requesting the content. It can be used to decrypt the content
signed by the associated SSL key.

We can create a self-signed key and certificate pair with OpenSSL in a single command:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-
selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt

You will be asked a series of questions. Before we go over that, let’s take a look at what is
happening in the command we are issuing:

 openssl: This is the basic command line tool for creating and managing OpenSSL
certificates, keys, and other files.
 req: This subcommand specifies that we want to use X.509 certificate signing request
(CSR) management. The “X.509” is a public key infrastructure standard that SSL and
TLS adheres to for its key and certificate management. We want to create a new X.509
cert, so we are using this subcommand.
 -x509: This further modifies the previous subcommand by telling the utility that we
want to make a self-signed certificate instead of generating a certificate signing
request, as would normally happen.
 -nodes: This tells OpenSSL to skip the option to secure our certificate with a
passphrase. We need Apache to be able to read the file, without user intervention,
when the server starts up. A passphrase would prevent this from happening because
we would have to enter it after every restart.
 -days 365: This option sets the length of time that the certificate will be considered
valid. We set it for one year here.
 -newkey rsa:2048: This specifies that we want to generate a new certificate and a new
key at the same time. We did not create the key that is required to sign the certificate
in a previous step, so we need to create it along with the certificate. The rsa:2048
portion tells it to make an RSA key that is 2048 bits long.
 -keyout: This line tells OpenSSL where to place the generated private key file that we
are creating.
 -out: This tells OpenSSL where to place the certificate that we are creating.

As we stated above, these options will create both a key file and a certificate. We will be
asked a few questions about our server in order to embed the information correctly in the
certificate.

Fill out the prompts appropriately. The most important line is the one that requests the
Common Name (e.g. server FQDN or YOUR name). You need to enter the domain name
associated with your server or, more likely, your server’s public IP address.

The entirety of the prompts will look something like this:


Step 2 – Configuring Apache to Use SSL

We have created our key and certificate files under the /etc/ssl directory. Now we just need
to modify our Apache configuration to take advantage of these.

We will make a few adjustments to our configuration:

1. We will create a configuration snippet to specify strong default SSL settings.


2. We will modify the included SSL Apache Virtual Host file to point to our generated SSL
certificates.

3. (Recommended) We will modify the unencrypted Virtual Host file to automatically redirect
requests to the encrypted Virtual Host.

Creating an Apache Configuration Snippet with Strong Encryption Settings

First, we will create an Apache configuration snippet to define some SSL settings. This will
set Apache up with a strong SSL cipher suite and enable some advanced features that will
help keep our server secure. The parameters we will set can be used by any Virtual Hosts
enabling SSL.

Create a new snippet in the /etc/apache2/conf-available directory. We will name the file
ssl-params.conf to make its purpose clear:

 sudo nano /etc/apache2/conf-available/ssl-params.conf


 

To set up Apache SSL securely, we will be using the recommendations by Remy van Elst on
the site. This site is designed to provide easy-to-consume encryption settings for popular
software.

Modifying the Default Apache SSL Virtual Host File

Next, let’s modify /etc/apache2/sites-available/default-ssl.conf, the default


Apache SSL Virtual Host file. If you are using a different server block file, substitute its name
in the commands below.

Before we go any further, let’s back up the original SSL Virtual Host file:

sudo cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/default-


ssl.conf.bak
SSL Virtual Host file to make adjustments:

 sudo nano /etc/apache2/sites-available/default-ssl.conf



 

Inside, with most of the comments removed, the Virtual Host file should look something like
this by default:

Modifying the HTTP Host File to Redirect to HTTPS

As it stands now, the server will provide both unencrypted HTTP and encrypted HTTPS
traffic. For better security, it is recommended in most cases to redirect HTTP to HTTPS
automatically. If you do not want or need this functionality, you can safely skip this section.

To adjust the unencrypted Virtual Host file to redirect all traffic to be SSL encrypted, we can
open the /etc/apache2/sites-available/000-default.conf file:

 sudo nano /etc/apache2/sites-available/000-default.conf



 

Inside, within the VirtualHost configuration blocks, we need to add a Redirect directive,
pointing all traffic to the SSL version of the site:

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
. . .

Redirect "/" "https://your_domain_or_IP/"


. . .
</VirtualHost>
 

Save and close the file when you are finished.

Step 3 – Adjusting the Firewall

If you have the ufw firewall enabled, as recommended by the prerequisite guides, you might
need to adjust the settings to allow for SSL traffic. Luckily, Apache registers a few profiles
with ufw upon installation.

We can see the available profiles by typing:

 sudo ufw app list



 

You should see a list like this:

Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH

You can see the current setting by typing:

 sudo ufw status



 

If you allowed only regular HTTP traffic earlier, your output might look like this:

Output
Status: active

To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Apache ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache (v6) ALLOW Anywhere (v6)

To additionally let in HTTPS traffic, we can allow the “Apache Full” profile and then delete
the redundant “Apache” profile allowance:

 sudo ufw allow 'Apache Full'



 sudo ufw delete allow 'Apache'

 
Your status should look like this now:

 sudo ufw status



 

Output
Status: active

To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Apache Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache Full (v6) ALLOW Anywhere (v6)

Step 4 – Enabling the Changes in Apache

Now that we’ve made our changes and adjusted our firewall, we can enable the SSL and
headers modules in Apache, enable our SSL-ready Virtual Host, and restart Apache.

We can enable mod_ssl, the Apache SSL module, and mod_headers, needed by some of the
settings in our SSL snippet, with the a2enmod command:

 sudo a2enmod ssl



 sudo a2enmod headers

 

Next, we can enable our SSL Virtual Host with the a2ensite command:

 sudo a2ensite default-ssl



 

We will also need to enable our ssl-params.conf file, to read in the values we set:

 sudo a2enconf ssl-params



 

At this point, our site and the necessary modules are enabled. We should check to make sure
that there are no syntax errors in our files. We can do this by typing:

 sudo apache2ctl configtest



 

If everything is successful, you will get a result that looks like this:

Output
AH00558: apache2: Could not reliably determine the server's fully qualified
domain name, using 127.0.1.1. Set the 'ServerName' directive globally to
suppress this message
Syntax OK

The first line is just a message telling you that the ServerName directive is not set globally. If
you want to get rid of that message, you can set ServerName to your server’s domain name or
IP address in /etc/apache2/apache2.conf. This is optional as the message will do no harm.

If your output has Syntax OK in it, your configuration file has no syntax errors. We can safely
restart Apache to implement our changes:

 sudo systemctl restart apache2



 

Step 5 – Testing Encryption

Now, we’re ready to test our SSL server.

Open your web browser and type https:// followed by your server’s domain name or IP
into the address bar:

https://server_domain_or_IP

This is expected and normal. We are only interested in the encryption aspect of our certificate, not
the third party validation of our host’s authenticity. Click “ADVANCED” and then the link provided to
proceed to your host anyways

Open your server block configuration file again:

 sudo nano /etc/apache2/sites-available/000-default.conf



 

Find the Redirect line we added earlier. Add permanent to that line, which changes the
redirect from a 302 temporary redirect to a 301 permanent redirect:

/etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
. . .

Redirect permanent "/" "https://your_domain_or_IP/"

. . .
</VirtualHost>
 

Save and close the file.

Check your configuration for syntax errors:


 sudo apache2ctl configtest

 

When you’re ready, restart Apache to make the redirect permanent:

 sudo systemctl restart apache2


 Log in to your Ubuntu server and gain access to the bash prompt. The first thing to do
is load the SSL module with the command: 

 sudo a2enmod ssl


 Once the module is loaded, you then need to enable the default SSL configuration with
the command: 

 sudo a2ensite default-ssl.conf


 This configuration will set the SELengine to On and make use of a self-signed (snake
oil) certificate and key. If you're using an actual SSL certificate from a trusted CA,
you'd configure it with the lines SSLCertificateFIle and SSLCertificateKeyFile. 

 Finally, restart Apache with the command:

 sudo systemctl restart apache2

 sudo a2dismod ssl


 and restart apache2

 sudo service apache2 restart


 To do the opposite, use this command

 sudo a2enmod ssl

 and also restart apache2

nd enabled the ssl mod with sudo a2enmod ssl

My apache2.conf file includes the mods:

# Include module configuration:


Include mods-enabled/*.load
Include mods-enabled/*.conf

My ports.conf file reads:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default
# This is also true if you have upgraded from before 2.2.9-3 (i.e. from
# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and
# README.Debian.gz

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

My sites-available/ folder has two files: default and default-ssl

default reads:

<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/


<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,


# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined


Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

Alias /bugzilla/ /var/www/bugzilla/


<directory /var/www//bugzilla>
AddHandler cgi-script .cgi .pl
Options +Indexes +ExecCGI +FollowSymLinks
DirectoryIndex index.cgi
AllowOverride Limit
</directory>

</VirtualHost>

and default-ssl reads:

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster@localhost

DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/


<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,


# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined


Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

# SSL Engine Switch:


# Enable/Disable SSL for this virtual host.
SSLEngine on

# A self-signed (snakeoil) certificate can be created by


installing
# the ssl-cert package. See
# /usr/share/doc/apache2.2-common/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only
the
# SSLCertificateFile directive is needed.
# SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
# SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
# Modified
SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key

# Server Certificate Chain:


# Point SSLCertificateChainFile at a file containing the
# concatenation of PEM encoded CA certificates which form the
# certificate chain for the server certificate. Alternatively
# the referenced file can be the same as SSLCertificateFile
# when the CA certificates are directly appended to the server
# certificate for convinience.
#SSLCertificateChainFile /etc/apache2/ssl.crt/server-ca.crt

# Certificate Authority (CA):


# Set the CA certificate verification path where to find CA
# certificates for client authentication or alternatively one
# huge file containing all of them (file must be PEM encoded)
# Note: Inside SSLCACertificatePath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCACertificatePath /etc/ssl/certs/
#SSLCACertificateFile /etc/apache2/ssl.crt/ca-bundle.crt

# Certificate Revocation Lists (CRL):


# Set the CA revocation path where to find CA CRLs for client
# authentication or alternatively one huge file containing all
# of them (file must be PEM encoded)
# Note: Inside SSLCARevocationPath you need hash symlinks
# to point to the certificate files. Use the provided
# Makefile to update the hash symlinks after changes.
#SSLCARevocationPath /etc/apache2/ssl.crl/
#SSLCARevocationFile /etc/apache2/ssl.crl/ca-bundle.crl
# Client Authentication (Type):
# Client certificate verification type and depth. Types are
# none, optional, require and optional_no_ca. Depth is a
# number which specifies how deeply to verify the certificate
# issuer chain before deciding the certificate is not valid.
#SSLVerifyClient require
#SSLVerifyDepth 10

# Access Control:
# With SSLRequire you can do per-directory access control based
# on arbitrary complex boolean expressions containing server
# variable checks and other lookup directives. The syntax is a
# mixture between C and Perl. See the mod_ssl documentation
# for more details.
#<Location />
#SSLRequire ( %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
# and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
# and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
# and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
# and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20 ) \
# or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
#</Location>

# SSL Engine Options:


# Set various options for the SSL engine.
# o FakeBasicAuth:
# Translate the client X.509 into a Basic Authorisation. This
means that
# the standard Auth/DBMAuth methods can be used for access
control. The
# user name is the `one line' version of the client's X.509
certificate.
# Note that no password is obtained from the user. Every entry
in the user
# file needs this password: `xxj31ZMTZzkVA'.
# o ExportCertData:
# This exports two additional environment variables:
SSL_CLIENT_CERT and
# SSL_SERVER_CERT. These contain the PEM-encoded certificates
of the
# server (always existing) and the client (only existing when
client
# authentication is used). This can be used to import the
certificates
# into CGI scripts.
# o StdEnvVars:
# This exports the standard SSL/TLS related `SSL_*' environment
variables.
# Per default this exportation is switched off for performance
reasons,
# because the extraction step is an expensive operation and is
usually
# useless for serving static content. So one usually enables
the
# exportation for CGI and SSI requests only.
# o StrictRequire:
# This denies access when "SSLRequireSSL" or "SSLRequire"
applied even
# under a "Satisfy any" situation, i.e. when it applies access
is denied
# and no other module can change it.
# o OptRenegotiate:
# This enables optimized SSL connection renegotiation handling
when SSL
# directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

# o StdEnvVars:
# This exports the standard SSL/TLS related `SSL_*' environment
variables.
# Per default this exportation is switched off for performance
reasons,
# because the extraction step is an expensive operation and is
usually
# useless for serving static content. So one usually enables
the
# exportation for CGI and SSI requests only.
# o StrictRequire:
# This denies access when "SSLRequireSSL" or "SSLRequire"
applied even
# under a "Satisfy any" situation, i.e. when it applies access
is denied
# and no other module can change it.
# o OptRenegotiate:
# This enables optimized SSL connection renegotiation handling
when SSL
# directives are used in per-directory context.
#SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>

# SSL Protocol Adjustments:


# The safe and default but still SSL/TLS standard compliant
shutdown
# approach is that mod_ssl sends the close notify alert but
doesn't wait for
# the close notify alert from client. When you need a different
shutdown
# approach you can use one of the following variables:
# o ssl-unclean-shutdown:
# This forces an unclean shutdown when the connection is
closed, i.e. no
# SSL close notify alert is send or allowed to received. This
violates
# the SSL/TLS standard but is needed for some brain-dead
browsers. Use
# this when you receive I/O errors because of the standard
approach where
# mod_ssl sends the close notify alert.
# o ssl-accurate-shutdown:
# This forces an accurate shutdown when the connection is
closed, i.e. a
# SSL close notify alert is send and mod_ssl waits for the
close notify
# alert of the client. This is 100% SSL/TLS standard compliant,
but in
# practice often causes hanging connections with brain-dead
browsers. Use
# this only for browsers where you know that their SSL
implementation
# works correctly.
# Notice: Most problems of broken clients are also related to the
HTTP
# keep-alive facility, so you usually additionally want to
disable
# keep-alive for those clients, too. Use variable "nokeepalive"
for this.
# Similarly, one has to force some clients to use HTTP/1.0 to
workaround
# their broken HTTP/1.1 implementation. Use variables "downgrade-
1.0" and
# "force-response-1.0" for this.
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>
</IfModule>

After making all the changes I was sure to restart apache (using service apache2 restart,
apchectl -k restart, sudo /etc/init.d/apache2 restart - I've used them all at some point, though I
don't know if there is a difference).

After all this, HTTPS does not work: If I try to go to https://fileserver with my browser
(Chromium) I get an error:

SSL connection error


Unable to make a secure connection to the server. This may be a problem
with the server, or it may be requiring a client authentication certificate
that you don't have.
Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error.

But if I try to go to my wiki, using for example http://fileserver:443/wiki/Main_Page,


I do get to the main page, but it doesnt appear to be an ssl connection. If I try to access it via
https://fileserver/wiki/Main_Page I get the same error as above. I
1.2.1: Step 1 - Activation of the SSL Module

first step in the simple and user-friendly process remains to activate SSL on the droplet. This
can be done by using the following command:

sudo a2enmod ssl

The above step needs to be followed up by restarting Apache, by using the following
command:

sudo service apache2 restart


The above completes the first step in the process of creating an Apache SSL Certificate on
Ubuntu.

1.2.2: Step 2 - Creation of a New Directory for the SSL Certificate

The second step entails creation of a new directory to store the server key and certificate. The
following command shall help users achieve that:

sudo mkdir /etc/apache2/ssl

The above command shall lead to the creation of a new directory, as required. You are now
ready to move on to the next step.

1.2.3: Step 3 - Creation of a Self-Signed SSL Certificate

When creating a new SSL certificate, one needs to specify the duration validity of the same by
changing the value 365 (as appearing in the message below) to the preferred number of days.
It is important to mention here that the certificate so created stands to auto-expire upon
completion of one year.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout
/etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

The above command is rather versatile, and lets users create both the self-signed SSL
certificate and the server key to safeguard it, in addition to placing both of these into the new
directory. The command shall prompt the terminal to display a long list of important fields
that need to be supplied with correct details (as outlined below):

Generating a 2048 bit RSA private key


...................................................................................+++
.+++
writing new private key to '/etc/apache2/ssl/apache.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) [AU]: <- e.g. UK
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]: <- enter your name or company
name here
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []: <- Enter your domain name here. e.g.
sample.com
Email Address []:
The most important field on the above screen remains - Common Name -. You need to key in
the official domain name of the company here or, your website's complete IP address in the
absence of a formal company domain name.

1.2.4: Step 4 - Setting Up the Certificate

Execution of Step 1 through 3 shall ensure availability of all the requisite components of the
finished certificate. Consequently, users need to set up the virtual hosts that can display the
new certificate. This can be done by opening up the SSL configuration file, using the
following command:

nano /etc/apache2/sites-available/default-ssl

You need to locate the section that begins with on the window the above command shall lead
you to, and make the following changes in a swift manner. Subsequently, you need to add a
line with your unique server name right underneath the Server Admin email (as shown below)

ServerName sample.com:443

Here, users must replace - sample.com - with their unique DNS approved domain name/IP
address of the server. An important point to note here is that the unique domain name/server
IP address on the certificate must correspond to that supplied by the user under the field
‘common name) as part of Step 3 above.

Further, users need to locate the following three lines on the screen, and ensure an appropriate
match with the extensions below:

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

Once this is done, all you need to do is save and exit out of the file, which completes Step 4
for you.

1.2.5: Step 5 - Activation of the New Virtual Host

Prior to the activation of the website that will appear on the 443 port, it is important to enable
that Virtual Host: The following command shall help you do that:

sudo a2ensite default-ssl

With the activation of the new Virtual Host using the above command, you are all set. All you
need to do is restart the Apache server to reload it with all the incorporated changes as per the
aforementioned steps. The following command shall lead you there:

sudo service apache2 reload


Once the Restart process is complete and the Apache server has been reloaded with all the
requested changes, users need to type https://yourwebsiteaddress, to be able to view the new
certificate. Lastly, once the SSL certificate has been successfully set up on the site, users may
install an FTP server if the same has not been done yet.

Conclusion

You have configured your Apache server to use strong encryption for client connections. This
will allow you serve requests securely, and will prevent outside parties from reading your
traffic.

Das könnte Ihnen auch gefallen