diff options
Diffstat (limited to 'pg/src/main/java/org/bouncycastle/bcpg')
71 files changed, 0 insertions, 6397 deletions
diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java b/pg/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java deleted file mode 100644 index 802cdf91..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ArmoredInputStream.java +++ /dev/null @@ -1,473 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Vector; - -/** - * reader for Base64 armored objects - read the headers and then start returning - * bytes when the data is reached. An IOException is thrown if the CRC check - * fails. - */ -public class ArmoredInputStream - extends InputStream -{ - /* - * set up the decoding table. - */ - private static final byte[] decodingTable; - - static - { - decodingTable = new byte[128]; - - for (int i = 'A'; i <= 'Z'; i++) - { - decodingTable[i] = (byte)(i - 'A'); - } - - for (int i = 'a'; i <= 'z'; i++) - { - decodingTable[i] = (byte)(i - 'a' + 26); - } - - for (int i = '0'; i <= '9'; i++) - { - decodingTable[i] = (byte)(i - '0' + 52); - } - - decodingTable['+'] = 62; - decodingTable['/'] = 63; - } - - /** - * decode the base 64 encoded input data. - * - * @return the offset the data starts in out. - */ - private int decode( - int in0, - int in1, - int in2, - int in3, - int[] out) - throws EOFException - { - int b1, b2, b3, b4; - - if (in3 < 0) - { - throw new EOFException("unexpected end of file in armored stream."); - } - - if (in2 == '=') - { - b1 = decodingTable[in0] &0xff; - b2 = decodingTable[in1] & 0xff; - - out[2] = ((b1 << 2) | (b2 >> 4)) & 0xff; - - return 2; - } - else if (in3 == '=') - { - b1 = decodingTable[in0]; - b2 = decodingTable[in1]; - b3 = decodingTable[in2]; - - out[1] = ((b1 << 2) | (b2 >> 4)) & 0xff; - out[2] = ((b2 << 4) | (b3 >> 2)) & 0xff; - - return 1; - } - else - { - b1 = decodingTable[in0]; - b2 = decodingTable[in1]; - b3 = decodingTable[in2]; - b4 = decodingTable[in3]; - - out[0] = ((b1 << 2) | (b2 >> 4)) & 0xff; - out[1] = ((b2 << 4) | (b3 >> 2)) & 0xff; - out[2] = ((b3 << 6) | b4) & 0xff; - - return 0; - } - } - - InputStream in; - boolean start = true; - int[] outBuf = new int[3]; - int bufPtr = 3; - CRC24 crc = new CRC24(); - boolean crcFound = false; - boolean hasHeaders = true; - String header = null; - boolean newLineFound = false; - boolean clearText = false; - boolean restart = false; - Vector headerList= new Vector(); - int lastC = 0; - boolean isEndOfStream; - - /** - * Create a stream for reading a PGP armoured message, parsing up to a header - * and then reading the data that follows. - * - * @param in - */ - public ArmoredInputStream( - InputStream in) - throws IOException - { - this(in, true); - } - - /** - * Create an armoured input stream which will assume the data starts - * straight away, or parse for headers first depending on the value of - * hasHeaders. - * - * @param in - * @param hasHeaders true if headers are to be looked for, false otherwise. - */ - public ArmoredInputStream( - InputStream in, - boolean hasHeaders) - throws IOException - { - this.in = in; - this.hasHeaders = hasHeaders; - - if (hasHeaders) - { - parseHeaders(); - } - - start = false; - } - - public int available() - throws IOException - { - return in.available(); - } - - private boolean parseHeaders() - throws IOException - { - header = null; - - int c; - int last = 0; - boolean headerFound = false; - - headerList = new Vector(); - - // - // if restart we already have a header - // - if (restart) - { - headerFound = true; - } - else - { - while ((c = in.read()) >= 0) - { - if (c == '-' && (last == 0 || last == '\n' || last == '\r')) - { - headerFound = true; - break; - } - - last = c; - } - } - - if (headerFound) - { - StringBuffer buf = new StringBuffer("-"); - boolean eolReached = false; - boolean crLf = false; - - if (restart) // we've had to look ahead two '-' - { - buf.append('-'); - } - - while ((c = in.read()) >= 0) - { - if (last == '\r' && c == '\n') - { - crLf = true; - } - if (eolReached && (last != '\r' && c == '\n')) - { - break; - } - if (eolReached && c == '\r') - { - break; - } - if (c == '\r' || (last != '\r' && c == '\n')) - { - String line = buf.toString(); - if (line.trim().length() == 0) - { - break; - } - headerList.addElement(line); - buf.setLength(0); - } - - if (c != '\n' && c != '\r') - { - buf.append((char)c); - eolReached = false; - } - else - { - if (c == '\r' || (last != '\r' && c == '\n')) - { - eolReached = true; - } - } - - last = c; - } - - if (crLf) - { - in.read(); // skip last \n - } - } - - if (headerList.size() > 0) - { - header = (String)headerList.elementAt(0); - } - - clearText = "-----BEGIN PGP SIGNED MESSAGE-----".equals(header); - newLineFound = true; - - return headerFound; - } - - /** - * @return true if we are inside the clear text section of a PGP - * signed message. - */ - public boolean isClearText() - { - return clearText; - } - - /** - * @return true if the stream is actually at end of file. - */ - public boolean isEndOfStream() - { - return isEndOfStream; - } - - /** - * Return the armor header line (if there is one) - * @return the armor header line, null if none present. - */ - public String getArmorHeaderLine() - { - return header; - } - - /** - * Return the armor headers (the lines after the armor header line), - * @return an array of armor headers, null if there aren't any. - */ - public String[] getArmorHeaders() - { - if (headerList.size() <= 1) - { - return null; - } - - String[] hdrs = new String[headerList.size() - 1]; - - for (int i = 0; i != hdrs.length; i++) - { - hdrs[i] = (String)headerList.elementAt(i + 1); - } - - return hdrs; - } - - private int readIgnoreSpace() - throws IOException - { - int c = in.read(); - - while (c == ' ' || c == '\t') - { - c = in.read(); - } - - return c; - } - - public int read() - throws IOException - { - int c; - - if (start) - { - if (hasHeaders) - { - parseHeaders(); - } - - crc.reset(); - start = false; - } - - if (clearText) - { - c = in.read(); - - if (c == '\r' || (c == '\n' && lastC != '\r')) - { - newLineFound = true; - } - else if (newLineFound && c == '-') - { - c = in.read(); - if (c == '-') // a header, not dash escaped - { - clearText = false; - start = true; - restart = true; - } - else // a space - must be a dash escape - { - c = in.read(); - } - newLineFound = false; - } - else - { - if (c != '\n' && lastC != '\r') - { - newLineFound = false; - } - } - - lastC = c; - - if (c < 0) - { - isEndOfStream = true; - } - - return c; - } - - if (bufPtr > 2 || crcFound) - { - c = readIgnoreSpace(); - - if (c == '\r' || c == '\n') - { - c = readIgnoreSpace(); - - while (c == '\n' || c == '\r') - { - c = readIgnoreSpace(); - } - - if (c < 0) // EOF - { - isEndOfStream = true; - return -1; - } - - if (c == '=') // crc reached - { - bufPtr = decode(readIgnoreSpace(), readIgnoreSpace(), readIgnoreSpace(), readIgnoreSpace(), outBuf); - if (bufPtr == 0) - { - int i = ((outBuf[0] & 0xff) << 16) - | ((outBuf[1] & 0xff) << 8) - | (outBuf[2] & 0xff); - - crcFound = true; - - if (i != crc.getValue()) - { - throw new IOException("crc check failed in armored message."); - } - return read(); - } - else - { - throw new IOException("no crc found in armored message."); - } - } - else if (c == '-') // end of record reached - { - while ((c = in.read()) >= 0) - { - if (c == '\n' || c == '\r') - { - break; - } - } - - if (!crcFound) - { - throw new IOException("crc check not found."); - } - - crcFound = false; - start = true; - bufPtr = 3; - - if (c < 0) - { - isEndOfStream = true; - } - - return -1; - } - else // data - { - bufPtr = decode(c, readIgnoreSpace(), readIgnoreSpace(), readIgnoreSpace(), outBuf); - } - } - else - { - if (c >= 0) - { - bufPtr = decode(c, readIgnoreSpace(), readIgnoreSpace(), readIgnoreSpace(), outBuf); - } - else - { - isEndOfStream = true; - return -1; - } - } - } - - c = outBuf[bufPtr++]; - - crc.update(c); - - return c; - } - - public void close() - throws IOException - { - in.close(); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java b/pg/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java deleted file mode 100644 index 5233d1a2..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ArmoredOutputStream.java +++ /dev/null @@ -1,423 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.Enumeration; -import java.util.Hashtable; - -/** - * Output stream that writes data in ASCII Armored format. - */ -public class ArmoredOutputStream - extends OutputStream -{ - private static final byte[] encodingTable = - { - (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G', - (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N', - (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', - (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z', - (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g', - (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n', - (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', - (byte)'v', - (byte)'w', (byte)'x', (byte)'y', (byte)'z', - (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', - (byte)'7', (byte)'8', (byte)'9', - (byte)'+', (byte)'/' - }; - - /** - * encode the input data producing a base 64 encoded byte array. - */ - private void encode( - OutputStream out, - int[] data, - int len) - throws IOException - { - int d1, d2, d3; - - switch (len) - { - case 0: /* nothing left to do */ - break; - case 1: - d1 = data[0]; - - out.write(encodingTable[(d1 >>> 2) & 0x3f]); - out.write(encodingTable[(d1 << 4) & 0x3f]); - out.write('='); - out.write('='); - break; - case 2: - d1 = data[0]; - d2 = data[1]; - - out.write(encodingTable[(d1 >>> 2) & 0x3f]); - out.write(encodingTable[((d1 << 4) | (d2 >>> 4)) & 0x3f]); - out.write(encodingTable[(d2 << 2) & 0x3f]); - out.write('='); - break; - case 3: - d1 = data[0]; - d2 = data[1]; - d3 = data[2]; - - out.write(encodingTable[(d1 >>> 2) & 0x3f]); - out.write(encodingTable[((d1 << 4) | (d2 >>> 4)) & 0x3f]); - out.write(encodingTable[((d2 << 2) | (d3 >>> 6)) & 0x3f]); - out.write(encodingTable[d3 & 0x3f]); - break; - default: - throw new IOException("unknown length in encode"); - } - } - - OutputStream out; - int[] buf = new int[3]; - int bufPtr = 0; - CRC24 crc = new CRC24(); - int chunkCount = 0; - int lastb; - - boolean start = true; - boolean clearText = false; - boolean newLine = false; - - String nl = System.getProperty("line.separator"); - - String type; - String headerStart = "-----BEGIN PGP "; - String headerTail = "-----"; - String footerStart = "-----END PGP "; - String footerTail = "-----"; - - String version = "BCPG v@RELEASE_NAME@"; - - Hashtable headers = new Hashtable(); - - /** - * Constructs an armored output stream with {@link #resetHeaders() default headers}. - * - * @param out the OutputStream to wrap. - */ - public ArmoredOutputStream( - OutputStream out) - { - this.out = out; - - if (nl == null) - { - nl = "\r\n"; - } - - resetHeaders(); - } - - /** - * Constructs an armored output stream with default and custom headers. - * - * @param out the OutputStream to wrap. - * @param headers additional headers that add to or override the {@link #resetHeaders() default - * headers}. - */ - public ArmoredOutputStream( - OutputStream out, - Hashtable headers) - { - this(out); - - Enumeration e = headers.keys(); - - while (e.hasMoreElements()) - { - Object key = e.nextElement(); - - this.headers.put(key, headers.get(key)); - } - } - - /** - * Set an additional header entry. - * - * @param name the name of the header entry. - * @param value the value of the header entry. - */ - public void setHeader( - String name, - String value) - { - this.headers.put(name, value); - } - - /** - * Reset the headers to only contain a Version string. - */ - public void resetHeaders() - { - headers.clear(); - headers.put("Version", version); - } - - /** - * Start a clear text signed message. - * @param hashAlgorithm - */ - public void beginClearText( - int hashAlgorithm) - throws IOException - { - String hash; - - switch (hashAlgorithm) - { - case HashAlgorithmTags.SHA1: - hash = "SHA1"; - break; - case HashAlgorithmTags.SHA256: - hash = "SHA256"; - break; - case HashAlgorithmTags.SHA384: - hash = "SHA384"; - break; - case HashAlgorithmTags.SHA512: - hash = "SHA512"; - break; - case HashAlgorithmTags.MD2: - hash = "MD2"; - break; - case HashAlgorithmTags.MD5: - hash = "MD5"; - break; - case HashAlgorithmTags.RIPEMD160: - hash = "RIPEMD160"; - break; - default: - throw new IOException("unknown hash algorithm tag in beginClearText: " + hashAlgorithm); - } - - String armorHdr = "-----BEGIN PGP SIGNED MESSAGE-----" + nl; - String hdrs = "Hash: " + hash + nl + nl; - - for (int i = 0; i != armorHdr.length(); i++) - { - out.write(armorHdr.charAt(i)); - } - - for (int i = 0; i != hdrs.length(); i++) - { - out.write(hdrs.charAt(i)); - } - - clearText = true; - newLine = true; - lastb = 0; - } - - public void endClearText() - { - clearText = false; - } - - private void writeHeaderEntry( - String name, - String value) - throws IOException - { - for (int i = 0; i != name.length(); i++) - { - out.write(name.charAt(i)); - } - - out.write(':'); - out.write(' '); - - for (int i = 0; i != value.length(); i++) - { - out.write(value.charAt(i)); - } - - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - } - - public void write( - int b) - throws IOException - { - if (clearText) - { - out.write(b); - - if (newLine) - { - if (!(b == '\n' && lastb == '\r')) - { - newLine = false; - } - if (b == '-') - { - out.write(' '); - out.write('-'); // dash escape - } - } - if (b == '\r' || (b == '\n' && lastb != '\r')) - { - newLine = true; - } - lastb = b; - return; - } - - if (start) - { - boolean newPacket = (b & 0x40) != 0; - int tag = 0; - - if (newPacket) - { - tag = b & 0x3f; - } - else - { - tag = (b & 0x3f) >> 2; - } - - switch (tag) - { - case PacketTags.PUBLIC_KEY: - type = "PUBLIC KEY BLOCK"; - break; - case PacketTags.SECRET_KEY: - type = "PRIVATE KEY BLOCK"; - break; - case PacketTags.SIGNATURE: - type = "SIGNATURE"; - break; - default: - type = "MESSAGE"; - } - - for (int i = 0; i != headerStart.length(); i++) - { - out.write(headerStart.charAt(i)); - } - - for (int i = 0; i != type.length(); i++) - { - out.write(type.charAt(i)); - } - - for (int i = 0; i != headerTail.length(); i++) - { - out.write(headerTail.charAt(i)); - } - - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - - writeHeaderEntry("Version", (String)headers.get("Version")); - - Enumeration e = headers.keys(); - while (e.hasMoreElements()) - { - String key = (String)e.nextElement(); - - if (!key.equals("Version")) - { - writeHeaderEntry(key, (String)headers.get(key)); - } - } - - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - - start = false; - } - - if (bufPtr == 3) - { - encode(out, buf, bufPtr); - bufPtr = 0; - if ((++chunkCount & 0xf) == 0) - { - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - } - } - - crc.update(b); - buf[bufPtr++] = b & 0xff; - } - - public void flush() - throws IOException - { - } - - /** - * <b>Note</b>: close does nor close the underlying stream. So it is possible to write - * multiple objects using armoring to a single stream. - */ - public void close() - throws IOException - { - if (type != null) - { - encode(out, buf, bufPtr); - - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - out.write('='); - - int crcV = crc.getValue(); - - buf[0] = ((crcV >> 16) & 0xff); - buf[1] = ((crcV >> 8) & 0xff); - buf[2] = (crcV & 0xff); - - encode(out, buf, 3); - - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - - for (int i = 0; i != footerStart.length(); i++) - { - out.write(footerStart.charAt(i)); - } - - for (int i = 0; i != type.length(); i++) - { - out.write(type.charAt(i)); - } - - for (int i = 0; i != footerTail.length(); i++) - { - out.write(footerTail.charAt(i)); - } - - for (int i = 0; i != nl.length(); i++) - { - out.write(nl.charAt(i)); - } - - out.flush(); - - type = null; - start = true; - } - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/BCPGInputStream.java b/pg/src/main/java/org/bouncycastle/bcpg/BCPGInputStream.java deleted file mode 100644 index bc7cb802..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/BCPGInputStream.java +++ /dev/null @@ -1,395 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; - -import org.bouncycastle.util.io.Streams; - -/** - * Stream reader for PGP objects - */ -public class BCPGInputStream - extends InputStream implements PacketTags -{ - InputStream in; - boolean next = false; - int nextB; - - public BCPGInputStream( - InputStream in) - { - this.in = in; - } - - public int available() - throws IOException - { - return in.available(); - } - - public int read() - throws IOException - { - if (next) - { - next = false; - - return nextB; - } - else - { - return in.read(); - } - } - - public int read( - byte[] buf, - int off, - int len) - throws IOException - { - if (len == 0) - { - return 0; - } - - if (!next) - { - return in.read(buf, off, len); - } - - // We have next byte waiting, so return it - - if (nextB < 0) - { - return -1; // EOF - } - - buf[off] = (byte)nextB; // May throw NullPointerException... - next = false; // ...so only set this afterwards - - return 1; - } - - public void readFully( - byte[] buf, - int off, - int len) - throws IOException - { - if (Streams.readFully(this, buf, off, len) < len) - { - throw new EOFException(); - } - } - - public byte[] readAll() - throws IOException - { - return Streams.readAll(this); - } - - public void readFully( - byte[] buf) - throws IOException - { - readFully(buf, 0, buf.length); - } - - /** - * Obtains the tag of the next packet in the stream. - * - * @return the {@link PacketTags tag number}. - * - * @throws IOException if an error occurs reading the tag from the stream. - */ - public int nextPacketTag() - throws IOException - { - if (!next) - { - try - { - nextB = in.read(); - } - catch (EOFException e) - { - nextB = -1; - } - } - - next = true; - - if (nextB >= 0) - { - if ((nextB & 0x40) != 0) // new - { - return (nextB & 0x3f); - } - else // old - { - return ((nextB & 0x3f) >> 2); - } - } - - return nextB; - } - - /** - * Reads the next packet from the stream. - * @throws IOException - */ - public Packet readPacket() - throws IOException - { - int hdr = this.read(); - - if (hdr < 0) - { - return null; - } - - if ((hdr & 0x80) == 0) - { - throw new IOException("invalid header encountered"); - } - - boolean newPacket = (hdr & 0x40) != 0; - int tag = 0; - int bodyLen = 0; - boolean partial = false; - - if (newPacket) - { - tag = hdr & 0x3f; - - int l = this.read(); - - if (l < 192) - { - bodyLen = l; - } - else if (l <= 223) - { - int b = in.read(); - - bodyLen = ((l - 192) << 8) + (b) + 192; - } - else if (l == 255) - { - bodyLen = (in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read(); - } - else - { - partial = true; - bodyLen = 1 << (l & 0x1f); - } - } - else - { - int lengthType = hdr & 0x3; - - tag = (hdr & 0x3f) >> 2; - - switch (lengthType) - { - case 0: - bodyLen = this.read(); - break; - case 1: - bodyLen = (this.read() << 8) | this.read(); - break; - case 2: - bodyLen = (this.read() << 24) | (this.read() << 16) | (this.read() << 8) | this.read(); - break; - case 3: - partial = true; - break; - default: - throw new IOException("unknown length type encountered"); - } - } - - BCPGInputStream objStream; - - if (bodyLen == 0 && partial) - { - objStream = this; - } - else - { - objStream = new BCPGInputStream(new PartialInputStream(this, partial, bodyLen)); - } - - switch (tag) - { - case RESERVED: - return new InputStreamPacket(objStream); - case PUBLIC_KEY_ENC_SESSION: - return new PublicKeyEncSessionPacket(objStream); - case SIGNATURE: - return new SignaturePacket(objStream); - case SYMMETRIC_KEY_ENC_SESSION: - return new SymmetricKeyEncSessionPacket(objStream); - case ONE_PASS_SIGNATURE: - return new OnePassSignaturePacket(objStream); - case SECRET_KEY: - return new SecretKeyPacket(objStream); - case PUBLIC_KEY: - return new PublicKeyPacket(objStream); - case SECRET_SUBKEY: - return new SecretSubkeyPacket(objStream); - case COMPRESSED_DATA: - return new CompressedDataPacket(objStream); - case SYMMETRIC_KEY_ENC: - return new SymmetricEncDataPacket(objStream); - case MARKER: - return new MarkerPacket(objStream); - case LITERAL_DATA: - return new LiteralDataPacket(objStream); - case TRUST: - return new TrustPacket(objStream); - case USER_ID: - return new UserIDPacket(objStream); - case USER_ATTRIBUTE: - return new UserAttributePacket(objStream); - case PUBLIC_SUBKEY: - return new PublicSubkeyPacket(objStream); - case SYM_ENC_INTEGRITY_PRO: - return new SymmetricEncIntegrityPacket(objStream); - case MOD_DETECTION_CODE: - return new ModDetectionCodePacket(objStream); - case EXPERIMENTAL_1: - case EXPERIMENTAL_2: - case EXPERIMENTAL_3: - case EXPERIMENTAL_4: - return new ExperimentalPacket(tag, objStream); - default: - throw new IOException("unknown packet type encountered: " + tag); - } - } - - public void close() - throws IOException - { - in.close(); - } - - /** - * a stream that overlays our input stream, allowing the user to only read a segment of it. - * - * NB: dataLength will be negative if the segment length is in the upper range above 2**31. - */ - private static class PartialInputStream - extends InputStream - { - private BCPGInputStream in; - private boolean partial; - private int dataLength; - - PartialInputStream( - BCPGInputStream in, - boolean partial, - int dataLength) - { - this.in = in; - this.partial = partial; - this.dataLength = dataLength; - } - - public int available() - throws IOException - { - int avail = in.available(); - - if (avail <= dataLength || dataLength < 0) - { - return avail; - } - else - { - if (partial && dataLength == 0) - { - return 1; - } - return dataLength; - } - } - - private int loadDataLength() - throws IOException - { - int l = in.read(); - - if (l < 0) - { - return -1; - } - - partial = false; - if (l < 192) - { - dataLength = l; - } - else if (l <= 223) - { - dataLength = ((l - 192) << 8) + (in.read()) + 192; - } - else if (l == 255) - { - dataLength = (in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read(); - } - else - { - partial = true; - dataLength = 1 << (l & 0x1f); - } - - return dataLength; - } - - public int read(byte[] buf, int offset, int len) - throws IOException - { - do - { - if (dataLength != 0) - { - int readLen = (dataLength > len || dataLength < 0) ? len : dataLength; - readLen = in.read(buf, offset, readLen); - if (readLen < 0) - { - throw new EOFException("premature end of stream in PartialInputStream"); - } - dataLength -= readLen; - return readLen; - } - } - while (partial && loadDataLength() >= 0); - - return -1; - } - - public int read() - throws IOException - { - do - { - if (dataLength != 0) - { - int ch = in.read(); - if (ch < 0) - { - throw new EOFException("premature end of stream in PartialInputStream"); - } - dataLength--; - return ch; - } - } - while (partial && loadDataLength() >= 0); - - return -1; - } - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/BCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/BCPGKey.java deleted file mode 100644 index 632ef91d..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/BCPGKey.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * base interface for a PGP key - */ -public interface BCPGKey -{ - /** - * Return the base format for this key - in the case of the symmetric keys it will generally - * be raw indicating that the key is just a straight byte representation, for an asymmetric - * key the format will be PGP, indicating the key is a string of MPIs encoded in PGP format. - * - * @return "RAW" or "PGP" - */ - public String getFormat(); - - /** - * return a string of bytes giving the encoded format of the key, as described by it's format. - * - * @return byte[] - */ - public byte[] getEncoded(); - -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/BCPGObject.java b/pg/src/main/java/org/bouncycastle/bcpg/BCPGObject.java deleted file mode 100644 index 1018f189..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/BCPGObject.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * Base class for a PGP object. - */ -public abstract class BCPGObject -{ - public byte[] getEncoded() - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.writeObject(this); - - return bOut.toByteArray(); - } - - public abstract void encode(BCPGOutputStream out) - throws IOException; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java b/pg/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java deleted file mode 100644 index 640310b4..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/BCPGOutputStream.java +++ /dev/null @@ -1,361 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Basic output stream. - */ -public class BCPGOutputStream - extends OutputStream - implements PacketTags, CompressionAlgorithmTags -{ - OutputStream out; - private byte[] partialBuffer; - private int partialBufferLength; - private int partialPower; - private int partialOffset; - - private static final int BUF_SIZE_POWER = 16; // 2^16 size buffer on long files - - public BCPGOutputStream( - OutputStream out) - { - this.out = out; - } - - /** - * Create a stream representing an old style partial object. - * - * @param tag the packet tag for the object. - */ - public BCPGOutputStream( - OutputStream out, - int tag) - throws IOException - { - this.out = out; - this.writeHeader(tag, true, true, 0); - } - - /** - * Create a stream representing a general packet. - * - * @param out - * @param tag - * @param length - * @param oldFormat - * @throws IOException - */ - public BCPGOutputStream( - OutputStream out, - int tag, - long length, - boolean oldFormat) - throws IOException - { - this.out = out; - - if (length > 0xFFFFFFFFL) - { - this.writeHeader(tag, false, true, 0); - this.partialBufferLength = 1 << BUF_SIZE_POWER; - this.partialBuffer = new byte[partialBufferLength]; - this.partialPower = BUF_SIZE_POWER; - this.partialOffset = 0; - } - else - { - this.writeHeader(tag, oldFormat, false, length); - } - } - - /** - * - * @param tag - * @param length - * @throws IOException - */ - public BCPGOutputStream( - OutputStream out, - int tag, - long length) - throws IOException - { - this.out = out; - - this.writeHeader(tag, false, false, length); - } - - /** - * Create a new style partial input stream buffered into chunks. - * - * @param out output stream to write to. - * @param tag packet tag. - * @param buffer size of chunks making up the packet. - * @throws IOException - */ - public BCPGOutputStream( - OutputStream out, - int tag, - byte[] buffer) - throws IOException - { - this.out = out; - this.writeHeader(tag, false, true, 0); - - this.partialBuffer = buffer; - - int length = partialBuffer.length; - - for (partialPower = 0; length != 1; partialPower++) - { - length >>>= 1; - } - - if (partialPower > 30) - { - throw new IOException("Buffer cannot be greater than 2^30 in length."); - } - - this.partialBufferLength = 1 << partialPower; - this.partialOffset = 0; - } - - private void writeNewPacketLength( - long bodyLen) - throws IOException - { - if (bodyLen < 192) - { - out.write((byte)bodyLen); - } - else if (bodyLen <= 8383) - { - bodyLen -= 192; - - out.write((byte)(((bodyLen >> 8) & 0xff) + 192)); - out.write((byte)bodyLen); - } - else - { - out.write(0xff); - out.write((byte)(bodyLen >> 24)); - out.write((byte)(bodyLen >> 16)); - out.write((byte)(bodyLen >> 8)); - out.write((byte)bodyLen); - } - } - - private void writeHeader( - int tag, - boolean oldPackets, - boolean partial, - long bodyLen) - throws IOException - { - int hdr = 0x80; - - if (partialBuffer != null) - { - partialFlush(true); - partialBuffer = null; - } - - if (oldPackets) - { - hdr |= tag << 2; - - if (partial) - { - this.write(hdr | 0x03); - } - else - { - if (bodyLen <= 0xff) - { - this.write(hdr); - this.write((byte)bodyLen); - } - else if (bodyLen <= 0xffff) - { - this.write(hdr | 0x01); - this.write((byte)(bodyLen >> 8)); - this.write((byte)(bodyLen)); - } - else - { - this.write(hdr | 0x02); - this.write((byte)(bodyLen >> 24)); - this.write((byte)(bodyLen >> 16)); - this.write((byte)(bodyLen >> 8)); - this.write((byte)bodyLen); - } - } - } - else - { - hdr |= 0x40 | tag; - this.write(hdr); - - if (partial) - { - partialOffset = 0; - } - else - { - this.writeNewPacketLength(bodyLen); - } - } - } - - private void partialFlush( - boolean isLast) - throws IOException - { - if (isLast) - { - writeNewPacketLength(partialOffset); - out.write(partialBuffer, 0, partialOffset); - } - else - { - out.write(0xE0 | partialPower); - out.write(partialBuffer, 0, partialBufferLength); - } - - partialOffset = 0; - } - - private void writePartial( - byte b) - throws IOException - { - if (partialOffset == partialBufferLength) - { - partialFlush(false); - } - - partialBuffer[partialOffset++] = b; - } - - private void writePartial( - byte[] buf, - int off, - int len) - throws IOException - { - if (partialOffset == partialBufferLength) - { - partialFlush(false); - } - - if (len <= (partialBufferLength - partialOffset)) - { - System.arraycopy(buf, off, partialBuffer, partialOffset, len); - partialOffset += len; - } - else - { - System.arraycopy(buf, off, partialBuffer, partialOffset, partialBufferLength - partialOffset); - off += partialBufferLength - partialOffset; - len -= partialBufferLength - partialOffset; - partialFlush(false); - - while (len > partialBufferLength) - { - System.arraycopy(buf, off, partialBuffer, 0, partialBufferLength); - off += partialBufferLength; - len -= partialBufferLength; - partialFlush(false); - } - - System.arraycopy(buf, off, partialBuffer, 0, len); - partialOffset += len; - } - } - - public void write( - int b) - throws IOException - { - if (partialBuffer != null) - { - writePartial((byte)b); - } - else - { - out.write(b); - } - } - - public void write( - byte[] bytes, - int off, - int len) - throws IOException - { - if (partialBuffer != null) - { - writePartial(bytes, off, len); - } - else - { - out.write(bytes, off, len); - } - } - - public void writePacket( - ContainedPacket p) - throws IOException - { - p.encode(this); - } - - void writePacket( - int tag, - byte[] body, - boolean oldFormat) - throws IOException - { - this.writeHeader(tag, oldFormat, false, body.length); - this.write(body); - } - - public void writeObject( - BCPGObject o) - throws IOException - { - o.encode(this); - } - - /** - * Flush the underlying stream. - */ - public void flush() - throws IOException - { - out.flush(); - } - - /** - * Finish writing out the current packet without closing the underlying stream. - */ - public void finish() - throws IOException - { - if (partialBuffer != null) - { - partialFlush(true); - partialBuffer = null; - } - } - - public void close() - throws IOException - { - this.finish(); - out.flush(); - out.close(); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/CRC24.java b/pg/src/main/java/org/bouncycastle/bcpg/CRC24.java deleted file mode 100644 index 82c4b9a8..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/CRC24.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.bouncycastle.bcpg; - -public class CRC24 -{ - private static final int CRC24_INIT = 0x0b704ce; - private static final int CRC24_POLY = 0x1864cfb; - - private int crc = CRC24_INIT; - - public CRC24() - { - } - - public void update( - int b) - { - crc ^= b << 16; - for (int i = 0; i < 8; i++) - { - crc <<= 1; - if ((crc & 0x1000000) != 0) - { - crc ^= CRC24_POLY; - } - } - } - - public int getValue() - { - return crc; - } - - public void reset() - { - crc = CRC24_INIT; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java deleted file mode 100644 index 7239d91e..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/CompressedDataPacket.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -/** - * A generic compressed data object. - */ -public class CompressedDataPacket - extends InputStreamPacket -{ - int algorithm; - - CompressedDataPacket( - BCPGInputStream in) - throws IOException - { - super(in); - - algorithm = in.read(); - } - - /** - * Gets the {@link CompressionAlgorithmTags compression algorithm} used for this packet. - * - * @return the compression algorithm tag value. - */ - public int getAlgorithm() - { - return algorithm; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/CompressionAlgorithmTags.java b/pg/src/main/java/org/bouncycastle/bcpg/CompressionAlgorithmTags.java deleted file mode 100644 index 0e947d54..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/CompressionAlgorithmTags.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Basic tags for compression algorithms - */ -public interface CompressionAlgorithmTags -{ - /** No compression. */ - public static final int UNCOMPRESSED = 0; - - /** ZIP (RFC 1951) compression. Unwrapped DEFLATE. */ - public static final int ZIP = 1; - - /** ZLIB (RFC 1950) compression. DEFLATE with a wrapper for better error detection. */ - public static final int ZLIB = 2; - - /** BZIP2 compression. Better compression than ZIP but much slower to compress and decompress. */ - public static final int BZIP2 = 3; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java deleted file mode 100644 index fca0078c..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ContainedPacket.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * Basic type for a PGP packet. - */ -public abstract class ContainedPacket - extends Packet -{ - public byte[] getEncoded() - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.writePacket(this); - - return bOut.toByteArray(); - } - - public abstract void encode( - BCPGOutputStream pOut) - throws IOException; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/DSAPublicBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/DSAPublicBCPGKey.java deleted file mode 100644 index c2315174..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/DSAPublicBCPGKey.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.math.BigInteger; - -/** - * base class for a DSA Public Key. - */ -public class DSAPublicBCPGKey - extends BCPGObject implements BCPGKey -{ - MPInteger p; - MPInteger q; - MPInteger g; - MPInteger y; - - /** - * @param in the stream to read the packet from. - */ - public DSAPublicBCPGKey( - BCPGInputStream in) - throws IOException - { - this.p = new MPInteger(in); - this.q = new MPInteger(in); - this.g = new MPInteger(in); - this.y = new MPInteger(in); - } - - public DSAPublicBCPGKey( - BigInteger p, - BigInteger q, - BigInteger g, - BigInteger y) - { - this.p = new MPInteger(p); - this.q = new MPInteger(q); - this.g = new MPInteger(g); - this.y = new MPInteger(y); - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(p); - out.writeObject(q); - out.writeObject(g); - out.writeObject(y); - } - - /** - * @return g - */ - public BigInteger getG() - { - return g.getValue(); - } - - /** - * @return p - */ - public BigInteger getP() - { - return p.getValue(); - } - - /** - * @return q - */ - public BigInteger getQ() - { - return q.getValue(); - } - - /** - * @return g - */ - public BigInteger getY() - { - return y.getValue(); - } - -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/DSASecretBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/DSASecretBCPGKey.java deleted file mode 100644 index 9f2d48f0..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/DSASecretBCPGKey.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.math.BigInteger; - -/** - * base class for a DSA Secret Key. - */ -public class DSASecretBCPGKey - extends BCPGObject implements BCPGKey -{ - MPInteger x; - - /** - * - * @param in - * @throws IOException - */ - public DSASecretBCPGKey( - BCPGInputStream in) - throws IOException - { - this.x = new MPInteger(in); - } - - /** - * - * @param x - */ - public DSASecretBCPGKey( - BigInteger x) - { - this.x = new MPInteger(x); - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(x); - } - - /** - * @return x - */ - public BigInteger getX() - { - return x.getValue(); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ECDHPublicBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/ECDHPublicBCPGKey.java deleted file mode 100644 index 44c5b30f..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ECDHPublicBCPGKey.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -import org.bouncycastle.asn1.ASN1ObjectIdentifier; -import org.bouncycastle.math.ec.ECPoint; - -/** - * base class for an ECDH Public Key. - */ -public class ECDHPublicBCPGKey - extends ECPublicBCPGKey -{ - private byte reserved; - private byte hashFunctionId; - private byte symAlgorithmId; - - /** - * @param in the stream to read the packet from. - */ - public ECDHPublicBCPGKey( - BCPGInputStream in) - throws IOException - { - super(in); - - int length = in.read(); - byte[] kdfParameters = new byte[length]; - if (kdfParameters.length != 3) - { - throw new IllegalStateException("kdf parameters size of 3 expected."); - } - - in.read(kdfParameters); - - reserved = kdfParameters[0]; - hashFunctionId = kdfParameters[1]; - symAlgorithmId = kdfParameters[2]; - - verifyHashAlgorithm(); - verifySymmetricKeyAlgorithm(); - } - - public ECDHPublicBCPGKey( - ASN1ObjectIdentifier oid, - ECPoint point, - int hashAlgorithm, - int symmetricKeyAlgorithm) - { - super(oid, point); - - reserved = 1; - hashFunctionId = (byte)hashAlgorithm; - symAlgorithmId = (byte)symmetricKeyAlgorithm; - - verifyHashAlgorithm(); - verifySymmetricKeyAlgorithm(); - } - - public byte getReserved() - { - return reserved; - } - - public byte getHashAlgorithm() - { - return hashFunctionId; - } - - public byte getSymmetricKeyAlgorithm() - { - return symAlgorithmId; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - super.encode(out); - out.write(0x3); - out.write(reserved); - out.write(hashFunctionId); - out.write(symAlgorithmId); - } - - private void verifyHashAlgorithm() - { - switch (hashFunctionId) - { - case HashAlgorithmTags.SHA256: - case HashAlgorithmTags.SHA384: - case HashAlgorithmTags.SHA512: - break; - - default: - throw new IllegalStateException("Hash algorithm must be SHA-256 or stronger."); - } - } - - private void verifySymmetricKeyAlgorithm() - { - switch (symAlgorithmId) - { - case SymmetricKeyAlgorithmTags.AES_128: - case SymmetricKeyAlgorithmTags.AES_192: - case SymmetricKeyAlgorithmTags.AES_256: - break; - - default: - throw new IllegalStateException("Symmetric key algorithm must be AES-128 or stronger."); - } - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ECDSAPublicBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/ECDSAPublicBCPGKey.java deleted file mode 100644 index a7b8867d..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ECDSAPublicBCPGKey.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; -import java.math.BigInteger; - -import org.bouncycastle.asn1.ASN1ObjectIdentifier; -import org.bouncycastle.math.ec.ECPoint; - -/** - * base class for an ECDSA Public Key. - */ -public class ECDSAPublicBCPGKey - extends ECPublicBCPGKey -{ - /** - * @param in the stream to read the packet from. - */ - protected ECDSAPublicBCPGKey( - BCPGInputStream in) - throws IOException - { - super(in); - } - - public ECDSAPublicBCPGKey( - ASN1ObjectIdentifier oid, - ECPoint point) - { - super(oid, point); - } - - public ECDSAPublicBCPGKey( - ASN1ObjectIdentifier oid, - BigInteger encodedPoint) - throws IOException - { - super(oid, encodedPoint); - } - -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ECPublicBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/ECPublicBCPGKey.java deleted file mode 100644 index 3c858439..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ECPublicBCPGKey.java +++ /dev/null @@ -1,151 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; - -import org.bouncycastle.asn1.ASN1ObjectIdentifier; -import org.bouncycastle.asn1.ASN1Primitive; -import org.bouncycastle.asn1.x9.ECNamedCurveTable; -import org.bouncycastle.asn1.x9.X9ECParameters; -import org.bouncycastle.crypto.ec.CustomNamedCurves; -import org.bouncycastle.math.ec.ECAlgorithms; -import org.bouncycastle.math.ec.ECPoint; -import org.bouncycastle.util.BigIntegers; - -/** - * base class for an EC Public Key. - */ -public abstract class ECPublicBCPGKey - extends BCPGObject - implements BCPGKey -{ - ASN1ObjectIdentifier oid; - ECPoint point; - - /** - * @param in the stream to read the packet from. - */ - protected ECPublicBCPGKey( - BCPGInputStream in) - throws IOException - { - this.oid = ASN1ObjectIdentifier.getInstance(ASN1Primitive.fromByteArray(readBytesOfEncodedLength(in))); - this.point = decodePoint(new MPInteger(in).getValue(), oid); - } - - protected ECPublicBCPGKey( - ASN1ObjectIdentifier oid, - ECPoint point) - { - this.point = point.normalize(); - this.oid = oid; - } - - protected ECPublicBCPGKey( - ASN1ObjectIdentifier oid, - BigInteger encodedPoint) - throws IOException - { - this.point = decodePoint(encodedPoint, oid); - this.oid = oid; - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - byte[] oid = this.oid.getEncoded(); - out.write(oid, 1, oid.length - 1); - - MPInteger point = new MPInteger(new BigInteger(1, this.point.getEncoded())); - out.writeObject(point); - } - - /** - * @return point - */ - public ECPoint getPoint() - { - return point; - } - - /** - * @return oid - */ - public ASN1ObjectIdentifier getCurveOID() - { - return oid; - } - - protected static byte[] readBytesOfEncodedLength( - BCPGInputStream in) - throws IOException - { - int length = in.read(); - if (length == 0 || length == 0xFF) - { - throw new IOException("future extensions not yet implemented."); - } - - byte[] buffer = new byte[length + 2]; - in.readFully(buffer, 2, buffer.length - 2); - buffer[0] = (byte)0x06; - buffer[1] = (byte)length; - - return buffer; - } - - private static ECPoint decodePoint( - BigInteger encodedPoint, - ASN1ObjectIdentifier oid) - throws IOException - { - X9ECParameters x9 = CustomNamedCurves.getByOID(oid); - if (x9 == null) - { - x9 = ECNamedCurveTable.getByOID(oid); - if (x9 == null) - { - throw new IOException(oid.getId() + " does not match any known curve."); - } - } - if (!ECAlgorithms.isFpCurve(x9.getCurve())) - { - throw new IOException("Only prime field curves are supported."); - } - return x9.getCurve().decodePoint(BigIntegers.asUnsignedByteArray(encodedPoint)); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ECSecretBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/ECSecretBCPGKey.java deleted file mode 100644 index bec3c0d6..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ECSecretBCPGKey.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.math.BigInteger; - -/** - * base class for an EC Secret Key. - */ -public class ECSecretBCPGKey - extends BCPGObject - implements BCPGKey -{ - MPInteger x; - - /** - * @param in - * @throws IOException - */ - public ECSecretBCPGKey( - BCPGInputStream in) - throws IOException - { - this.x = new MPInteger(in); - } - - /** - * @param x - */ - public ECSecretBCPGKey( - BigInteger x) - { - this.x = new MPInteger(x); - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(x); - } - - /** - * @return x - */ - public BigInteger getX() - { - return x.getValue(); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ElGamalPublicBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/ElGamalPublicBCPGKey.java deleted file mode 100644 index 8c273682..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ElGamalPublicBCPGKey.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.math.BigInteger; - -/** - * base class for an ElGamal Public Key. - */ -public class ElGamalPublicBCPGKey - extends BCPGObject implements BCPGKey -{ - MPInteger p; - MPInteger g; - MPInteger y; - - /** - * - */ - public ElGamalPublicBCPGKey( - BCPGInputStream in) - throws IOException - { - this.p = new MPInteger(in); - this.g = new MPInteger(in); - this.y = new MPInteger(in); - } - - public ElGamalPublicBCPGKey( - BigInteger p, - BigInteger g, - BigInteger y) - { - this.p = new MPInteger(p); - this.g = new MPInteger(g); - this.y = new MPInteger(y); - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public BigInteger getP() - { - return p.getValue(); - } - - public BigInteger getG() - { - return g.getValue(); - } - - public BigInteger getY() - { - return y.getValue(); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(p); - out.writeObject(g); - out.writeObject(y); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ElGamalSecretBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/ElGamalSecretBCPGKey.java deleted file mode 100644 index 31c113ce..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ElGamalSecretBCPGKey.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.math.BigInteger; - -/** - * base class for an ElGamal Secret Key. - */ -public class ElGamalSecretBCPGKey - extends BCPGObject implements BCPGKey -{ - MPInteger x; - - /** - * - * @param in - * @throws IOException - */ - public ElGamalSecretBCPGKey( - BCPGInputStream in) - throws IOException - { - this.x = new MPInteger(in); - } - - /** - * - * @param x - */ - public ElGamalSecretBCPGKey( - BigInteger x) - { - this.x = new MPInteger(x); - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - public BigInteger getX() - { - return x.getValue(); - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(x); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ExperimentalPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/ExperimentalPacket.java deleted file mode 100644 index 8407052b..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ExperimentalPacket.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -import org.bouncycastle.util.Arrays; - -/** - * basic packet for an experimental packet. - */ -public class ExperimentalPacket - extends ContainedPacket implements PublicKeyAlgorithmTags -{ - private int tag; - private byte[] contents; - - /** - * - * @param in - * @throws IOException - */ - ExperimentalPacket( - int tag, - BCPGInputStream in) - throws IOException - { - this.tag = tag; - this.contents = in.readAll(); - } - - public int getTag() - { - return tag; - } - - public byte[] getContents() - { - return Arrays.clone(contents); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(tag, contents, true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/HashAlgorithmTags.java b/pg/src/main/java/org/bouncycastle/bcpg/HashAlgorithmTags.java deleted file mode 100644 index da52bc85..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/HashAlgorithmTags.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * basic tags for hash algorithms - */ -public interface HashAlgorithmTags -{ - public static final int MD5 = 1; // MD5 - public static final int SHA1 = 2; // SHA-1 - public static final int RIPEMD160 = 3; // RIPE-MD/160 - public static final int DOUBLE_SHA = 4; // Reserved for double-width SHA (experimental) - public static final int MD2 = 5; // MD2 - public static final int TIGER_192 = 6; // Reserved for TIGER/192 - public static final int HAVAL_5_160 = 7; // Reserved for HAVAL (5 pass, 160-bit) - - public static final int SHA256 = 8; // SHA-256 - public static final int SHA384 = 9; // SHA-384 - public static final int SHA512 = 10; // SHA-512 - public static final int SHA224 = 11; // SHA-224 -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/InputStreamPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/InputStreamPacket.java deleted file mode 100644 index 9073a2e8..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/InputStreamPacket.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * A block of data associated with other packets in a PGP object stream. - */ -public class InputStreamPacket - extends Packet -{ - private BCPGInputStream in; - - public InputStreamPacket( - BCPGInputStream in) - { - this.in = in; - } - - /** - * Obtains an input stream to read the contents of the packet. - * <p/> - * Note: you can only read from this once... - * - * @return the data in this packet. - */ - public BCPGInputStream getInputStream() - { - return in; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/LiteralDataPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/LiteralDataPacket.java deleted file mode 100644 index b57c8bde..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/LiteralDataPacket.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.Strings; - -/** - * Generic literal data packet. - */ -public class LiteralDataPacket - extends InputStreamPacket -{ - int format; - byte[] fileName; - long modDate; - - LiteralDataPacket( - BCPGInputStream in) - throws IOException - { - super(in); - - format = in.read(); - int l = in.read(); - - fileName = new byte[l]; - for (int i = 0; i != fileName.length; i++) - { - fileName[i] = (byte)in.read(); - } - - modDate = ((long)in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read(); - } - - /** - * Return the format tag of the data packet. - */ - public int getFormat() - { - return format; - } - - /** - * Return the modification time for the file (milliseconds at second level precision). - */ - public long getModificationTime() - { - return modDate * 1000L; - } - - /** - * Return the file name associated with the data packet. - */ - public String getFileName() - { - return Strings.fromUTF8ByteArray(fileName); - } - - /** - * Return the file name as an uninterpreted byte array. - */ - public byte[] getRawFileName() - { - return Arrays.clone(fileName); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/MPInteger.java b/pg/src/main/java/org/bouncycastle/bcpg/MPInteger.java deleted file mode 100644 index ebd22615..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/MPInteger.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.math.BigInteger; - -/** - * a multiple precision integer - */ -public class MPInteger - extends BCPGObject -{ - BigInteger value = null; - - public MPInteger( - BCPGInputStream in) - throws IOException - { - int length = (in.read() << 8) | in.read(); - byte[] bytes = new byte[(length + 7) / 8]; - - in.readFully(bytes); - - value = new BigInteger(1, bytes); - } - - public MPInteger( - BigInteger value) - { - if (value == null || value.signum() < 0) - { - throw new IllegalArgumentException("value must not be null, or negative"); - } - - this.value = value; - } - - public BigInteger getValue() - { - return value; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - int length = value.bitLength(); - - out.write(length >> 8); - out.write(length); - - byte[] bytes = value.toByteArray(); - - if (bytes[0] == 0) - { - out.write(bytes, 1, bytes.length - 1); - } - else - { - out.write(bytes, 0, bytes.length); - } - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/MarkerPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/MarkerPacket.java deleted file mode 100644 index a3e9757f..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/MarkerPacket.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -/** - * Basic type for a marker packet - */ -public class MarkerPacket - extends ContainedPacket -{ - // "PGP" - - byte[] marker = { (byte)0x50, (byte)0x47, (byte)0x50 }; - - public MarkerPacket( - BCPGInputStream in) - throws IOException - { - in.readFully(marker); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(MARKER, marker, true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/ModDetectionCodePacket.java b/pg/src/main/java/org/bouncycastle/bcpg/ModDetectionCodePacket.java deleted file mode 100644 index 812e9374..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/ModDetectionCodePacket.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; - -/** - * basic packet for a modification detection code packet. - */ -public class ModDetectionCodePacket - extends ContainedPacket -{ - private byte[] digest; - - ModDetectionCodePacket( - BCPGInputStream in) - throws IOException - { - this.digest = new byte[20]; - in.readFully(this.digest); - } - - public ModDetectionCodePacket( - byte[] digest) - throws IOException - { - this.digest = new byte[digest.length]; - - System.arraycopy(digest, 0, this.digest, 0, this.digest.length); - } - - public byte[] getDigest() - { - byte[] tmp = new byte[digest.length]; - - System.arraycopy(digest, 0, tmp, 0, tmp.length); - - return tmp; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(MOD_DETECTION_CODE, digest, false); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java b/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java deleted file mode 100644 index fde95576..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; - -/** - * generic signature object - */ -public class OnePassSignaturePacket - extends ContainedPacket -{ - private int version; - private int sigType; - private int hashAlgorithm; - private int keyAlgorithm; - private long keyID; - private int nested; - - OnePassSignaturePacket( - BCPGInputStream in) - throws IOException - { - version = in.read(); - sigType = in.read(); - hashAlgorithm = in.read(); - keyAlgorithm = in.read(); - - keyID |= (long)in.read() << 56; - keyID |= (long)in.read() << 48; - keyID |= (long)in.read() << 40; - keyID |= (long)in.read() << 32; - keyID |= (long)in.read() << 24; - keyID |= (long)in.read() << 16; - keyID |= (long)in.read() << 8; - keyID |= in.read(); - - nested = in.read(); - } - - public OnePassSignaturePacket( - int sigType, - int hashAlgorithm, - int keyAlgorithm, - long keyID, - boolean isNested) - { - this.version = 3; - this.sigType = sigType; - this.hashAlgorithm = hashAlgorithm; - this.keyAlgorithm = keyAlgorithm; - this.keyID = keyID; - this.nested = (isNested) ? 0 : 1; - } - - /** - * Return the signature type. - * @return the signature type - */ - public int getSignatureType() - { - return sigType; - } - - /** - * return the encryption algorithm tag - */ - public int getKeyAlgorithm() - { - return keyAlgorithm; - } - - /** - * return the hashAlgorithm tag - */ - public int getHashAlgorithm() - { - return hashAlgorithm; - } - - /** - * @return long - */ - public long getKeyID() - { - return keyID; - } - - /** - * - */ - public void encode( - BCPGOutputStream out) - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.write(version); - pOut.write(sigType); - pOut.write(hashAlgorithm); - pOut.write(keyAlgorithm); - - pOut.write((byte)(keyID >> 56)); - pOut.write((byte)(keyID >> 48)); - pOut.write((byte)(keyID >> 40)); - pOut.write((byte)(keyID >> 32)); - pOut.write((byte)(keyID >> 24)); - pOut.write((byte)(keyID >> 16)); - pOut.write((byte)(keyID >> 8)); - pOut.write((byte)(keyID)); - - pOut.write(nested); - - out.writePacket(ONE_PASS_SIGNATURE, bOut.toByteArray(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/OutputStreamPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/OutputStreamPacket.java deleted file mode 100644 index fcf3a97b..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/OutputStreamPacket.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -public abstract class OutputStreamPacket -{ - protected BCPGOutputStream out; - - public OutputStreamPacket( - BCPGOutputStream out) - { - this.out = out; - } - - public abstract BCPGOutputStream open() throws IOException; - - public abstract void close() throws IOException; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/Packet.java b/pg/src/main/java/org/bouncycastle/bcpg/Packet.java deleted file mode 100644 index b233fd56..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/Packet.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - */ -public class Packet - implements PacketTags -{ - -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/PacketTags.java b/pg/src/main/java/org/bouncycastle/bcpg/PacketTags.java deleted file mode 100644 index 3fc163cb..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/PacketTags.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Basic PGP packet tag types. - */ -public interface PacketTags -{ - public static final int RESERVED = 0 ; // Reserved - a packet tag must not have this value - public static final int PUBLIC_KEY_ENC_SESSION = 1; // Public-Key Encrypted Session Key Packet - public static final int SIGNATURE = 2; // Signature Packet - public static final int SYMMETRIC_KEY_ENC_SESSION = 3; // Symmetric-Key Encrypted Session Key Packet - public static final int ONE_PASS_SIGNATURE = 4 ; // One-Pass Signature Packet - public static final int SECRET_KEY = 5; // Secret Key Packet - public static final int PUBLIC_KEY = 6 ; // Public Key Packet - public static final int SECRET_SUBKEY = 7; // Secret Subkey Packet - public static final int COMPRESSED_DATA = 8; // Compressed Data Packet - public static final int SYMMETRIC_KEY_ENC = 9; // Symmetrically Encrypted Data Packet - public static final int MARKER = 10; // Marker Packet - public static final int LITERAL_DATA = 11; // Literal Data Packet - public static final int TRUST = 12; // Trust Packet - public static final int USER_ID = 13; // User ID Packet - public static final int PUBLIC_SUBKEY = 14; // Public Subkey Packet - public static final int USER_ATTRIBUTE = 17; // User attribute - public static final int SYM_ENC_INTEGRITY_PRO = 18; // Symmetric encrypted, integrity protected - public static final int MOD_DETECTION_CODE = 19; // Modification detection code - - public static final int EXPERIMENTAL_1 = 60; // Private or Experimental Values - public static final int EXPERIMENTAL_2 = 61; - public static final int EXPERIMENTAL_3 = 62; - public static final int EXPERIMENTAL_4 = 63; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyAlgorithmTags.java b/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyAlgorithmTags.java deleted file mode 100644 index ef04c1c3..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyAlgorithmTags.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Public Key Algorithm tag numbers - */ -public interface PublicKeyAlgorithmTags -{ - public static final int RSA_GENERAL = 1; // RSA (Encrypt or Sign) - public static final int RSA_ENCRYPT = 2; // RSA Encrypt-Only - public static final int RSA_SIGN = 3; // RSA Sign-Only - public static final int ELGAMAL_ENCRYPT = 16; // Elgamal (Encrypt-Only), see [ELGAMAL] - public static final int DSA = 17; // DSA (Digital Signature Standard) - public static final int EC = 18; // Reserved for Elliptic Curve - public static final int ECDH = 18; // Reserved for Elliptic Curve (actual algorithm name) - public static final int ECDSA = 19; // Reserved for ECDSA - public static final int ELGAMAL_GENERAL = 20; // Elgamal (Encrypt or Sign) - public static final int DIFFIE_HELLMAN = 21; // Reserved for Diffie-Hellman (X9.42, as defined for IETF-S/MIME) - - public static final int EXPERIMENTAL_1 = 100; - public static final int EXPERIMENTAL_2 = 101; - public static final int EXPERIMENTAL_3 = 102; - public static final int EXPERIMENTAL_4 = 103; - public static final int EXPERIMENTAL_5 = 104; - public static final int EXPERIMENTAL_6 = 105; - public static final int EXPERIMENTAL_7 = 106; - public static final int EXPERIMENTAL_8 = 107; - public static final int EXPERIMENTAL_9 = 108; - public static final int EXPERIMENTAL_10 = 109; - public static final int EXPERIMENTAL_11 = 110; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyEncSessionPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyEncSessionPacket.java deleted file mode 100644 index a935dc33..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyEncSessionPacket.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.io.Streams; - -/** - * basic packet for a PGP public key - */ -public class PublicKeyEncSessionPacket - extends ContainedPacket implements PublicKeyAlgorithmTags -{ - private int version; - private long keyID; - private int algorithm; - private byte[][] data; - - PublicKeyEncSessionPacket( - BCPGInputStream in) - throws IOException - { - version = in.read(); - - keyID |= (long)in.read() << 56; - keyID |= (long)in.read() << 48; - keyID |= (long)in.read() << 40; - keyID |= (long)in.read() << 32; - keyID |= (long)in.read() << 24; - keyID |= (long)in.read() << 16; - keyID |= (long)in.read() << 8; - keyID |= in.read(); - - algorithm = in.read(); - - switch (algorithm) - { - case RSA_ENCRYPT: - case RSA_GENERAL: - data = new byte[1][]; - - data[0] = new MPInteger(in).getEncoded(); - break; - case ELGAMAL_ENCRYPT: - case ELGAMAL_GENERAL: - data = new byte[2][]; - - data[0] = new MPInteger(in).getEncoded(); - data[1] = new MPInteger(in).getEncoded(); - break; - case ECDH: - data = new byte[1][]; - - data[0] = Streams.readAll(in); - break; - default: - throw new IOException("unknown PGP public key algorithm encountered"); - } - } - - public PublicKeyEncSessionPacket( - long keyID, - int algorithm, - byte[][] data) - { - this.version = 3; - this.keyID = keyID; - this.algorithm = algorithm; - this.data = new byte[data.length][]; - - for (int i = 0; i != data.length; i++) - { - this.data[i] = Arrays.clone(data[i]); - } - } - - public int getVersion() - { - return version; - } - - public long getKeyID() - { - return keyID; - } - - public int getAlgorithm() - { - return algorithm; - } - - public byte[][] getEncSessionKey() - { - return data; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.write(version); - - pOut.write((byte)(keyID >> 56)); - pOut.write((byte)(keyID >> 48)); - pOut.write((byte)(keyID >> 40)); - pOut.write((byte)(keyID >> 32)); - pOut.write((byte)(keyID >> 24)); - pOut.write((byte)(keyID >> 16)); - pOut.write((byte)(keyID >> 8)); - pOut.write((byte)(keyID)); - - pOut.write(algorithm); - - for (int i = 0; i != data.length; i++) - { - pOut.write(data[i]); - } - - out.writePacket(PUBLIC_KEY_ENC_SESSION , bOut.toByteArray(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyPacket.java deleted file mode 100644 index 3a5dac26..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyPacket.java +++ /dev/null @@ -1,133 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Date; - -/** - * basic packet for a PGP public key - */ -public class PublicKeyPacket - extends ContainedPacket implements PublicKeyAlgorithmTags -{ - private int version; - private long time; - private int validDays; - private int algorithm; - private BCPGKey key; - - PublicKeyPacket( - BCPGInputStream in) - throws IOException - { - version = in.read(); - time = ((long)in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read(); - - if (version <= 3) - { - validDays = (in.read() << 8) | in.read(); - } - - algorithm = (byte)in.read(); - - switch (algorithm) - { - case RSA_ENCRYPT: - case RSA_GENERAL: - case RSA_SIGN: - key = new RSAPublicBCPGKey(in); - break; - case DSA: - key = new DSAPublicBCPGKey(in); - break; - case ELGAMAL_ENCRYPT: - case ELGAMAL_GENERAL: - key = new ElGamalPublicBCPGKey(in); - break; - case EC: - key = new ECDHPublicBCPGKey(in); - break; - case ECDSA: - key = new ECDSAPublicBCPGKey(in); - break; - default: - throw new IOException("unknown PGP public key algorithm encountered"); - } - } - - /** - * Construct version 4 public key packet. - * - * @param algorithm - * @param time - * @param key - */ - public PublicKeyPacket( - int algorithm, - Date time, - BCPGKey key) - { - this.version = 4; - this.time = time.getTime() / 1000; - this.algorithm = algorithm; - this.key = key; - } - - public int getVersion() - { - return version; - } - - public int getAlgorithm() - { - return algorithm; - } - - public int getValidDays() - { - return validDays; - } - - public Date getTime() - { - return new Date(time * 1000); - } - - public BCPGKey getKey() - { - return key; - } - - public byte[] getEncodedContents() - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.write(version); - - pOut.write((byte)(time >> 24)); - pOut.write((byte)(time >> 16)); - pOut.write((byte)(time >> 8)); - pOut.write((byte)time); - - if (version <= 3) - { - pOut.write((byte)(validDays >> 8)); - pOut.write((byte)validDays); - } - - pOut.write(algorithm); - - pOut.writeObject((BCPGObject)key); - - return bOut.toByteArray(); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(PUBLIC_KEY, getEncodedContents(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/PublicSubkeyPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/PublicSubkeyPacket.java deleted file mode 100644 index e203fe37..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/PublicSubkeyPacket.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.util.Date; - -/** - * basic packet for a PGP public key - */ -public class PublicSubkeyPacket - extends PublicKeyPacket -{ - PublicSubkeyPacket( - BCPGInputStream in) - throws IOException - { - super(in); - } - - /** - * Construct version 4 public key packet. - * - * @param algorithm - * @param time - * @param key - */ - public PublicSubkeyPacket( - int algorithm, - Date time, - BCPGKey key) - { - super(algorithm, time, key); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(PUBLIC_SUBKEY, getEncodedContents(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/RSAPublicBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/RSAPublicBCPGKey.java deleted file mode 100644 index 1729f4d8..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/RSAPublicBCPGKey.java +++ /dev/null @@ -1,91 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.math.BigInteger; -import java.io.*; - -/** - * base class for an RSA Public Key. - */ -public class RSAPublicBCPGKey - extends BCPGObject implements BCPGKey -{ - MPInteger n; - MPInteger e; - - /** - * Construct an RSA public key from the passed in stream. - * - * @param in - * @throws IOException - */ - public RSAPublicBCPGKey( - BCPGInputStream in) - throws IOException - { - this.n = new MPInteger(in); - this.e = new MPInteger(in); - } - - /** - * - * @param n the modulus - * @param e the public exponent - */ - public RSAPublicBCPGKey( - BigInteger n, - BigInteger e) - { - this.n = new MPInteger(n); - this.e = new MPInteger(e); - } - - public BigInteger getPublicExponent() - { - return e.getValue(); - } - - public BigInteger getModulus() - { - return n.getValue(); - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(n); - out.writeObject(e); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/RSASecretBCPGKey.java b/pg/src/main/java/org/bouncycastle/bcpg/RSASecretBCPGKey.java deleted file mode 100644 index 6a6e7e6d..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/RSASecretBCPGKey.java +++ /dev/null @@ -1,176 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; -import java.math.BigInteger; - -/** - * base class for an RSA Secret (or Private) Key. - */ -public class RSASecretBCPGKey - extends BCPGObject implements BCPGKey -{ - MPInteger d; - MPInteger p; - MPInteger q; - MPInteger u; - - BigInteger expP, expQ, crt; - - /** - * - * @param in - * @throws IOException - */ - public RSASecretBCPGKey( - BCPGInputStream in) - throws IOException - { - this.d = new MPInteger(in); - this.p = new MPInteger(in); - this.q = new MPInteger(in); - this.u = new MPInteger(in); - - expP = d.getValue().remainder(p.getValue().subtract(BigInteger.valueOf(1))); - expQ = d.getValue().remainder(q.getValue().subtract(BigInteger.valueOf(1))); - crt = q.getValue().modInverse(p.getValue()); - } - - /** - * - * @param d - * @param p - * @param q - */ - public RSASecretBCPGKey( - BigInteger d, - BigInteger p, - BigInteger q) - { - // - // pgp requires (p < q) - // - int cmp = p.compareTo(q); - if (cmp >= 0) - { - if (cmp == 0) - { - throw new IllegalArgumentException("p and q cannot be equal"); - } - - BigInteger tmp = p; - p = q; - q = tmp; - } - - this.d = new MPInteger(d); - this.p = new MPInteger(p); - this.q = new MPInteger(q); - this.u = new MPInteger(p.modInverse(q)); - - expP = d.remainder(p.subtract(BigInteger.valueOf(1))); - expQ = d.remainder(q.subtract(BigInteger.valueOf(1))); - crt = q.modInverse(p); - } - - /** - * return the modulus for this key. - * - * @return BigInteger - */ - public BigInteger getModulus() - { - return p.getValue().multiply(q.getValue()); - } - - /** - * return the private exponent for this key. - * - * @return BigInteger - */ - public BigInteger getPrivateExponent() - { - return d.getValue(); - } - - /** - * return the prime P - */ - public BigInteger getPrimeP() - { - return p.getValue(); - } - - /** - * return the prime Q - */ - public BigInteger getPrimeQ() - { - return q.getValue(); - } - - /** - * return the prime exponent of p - */ - public BigInteger getPrimeExponentP() - { - return expP; - } - - /** - * return the prime exponent of q - */ - public BigInteger getPrimeExponentQ() - { - return expQ; - } - - /** - * return the crt coefficient - */ - public BigInteger getCrtCoefficient() - { - return crt; - } - - /** - * return "PGP" - * - * @see org.bouncycastle.bcpg.BCPGKey#getFormat() - */ - public String getFormat() - { - return "PGP"; - } - - /** - * return the standard PGP encoding of the key. - * - * @see org.bouncycastle.bcpg.BCPGKey#getEncoded() - */ - public byte[] getEncoded() - { - try - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pgpOut = new BCPGOutputStream(bOut); - - pgpOut.writeObject(this); - - return bOut.toByteArray(); - } - catch (IOException e) - { - return null; - } - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writeObject(d); - out.writeObject(p); - out.writeObject(q); - out.writeObject(u); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/S2K.java b/pg/src/main/java/org/bouncycastle/bcpg/S2K.java deleted file mode 100644 index 389814f7..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/S2K.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; - - -/** - * Parameter specifier for the PGP string-to-key password based key derivation function. - * <p/> - * In iterated mode, S2K takes a single byte iteration count specifier, which is converted to an - * actual iteration count using a formula that grows the iteration count exponentially as the byte - * value increases.<br/> - * e.g. <code>0x01<code> == 1088 iterations, and <code>0xFF</code> == 65,011,712 iterations. - */ -public class S2K - extends BCPGObject -{ - private static final int EXPBIAS = 6; - - /** Simple key generation. A single non-salted iteration of a hash function */ - public static final int SIMPLE = 0; - /** Salted key generation. A single iteration of a hash function with a (unique) salt */ - public static final int SALTED = 1; - /** Salted and iterated key generation. Multiple iterations of a hash function, with a salt */ - public static final int SALTED_AND_ITERATED = 3; - - public static final int GNU_DUMMY_S2K = 101; - - int type; - int algorithm; - byte[] iv; - int itCount = -1; - int protectionMode = -1; - - S2K( - InputStream in) - throws IOException - { - DataInputStream dIn = new DataInputStream(in); - - type = dIn.read(); - algorithm = dIn.read(); - - // - // if this happens we have a dummy-S2K packet. - // - if (type != GNU_DUMMY_S2K) - { - if (type != 0) - { - iv = new byte[8]; - dIn.readFully(iv, 0, iv.length); - - if (type == 3) - { - itCount = dIn.read(); - } - } - } - else - { - dIn.read(); // G - dIn.read(); // N - dIn.read(); // U - protectionMode = dIn.read(); // protection mode - } - } - - /** - * Constructs a specifier for a {@link #SIMPLE simple} S2K generation. - * - * @param algorithm the {@link HashAlgorithmTags digest algorithm} to use. - */ - public S2K( - int algorithm) - { - this.type = 0; - this.algorithm = algorithm; - } - - /** - * Constructs a specifier for a {@link #SALTED salted} S2K generation. - * - * @param algorithm the {@link HashAlgorithmTags digest algorithm} to use. - * @param iv the salt to apply to input to the key generation. - */ - public S2K( - int algorithm, - byte[] iv) - { - this.type = 1; - this.algorithm = algorithm; - this.iv = iv; - } - - /** - * Constructs a specifier for a {@link #SALTED_AND_ITERATED salted and iterated} S2K generation. - * - * @param algorithm the {@link HashAlgorithmTags digest algorithm} to iterate. - * @param iv the salt to apply to input to the key generation. - * @param itCount the single byte iteration count specifier. - */ - public S2K( - int algorithm, - byte[] iv, - int itCount) - { - this.type = 3; - this.algorithm = algorithm; - this.iv = iv; - this.itCount = itCount; - } - - /** - * Gets the {@link HashAlgorithmTags digest algorithm} specified. - */ - public int getType() - { - return type; - } - - /** - * Gets the {@link HashAlgorithmTags hash algorithm} for this S2K. - */ - public int getHashAlgorithm() - { - return algorithm; - } - - /** - * Gets the iv/salt to use for the key generation. - */ - public byte[] getIV() - { - return iv; - } - - /** - * Gets the actual (expanded) iteration count. - */ - public long getIterationCount() - { - return (16 + (itCount & 15)) << ((itCount >> 4) + EXPBIAS); - } - - /** - * Gets the protection mode - only if GNU_DUMMY_S2K - */ - public int getProtectionMode() - { - return protectionMode; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.write(type); - out.write(algorithm); - - if (type != GNU_DUMMY_S2K) - { - if (type != 0) - { - out.write(iv); - } - - if (type == 3) - { - out.write(itCount); - } - } - else - { - out.write('G'); - out.write('N'); - out.write('U'); - out.write(protectionMode); - } - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SecretKeyPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SecretKeyPacket.java deleted file mode 100644 index d362bb93..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SecretKeyPacket.java +++ /dev/null @@ -1,185 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * basic packet for a PGP secret key - */ -public class SecretKeyPacket - extends ContainedPacket implements PublicKeyAlgorithmTags -{ - public static final int USAGE_NONE = 0x00; - public static final int USAGE_CHECKSUM = 0xff; - public static final int USAGE_SHA1 = 0xfe; - - private PublicKeyPacket pubKeyPacket; - private byte[] secKeyData; - private int s2kUsage; - private int encAlgorithm; - private S2K s2k; - private byte[] iv; - - /** - * - * @param in - * @throws IOException - */ - SecretKeyPacket( - BCPGInputStream in) - throws IOException - { - if (this instanceof SecretSubkeyPacket) - { - pubKeyPacket = new PublicSubkeyPacket(in); - } - else - { - pubKeyPacket = new PublicKeyPacket(in); - } - - s2kUsage = in.read(); - - if (s2kUsage == USAGE_CHECKSUM || s2kUsage == USAGE_SHA1) - { - encAlgorithm = in.read(); - s2k = new S2K(in); - } - else - { - encAlgorithm = s2kUsage; - } - - if (!(s2k != null && s2k.getType() == S2K.GNU_DUMMY_S2K && s2k.getProtectionMode() == 0x01)) - { - if (s2kUsage != 0) - { - if (encAlgorithm < 7) - { - iv = new byte[8]; - } - else - { - iv = new byte[16]; - } - in.readFully(iv, 0, iv.length); - } - } - - this.secKeyData = in.readAll(); - } - - /** - * - * @param pubKeyPacket - * @param encAlgorithm - * @param s2k - * @param iv - * @param secKeyData - */ - public SecretKeyPacket( - PublicKeyPacket pubKeyPacket, - int encAlgorithm, - S2K s2k, - byte[] iv, - byte[] secKeyData) - { - this.pubKeyPacket = pubKeyPacket; - this.encAlgorithm = encAlgorithm; - - if (encAlgorithm != SymmetricKeyAlgorithmTags.NULL) - { - this.s2kUsage = USAGE_CHECKSUM; - } - else - { - this.s2kUsage = USAGE_NONE; - } - - this.s2k = s2k; - this.iv = iv; - this.secKeyData = secKeyData; - } - - public SecretKeyPacket( - PublicKeyPacket pubKeyPacket, - int encAlgorithm, - int s2kUsage, - S2K s2k, - byte[] iv, - byte[] secKeyData) - { - this.pubKeyPacket = pubKeyPacket; - this.encAlgorithm = encAlgorithm; - this.s2kUsage = s2kUsage; - this.s2k = s2k; - this.iv = iv; - this.secKeyData = secKeyData; - } - - public int getEncAlgorithm() - { - return encAlgorithm; - } - - public int getS2KUsage() - { - return s2kUsage; - } - - public byte[] getIV() - { - return iv; - } - - public S2K getS2K() - { - return s2k; - } - - public PublicKeyPacket getPublicKeyPacket() - { - return pubKeyPacket; - } - - public byte[] getSecretKeyData() - { - return secKeyData; - } - - public byte[] getEncodedContents() - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.write(pubKeyPacket.getEncodedContents()); - - pOut.write(s2kUsage); - - if (s2kUsage == USAGE_CHECKSUM || s2kUsage == USAGE_SHA1) - { - pOut.write(encAlgorithm); - pOut.writeObject(s2k); - } - - if (iv != null) - { - pOut.write(iv); - } - - if (secKeyData != null && secKeyData.length > 0) - { - pOut.write(secKeyData); - } - - return bOut.toByteArray(); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(SECRET_KEY, getEncodedContents(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SecretSubkeyPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SecretSubkeyPacket.java deleted file mode 100644 index 728ab3d7..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SecretSubkeyPacket.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.*; - -/** - * basic packet for a PGP secret key - */ -public class SecretSubkeyPacket - extends SecretKeyPacket -{ - /** - * - * @param in - * @throws IOException - */ - SecretSubkeyPacket( - BCPGInputStream in) - throws IOException - { - super(in); - } - - /** - * - * @param pubKeyPacket - * @param encAlgorithm - * @param s2k - * @param iv - * @param secKeyData - */ - public SecretSubkeyPacket( - PublicKeyPacket pubKeyPacket, - int encAlgorithm, - S2K s2k, - byte[] iv, - byte[] secKeyData) - { - super(pubKeyPacket, encAlgorithm, s2k, iv, secKeyData); - } - - public SecretSubkeyPacket( - PublicKeyPacket pubKeyPacket, - int encAlgorithm, - int s2kUsage, - S2K s2k, - byte[] iv, - byte[] secKeyData) - { - super(pubKeyPacket, encAlgorithm, s2kUsage, s2k, iv, secKeyData); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(SECRET_SUBKEY, getEncodedContents(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java deleted file mode 100644 index 75edc025..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SignaturePacket.java +++ /dev/null @@ -1,531 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Vector; - -import org.bouncycastle.bcpg.sig.IssuerKeyID; -import org.bouncycastle.bcpg.sig.SignatureCreationTime; -import org.bouncycastle.util.Arrays; - -/** - * generic signature packet - */ -public class SignaturePacket - extends ContainedPacket implements PublicKeyAlgorithmTags -{ - private int version; - private int signatureType; - private long creationTime; - private long keyID; - private int keyAlgorithm; - private int hashAlgorithm; - private MPInteger[] signature; - private byte[] fingerPrint; - private SignatureSubpacket[] hashedData; - private SignatureSubpacket[] unhashedData; - private byte[] signatureEncoding; - - SignaturePacket( - BCPGInputStream in) - throws IOException - { - version = in.read(); - - if (version == 3 || version == 2) - { - int l = in.read(); - - signatureType = in.read(); - creationTime = (((long)in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read()) * 1000; - keyID |= (long)in.read() << 56; - keyID |= (long)in.read() << 48; - keyID |= (long)in.read() << 40; - keyID |= (long)in.read() << 32; - keyID |= (long)in.read() << 24; - keyID |= (long)in.read() << 16; - keyID |= (long)in.read() << 8; - keyID |= in.read(); - keyAlgorithm = in.read(); - hashAlgorithm = in.read(); - } - else if (version == 4) - { - signatureType = in.read(); - keyAlgorithm = in.read(); - hashAlgorithm = in.read(); - - int hashedLength = (in.read() << 8) | in.read(); - byte[] hashed = new byte[hashedLength]; - - in.readFully(hashed); - - // - // read the signature sub packet data. - // - SignatureSubpacket sub; - SignatureSubpacketInputStream sIn = new SignatureSubpacketInputStream( - new ByteArrayInputStream(hashed)); - - Vector v = new Vector(); - while ((sub = sIn.readPacket()) != null) - { - v.addElement(sub); - } - - hashedData = new SignatureSubpacket[v.size()]; - - for (int i = 0; i != hashedData.length; i++) - { - SignatureSubpacket p = (SignatureSubpacket)v.elementAt(i); - if (p instanceof IssuerKeyID) - { - keyID = ((IssuerKeyID)p).getKeyID(); - } - else if (p instanceof SignatureCreationTime) - { - creationTime = ((SignatureCreationTime)p).getTime().getTime(); - } - - hashedData[i] = p; - } - - int unhashedLength = (in.read() << 8) | in.read(); - byte[] unhashed = new byte[unhashedLength]; - - in.readFully(unhashed); - - sIn = new SignatureSubpacketInputStream( - new ByteArrayInputStream(unhashed)); - - v.removeAllElements(); - while ((sub = sIn.readPacket()) != null) - { - v.addElement(sub); - } - - unhashedData = new SignatureSubpacket[v.size()]; - - for (int i = 0; i != unhashedData.length; i++) - { - SignatureSubpacket p = (SignatureSubpacket)v.elementAt(i); - if (p instanceof IssuerKeyID) - { - keyID = ((IssuerKeyID)p).getKeyID(); - } - - unhashedData[i] = p; - } - } - else - { - throw new RuntimeException("unsupported version: " + version); - } - - fingerPrint = new byte[2]; - in.readFully(fingerPrint); - - switch (keyAlgorithm) - { - case RSA_GENERAL: - case RSA_SIGN: - MPInteger v = new MPInteger(in); - - signature = new MPInteger[1]; - signature[0] = v; - break; - case DSA: - MPInteger r = new MPInteger(in); - MPInteger s = new MPInteger(in); - - signature = new MPInteger[2]; - signature[0] = r; - signature[1] = s; - break; - case ELGAMAL_ENCRYPT: // yep, this really does happen sometimes. - case ELGAMAL_GENERAL: - MPInteger p = new MPInteger(in); - MPInteger g = new MPInteger(in); - MPInteger y = new MPInteger(in); - - signature = new MPInteger[3]; - signature[0] = p; - signature[1] = g; - signature[2] = y; - break; - case ECDSA: - MPInteger ecR = new MPInteger(in); - MPInteger ecS = new MPInteger(in); - - signature = new MPInteger[2]; - signature[0] = ecR; - signature[1] = ecS; - break; - default: - if (keyAlgorithm >= PublicKeyAlgorithmTags.EXPERIMENTAL_1 && keyAlgorithm <= PublicKeyAlgorithmTags.EXPERIMENTAL_11) - { - signature = null; - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - int ch; - while ((ch = in.read()) >= 0) - { - bOut.write(ch); - } - signatureEncoding = bOut.toByteArray(); - } - else - { - throw new IOException("unknown signature key algorithm: " + keyAlgorithm); - } - } - } - - /** - * Generate a version 4 signature packet. - * - * @param signatureType - * @param keyAlgorithm - * @param hashAlgorithm - * @param hashedData - * @param unhashedData - * @param fingerPrint - * @param signature - */ - public SignaturePacket( - int signatureType, - long keyID, - int keyAlgorithm, - int hashAlgorithm, - SignatureSubpacket[] hashedData, - SignatureSubpacket[] unhashedData, - byte[] fingerPrint, - MPInteger[] signature) - { - this(4, signatureType, keyID, keyAlgorithm, hashAlgorithm, hashedData, unhashedData, fingerPrint, signature); - } - - /** - * Generate a version 2/3 signature packet. - * - * @param signatureType - * @param keyAlgorithm - * @param hashAlgorithm - * @param fingerPrint - * @param signature - */ - public SignaturePacket( - int version, - int signatureType, - long keyID, - int keyAlgorithm, - int hashAlgorithm, - long creationTime, - byte[] fingerPrint, - MPInteger[] signature) - { - this(version, signatureType, keyID, keyAlgorithm, hashAlgorithm, null, null, fingerPrint, signature); - - this.creationTime = creationTime; - } - - public SignaturePacket( - int version, - int signatureType, - long keyID, - int keyAlgorithm, - int hashAlgorithm, - SignatureSubpacket[] hashedData, - SignatureSubpacket[] unhashedData, - byte[] fingerPrint, - MPInteger[] signature) - { - this.version = version; - this.signatureType = signatureType; - this.keyID = keyID; - this.keyAlgorithm = keyAlgorithm; - this.hashAlgorithm = hashAlgorithm; - this.hashedData = hashedData; - this.unhashedData = unhashedData; - this.fingerPrint = fingerPrint; - this.signature = signature; - - if (hashedData != null) - { - setCreationTime(); - } - } - - /** - * get the version number - */ - public int getVersion() - { - return version; - } - - /** - * return the signature type. - */ - public int getSignatureType() - { - return signatureType; - } - - /** - * return the keyID - * @return the keyID that created the signature. - */ - public long getKeyID() - { - return keyID; - } - - /** - * return the signature trailer that must be included with the data - * to reconstruct the signature - * - * @return byte[] - */ - public byte[] getSignatureTrailer() - { - byte[] trailer = null; - - if (version == 3 || version == 2) - { - trailer = new byte[5]; - - long time = creationTime / 1000; - - trailer[0] = (byte)signatureType; - trailer[1] = (byte)(time >> 24); - trailer[2] = (byte)(time >> 16); - trailer[3] = (byte)(time >> 8); - trailer[4] = (byte)(time); - } - else - { - ByteArrayOutputStream sOut = new ByteArrayOutputStream(); - - try - { - sOut.write((byte)this.getVersion()); - sOut.write((byte)this.getSignatureType()); - sOut.write((byte)this.getKeyAlgorithm()); - sOut.write((byte)this.getHashAlgorithm()); - - ByteArrayOutputStream hOut = new ByteArrayOutputStream(); - SignatureSubpacket[] hashed = this.getHashedSubPackets(); - - for (int i = 0; i != hashed.length; i++) - { - hashed[i].encode(hOut); - } - - byte[] data = hOut.toByteArray(); - - sOut.write((byte)(data.length >> 8)); - sOut.write((byte)data.length); - sOut.write(data); - - byte[] hData = sOut.toByteArray(); - - sOut.write((byte)this.getVersion()); - sOut.write((byte)0xff); - sOut.write((byte)(hData.length>> 24)); - sOut.write((byte)(hData.length >> 16)); - sOut.write((byte)(hData.length >> 8)); - sOut.write((byte)(hData.length)); - } - catch (IOException e) - { - throw new RuntimeException("exception generating trailer: " + e); - } - - trailer = sOut.toByteArray(); - } - - return trailer; - } - - /** - * return the encryption algorithm tag - */ - public int getKeyAlgorithm() - { - return keyAlgorithm; - } - - /** - * return the hashAlgorithm tag - */ - public int getHashAlgorithm() - { - return hashAlgorithm; - } - - /** - * return the signature as a set of integers - note this is normalised to be the - * ASN.1 encoding of what appears in the signature packet. - */ - public MPInteger[] getSignature() - { - return signature; - } - - /** - * Return the byte encoding of the signature section. - * @return uninterpreted signature bytes. - */ - public byte[] getSignatureBytes() - { - if (signatureEncoding == null) - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream bcOut = new BCPGOutputStream(bOut); - - for (int i = 0; i != signature.length; i++) - { - try - { - bcOut.writeObject(signature[i]); - } - catch (IOException e) - { - throw new RuntimeException("internal error: " + e); - } - } - return bOut.toByteArray(); - } - else - { - return Arrays.clone(signatureEncoding); - } - } - public SignatureSubpacket[] getHashedSubPackets() - { - return hashedData; - } - - public SignatureSubpacket[] getUnhashedSubPackets() - { - return unhashedData; - } - - /** - * Return the creation time of the signature in milli-seconds. - * - * @return the creation time in millis - */ - public long getCreationTime() - { - return creationTime; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.write(version); - - if (version == 3 || version == 2) - { - pOut.write(5); // the length of the next block - - long time = creationTime / 1000; - - pOut.write(signatureType); - pOut.write((byte)(time >> 24)); - pOut.write((byte)(time >> 16)); - pOut.write((byte)(time >> 8)); - pOut.write((byte)time); - - pOut.write((byte)(keyID >> 56)); - pOut.write((byte)(keyID >> 48)); - pOut.write((byte)(keyID >> 40)); - pOut.write((byte)(keyID >> 32)); - pOut.write((byte)(keyID >> 24)); - pOut.write((byte)(keyID >> 16)); - pOut.write((byte)(keyID >> 8)); - pOut.write((byte)(keyID)); - - pOut.write(keyAlgorithm); - pOut.write(hashAlgorithm); - } - else if (version == 4) - { - pOut.write(signatureType); - pOut.write(keyAlgorithm); - pOut.write(hashAlgorithm); - - ByteArrayOutputStream sOut = new ByteArrayOutputStream(); - - for (int i = 0; i != hashedData.length; i++) - { - hashedData[i].encode(sOut); - } - - byte[] data = sOut.toByteArray(); - - pOut.write(data.length >> 8); - pOut.write(data.length); - pOut.write(data); - - sOut.reset(); - - for (int i = 0; i != unhashedData.length; i++) - { - unhashedData[i].encode(sOut); - } - - data = sOut.toByteArray(); - - pOut.write(data.length >> 8); - pOut.write(data.length); - pOut.write(data); - } - else - { - throw new IOException("unknown version: " + version); - } - - pOut.write(fingerPrint); - - if (signature != null) - { - for (int i = 0; i != signature.length; i++) - { - pOut.writeObject(signature[i]); - } - } - else - { - pOut.write(signatureEncoding); - } - - out.writePacket(SIGNATURE, bOut.toByteArray(), true); - } - - private void setCreationTime() - { - for (int i = 0; i != hashedData.length; i++) - { - if (hashedData[i] instanceof SignatureCreationTime) - { - creationTime = ((SignatureCreationTime)hashedData[i]).getTime().getTime(); - break; - } - } - } - - public static SignaturePacket fromByteArray(byte[] data) - throws IOException - { - BCPGInputStream in = new BCPGInputStream(new ByteArrayInputStream(data)); - - return new SignaturePacket(in); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java deleted file mode 100644 index c44e9eac..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacket.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; -import java.io.OutputStream; - -/** - * Basic type for a PGP Signature sub-packet. - */ -public class SignatureSubpacket -{ - int type; - boolean critical; - - protected byte[] data; - - protected SignatureSubpacket( - int type, - boolean critical, - byte[] data) - { - this.type = type; - this.critical = critical; - this.data = data; - } - - public int getType() - { - return type; - } - - public boolean isCritical() - { - return critical; - } - - /** - * return the generic data making up the packet. - */ - public byte[] getData() - { - return data; - } - - public void encode( - OutputStream out) - throws IOException - { - int bodyLen = data.length + 1; - - if (bodyLen < 192) - { - out.write((byte)bodyLen); - } - else if (bodyLen <= 8383) - { - bodyLen -= 192; - - out.write((byte)(((bodyLen >> 8) & 0xff) + 192)); - out.write((byte)bodyLen); - } - else - { - out.write(0xff); - out.write((byte)(bodyLen >> 24)); - out.write((byte)(bodyLen >> 16)); - out.write((byte)(bodyLen >> 8)); - out.write((byte)bodyLen); - } - - if (critical) - { - out.write(0x80 | type); - } - else - { - out.write(type); - } - - out.write(data); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketInputStream.java b/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketInputStream.java deleted file mode 100644 index 891511be..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketInputStream.java +++ /dev/null @@ -1,159 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; - -import org.bouncycastle.bcpg.sig.Exportable; -import org.bouncycastle.bcpg.sig.IssuerKeyID; -import org.bouncycastle.bcpg.sig.KeyExpirationTime; -import org.bouncycastle.bcpg.sig.KeyFlags; -import org.bouncycastle.bcpg.sig.NotationData; -import org.bouncycastle.bcpg.sig.PreferredAlgorithms; -import org.bouncycastle.bcpg.sig.PrimaryUserID; -import org.bouncycastle.bcpg.sig.Revocable; -import org.bouncycastle.bcpg.sig.SignatureCreationTime; -import org.bouncycastle.bcpg.sig.SignatureExpirationTime; -import org.bouncycastle.bcpg.sig.SignerUserID; -import org.bouncycastle.bcpg.sig.TrustSignature; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.io.Streams; - -/** - * reader for signature sub-packets - */ -public class SignatureSubpacketInputStream - extends InputStream implements SignatureSubpacketTags -{ - InputStream in; - - public SignatureSubpacketInputStream( - InputStream in) - { - this.in = in; - } - - public int available() - throws IOException - { - return in.available(); - } - - public int read() - throws IOException - { - return in.read(); - } - - public SignatureSubpacket readPacket() - throws IOException - { - int l = this.read(); - int bodyLen = 0; - - if (l < 0) - { - return null; - } - - if (l < 192) - { - bodyLen = l; - } - else if (l <= 223) - { - bodyLen = ((l - 192) << 8) + (in.read()) + 192; - } - else if (l == 255) - { - bodyLen = (in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read(); - } - else - { - // TODO Error? - } - - int tag = in.read(); - - if (tag < 0) - { - throw new EOFException("unexpected EOF reading signature sub packet"); - } - - byte[] data = new byte[bodyLen - 1]; - - // - // this may seem a bit strange but it turns out some applications miscode the length - // in fixed length fields, so we check the length we do get, only throwing an exception if - // we really cannot continue - // - int bytesRead = Streams.readFully(in, data); - - boolean isCritical = ((tag & 0x80) != 0); - int type = tag & 0x7f; - - if (bytesRead != data.length) - { - switch (type) - { - case CREATION_TIME: - data = checkData(data, 4, bytesRead, "Signature Creation Time"); - break; - case ISSUER_KEY_ID: - data = checkData(data, 8, bytesRead, "Issuer"); - break; - case KEY_EXPIRE_TIME: - data = checkData(data, 4, bytesRead, "Signature Key Expiration Time"); - break; - case EXPIRE_TIME: - data = checkData(data, 4, bytesRead, "Signature Expiration Time"); - break; - default: - throw new EOFException("truncated subpacket data."); - } - } - - switch (type) - { - case CREATION_TIME: - return new SignatureCreationTime(isCritical, data); - case KEY_EXPIRE_TIME: - return new KeyExpirationTime(isCritical, data); - case EXPIRE_TIME: - return new SignatureExpirationTime(isCritical, data); - case REVOCABLE: - return new Revocable(isCritical, data); - case EXPORTABLE: - return new Exportable(isCritical, data); - case ISSUER_KEY_ID: - return new IssuerKeyID(isCritical, data); - case TRUST_SIG: - return new TrustSignature(isCritical, data); - case PREFERRED_COMP_ALGS: - case PREFERRED_HASH_ALGS: - case PREFERRED_SYM_ALGS: - return new PreferredAlgorithms(type, isCritical, data); - case KEY_FLAGS: - return new KeyFlags(isCritical, data); - case PRIMARY_USER_ID: - return new PrimaryUserID(isCritical, data); - case SIGNER_USER_ID: - return new SignerUserID(isCritical, data); - case NOTATION_DATA: - return new NotationData(isCritical, data); - } - - return new SignatureSubpacket(type, isCritical, data); - } - - private byte[] checkData(byte[] data, int expected, int bytesRead, String name) - throws EOFException - { - if (bytesRead != expected) - { - throw new EOFException("truncated " + name + " subpacket data."); - } - - return Arrays.copyOfRange(data, 0, expected); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketTags.java b/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketTags.java deleted file mode 100644 index 8c279586..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SignatureSubpacketTags.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Basic PGP signature sub-packet tag types. - */ -public interface SignatureSubpacketTags -{ - public static final int CREATION_TIME = 2; // signature creation time - public static final int EXPIRE_TIME = 3; // signature expiration time - public static final int EXPORTABLE = 4; // exportable certification - public static final int TRUST_SIG = 5; // trust signature - public static final int REG_EXP = 6; // regular expression - public static final int REVOCABLE = 7; // revocable - public static final int KEY_EXPIRE_TIME = 9; // key expiration time - public static final int PLACEHOLDER = 10; // placeholder for backward compatibility - public static final int PREFERRED_SYM_ALGS = 11; // preferred symmetric algorithms - public static final int REVOCATION_KEY = 12; // revocation key - public static final int ISSUER_KEY_ID = 16; // issuer key ID - public static final int NOTATION_DATA = 20; // notation data - public static final int PREFERRED_HASH_ALGS = 21; // preferred hash algorithms - public static final int PREFERRED_COMP_ALGS = 22; // preferred compression algorithms - public static final int KEY_SERVER_PREFS = 23; // key server preferences - public static final int PREFERRED_KEY_SERV = 24; // preferred key server - public static final int PRIMARY_USER_ID = 25; // primary user id - public static final int POLICY_URL = 26; // policy URL - public static final int KEY_FLAGS = 27; // key flags - public static final int SIGNER_USER_ID = 28; // signer's user id - public static final int REVOCATION_REASON = 29; // reason for revocation - public static final int FEATURES = 30; // features - public static final int SIGNATURE_TARGET = 31; // signature target - public static final int EMBEDDED_SIGNATURE = 32; // embedded signature -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricEncDataPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SymmetricEncDataPacket.java deleted file mode 100644 index 6efe350a..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricEncDataPacket.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Basic type for a symmetric key encrypted packet - */ -public class SymmetricEncDataPacket - extends InputStreamPacket -{ - public SymmetricEncDataPacket( - BCPGInputStream in) - { - super(in); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java deleted file mode 100644 index 8e8fac66..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricEncIntegrityPacket.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -/** - * A symmetric key encrypted packet with an associated integrity check code. - */ -public class SymmetricEncIntegrityPacket - extends InputStreamPacket -{ - int version; - - SymmetricEncIntegrityPacket( - BCPGInputStream in) - throws IOException - { - super(in); - - version = in.read(); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyAlgorithmTags.java b/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyAlgorithmTags.java deleted file mode 100644 index 43b66cd2..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyAlgorithmTags.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Basic tags for symmetric key algorithms - */ -public interface SymmetricKeyAlgorithmTags -{ - public static final int NULL = 0; // Plaintext or unencrypted data - public static final int IDEA = 1; // IDEA [IDEA] - public static final int TRIPLE_DES = 2; // Triple-DES (DES-EDE, as per spec -168 bit key derived from 192) - public static final int CAST5 = 3; // CAST5 (128 bit key, as per RFC 2144) - public static final int BLOWFISH = 4; // Blowfish (128 bit key, 16 rounds) [BLOWFISH] - public static final int SAFER = 5; // SAFER-SK128 (13 rounds) [SAFER] - public static final int DES = 6; // Reserved for DES/SK - public static final int AES_128 = 7; // Reserved for AES with 128-bit key - public static final int AES_192 = 8; // Reserved for AES with 192-bit key - public static final int AES_256 = 9; // Reserved for AES with 256-bit key - public static final int TWOFISH = 10; // Reserved for Twofish - public static final int CAMELLIA_128 = 11; // Reserved for Camellia with 128-bit key - public static final int CAMELLIA_192 = 12; // Reserved for Camellia with 192-bit key - public static final int CAMELLIA_256 = 13; // Reserved for Camellia with 256-bit key -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyEncSessionPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyEncSessionPacket.java deleted file mode 100644 index 37769fef..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/SymmetricKeyEncSessionPacket.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * Basic type for a symmetric encrypted session key packet - */ -public class SymmetricKeyEncSessionPacket - extends ContainedPacket -{ - private int version; - private int encAlgorithm; - private S2K s2k; - private byte[] secKeyData; - - public SymmetricKeyEncSessionPacket( - BCPGInputStream in) - throws IOException - { - version = in.read(); - encAlgorithm = in.read(); - - s2k = new S2K(in); - - this.secKeyData = in.readAll(); - } - - public SymmetricKeyEncSessionPacket( - int encAlgorithm, - S2K s2k, - byte[] secKeyData) - { - this.version = 4; - this.encAlgorithm = encAlgorithm; - this.s2k = s2k; - this.secKeyData = secKeyData; - } - - /** - * @return int - */ - public int getEncAlgorithm() - { - return encAlgorithm; - } - - /** - * @return S2K - */ - public S2K getS2K() - { - return s2k; - } - - /** - * @return byte[] - */ - public byte[] getSecKeyData() - { - return secKeyData; - } - - /** - * @return int - */ - public int getVersion() - { - return version; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - BCPGOutputStream pOut = new BCPGOutputStream(bOut); - - pOut.write(version); - pOut.write(encAlgorithm); - pOut.writeObject(s2k); - - if (secKeyData != null && secKeyData.length > 0) - { - pOut.write(secKeyData); - } - - out.writePacket(SYMMETRIC_KEY_ENC_SESSION, bOut.toByteArray(), true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/TrustPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/TrustPacket.java deleted file mode 100644 index 05a00322..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/TrustPacket.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -/** - * Basic type for a trust packet - */ -public class TrustPacket - extends ContainedPacket -{ - byte[] levelAndTrustAmount; - - public TrustPacket( - BCPGInputStream in) - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - int ch; - - while ((ch = in.read()) >= 0) - { - bOut.write(ch); - } - - levelAndTrustAmount = bOut.toByteArray(); - } - - public TrustPacket( - int trustCode) - { - this.levelAndTrustAmount = new byte[1]; - - this.levelAndTrustAmount[0] = (byte)trustCode; - } - - public byte[] getLevelAndTrustAmount() - { - return levelAndTrustAmount; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(TRUST, levelAndTrustAmount, true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributePacket.java b/pg/src/main/java/org/bouncycastle/bcpg/UserAttributePacket.java deleted file mode 100644 index 3f4913ab..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributePacket.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Vector; - -/** - * Basic type for a user attribute packet. - */ -public class UserAttributePacket - extends ContainedPacket -{ - private UserAttributeSubpacket[] subpackets; - - public UserAttributePacket( - BCPGInputStream in) - throws IOException - { - UserAttributeSubpacketInputStream sIn = new UserAttributeSubpacketInputStream(in); - UserAttributeSubpacket sub; - - Vector v= new Vector(); - while ((sub = sIn.readPacket()) != null) - { - v.addElement(sub); - } - - subpackets = new UserAttributeSubpacket[v.size()]; - - for (int i = 0; i != subpackets.length; i++) - { - subpackets[i] = (UserAttributeSubpacket)v.elementAt(i); - } - } - - public UserAttributePacket( - UserAttributeSubpacket[] subpackets) - { - this.subpackets = subpackets; - } - - public UserAttributeSubpacket[] getSubpackets() - { - return subpackets; - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - - for (int i = 0; i != subpackets.length; i++) - { - subpackets[i].encode(bOut); - } - - out.writePacket(USER_ATTRIBUTE, bOut.toByteArray(), false); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacket.java b/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacket.java deleted file mode 100644 index f372399d..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacket.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; -import java.io.OutputStream; - -import org.bouncycastle.util.Arrays; - -/** - * Basic type for a user attribute sub-packet. - */ -public class UserAttributeSubpacket -{ - int type; - private boolean forceLongLength; // we preserve this as not everyone encodes length properly. - protected byte[] data; - - protected UserAttributeSubpacket( - int type, - byte[] data) - { - this(type, false, data); - } - - protected UserAttributeSubpacket( - int type, - boolean forceLongLength, - byte[] data) - { - this.type = type; - this.forceLongLength = forceLongLength; - this.data = data; - } - - public int getType() - { - return type; - } - - /** - * return the generic data making up the packet. - */ - public byte[] getData() - { - return data; - } - - public void encode( - OutputStream out) - throws IOException - { - int bodyLen = data.length + 1; - - if (bodyLen < 192 && !forceLongLength) - { - out.write((byte)bodyLen); - } - else if (bodyLen <= 8383 && !forceLongLength) - { - bodyLen -= 192; - - out.write((byte)(((bodyLen >> 8) & 0xff) + 192)); - out.write((byte)bodyLen); - } - else - { - out.write(0xff); - out.write((byte)(bodyLen >> 24)); - out.write((byte)(bodyLen >> 16)); - out.write((byte)(bodyLen >> 8)); - out.write((byte)bodyLen); - } - - out.write(type); - out.write(data); - } - - public boolean equals( - Object o) - { - if (o == this) - { - return true; - } - - if (!(o instanceof UserAttributeSubpacket)) - { - return false; - } - - UserAttributeSubpacket other = (UserAttributeSubpacket)o; - - return this.type == other.type - && Arrays.areEqual(this.data, other.data); - } - - public int hashCode() - { - return type ^ Arrays.hashCode(data); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketInputStream.java b/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketInputStream.java deleted file mode 100644 index 2b1ed0d1..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketInputStream.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; - -import org.bouncycastle.bcpg.attr.ImageAttribute; - -/** - * reader for user attribute sub-packets - */ -public class UserAttributeSubpacketInputStream - extends InputStream implements UserAttributeSubpacketTags -{ - InputStream in; - - public UserAttributeSubpacketInputStream( - InputStream in) - { - this.in = in; - } - - public int available() - throws IOException - { - return in.available(); - } - - public int read() - throws IOException - { - return in.read(); - } - - private void readFully( - byte[] buf, - int off, - int len) - throws IOException - { - if (len > 0) - { - int b = this.read(); - - if (b < 0) - { - throw new EOFException(); - } - - buf[off] = (byte)b; - off++; - len--; - } - - while (len > 0) - { - int l = in.read(buf, off, len); - - if (l < 0) - { - throw new EOFException(); - } - - off += l; - len -= l; - } - } - - public UserAttributeSubpacket readPacket() - throws IOException - { - int l = this.read(); - int bodyLen = 0; - boolean longLength = false; - - if (l < 0) - { - return null; - } - - if (l < 192) - { - bodyLen = l; - } - else if (l <= 223) - { - bodyLen = ((l - 192) << 8) + (in.read()) + 192; - } - else if (l == 255) - { - bodyLen = (in.read() << 24) | (in.read() << 16) | (in.read() << 8) | in.read(); - longLength = true; - } - else - { - throw new IOException("unrecognised length reading user attribute sub packet"); - } - - int tag = in.read(); - - if (tag < 0) - { - throw new EOFException("unexpected EOF reading user attribute sub packet"); - } - - byte[] data = new byte[bodyLen - 1]; - - this.readFully(data, 0, data.length); - - int type = tag; - - switch (type) - { - case IMAGE_ATTRIBUTE: - return new ImageAttribute(longLength, data); - } - - return new UserAttributeSubpacket(type, longLength, data); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketTags.java b/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketTags.java deleted file mode 100644 index f6675d86..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/UserAttributeSubpacketTags.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.bouncycastle.bcpg; - -/** - * Basic PGP user attribute sub-packet tag types. - */ -public interface UserAttributeSubpacketTags -{ - public static final int IMAGE_ATTRIBUTE = 1; -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/UserIDPacket.java b/pg/src/main/java/org/bouncycastle/bcpg/UserIDPacket.java deleted file mode 100644 index 7fd79186..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/UserIDPacket.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.bouncycastle.bcpg; - -import java.io.IOException; - -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.Strings; - -/** - * Basic type for a user ID packet. - */ -public class UserIDPacket - extends ContainedPacket -{ - private byte[] idData; - - public UserIDPacket( - BCPGInputStream in) - throws IOException - { - this.idData = in.readAll(); - } - - public UserIDPacket( - String id) - { - this.idData = Strings.toUTF8ByteArray(id); - } - - public UserIDPacket(byte[] rawID) - { - this.idData = Arrays.clone(rawID); - } - - public String getID() - { - return Strings.fromUTF8ByteArray(idData); - } - - public byte[] getRawID() - { - return Arrays.clone(idData); - } - - public boolean equals(Object o) - { - if (o instanceof UserIDPacket) - { - return Arrays.areEqual(this.idData, ((UserIDPacket)o).idData); - } - - return false; - } - - public int hashCode() - { - return Arrays.hashCode(this.idData); - } - - public void encode( - BCPGOutputStream out) - throws IOException - { - out.writePacket(USER_ID, idData, true); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/attr/ImageAttribute.java b/pg/src/main/java/org/bouncycastle/bcpg/attr/ImageAttribute.java deleted file mode 100644 index 467f5015..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/attr/ImageAttribute.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.bouncycastle.bcpg.attr; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -import org.bouncycastle.bcpg.UserAttributeSubpacket; -import org.bouncycastle.bcpg.UserAttributeSubpacketTags; - -/** - * Basic type for a image attribute packet. - */ -public class ImageAttribute - extends UserAttributeSubpacket -{ - public static final int JPEG = 1; - - private static final byte[] ZEROES = new byte[12]; - - private int hdrLength; - private int version; - private int encoding; - private byte[] imageData; - - public ImageAttribute( - byte[] data) - { - this(false, data); - } - - public ImageAttribute( - boolean forceLongLength, - byte[] data) - { - super(UserAttributeSubpacketTags.IMAGE_ATTRIBUTE, forceLongLength, data); - - hdrLength = ((data[1] & 0xff) << 8) | (data[0] & 0xff); - version = data[2] & 0xff; - encoding = data[3] & 0xff; - - imageData = new byte[data.length - hdrLength]; - System.arraycopy(data, hdrLength, imageData, 0, imageData.length); - } - - public ImageAttribute( - int imageType, - byte[] imageData) - { - this(toByteArray(imageType, imageData)); - } - - private static byte[] toByteArray(int imageType, byte[] imageData) - { - ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - - try - { - bOut.write(0x10); bOut.write(0x00); bOut.write(0x01); - bOut.write(imageType); - bOut.write(ZEROES); - bOut.write(imageData); - } - catch (IOException e) - { - throw new RuntimeException("unable to encode to byte array!"); - } - - return bOut.toByteArray(); - } - - public int version() - { - return version; - } - - public int getEncoding() - { - return encoding; - } - - public byte[] getImageData() - { - return imageData; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/EmbeddedSignature.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/EmbeddedSignature.java deleted file mode 100644 index 1288389f..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/EmbeddedSignature.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * Packet embedded signature - */ -public class EmbeddedSignature - extends SignatureSubpacket -{ - public EmbeddedSignature( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.EMBEDDED_SIGNATURE, critical, data); - } -}
\ No newline at end of file diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/Exportable.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/Exportable.java deleted file mode 100644 index 8adafba5..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/Exportable.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving signature creation time. - */ -public class Exportable - extends SignatureSubpacket -{ - private static byte[] booleanToByteArray( - boolean value) - { - byte[] data = new byte[1]; - - if (value) - { - data[0] = 1; - return data; - } - else - { - return data; - } - } - - public Exportable( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.EXPORTABLE, critical, data); - } - - public Exportable( - boolean critical, - boolean isExportable) - { - super(SignatureSubpacketTags.EXPORTABLE, critical, booleanToByteArray(isExportable)); - } - - public boolean isExportable() - { - return data[0] != 0; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/Features.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/Features.java deleted file mode 100644 index 1adf2643..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/Features.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -public class Features - extends SignatureSubpacket -{ - - /** Identifier for the modification detection feature */ - public static final byte FEATURE_MODIFICATION_DETECTION = 1; - - private static final byte[] featureToByteArray(byte feature) - { - byte[] data = new byte[1]; - data[0] = feature; - return data; - } - - public Features(boolean critical, byte[] data) - { - super(SignatureSubpacketTags.FEATURES, critical, data); - } - - public Features(boolean critical, byte feature) - { - super(SignatureSubpacketTags.FEATURES, critical, featureToByteArray(feature)); - } - - /** - * Returns if modification detection is supported. - */ - public boolean supportsModificationDetection() - { - return supportsFeature(FEATURE_MODIFICATION_DETECTION); - } - - -// /** Class should be immutable. -// * Set modification detection support. -// */ -// public void setSupportsModificationDetection(boolean support) -// { -// setSupportsFeature(FEATURE_MODIFICATION_DETECTION, support); -// } - - - /** - * Returns if a particular feature is supported. - */ - public boolean supportsFeature(byte feature) - { - for (int i = 0; i < data.length; i++) - { - if (data[i] == feature) - { - return true; - } - } - return false; - } - - - /** - * Sets support for a particular feature. - */ - private void setSupportsFeature(byte feature, boolean support) - { - if (feature == 0) - { - throw new IllegalArgumentException("feature == 0"); - } - if (supportsFeature(feature) != support) - { - if (support == true) - { - byte[] temp = new byte[data.length + 1]; - System.arraycopy(data, 0, temp, 0, data.length); - temp[data.length] = feature; - data = temp; - } - else - { - for (int i = 0; i < data.length; i++) - { - if (data[i] == feature) - { - byte[] temp = new byte[data.length - 1]; - System.arraycopy(data, 0, temp, 0, i); - System.arraycopy(data, i + 1, temp, i, temp.length - i); - data = temp; - break; - } - } - } - } - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/IssuerKeyID.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/IssuerKeyID.java deleted file mode 100644 index 2b908cd3..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/IssuerKeyID.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving signature creation time. - */ -public class IssuerKeyID - extends SignatureSubpacket -{ - protected static byte[] keyIDToBytes( - long keyId) - { - byte[] data = new byte[8]; - - data[0] = (byte)(keyId >> 56); - data[1] = (byte)(keyId >> 48); - data[2] = (byte)(keyId >> 40); - data[3] = (byte)(keyId >> 32); - data[4] = (byte)(keyId >> 24); - data[5] = (byte)(keyId >> 16); - data[6] = (byte)(keyId >> 8); - data[7] = (byte)keyId; - - return data; - } - - public IssuerKeyID( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.ISSUER_KEY_ID, critical, data); - } - - public IssuerKeyID( - boolean critical, - long keyID) - { - super(SignatureSubpacketTags.ISSUER_KEY_ID, critical, keyIDToBytes(keyID)); - } - - public long getKeyID() - { - long keyID = ((long)(data[0] & 0xff) << 56) | ((long)(data[1] & 0xff) << 48) | ((long)(data[2] & 0xff) << 40) | ((long)(data[3] & 0xff) << 32) - | ((long)(data[4] & 0xff) << 24) | ((data[5] & 0xff) << 16) | ((data[6] & 0xff) << 8) | (data[7] & 0xff); - - return keyID; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/KeyExpirationTime.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/KeyExpirationTime.java deleted file mode 100644 index 91b21b07..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/KeyExpirationTime.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving time after creation at which the key expires. - */ -public class KeyExpirationTime - extends SignatureSubpacket -{ - protected static byte[] timeToBytes( - long t) - { - byte[] data = new byte[4]; - - data[0] = (byte)(t >> 24); - data[1] = (byte)(t >> 16); - data[2] = (byte)(t >> 8); - data[3] = (byte)t; - - return data; - } - - public KeyExpirationTime( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.KEY_EXPIRE_TIME, critical, data); - } - - public KeyExpirationTime( - boolean critical, - long seconds) - { - super(SignatureSubpacketTags.KEY_EXPIRE_TIME, critical, timeToBytes(seconds)); - } - - /** - * Return the number of seconds after creation time a key is valid for. - * - * @return second count for key validity. - */ - public long getTime() - { - long time = ((long)(data[0] & 0xff) << 24) | ((data[1] & 0xff) << 16) | ((data[2] & 0xff) << 8) | (data[3] & 0xff); - - return time; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/KeyFlags.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/KeyFlags.java deleted file mode 100644 index 326f9282..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/KeyFlags.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * Packet holding the key flag values. - */ -public class KeyFlags - extends SignatureSubpacket -{ - public static final int CERTIFY_OTHER = 0x01; - public static final int SIGN_DATA = 0x02; - public static final int ENCRYPT_COMMS = 0x04; - public static final int ENCRYPT_STORAGE = 0x08; - public static final int SPLIT = 0x10; - public static final int AUTHENTICATION = 0x20; - public static final int SHARED = 0x80; - - private static byte[] intToByteArray( - int v) - { - byte[] tmp = new byte[4]; - int size = 0; - - for (int i = 0; i != 4; i++) - { - tmp[i] = (byte)(v >> (i * 8)); - if (tmp[i] != 0) - { - size = i; - } - } - - byte[] data = new byte[size + 1]; - - System.arraycopy(tmp, 0, data, 0, data.length); - - return data; - } - - public KeyFlags( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.KEY_FLAGS, critical, data); - } - - public KeyFlags( - boolean critical, - int flags) - { - super(SignatureSubpacketTags.KEY_FLAGS, critical, intToByteArray(flags)); - } - - /** - * Return the flag values contained in the first 4 octets (note: at the moment - * the standard only uses the first one). - * - * @return flag values. - */ - public int getFlags() - { - int flags = 0; - - for (int i = 0; i != data.length; i++) - { - flags |= (data[i] & 0xff) << (i * 8); - } - - return flags; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/NotationData.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/NotationData.java deleted file mode 100644 index 85172ee3..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/NotationData.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import java.io.ByteArrayOutputStream; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; -import org.bouncycastle.util.Strings; - -/** - * Class provided a NotationData object according to - * RFC2440, Chapter 5.2.3.15. Notation Data - */ -public class NotationData - extends SignatureSubpacket -{ - public static final int HEADER_FLAG_LENGTH = 4; - public static final int HEADER_NAME_LENGTH = 2; - public static final int HEADER_VALUE_LENGTH = 2; - - public NotationData(boolean critical, byte[] data) - { - super(SignatureSubpacketTags.NOTATION_DATA, critical, data); - } - - public NotationData( - boolean critical, - boolean humanReadable, - String notationName, - String notationValue) - { - super(SignatureSubpacketTags.NOTATION_DATA, critical, createData(humanReadable, notationName, notationValue)); - } - - private static byte[] createData(boolean humanReadable, String notationName, String notationValue) - { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - -// (4 octets of flags, 2 octets of name length (M), -// 2 octets of value length (N), -// M octets of name data, -// N octets of value data) - - // flags - out.write(humanReadable ? 0x80 : 0x00); - out.write(0x0); - out.write(0x0); - out.write(0x0); - - byte[] nameData, valueData = null; - int nameLength, valueLength; - - nameData = Strings.toUTF8ByteArray(notationName); - nameLength = Math.min(nameData.length, 0xFFFF); - - if (nameLength != nameData.length) - { - throw new IllegalArgumentException("notationName exceeds maximum length."); - } - - valueData = Strings.toUTF8ByteArray(notationValue); - valueLength = Math.min(valueData.length, 0xFFFF); - if (valueLength != valueData.length) - { - throw new IllegalArgumentException("notationValue exceeds maximum length."); - } - - // name length - out.write((nameLength >>> 8) & 0xFF); - out.write((nameLength >>> 0) & 0xFF); - - // value length - out.write((valueLength >>> 8) & 0xFF); - out.write((valueLength >>> 0) & 0xFF); - - // name - out.write(nameData, 0, nameLength); - - // value - out.write(valueData, 0, valueLength); - - return out.toByteArray(); - } - - public boolean isHumanReadable() - { - return data[0] == (byte)0x80; - } - - public String getNotationName() - { - int nameLength = (((data[HEADER_FLAG_LENGTH] & 0xff) << 8) + (data[HEADER_FLAG_LENGTH + 1] & 0xff)); - - byte bName[] = new byte[nameLength]; - System.arraycopy(data, HEADER_FLAG_LENGTH + HEADER_NAME_LENGTH + HEADER_VALUE_LENGTH, bName, 0, nameLength); - - return Strings.fromUTF8ByteArray(bName); - } - - public String getNotationValue() - { - return Strings.fromUTF8ByteArray(getNotationValueBytes()); - } - - public byte[] getNotationValueBytes() - { - int nameLength = (((data[HEADER_FLAG_LENGTH] & 0xff) << 8) + (data[HEADER_FLAG_LENGTH + 1] & 0xff)); - int valueLength = (((data[HEADER_FLAG_LENGTH + HEADER_NAME_LENGTH] & 0xff) << 8) + (data[HEADER_FLAG_LENGTH + HEADER_NAME_LENGTH + 1] & 0xff)); - - byte bValue[] = new byte[valueLength]; - System.arraycopy(data, HEADER_FLAG_LENGTH + HEADER_NAME_LENGTH + HEADER_VALUE_LENGTH + nameLength, bValue, 0, valueLength); - return bValue; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/PreferredAlgorithms.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/PreferredAlgorithms.java deleted file mode 100644 index ca83b056..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/PreferredAlgorithms.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; - -/** - * packet giving signature creation time. - */ -public class PreferredAlgorithms - extends SignatureSubpacket -{ - private static byte[] intToByteArray( - int[] v) - { - byte[] data = new byte[v.length]; - - for (int i = 0; i != v.length; i++) - { - data[i] = (byte)v[i]; - } - - return data; - } - - public PreferredAlgorithms( - int type, - boolean critical, - byte[] data) - { - super(type, critical, data); - } - - public PreferredAlgorithms( - int type, - boolean critical, - int[] preferrences) - { - super(type, critical, intToByteArray(preferrences)); - } - - /** - * @deprecated mispelt! - */ - public int[] getPreferrences() - { - return getPreferences(); - } - - public int[] getPreferences() - { - int[] v = new int[data.length]; - - for (int i = 0; i != v.length; i++) - { - v[i] = data[i] & 0xff; - } - - return v; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/PrimaryUserID.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/PrimaryUserID.java deleted file mode 100644 index 2e0d7fd3..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/PrimaryUserID.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving whether or not the signature is signed using the primary user ID for the key. - */ -public class PrimaryUserID - extends SignatureSubpacket -{ - private static byte[] booleanToByteArray( - boolean value) - { - byte[] data = new byte[1]; - - if (value) - { - data[0] = 1; - return data; - } - else - { - return data; - } - } - - public PrimaryUserID( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.PRIMARY_USER_ID, critical, data); - } - - public PrimaryUserID( - boolean critical, - boolean isPrimaryUserID) - { - super(SignatureSubpacketTags.PRIMARY_USER_ID, critical, booleanToByteArray(isPrimaryUserID)); - } - - public boolean isPrimaryUserID() - { - return data[0] != 0; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/Revocable.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/Revocable.java deleted file mode 100644 index 9807ca89..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/Revocable.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving whether or not is revocable. - */ -public class Revocable - extends SignatureSubpacket -{ - private static byte[] booleanToByteArray( - boolean value) - { - byte[] data = new byte[1]; - - if (value) - { - data[0] = 1; - return data; - } - else - { - return data; - } - } - - public Revocable( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.REVOCABLE, critical, data); - } - - public Revocable( - boolean critical, - boolean isRevocable) - { - super(SignatureSubpacketTags.REVOCABLE, critical, booleanToByteArray(isRevocable)); - } - - public boolean isRevocable() - { - return data[0] != 0; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationKey.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationKey.java deleted file mode 100644 index b46eab56..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationKey.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * Represents revocation key OpenPGP signature sub packet. - */ -public class RevocationKey extends SignatureSubpacket -{ - // 1 octet of class, - // 1 octet of public-key algorithm ID, - // 20 octets of fingerprint - public RevocationKey(boolean isCritical, byte[] data) - { - super(SignatureSubpacketTags.REVOCATION_KEY, isCritical, data); - } - - public RevocationKey(boolean isCritical, byte signatureClass, int keyAlgorithm, - byte[] fingerprint) - { - super(SignatureSubpacketTags.REVOCATION_KEY, isCritical, createData(signatureClass, - (byte)(keyAlgorithm & 0xff), fingerprint)); - } - - private static byte[] createData(byte signatureClass, byte keyAlgorithm, byte[] fingerprint) - { - byte[] data = new byte[2 + fingerprint.length]; - data[0] = signatureClass; - data[1] = keyAlgorithm; - System.arraycopy(fingerprint, 0, data, 2, fingerprint.length); - return data; - } - - public byte getSignatureClass() - { - return this.getData()[0]; - } - - public int getAlgorithm() - { - return this.getData()[1]; - } - - public byte[] getFingerprint() - { - byte[] data = this.getData(); - byte[] fingerprint = new byte[data.length - 2]; - System.arraycopy(data, 2, fingerprint, 0, fingerprint.length); - return fingerprint; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationKeyTags.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationKeyTags.java deleted file mode 100644 index aee90c1e..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationKeyTags.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -public interface RevocationKeyTags -{ - public static final byte CLASS_DEFAULT = (byte)0x80; - public static final byte CLASS_SENSITIVE = (byte)0x40; - -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationReason.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationReason.java deleted file mode 100644 index e3b50fec..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationReason.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; -import org.bouncycastle.util.Strings; - -/** - * Represents revocation reason OpenPGP signature sub packet. - */ -public class RevocationReason extends SignatureSubpacket -{ - public RevocationReason(boolean isCritical, byte[] data) - { - super(SignatureSubpacketTags.REVOCATION_REASON, isCritical, data); - } - - public RevocationReason(boolean isCritical, byte reason, String description) - { - super(SignatureSubpacketTags.REVOCATION_REASON, isCritical, createData(reason, description)); - } - - private static byte[] createData(byte reason, String description) - { - byte[] descriptionBytes = Strings.toUTF8ByteArray(description); - byte[] data = new byte[1 + descriptionBytes.length]; - - data[0] = reason; - System.arraycopy(descriptionBytes, 0, data, 1, descriptionBytes.length); - - return data; - } - - public byte getRevocationReason() - { - return getData()[0]; - } - - public String getRevocationDescription() - { - byte[] data = getData(); - if (data.length == 1) - { - return ""; - } - - byte[] description = new byte[data.length - 1]; - System.arraycopy(data, 1, description, 0, description.length); - - return Strings.fromUTF8ByteArray(description); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationReasonTags.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationReasonTags.java deleted file mode 100644 index 576b1818..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/RevocationReasonTags.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -public interface RevocationReasonTags -{ - public static final byte NO_REASON = 0; // No reason specified (key revocations or cert revocations) - public static final byte KEY_SUPERSEDED = 1; // Key is superseded (key revocations) - public static final byte KEY_COMPROMISED = 2; // Key material has been compromised (key revocations) - public static final byte KEY_RETIRED = 3; // Key is retired and no longer used (key revocations) - public static final byte USER_NO_LONGER_VALID = 32; // User ID information is no longer valid (cert revocations) - - // 100-110 - Private Use -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/SignatureCreationTime.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/SignatureCreationTime.java deleted file mode 100644 index 51705013..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/SignatureCreationTime.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import java.util.Date; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving signature creation time. - */ -public class SignatureCreationTime - extends SignatureSubpacket -{ - protected static byte[] timeToBytes( - Date date) - { - byte[] data = new byte[4]; - long t = date.getTime() / 1000; - - data[0] = (byte)(t >> 24); - data[1] = (byte)(t >> 16); - data[2] = (byte)(t >> 8); - data[3] = (byte)t; - - return data; - } - - public SignatureCreationTime( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.CREATION_TIME, critical, data); - } - - public SignatureCreationTime( - boolean critical, - Date date) - { - super(SignatureSubpacketTags.CREATION_TIME, critical, timeToBytes(date)); - } - - public Date getTime() - { - long time = ((long)(data[0] & 0xff) << 24) | ((data[1] & 0xff) << 16) | ((data[2] & 0xff) << 8) | (data[3] & 0xff); - - return new Date(time * 1000); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/SignatureExpirationTime.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/SignatureExpirationTime.java deleted file mode 100644 index 6aa949c5..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/SignatureExpirationTime.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving signature expiration time. - */ -public class SignatureExpirationTime - extends SignatureSubpacket -{ - protected static byte[] timeToBytes( - long t) - { - byte[] data = new byte[4]; - - data[0] = (byte)(t >> 24); - data[1] = (byte)(t >> 16); - data[2] = (byte)(t >> 8); - data[3] = (byte)t; - - return data; - } - - public SignatureExpirationTime( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.EXPIRE_TIME, critical, data); - } - - public SignatureExpirationTime( - boolean critical, - long seconds) - { - super(SignatureSubpacketTags.EXPIRE_TIME, critical, timeToBytes(seconds)); - } - - /** - * return time in seconds before signature expires after creation time. - */ - public long getTime() - { - long time = ((long)(data[0] & 0xff) << 24) | ((data[1] & 0xff) << 16) | ((data[2] & 0xff) << 8) | (data[3] & 0xff); - - return time; - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/SignerUserID.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/SignerUserID.java deleted file mode 100644 index 589208d2..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/SignerUserID.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; -import org.bouncycastle.util.Arrays; -import org.bouncycastle.util.Strings; - -/** - * packet giving the User ID of the signer. - */ -public class SignerUserID - extends SignatureSubpacket -{ - public SignerUserID( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.SIGNER_USER_ID, critical, data); - } - - public SignerUserID( - boolean critical, - String userID) - { - super(SignatureSubpacketTags.SIGNER_USER_ID, critical, Strings.toUTF8ByteArray(userID)); - } - - public String getID() - { - return Strings.fromUTF8ByteArray(data); - } - - public byte[] getRawID() - { - return Arrays.clone(data); - } -} diff --git a/pg/src/main/java/org/bouncycastle/bcpg/sig/TrustSignature.java b/pg/src/main/java/org/bouncycastle/bcpg/sig/TrustSignature.java deleted file mode 100644 index a3239003..00000000 --- a/pg/src/main/java/org/bouncycastle/bcpg/sig/TrustSignature.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.bouncycastle.bcpg.sig; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; - -/** - * packet giving trust. - */ -public class TrustSignature - extends SignatureSubpacket -{ - private static byte[] intToByteArray( - int v1, - int v2) - { - byte[] data = new byte[2]; - - data[0] = (byte)v1; - data[1] = (byte)v2; - - return data; - } - - public TrustSignature( - boolean critical, - byte[] data) - { - super(SignatureSubpacketTags.TRUST_SIG, critical, data); - } - - public TrustSignature( - boolean critical, - int depth, - int trustAmount) - { - super(SignatureSubpacketTags.TRUST_SIG, critical, intToByteArray(depth, trustAmount)); - } - - public int getDepth() - { - return data[0] & 0xff; - } - - public int getTrustAmount() - { - return data[1] & 0xff; - } -} |