CO3404 Distributed Systems
CO3404 - Exam Revision 4 (19-07-2026) - SQL Injection
Block 2 ā Security & Networking¶
- TLS: symmetric vs asymmetric crypto, certificates, handshake steps, what TLS actually secures (confidentiality, integrity, authentication) (CIA)
Relevant Lecture¶
Security - TLS¶
Transport Layer Security
Secure Socket Layer (SSL) was replaced by TLS, even though SSL is still referred to, its typically meaning TLS, as SSL is an outdated insecure certificate.
Focuses on the underlying principles of Transport Layer Security used to enable HTTPs enables encryption in transit to provide secure communication.
Confidentiality¶
No one other than the intended person can read the data. It is secret.
Integrity¶
It can be assured that the data has not been tampered with or corrupted.
Authenticity¶
It can be known for sure who and where the data came from.
Non-Repudiation¶
Provider cannot later claim that the data was not sent by them.
TLS provides crypto approaches that deal with most of these reassurances. However, TLS doesn't provide non-repudiation but a technique it utilises can. Furthermore, TLS enables the usage of HTTPS which enforce security of data in transit through encryption and authentication.
TLS Processes¶
TLS uses the following crypto processes:
- Hashing āļø
- MAC / HMAC āļø
- Symmetric Key Encryption āļø
- Asymmetric Key Encryption
- Digital Signature
- Key Exchange
- Digital Certificate
Base64¶
Data is a sequence of binary bits.
Binary Block (8 bits) split into 6 bit blocks then stored as bytes 4 characters in 3 bytes.
The 6 bits represent the position in the base64 alphabet where:
A = 0
d = 20
+ = 62
/ = 63
Split into 6 bit blocks.
Example¶
File of 4 bytes
110100 111111 11010 110110 000000 00 0000 <- padding
As the smallest byte sequence to fit 6 bit numbers is 24 bits or 3 bytes we need to pad a byte with zeros then indate how many types are missing from the 3 byte block. Padding the last byte with the car = A in this case.
Doesn't with work with URLs as +, / and = are in the in other things related to internet data. i.e. + is a space, and / is a url path separator.
Hashing¶
Hashing in TLS is used for Integrity.
One-way Crypto function that provide a fixed length number (also known as a digest).
Use Cases¶
- Password Protection
```SHA256 Hash Example
Password - e7cf3ef4f17c3999a94f2c6f612e8a888e5b1026878e4e19398b23bd38ec221a
Cannot be reversed but not invulnerable to rainbow tables if a common password, so a strong password must be used.
File / Message Integrity check
- File data integrity and photo steganography
#### Good Hashing Practices
- Use long complex passwords and a password manager
- Use Single sign-on
- Use Multi-Factor Authentication.
### Message Authentication Code (MAC)
MAC in TLC is used for **Integrity and Authenticity**.
Hashing is good for integrity but not for security. MAC fixes this by adding authenticity as long as the shared secret is kept secret.
HMAC is a MAC generated using a hashing function. i.e. MAC Hashing Function?
#### Sender
| Key, K |
||
Ā /
/
Message -> MAC Algorithm -> MAC
| Key, K |
||
Ā /
/
Message -> MAC Algorithm -> MAC
#### Integrity and Authenticity
if Sender MAC and Receiver MAC are equal then it this can confirm `Who` it came from and that it has not been `Tampered` with.
#### Non-Repudiation
MAC cannot confirm the original sender, therefore if the sender claims they didn't send it, there is no evidence that they did.
> The original message could of been forged by the claimer as a false accusation.
### Symmetric Key Encryption
Symmetric key encryption is used in TLS for **Confidentiality**.
AES (Advanced Encryption Standard) is the most common used symmetric key encryption. It can accommodate keys as 128, 192 and 256 bit key.
Very fast, so good for large data blocks. The *challenge* with AES is securely getting the key to the second party.
#### Sender
Plaintext -> AES-128 Algorithm -> Cipher Text
(Hello) (Secret Key ('Hello World Keys')) (VSX4d6nJc4h5joNMpWbcyA==)
|```
Plaintext -> AES-128 Algorithm -> Plaintext
(VSX4d6nJc4h5joNMpWbcyA==) (Secret Key ('Hello World Keys')) (Hello)
!!! important "Important"
The **same key** is used to encrypt as it is to decrypt.
### Asymmetric Key Encryption
Asymmetric Key Encryption in TLS focuses on **confidentiality**.
A common example of Asymmetric Key Encryption is RSA.
Asymmetric Key Encryption unlike symmetric uses a pair of complementary but different private and public key. The public key is made public.
[Key Generation Source](https://www.ecs.umass.edu/ece/koren/FaultTolerantSystems/simulator/RSA/new_page_5.htm#:~:text=Explanation%20of%20RSA-,The%20key%20generation,-%3A)
The key generation:
- Generate two large prime numbers,Ā pĀ andĀ q
- LetĀ n = pq
- LetĀ m = (p-1)(q-1)
- Choose a small numberĀ e, coprime toĀ m
- FindĀ d, such thatĀ de % m = 1
PublishĀ eĀ andĀ nĀ as the public key.
KeepĀ dĀ andĀ nĀ as the secret key.
Encryption:
C = PeĀ % n
Decryption:
P = CdĀ % n
Note:Ā PĀ stands for the plain text, andĀ CĀ stands for the cipher text.
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCDDbPnBYN2S6hnVEvKL9agQIRe
Rfpxvn0RMTqanrlrxMVd1xM9giYe36SJkIRcwHfrSqgvKfNz8u/PDj8fHe6G/6e6
FyMfhY9a34nNkkkO1yqjlywvZ7V+zE0f5XBiimxrDnNCIuz74Z8GNgrbuArn/1/V
fVb2fB+RwCQOEGA8hQIDAQAB
-----END PUBLIC KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCDDbPnBYN2S6hnVEvKL9agQIReRfpxvn0RMTqanrlrxMVd1xM9
giYe36SJkIRcwHfrSqgvKfNz8u/PDj8fHe6G/6e6FyMfhY9a34nNkkkO1yqjlywv
Z7V+zE0f5XBiimxrDnNCIuz74Z8GNgrbuArn/1/VfVb2fB+RwCQOEGA8hQIDAQAB
AoGAPlMC7mgJ1/UtFk7ZaEMN39Iu4SKIcxVzJvzxcNzxM1Y1wmXpKYQ+msoi1qUa
vX1uykAL8boSpF6xOxf8XtD+QRTkO5IVQKU78NnAdclhiRsNZPgL2HFnKKj3kaTk
ok4M9rrfC5J+qy9lS9tQLoyDEHQrMYwdlsTMb6HA4xVkajUCQQDkBXp27+JM1ODH
iKxOzmQeXLvnVaLRx9nS0DA7XnphHAraT2fLBeAcg8Jl1QDLt8SO4mMy69VmE/Gk
OnUZaYMvAkEAkyJObKsKNbWKK7TxPzarPiSvDqS6dTD4+enMDbvuZfRRMK8SzPsD
X9e2X+cNjj0Z3k/Hq7fdGOCjlPi+wRGeiwJAGW76//U12rgL8nWuMoQW6sQROXZ1
2Mxf4YHTP2wEXnyQQVWGEEExhDy2HEGr+w0eYYmi4vUnMmGbHGRg11rLhQJAbuoh
rJGTdMGRkzkn07tmg8YroSJU3Rs51UuF46SUJo9y1Pxlc9iVxp5agRkwgtVUtt31
a2GDbsmJBzgstGaP2QJABUxwuxZ1cPdav1/Uexle90HDURVqULqLwdHWp3boDsN1
GDvt1IKqYr4bmvgFvQbW0B42amXhOVtplJiKSxLhCA==
-----END RSA PRIVATE KEY-----
Plaintext -> RSA-1024 Algorithm -> CipherText
('Hello') -> (RSA-1024 Pub Key) -> (3edb092ac6a8df676ed40d9ad95596328217d6c0285aa18ab9dcb3c6be65e86d1262bf78a5ee215940d3abbb832980dfd616b5621f3c33b846d8a43f3a5823b350f0e0ceb95ea73d699584e962f9b16b817c76ddd38f39c557a1d89bf6f9da8372580973d9e2248ba49f097ddc03af81085074c347877fa420f7050eaf3fe3bc)
CipherText -> RSA-1024 Algorithm -> PlainText
(3edb092ac6a8df676ed40d9ad95596328217d6c0285aa18ab9dcb3c6be65e86d1262bf78a5ee215940d3abbb832980dfd616b5621f3c33b846d8a43f3a5823b350f0e0ceb95ea73d699584e962f9b16b817c76ddd38f39c557a1d89bf6f9da8372580973d9e2248ba49f097ddc03af81085074c347877fa420f7050eaf3fe3bc) -> (RSA-1024 Private Key) -> ('Hello World')
Problem with Asymmetric Key Encryption is that it can't be reassured where the public key came from.
Complex maths, so not useful for large data blocks.
Elliptic Curve is another popular asymmetric algorithm.
The NIST (National Institute of Standards and Technology) define crypto strength in "bits of security".
- 112 bits is good until about 2030
- Approximate equivalencies:
- 2048 bit RSA key
- 224 bit ECC key
- 128 bit AES
### Secure Key Agreement
Secure Key Agreement is **different** to *Key Exchange*.
[Diffie-Hellman](https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange) is a very popular method of `key agreement`.
Each party creates values that are exchanged and from those values, the secret keys are computed.
The 'beauty' of this method is that the secret keys are not exchanged so they cannot be intercepted and if the values which are exchanged are intercepted then they can be used to compute the original shared secret.
Instead if there is a man in the middle they would been to intercept the changes and substitute both values. Therefore, to protect against this, the server value also provides a `digital signature` so that the value can't be changed without detection.
From the exchanged values, both parties can compute the same value which is the shared secret. Although, the shared secret could be used now for encryption, generally working keys based on these shared values will be seen in further aspects of TLS.
## Summary of Basic Properties
- Symmetric keys are the same for encryption and decryption and provide confidentiality.
- Encryption and Decryption as a result is very fast
- Securely getting the key to the 2nd party is the difficulty. Diffie-Helman is a popular approach to that problem as actual keys aren't exchanged but calculated based on the exchanged data.
- AES is popular for symmetric encryption (in transit and at rest)
- Hash can be used for integrity as it is unique and a fixed length which is very sensitive to data change.
- MAC / HMAC (Hashed Message Authentication Code) used to provide security of the hash by mixing in a symmetric key so provides **Authenticity** and **Integrity**.
- Public Key Encryption - Keys are a pair and are different. Private (Secret) and Public.
- Public key used to encrypt data for **confidentiality**.
- Private key used to decrypt confidential data encrypted with public key.
- Private Key Encryption - Can be used to create Digital Signature
- Provides **integrity**, **authenticity**, and **non-repudiation**.
- Digital Signature is the equivalent to symmetric key HMAC but better as it provides *non-repudiation*.
- RSA and Elliptic Curve are popular for asymmetric encryption e.g. digital signature, and digital certificates.
---
# Digital Signature
Digital signature in TLS focuses on; **authenticity**, **integrity**, and **non-repudiation**.
It does not however allow **confidentiality**.
More secure alternative than a handwritten signature, by guaranteeing authenticity of the sender, therefore providing non-repudiation as long as the secret isn't shared for legal problems. E.g. Using HSM, or Smart Card to hold the secret key. Digital signatures also ensure integrity.
```mermaid
sequenceDiagram
participant Bob
participant Employee
Bob->>Employee: Sends Public Key
Bob->>Bob: Hashes contract to create a digest.
Bob->>Bob: Encrypts digest using his private key.
Bob->>Employee: Provides contract.csv, digest.txt
Employee->>Employee: Decrypts Digital Signature using Bob's public key to get Hash value. (No Confidentiality)
Employee->>Employee: Hash the contract file to get the digest (hash) to verify it's the same as Bob's (Integrity)
Creating a Digital Signature¶
PlainText Message -> Hash Value -> Private Key -> Digital Signature
Hashing Digital
Algorithm Signature
(MD5, SHA1, etc) Algorithm
(DSA, RSA, etc)
Digital Certificates¶
Digital certificates answer the question "Can it be verified that Bob's public key really is Bob's."
Bob creates a public key, then it gets embedded into a digital certificate by a trusted third party. i.e. CA (Certification Authority).
Bob's usage of the CA
Bob needs to provide other info including the domain the certificate will be used e.g. bob.com. This is checked by the CA
Certificate Authority¶
The CA then adds bob's public key and his domain then signs the certificate with its own digital signature to validate it.
When using Bob's public key, the certificate is requested.
The CA certificate can be checked using the CA public key, and if that is fine, then it is reassured that Bob's public key is trustworthy and from its origin source, so therefore it can be extracted and used from the certificate.
In HTTPs Bob would store his certificate on the server that is used to provide a service at the certified domain.
For practical purposes there is more than one CA in the world, and the CA can delegate authority to intermediate CAs to make the process more manageable, thus creating a chain of trust.
Root Certificates¶
A root certificate is self-signed as it must start somewhere. The CA digitally signs its certificate using its secret key. Root certificate authorities are known and trusted by most browsers and installed in OS and the browser during updates.
Intermediate Certificates¶
These can be created from the root and used by delegated organisations to sign user certificates. The lineage of certificate signing is held in the certificate. Having just a root CA is limiting in that it could be a bottleneck in providing certificates to others, and if its secret key is compromised then all its certifications are worthless so intermediates are where the certification should tend to be obtained from.
Info
Intermediate certs and your cert should be installed on the server. The Root cert should be on the client in the OS trusted store
How to get a Certified Digital Certification¶
- Need to make a
Certification Signing Request (CSR) - X.509 is the most common standard
- Name - Generally host name of the server wanting tom be used e.g. yourdomain.com
- Organisation - If relevant. This can be verified by the CA if it is registered.
- Division within Organisation - If relevant
-
City, State/Country, Email Address - May be used to contract on this.
-
Need to provide verifiable details:
- Depending on the type of certification may need to check domain name provider, your payment provider, email, phone, etc
- Extended Validation (EV) - Legal Business Name, Jurisdiction of Incorporation, Registration Number etc.
- Organisational Validation (OV) - Organisation details such as verified name.
-
Domain Validation (DV) - Simply providing the domain is owned by the enquiring user.
-
You create public / private key pair
- Keep the private key secure and private
- Public key will be sent to CA in the CSR and will be embedded in the signed certificate
Creating a Simple DV Certification¶
- Domain Validation Certifications are very popular
- MKCert is a useful app from mkcert.org
- MKCert creates a CA on the client machine which enables the creation of own certifications
- MKCert adds itself to the secure vault in the trusted CAs in your OS so any certifications created form it and deployed to your server are trusted.
- Useful for quick SSH testing. Can use an IP with it in the domain registration
- The certs won't be trusted by anyone else's browser so it's good for development and learning
Info
Get the app (Window): winget install mkcert
Once we have a CA trusted by our browsers we can create our own certificates
mkcert -key-file key.pem -cert-file cert.pem domain
this will create key.pem and cert.pem in the current directory.
Domain needs to be localhost,
20.117.114.49or wherever you
will use the cert. The browser can check the IP it called and compare to this value
If you want to look at the cert in a readable form:
certutil -decode cert.pem(on Windows)Check the X509v3 Subject Alternative Name: IP Address: 20.117.114.49 or wherever, is correct if you are having problems
We don't add certs into the container, or each container needs one and the secret key is in the image on Docker hub
Creating a let's encrypt real cert¶
Cannot create a let's encrypt cert using an IP address - you need a domain name
You install certbot on your server then using it in a single command it will:
ā¹ Send a server to let's encrypt (LE) server POST request with the domain name you want to register
ā¹ Server receives a token from LE - basically a random string - this is a challenge step
ā¹ Server POSTS back the token and a hash of the public key as a response to the challenge
ā¹ Server POSTS a "Please validate the challenge" to LE
ā¹ LE makes a get request to a web server on your server (typically port 80) asking for the token to check it matches
ā¹ If it matches, certbot creates a key pair and a CSR containing the public key, domain names, and a digital signature proving
ownership of the private key associated to the public key in the CSR and server sends it to LE
ā¹ LE creates and returns cert.pem, chain.pem (the intermediate cert) and chain.pem (both in one file). We tend to use this one
All that is done for you but you should know the sequence of events behind it:
āø It does create a CSR and it is stored on your server but you never see it unless you look for it
āø If use digicert or similar, you create a CSR on their web page, add your public key and they send you the certs
CO3404 - Exam Revision 6 (30-07-2026) - Baston Hosts & Authentication-Authorisation