digest.update(server.getDesKey().getEncoded());
String symVersion = new String(digest.digest(), "UTF-8");
// encrypt and send an initial message to peer
Cipher cipher = server.getSymEncodingCipher();
Message msg = new Message();
msg.setBuffer(cipher.doFinal("hello".getBytes()));
msg.putHeader(EncryptHeader.KEY, new EncryptHeader(
EncryptHeader.ENCRYPT, symVersion));
Event evt = new Event(Event.MSG,msg);
peer.up(evt);
//assert that message is queued as we have no key from server
assertTrue(peerObserver.getUpMessages().isEmpty());
// send a view change where we are not the controller
// send to peer - which should have peer2 as its key server
peer.up(serverEvent);
// assert that peer\ keyserver address is now set
assertTrue(serverAddress == peer.getKeyServerAddr());
// get the resulting message from the peer - should be a key request
Event sent = (Event)peerObserver.getDownMessages().get("message0");
assertTrue(((EncryptHeader)((Message)sent.getArg()).getHeader(ENCRYPT.EncryptHeader.KEY)).getType() == ENCRYPT.EncryptHeader.KEY_REQUEST);
assertEquals(new String(((Message)sent.getArg()).getBuffer()),new String(peer.getKpair().getPublic().getEncoded()));
// send this event to server
server.up(sent);
Event reply = (Event)serverObserver.getDownMessages().get("message1");
//assert that reply is the session key encrypted with peer's public key
assertTrue(((EncryptHeader)((Message)reply.getArg()).getHeader(ENCRYPT.EncryptHeader.KEY)).getType() == ENCRYPT.EncryptHeader.SECRETKEY);
assertNotSame(peer.getDesKey(),server.getDesKey());
// now send back to peer
peer.up(reply);
// assert that both now have same key
assertEquals(peer.getDesKey(),server.getDesKey());
// send another encrypted message to peer to test queue
Message msg2 = new Message();
msg2.setBuffer(cipher.doFinal("hello2".getBytes()));
msg2.putHeader(EncryptHeader.KEY, new EncryptHeader(
EncryptHeader.ENCRYPT, symVersion));
Event evt2 = new Event(Event.MSG,msg2);