cs255 programming project 1. programming project 1 due: friday feb 8 th (11:59pm) – can use...

22
CS255 Programming Project 1

Upload: lorena-scott

Post on 24-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

CS255 Programming Project 1

Page 2: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Programming Project 1

• Due: Friday Feb 8th (11:59pm)– Can use extension days

• Can work in pairs– One solution per pair

• Test and submit on Leland machines– SCPD students: get SUNet ID!

sunetid.stanford.edu

Page 3: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Overview

• Build a password manager• Effectively a secure, networked map• Works like OS keychain• Client-server model• Written in Java using JCE

Page 4: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Security Features

• Passwords cannot be stolen– Not even if the server is compromised

• Network attackers can't tamper– Can't impersonate the server either

• Master password can be changed– Shouldn't require reciphering everything

Page 5: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

What is provided?

• Most of the application– GUI– Server– IO layer– Layered Map API– Simple test cases

• Skeleton code– AES– Secure network code

Page 6: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

GUI

• Simple, unpolished SWT– List of resource names– Create new RN/password with ^N– Edit password with ENTER– Delete password with DEL– Change master password– Only connects to localhost

• Improvements welcome– Not required by any means

Page 7: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Server

• (Mostly-) atomic file store• Backed by the filesystem–More transparent than a database

• Doesn't know anything about crypto• Sets master password = 'passw0rd'– Change it in the GUI

Page 8: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

IO Layer

• Probably a sign that I don't know Java• IO for blobs– byte[] and byte[][]– Uses simple length encoding– Filesystem instance for server– Network instance for client/server– Secure network instance... write me!

Page 9: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Layered Maps

• Store byte[] -> byte[] maps on disk• Export them over the network• Encrypt and MAC them• Use them as String -> String maps

Page 10: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Skeleton Crypto Code

• Wrapper around HMAC-SHA1• Catches exceptions–Most of them statically can't be thrown– Probably a few of them can (BUGS!)

• Provides a more functional interface

Page 11: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Quirks in the code

• I'm not a Java programmer• byte[] is usually assumed immutable• Needs testing on Windows– GUI code– Atomic file operations

• There are definitely bugs

Page 12: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

What needs to be done

• Aes class– AES-CTR mode– Authenticate with HMAC-SHA1

• SecureBlobIO class– Negotiate secure network connection– Prevent attacker from faking commands–Watch out for replay attacks!– Store necessary parameters on disk– Recover master AES key

Page 13: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Errata

• You are NOT required to:– protect integrity of keys from compromised server– protect secrecy of keys from anyone

Page 14: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Security

• Don’t use the same key to encrypt and MAC !!!

• Use a common key, K, and derive encryption and MAC keys, Kenc, Kmac using a PRF– Kenc = HMAC(K, “encrypt”);

– Kmac = HMAC(K, ”integrity”);

Page 15: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Counter Mode

• You must implement it.• To get a “plain” cipher use ECB mode with no

padding–Warning! CBC mode used by default– Need to specify “AES/ECB/NoPadding”

• Need a counter (try BigInteger)

Page 16: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Java Cryptography Extension

• Implementations of crypto primitives

Cipher Cipher

Pseudo-random Generator SecureRandom

Message Authentication Code Mac

Cryptographic Hash MessageDigest

Page 17: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

JCE: Generating Random Keys

1. Start the PRG (random seed set by default)

2. Initialize KeyGenerator with the PRG3. Generate the key

// Generate a random encryption keySecureRandom prng = SecureRandom.getInstance("SHA1PRNG");

KeyGenerator enckeygen = KeyGenerator.getInstance("AES");

enckeygen.init(prng);

SecretKey enckey = enckeygen.generateKey();

Page 18: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

JCE: Keys From Byte Data

• Use SecretKeySpec– Extends SecretKey

// Use KeyTree API to get key bytes from passwordbyte[] keyBytes = KeyTree.createAESKeyMaterial(passwd);

// Use the bytes to create a new SecretKeySecretKeySpec keySpec = new SecretKeySpec(keyBytes, “AES”);

Page 19: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

JCE: Using Ciphers

1. Select the algorithm2. Initialize with desired mode and key3. Encrypt/Decrypt// Create and initialize the cipherCipher cipher = Cipher.getInstance("AES/ECB/NoPadding");

cipher.init(Cipher.ENCRYPT_MODE, enckey);

// Encrypt the messagebyte[] msg = "Content is here.".getBytes();byte[] enc = cipher.doFinal(msg);

• Mac class has a similar API

Page 20: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Grading

• Security comes first– Design choices– Correctness of the implementation

• Did you implement all required parts?• Secondary– Cosmetics– Coding style– Efficiency

Page 21: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Submitting

• README file– Names, student IDs– Describe your design choices

• Your sources• Use /usr/class/cs255/bin/submit from a

Leland machine

Page 22: CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use extension days Can work in pairs – One solution per pair

Stuck?

• Use the newsgroup (su.class.cs255)– Best way to have your questions answered quickly

• TAs cannot:– Debug your code– Troubleshoot your local Java installation