314. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 12/5/2017 12:06:46 PM Central Standard 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.

314.1 Files compared

# Location File Last Modified
1 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\Log4JEncryption\main\src\java\gov\va\med\log4j\encryption EncryptingPatternLayout.java Mon Dec 4 21:34:30 2017 UTC
2 IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\Log4JEncryption\main\src\java\gov\va\med\log4j\encryption EncryptingPatternLayout.java Tue Dec 5 13:25:00 2017 UTC

314.2 Comparison summary

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

314.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

314.4 Active regular expressions

No regular expressions were active.

314.5 Comparison detail

  1   /**
  2    * Per VHA  Directive  2004-038,  this rout ine should  not be mo dified.
  3    * Propert y of the U S Governme nt.  No pe rmission t o copy or  redistribu te this so ftware is  given. 
  4    * Use of  unreleased  versions  of this so ftware req uires the  user to ex ecute a wr itten agre ement 
  5    * with th e VistA Im aging Nati onal Proje ct Office  of the Dep artment of  Veterans  Affairs.  
  6    * Please  contact th e National  Service D esk at  PHONE  or  PII                      in order t
  7    * reach t he VistA I maging Nat ional Proj ect office .
  8    * 
  9    * The Foo d and Drug  Administr ation clas sifies thi s software  as a medi cal device .  As such , it 
  10    * may not  be change d in any w ay.  Modif ications t o this sof tware may  result in  an adulter ated 
  11    * medical  device un der 21CFR,  the use o f which is  considere d to be a  violation  of US Fede ral Statut es.
  12    * 
  13    * Federal  law restr icts this  device to  use by or  on the ord er of eith er a licen sed practi tioner or  persons 
  14    * lawfull y engaged  in the man ufacture,  support, o r distribu tion of th e product.
  15    * 
  16    * Created : Mar 8, 2 012
  17    * Author:         
BECKEC
  18    */
  19   package go v.va.med.l og4j.encry ption;
  20  
  21   import jav a.nio.Byte Buffer;
  22   import jav a.nio.char set.Charse t;
  23   import jav a.util.Arr ayList;
  24   import jav a.util.Has hMap;
  25   import jav a.util.Lis t;
  26   import jav a.util.Lis tIterator;
  27   import jav a.util.Map ;
  28   import jav a.util.reg ex.Matcher ;
  29   import jav a.util.reg ex.Pattern ;
  30  
  31   import org .apache.lo gging.log4 j.core.Log Event;
  32   import org .apache.lo gging.log4 j.core.con fig.Config uration;
  33   import org .apache.lo gging.log4 j.core.lay out.Abstra ctStringLa yout;
  34   import org .apache.lo gging.log4 j.core.lay out.Patter nLayout;
  35   import org .apache.lo gging.log4 j.core.lay out.Patter nSelector;
  36   import org .apache.lo gging.log4 j.core.lay out.Abstra ctStringLa yout.Seria lizer;
  37   import org .apache.lo gging.log4 j.core.lay out.Patter nLayout.Se rializerBu ilder;
  38   import org .apache.lo gging.log4 j.core.pat tern.Regex Replacemen t;
  39  
  40  
  41   /**
  42    * @author         
BECKEC
  43    */
  44   public cla ss Encrypt ingPattern Layout
  45   extends Ab stractStri ngLayout
  46   {
  47       public  static fi nal String  DEFAULT_C ONVERSION_ PATTERN =  "%m%n";
  48  
  49       privat e final St ring conve rsionPatte rn;
  50       privat e final Pa tternSelec tor patter nSelector;
  51       privat e final Se rializer e ventSerial izer;
  52       
  53  
  54       privat e Encrypti ngPatternL ayout(fina l Configur ation conf ig, final  RegexRepla cement rep lace, fina l String e ventPatter n,
  55                final Pa tternSelec tor patter nSelector,  final Cha rset chars et, final  boolean al waysWriteE xceptions,
  56                final bo olean disa bleAnsi, f inal boole an noConso leNoAnsi,  final Stri ng headerP attern,
  57                final St ring foote rPattern)  {
  58           su per(config , charset,
  59                    newS erializerB uilder()
  60                             .setCo nfiguratio n(config)
  61                             .setRe place(repl ace)
  62                             .setPa tternSelec tor(patter nSelector)
  63                             .setAl waysWriteE xceptions( alwaysWrit eException s)
  64                             .setDi sableAnsi( disableAns i)
  65                             .setNo ConsoleNoA nsi(noCons oleNoAnsi)
  66                             .setPa ttern(head erPattern)
  67                             .build (),
  68                    newS erializerB uilder()
  69                             .setCo nfiguratio n(config)
  70                             .setRe place(repl ace)
  71                             .setPa tternSelec tor(patter nSelector)
  72                             .setAl waysWriteE xceptions( alwaysWrit eException s)
  73                             .setDi sableAnsi( disableAns i)
  74                             .setNo ConsoleNoA nsi(noCons oleNoAnsi)
  75                             .setPa ttern(foot erPattern)
  76                             .build ());
  77           th is.convers ionPattern  = eventPa ttern;
  78           th is.pattern Selector =  patternSe lector;
  79           th is.eventSe rializer =  newSerial izerBuilde r()
  80                    .set Configurat ion(config )
  81                    .set Replace(re place)
  82                    .set PatternSel ector(patt ernSelecto r)
  83                    .set AlwaysWrit eException s(alwaysWr iteExcepti ons)
  84                    .set DisableAns i(disableA nsi)
  85                    .set NoConsoleN oAnsi(noCo nsoleNoAns i)
  86                    .set Pattern(ev entPattern )
  87                    .set DefaultPat tern(DEFAU LT_CONVERS ION_PATTER N)
  88                    .bui ld();
  89       }
  90  
  91       public  static Se rializerBu ilder newS erializerB uilder() {
  92           re turn new S erializerB uilder();
  93       }
  94  
  95  
  96           pr ivate Stri ng key;
  97           pr ivate Stri ng transfo rmation;
  98           pr ivate Patt ernLayout  layout;
  99           
  100           //  e.g. %-20 .30c
  101           //  \\x2E - d ot
  102           //  \\x7B - {
  103           //  \\x7D - }
  104           pu blic final  static St ring FIELD _REGEX = " %((-)?[\\d ]*(\\x2E[\ \d]*)?)?(\ \x7B[\\w]* \\x7D)([cC dFlLmMnprt xX%])";
  105           pu blic final  static Pa ttern FIEL D_PATTERN  = Pattern. compile(FI ELD_REGEX) ;
  106           pu blic final  static in t TABBING_ GROUP = 1;
  107           pu blic final  static in t NEGATION _GROUP = 2 ;
  108           pu blic final  static in t FRACTION AL_GROUP =  3;
  109           pu blic final  static in t ENCRYPTI ON_GROUP =  4;
  110           pu blic final  static in t FIELD_GR OUP = 5;
  111  
  112           //  
  113           pr ivate Map< PatternLay outField,  String> fi eldEncrypt ion = new  HashMap<Pa tternLayou tField, St ring>();
  114           pr ivate fina l String t hisPackage Name = thi s.getClass ().getPack age().getN ame();
  115           pr ivate Stri ng cPatter n;
  116           
  117           /* *
  118            *  
  119            *  e.g. %d{D ATE} %5p [ %t] (%F:%L ) - %m%n
  120            * /
  121           pu blic void  setConvers ionPattern (String co nversionPa ttern)
  122           {
  123                    List <Encrypted Field> enc ryptedFiel ds = new A rrayList<E ncryptedFi eld>();
  124                    Matc her fieldM atcher = F IELD_PATTE RN.matcher (conversio nPattern);
  125                    
  126                    // f ind each o f the fiel ds that ar e expected  to be enc rypted
  127                    whil e( fieldMa tcher.find () )
  128                    {
  129                             String  group = f ieldMatche r.group();
  130                             System .out.print ln( "Encry pting " +  group);
  131                             
  132                             Matche r fieldCon tentMatche r = FIELD_ PATTERN.ma tcher(grou p);
  133                             if( !  fieldConte ntMatcher. matches()  )
  134                                      throw ne w IllegalS tateExcept ion("Unabl e to match  group " +  group + "  with patt ern " + FI ELD_PATTER N.pattern( ) + ".");
  135                             
  136                             String  encryptio n = fieldC ontentMatc her.group( ENCRYPTION _GROUP);
  137                             String  field = f ieldConten tMatcher.g roup(FIELD _GROUP);
  138                             
  139                             String Builder un encryptedF ield = new  StringBui lder(); 
  140                             unencr yptedField .append("% ");
  141                             if(fie ldContentM atcher.gro up(TABBING _GROUP) !=  null && f ieldConten tMatcher.g roup(TABBI NG_GROUP). length() >  0)
  142                                      unencryp tedField.a ppend(fiel dContentMa tcher.grou p(TABBING_ GROUP));
  143                             unencr yptedField .append(fi eld);
  144                             
  145                             String  unencrypt edFieldSpe cification  = unencry ptedField. toString() ;
  146                             
  147                             System .out.print ln( "Encry pting " +  field + "  with " + e ncryption  + " => " +  unencrypt edFieldSpe cification );
  148                             
  149                             encryp tedFields. add(new En cryptedFie ld(field.c harAt(0),  encryption , group, u nencrypted FieldSpeci fication)) ;
  150                    }
  151  
  152                    //
  153                    for( ListIterat or<Encrypt edField> i ter = encr yptedField s.listIter ator(); it er.hasNext (); )
  154                    {
  155                             Encryp tedField e ncryptedFi eld = iter .next();
  156                             conver sionPatter n = conver sionPatter n.replace( encryptedF ield.getEn cryptedFie ldSpecific ation(), e ncryptedFi eld.getUne ncryptedFi eldSpecifi cation() ) ;
  157                             
  158                             Patter nLayoutFie ld field =  PatternLa youtField. findByFiel dChar(encr yptedField .getField( ));
  159                             // rem ove the cu rly bracke ts before  saving the  encryptio n
  160                             fieldE ncryption. put(field,  encrypted Field.getE ncryption( ).substrin g(1, encry ptedField. getEncrypt ion().leng th()-1));
  161                             
  162                             iter.r emove();
  163                    }
  164                    
  165                    cPat tern = con versionPat tern;
  166           }
  167  
  168           pu blic Strin g getConve rsionPatte rn()
  169           {
  170                    retu rn cPatter n;
  171           }
  172  
  173           pu blic Strin g getKey()
  174           {
  175                    retu rn key;
  176           }
  177  
  178           pu blic void  setKey(Str ing key)
  179           {
  180                    this .key = key ;
  181           }
  182  
  183           pu blic Strin g getTrans formation( )
  184           {
  185                    retu rn transfo rmation;
  186           }
  187  
  188           pu blic void  setTransfo rmation(St ring trans formation)
  189           {
  190                    this .transform ation = tr ansformati on;
  191           }
  192  
  193   //      @O verride
  194   //      pu blic Strin g format(L oggingEven t event)
  195   //      {
  196   //               Stri ng categor y = event. fqnOfCateg oryClass;
  197   //               Stri ng logger  = event.ge tLoggerNam e();//getL ogger();
  198   //               long  timeStamp  = event.t imeStamp;   //getTime Stamp()
  199   //               Leve l level =  event.getL evel();
  200   //               Obje ct message  = event.g etMessage( );
  201   //               Stri ng threadN ame = even t.getThrea dName();
  202   //               Thro wableInfor mation thr owableInfo  = event.g etThrowabl eInformati on();
  203   //               Stri ng ndc = e vent.getND C();
  204   //               Loca tionInfo l ocationInf ormation =  event.get LocationIn formation( );
  205   //               //Ma p<?,?> pro perties =  event.getP roperties( );
  206   //               
  207   //               Stri ng categor yEncryptio n = this.f ieldEncryp tion.get(P atternLayo utField.CA TEGORY);
  208   //               Stri ng message Encryption  = this.fi eldEncrypt ion.get(Pa tternLayou tField.MES SAGE);
  209   //               Stri ng threadN ameEncrypt ion = this .fieldEncr yption.get (PatternLa youtField. THREAD);
  210   //               Stri ng ndcEncr yption = t his.fieldE ncryption. get(Patter nLayoutFie ld.NDC);
  211   //
  212   //               // l og4j 1.2.1 4 compatib le
  213   //               Logg ingEvent c lone = new  LoggingEv ent(
  214   //                        catego ry, 
  215   //                        Catego ry.getInst ance(logge r),
  216   //                        timeSt amp,
  217   //                        Priori ty.toPrior ity(level. toInt()),
  218   //                        messag eEncryptio n != null  ? encryptF ield(messa ge == null  ? "" : me ssage.toSt ring(), me ssageEncry ption) : m essage, 
  219   //                        throwa bleInfo !=  null ? th rowableInf o.getThrow able() : n ull
  220   //               );
  221  
  222                    // l og4j 1.2.1 6 compatib le
  223   //               Logg ingEvent c lone = new  LoggingEv ent(
  224   //                        catego ryEncrypti on != null  ? encrypt Field(cate gory, cate goryEncryp tion) : ca tegory, 
  225   //                        logger ,
  226   //                        timeSt amp, 
  227   //                        level,  
  228   //                        messag eEncryptio n != null  ? encryptF ield(messa ge.toStrin g(), messa geEncrypti on) : mess age, 
  229   //                        thread NameEncryp tion != nu ll ? encry ptField(th readName,  threadName Encryption ) : thread Name, 
  230   //                        throwa bleInfo, 
  231   //                        ndcEnc ryption !=  null ? en cryptField (ndc, ndcE ncryption)  : ndc, 
  232   //                        locati onInformat ion 
  233   //                        proper ties
  234   //               );
  235                    
  236   //               retu rn super.f ormat(clon e);
  237   //      }
  238  
  239           /* *
  240            *  
  241            *  @param cl eartext
  242            *  @param en cryption
  243            *  @return
  244            * /
  245           pr ivate Stri ng encrypt Field(Stri ng clearte xt, String  encryptio n)
  246           {
  247                    Fiel dEncryptor  fieldEncr yptor = ge tFieldEncr yptor(encr yption);
  248                    Byte Buffer cle ar = field Encryptor. getCharset ().encode( cleartext) ;
  249                    byte [] clearte xtBytes =  clear.arra y();
  250                    
  251                    byte [] encrypt edBytes =  fieldEncry ptor.encry pt(clearte xtBytes);
  252                    
  253                    Stri ng encoded  = fieldEn cryptor.en code(encry ptedBytes) ;
  254                    
  255                    retu rn "{" + e ncryption  + "}" + en coded;
  256           }
  257           
  258           pr ivate Map< String, Fi eldEncrypt or> fieldE ncryptors  = new Hash Map<String , FieldEnc ryptor>();
  259           pr ivate Fiel dEncryptor  getFieldE ncryptor(S tring encr yption)
  260           {
  261                    Fiel dEncryptor  fieldEncr yptor = nu ll;
  262                    
  263                    sync hronized ( fieldEncry ptors)
  264                    {
  265                             fieldE ncryptor =  fieldEncr yptors.get (encryptio n);
  266                             if(fie ldEncrypto r == null)
  267                             {
  268                                      // if th e encrypti on has a ' .' in it t hen it is  a fully qu alified cl ass name
  269                                      // else  it is assu med to be  in the sam e package  as this cl ass
  270                                      String f ieldEncryp torClassNa me = 
  271                                               encryption .indexOf(' .') > 0 ? 
  272                                                       en cryption :   
  273                                                       th isPackageN ame + "."  + encrypti on;
  274                                      try
  275                                      {
  276                                               @SuppressW arnings("u nchecked")
  277                                               Class<Fiel dEncryptor > fieldEnc ryptorClas s = (Class <FieldEncr yptor>)Cla ss.forName (fieldEncr yptorClass Name);
  278                                               fieldEncry ptor = fie ldEncrypto rClass.new Instance() ;
  279                                               fieldEncry ptors.put(  encryptio n, fieldEn cryptor );
  280                                      }
  281                                      catch (E xception e )
  282                                      {
  283                                               e.printSta ckTrace();
  284                                      }
  285                             }
  286                    }
  287                    
  288                    retu rn fieldEn cryptor;
  289           }
  290           
  291           //  ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========
  292           cl ass Encryp tedField
  293           {
  294                    priv ate final  char field ;
  295                    priv ate final  String enc ryption;
  296                    priv ate final  String enc ryptedFiel dSpecifica tion;
  297                    priv ate final  String une ncryptedFi eldSpecifi cation;
  298                    
  299                    publ ic Encrypt edField(ch ar field,  String enc ryption, S tring encr yptedField Specificat ion, Strin g unencryp tedFieldSp ecificatio n)
  300                    {
  301                             super( );
  302                             
  303                             this.f ield = fie ld;
  304                             this.e ncryption  = encrypti on;
  305                             this.e ncryptedFi eldSpecifi cation = e ncryptedFi eldSpecifi cation;
  306                             this.u nencrypted FieldSpeci fication =  unencrypt edFieldSpe cification ;
  307                    }
  308                    publ ic char ge tField()
  309                    {
  310                             return  this.fiel d;
  311                    }
  312                    publ ic String  getEncrypt ion()
  313                    {
  314                             return  this.encr yption;
  315                    }
  316                    publ ic String  getEncrypt edFieldSpe cification ()
  317                    {
  318                             return  encrypted FieldSpeci fication;
  319                    }
  320                    publ ic String  getUnencry ptedFieldS pecificati on()
  321                    {
  322                             return  unencrypt edFieldSpe cification ;
  323                    }
  324           }
  325           
  326           cl ass Encryp tionSpecif ication
  327           {
  328           }
  329  
  330  
  331       @Overr ide
  332       public  String to Serializab le(final L ogEvent ev ent) {
  333           re turn event Serializer .toSeriali zable(even t);
  334       }
  335   }