From 6ee27b4e16c9478762516bb90ac49e64317b6e57 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Mon, 27 Oct 2003 19:07:26 +0000 Subject: First go at SURBs. Still needs testing. Moo. --- src/org/noreply/fancydress/misc/Util.java | 27 ++++++++++ src/org/noreply/fancydress/type3/SURB.java | 84 +++++++++++++++++++++++++++--- 2 files changed, 103 insertions(+), 8 deletions(-) diff --git a/src/org/noreply/fancydress/misc/Util.java b/src/org/noreply/fancydress/misc/Util.java index d9b46da..5b67956 100644 --- a/src/org/noreply/fancydress/misc/Util.java +++ b/src/org/noreply/fancydress/misc/Util.java @@ -1,6 +1,7 @@ /* $Id$ */ package org.noreply.fancydress.misc; +import org.bouncycastle.util.encoders.Base64; import java.io.IOException; import java.text.SimpleDateFormat; import java.text.ParseException; @@ -260,4 +261,30 @@ public class Util { return (String[]) list.toArray(new String[list.size()]); } + + /** + * embed the data in RFC2440 ASCII Armor. + * + * @param buf octet array to encode + * @param header header text + * @param additionalHeaders additional headers. /*FIXME: docs are bad + */ + public static String armor(byte[] buf, String header, String[] additionalHeaders) { + StringBuffer strbuf = new StringBuffer(); + strbuf.append("-----BEGIN "); + strbuf.append(header); + strbuf.append("-----\n"); + for(int i=0; i>24) & 0xff); + pos++; + result[pos] = (byte) ( (useBy >>16) & 0xff); + pos++; + result[pos] = (byte) ( (useBy >> 8) & 0xff); + pos++; + result[pos] = (byte) ( (useBy ) & 0xff); + pos++; + System.arraycopy(super.asOctets(), 0, result, pos, SINGLE_HEADER_LEN); + pos += SINGLE_HEADER_LEN; + result[pos] = (byte) ( (routingSize >> 8) & 0xff); + pos++; + result[pos] = (byte) ( routingSize & 0xff); + pos++; + result[pos] = (byte) ( (routingType >> 8) & 0xff); + pos++; + result[pos] = (byte) ( routingType & 0xff); + pos++; + System.arraycopy(sharedSecret, 0, result, pos, CryptoPrimitives.KEY_LEN); + pos += CryptoPrimitives.KEY_LEN; + System.arraycopy(routingInformation, 0, result, pos, routingSize); + pos += routingSize; + + if (pos != result.length) + throw new Error("did not fill in expected number of bytes"); + + String[] headers = new String[1]; + headers[0] = "Version: "+ARMOR_VERSION; + return Util.armor(result, "TYPE III REPLY BLOCK", headers); } } - -- cgit v1.2.3