assertTrue(((EncryptHeader)((Message)sent.getArg()).getHeader(ENCRYPT.EncryptHeader.KEY)).getType() == ENCRYPT.EncryptHeader.KEY_REQUEST);
assertEquals(((EncryptHeader)((Message)sent.getArg()).getHeader(EncryptHeader.KEY)).getType(), EncryptHeader.KEY_REQUEST);
	public void testViewChangeNewKeyServer() throws Exception{		// create peer and server		ENCRYPT peer = new ENCRYPT();		try {			peer.init();		} catch (Exception e){			fail(e.getMessage());		}				ENCRYPT server = new ENCRYPT();		try {			server.init();		} catch (Exception e){			fail(e.getMessage());		}				// set up server 		server.keyServer = true;		MockObserver serverObserver = new MockObserver();		server.setObserver(serverObserver);		Address serverAddress =new MockAddress("server");				server.setLocal_addr(serverAddress);		//set the server up as keyserver		Vector serverVector = new Vector();		serverVector.add(serverAddress);		View tempView = new View(new ViewId(serverAddress,1),serverVector);		Event serverEvent = new Event(Event.VIEW_CHANGE,tempView);		server.up(serverEvent);				// set up peer		Address peerAddress =new MockAddress("peer");		peer.setLocal_addr(peerAddress);		MockObserver peerObserver = new MockObserver();		peer.setObserver(peerObserver);		peer.keyServer = false;						MessageDigest digest = MessageDigest.getInstance("MD5");		digest.reset();		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);		peer.up(evt2);				// make sure we have the events now in the up layers		assertEquals(3,peerObserver.getUpMessages().size());				Event tempEvt = (Event)peerObserver.getUpMessages().get("message2");						assertEquals(new String(((Message)tempEvt.getArg()).getBuffer()),"hello");				tempEvt = (Event)peerObserver.getUpMessages().get("message3");				assertEquals(new String(((Message)tempEvt.getArg()).getBuffer()),"hello2");						}