· 7 years ago · May 15, 2018, 10:30 AM
1 Channel channel = new TCPChannel();
2 channel = new ChannelBase64(channel);
3 setPublicKey("scheduler");
4 channel.setPublicKey(publicKey);
5 channel.setPrivateKey(privateKey);
6 set_schedulerSocket(new Socket(InetAddress.getByName(_schedulerHost), _schedulerTCPPort));
7 String challenge = channel.generateChallenge();
8 System.out.println("challenge = " + challenge);
9 channel.setSchedulerSocket(this.get_schedulerSocket());
10 channel.sendMessage("!login " + challenge);
11 String answer = channel.receiveMessage();
12
13 String parts[] = answer.split(" ");
14 String command = parts[0].trim();
15 String ownChallenge = new String(Base64.decode(parts[1])).trim();
16 String schedulerChallenge = new String(Base64.decode(parts[2])).trim();
17 String secretKey = new String(Base64.decode(parts[3])).trim();
18 String iv = new String(Base64.decode(parts[4])).trim();
19
20 if (!ownChallenge.equals(challenge)) {
21 System.out.println("Challenges are not the same");
22 System.exit(1);
23 return;
24 }