[Bedework-commit] rpiutil r89 - in trunk/src/edu/rpi/cmt: .
security security/pki
svnadmin at bedework.org
svnadmin at bedework.org
Sun Jul 13 22:41:35 EDT 2008
Author: douglm
Date: 2008-07-13 22:41:31 -0400 (Sun, 13 Jul 2008)
New Revision: 89
Added:
trunk/src/edu/rpi/cmt/security/
trunk/src/edu/rpi/cmt/security/pki/
trunk/src/edu/rpi/cmt/security/pki/PKITools.java
trunk/src/edu/rpi/cmt/security/pki/PkiUtil.java
Log:
Add some security classes.
Added: trunk/src/edu/rpi/cmt/security/pki/PKITools.java
===================================================================
--- trunk/src/edu/rpi/cmt/security/pki/PKITools.java (rev 0)
+++ trunk/src/edu/rpi/cmt/security/pki/PKITools.java 2008-07-14 02:41:31 UTC (rev 89)
@@ -0,0 +1,527 @@
+/* **********************************************************************
+ Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.cmt.security.pki;
+
+import org.apache.log4j.Logger;
+// import org.bouncycastle.jce.provider.BouncyCastleProvider;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.Key;
+import java.security.KeyFactory;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PrivateKey;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+
+import javax.crypto.Cipher;
+
+/** Tools to implement public key encryption.
+ * Modified by Mike Douglass to incorporate into CVS repository.
+ *
+ * User a encrypts with user b's public key.
+ * User b decrypts with their private key.
+ *
+ * Copyright (c) 2001
+ *
+ * @author Alan Powell (powela rpi.edu)
+ * @author Mike Douglass (douglm rpi.edu)
+ * @version 1.02
+ */
+public class PKITools {
+ private boolean debug;
+ private boolean verbose;
+
+ protected transient Logger log;
+
+ private static class Schema {
+ Provider p;
+ String pName;
+ String algorithm;
+ String keyFactory;
+
+ Schema(Provider p, String pName, String algorithm,
+ String keyFactory) {
+ this.p = p;
+ this.pName = pName;
+ this.algorithm = algorithm;
+ this.keyFactory = keyFactory;
+ }
+ }
+
+ Schema[] schemas = {
+ new Schema(null, null, "RSA", "RSA"),
+ // new Schema(new BouncyCastleProvider(), "BC", "RSA/ECB/PKCS1Padding", "RSA"),
+ };
+
+ Schema curSchema;
+
+ /**
+ * @author douglm
+ *
+ */
+ public static class PKIException extends Throwable {
+ /**
+ * @param t
+ */
+ public PKIException(Throwable t) {
+ super(t);
+ }
+
+ /**
+ * @param s
+ */
+ public PKIException(String s) {
+ super(s);
+ }
+ }
+
+ /**
+ * Constructor
+ */
+ public PKITools() {
+ this(true, false);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param verbose
+ * @param debug
+ */
+ public PKITools(boolean verbose, boolean debug) {
+ this.verbose = verbose;
+ this.debug = debug;
+
+ curSchema = schemas[0];
+ if (curSchema.p != null) {
+ Security.addProvider(curSchema.p);
+ }
+ }
+
+ /**
+ */
+ public class RSAKeys {
+ /** */
+ public byte[] privateKey;
+ /** */
+ public byte[] publicKey;
+ }
+
+ /**
+ * @param privKeyFile
+ * @param pubKeyFile
+ * @param append true to add the key to the files.
+ * @return RSAKeys
+ * @throws PKIException
+ */
+ public RSAKeys genRSAKeysIntoFiles(String privKeyFile,
+ String pubKeyFile,
+ boolean append) throws PKIException {
+ RSAKeys keys = genRSAKeys();
+
+ if (keys == null) {
+ return null;
+ }
+
+ try {
+ // write the encoded key to a file
+ writeFile(pubKeyFile, toHex(keys.publicKey), append);
+
+ if (debug & verbose) {
+ trace("Saving Private Key...");
+ }
+
+ // write the encoded key to a file
+ writeFile(privKeyFile, toHex(keys.privateKey), append);
+
+ return keys;
+ } catch(Throwable t) {
+ throw new PKIException(t);
+ }
+ }
+
+ /**
+ * @return RSAKeys
+ * @throws PKIException
+ */
+ public RSAKeys genRSAKeys() throws PKIException {
+ RSAKeys keys = new RSAKeys();
+
+ try {
+ SecureRandom secureRandom = new SecureRandom();
+ secureRandom.nextBytes(new byte[1]);
+ KeyPairGenerator rsaKeyGen;
+
+ if (curSchema.pName == null) {
+ rsaKeyGen = KeyPairGenerator.getInstance(curSchema.keyFactory);
+ } else {
+ rsaKeyGen = KeyPairGenerator.getInstance(curSchema.keyFactory,
+ curSchema.pName);
+ }
+
+ rsaKeyGen.initialize(1024, secureRandom);
+
+ if (verbose) {
+ trace("Generating keys...");
+ }
+
+ KeyPair rsaKeyPair = rsaKeyGen.generateKeyPair();
+
+ if (verbose) {
+ trace("Saving Public Key...");
+ }
+
+ keys.privateKey = rsaKeyPair.getPrivate().getEncoded();
+ keys.publicKey = rsaKeyPair.getPublic().getEncoded();
+
+ if (verbose) {
+ trace("Done...");
+ }
+
+ return keys;
+ } catch(Throwable t) {
+ throw new PKIException(t);
+ }
+ }
+
+ /**
+ * @param pubKeyFile
+ * @param item
+ * @param keyNum
+ * @return encrypted value
+ * @throws PKIException
+ */
+ public String encryptWithKeyFile(String pubKeyFile,
+ String item,
+ int keyNum) throws PKIException {
+ try {
+ if (verbose) {
+ trace("Reading Public Key from file...");
+ }
+
+ return encrypt(fromHex(getEncryptedKey(pubKeyFile, keyNum)), item);
+ } catch(Throwable t) {
+ throw new PKIException(t);
+ }
+ }
+
+ /**
+ * @param pubKeyBytes
+ * @param item
+ * @return encrypted value
+ * @throws PKIException
+ */
+ public String encrypt(byte[] pubKeyBytes,
+ String item) throws PKIException {
+ byte[] encryptedItem = null;
+ Cipher asymmetricCipher;
+
+ try {
+ X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(pubKeyBytes);
+ Key publicKey;
+
+ if (curSchema.pName == null) {
+ KeyFactory kf = KeyFactory.getInstance(curSchema.algorithm);
+ publicKey = kf.generatePublic(publicKeySpec);
+
+ asymmetricCipher = Cipher.getInstance(curSchema.algorithm);
+ } else {
+ KeyFactory kf = KeyFactory.getInstance(curSchema.algorithm,
+ curSchema.pName);
+ publicKey = kf.generatePublic(publicKeySpec);
+
+ asymmetricCipher = Cipher.getInstance(curSchema.algorithm,
+ curSchema.pName);
+ }
+
+ asymmetricCipher.init(Cipher.ENCRYPT_MODE, publicKey);
+ encryptedItem = asymmetricCipher.doFinal(item.getBytes());
+ if (verbose) {
+ trace("Item to be encrypted: " +item);
+ }
+ } catch(Throwable t) {
+ throw new PKIException(t);
+ }
+
+ return toHex(encryptedItem);
+ }
+
+ /**
+ * @param privKeyFile
+ * @param hexVal
+ * @param keyNum
+ * @return Decrypted value
+ * @throws PKIException
+ */
+ public String decryptWithKeyFile(String privKeyFile,
+ String hexVal,
+ int keyNum) throws PKIException {
+ return decrypt(fromHex(getEncryptedKey(privKeyFile, keyNum)), hexVal);
+ }
+
+ /**
+ * @param privKeyBytes
+ * @param hexVal
+ * @return String decrypted value
+ * @throws PKIException
+ */
+ public String decrypt(byte[] privKeyBytes,
+ String hexVal) throws PKIException {
+ Cipher asymmetricCipher;
+ byte[] eVal = fromHex(hexVal);
+
+ try {
+ PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privKeyBytes);
+ PrivateKey privateKey;
+
+ if (curSchema.pName == null) {
+ KeyFactory kf = KeyFactory.getInstance(curSchema.algorithm);
+ privateKey = kf.generatePrivate(privateKeySpec);
+
+ asymmetricCipher = Cipher.getInstance(curSchema.algorithm);
+ } else {
+ KeyFactory kf = KeyFactory.getInstance(curSchema.algorithm,
+ curSchema.pName);
+ privateKey = kf.generatePrivate(privateKeySpec);
+
+ asymmetricCipher = Cipher.getInstance(curSchema.algorithm,
+ curSchema.pName);
+ }
+
+ asymmetricCipher.init(Cipher.DECRYPT_MODE, privateKey);
+ byte[] decryptedItem = asymmetricCipher.doFinal(eVal);
+
+ return new String(decryptedItem);
+ } catch(Throwable t) {
+ throw new PKIException(t);
+ }
+ }
+
+ /**
+ * @param fileName
+ * @return number of keys in file.
+ * @throws PKIException
+ */
+ public int countKeys(String fileName) throws PKIException {
+ byte[] keys = getKeys(fileName);
+
+ int foundKeys = 0;
+ for (int i = 0; i <keys.length; i++) {
+ if (keys[i] != '\n') {
+ continue;
+ }
+
+ foundKeys++;
+ }
+
+ return foundKeys;
+ }
+
+ /* *************************************************************************
+ * Private methods
+ * ************************************************************************ */
+
+ private String getEncryptedKey(String fileName,
+ int keyNum) throws PKIException {
+ byte[] keys = getKeys(fileName);
+
+ int foundKeys = 0;
+ int keyStart = 0;
+ for (int i = 0; i <keys.length; i++) {
+ if (keys[i] != '\n') {
+ continue;
+ }
+
+ if (keyNum != foundKeys) {
+ keyStart = i + 1;
+ foundKeys++;
+ continue;
+ }
+
+ // At end of our key
+
+ int keyLen = i - keyStart;
+ byte[] key = new byte[keyLen];
+ System.arraycopy(keys, keyStart, key, 0, keyLen);
+
+ return new String(key);
+ }
+
+ throw new PKIException("Invalid key number");
+ }
+
+ private byte[] getKeys(String fileName) throws PKIException {
+ FileInputStream fstr = null;
+ byte[] keys = null;
+
+ try {
+ fstr = new FileInputStream(fileName);
+ keys = new byte[fstr.available()];
+ fstr.read(keys);
+ } catch(Throwable t) {
+ throw new PKIException(t);
+ } finally {
+ if (fstr != null) {
+ try {
+ fstr.close();
+ } catch (Throwable t) {}
+ }
+ }
+
+ return keys;
+ }
+
+ /** Write a single string to a file. Used to write keys
+ *
+ * @param fileName String file to write to
+ * @param s String to write
+ * @param append true to add the key to the file.
+ * @throws IOException
+ */
+ private void writeFile(String fileName,
+ String s,
+ boolean append) throws IOException {
+ FileOutputStream fstr = null;
+
+ try {
+ fstr = new FileOutputStream(fileName, append);
+ fstr.write(s.getBytes());
+
+ // Terminate key with newline
+ fstr.write('\n');
+
+ fstr.flush();
+ } finally {
+ if (fstr != null) {
+ fstr.close();
+ }
+ }
+ }
+
+ private static String toHex(byte[] byteArray) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < byteArray.length; i++) {
+ String s = Integer.toHexString(byteArray[i] & 0x000000FF);
+
+ if (s.length() == 1) {
+ sb.append("0");
+ }
+ sb.append(s);
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * @param val
+ * @return byte[]
+ */
+ public static byte[] fromHex(String val) {
+ if ((val == null) || (val.length() == 0)) {
+ return null;
+ }
+
+ int nBytes = val.length()/2;
+
+ byte[] bytes = new byte[nBytes];
+ int offset=0;
+
+ for(int i = 0; i < nBytes; i++) {
+ bytes[i] = (byte)(Integer.parseInt(val.substring(offset, offset + 2), 16) &
+ 0x000000FF);
+ offset += 2;
+ }
+
+ return bytes;
+ }
+
+ /* *
+ * @param str
+ * @return byte[]
+ * /
+ public static byte[] fromHex(String str) {
+ int len = str.length(); // probably should check length
+ char hex[] = str.toCharArray();
+ byte[] buf = new byte[len / 2];
+
+ for (int pos = 0; pos < len / 2; pos++) {
+ buf[pos] = (byte)( ((data(hex[2 * pos]) << 4) & 0xF0)
+ | (data(hex[2 * pos + 1]) & 0x0F) );
+ }
+
+ return buf;
+ }
+
+ private static byte data(char c) {
+ if (('0' <= c) && (c <= '9' )) {
+ return (byte)((byte)c - (byte)'0');
+ }
+
+ if (('a' <= c) && (c <= 'f' )) {
+ return (byte)((byte)c - (byte)'a' + 10);
+ }
+
+ if (('A' <= c) && (c <= 'F' )) {
+ return (byte)((byte)c - (byte)'A' + 10);
+ }
+
+ return -1;
+ }
+ */
+
+ /**
+ * @return Logger
+ */
+ protected Logger getLogger() {
+ if (log == null) {
+ log = Logger.getLogger(this.getClass());
+ }
+
+ return log;
+ }
+
+ protected void debugMsg(String msg) {
+ getLogger().debug(msg);
+ }
+
+ protected void error(Throwable t) {
+ getLogger().error(this, t);
+ }
+
+ protected void error(String msg) {
+ getLogger().error(msg);
+ }
+
+ protected void trace(String msg) {
+ getLogger().debug(msg);
+ }
+}
Added: trunk/src/edu/rpi/cmt/security/pki/PkiUtil.java
===================================================================
--- trunk/src/edu/rpi/cmt/security/pki/PkiUtil.java (rev 0)
+++ trunk/src/edu/rpi/cmt/security/pki/PkiUtil.java 2008-07-14 02:41:31 UTC (rev 89)
@@ -0,0 +1,345 @@
+/* **********************************************************************
+ Copyright 2008 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.cmt.security.pki;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+
+/**
+ * This program helps create keys and encrypt/decrypt data
+ *
+ * @author Mike Douglass
+ */
+public class PkiUtil {
+ private boolean debug = false;
+ private boolean verbose = false;
+
+ protected transient Logger log;
+
+ private boolean genKeys = false; // generate keys
+ private boolean encrypt = false; // Encrypt a file
+ private boolean decrypt = false; // Decrypt a file
+ private boolean dumppublic = false; // Dump the public key as text
+
+ private String privKeyFileName;
+ private String pubKeyFileName;
+ private boolean append = true;
+
+ private String inFileName;
+ private String outFileName;
+
+ //private PropertyUtil pr; // properties used throughout
+ private PKITools pki;
+
+ /** Following is some random text which we encode and decode to ensure
+ * generated keys work
+ */
+ String testText =
+ "A variable of array type holds a reference to an object. ";/* +
+ "Declaring a variable of array type does not create an array object \n" +
+ "or allocate any space for array components. It creates only the \n" +
+ "variable itself, which can contain a reference to an array. However, \n" +
+ "the initializer part of a declarator (§8.3) may create an array, a \n" +
+ "reference to which then becomes the initial value of the variable.\n";/* +
+ " \n" +
+ "Because an array's length is not part of its type, a single variable \n" +
+ "of array type may contain references to arrays of different lengths.\n" +
+ "\n" +
+ "Here are examples of declarations of array variables that do not \n" +
+ "create arrays:\n" +
+ "\n" +
+ " int[] ai; // array of int\n" +
+ " short[][] as; // array of array of short\n" +
+ " Object[] ao, // array of Object\n" +
+ " otherAo; // array of Object\n" +
+ " short s, // scalar short \n" +
+ " aas[][]; // array of array of short";
+ */
+
+ String getInFileName() {
+ return inFileName;
+ }
+
+ String getOutFileName() {
+ return outFileName;
+ }
+
+ boolean getDebug() {
+ return debug;
+ }
+
+ boolean getGenKeys() {
+ return genKeys;
+ }
+
+ boolean getEncrypt() {
+ return encrypt;
+ }
+
+ boolean getDecrypt() {
+ return decrypt;
+ }
+
+ void processArgs(String[] args) throws Exception {
+ if (args == null) {
+ return;
+ }
+
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equals("-genkeys")) {
+ genKeys = true;
+ } else if (args[i].equals("-encrypt")) {
+ encrypt = true;
+ decrypt = false;
+ } else if (args[i].equals("-decrypt")) {
+ encrypt = false;
+ decrypt = true;
+ } else if (args[i].equals("-verbose")) {
+ verbose = true;
+ } else if (args[i].equals("-nverbose")) {
+ verbose = false;
+ } else if (args[i].equals("-append")) {
+ append = true;
+ } else if (args[i].equals("-nappend")) {
+ append= false;
+ } else if (args[i].equals("-debug")) {
+ debug = true;
+ } else if (args[i].equals("-ndebug")) {
+ debug = false;
+ } else if (args[i].equals("-dumppublic")) {
+ dumppublic = true;
+ } else if (argpar("-in", args, i)) {
+ i++;
+ inFileName = args[i];
+ } else if (argpar("-out", args, i)) {
+ i++;
+ outFileName = args[i];
+ } else if (argpar("-key", args, i)) {
+ i++;
+ privKeyFileName = args[i];
+ } else if (argpar("-privkey", args, i)) {
+ i++;
+ privKeyFileName = args[i];
+ } else if (argpar("-pubkey", args, i)) {
+ i++;
+ pubKeyFileName = args[i];
+ }
+ }
+ }
+
+ boolean argpar(String n, String[] args, int i) throws Exception {
+ if (!args[i].equals(n)) {
+ return false;
+ }
+
+ if ((i + 1) == args.length) {
+ throw new Exception("Invalid arguments");
+ }
+
+ return true;
+ }
+
+ boolean doGenKeys() throws Throwable {
+ if (privKeyFileName == null) {
+ error("Must provide a -privkey <file> parameter");
+ }
+
+ if (pubKeyFileName == null) {
+ error("Must provide a -pubkey <file> parameter");
+ }
+
+ PKITools.RSAKeys keys = pki.genRSAKeysIntoFiles(privKeyFileName,
+ pubKeyFileName,
+ append);
+ if (keys == null) {
+ error("Generation of keys failed");
+ return false;
+ }
+
+ if (dumppublic) {
+ if (!dumpKey(keys.publicKey)) {
+ return false;
+ }
+ }
+
+ // Now try the keys on the test text.
+
+ int numKeys = pki.countKeys(privKeyFileName);
+
+ if (debug) {
+ debugMsg("Number of keys: " + numKeys);
+ }
+
+ System.out.println("test with---->" + testText);
+ String etext = pki.encryptWithKeyFile(pubKeyFileName, testText, numKeys - 1);
+ System.out.println("encrypts to-->" + etext);
+ String detext = pki.decryptWithKeyFile(privKeyFileName, etext, numKeys - 1);
+ System.out.println("decrypts to-->" + detext);
+
+ if (!testText.equals(detext)) {
+ error("Validity check failed: encrypt/decrypt failure");
+ }
+
+ return true;
+ }
+
+ boolean doit(String[] args) throws Throwable {
+ processArgs(args);
+
+ pki = new PKITools(verbose, debug);
+
+ if (getGenKeys()) {
+ return doGenKeys();
+ }
+
+ return false;
+ }
+
+ /** Dump a byte array as a base 64 encoded value. We also check that the
+ * form we emit can be decoded and produce an identical key.
+ * <p>
+ * We then go on to encode and decode our testText to see if they match.
+ *
+ * @param key
+ * @return boolean
+ * @throws Exception
+ */
+ private boolean dumpKey(byte[] key) throws Exception {
+ byte[] encoded = Base64.encodeBase64Chunked(key);
+ String encText = new String(encoded);
+
+ System.out.println("Copy the text between the delimiters");
+ System.out.println("Take all below this line ----------------------->");
+ System.out.println(encText);
+ System.out.println("<--------------- up to and not including this line");
+
+ // See if it decodes
+ byte[] decoded = Base64.encodeBase64Chunked(encText.getBytes());
+
+ if (decoded.length != key.length) {
+ error("Validity check failed: lengths not equal " +
+ "(decoded=" + decoded.length + " key=" + key.length + ")");
+ dumpHex(decoded);
+ error(" ");
+ dumpHex(key);
+ return false;
+ }
+
+ for (int i = 0; i < decoded.length; i++) {
+ if (decoded[i] != key[i]) {
+ error("Validity check failed: byte at position " + i + " not equal");
+ dumpHex(decoded);
+ error(" ");
+ dumpHex(key);
+
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private void dumpHex(byte[] hex) {
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < hex.length; i++) {
+ sb.append(toHex(hex[i]));
+ // string += toHex(byteArray[i]) + " ";
+ }
+
+ int pos = 0;
+ int seglen = 50;
+ while (pos < sb.length()) {
+ int len = Math.min(seglen, sb.length() - pos);
+
+ error(" " + sb.substring(pos, pos + len));
+
+ pos += len;
+ }
+ }
+
+ private static String toHex(byte b) {
+ int i = (b >> 4) & 0x0F;
+ String tmp;
+
+ if (i < 10) {
+ tmp = Integer.toString(i);
+ } else {
+ tmp = new Character((char)('A'+i-10)).toString();
+ }
+
+ i = b & 0x0F;
+
+ if (i < 10) {
+ tmp += Integer.toString(i);
+ } else {
+ tmp += new Character((char)('A'+(i-10))).toString();
+ }
+
+ return tmp;
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ PkiUtil pkiu = new PkiUtil();
+
+ try {
+ pkiu.doit(args);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ /**
+ * @return Logger
+ */
+ protected Logger getLogger() {
+ if (log == null) {
+ log = Logger.getLogger(this.getClass());
+ }
+
+ return log;
+ }
+
+ protected void debugMsg(String msg) {
+ getLogger().debug(msg);
+ }
+
+ protected void error(Throwable t) {
+ getLogger().error(this, t);
+ }
+
+ protected void error(String msg) {
+ getLogger().error(msg);
+ }
+
+ protected void trace(String msg) {
+ getLogger().debug(msg);
+ }
+}
+
More information about the Bedework-commit
mailing list