Back to home page

Enduro/X

 
 

    


0001 #!/bin/bash
0002 ##
0003 ## @brief @(#) Test encryption - test launcher
0004 ##
0005 ## @file run.sh
0006 ##
0007 ## -----------------------------------------------------------------------------
0008 ## Enduro/X Middleware Platform for Distributed Transaction Processing
0009 ## Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0010 ## Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0011 ## This software is released under one of the following licenses:
0012 ## AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0013 ## See LICENSE file for full text.
0014 ## -----------------------------------------------------------------------------
0015 ## AGPL license:
0016 ##
0017 ## This program is free software; you can redistribute it and/or modify it under
0018 ## the terms of the GNU Affero General Public License, version 3 as published
0019 ## by the Free Software Foundation;
0020 ##
0021 ## This program is distributed in the hope that it will be useful, but WITHOUT ANY
0022 ## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0023 ## PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0024 ## for more details.
0025 ##
0026 ## You should have received a copy of the GNU Affero General Public License along 
0027 ## with this program; if not, write to the Free Software Foundation, Inc.,
0028 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0029 ##
0030 ## -----------------------------------------------------------------------------
0031 ## A commercial use license is available from Mavimax, Ltd
0032 ## contact@mavimax.com
0033 ## -----------------------------------------------------------------------------
0034 ##
0035 TESTNAME="test043_encrypt"
0036 
0037 PWD=`pwd`
0038 if [ `echo $PWD | grep $TESTNAME ` ]; then
0039         # Do nothing 
0040         echo > /dev/null
0041 else
0042         # started from parent folder
0043         pushd .
0044         echo "Doing cd"
0045         cd test043_encrypt
0046 fi;
0047 
0048 . ../testenv.sh
0049 
0050 export TESTDIR="$NDRX_APPHOME/atmitest/$TESTNAME"
0051 export PATH=$PATH:$TESTDIR
0052 
0053 xadmin killall atmi.sv43 2>/dev/null
0054 xadmin killall atmiclt43 2>/dev/null
0055 
0056 # client timeout
0057 export NDRX_TOUT=10
0058 export NDRX_DEBUG_CONF=`pwd`/debug.conf
0059 
0060 function go_out {
0061     echo "Test exiting with: $1"
0062     xadmin killall atmi.sv43 2>/dev/null
0063     xadmin killall atmiclt43 2>/dev/null
0064     
0065     popd 2>/dev/null
0066     exit $1
0067 }
0068 
0069 rm *.log
0070 
0071 
0072 ENCSTR=""
0073 
0074 #
0075 # Test standard encryption
0076 # We test internal key with external plugin key
0077 #
0078 for i in 1 2
0079 do
0080     if [ "X$i" == "X2" ]; then
0081         export NDRX_PLUGINS=libcryptohost.so
0082 
0083         if [ "$(uname)" == "Darwin" ]; then
0084                 echo "Darwin host"
0085                 export NDRX_PLUGINS=libcryptohost.dylib
0086         fi
0087 
0088     fi
0089 
0090     CLR="hello Test $i"
0091 
0092     ENCSTR=`exencrypt "$CLR"`
0093     RET=$?
0094 
0095     if [ "$RET" -ne "0" ]; then
0096             echo "Failed to encrypt..."
0097             go_out -3
0098     fi
0099 
0100     echo "Encrypted string: [$ENCSTR]"
0101 
0102     if [ "Xhello Test" == "X$ENCSTR" ]; then
0103             echo "ENCSTR must not be equal to non encrypted value!!!"
0104             go_out -4
0105     fi
0106 
0107 
0108     DECSTR=`exdecrypt $ENCSTR`
0109     RET=$?
0110 
0111     if [ "$RET" -ne "0" ]; then
0112             echo "Failed to decrypt..."
0113             go_out -5
0114     fi
0115 
0116     echo "Decrypted string: [$DECSTR] (clear: [$CLR])"
0117 
0118     if [ "Xhello Test $i" != "X$DECSTR" ]; then
0119             echo "DECSTR Must be equal to clear value, but got [$DECSTR]"
0120             go_out -6
0121     fi
0122 done
0123 
0124 unset NDRX_PLUGINS
0125 
0126 #
0127 # Now if we try to decryp the ENCSTR it should fail or value shall not be equal
0128 # to clear string, because we are not using cryptohost but default built in
0129 # crypto key function.
0130 #
0131 
0132 DECSTR=`exdecrypt $ENCSTR`
0133 RET=$?
0134 
0135 echo "Decrypted value (with different key): [$DECSTR]"
0136 
0137 if [ "$RET" -eq "0" ] && [ "X$DECSTR" == "Xhello Test 2" ]; then
0138     echo "ERROR ! value shall not be decrypted successfully with different key! $RET"
0139     go_out -7
0140 fi
0141 
0142 echo "Checking interactive mode..."
0143 #
0144 # Check the CLI interactive mode
0145 #
0146 ENC_CLI=`{ echo 'hello Test 2'; echo 'hello Test 2'; } | exencrypt`
0147 RET=$?
0148 
0149 #Check values...
0150 if [ "$RET" -eq "0" ] && [ "X$ENC_CLI" == "X$ENCSTR" ]; then
0151     echo "ERROR ! Interactive enc value [$ENC_CLI] expected [$ENCSTR]! $RET"
0152     go_out -8
0153 fi
0154 
0155 # check input do not match...
0156 
0157 ENC_CLI=`{ echo 'hello Test 2'; echo 'hello Test 1'; } | exencrypt`
0158 RET=$?
0159 
0160 #Check values...
0161 if [ "$RET" -eq "0" ]; then
0162     echo "ERROR ! Interactive no error on non matching data!"
0163     go_out -9
0164 fi
0165 
0166 #
0167 # Export plugin again. Now we will export encrypted string to the global
0168 # section of the ini file. And this this env variable shall be readable ok
0169 # from the client process
0170 #
0171 export NDRX_PLUGINS=libcryptohost.so
0172 
0173 if [ "$(uname)" == "Darwin" ]; then
0174         echo "Darwin host"
0175         export NDRX_PLUGINS=libcryptohost.dylib
0176 fi
0177 
0178 echo "[@global]" > test.conf
0179 echo "TEST_ENV_PARAM=\${dec=$ENCSTR}" >> test.conf
0180 
0181 #
0182 # Export CC Config
0183 #
0184 export NDRX_CCONFIG=`pwd`/test.conf
0185 
0186 
0187 (./atmiclt43 2>&1) > ./atmiclt43.log
0188 
0189 RET=$?
0190 
0191 if [ "$RET" -ne "0" ]; then
0192     echo "ERROR ! atmiclt43 failed!"
0193     go_out -11
0194 fi
0195 
0196 #
0197 # Check the tptools do the same
0198 #
0199 (./atmiclt43_tp $ENCSTR 2>&1) > ./atmiclt43_tp.log
0200 
0201 RET=$?
0202 
0203 if [ "$RET" -ne "0" ]; then
0204     echo "ERROR ! atmiclt43_tp failed!"
0205     go_out -12
0206 fi
0207 
0208 # Catch is there is test error!!!
0209 if [ "X`grep TESTERROR *.log`" != "X" ]; then
0210         echo "Test error detected!"
0211         go_out -2
0212 fi
0213 
0214 go_out $RET
0215 
0216 # vim: set ts=4 sw=4 et smartindent: