Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ProtectDebugInfo: allow wiping of TLVList items. #165

Merged
merged 2 commits into from
Jul 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*.swp
.DS_Store
modules/*/bin
.vscode/
# IDEA Ignores
*.iml
*.ipr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOUtil;
import org.jpos.tlv.TLVList;
import org.jpos.util.FSDMsg;
import org.jpos.util.ProtectedLogListener;

Expand All @@ -41,6 +42,7 @@
* <property name="protect-entry" value="REQUEST" />
* <property name="protect-entry" value="RESPONSE" />
* <property name="protect-entry" value="PAN" />
* <property name="protect-entry" value="REQUEST_ICC_DATA" />
*
* <property name="wipe-entry" value="EXPDATE" />
*
Expand All @@ -49,6 +51,11 @@
* <property name="protect-ISOMsg" value="45" />
* <property name="wipe-ISOMsg" value="52" />
* <property name="wipe-ISOMsg" value="55" />
*
* <property name="wipe-TLVList" value="0x56" />
* <property name="wipe-TLVList" value="0x57" />
* <property name="wipe-TLVList" value="0x5a" />
* <property name="wipe-TLVList" value="0x5f20" />
*
* <property name="protect-FSDMsg" value="account-number" />
* <property name="protect-FSDMsg" value="track2-data" />
Expand All @@ -62,6 +69,7 @@ public class ProtectDebugInfo extends TxnSupport implements AbortParticipant {
private String[] protectFSD;
private String[] protectISO;
private String[] wipeISO;
private String[] wipeTLV;

public int prepare (long id, Serializable o) {
return PREPARED | READONLY;
Expand Down Expand Up @@ -105,6 +113,13 @@ private void protect (Context ctx) {
if (p != null){
ctx.put(s, protect (p));
}
}
if (o instanceof TLVList) {
TLVList tlv = ctx.get(s);
if (tlv != null) {
for (String t: wipeTLV)
wipeTag(tlv, t);
}
}
}
}
Expand All @@ -131,6 +146,19 @@ private void wipeField (ISOMsg m, String f) {
}
}

static void wipeTag(TLVList tlv, String tag) {
if (tlv == null)
return;
try {
int tagName = Integer.decode(tag);
if (tlv.hasTag(tagName)) {
tlv.deleteByTag(tagName);
tlv.append(tagName, ProtectedLogListener.BINARY_WIPED);
}
}
catch (Throwable ignored) { }
}

private void protectField (FSDMsg m, String f) {
if (f != null) {
String s = m.get (f);
Expand All @@ -153,9 +181,8 @@ public void setConfiguration (Configuration cfg)
this.protectedEntrys = cfg.getAll("protect-entry");
this.wipedEntrys = cfg.getAll("wipe-entry");
this.protectFSD = cfg.getAll("protect-FSDMsg");

this.protectISO = cfg.getAll("protect-ISOMsg");
this.wipeISO = cfg.getAll("wipe-ISOMsg");
this.wipeTLV = cfg.getAll("wipe-TLVList");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jpos.transaction;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.jpos.core.ConfigurationException;
import org.jpos.core.SimpleConfiguration;
import org.jpos.tlv.TLVList;
import org.junit.jupiter.api.Test;

public final class ProtectDebugInfoTest {

@Test
void test_wipe_tag() throws ConfigurationException {

TLVList tlv = new TLVList();
tlv.append(0x54, "AABBCCDDEEFF");
tlv.append(0x55, "BBDDFFEEDDAA");

SimpleConfiguration cfg = new SimpleConfiguration();
cfg.put("protect-entry", "TEST_ENTRY");
cfg.put("wipe-TLVList", "0x54");

ProtectDebugInfo participant = new ProtectDebugInfo();
participant.setConfiguration(cfg);

Context ctx = new Context();
ctx.put("TEST_ENTRY", tlv);

participant.commit(0, ctx);

ctx.dump(System.out, " ");
assertNotEquals("AABBCCDDEEFF", tlv.getString(0x54));
assertEquals("BBDDFFEEDDAA", tlv.getString(0x55));
}
}