Search in sources :

Example 61 with SimpleConfiguration

use of org.jpos.core.SimpleConfiguration in project jPOS by jpos.

the class StatefulFilterTest method testSetConfiguration.

@Test
public void testSetConfiguration() throws Throwable {
    StatefulFilter statefulFilter = new StatefulFilter();
    int[] ignoredFields = new int[0];
    statefulFilter.setIgnoredFields(ignoredFields);
    statefulFilter.setConfiguration(new SimpleConfiguration());
    assertTrue("m_statefulFilter.isOverwriteOriginalFields()", statefulFilter.isOverwriteOriginalFields());
    assertEquals("m_statefulFilter.getSavedFields().length", 0, statefulFilter.getSavedFields().length);
    assertEquals("m_statefulFilter.getIgnoredFields().length", 0, statefulFilter.getIgnoredFields().length);
    assertEquals("m_statefulFilter.getKey().length", 2, statefulFilter.getKey().length);
    assertFalse("m_statefulFilter.isVetoUnmatched()", statefulFilter.isVetoUnmatched());
    assertEquals("m_statefulFilter.getMatchDirection()", 1, statefulFilter.getMatchDirection());
    assertEquals("m_statefulFilter.getTimeout()", 60000L, statefulFilter.getTimeout());
}
Also used : SimpleConfiguration(org.jpos.core.SimpleConfiguration) Test(org.junit.Test)

Example 62 with SimpleConfiguration

use of org.jpos.core.SimpleConfiguration in project jPOS by jpos.

the class GenericPackagerTest method testSetConfigurationThrowsConfigurationException.

@Ignore("test failing")
@Test
public void testSetConfigurationThrowsConfigurationException() throws Throwable {
    GenericPackager genericPackager = new GenericPackager();
    Configuration cfg = new SimpleConfiguration();
    try {
        genericPackager.setConfiguration(cfg);
        fail("Expected ConfigurationException to be thrown");
    } catch (ConfigurationException ex) {
        assertEquals("ex.getMessage()", "org.jpos.iso.ISOException: java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl (java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl)", ex.getMessage());
        assertEquals("ex.getNested().getMessage()", "java.lang.ClassNotFoundException: org.apache.crimson.parser.XMLReaderImpl", ex.getNested().getMessage());
        assertEquals("(GenericValidatingPackager) genericValidatingPackager.getLogger().getName()", "", genericPackager.getLogger().getName());
        assertEquals("(GenericValidatingPackager) genericValidatingPackager.getRealm()", "", genericPackager.getRealm());
    }
}
Also used : SubConfiguration(org.jpos.core.SubConfiguration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Configuration(org.jpos.core.Configuration) ConfigurationException(org.jpos.core.ConfigurationException) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 63 with SimpleConfiguration

use of org.jpos.core.SimpleConfiguration in project jPOS by jpos.

the class JPOSLogger method isLevelEnabled.

protected boolean isLevelEnabled(int logLevel) {
    Logger logger = log.getLogger();
    Configuration cfg = logger.getConfiguration();
    if (cfg == null)
        cfg = new SimpleConfiguration();
    String levelString = cfg.get("slf4j.level", System.getProperty("slf4j.level"));
    int currentLogLevel = levelString != null ? stringToLevel(levelString) : DEFAULT_LOG_LEVEL;
    return (logLevel >= currentLogLevel);
}
Also used : Configuration(org.jpos.core.Configuration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Logger(org.jpos.util.Logger) LocationAwareLogger(org.slf4j.spi.LocationAwareLogger)

Example 64 with SimpleConfiguration

use of org.jpos.core.SimpleConfiguration in project jPOS by jpos.

the class SimpleConfigurationFactory method getConfiguration.

public Configuration getConfiguration(Element e) throws ConfigurationException {
    Properties props = new Properties();
    Iterator iter = e.getChildren("property").iterator();
    while (iter.hasNext()) {
        Element property = (Element) iter.next();
        String name = property.getAttributeValue("name");
        String value = property.getAttributeValue("value");
        String file = property.getAttributeValue("file");
        if (file != null)
            try {
                props.load(new FileInputStream(new File(file)));
            } catch (Exception ex) {
                throw new ConfigurationException(file, ex);
            }
        else if (name != null && value != null) {
            Object obj = props.get(name);
            if (obj instanceof String[]) {
                String[] mobj = (String[]) obj;
                String[] m = new String[mobj.length + 1];
                System.arraycopy(mobj, 0, m, 0, mobj.length);
                m[mobj.length] = value;
                props.put(name, m);
            } else if (obj instanceof String) {
                String[] m = new String[2];
                m[0] = (String) obj;
                m[1] = value;
                props.put(name, m);
            } else
                props.put(name, value);
        }
    }
    return new SimpleConfiguration(props);
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) Element(org.jdom2.Element) Iterator(java.util.Iterator) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) ConfigurationException(org.jpos.core.ConfigurationException)

Example 65 with SimpleConfiguration

use of org.jpos.core.SimpleConfiguration in project jPOS by jpos.

the class Console method exec.

public void exec(PrintStream outPS, PrintStream errPS, String[] args) {
    JCESecurityModule sm = new JCESecurityModule();
    Logger logger = new Logger();
    logger.addListener(new SimpleLogListener(outPS));
    sm.setLogger(logger, "jce-security-module");
    Properties cfgProps = new Properties();
    SimpleConfiguration cfg = new SimpleConfiguration(cfgProps);
    String commandName = null;
    // 10 is Maximum number of paramters for a command
    String[] commandParams = new String[10];
    outPS.println("Welcome to JCE Security Module console commander!");
    if (args.length == 0) {
        outPS.println("Usage: Console [-options] command [commandparameters...]");
        outPS.println("\nwhere options include:");
        outPS.println("    -lmk <filename>");
        outPS.println("                  to specify the Local Master Keys file");
        outPS.println("    -rebuildlmk   to rebuild new Local Master Keys");
        outPS.println("                  WARNING: old Local Master Keys gets overwritten");
        outPS.println("    -jce <provider classname>");
        outPS.println("                  to specify a JavaTM Cryptography Extension 1.2.1 provider");
        outPS.println("\nWhere command include: ");
        outPS.println("    GC <keyLength>");
        outPS.println("                  to generate a clear key component.");
        outPS.println("    FK <keyLength> <keyType> <component1> <component2> <component3>");
        outPS.println("                  to form a key from three clear components.");
        outPS.println("                  and returns the key encrypted under LMK");
        outPS.println("                  Odd parity is be forced before encryption under LMK");
        outPS.println("    CK <keyLength> <keyType> <KEYunderLMK>");
        outPS.println("                  to generate a key check value for a key encrypted under LMK.");
        outPS.println("    IK <keyLength> <keyType> <KEYunderKEK> ");
        outPS.println("       <kekLength> <kekType> <KEKunderLMK> <KEKcheckValue>");
        outPS.println("                  to import a key from encryption under KEK (eg. ZMK,TMK) to encryption under LMK");
        outPS.println("                  Odd parity is be forced before encryption under LMK");
        outPS.println("    KE <keyLength> <keyType> <KEYunderLMK> <KEYcheckValue> ");
        outPS.println("       <kekLength> <kekType> <KEKunderLMK> <KEKcheckValue> ");
        outPS.println("                  to translate (export) a key from encryption under LMK");
        outPS.println("                  to encryption under KEK (eg. ZMK,TMK)");
    } else {
        int argsCounter = 0;
        for (int j = 0; j < 10; j++) {
            if (argsCounter < args.length && args[argsCounter].toLowerCase().compareTo("-lmk") == 0) {
                argsCounter++;
                cfgProps.setProperty("lmk", args[argsCounter++]);
            }
            if (argsCounter < args.length && args[argsCounter].toLowerCase().compareTo("-jce") == 0) {
                argsCounter++;
                cfgProps.setProperty("provider", args[argsCounter++]);
            }
            if (argsCounter < args.length && args[argsCounter].toLowerCase().compareTo("-rebuildlmk") == 0) {
                argsCounter++;
                cfgProps.setProperty("rebuildlmk", "true");
            }
        }
        if (argsCounter < args.length) {
            commandName = args[argsCounter++];
            int i = 0;
            while (argsCounter < args.length) {
                commandParams[i++] = args[argsCounter++];
            }
        }
        // Configure JCE Security Module
        try {
            sm.setConfiguration(cfg);
        } catch (ConfigurationException e) {
            e.printStackTrace(errPS);
            return;
        }
        // Execute Command
        if (commandName != null) {
            try {
                short keyLength = (short) Integer.parseInt(commandParams[0]);
                if (commandName.toUpperCase().compareTo("GC") == 0) {
                    String clearKeyComponenetHexString = sm.generateClearKeyComponent(keyLength);
                } else if (commandName.toUpperCase().compareTo("FK") == 0) {
                    SecureDESKey KEYunderLMK = sm.formKEYfromThreeClearComponents(keyLength, commandParams[1].toUpperCase(), commandParams[2], commandParams[3], commandParams[4]);
                } else if (commandName.toUpperCase().compareTo("CK") == 0) {
                    byte[] keyCheckValue = sm.generateKeyCheckValue(new SecureDESKey(keyLength, commandParams[1].toUpperCase(), commandParams[2], ""));
                } else if (commandName.toUpperCase().compareTo("IK") == 0) {
                    SecureDESKey KEKunderLMK = new SecureDESKey((short) Integer.parseInt(commandParams[3]), commandParams[4].toUpperCase(), commandParams[5], commandParams[6]);
                    sm.importKey(keyLength, commandParams[1].toUpperCase(), ISOUtil.hex2byte(commandParams[2]), KEKunderLMK, true);
                } else if (commandName.toUpperCase().compareTo("KE") == 0) {
                    SecureDESKey KEKunderLMK = new SecureDESKey((short) Integer.parseInt(commandParams[4]), commandParams[5].toUpperCase(), commandParams[6], commandParams[7]);
                    SecureDESKey KEYunderLMK = new SecureDESKey(keyLength, commandParams[1].toUpperCase(), commandParams[2], commandParams[3]);
                    sm.exportKey(KEYunderLMK, KEKunderLMK);
                } else {
                    System.err.println("Unknown command: " + commandName);
                }
            } catch (SMException e) {
                e.printStackTrace(errPS);
            } catch (java.lang.NumberFormatException e) {
                errPS.println("Invalid KeyLength");
            }
        } else {
            errPS.println("No command specified");
        }
    }
}
Also used : SMException(org.jpos.security.SMException) Logger(org.jpos.util.Logger) Properties(java.util.Properties) SimpleLogListener(org.jpos.util.SimpleLogListener) ConfigurationException(org.jpos.core.ConfigurationException) SimpleConfiguration(org.jpos.core.SimpleConfiguration) SecureDESKey(org.jpos.security.SecureDESKey)

Aggregations

SimpleConfiguration (org.jpos.core.SimpleConfiguration)65 Test (org.junit.Test)55 Configuration (org.jpos.core.Configuration)24 SubConfiguration (org.jpos.core.SubConfiguration)15 ISOMsg (org.jpos.iso.ISOMsg)15 Properties (java.util.Properties)14 LogEvent (org.jpos.util.LogEvent)14 ConfigurationException (org.jpos.core.ConfigurationException)9 ASCIIChannel (org.jpos.iso.channel.ASCIIChannel)7 ISOFilter (org.jpos.iso.ISOFilter)6 Logger (org.jpos.util.Logger)6 GZIPChannel (org.jpos.iso.channel.GZIPChannel)4 ISOBaseValidatingPackager (org.jpos.iso.packager.ISOBaseValidatingPackager)4 PostChannel (org.jpos.iso.channel.PostChannel)3 PostPackager (org.jpos.iso.packager.PostPackager)3 XMLPackager (org.jpos.iso.packager.XMLPackager)3 BASE24TCPChannel (org.jpos.iso.channel.BASE24TCPChannel)2 LogChannel (org.jpos.iso.channel.LogChannel)2 PADChannel (org.jpos.iso.channel.PADChannel)2 Base1Packager (org.jpos.iso.packager.Base1Packager)2