4 import java.security.*;
\r
5 import javax.crypto.*;
\r
8 import org.bouncycastle.openssl.*;
\r
9 import org.bouncycastle.util.encoders.*;
\r
11 public class Main implements Runnable{
\r
12 static private BufferedReader $con = null;
\r
14 static private TCP $tcp = null;
\r
15 static private UDP $udp = null;
\r
16 static public Config $cfg = new Config("client");
\r
19 static public void main(String[] $args)throws Exception{
\r
20 System.out.println("CLIENT Starting...");
\r
22 $udp = new UDP($cfg.getString("server.host"),$cfg.getInt("server.tcp.port"));
\r
23 $tcp = new TCP($cfg.getString("server.host"),$cfg.getInt("server.udp.port"));
\r
25 new Thread(new Main()).start();
\r
26 System.out.println("CLIENT IDLE.");
\r
31 Thread.currentThread().setPriority(9);
\r
32 $con = new BufferedReader (new InputStreamReader(System.in));
\r
33 while($con != null)try{auswertung($con.readLine().trim());}catch(Exception $e){$e.printStackTrace();} //Eingaben auswerten
\r
34 }catch(Exception $e){$e.printStackTrace();}
\r
38 static public void auswertung(String $eingraw)throws Exception{
\r
39 if($eingraw.equals("") || $eingraw == null)return; // Ignore null-commands
\r
40 String[] $eing = $eingraw.split("\\s+"); //regex: whitespace character once and more
\r
42 if($eing[0].equalsIgnoreCase("!login")){
\r
43 if($eing.length == 1){
\r
44 PEMReader in = new PEMReader(new FileReader($cfg.getString("keys.private.dir")+File.separator+$eing[1]+".pem"), new PasswordFinder() {
\r
46 public char[] getPassword(){
\r
47 try{System.out.println("Enter pass phrase:"); return (new BufferedReader(new InputStreamReader(System.in)).readLine()).toCharArray();}catch(Exception $e){$e.printStackTrace();}return null;
\r
49 $tcp.$prk = ((KeyPair) in.readObject()).getPrivate();
\r
51 byte[] $rand = new byte[32];
\r
52 new SecureRandom().nextBytes($rand);
\r
53 $tcp.$challenge = new String(Base64.encode($rand));
\r
55 $tcp.send($eingraw+" "+new String(Base64.encode($rand)));
\r
58 System.out.println("Ungültige Loginanfrage. !login <username>");
\r
62 if($eing[0].equalsIgnoreCase("!end")){
\r
63 $tcp.send("!logout");
\r
70 if($eing[0].equalsIgnoreCase("!list")){$udp.send($eingraw); return;}
\r
71 if($eing[0].equalsIgnoreCase("!info")){$udp.send($eingraw); return;}
\r
72 if($eing[0].charAt(0) == '!'){$tcp.send($eingraw); return;}
\r
73 System.out.println("Unknown input: "+$eingraw);
\r