[Webfunds-commits] java/webfunds/sox Utils.java
Jeroen C. van Gelderen
gelderen@cypherpunks.ai
Sat, 29 Jul 2000 20:07:06 -0400 (AST)
gelderen 00/07/29 20:07:06
Modified: webfunds/sox Utils.java
Log:
Add transparent OpenPGP support to getCertificate(...).
We now try and construct an OpenPGP Certificate from the data passed in
and if that fails we fall back to X.509. Method signature didn't change.
Revision Changes Path
1.17 +23 -19 java/webfunds/sox/Utils.java
Index: Utils.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Utils.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Utils.java 2000/07/21 21:31:18 1.16
+++ Utils.java 2000/07/30 00:07:06 1.17
@@ -1,5 +1,5 @@
/*
- * $Id: Utils.java,v 1.16 2000/07/21 21:31:18 gelderen Exp $
+ * $Id: Utils.java,v 1.17 2000/07/30 00:07:06 gelderen Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -18,6 +18,11 @@
*/
public final class Utils
{
+ private static final void logDebug(String s) {
+ System.err.println("Utils: " + s);
+ }
+
+
private Utils() {}
/**
@@ -39,10 +44,24 @@
public static Certificate getCertificate(byte[] data) throws IOException {
+
try {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- ByteArrayInputStream bais = new ByteArrayInputStream(data);
- return cf.generateCertificate(bais);
+ try {
+ logDebug("getCertificate, trying OpenPGP...");
+ CertificateFactory cf =
+ CertificateFactory.getInstance("OpenPGP");
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ Certificate cert = cf.generateCertificate(bais);
+ logDebug(" OpenPGP Certificate being returned...");
+ return cert;
+ } catch(CertificateException e) {
+ logDebug(" OpenPGP failed, trying X.509...");
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ Certificate cert = cf.generateCertificate(bais);
+ logDebug(" X.509 Certificate being returned...");
+ return cert;
+ }
} catch(CertificateException e) {
throw new IOException("Uh :-(");
}
@@ -206,19 +225,4 @@
pk = (PrivateKey)new cryptix.provider.rsa.RawRSAPrivateKey(d, p, q, u);
return pk;
}
-
-// moved to webfunds.utils.Hex
-// public static String printable(byte[] data)
-// {
-// int len = data.length;
-// for (int pos = 0; pos < len; pos++)
-// {
-// if (0x20 <= data[pos] && data[pos] <= 0xEF)
-// continue ;
-// if (data[pos] == '\r' || data[pos] == '\n' || data[pos] == '\t')
-// continue ;
-// return webfunds.utils.Hex.data2hex(data);
-// }
-// return new String(data);
-// }
}