Implementing and using SSL to secure HTTP traffic (2024)

Security of the data stored on a file server is very important these days. Compromised data can cost thousands of dollars tocompany. In the last section, we compiled LDAP authentication module into the Apache build to provide a Authentication mechanism. However HTTP traffic is very insecure, and all data is transferred in clear text - meaning, the LDAP authentication(userid/passwd) will be transmitted as clear text as well. This creates a problem. Anyone can sniff these userid/passwd and gainaccess to DAV store. To prevent this we have to encrypt HTTP traffic, essentially HTTP + SSL or HTTPS. Anything transferred overHTTPS is encrypted, so the LDAP userid/passwd can not be easily deciphered. HTTPS runs on port 443. The resulting build from the last section's compilation process will have Apache to listen to both port 80 (normal HTTP) and 443 (HTTPS). If you are just goingto use this server for DAV, then I will highly suggest that you close port 80. In this section of the HOWTO I will provide some information regarding SSL and maintaining SSL on a Apache HTTP server.

6.1. Introduction to SSL

SSL (Secure Socket Layer) is a protocol layer that exists between the Network Layer and Application layer. As the name suggestSSL provides a mechanism for encrypting all kinds of traffic - LDAP, POP, IMAP and most importantly HTTP.

The following is a over-simplified structure of the layers involved in SSL.

+-------------------------------------------+| LDAP | HTTP | POP | IMAP |+-------------------------------------------+| SSL |+-------------------------------------------+| Network Layer |+-------------------------------------------+

6.1.1. Encryption algorithms used in SSL

There are three kinds of cryptographic techniques used in SSL: Public-Private Key, Symmetric Key, and Digital Signature.

Public-Private Key Crytography - Initiating SSL connection: In this algorithm, encryption and decryption is performed using a pair of private and public keys. The Web-server holds the private Key, and sends the Public key to the client in the Certificate.

  1. The client request content from the Web Server using HTTPS.

  2. The web server responds with a Digital Certificate which includes the server's public key.

  3. The client checks to see if the certificate has expired.

  4. Then the client checks if the Certificate Authority that signed the certificate, is a trusted authority listed in the browser. This explains why we need to get a certificate from a a trusted CA.

  5. The client then checks to see if the Fully Qualified Domain Name (FQDN) of the web server matches the Comman Name (CN) on the certificate?

  6. If everything is successful the SSL connection is initiated.

Implementing and using SSL to secure HTTP traffic (1)Note:

Anything encrypted with Private Key can only be decrypted by using the Public Key. Similarly anything encrypted using the Public Key can only be decrypted using the Private Key. There is a common mis-conception that only the Public Key is used for encryption and Private Key is used for decryption. This is not case. Any key can be used for encryption/decryption. However if one key is used for encryption then the other key must be used for decryption. e.g. A message can not encrypted and then decrypted using only the Public Key.

Using Private Key to encrypt and a Public Key to decrypt ensures the integrity of the sender (owner of the Private Key) to the recipients. Using Public Key to encrypt and a Private Key to decrypt ensures that only the inteded recipient (owner of the Private Key) will have access to the data.(i.e. only the person who holds the Private Key will be able to decipher the message).

Symmetric Cryptography - Actual transmission of data: After the SSL connection has been established, Symmetric cryptography is used for encrypting data as it uses less CPU cycles. In symmetric cryptography the data can be encrypted and decrypted using the same key. The Key for symmetric cryptography is exchanged during the initiation process, using Public Key Cryptography.

Message Digest The server uses message digest algoritm such as HMAC, SHA-1, MD5 to verify the integrity of the transferred data.

6.1.2. Ensuring Authenticity and Integrity

Encryption Process

 Sender's Receiver's PrivateKey PublicKey ,-. ,-. ( ).......... ( ).......... `-' ''''|'|'|| `-' ''''''''|| | | | | | | .----------. | | .----------. | .----------. | | V | | | V | | |Clear Text|--------->|CipherText|--------->|CipherText| | | Step1 | 1 | Step2 | 2 |\ `----------' | `----------' `----------' \ __ | | \ [_' | | step5 \ | |Step3 | __ --|-- | | _.--' | V | _..-'' / \ .---------. | .---------. _..-'' Receiver | SHA 1 | V | Digital | _..-'' |MsgDigest|--------->|Signature|' _ `---------' Step4 `---------' _ (_) _____ ____ ____ ____ _ _ ____ _| |_ _ ___ ____ | ___ | _ \ / ___)/ ___) | | | _ (_ _) |/ _ \| _ \ | ____| | | ( (___| | | |_| | |_| || |_| | |_| | | | | |_____)_| |_|\____)_| \__ | __/ \__)_|\___/|_| |_| (____/|_|

  • Step1: In this step the Original "Clear Text" message is encrypted using the Sender's Private Key, which results in Cipher Text 1. This ensures the Authenticity of the sender.

  • Step2: In this step the "CipherText 1" is encrypted using Receiver's Public Key resulting in "CipherText 2". This will ensure the Authenticity of the Receiver i.e. only the Receiver can decipher the Messsage using his Private Key.

  • Step3: Here the SHA1 Message Digest of the "Clear Text" is created.

  • Step4: SHA1 Message Digest is then encrypted using Sender's Private Key resulting in the Digital Signature of the "ClearText". This Digital Signature can be used by the receiver to ensure the Integrity of the message and authenticity of the Sender.

  • Step5: The "Digital Signature" and the "CipherText 2" are then send to the Receiver.

Decryption Process

 Receiver's Sender's PrivateKey PublicKey ,-. ,-. ( ).......... ( ).......... `-' ''''''''|| `-' '''''''||| | | | | | | .----------. | .----------. | | .----------. | | V | | V | | | .---#1----. |CipherText|--------->|CipherText|--------->|ClearText |------>| SHA 1 | | 2 | Step1 | 1 | Step2 | | | Step3 |MsgDigest| `----------' `----------' | `----------' `---------' | || | ||Step5 | || | || .---------. | .---------. | Digital | V | SHA 1 | |Signature|---------------------->|MsgDigest| _ `---------' Step4 _ `---#2----' | | _ (_) __| |_____ ____ ____ _ _ ____ _| |_ _ ___ ____ / _ | ___ |/ ___)/ ___) | | | _ (_ _) |/ _ \| _ \ ( (_| | ____( (___| | | |_| | |_| || |_| | |_| | | | | \____|_____)\____)_| \__ | __/ \__)_|\___/|_| |_| (____/|_|

  • Step1: In this step the "CipherText 2" message is decrypted using the Receiver's Private Key, which results in Cipher Text 1.

  • Step2: In this step the "CipherText 1" is decrypted using Sender's Public Key resulting in "ClearText".

  • Step3: Here the SHA1 Message Digest of the "Clear Text" is created.

  • Step4: The "Digital Signature" is then decrypted using Sender's Public Key, resulting the "SHA 1 MSG Digest".

  • Step5: The "SHA1 MsgDigest #1" is then compared against "SHA1 MsgDigest #2". If they are equal, the data was not modified during transmission, and the integrity of the Original "Clear Text" has been maintained

6.2. Test Certificates

While compiling Apache we created a test certificate. We used the makefile provided bymod_ssl to create this custom Certificate. We used the command:

# make certificate TYPE=custom

This certificate can be used for testing purposes.

6.3. Certificates for Production use

For production use you will need a certificate from a Certificate Authority (hereafter CA). Certificate Authorities are certificate vendors, who are listed as a Trusted CA in the user's browser. As mentioned in the Encryption Algorithms section, if the CA is not listed as a trusted authority, your user will get a warning message when trying to connect to a secure location.

Similarly the test certificates will also cause a warning message to appear on the user's browser.

6.4. How to generate a CSR

CSR or Certificate Signing Request must be sent to the trusted CA for signing. This section discusses howto create a CSR,and send it to the CA of your choice. # openssl req command can be used to a CSR as follows:

# cd /usr/local/apache/conf/# /usr/local/ssl/bin/openssl req -new -nodes -keyout private.key -out public.csrGenerating a 1024 bit RSA private key............++++++....++++++writing new private key to 'private.key'-----You are about to be asked to enter information that will be incorporatedinto 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 blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [AU]:USState or Province Name (full name) [Some-State]:CaliforniaLocality Name (eg, city) []:San JoseOrganization Name (eg, company) [Internet Widgits Pty Ltd]:Seagate Organizational Unit Name (eg, section) []:Global Client ServerCommon Name (eg, YOUR name) []:xml.seagate.comEmail Address []:saqib@seagate.comPlease enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:badpasswordAn optional company name []:

Implementing and using SSL to secure HTTP traffic (2)"PRNG not seeded"

If you do not have /dev/random on your system you will get a "PRNG not seeded" error message. In that case you can use the following command:

# /usr/local/ssl/bin/openssl req -rand some_file.ext -new -nodes -keyout private.key -out public.csr 

Replace some_file.ext with the name of a existing file on your file system. Any file can be specified. Openssl will use that file to generate the seed

Solaris 9 comes with /dev/random. However on Solaris you might have to install the 112438 patch to get the /dev/random

At this point you will be asked several questions about your server to generate the Certificate Singning Request

Note: Your Common Name (CN) is the Fully Qualified DNS (FQDN) name of your webserver e.g. dav.server.com . If you put in anything else, it will NOT work. Remember the password that you use, for future reference.

Once the process is complete, you will have private.key and a public.csr . You will need to submit the public.csr to the Certification Authority. At this pointe the public.key is not encrypted. To encrypt:

 # mv private.key private.key.unecrpyted# /usr/local/ssl/bin/openssl rsa -in private.key.unecrpyted -des3 -out private.key

6.5. Installing Server Private Key, and Server Certificate

Once the Certification Authority processes your request, they will send an encoded certificate (Digital Certificate) back to you. The Digital Certificate is in the format defined by X.509 v3. The following shows the structure of a typical X509 v3 Digital Certificate

  • Certificate

    • Validity

      • Not Before

      • Not After

    • Subject

    • Subject Public Key Info

      • Public Key Algorithm

      • RSA Public Key

    • Extensions

  • Certificate Signature Algorithm

  • Certificate Signature

6.5.1. Verifying a Digital Certificate

To verify a X.509 Certificate use the following command

# openssl verify server.crtserver.crt: OK 

Where server.crt is the name of the file that contains the Digital Certificate

6.5.2. Viewing the contents of a Digital Certificate

The contents of a Digital Certificate can be viewed by using the # openssl x509 command as follows:

# openssl x509 -text -in server.crtCertificate: Data: Version: 3 (0x2) Serial Number: 312312312 (0x0) Signature Algorithm: md5WithRSAEncryptionIssuer: C=US, O=GTE Corporation, CN=GTE CyberTrust Root Validity Not Before: Feb 8 03:25:50 2000 GMT Not After : Feb 8 03:25:50 2001 GMT Subject: C=US, ST=New York, L=Pelham, O=xml-dev, OU=web, CN=www.xml-dev.com/Email=saqib@xml-dev.com Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public Key: (1024 bit) Modulus (1024 bit):........................ Exponent: 65537 (0x10001) Signature Algorithm: md5WithRSAEncryption ........................

6.5.3. Modifying the httpd.conf to Install the Certificates

You will need to place this certificate on the server, and tell Apache where to find it.

For this example, the Private Key is placed in the /usr/local/apache2/conf/ssl.key/ directory, and the Sever Certificate is placed in the /usr/local/apache2/conf/ssl.crt/.

Copy the file received from the Certification to a file called server.crt in the /usr/local/apache2/conf/ssl.crt/.

And place the private.key generated in the previous step in the /usr/local/apache2/conf/ssl.key/

Then modify the /usr/local/apache2/conf/ssl.conf to point to the correct Private Key and Server Certificate files:

# Server Certificate:# Point SSLCertificateFile at a PEM encoded certificate. If# the certificate is encrypted, then you will be prompted for a# pass phrase. Note that a kill -HUP will prompt again. Keep# in mind that if you have both an RSA and a DSA certificate you# can configure both in parallel (to also allow the use of DSA# ciphers, etc.)SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server.crt#SSLCertificateFile /usr/local/apache2/conf/ssl.crt/server-dsa.crt# Server Private Key:# If the key is not combined with the certificate, use this# directive to point at the key file. Keep in mind that if# you've both a RSA and a DSA private key you can configure# both in parallel (to also allow the use of DSA ciphers, etc.)SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/private.key#SSLCertificateKeyFile /usr/local/apache2/conf/ssl.key/server-dsa.key

6.6. Removing passphrase from the RSA Private Key

RSA Private Key stored on the webserver is usually encrypted, and you need a passphrase to parse the file. That is why youare prompted for a passphrase when start Apache with modssl:

# apachectl startsslApache/1.3.23 mod_ssl/2.8.6 (Pass Phrase Dialog)Some of your private key files are encrypted for security reasons.In order to read them you have to provide us with the pass phrases.Server your.server.dom:443 (RSA)Enter pass phrase:

Encrypting the RSA Private Key is very important. If a cracker gets hold of your "Unencrypted RSA Private Key" he/she can easily impersonate your webserver. If the Key is encrypted, the cracker can not do anything without brute forcing the passphrase. Use of a strong (ie: long) passphrase is encouraged.

However encrypting the Key can sometimes be nuisance, since you will be prompted for a passphrase everytime you start the web-server. Especially if you are using rc scripts to start the webserver at boot time. The prompt for a passphrase will stop the boot process, waiting for your input.

You can get rid of the passphrase prompt easily by decrypting the Key. However make sure that no one can hold of this Key. I would recommend Hardening and Securing guidelines be followed before decrypting the Key on the webserver.

To decrypt the Key:

First make a copy of the encrypted key

# cp server.key server.key.cryp

Then re-write the key with encryption. You will be prompted for the original encrypted Key passphrase

# /usr/local/ssl/bin/openssl rsa -in server.key.cryp -out server.keyread RSA keyEnter PEM pass phrase:writing RSA key

One way to secure the decrypted Private Key is to make readable only by the root:

# chmod 400 server.key

6.7. SSL Performance Tuning

6.7.1. Inter Process SSL Session Cache

Apache uses a multi-process model, in which all the request are NOT handled by the same process. This causes the SSL Session Information to be lost when a Client makes multiple requests. Multiple SSL HandShakes causes lot of overhead on the webserver and the client. To avoid this, SSL Session Information must be stored in a inter-process Session Cache, allowing all the processes to have access to to handshake information. SSLSessionCache Directive the in /usr/local/apache2/conf/ssl.conf file can be used to specify the location of the SSL Session Cache:

SSLSessionCache shmht:logs/ssl_scache(512000)#SSLSessionCache shmcb:logs/ssl_scache(512000)#SSLSessionCache dbm:logs/ssl_scacheSSLSessionCacheTimeout 300

Using dbm:logs/ssl_scache creates the Cache as DBM hashfile on the local disk.

Using shmht:logs/ssl_scache(512000) creates the Cache in Shared Memory Segment

Implementing and using SSL to secure HTTP traffic (3)shmht vs shmcb

shmht: uses a Hash Table to Cache the SSL HandShake Information in the Shared Memory

shmht: uses a Cyclic Buffer to Cache the SSL HandShake Informationin the Shared Memory

Implementing and using SSL to secure HTTP traffic (4)Note:

Not all platforms/OS support creation of Hash table in the Shared Memory. So dbm:logs/ssl_scache must be used instead

6.7.2. Verifying SSLSession Cache

To verify if the SSLSessionCache is working properly, you can use the openssl utility with the -reconnect as follows:

# openssl s_client -connect your.server.dom:443 -state -reconnectCONNECTED(00000003)..............Reused, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHASSL-Session:.....Reused, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHASSL-Session:.....Reused, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHASSL-Session:.....Reused, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHASSL-Session:.....Reused, TLSv1/SSLv3, Cipher is EDH-RSA-DES-CBC3-SHASSL-Session:.....

-reconnect forces the s_client to connect to the server 5 times using the same SSL session ID. You should see 5 attempts of Reusing the same Session-ID as shown above.

Implementing and using SSL to secure HTTP traffic (2024)

FAQs

How do I secure HTTP traffic? ›

To ensure that an attacker cannot use DNS spoofing to direct the user to a plain http:// connection where traffic can be intercepted, websites can use HTTP Strict Transport Security (HSTS) to instruct browsers to require an HTTPS connection for their domain at all times.

What is SSL and how do you implement it? ›

SSL: Secure Sockets Layer

SSL is standard technology for securing an internet connection by encrypting data sent between a website and a browser (or between two servers). It prevents hackers from seeing or stealing any information transferred, including personal or financial data.

How does SSL work with HTTP? ›

HTTPS uses an encryption protocol to encrypt communications. The protocol is called Transport Layer Security (TLS), although formerly it was known as Secure Sockets Layer (SSL). This protocol secures communications by using what's known as an asymmetric public key infrastructure.

What makes HTTPS more secure than HTTP explain your answer? ›

The only difference between the two protocols is that HTTPS uses TLS (SSL) to encrypt normal HTTP requests and responses, and to digitally sign those requests and responses. As a result, HTTPS is far more secure than HTTP. A website that uses HTTP has http:// in its URL, while a website that uses HTTPS has https://.

How to implement SSL? ›

How to add an SSL to your website
  1. Common name. The fully-qualified domain name, or URL, you want to secure. ...
  2. Organization. The legally registered name for your business. ...
  3. City/Locality. ...
  4. State/Province. ...
  5. Country. ...
  6. Generating your CSR. ...
  7. Request your SSL. ...
  8. Verify your SSL request.
Jan 31, 2024

How do you implement HTTPS? ›

How to properly enable HTTPS on your server
  1. Buy an SSL certificate.
  2. Request the SSL certificate.
  3. Install the certificate.
  4. Update your site to enable HTTPS.
Jan 26, 2024

How does SSL work step by step? ›

how SSL works
  1. A browser attempts to connect to a web site secured with SSL. ...
  2. The server sends the browser a copy of its SSL certificate.
  3. The browser checks whether it trusts the SSL certificate. ...
  4. The server sends back a digitally signed acknowledgement to start an SSL encrypted session.

How SSL works with example? ›

A browser or server attempts to connect to a website (i.e. a web server) secured with SSL. The browser/server requests that the web server identify itself. The web server sends the browser/server a copy of its SSL certificate. The browser/server checks to see whether or not it trusts the SSL certificate.

What is an example of SSL? ›

SSL protocol and SSL certificate

One example of sensitive data protected by SSL is financial information, such as credit card numbers. Other examples include: User login credentials. Personally identifiable information (PII).

Does HTTP need SSL? ›

Most browsers tag HTTP sites – those without SSL certificates – as "not secure." This sends a clear signal to users that the site may not be trustworthy – incentivizing businesses who have not done so to migrate to HTTPS. An SSL certificate helps to secure information such as: Login credentials.

Does HTTP require SSL? ›

HTTP does not require SSL certificates, meaning that the additional validation step that ensures a secure connection is removed. The requests require no identity, authentication, or encryption meaning that due to its stateless system design the data is sent over as soon as the request is received.

How to enable SSL in HTTP server? ›

Enable secure sockets layer (SSL) to encrypt a user's communication with the Web server. To enable SSL on your Web server, you must obtain a Web server certificate signed by a Certificate Authority and install it into your Web server.

What are the advantages of a secure HTTP? ›

With HTTPS, data is encrypted in transit in both directions: going to and coming from the origin server. The protocol keeps communications secure so that malicious parties can't observe what data is being sent. As a result usernames and passwords can't be stolen in transit when users enter them into a form.

Which HTTP method is more secure? ›

GET is less secure because the URL contains part of the data sent. On the other hand, POST is safer because the parameters are not stored in web server logs or the browser history.

What is an example of HTTP and HTTPS? ›

HTTP sends data through plain text. For example, if you were to access your bank's web page and they are using HTTP, a hacker may be able to access it and read any information that you send. This is where HTTPS comes in. Many companies have implemented HTTPS to be able to allow their users to send data securely.

Which HTTP methods are secure? ›

An HTTP method is safe if it doesn't alter the state of the server. In other words, a method is safe if it leads to a read-only operation. Several common HTTP methods are safe: GET , HEAD , or OPTIONS .

How do I secure my HTTP endpoint? ›

Conclusion
  1. Authorize users using API keys.
  2. Enforce HTTPS for all APIs, even if they appear to be trivial.
  3. Use one-way password hashing with strong encryption to protect passwords.
  4. Use rate limiting to prevent unreasonable access and block DoS attacks.
  5. Validate inputs to avoid code injection attacks.
Jan 20, 2021

Top Articles
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 6111

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.