CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use...
-
Upload
lorena-scott -
Category
Documents
-
view
212 -
download
0
Transcript of CS255 Programming Project 1. Programming Project 1 Due: Friday Feb 8 th (11:59pm) – Can use...
![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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/1.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/2.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/3.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/4.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/5.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/6.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/7.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/8.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/9.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/10.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/11.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/12.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/13.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/14.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/15.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/16.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/17.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/18.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/19.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/20.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/21.jpg)
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.](https://reader035.fdocuments.us/reader035/viewer/2022062715/56649db95503460f94aa96ea/html5/thumbnails/22.jpg)
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