package backend;

/** Certificate authority */
public class CertAuth {

	public enum TYPE {
		SMARTCARD, RENTALTERM, VEHICLETERM
	};

	/**
	 * Hard-coded(!) signature key of the CA (SK_{CA}) 
	 */
	private static final byte[] signKey = new byte[] { (byte) 0xca,
			(byte) 0xfe, (byte) 0xba, (byte) 0xbe };
	private byte[] verifKey;

	public CertAuth() {
		// TODO: verifKey = derivePublicKey(signKey)S
	}
	
	public byte[] getVerificationKey() {
		return verifKey.clone();
	}

	public byte[] makeCert(TYPE type, byte[] publicKey) {
		// TODO: encode certificate
		byte[] encoded = new byte[64];
		return signRaw(encoded);
	}

	public byte[] makeCert(TYPE type, byte[] publicKey, long exp) {
		// TODO: encode certificate
		byte[] encoded = new byte[64];
		return signRaw(encoded);
	}

	private byte[] signRaw(byte[] rawData) {
		byte[] sig = new byte[64];
		// TODO: implement
		return sig;
	}

}

@@ -15,396 +15,1244 @@
 d;%0A%0A
-/** Certificate authority */%0Apublic class CertAuth %7B%0A%0A%09public enum TYPE %7B%0A%09%09SMARTCARD, RENTALTERM, VEHICLETERM%0A%09%7D;%0A%0A%09/**%0A%09 * Hard-coded(!) signature key of the CA (SK_%7BCA%7D) %0A%09 */%0A%09private static final byte%5B%5D signKey = new byte%5B%5D %7B (byte) 0xca,%0A%09%09%09(byte) 0xfe, (byte) 0xba, (byte) 0xbe %7D;%0A%09private byte%5B%5D verifKey;%0A%0A%09public CertAuth() %7B%0A%09%09// TODO: verifKey = derivePublicKey(signKey)S
+import java.io.FileInputStream;%0Aimport java.io.FileOutputStream;%0Aimport java.security.PublicKey;%0Aimport java.security.interfaces.RSAPrivateKey;%0Aimport java.security.interfaces.RSAPublicKey;%0A%0Aimport javax.crypto.Cipher;%0A%0A/** Certificate authority */%0Apublic class CertAuth %7B%0A%0A%09public enum TYPE %7B%0A%09%09SMARTCARD, RENTALTERM, VEHICLETERM%0A%09%7D;%0A%0A%09private RSAPublicKey capubkey;%0A%09private RSAPrivateKey caprivkey;%0A%0A%09public CertAuth() %7B%0A%09%09// TODO: read keys from files%0A%09%09try %7B%0A%09%09%09/* Get the secret message from file. */%0A%09%09%09FileInputStream plainfile = new FileInputStream(inFileName);%0A%09%09%09byte%5B%5D plaintext = new byte%5Bplainfile.available()%5D;%0A%09%09%09plainfile.read(plaintext);%0A%09%09%09plainfile.close();%0A%0A%09%09%09/* Get the public key from file. */%0A%09%09%09PublicKey publickey = readPublicKey(%22publickey%22);%0A%0A%09%09%09/* Create a cipher for encrypting. */%0A%09%09%09Cipher encrypt_cipher = Cipher.getInstance(%22RSA/ECB/PKCS1Padding%22);%0A%09%09%09encrypt_cipher.init(Cipher.ENCRYPT_MODE, publickey);%0A%0A%09%09%09/* Encrypt the secret message and store in file. */%0A%09%09%09byte%5B%5D ciphertext = encrypt_cipher.doFinal(plaintext);%0A%09%09%09FileOutputStream cipherfile = new FileOutputStream(outFileName);%0A%09%09%09cipherfile.write(ciphertext);%0A%09%09%09cipherfile.close();%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %0A%09%7D%0A
-%09
 %0A%09pu

Change key types in CertAuth