Datasäkerhet och integritet Utveckling av eTjänster
Datasäkerhet och integritet
Chapter 3
•
Kryptering
•
Hashing
•
Digitala signaturer
•
Certifikat & PKI
•
Säker kommunikation
What is cryptography?
•
Cryptography is the use of mathematical
operations to protect messages traveling between
parties or stored on a computer
•
Confidentiality means that someone intercepting
your communications cannot read them
Cryptography och CIA
• Confidentiality is only one cryptographic protection
• Integrity means that the message cannot be changed or, if it is change, that this change will be detected
• Availability or Authentication means proving one’s identity to another so they can trust you more
• Encryption for confidentiality needs a cipher (mathematical method) to encrypt and decrypt
– The cipher standard cannot be kept secret
• The two parties using the cipher also need to know a secret key or keys
– A key is merely a long stream of bits (1s and 0s) – The key or keys must be kept secret
Kryptering taxonomi
CIA-Hemlig
nyckel
(tex. DES)
Autentisering Meddelande
integritet
Hemlighets-
hållande
Message
diggest
(tex. MD5)
Publik
nyckel
(tex. RSA)
Säkerhet
Säkerhets-
tjänster
Krypterings-
Kryptering och dekryptering
•
Meddelandet i ”cleartext” omvandlas till oläsbar
”ciphertext” med hjälp av krypteringssystem och nyckel
•
Dekryptering reverserar förloppet med rätt nyckel
•
Exempel på enkla krypteringsalgoritmer
– Rövarspråket
• Efter varje konsonant lägger man till ett ”o” och samma konsonant
igen, exempel: Hej -> Hohejoj
– Ceasarrullning eller ROT(n)
• Varje bokstav i meddelandet flyttas ett fixt antal steg (n) framåt,
exempel med fyrstegsrullning: HEMLIG -> LIQPMK
•
Det finns i huvudsak två olika krypteringsmetoder
Symmetrisk kryptering
och dekryptering
• Vid symmetrisk kryptering används samma krypteringsalgoritm och (privata/hemliga) nyckel av sändare och mottagare
• Används oftast då säkerhetskraven är mycket höga • Nackdelen är säker
skötsel av nycklar i ett distribuerat
system
• Det finns två typer av symmetrisk
kryptering
Types of Ciphers
•
Substitution Ciphers
– Substitute one letter (or bit) for another in each place as ROT(n)
•
Transposition Ciphers
– Transposition ciphers do not
change individual letters or bits, but they change their order
•
Example for plaintext “nowisthet”
•
The cipher text in col/row (1/1,
1/2, 1/3, 2/1, …) order is hnit …
• Applying the col key backwards on the new matrix using a reversed row key decipher the cipher text
Key (Part 1)
Key (Part 2) 1 3 2
1 h n i
3 t w t
2 e o s
Key (Part 1)
Key (Part 2) 1 3 2
2 n o w
3 i s t
1 h e t
Key = 132 231
Plain
Ciphers versus Codes
•
Ciphers can encrypt any message
expressed in binary (1s and 0s)
– This flexibility and the speed of computing makes ciphers dominant for encryption today
•
Codes are more specialized
– They substitute one thing for another
– Usually a word for another word or a number for a word
– Codes are good for humans and may be included in messages sent via encipherment
Message Code From 17434 Akagi 63717 To 83971 Truk 11131 STOP 34058 ETA 53764
6 PM 73104
Symmetrisk kryptering och
dekryptering
•
Block chiffer
–
Meddelandet delas upp i fixerade block av bitar
som behandlas i olika substitutions boxar
–
Om längden på data är mindre än blocklängden
måste man ”padda” (fylla i) data
–
Implementeras mest i mjukvara
• AES, Advanced Encryption Standard • DES, Digital Encryption Standard • 3DES (tripple DES)
• RC5, RC6
• Blowfish, Twofish
Symmetrisk kryptering och
dekryptering
•
Ström chiffer
– Behandlar meddelandet som en ström av bitar/bytes och gör matematiska funktioner för dem individuellt
– Används när längden på sändningen av data inte är känd, t.ex. i trådlösa tillämpningar
– Implementeras oftast i hårdvara • Exempel är t.ex. RC4, A5/1
•
Attacken för att knäcka båda metoderna är ”brute
force” (om algoritmen är bra)
– Pröva dekrypteringsnycklar tills output är läsbar
– Generellt gäller att en längre nyckel gör det svårare att knäcka krypteringen (precis som för ett lösenord)
Symmetrisk kryptering och dekryptering
RC4 Ström chiffer
– Ron Rivest•
Tidigare använd i trådlösa
nätverk (WEP)
– TLS/SSL
•
Populärt därför att det är
– Snabbt
– Enkelt att implementera – Svårt att attackera
•
Algoritmen använder nyckeln
för att generera ett slumptal,
vilket är exklusivt OR:at med
cleartexten för att producera
ciphertexten
• ClearT = 1011, key = 1001 • ClearT XOR key = 0010
• Decrypt
12
Key Length and
Exhaustive Search Time
Key Length in Bits
Number of Possible Keys
1 2 2 4 4 16 8 256 16 65,536 40 1,099,511,627,776 56 72,057,594,037,927,900 112 5,192,296,858,534,830,000,000,000,000,000,000 112 5.1923E+33 168 3.74144E+50 256 1.15792E+77
Each extra bit
doubles the
number of keys
Each extra bit
doubles the
number of keys
Shaded keys are
Strong symmetric
Entropy (password entropy)
• Measuring password strength (disorder)
• For a completely random password, each character is worth approximately 6.56 bits
• With a user-chosen, first sign give 4 bits, characters 2-8 gives 2 bits, characters 9-20 gives 1.5 and 21-... provides 1 bit per character
• Entropy (bits) table for various lengths of passwords
• The number of variations for a password is 2^(number of bits)
• However (number of possible characters)^(number of characters) is basically flawed because a short passwords can be complex and long passwords can be of an easily guessable character
2^6,56=95
User-choosen
(according to rules) Length (chars)
User-choosen (freely choosen)
Major Symmetric Key Encryption Ciphers
RC4 DES 3DES AES
Key Length (bits)
40 bits or more
56 112 or 168 128, 192, or 256
Key Strength Very weak
at 40 bits Weak Strong Strong
Processing Requirements
Low Moderate High Low
RAM
Requirements
Low Moderate Moderate Low
Remarks Can use
keys of variable
length
Created in
Stage 1: Selecting methods and parameters
Cipher Suite Key
Negotiation DigitalSignature Method Symmetric Key Encryption Method Hashing Method for HMAC Strength
NULL_WITH_NULL_NULL None None None None None
RSA_EXPORT_WITH_
RC4_40_MD5 RSAexport
strength (40 bits) RSA export strength (40 bits) RC4 (40-bit
key) MD5 Weak
RSA_WITH_DES_CBC_ SHA
RSA RSA DES_CBC SHA-1 Stronger
but not very strong DH_DSS_WITH_3DES_ EDE_CBC_SHA Diffie-Hellman Digital Signature Standard 3DES_ EDE_CBC SHA-1 Strong RSA_WITH_AES_256_CBC
Stage 2: Authentication
1. Selecting methods and parameters (prev. slide)
2. Authentication: Supplicant, Verifier, and Credentials
3. Keying (the secure exchange of secrets)
Hashing
•
A hashing algorithm is applied to a bit string of any length
•
The result of the calculation is called the hash
•
For a given hashing algorithm, all hashes are the same short
length
•
Det är mycket
osannolikt att två
olika input (strängar)
ska ge samma
Hashing
•
Hashing Algorithms
– MD5 (128-bit hashes) – SHA-1 (160-bit hashes)
– SHA-224, SHA-256, SHA-384, and SHA-512 (name gives hash length in bits)
•
Hashing versus Encryption
Characteristic Encryption Hashing
Result length About the same length
as the plaintext Short fixed length regardless of message length
Reversible? Yes. Decryption No. There is no way to get from the short hash back to the long original message
MD (Message Digest) hashalgoritmer
•
Ex: MD5, SHA-X (Secure Hash Algorithm)
•
Används främst för att kontrollera integriteten med
en checksumma av ett meddelande M
– Ej modifierad eller förvanskat på resan
•
Message digest 5 implementeras som en 128 bitars
en-vägs hash-funktion H(M)
•
Enkelt att beräkna H(M) men mycket svårt att
bestämma M så att H(M) = h för given kod h
•
MD5 representeras oftast med 32 hexadecimala tal
(128 bitar)
•
MD5("The quick brown fox jumps over the lazy dog")
Stage 3: Keying (the secure
exchange of secrets)
•
Public Key Encryption for Confidentiality
•
There are two types of ciphers used for confidentiality
•
In symmetric key encryption for confidentiality, the
two sides use the same key
– For each dialogue (session), a new symmetric key is generated: the symmetric session key
•
In public key encryption, each party has a public key
and a private key that are never changed
Asymmetrisk (publik) kryptering och
dekryptering
• Två olika nycklar används för kryptering och dekryptering – Den privata nyckeln är hemlig
– Den publika nyckeln kan läsas av vem som helst
• Funktionen är möjlig tack vare att det alltid finns ett nyckelpar som matchar varandra
– Irrelevant i vilken ordning eller med vilken nyckel kryptering och
dekryptering sker
– Samma nyckel kan inte kryptera och dekryptera i nyckelparet
– Meddelanden som t.ex. krypterats med en publik nyckel kan endast
dekrypteras med den matchande privata nyckeln
Asymmetrisk (publik) kryptering och
dekryptering
•
Iom. att publik kryptering är långsamt i jämförelse mot
privat kryptering brukar man ofta endast kryptera en
symmetrisk nyckel som kallas för ”sessions nyckel”,
vilken används för att dekryptera meddelandet
•
Attacken är matematisk - faktorering av stora tal
– Bryt ner ett heltal i dess faktorer, t.ex. 15 = 5 och 3
– Faktorerna måste vara primtal, enkelt för små tal men otroligt svårt för stora (kallas NP-kompletta i matematiken, ingen
lösning utom att prova alla kombinationer)
•
Militärt värde
– Exportrestriktioner råder t.ex. från USA. Max 40 bits symmetrisk och 512 bitar assymetrisk
Asymmetrisk (publik) kryptering och
dekryptering exempel 1
Bob
Bob har fått två nycklar. En kallas för Public Key (grön), den andra Private Key (röd)
Vemsomhelst kan få Bobs publika nyckel, men den privata behåller han själv
Båda Bobs nycklar kan kryptera data och den ena nyckeln kan dekryptera vad den andra nyckeln skrev för data och vice versa
Asymmetrisk (publik) kryptering och
dekryptering exempel 2
Alice
Alice kan kryptera ett meddelande till Bob med sin publika nyckel hon fått från Bob
Vemsomhelst kan få tillgång till Alices krypterade meddelande, men meddelandet är värdelöst utan Bobs privata nyckel
Bob
Hej Bob! Vad sägs om en öl på krogen i kväll? Det är happy hour hela
natten! HNFmsEm6Un BejhhyCGKOK JUxhiygSBCEiC 0QYIh/Hn3xgiK HNFmsEm6Un BejhhyCGKOK JUxhiygSBCEiC 0QYIh/Hn3xgiK
Hej Bob! Vad sägs om en öl på krogen i kväll? Det är happy hour hela
Asymmetrisk kryptering och
dekryptering, algoritmer
•
RSA algoritmen (Rivest, Shamir, Adleman, 1978)
PKCS#3 – Välj två stora primtal (bara delbara med 1) P och Q. Hitta derasprodukt n = PQ
– Beräkna x = (P-1)(Q-1)
– Välj ett relativt prima (gemensam nämnare med x som är 1) tal
e mindre än x och större än 1. Formeln blir då: d = 1/e mod x där e är den publika och d den privata exponenten.
– Den publika nyckeln är paret n och e och den privata nyckeln är paret n och d. Faktorerna P och Q måste hållas hemliga eller förstöras
•
DSA algoritmen (Digital Signature Algorithm, 1991)
– US Federal Goverment standard
RSA exempel
modulo ger resten vid en heltalsdivision, ex 5 mod 4 = 1
p = 5
- Första primtalet (förvaras säkert eller raderas)
q = 11
- Andra primtalet (förvaras säkert eller raderas)
n = p*q = 55
- modulo (blir publik & privat)
x = (p-1)*(q-1) = 40
e = 7, talet måste ha endast en gemensam nämnare med x som är 1
- publik exponent (blir publik)
Vi beräknar d = 1/e mod x
7*d mod 40 = 1 => d = 23 (7*23/40=1)
- privat exponent (förvaras hemligt)
• Den publika nyckeln är (e, n) och den privata nyckeln är (d, n).
Krypteringsfunktionen är:
– encrypt(m) = m^e mod n => m^7 mod 55 - där m är ”plaintext” och m < n.
• Dekrypteringsfunktionen är:
– decrypt(c) = c^d mod n => c^23 mod 55 - där c är ”ciphertext”.
• För att kryptera plain-text värdet 8, beräknar vi
– encrypt(8) =
8^7 mod 55 =
2097152 mod 55 = 2
• För att dekryptera chiffertext värdet 2, beräknar vi
– decrypt(2) =
2^23 mod 55 =
Elleptic Curve Cryptography (ECC)
• An approach to public-key cryptography
based on the algebraic structure of elliptic curves over finite fields
• An elliptic curve is a plane curve over a finite field
which consists of the points satisfying the equation
http://en.wikipedia.org/wiki/Elliptic_curve_cryptography
Galois field
Keying Using Diffie-Hellman Key Agreement
1. The two parties exchange parameters p and g
2-3. Each uses a number that is never shared explicitly to compute a second number 4. Each sends the other their second number
5. Each does another computation on the second computed number
6. Both get the third number, which is the key
All of this communication is sent in the clear
The gory
details
The gory
Ongoing Communication
•
Consumes nearly all of the dialogues
•
Message-by-Message Encryption
–
Nearly always uses symmetric key encryption
–
Already covered
–
Public key encryption is too inefficient
•
Message-by-Message Authentication
–
Digital signatures
–
Message Authentication Codes (MACs)
Digital Signature for
Message-by-Message Authentication 1
Encryption is done to protect the
plaintext.
It is not needed for
message-by-message authentication. Encryption is done
to protect the plaintext.
It is not needed for
Finding the True Party’s Public Key
• Cannot use the sender’s public key
– It would always “validate” the sender’s digital signature
• Normally requires a digital certificate
– File provided by a trustworthy certificate authority (CA)
• Digital certificate provides the subject’s (True Party’s) name and public key
• Don’t confuse digital signatures and the digital certificates used to test digital signatures!
Encryption Goal Sender Encrypts with Receiver Decrypts with
Public Key Encryption for
Confidentiality The receiver’s public key The receiver’s private key Public Key Encryption for
Authentication The sender’s private key The (not the True Party’s sender’s public keypublic key)
Point of frequent confusion
X.509 Digital Certificate Fields 1
Field Description
Version
Number Version number of the X.509 standard. Most certificates follow Version 3. Different versions have different fields. This figure reflects the Version 3 standard.
Issuer Name of the Certificate Authority (CA). Serial
Number
Unique serial number for the certificate, set by the CA.
Subject
(True Party) The name of the person, organization, computer, or program to which the certificate has been issued. This is the true party.
Public Key The public key of the subject (the true party). Public Key
Algorithm
The algorithm the subject uses to sign messages with digital signatures.
Certificate provides the Certificate provides the
Serial number allows the receiver to check if the digital certificate
has been revoked by the CA. Serial number allows the receiver
X.509 Digital Certificate Fields 2
Field Description
Digital Signature
The digital signature of the certificate, signed by the CA with the CA’s own private key.
For testing certificate authentication and integrity. User must know the CA’s public key independently.
Signature Algorithm Identifier
The digital signature algorithm the CA uses to sign its certificates.
Other Fields … The CA signs the cert with its own
private key so that the cert’s validity can be checked for alterations.
The CA signs the cert with its own private key so that the cert’s validity can
Verifying the Digital Certificate 1
•
Testing the Digital Signature
– The digital certificate has a digital signature of its own – Signed with the Certificate Authority’s (CA’s) private key – Must be tested with the CA’s well-known public key
– If the test works, the certificate is authentic and unmodified
•
Checking the Valid Period
– Certificate is valid only during the valid period in the digital certificate (not shown in the figure)
Verifying the Digital Certificate 2
•
Checking for Revocation
– Certificates may be revoked for improper behavior or other reasons
– Revocation must be tested
– Cannot be done by looking at fields within the certificate – Receiver must check with the CA
– Verifier may download the entire certificate revocation list from the CA
– See if the serial number is on the certificate revocation list – If so, do not accept the certificate
– Or the verifier may send a query to the CA
Message-by-Message
Authentication
•
Also Brings Message Integrity
– If the message has been altered, the authentication method will fail automatically
•
Digital Signature Authentication
– Uses public key encryption for authentication
– Very strong but use extensive processing power, also expensive and difficult to set up
•
Key-Hashed Message Authentication Codes
– An alternate authentication method using hashing
– Much less expensive than digital signature authentication and use less processing power == faster
Key-Hashed Message Authentication Code
(HMAC) 2
As in the case of digital signatures, confidentiality is done to protect the plaintext. It is not needed for authentication and has nothing to do with authentication. As in the case of digital signatures, confidentiality is done to protect the plaintext.
Nonrepudiation
• Nonrepudiation means that the sender cannot deny that he or she sent a message
• With digital signatures, the sender must use his or her private key – It is difficult to repudiate that you sent something if you use your
private key
• With HMACs, both parties know the key used to create the HMAC – The sender can repudiate the message, claiming that the receiver
created it
•
Packet-level nonrepudiation is unimportant in most cases
– The application message - an e-mail message, a contract, etc. is the
important thing
– If the application layer message has its own digital signature, you have
Replay Attacks and Defenses
•
Replay Attacks
– Capture and then retransmit an encrypted message later
– May have a desired effect - even if the attacker cannot read the message
•
Thwarting Replay Attacks
– Time stamps to ensure freshness of each message
– Sequence numbers so that repeated messages can be detected – Nonces
• Unique randomly generated number placed in each request
message
• Reflected in the response message
Core Cryptographic Processes
Confidentiality Authentication Symmetric Key
Encryption Applicable. Sender encrypts with key shared with the receiver.
Not applicable.
Public Key
Encryption Applicable. Sender encrypts with receiver’s public key. Receiver decrypts with the receiver’s own private key.
Applicable. Sender (supplicant) encrypts with own private key. Receiver (verifier) decrypts with the public key of the true party, usually obtained from the true party’s digital certificate.
Hashing Not applicable. Applicable. Used in MS-CHAP for initial authentication and in
Quantum Security
• Quantum Mechanics
– Describes the behavior of fundamental particles – Complex and even weird results
• Quantum Key Distribution
– Transmits a very long key - as long as the message – This is a one-time key that will not be used again
– A one-time key as long as a message cannot be cracked by
cryptanalysis
– If an interceptor reads part of the key in transit, this will be
immediately apparent to the sender and receiver
• Quantum Key Cracking
– Tests many keys simultaneously
– If quantum key cracking becomes capable of working on long keys,
Cryptographic Systems
Host-to-Host SSL/TLS VPN
IP Security (IPsec) versus
SSL/TLS
SSL/TLS IPsec
Cryptographic security standard Yes Yes Cryptographic security protections Good Gold
Standard
Supports central management No Yes
Complexity and expense Lower Higher
Layer of operation Transport Internet
Transparently protects all higher-layer traffic
No Yes
Works with IPv4 and IPv6 NA Yes
Modes of operation NA Transport,
IPsec Operation: Transport Mode
1. End-to-End Security (Good) 1. End-to-End Security (Good) 2. Security in Site Network 2. Security in Site Network 3. Setup Cost On Each Host3.
IPsec Operation: Tunnel Mode
2.
No Security in Site Network
(Bad) 2.
No Security in Site Network
(Bad)
3.
No Setup Cost On Each Host
(Good) 3.
No Setup Cost On Each Host
Comparing IPsec Transport and
Tunnel Modes
Characteristic Transport Mode Tunnel Mode
Uses an IPsec VPN Gateway? No Yes
Cryptographic Protection All the way from the source host to the destination host, including the Internet and the two site networks.
Only over the Internet between the IPsec gateways. Not within the two site networks.
Setup Costs High. Setup requires the creation of a digital certificate for each client and significant
configuration work.
Low. Only the IPsec gateways must implement IPsec, so only they need digital certificates and need to be configured.
Firewall Friendliness Bad. A firewall at the border to a site cannot filter packets because the content is encrypted.
Good. Each packet is decrypted by the IPsec gateway. A border firewall after the IPsec gateway can filter the decrypted packet.
PKI (Public Key Infrastructure)
•
Lösning eller falsk säkerhet?
•
PKI är en infrastruktur som möjliggör
–
Stark autentisering – lösenord + certifikat
–
Säker e-post – signering/kryptering + certifikat
–
Digitala signaturer
–
Säker fjärråtkomst
–
Filkryptering
–
Kodsignering – säkra tjänster på www
–
Informationsintegritet och Upphovsrättskydd
–
Säkra webbserveruppkopplingar
–
Aktiva kort - lagring av certifikat
PKI grundsten och komponter
•
Baseras på förtroende/tillit mellan kund och
utgivare CA (Certification Authority)
–
Risker med detta?
•
PKI-komponeter
–
CA (Certification Authority)
–
RA (Registration Authority)
–
Certifikat/PKI-server
–
Certifikatlager (Certificate Repository)
Upprätthålla PKI, aktiva kort
•
Hur länge skall ett certifikat gälla?
•
När skall certifikat återkallas?
•
CRL (Certificate Revocation List)
•
Idag är aktiva kort mycket vanliga
–
SIM-kort, bankautomatkort etc.
•
PC/SC (Personal Computer/Smart Card)
–
PKI på det aktiva kortet
–
Samverka med applikationer via cryptoAPI
•
Omfattande arbete innan PKI kan införas i en
Behov av säker e-post?
•
Vykort!?
•
E-post används till all typ av information
– Reseräkningar, internbeställningar – Kärlekstjafs
– Viktig kommunikation med kunder/leverantörer
•
Problem
– E-post är store-and-forward, och går underliga vägar (hoppar mellan servrar)
– Forwardering av mail från företagskonto till Hotmail – Feladressering
MIME (Multipurpose Internet Mail Extensions)
• Internet Standard för formatet på e-post, kallas ibland för SMTP/MIME
• e-post sänds med protokollet SMTP som endast stödjer 7-bits ASCII
• MIME definierar mekanismer för att sända e-post med andra språk och inkluderade bilagor av alla slag
• Används också för att kunna sända viss data inbäddat i andra protokoll, t.ex. av HTTP (MIME types)
• ”Transfer encodings” definierar hur man representerar 8-bits binär data med 7-bits ASCII
PGP/MIME & OpenPGP
http://www.bretschneidernet.de/tips/secmua.html
•
PGP (Pretty Good Privacy)
– Phil Zimmerman 1991
– Privat nyckel på hemlig nyckelring
– Bygger på ”web of trust”, personliga förhållanden (tillit) • www.thawte.com har kommersiell tjänst för detta
– PGP blev kommersiellt kring 1996
•
OpenPGP & GnuPG (Gnu Privacy Guard)
•
PGP/MIME för att kryptera hela meddelandet
byggde på
– RFC 1991, PGP Message Exchange Formats
– RFC 2015, MIME Security with Pretty Good Privacy
•
Nu gäller
PGP/MIME & Secure (S/MIME) Vx
• Är en standard baserad på MIME och utvecklad av RSA Data Security Inc. för att sända säker e-post
• Certifikatbaserad = behöver PKI (denna kan dock vara enkel) • S/MIME är likt OpenPGP och det äldre PGP/MIME (i stort sett
samma funktioner som nedan) men inkompatibelt med dessa • Signerad e-post i S/MIME formatet innehåller en signaturbilaga
i PKCS#7-formatet samt en hash från originalmeddelandet signerat med sändarens privata nyckel och sändarens certifikat • Krypterad e-post genereras med mottagarens publika nyckel
– Meddelandet krypteras dock först med en symmetrisk nyckel,
denna nyckel krypteras också i sin tur med mottagarens publika nyckel och sänds med meddelandet
– Om meddelandet sänds till flera mottagare så krypteras den
symmetriska nyckeln separat av alla mottagares publika nyckel