mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/encryption/TestEncryptedSystem.java
@Test
    public void testEncryptionInfoErrorResponse() throws IOException, InvalidKeyException, IllegalBlockSizeException, 
        BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, 
        NoSuchPaddingException, InterruptedException
    {
        //Create the message to alter encryption level property.
        TerraHarvestMessage message = EncryptionUtil.createSetEncryptionLevelMessage(EncryptionMode.AES_ECDH_ECDSA);
        
        //Send message
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        //wait for response
        MessageListener listener = new MessageListener(m_Socket);
        
        listener.waitForMessage(Namespace.ConfigAdmin,  ConfigAdminMessageType.SetPropertyResponse, 800);
       
        //Send unencrypted message that should cause an encryption error.
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        //Verify only one encryption error response is received.
        listener = new MessageListener(m_Socket);
        
        listener.waitForMessage(Namespace.EncryptionInfo, 
                EncryptionInfoMessageType.EncryptionInfoErrorResponse, 1000);
        
        //Create message to return encryption type to none.
        message = EncryptionUtil.createSetEncryptionLevelMessage(EncryptionMode.NONE);
        TerraHarvestMessage encryptedMessage = EncryptionUtil.encryptMessageWithECDH(message);
        
        //Send message
        encryptedMessage.writeDelimitedTo(m_Socket.getOutputStream());
        
        //wait for response
        listener.waitForMessage(Namespace.ConfigAdmin, ConfigAdminMessageType.SetPropertyResponse, 1000);
        
        //Create message
        message = EncryptionUtil.createEncryptionInfoMessage(
                EncryptionInfoMessageType.GetEncryptionTypeRequest, null);
        
        //Send request
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        //wait for response
        final EncryptionInfoNamespace namespace = (EncryptionInfoNamespace)listener.waitForMessage(
                Namespace.EncryptionInfo, EncryptionInfoMessageType.GetEncryptionTypeResponse, 500);
        
        //Verify response
        final GetEncryptionTypeResponseData data = GetEncryptionTypeResponseData.parseFrom(namespace.getData());
        
        assertThat(data.getType(), is(EncryptType.NONE));
    }
/**
     * Verify that an encryption info error response is sent when an unencrypted message is sent to an encrypted system.
     */
Verify that an encryption info error response is sent when an unencrypted message is sent to an encrypted system.
Verify that an encryption info error response is sent when an unencrypted message is sent to an encrypted system .
@Test
    public void testEncryptionInfoErrorResponse() throws IOException, InvalidKeyException, IllegalBlockSizeException, 
        BadPaddingException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, 
        NoSuchPaddingException, InterruptedException
    {
        TerraHarvestMessage message = EncryptionUtil.createSetEncryptionLevelMessage(EncryptionMode.AES_ECDH_ECDSA);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        MessageListener listener = new MessageListener(m_Socket);
        listener.waitForMessage(Namespace.ConfigAdmin,  ConfigAdminMessageType.SetPropertyResponse, 800);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        listener = new MessageListener(m_Socket);
        listener.waitForMessage(Namespace.EncryptionInfo, 
                EncryptionInfoMessageType.EncryptionInfoErrorResponse, 1000);
        message = EncryptionUtil.createSetEncryptionLevelMessage(EncryptionMode.NONE);
        TerraHarvestMessage encryptedMessage = EncryptionUtil.encryptMessageWithECDH(message);
        encryptedMessage.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForMessage(Namespace.ConfigAdmin, ConfigAdminMessageType.SetPropertyResponse, 1000);
        message = EncryptionUtil.createEncryptionInfoMessage(
                EncryptionInfoMessageType.GetEncryptionTypeRequest, null);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        final EncryptionInfoNamespace namespace = (EncryptionInfoNamespace)listener.waitForMessage(
                Namespace.EncryptionInfo, EncryptionInfoMessageType.GetEncryptionTypeResponse, 500);
        final GetEncryptionTypeResponseData data = GetEncryptionTypeResponseData.parseFrom(namespace.getData());
        assertThat(data.getType(), is(EncryptType.NONE));
    }
@ Test public void testEncryptionInfoErrorResponse ( ) throws IOException , InvalidKeyException , IllegalBlockSizeException , BadPaddingException , InvalidAlgorithmParameterException , NoSuchAlgorithmException , NoSuchProviderException , NoSuchPaddingException , InterruptedException { TerraHarvestMessage message = EncryptionUtil . createSetEncryptionLevelMessage ( EncryptionMode . AES_ECDH_ECDSA ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; MessageListener listener = new MessageListener ( m_Socket ) ; listener . waitForMessage ( Namespace . ConfigAdmin , ConfigAdminMessageType . SetPropertyResponse , 800 ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener = new MessageListener ( m_Socket ) ; listener . waitForMessage ( Namespace . EncryptionInfo , EncryptionInfoMessageType . EncryptionInfoErrorResponse , 1000 ) ; message = EncryptionUtil . createSetEncryptionLevelMessage ( EncryptionMode . NONE ) ; TerraHarvestMessage encryptedMessage = EncryptionUtil . encryptMessageWithECDH ( message ) ; encryptedMessage . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . ConfigAdmin , ConfigAdminMessageType . SetPropertyResponse , 1000 ) ; message = EncryptionUtil . createEncryptionInfoMessage ( EncryptionInfoMessageType . GetEncryptionTypeRequest , null ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; final EncryptionInfoNamespace namespace = ( EncryptionInfoNamespace ) listener . waitForMessage ( Namespace . EncryptionInfo , EncryptionInfoMessageType . GetEncryptionTypeResponse , 500 ) ; final GetEncryptionTypeResponseData data = GetEncryptionTypeResponseData . parseFrom ( namespace . getData ( ) ) ; assertThat ( data . getType ( ) , is ( EncryptType . NONE ) ) ; }
Verify that an encryption info error response is sent when an unencrypted message is sent to an encrypted system.
Verify that an encryption info error response is sent when an unencrypted message is sent to an encrypted system .
//Create the message to alter encryption level property. //Send message //wait for response //Send unencrypted message that should cause an encryption error. //Verify only one encryption error response is received. //Create message to return encryption type to none. //Send message //wait for response //Create message //Send request //wait for response //Verify response