Programming with cryptography

Similar documents
Overview of CSS SSL. SSL Cryptography Overview CHAPTER

Communication Security for Applications

Overview. SSL Cryptography Overview CHAPTER 1

Communication Systems SSL

Lecture 9: Application of Cryptography

Communication Systems 16 th lecture. Chair of Communication Systems Department of Applied Sciences University of Freiburg 2009

CS 356 Lecture 27 Internet Security Protocols. Spring 2013

Lecture 31 SSL. SSL: Secure Socket Layer. History SSL SSL. Security April 13, 2005

TLS/SSL in distributed systems. Eugen Babinciuc

Announcement. Final exam: Wed, June 9, 9:30-11:18 Scope: materials after RSA (but you need to know RSA) Open books, open notes. Calculators allowed.

Chapter 17. Transport-Level Security

Web Security Considerations

Savitribai Phule Pune University

How To Understand And Understand The Ssl Protocol ( And Its Security Features (Protocol)

Managing and Securing Computer Networks. Guy Leduc. Chapter 4: Securing TCP. connections. connections. Chapter goals: security in practice:

Authenticity of Public Keys

Software Engineering 4C03 Research Project. An Overview of Secure Transmission on the World Wide Web. Sean MacDonald

Real-Time Communication Security: SSL/TLS. Guevara Noubir CSU610

Security Engineering Part III Network Security. Security Protocols (I): SSL/TLS

CSC 474 Information Systems Security

Network Security Web Security and SSL/TLS. Angelos Keromytis Columbia University

CSC Network Security

Outline. Transport Layer Security (TLS) Security Protocols (bmevihim132)

Cryptography and Network Security Sicurezza delle reti e dei sistemi informatici SSL/TSL

Using etoken for SSL Web Authentication. SSL V3.0 Overview

Secure Socket Layer (SSL) and Trnasport Layer Security (TLS)

Chapter 10. Network Security

IT Networks & Security CERT Luncheon Series: Cryptography

3.2: Transport Layer: SSL/TLS Secure Socket Layer (SSL) Transport Layer Security (TLS) Protocol

Overview of SSL. Outline. CSC/ECE 574 Computer and Network Security. Reminder: What Layer? Protocols. SSL Architecture

ISA 562 Information System Security

Lecture 7: Transport Level Security SSL/TLS. Course Admin

Network Security. Gaurav Naik Gus Anderson. College of Engineering. Drexel University, Philadelphia, PA. Drexel University. College of Engineering

Secure Sockets Layer

CRYPTOGRAPHY IN NETWORK SECURITY

Protocol Rollback and Network Security

Web Security. Mahalingam Ramkumar

Transport Layer Security Protocols

Secure Sockets Layer (SSL ) / Transport Layer Security (TLS) Network Security Products S31213

SSL Secure Socket Layer

CIS 6930 Emerging Topics in Network Security. Topic 2. Network Security Primitives

SSL Secure Socket Layer

Secure Socket Layer (TLS) Carlo U. Nicola, SGI FHNW With extracts from publications of : William Stallings.

Lukasz Pater CMMS Administrator and Developer

SECURE SOCKETS LAYER (SSL)

Introduction to Cryptography

Learning Network Security with SSL The OpenSSL Way

Binding Security Tokens to TLS Channels. A. Langley, Google Inc. D. Balfanz, Google Inc. A. Popov, Microsoft Corp.

HTTPS: Transport-Layer Security (TLS), aka Secure Sockets Layer (SSL)

SECURE SOCKET LAYER PROTOCOL SIMULATION IN JAVA. A Research Project NAGENDRA KARRI

Information Security

Secure Socket Layer. Carlo U. Nicola, SGI FHNW With extracts from publications of : William Stallings.

The Secure Sockets Layer (SSL)

Practical Invalid Curve Attacks on TLS-ECDH

Low-Level TLS Hacking

Certificates and network security

Digital Certificates (Public Key Infrastructure) Reshma Afshar Indiana State University

An Introduction to Cryptography as Applied to the Smart Grid

SBClient SSL. Ehab AbuShmais

Secure Socket Layer (SSL) and Transport Layer Security (TLS)

Network Security (2) CPSC 441 Department of Computer Science University of Calgary

Chapter 7: Network security

Security Protocols and Infrastructures. h_da, Winter Term 2011/2012

Revisiting SSL/TLS Implementations: New Bleichenbacher Side Channels and Attacks

MatrixSSL Developer s Guide

Secure Socket Layer. Security Threat Classifications

Cryptography & Digital Signatures

Lecture 9 - Network Security TDTS (ht1)

CRYPTOGRAPHY 456 ANDROID SECURE FILE TRANSFER W/ SSL

SSL/TLS. What Layer? History. SSL vs. IPsec. SSL Architecture. SSL Architecture. IT443 Network Security Administration Instructor: Bo Sheng

SSL: Secure Socket Layer

Common security requirements Basic security tools. Example. Secret-key cryptography Public-key cryptography. Online shopping with Amazon

qwertyuiopasdfghjklzxcvbnmqwertyui opasdfghjklzxcvbnmqwertyuiopasdfgh jklzxcvbnmqwertyuiopasdfghjklzxcvb

Web Application Entity Session Management using the eid Card Frank Cornelis 03/03/2010. Fedict All rights reserved

Network Security. Computer Networking Lecture 08. March 19, HKU SPACE Community College. HKU SPACE CC CN Lecture 08 1/23

Entrust Managed Services PKI. Getting started with digital certificates and Entrust Managed Services PKI. Document issue: 1.0

Chapter 7 Transport-Level Security

2. Cryptography 2.4 Digital Signatures

Network Security. Abusayeed Saifullah. CS 5600 Computer Networks. These slides are adapted from Kurose and Ross 8-1

Network Security [2] Plain text Encryption algorithm Public and private key pair Cipher text Decryption algorithm. See next slide

Network Security Part II: Standards

Lecture 4: Transport Layer Security (secure Socket Layer)

Security Protocols/Standards

Understanding Digital Certificates and Secure Sockets Layer (SSL)

Cryptosystems. Bob wants to send a message M to Alice. Symmetric ciphers: Bob and Alice both share a secret key, K.

AWS Encryption SDK. Developer Guide

Security. Learning Objectives. This module will help you...

Client Server Registration Protocol

Hash Functions. Integrity checks

Network Security Essentials Chapter 5

mod_ssl Cryptographic Techniques

What is network security?

Some solutions commonly used in order to guarantee a certain level of safety and security are:

Computer and Network Security

Today s Topics SSL/TLS. Certification Authorities VPN. Server Certificates Client Certificates. Trust Registration Authorities

CSCE 465 Computer & Network Security

The Beautiful Features of SSL And Why You Want to Use Them?

Security. Contents. S Wireless Personal, Local, Metropolitan, and Wide Area Networks 1

Chapter 8 Security. IC322 Fall Computer Networking: A Top Down Approach. 6 th edition Jim Kurose, Keith Ross Addison-Wesley March 2012

Transcription:

Programming with cryptography Chapter 11: Building Secure Software Lars-Helge Netland larshn@ii.uib.no 10.10.2005 INF329: Utvikling av sikre applikasjoner

Overview Intro: The importance of cryptography The fundamental theorem of cryptography Available cryptographic libraries Java code examples One-time pads Summary 2

Intro Cryptography kryptos (=hidden) graphein (=to write) Layman description: the science of encrypting and decrypting text 3

The Code Book Simon Singh Highly accessible introduction to cryptography Retails at $10 (free at public libraries) Includes crypto challenges 4

Crypto: Why is it important?(i) Basic services: confidentiality encrypted text only viewable by the intended recipient integrity assurance to the involved parties that the text was not tampered with in transit authentication proof of a binding of an identity to an identification tag (often involves trusted third parties) 5

Crypto: Why is it important?(ii) Basic services (continued) authorization restricting access to resources (often involves authentication) digital signatures electronic equivalent of hand-written signatures non-repudiation 6

The fundamental theorem of cryptography Do NOT develop your own cryptographic primitives or protocols The history of cryptography repeatedly shows how secure systems have been broken due to unknown vulnerabilities in the design If you really have to: PUBLISH the algorithm 7

Examples on how ciphers have been broken Early substitution ciphers broken by exploiting the relative frequency of letters WW2: The enigma machine SHA-1: Wang 8

Overview of cryptographic libraries Cryptlib OpenSSL Crypto++ BSAFE Cryptix Bouncy Castle 9

Cryptlib http://www.cs.auckland.ac.nz/~pgut001/ cryptlib/ Very easy to use Free for non-commercial use Extensively documented, robust, well-written and highly efficient 10

OpenSSL http://www.openssl.org Free software license Serious lack of documentation Not for the faint of heart: hard to use 11

Crypto++ http://www.eskimo.com/~weidai/ cryptlib.html Includes all the significant cryptographic algorithms Almost completely undocumented Use requires a good understanding of C++ Free for any use 12

BSAFE http://www.rsasecurity.com Most widely deployed commercial library available Pricing information not available Extremely efficient and of high quality 13

Cryptix http://www.cryptix.org Cryptographic package for Java Notoriously difficult to use Inadequate documentation and highly complex to use Free sofware 14

Bouncy Castle http://www.bouncycastle.org nice crypto extensions to Java very poorly documented lightweight API for J2ME; cell phones free! efficiency?? 15

Cryptography in Java (I) Cryptographic services are realized through engine classes an engine class is an abstraction of a particular cryptographic concept e.g., the signature engine encapsulates functionality to manage digital signatures each engine has a corresponding Java class with the same name 16

Cryptography in Java (II) Engines are instantiated through its static getinstance(string algorithm) method Engines can be associated with numerous algorithms e.g. signature algorithms: SHA1withRSA, ECDSA, MD5withRSA 17

Cryptography in Java (III) The Java Cryptography Architecture (JCA) was designed around 2 principles algorithm independence implementation independence Creating a message digest: MessageDigest md = MessageDigest.getInstance( SHA-1 ) security.provider.<n>=<classname> Mapping contained in the lib/security/java.security file 18

Cryptographic Engines Signature Provides the functionality required to create a digital signature, which in turn can be used for authentication or data assurance MessageDigest Enables message digests, which are secure one-way hash functions that take an arbitrary length input and produce a fixed length output SecureRandom Provides a cryptographically strong Random Number Generator (RNG) KeyGenerator Used for generation of symmetric keys KeyPairGenerator Used to generate asymmetric key pairs, i.e. public and private key pairs Cipher Provides the functionality to create cryptographic ciphers that can encrypt and decrypt data SSLContext Used to specify and retrieve SSL implementations MAC Provides the functionality of a Message Authentication Code (MAC) 19

Encryption and decryption (I) Symmetric key generation private SecretKey generatekey () { KeyGenerator kg = KeyGenerator.getInstance ("DESede"); return kg.generatekey(); } Encryption private byte[] encrypt(byte[] msg) { cipher.init(cipher.encrypt_mode, secretkey); return cipher.dofinal(msg); 20 }

Encryption and decryption (II) Decryption private byte[] decrypt(byte[] msg) { cipher.init(cipher.decrypt_mode,secretkey); return cipher.dofinal(msg); } 21

Public Key Cryptography (I) Key generation private KeyPair generatekeypair () { KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); return kpg.generatekeypair(); } Signature private byte[] sign(byte[] msg) { Signature signature = Signature.getInstance("SHA1withRSA"); signature.initsign(privkey); signature.update(msg); return signature.sign();} 22

Public Key Cryptography (II) Signature verification private boolean verify (byte[] msg, byte[] signature) { Signature sign = Signature.getInstance ("SHA1withRSA"); sign.initverify(pubkey); sign.update(msg); return sign.verify(signature); } 23

Public Key Infrastructure (PKI) Certificates identity, public key, issuer, validity window, issuer s digital signature Certification Authority (CA) Registration Authority (RA) Repository Archive 24

PKI entities Repository 5 Alice 3 Archive 1 4 2 RA 25 5 CA Bob 1

SSL Motivation: bring ecommerce to the Internet SSL Handshake Protocol SSL Change Cipher Spec Protocol SSL Alert Protocol HTTP SSL Record TCP IP Originated by Netscape in 1994 26

SSL Handshake Protocol CLIENT SERVER 1. ClientHello 2. ServerHello 3. Certificate 4. CertificateRequest 5. ServerHelloDone Time 6. Certificate 7. ClientKeyExchange 8. CertificateVerify 9. ChangeCipherSpec 10. Finished 11. ChangeCipherSpec 12. Finished 27

SSL in Java javax.net.ssl Important classes: SSLContext, SSLEngine, SSLSocket, SSLServerSocket Setting up SSL requires the following steps: initialize key and trust material initialize SSLContext create SSLServerSocketFactory & SSLSocketFactory create SSLServerSocket & SSLSocket 28

Initialize key and trust material (I) Use OpenSSL to generate CA and certificates locate the script CA.sh in your OpenSSL installation (default: /usr/local/ssl/misc) Invoke./CA.sh -newca to create a CA./CA.sh -newreq to generate a certificate request./ca.sh -sign to issue a certificate The generated certificates can be read into Java using the CertificateFactory class. 29

Initialize SSLContext SSLContext sslcon = SSLContext.getInstance( TLS ); KeyManagerFactory kmf = KeyManagerFactory.getInstance ( SunX509 ); KeyStore ks = KeyStore.getInstance( JKS ); char[] passwd = changeit.tochararray(); ks.load(new FileInputStream( filename ), null); kmf.init(ks, passwd); sslcon.init(kmf.getkeymanagers(), null, null); 30

Create ServerSocketFactory & ServerSocket ServerSocketFactory ssf = sslcon.getserversocketfactory(); ServerSocket ss = ssf.createserversocket(8080); 31

SSLEngine SSLEngine innet UNWRAP inapp HS ta da state machine HS da ta Communication channel outnet WRAP 32 outapp

One-time pad Perfect data secrecy! Ciphertext = plaintext XOR key Plaintext = ciphertext XOR key The length of the plaintext and key must be equal 33

One-time pad (II) difficult to distribute keys securely requires numbers that absolutely cannot be guessed if you must: I. Get high-quality random output II. Store those bits on two CDs, both identical III. Securely distribute and use the CDs IV. Make sure new CDs are available when more data are needed V. Destroy the CDs when done 34

Summary if(! The Code Book ) { enjoy! } Do not invent your own cryptographic primitives or protocols! Use existing crypto libraries Java contains a rich and powerful crypto API 35