126. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 3/25/2019 8:58:08 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

126.1 Files compared

# Location File Last Modified
1 C:\AraxisMergeCompare\Pri_un\IMAG_Source\VISA\Java\VixGuiWebApp\main\src\java\gov\va\med\imaging\exchange LogLineDecryptor.java Mon Mar 18 20:39:05 2019 UTC
2 C:\AraxisMergeCompare\Pri_re\IMAG_Source\VISA\Java\VixGuiWebApp\main\src\java\gov\va\med\imaging\exchange LogLineDecryptor.java Tue Mar 19 12:04:32 2019 UTC

126.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 462
Changed 2 4
Inserted 0 0
Removed 0 0

126.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

126.4 Active regular expressions

No regular expressions were active.

126.5 Comparison detail

  1   /**
  2    * 
  3     Package:  MAG - Vis tA Imaging
  4     WARNING:  Per VHA D irective 2 004-038, t his routin e should n ot be modi fied.
  5     Date Cre ated: Mar  15, 2012
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:     DN S      BECKEC
  8     Descript ion: 
  9  
  10           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  11           ;;  Property  of the US  Government .
  12           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  13           ;;  Use of un released v ersions of  this soft ware requi res the us er
  14           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  15           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  16           ;;   telephon e (301) 73 4-0100.
  17           ;;
  18           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  19           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  20           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  21           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  22           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  23           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  24  
  25    */
  26   package go v.va.med.i maging.exc hange;
  27  
  28   import jav a.lang.ref lect.Invoc ationTarge tException ;
  29   import jav a.lang.ref lect.Metho d;
  30   import jav a.util.Has hMap;
  31   import jav a.util.Map ;
  32   import jav a.util.reg ex.Matcher ;
  33   import jav a.util.reg ex.Pattern ;
  34  
  35   import org .apache.lo gging.log4 j.Level;
  36   import org .apache.lo gging.log4 j.LogManag er;
  37   import org .apache.lo gging.log4 j.Logger;
  38  
  39   /**
  40    * 
  41    * The dec ryptor dec rypts each  log line  as decrypt () is call ed. 
  42    * If the  log line h as an encr ypted fiel d, i.e. it  matches t he pattern ,
  43    * then we  create a  decryptor  using the  name in th e log line  and decry pt
  44    * field.
  45    * The dec ryptors ar e cached f or later u se, since  most (usua lly all) o f the decr yption in  the
  46    * log fil e should u se the sam e decrypti on.
  47    * 
  48    * @author   DN S      BECKEC
  49    *
  50    */
  51   public cla ss LogLine Decryptor
  52   {
  53           pr ivate tran sient Logg er logger  = LogManag er.getLogg er(this.ge tClass());
  54           
  55           //  the encry pted field  pattern m atch depen ds on havi ng BASE64  encoded en crypted fi eld values
  56           //  that is A -Z a-z 0-9  / +
  57           //  If we don 't use tha t characte r set for  BASE64 enc oding than  we need t o update t he REGEX
  58           //  + is 0x2B
  59           //  / is 0x2F
  60           //  { is ox7B
  61           //  } is 0x7D
  62           pr ivate stat ic final S tring DECR YPTION_PAT TERN_REGEX  = "\\x7B( [\\w_]+)\\ x7D([A-Za- z0-9+/=]+) ";
  63           st atic final  Pattern D ECRYPTION_ PATTERN =  Pattern.co mpile(DECR YPTION_PAT TERN_REGEX );
  64           st atic final  int DECRY PTION_FIEL D_ENCRYPTO R_GROUP =  1;
  65           st atic final  int DECRY PTION_FIEL D_VALUE_GR OUP = 2;
  66           
  67           pu blic stati c final St ring DEFAU LT_ENCRYPT ION_PACKAG E = "gov.v a.med.log4 j.encrypti on";
  68           
  69           //  IMPORTANT  NOTE:
  70           //  The decry ption clas s must hav e the foll owing meth ods, we ca n't rely o n the inte rface that  declares  these
  71           //  to be ava ilable so  we must us e reflecti on to vali date the d ecryption  class and  make the c alls.
  72           //  Sometime  soon we sh ould move  the encryp ting layou t into the  main code  base and  eliminate  this ... m aybe 
  73           //  public ab stract byt e[] decryp t(byte[] e ncrypted);
  74           pu blic stati c final St ring DEFAU LT_DECRYPT ION_METHOD _NAME = "d ecrypt";
  75           pu blic stati c final Cl ass<?>[] D ECRYPTION_ METHOD_PAR AMETER_TYP ES = new C lass<?>[]{ byte[].cla ss};
  76           pu blic stati c final Cl ass<?> DEC RYPTION_ME THOD_RETUR N_TYPE = b yte[].clas s;
  77           //  public ab stract byt e[] decode (String  e ncoded);
  78           pu blic stati c final St ring DEFAU LT_DECODIN G_METHOD_N AME = "dec ode";
  79           pu blic stati c final Cl ass<?>[] D ECODING_ME THOD_PARAM ETER_TYPES  = new Cla ss<?>[]{St ring.class };
  80           pu blic stati c final Cl ass<?> DEC ODING_METH OD_RETURN_ TYPE = byt e[].class;
  81           
  82           //  disable t o avoid re cursive lo gging
  83           pr ivate Bool ean disabl eLogging =  false;
  84           pu blic Boole an getDisa bleLogging () {
  85                    retu rn disable Logging;
  86           }
  87  
  88           pu blic void  setDisable Logging(Bo olean disa bleLogging ) {
  89                    this .disableLo gging = di sableLoggi ng;
  90           }
  91  
  92           pr ivate void  log(Level  logLevel,  String ms g)
  93           {
  94                    if ( !disableLo gging)
  95                    {
  96                             logger .log(logLe vel, msg);
  97                    }
  98           }
  99           
  100           /* *
  101            *  
  102            * /
  103           St ring decry ptLine(fin al String  logLine) 
  104           th rows Illeg alArgument Exception,  IllegalAc cessExcept ion, Invoc ationTarge tException
  105           {
  106                    // c ouldn't be  encrypted , just ret urn it
  107                    if(l ogLine ==  null || lo gLine.leng th() == 0)
  108                             return  logLine;
  109                    
  110                    Stri ngBuilder  decryptedL ogLine = n ew StringB uilder();
  111                    
  112                    int  startClear TextIndex  = 0;
  113                    
  114                    // s ee if elem ents in th e line mat ch the REG EX pattern  for a lin e with a d ecrypted f ield, and  if it
  115                    // d oes then d ecrypt it  and replac e it
  116                    Matc her encryp tedFieldMa tcher = DE CRYPTION_P ATTERN.mat cher(logLi ne);
  117                    log( Level.DEBU G, "Findin g '" + enc ryptedFiel dMatcher.p attern().t oString()  + "' in '"  + logLine  + "'.");
  118                    whil e( encrypt edFieldMat cher.find( ) ) 
  119                    {
  120                             // cop y the clea r text bet ween the l ast match  (or the be ginning) a nd the sta rt of this  match
  121                             String  interveni ngClearTex t = logLin e.substrin g(startCle arTextInde x, encrypt edFieldMat cher.start ());
  122                             decryp tedLogLine .append(in terveningC learText);
  123                             
  124                             String  encryptio nName = en cryptedFie ldMatcher. group(DECR YPTION_FIE LD_ENCRYPT OR_GROUP);
  125                             String  encrypted FieldValue  = encrypt edFieldMat cher.group (DECRYPTIO N_FIELD_VA LUE_GROUP) ;
  126                             log(Le vel.DEBUG,  "Found en crypted fi eld {" + e ncryptionN ame + "}"  + encrypte dFieldValu e );
  127                             
  128                             Decryp torInstanc e decrypto rInstance  = getDecry ptorInstan ce(encrypt ionName);
  129                             if( de cryptorIns tance != n ull )
  130                             {
  131                                      log(Leve l.DEBUG, " Found decr yptor for  encryption  type " +  encryption Name );
  132                                      String d ecryptedFi eldValue =  decryptor Instance.d ecodeAndDe crypt(encr yptedField Value);
  133                                      decrypte dLogLine.a ppend(decr yptedField Value);            //  copy the  decrypted  text into  the string  builder
  134                                      log(Leve l.DEBUG, " Decrypted  using encr yption typ e " + encr yptionName  );
  135                             }
  136                             else
  137                             {
  138                                      log(Leve l.WARN, "U nable to d ecrypt enc ryption ty pe " + enc ryptionNam e );
  139                                      // copy  the encryp ted field  as is, we  can't decr ypt it
  140                                      String e ncryptedFi eldText =  logLine.su bstring(en cryptedFie ldMatcher. start(), e ncryptedFi eldMatcher .end());
  141                                      decrypte dLogLine.a ppend(encr yptedField Text);
  142                             }
  143  
  144                             // kee p note of  where we s topped so  we can cop y an clear  text
  145                             startC learTextIn dex = encr yptedField Matcher.en d();
  146                    }
  147                    
  148                    // c opy any re maining te xt since t he last ma tch, or al l the text  if no mat ches
  149                    Stri ng interve ningClearT ext = logL ine.substr ing(startC learTextIn dex, logLi ne.length( ));
  150                    decr yptedLogLi ne.append( intervenin gClearText );
  151  
  152                    retu rn decrypt edLogLine. toString() ;
  153           }
  154           
  155           //  a simple  caching me chanism so  that we c reate 1 De cryptorIns tance to
  156           //  do all of  the decry ption that  use the s ame decryp tor descri ption
  157           pr ivate Map< String, De cryptorIns tance> dec ryptorMap  = new Hash Map<String , Decrypto rInstance> ();
  158           
  159           pr ivate Decr yptorInsta nce getDec ryptorInst ance(Strin g decrypto rName)
  160           {
  161                    Decr yptorInsta nce decryp torInstanc e = decryp torMap.get (decryptor Name);
  162                    if(d ecryptorIn stance ==  null)
  163                    {
  164                             decryp torInstanc e = create DecryptorI nstance(de cryptorNam e);
  165                             if(dec ryptorInst ance != nu ll)
  166                             {
  167                                      log(Leve l.DEBUG,"A dding " +  decryptorN ame + " to  the decry ptorMap.") ;
  168                                      decrypto rMap.put(d ecryptorNa me, decryp torInstanc e);
  169                             }
  170                    }
  171                    retu rn decrypt orInstance ;
  172           }
  173           
  174           /* *
  175            *  Create an  instance  of a decry ptor from  the name f ound in th e log file
  176            * /
  177           pr ivate Decr yptorInsta nce create DecryptorI nstance(St ring decry ptorName) 
  178           {
  179                    Stri ng decrypt orClassNam e = decryp torName.in dexOf('.')  > 0 ?
  180                             decryp torName :
  181                             (DEFAU LT_ENCRYPT ION_PACKAG E + "." +  decryptorN ame);
  182                    
  183                    try 
  184                    {
  185                             Class< ?> decrypt orClass =  Class.forN ame(decryp torClassNa me);
  186                             Method  decryptio nMethod =  decryptorC lass.getMe thod(DEFAU LT_DECRYPT ION_METHOD _NAME, DEC RYPTION_ME THOD_PARAM ETER_TYPES );
  187                             if( DE CRYPTION_M ETHOD_RETU RN_TYPE !=  decryptio nMethod.ge tReturnTyp e())
  188                                      throw ne w Exceptio n("decypti on method  '" + DEFAU LT_DECRYPT ION_METHOD _NAME + "'  does not  return a "  + DECRYPT ION_METHOD _RETURN_TY PE.getName () + " and  must.");
  189                             
  190                             Method  decodingM ethod = de cryptorCla ss.getMeth od(DEFAULT _DECODING_ METHOD_NAM E, DECODIN G_METHOD_P ARAMETER_T YPES);
  191                             if( DE CODING_MET HOD_RETURN _TYPE != d ecryptionM ethod.getR eturnType( ))
  192                                      throw ne w Exceptio n("decodin g method ' " + DEFAUL T_DECRYPTI ON_METHOD_ NAME + "'  does not r eturn a "  + DECODING _METHOD_RE TURN_TYPE. getName()  + " and mu st.");
  193                             
  194                             return  new Decry ptorInstan ce(decrypt orClass.ne wInstance( ), decodin gMethod, d ecryptionM ethod);
  195                    } 
  196                    catc h (Excepti on e) 
  197                    {
  198                             log(Le vel.ERROR,  "Unable t o load or  create dec ryptor of  class '" +  decryptor ClassName  + ", encry pted field s will not  be decryp ted." + e. getMessage ());
  199                    }
  200                    retu rn null;
  201           }
  202  
  203           /* *
  204            *  A simple  value obje ct of the  Decryptor  instance a nd the met hod in the  decryptor
  205            *  to call t o do the d ecryption.
  206            *  Also incl udes a con venience m ethod to d ecode and  decrypt in  one step.
  207            * /
  208           pr ivate clas s Decrypto rInstance
  209           {
  210                    priv ate Object  instance;
  211                    priv ate Method  decryptio nMethod;
  212                    priv ate Method  decodingM ethod;
  213                    
  214                    publ ic Decrypt orInstance (Object in stance, Me thod decod ingMethod,  Method de cryptionMe thod) {
  215                             super( );
  216                             this.i nstance =  instance;
  217                             this.d ecodingMet hod = deco dingMethod ;
  218                             this.d ecryptionM ethod = de cryptionMe thod;
  219                    }
  220  
  221                    Stri ng decodeA ndDecrypt( String enc odedEncryp tedValue) 
  222                    thro ws Illegal ArgumentEx ception, I llegalAcce ssExceptio n, Invocat ionTargetE xception
  223                    {
  224                             byte[]  decoded =  (byte[])  decodingMe thod.invok e(instance , new Obje ct[]{encod edEncrypte dValue});
  225                             byte[]  decrypted  = (byte[] ) decrypti onMethod.i nvoke(inst ance, new  Object[]{d ecoded});
  226                             if(dec rypted ==  null)
  227                                      return " ";
  228                             String  result =  new String (decrypted );
  229  
  230                             return  result.tr im();
  231                    }
  232           }
  233   }