mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/encryption/TestEncryptedSystem.java
@Test
    public void testEncryptedResponse() throws IOException, InvalidKeyException, InvalidAlgorithmParameterException, 
        IllegalBlockSizeException, BadPaddingException, IllegalArgumentException, NoSuchAlgorithmException, 
        NoSuchProviderException, NoSuchPaddingException, InterruptedException
    {
        //message listener that will listen for response messages.
        MessageListener listener = new MessageListener(m_Socket);
        
        //create a request for system information
        TerraHarvestMessage thMessage = TerraHarvestMessageHelper.createRequestControllerInfoMsg();
        //need to set the encryption information so put the message to a builder
        TerraHarvestMessage.Builder builder = thMessage.toBuilder();
        builder.setEncryptType(EncryptType.AES_ECDH_ECDSA);
  
        //build the message containing encrypted payload information
        TerraHarvestMessage encryptedMessage = EncryptionUtil.encryptMessageWithECDH(thMessage);
        //send
        encryptedMessage.writeDelimitedTo(m_Socket.getOutputStream());
        
        //wait for a response
        listener.waitForMessage(Namespace.Base, BaseMessageType.ControllerInfo, 800);
        
        //verify
        List<MessageDetails> messages = listener.getCapturedTerraHarvestMessages();
        assertThat(messages.size(), is(1));
        //get the response
        TerraHarvestMessage responseMessage = messages.get(0).getMessage();
        assertThat(responseMessage.getEncryptType(), is(EncryptType.AES_ECDH_ECDSA));

        //parse the decrypted bytes
        TerraHarvestPayload payloadDecrypt = EncryptionUtil.decryptECDHMessage(responseMessage);
        
        //verify information in the response
        assertThat(payloadDecrypt.getNamespace(), is(Namespace.Base));
        
        //Get the base namespace message
        BaseNamespace namespaceData = BaseNamespace.parseFrom(payloadDecrypt.getNamespaceMessage());
        assertThat(namespaceData.getType(), is(BaseMessageType.ControllerInfo));
        
        //system info message
        ControllerInfoData dataMessage = ControllerInfoData.parseFrom(namespaceData.getData());
        assertThat(dataMessage.getBuildInfoCount(), greaterThan(0));
        assertThat(dataMessage.getName().length(), greaterThan(1));
    }
/**
     * Verify the ability to send and receive encrypted messages using ECDH with ECDSA.
     * This test requires that the public and private keys are already stored on the controller that is being connected
     * to.
     */
Verify the ability to send and receive encrypted messages using ECDH with ECDSA.
This test requires that the public and private keys are already stored on the controller that is being connected
to.
Verify the ability to send and receive encrypted messages using ECDH with ECDSA . This test requires that the public and private keys are already stored on the controller that is being connected to .
@Test
    public void testEncryptedResponse() throws IOException, InvalidKeyException, InvalidAlgorithmParameterException, 
        IllegalBlockSizeException, BadPaddingException, IllegalArgumentException, NoSuchAlgorithmException, 
        NoSuchProviderException, NoSuchPaddingException, InterruptedException
    {
        MessageListener listener = new MessageListener(m_Socket);
        TerraHarvestMessage thMessage = TerraHarvestMessageHelper.createRequestControllerInfoMsg();
        TerraHarvestMessage.Builder builder = thMessage.toBuilder();
        builder.setEncryptType(EncryptType.AES_ECDH_ECDSA);
        TerraHarvestMessage encryptedMessage = EncryptionUtil.encryptMessageWithECDH(thMessage);
        encryptedMessage.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForMessage(Namespace.Base, BaseMessageType.ControllerInfo, 800);
        List<MessageDetails> messages = listener.getCapturedTerraHarvestMessages();
        assertThat(messages.size(), is(1));
        TerraHarvestMessage responseMessage = messages.get(0).getMessage();
        assertThat(responseMessage.getEncryptType(), is(EncryptType.AES_ECDH_ECDSA));
        TerraHarvestPayload payloadDecrypt = EncryptionUtil.decryptECDHMessage(responseMessage);
         information in the response
        assertThat(payloadDecrypt.getNamespace(), is(Namespace.Base));
        BaseNamespace namespaceData = BaseNamespace.parseFrom(payloadDecrypt.getNamespaceMessage());
        assertThat(namespaceData.getType(), is(BaseMessageType.ControllerInfo));
        ControllerInfoData dataMessage = ControllerInfoData.parseFrom(namespaceData.getData());
        assertThat(dataMessage.getBuildInfoCount(), greaterThan(0));
        assertThat(dataMessage.getName().length(), greaterThan(1));
    }
@ Test public void testEncryptedResponse ( ) throws IOException , InvalidKeyException , InvalidAlgorithmParameterException , IllegalBlockSizeException , BadPaddingException , IllegalArgumentException , NoSuchAlgorithmException , NoSuchProviderException , NoSuchPaddingException , InterruptedException { MessageListener listener = new MessageListener ( m_Socket ) ; TerraHarvestMessage thMessage = TerraHarvestMessageHelper . createRequestControllerInfoMsg ( ) ; TerraHarvestMessage . Builder builder = thMessage . toBuilder ( ) ; builder . setEncryptType ( EncryptType . AES_ECDH_ECDSA ) ; TerraHarvestMessage encryptedMessage = EncryptionUtil . encryptMessageWithECDH ( thMessage ) ; encryptedMessage . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . Base , BaseMessageType . ControllerInfo , 800 ) ; List < MessageDetails > messages = listener . getCapturedTerraHarvestMessages ( ) ; assertThat ( messages . size ( ) , is ( 1 ) ) ; TerraHarvestMessage responseMessage = messages . get ( 0 ) . getMessage ( ) ; assertThat ( responseMessage . getEncryptType ( ) , is ( EncryptType . AES_ECDH_ECDSA ) ) ; TerraHarvestPayload payloadDecrypt = EncryptionUtil . decryptECDHMessage ( responseMessage ) ; assertThat ( payloadDecrypt . getNamespace ( ) , is ( Namespace . Base ) ) ; BaseNamespace namespaceData = BaseNamespace . parseFrom ( payloadDecrypt . getNamespaceMessage ( ) ) ; assertThat ( namespaceData . getType ( ) , is ( BaseMessageType . ControllerInfo ) ) ; ControllerInfoData dataMessage = ControllerInfoData . parseFrom ( namespaceData . getData ( ) ) ; assertThat ( dataMessage . getBuildInfoCount ( ) , greaterThan ( 0 ) ) ; assertThat ( dataMessage . getName ( ) . length ( ) , greaterThan ( 1 ) ) ; }
Verify the ability to send and receive encrypted messages using ECDH with ECDSA.
Verify the ability to send and receive encrypted messages using ECDH with ECDSA .
//message listener that will listen for response messages. //create a request for system information //need to set the encryption information so put the message to a builder //build the message containing encrypted payload information //send //wait for a response //verify //get the response //parse the decrypted bytes //verify information in the response //Get the base namespace message //system info message