@Test public void testFilter() throws Throwable { MD5Filter mD5Filter = new MD5Filter(); mD5Filter.setConfiguration(new SimpleConfiguration()); ISOMsg m = new ISOMsg("testMD5FilterMti"); m.setDirection(2); ISOMsg result = mD5Filter.filter(new ASCIIChannel(new EuroSubFieldPackager()), m, new LogEvent()); assertEquals(128, m.getMaxField(), "m.getMaxField()"); assertSame(m, result, "result"); }
public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException { if (key == null || fields == null) throw new VetoException ("MD5Filter not configured"); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update (getKey()); int[] f = getFields (m); for (int fld : f) { if (m.hasField(fld)) { ISOComponent c = m.getComponent(fld); if (c instanceof ISOBinaryField) md.update((byte[]) c.getValue()); else md.update(((String) c.getValue()).getBytes()); } } byte[] digest = md.digest(); if (m.getDirection() == ISOMsg.OUTGOING) { m.set (new ISOBinaryField ( 64, digest, 0, 8)); m.set (new ISOBinaryField (128, digest, 8, 8)); } else { byte[] rxDigest = new byte[16]; if (m.hasField (64)) System.arraycopy ( m.getValue(64), 0, rxDigest, 0, 8 ); if (m.hasField (128)) System.arraycopy ( m.getValue(128), 0, rxDigest, 8, 8 ); if (!Arrays.equals (digest, rxDigest)) { evt.addMessage (m); evt.addMessage ("MAC expected: " +ISOUtil.hexString (digest)); evt.addMessage ("MAC received: " +ISOUtil.hexString (rxDigest)); throw new VetoException ("invalid MAC"); } m.unset (64); m.unset (128); } } catch (NoSuchAlgorithmException e) { throw new VetoException (e); } catch (ISOException e) { throw new VetoException (e); } return m; }
MD5Filter implements ISOFilter, Configurable { public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException { if (key == null || fields == null) throw new VetoException ("MD5Filter not configured"); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update (getKey()); int[] f = getFields (m); for (int fld : f) { if (m.hasField(fld)) { ISOComponent c = m.getComponent(fld); if (c instanceof ISOBinaryField) md.update((byte[]) c.getValue()); else md.update(((String) c.getValue()).getBytes()); } } byte[] digest = md.digest(); if (m.getDirection() == ISOMsg.OUTGOING) { m.set (new ISOBinaryField ( 64, digest, 0, 8)); m.set (new ISOBinaryField (128, digest, 8, 8)); } else { byte[] rxDigest = new byte[16]; if (m.hasField (64)) System.arraycopy ( m.getValue(64), 0, rxDigest, 0, 8 ); if (m.hasField (128)) System.arraycopy ( m.getValue(128), 0, rxDigest, 8, 8 ); if (!Arrays.equals (digest, rxDigest)) { evt.addMessage (m); evt.addMessage ("MAC expected: " +ISOUtil.hexString (digest)); evt.addMessage ("MAC received: " +ISOUtil.hexString (rxDigest)); throw new VetoException ("invalid MAC"); } m.unset (64); m.unset (128); } } catch (NoSuchAlgorithmException e) { throw new VetoException (e); } catch (ISOException e) { throw new VetoException (e); } return m; } }
MD5Filter implements ISOFilter, Configurable { public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException { if (key == null || fields == null) throw new VetoException ("MD5Filter not configured"); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update (getKey()); int[] f = getFields (m); for (int fld : f) { if (m.hasField(fld)) { ISOComponent c = m.getComponent(fld); if (c instanceof ISOBinaryField) md.update((byte[]) c.getValue()); else md.update(((String) c.getValue()).getBytes()); } } byte[] digest = md.digest(); if (m.getDirection() == ISOMsg.OUTGOING) { m.set (new ISOBinaryField ( 64, digest, 0, 8)); m.set (new ISOBinaryField (128, digest, 8, 8)); } else { byte[] rxDigest = new byte[16]; if (m.hasField (64)) System.arraycopy ( m.getValue(64), 0, rxDigest, 0, 8 ); if (m.hasField (128)) System.arraycopy ( m.getValue(128), 0, rxDigest, 8, 8 ); if (!Arrays.equals (digest, rxDigest)) { evt.addMessage (m); evt.addMessage ("MAC expected: " +ISOUtil.hexString (digest)); evt.addMessage ("MAC received: " +ISOUtil.hexString (rxDigest)); throw new VetoException ("invalid MAC"); } m.unset (64); m.unset (128); } } catch (NoSuchAlgorithmException e) { throw new VetoException (e); } catch (ISOException e) { throw new VetoException (e); } return m; } MD5Filter(); }
MD5Filter implements ISOFilter, Configurable { public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException { if (key == null || fields == null) throw new VetoException ("MD5Filter not configured"); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update (getKey()); int[] f = getFields (m); for (int fld : f) { if (m.hasField(fld)) { ISOComponent c = m.getComponent(fld); if (c instanceof ISOBinaryField) md.update((byte[]) c.getValue()); else md.update(((String) c.getValue()).getBytes()); } } byte[] digest = md.digest(); if (m.getDirection() == ISOMsg.OUTGOING) { m.set (new ISOBinaryField ( 64, digest, 0, 8)); m.set (new ISOBinaryField (128, digest, 8, 8)); } else { byte[] rxDigest = new byte[16]; if (m.hasField (64)) System.arraycopy ( m.getValue(64), 0, rxDigest, 0, 8 ); if (m.hasField (128)) System.arraycopy ( m.getValue(128), 0, rxDigest, 8, 8 ); if (!Arrays.equals (digest, rxDigest)) { evt.addMessage (m); evt.addMessage ("MAC expected: " +ISOUtil.hexString (digest)); evt.addMessage ("MAC received: " +ISOUtil.hexString (rxDigest)); throw new VetoException ("invalid MAC"); } m.unset (64); m.unset (128); } } catch (NoSuchAlgorithmException e) { throw new VetoException (e); } catch (ISOException e) { throw new VetoException (e); } return m; } MD5Filter(); void setConfiguration(Configuration cfg); void setFields(int[] fields); int[] getFields(ISOMsg m); ISOMsg filter(ISOChannel channel, ISOMsg m, LogEvent evt); }
MD5Filter implements ISOFilter, Configurable { public ISOMsg filter (ISOChannel channel, ISOMsg m, LogEvent evt) throws VetoException { if (key == null || fields == null) throw new VetoException ("MD5Filter not configured"); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update (getKey()); int[] f = getFields (m); for (int fld : f) { if (m.hasField(fld)) { ISOComponent c = m.getComponent(fld); if (c instanceof ISOBinaryField) md.update((byte[]) c.getValue()); else md.update(((String) c.getValue()).getBytes()); } } byte[] digest = md.digest(); if (m.getDirection() == ISOMsg.OUTGOING) { m.set (new ISOBinaryField ( 64, digest, 0, 8)); m.set (new ISOBinaryField (128, digest, 8, 8)); } else { byte[] rxDigest = new byte[16]; if (m.hasField (64)) System.arraycopy ( m.getValue(64), 0, rxDigest, 0, 8 ); if (m.hasField (128)) System.arraycopy ( m.getValue(128), 0, rxDigest, 8, 8 ); if (!Arrays.equals (digest, rxDigest)) { evt.addMessage (m); evt.addMessage ("MAC expected: " +ISOUtil.hexString (digest)); evt.addMessage ("MAC received: " +ISOUtil.hexString (rxDigest)); throw new VetoException ("invalid MAC"); } m.unset (64); m.unset (128); } } catch (NoSuchAlgorithmException e) { throw new VetoException (e); } catch (ISOException e) { throw new VetoException (e); } return m; } MD5Filter(); void setConfiguration(Configuration cfg); void setFields(int[] fields); int[] getFields(ISOMsg m); ISOMsg filter(ISOChannel channel, ISOMsg m, LogEvent evt);  }