[Webfunds-commits] java/webfunds/x509 AsnUnknown.java AsnBitString.java AsnInputStream.java AsnInteger.java AsnObject.java AsnSequence.java X509Cert.java
Jeroen C. van Gelderen
gelderen@cypherpunks.ai
Wed, 19 Jul 2000 18:02:02 -0400 (AST)
gelderen 00/07/19 18:02:02
Modified: webfunds/sox Crypto.java
webfunds/x509 AsnBitString.java AsnInputStream.java
AsnInteger.java AsnObject.java AsnSequence.java
X509Cert.java
Added: webfunds/x509 AsnUnknown.java
Log:
Hack the ASN.1 library temporarirly so that it sort of works for X.509.
This will be redone properly when the library is imported into Cryptix.
Make WebFunds 'work' without using any of the Sun classes. WebFunds should
now be runnable on JDK 1.2.
Revision Changes Path
1.38 +3 -9 java/webfunds/sox/Crypto.java
Index: Crypto.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Crypto.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- Crypto.java 2000/07/19 02:35:41 1.37
+++ Crypto.java 2000/07/19 22:02:01 1.38
@@ -1,4 +1,4 @@
-/* $Id: Crypto.java,v 1.37 2000/07/19 02:35:41 gelderen Exp $
+/* $Id: Crypto.java,v 1.38 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) Systemics Inc. 1995-2000 on behalf of
* The WebFunds Development Team. All Rights Reserved.
@@ -49,7 +49,7 @@
*
* Centralized crypto methods. Currently being overhauled.
*
- * @version $Revision: 1.37 $
+ * @version $Revision: 1.38 $
*/
public final class Crypto
{
@@ -161,13 +161,7 @@
*/
public static PublicKey getPublicKeyFromCert(X509Cert cert)
{
- try {
- PublicKey xkey = cert.getPublicKey();
- return decodePublicKey(keyData(xkey));
- } catch (InvalidKeyException e) {
- throw new IllegalArgumentException(
- "Badly formatted certificate: "+e.getMessage());
- }
+ return cert.getPublicKey();
}
1.2 +6 -1 java/webfunds/x509/AsnBitString.java
Index: AsnBitString.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/x509/AsnBitString.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsnBitString.java 2000/07/19 02:35:41 1.1
+++ AsnBitString.java 2000/07/19 22:02:01 1.2
@@ -1,4 +1,4 @@
-/* $Id: AsnBitString.java,v 1.1 2000/07/19 02:35:41 gelderen Exp $
+/* $Id: AsnBitString.java,v 1.2 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -12,7 +12,7 @@
/**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@webfunds.org)
*/
public final class AsnBitString extends AsnObject
@@ -40,6 +40,11 @@
super(AsnObject.TAG_BITSTRING);
this.val = (byte[])(value.clone());
+ }
+
+
+ public String toString(String prefix) {
+ return "BIT_STRING";
}
1.2 +5 -3 java/webfunds/x509/AsnInputStream.java
Index: AsnInputStream.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/x509/AsnInputStream.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsnInputStream.java 2000/07/19 02:35:41 1.1
+++ AsnInputStream.java 2000/07/19 22:02:01 1.2
@@ -1,4 +1,4 @@
-/* $Id: AsnInputStream.java,v 1.1 2000/07/19 02:35:41 gelderen Exp $
+/* $Id: AsnInputStream.java,v 1.2 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -13,7 +13,7 @@
/**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@webfunds.org)
*/
public final class AsnInputStream {
@@ -43,8 +43,6 @@
if(tag == -1)
throw new IOException("End of stream.");
- System.out.println("tag: " +tag);
-
switch(tag) {
case AsnObject.TAG_OBJECT_ID:
return new AsnObjectId(this);
@@ -54,7 +52,11 @@
return new AsnInteger(this);
case AsnObject.TAG_NULL:
return new AsnNull(this);
+ case AsnObject.TAG_PRINTABLE_STRING:
+ case AsnObject.TAG_UTCTime:
+ return new AsnUnknown(this);
case AsnObject.TAG_SEQUENCE:
+ case AsnObject.TAG_SET:
return new AsnSequence(this);
default:
throw new IOException("Unknown ASN object type.");
1.2 +5 -1 java/webfunds/x509/AsnInteger.java
Index: AsnInteger.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/x509/AsnInteger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsnInteger.java 2000/07/19 02:35:41 1.1
+++ AsnInteger.java 2000/07/19 22:02:01 1.2
@@ -1,4 +1,4 @@
-/* $Id: AsnInteger.java,v 1.1 2000/07/19 02:35:41 gelderen Exp $
+/* $Id: AsnInteger.java,v 1.2 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -12,7 +12,7 @@
/**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@webfunds.org)
*/
public final class AsnInteger extends AsnObject
@@ -40,6 +40,10 @@
this.val = value;
}
+
+ public String toString(String prefix) {
+ return "BIGINTEGER (" + this.val.toString() + ")";
+ }
//............................................................................
1.2 +21 -7 java/webfunds/x509/AsnObject.java
Index: AsnObject.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/x509/AsnObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsnObject.java 2000/07/19 02:35:41 1.1
+++ AsnObject.java 2000/07/19 22:02:01 1.2
@@ -1,4 +1,4 @@
-/* $Id: AsnObject.java,v 1.1 2000/07/19 02:35:41 gelderen Exp $
+/* $Id: AsnObject.java,v 1.2 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -15,18 +15,22 @@
* AsnObjects can encode themselves to AsnOutputStreams. All AsnObjects are
* immutable.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@cryptix.org)
*/
public abstract class AsnObject {
/*package*/ static final byte
- TAG_MASK = 0x1F,
- TAG_INTEGER = 0x02,
- TAG_BITSTRING = 0x03,
- TAG_NULL = 0x05,
- TAG_OBJECT_ID = 0x06,
- TAG_SEQUENCE = 0x10 | 0x20;
+ TAG_MASK = 0x1F,
+ TAG_INTEGER = 0x02,
+ TAG_BITSTRING = 0x03,
+ TAG_NULL = 0x05,
+ TAG_OBJECT_ID = 0x06,
+ TAG_SEQUENCE = 0x10 | 0x20,
+ TAG_SET = 0x11 | 0x20,
+ TAG_PRINTABLE_STRING = 0x13,
+ TAG_UTCTime = 0x17,
+ TAG_UNKNOWN = 0x13;
private final byte tag;
@@ -34,6 +38,16 @@
protected AsnObject(byte tag) {
this.tag = tag;
+ }
+
+
+ public final String toString() {
+ return this.toString("");
+ }
+
+
+ public String toString(String prefix) {
+ return "uh";
}
1.2 +11 -6 java/webfunds/x509/AsnSequence.java
Index: AsnSequence.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/x509/AsnSequence.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AsnSequence.java 2000/07/19 02:35:41 1.1
+++ AsnSequence.java 2000/07/19 22:02:01 1.2
@@ -1,4 +1,4 @@
-/* $Id: AsnSequence.java,v 1.1 2000/07/19 02:35:41 gelderen Exp $
+/* $Id: AsnSequence.java,v 1.2 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -12,7 +12,7 @@
/**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@webfunds.org)
*/
public final class AsnSequence extends AsnObject
@@ -24,14 +24,10 @@
super(AsnObject.TAG_SEQUENCE);
int len = is.readLength();
- System.out.println(" " + len);
-
AsnInputStream sub_is = is.getSubStream( len );
Vector vec = new Vector(3);
- while( sub_is.available() > 0 ) {
- System.out.println(" yeah!");
+ while( sub_is.available() > 0 )
vec.addElement( sub_is.read() );
- }
vec.copyInto(this.vals = new AsnObject[ vec.size() ]);
}
@@ -49,6 +45,15 @@
objs[0] = a;
objs[1] = b;
this.vals = objs;
+ }
+
+
+ public String toString(String prefix) {
+ String s = "SEQUENCE (" + this.vals.length +" elements)";
+ for(int i=0; i<this.vals.length; i++)
+ s += "\n" + prefix+ " "+ this.vals[i].toString(prefix + " ");
+
+ return s;
}
1.2 +60 -6 java/webfunds/x509/X509Cert.java
Index: X509Cert.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/x509/X509Cert.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- X509Cert.java 2000/07/14 23:09:21 1.1
+++ X509Cert.java 2000/07/19 22:02:01 1.2
@@ -1,4 +1,4 @@
-/* $Id: X509Cert.java,v 1.1 2000/07/14 23:09:21 gelderen Exp $
+/* $Id: X509Cert.java,v 1.2 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
@@ -8,16 +8,70 @@
import java.io.IOException;
+import java.io.OutputStream;
+import java.security.PublicKey;
+import cryptix.provider.rsa.RawRSAPublicKey;
+
/**
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @author Jeroen C. van Gelderen (gelderen@webfunds.org)
*/
-public final class X509Cert extends sun.security.x509.X509Cert
+public final class X509Cert
{
- public X509Cert(byte[] data) throws IOException
- {
- super(data);
+ private final AsnObject cert;
+
+
+ private final PublicKey key;
+
+
+ public X509Cert(byte[] data) throws IOException {
+ try {
+ AsnInputStream is = new AsnInputStream(data);
+ AsnSequence seq1 = (AsnSequence)is.read();
+
+ AsnSequence seq2 = (AsnSequence)seq1.get(0);
+ AsnSequence seq3 = (AsnSequence)seq2.get(5);
+
+ this.cert = seq1;
+ this.key = decodePublicKey(seq3);;
+
+ } catch(ArrayIndexOutOfBoundsException e) {
+ e.printStackTrace();
+ throw new IOException("Uh :-(");
+ } catch(ClassCastException e) {
+ e.printStackTrace();
+ throw new IOException("Unexpected ASN.1 type detected.");
+ }
+ }
+
+
+ private PublicKey decodePublicKey(AsnSequence seq) throws IOException {
+ AsnBitString bs = (AsnBitString)seq.get(1);
+
+ AsnInputStream is = new AsnInputStream(bs.toByteArray());
+ AsnSequence seq2 = (AsnSequence)is.read();
+ AsnInteger n = (AsnInteger)seq2.get(0);
+ AsnInteger e = (AsnInteger)seq2.get(1);
+
+ return new RawRSAPublicKey(n.toBigInteger(), e.toBigInteger());
+ }
+
+
+ public void encode(OutputStream os) throws IOException {
+ System.out.println("NYI");
+ throw new RuntimeException("NYI");
+ }
+
+
+ public PublicKey getPublicKey() {
+ return this.key;
+ }
+
+
+ public void verify(PublicKey key) throws SecurityException {
+ System.out.println("XXX certificate may not be valid!!! XXX");
+ // XXX
}
}
1.1 java/webfunds/x509/AsnUnknown.java
Index: AsnUnknown.java
===================================================================
/* $Id: AsnUnknown.java,v 1.1 2000/07/19 22:02:01 gelderen Exp $
*
* Copyright (c) 2000 Systemics Inc. on behalf of
* The WebFunds Development Team. All rights reserved.
*/
package webfunds.x509;
import java.io.IOException;
/**
* @version $Revision: 1.1 $
* @author Jeroen C. van Gelderen (gelderen@webfunds.org)
*/
public final class AsnUnknown extends AsnObject
{
private final byte[] data;
public AsnUnknown(AsnInputStream is) throws IOException {
super(AsnObject.TAG_UNKNOWN);
int len = is.readLength();
this.data = is.readBytes(len);
}
/** Write out payload. */
protected void encodePayload(AsnOutputStream os) throws IOException {
os.writeBytes(data);
}
protected int getEncodedLengthOfPayload(AsnOutputStream os) {
return data.length;
}
}