package backend;

import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.math.BigInteger;
import java.util.List;
import java.util.Scanner;

import javax.swing.*;

import java.security.*;
import java.security.spec.*;
import java.security.interfaces.*;

import javax.smartcardio.*;

public class PersonalTerminal {
	// the personal terminal should upload a fresh secret key and certificate to a smartcard
	// the environment is secure by assumption, so no auth is required
	//Get certificate from the backend and send it to the card by addCertificate
	
	// use: Backend.registerNewCard(customerId)
	// call this function "InitData registerNewCard"
	// create smartcard object 
	
	public static void main(String[] args){
		//InitData nc = new InitData(cert, keypair.getPrivate(), certVerifKey);
		Backend bk = new Backend();
		InitData nc = bk.registerNewCard(8);
		
		byte[] pk = nc.privateKey;
		byte[] c = nc.certificate;
		byte[] ca = nc.caVerifKey;
		
		
		//issuing certificate to the terminal on request by user either rental terminal or vehicle terminal
		PersonalTerminal pt = new PersonalTerminal();
		
		System.out.println("Welcome to the Personilization Terminal");
		System.out.println("1. Issue certificate for Rental Terminal");
		System.out.println("2. Issue certificate for Vehicle Terminal");
		System.out.println("3. EXIT");
		System.out.println("Enter a number");
		Scanner scan = new Scanner(System.in);
		String menu = scan.nextLine();
		if (menu.equals("1")){
			bk.registerRentalTerminal();
			byte[] c1 = nc.certificate;
			byte[] pk1 = nc.privateKey;
			System.out.println("Certificate issued successfully");
			
		}
		else if (menu.equals("2")){
			bk.registerVehicleTerminal();
			byte[] c2 = nc.certificate;
			byte[] pk2 = nc.privateKey;
			byte[] sc2 = nc.secretKey;
			byte[] ca2 = nc.caVerifKey;
			System.out.println("Certificate issued successfully");
			
		}
		else
		{
			System.out.println("Thank You");
		}
		
		
	}
}

@@ -873,12 +873,11 @@
 ard(
-8
 );%0A
+
 %09%09%0A%09
@@ -1343,16 +1343,77 @@
 ntln(%223.
+ Issue certificate for Smartcard %22);%0A%09%09System.out.println(%224.
  EXIT%22);
@@ -1894,24 +1894,24 @@
 caVerifKey;%0A
-
 %09%09%09System.ou
@@ -1952,32 +1952,130 @@
 essfully%22);%0A%09%09%09%0A
+%09%09%7Delse if(menu.equals(%223%22))%7B%0A%09%09%09//add new smartcard%0A%09%09%09InitData init = bk.registerNewCard();%0A%09%09%09%0A
 %09%09%7D%0A%09%09else%0A%09%09%7B%0A%09

add menu initialise smartcard