Package org.jgroups.protocols.ENCRYPT

Examples of org.jgroups.protocols.ENCRYPT.EncryptHeader


        String symVersion=new String(digest.digest(), "UTF-8");

        encrypt.keyServer=false;
        Message msg=new Message();
        msg.setBuffer(cipher.doFinal("hello".getBytes()));
        msg.putHeader(ENCRYPT_ID, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));

        Event evt=new Event(Event.MSG, msg);

        //pass in event to encrypt layer

        encrypt.up(evt);

        // assert that message is queued as we have no key
        Util.assertTrue(observer.getUpMessages().isEmpty());

        // send a view change to trigger the become key server
        // we use the fact that our address is now the controller one
        Vector tempVector=new Vector();
        tempVector.add(tempAddress);
        View tempView=new View(new ViewId(tempAddress, 1), tempVector);
        Event event=new Event(Event.VIEW_CHANGE, tempView);
        // this should have changed us to the key server
        encrypt.up(event);

        // send another encrypted message
        Message msg2=new Message();
        msg2.setBuffer(cipher.doFinal("hello2".getBytes()));
        msg2.putHeader(ENCRYPT_ID, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));

        // we should have three messages now in our observer
        // that are decrypted

        Event evt2=new Event(Event.MSG, msg2);
View Full Code Here


        // encrypt and send an initial message to peer
        Cipher cipher=server.getSymEncodingCipher();
        Message msg=new Message();
        msg.setBuffer(cipher.doFinal("hello".getBytes()));
        msg.putHeader(ENCRYPT_ID, 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
        Util.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
        Util.assertEquals(serverAddress, peer.getKeyServerAddr());

        // get the resulting message from the peer - should be a key request

        Event sent=(Event)peerObserver.getDownMessages().get("message0");

        Util.assertEquals(((EncryptHeader)((Message)sent.getArg()).getHeader(ENCRYPT_ID)).getType(), EncryptHeader.KEY_REQUEST);
        Util.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
        Util.assertEquals(((EncryptHeader)((Message)reply.getArg()).getHeader(ENCRYPT_ID)).getType(), EncryptHeader.SECRETKEY);


        assert !peer.getDesKey().equals(server.getDesKey());
        // now send back to peer
        peer.up(reply);

        // assert that both now have same key
        Util.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(ENCRYPT_ID, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));

        Event evt2=new Event(Event.MSG, msg2);

        peer.up(evt2);
View Full Code Here

    String symVersion = new String(digest.digest(), "UTF-8");
   
    encrypt.keyServer = false;
    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);

    //pass in event to encrypt layer
   
    encrypt.up(evt);
   
    // assert that message is queued as we have no key
    assertTrue(observer.getUpMessages().isEmpty());
   
    // send a view change to trigger the become key server
    // we use the fact that our address is now the controller one
    Vector tempVector = new Vector();
    tempVector.add(tempAddress);
    View tempView = new View(new ViewId(tempAddress,1),tempVector);
    Event event = new Event(Event.VIEW_CHANGE,tempView);
    // this should have changed us to the key server
    encrypt.up(event);
   
    // send another encrypted message
    Message msg2 = new Message();
    msg2.setBuffer(cipher.doFinal("hello2".getBytes()));
    msg2.putHeader(EncryptHeader.KEY, new EncryptHeader(
        EncryptHeader.ENCRYPT, symVersion));
   
    // we should have three messages now in our observer
    // that are decrypted
   
View Full Code Here

   
    // 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);
View Full Code Here

        String symVersion=new String(digest.digest(), "UTF-8");

        encrypt.keyServer=false;
        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);

        //pass in event to encrypt layer

        encrypt.up(evt);

        // assert that message is queued as we have no key
        assertTrue(observer.getUpMessages().isEmpty());

        // send a view change to trigger the become key server
        // we use the fact that our address is now the controller one
        Vector tempVector=new Vector();
        tempVector.add(tempAddress);
        View tempView=new View(new ViewId(tempAddress, 1), tempVector);
        Event event=new Event(Event.VIEW_CHANGE, tempView);
        // this should have changed us to the key server
        encrypt.up(event);

        // send another encrypted message
        Message msg2=new Message();
        msg2.setBuffer(cipher.doFinal("hello2".getBytes()));
        msg2.putHeader(EncryptHeader.KEY, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));

        // we should have three messages now in our observer
        // that are decrypted

        Event evt2=new Event(Event.MSG, msg2);
View Full Code Here

        // 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
        assertEquals(serverAddress, peer.getKeyServerAddr());

        // get the resulting message from the peer - should be a key request

        Event sent=(Event)peerObserver.getDownMessages().get("message0");

        assertEquals(((EncryptHeader)((Message)sent.getArg()).getHeader(EncryptHeader.KEY)).getType(),
                     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
        assertEquals(((EncryptHeader)((Message)reply.getArg()).getHeader(EncryptHeader.KEY)).getType(),
                     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);
View Full Code Here

        digest.update(encrypt.getDesKey().getEncoded());

        byte[] symVersion=digest.digest();
        encrypt.keyServer=false;
        Message msg=new Message().setBuffer(cipher.doFinal("hello".getBytes()))
          .putHeader(ENCRYPT_ID, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));

        encrypt.up(new Event(Event.MSG, msg));

        // assert that message is queued as we have no key
        Util.assertTrue(observer.upMessages.isEmpty());

        // send a view change to trigger the become key server
        // we use the fact that our address is now the controller one
        View tempView=View.create(encrypt_addr,1,encrypt_addr);
        Event event=new Event(Event.VIEW_CHANGE, tempView);
        // this should have changed us to the key server
        encrypt.up(event);

        // send another encrypted message
        Message msg2=new Message().setBuffer(cipher.doFinal("hello2".getBytes()))
          .putHeader(ENCRYPT_ID,new EncryptHeader(EncryptHeader.ENCRYPT,symVersion));

        // we should have three messages now in our observer that are decrypted
        encrypt.up(new Event(Event.MSG, msg2));
        Util.assertEquals(3, observer.upMessages.size());
View Full Code Here

        // encrypt and send an initial message to peer
        Cipher cipher=server.getSymEncodingCipher();
        byte[] symVersion=digest.digest();
        Message msg=new Message().setBuffer(cipher.doFinal("hello".getBytes()))
          .putHeader(ENCRYPT_ID, new EncryptHeader(EncryptHeader.ENCRYPT, symVersion));

        peer.up(new Event(Event.MSG, msg));
        //assert that message is queued as we have no key from server
        Util.assertTrue(peerObserver.upMessages.isEmpty());

        // send a view change where we are not the controller

        // send to peer - which should have peer2 as its key server
        peer.up(viewChange);
        // assert that peer\ keyserver address is now set
        Util.assertEquals(server_addr, peer.getKeyServerAddr());

        // get the resulting message from the peer - should be a key request

        Event sent=peerObserver.downMessages.get("message0");

        Util.assertEquals(((EncryptHeader)((Message)sent.getArg()).getHeader(ENCRYPT_ID)).getType(), EncryptHeader.KEY_REQUEST);
        Util.assertEquals(new String(((Message)sent.getArg()).getBuffer()), new String(peer.getKpair().getPublic().getEncoded()));

        // send this event to server
        server.up(sent);

        Event reply=serverObserver.downMessages.get("message1");

        //assert that reply is the session key encrypted with peer's public key
        Util.assertEquals(((EncryptHeader)((Message)reply.getArg()).getHeader(ENCRYPT_ID)).getType(), EncryptHeader.SECRETKEY);


        assert !peer.getDesKey().equals(server.getDesKey());
        // now send back to peer
        peer.up(reply);

        // assert that both now have same key
        Util.assertEquals(peer.getDesKey(), server.getDesKey());

        // send another encrypted message to peer to test queue
        Message msg2=new Message().setBuffer(cipher.doFinal("hello2".getBytes()))
          .putHeader(ENCRYPT_ID,new EncryptHeader(EncryptHeader.ENCRYPT,symVersion));
        peer.up(new Event(Event.MSG, msg2));

        // make sure we have the events now in the up layers
        Util.assertEquals(3,peerObserver.upMessages.size());
View Full Code Here

TOP

Related Classes of org.jgroups.protocols.ENCRYPT.EncryptHeader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.