提交Unity 联机Pro

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-17 14:27:18 +08:00
parent f00193b000
commit 894100ae37
7448 changed files with 854473 additions and 0 deletions

View File

@@ -0,0 +1,531 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
* 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
* is detected and fails.
* <p>
* By default a missing CRC will not cause an exception. To force CRC detection use:
* <pre>
* ArmoredInputStream aIn = ...
*
* aIn.setDetectMissingCRC(true);
* </pre>
* </p>
*/
public class ArmoredInputStream
: BaseInputStream
{
/*
* set up the decoding table.
*/
private readonly static byte[] decodingTable;
static ArmoredInputStream()
{
decodingTable = new byte[128];
Arrays.Fill(decodingTable, 0xff);
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 static int Decode(int in0, int in1, int in2, int in3, int[] result)
{
if (in3 < 0)
throw new EndOfStreamException("unexpected end of file in armored stream.");
int b1, b2, b3, b4;
if (in2 == '=')
{
b1 = decodingTable[in0];
b2 = decodingTable[in1];
if ((b1 | b2) >= 128)
throw new IOException("invalid armor");
result[2] = ((b1 << 2) | (b2 >> 4)) & 0xff;
return 2;
}
else if (in3 == '=')
{
b1 = decodingTable[in0];
b2 = decodingTable[in1];
b3 = decodingTable[in2];
if ((b1 | b2 | b3) >= 128)
throw new IOException("invalid armor");
result[1] = ((b1 << 2) | (b2 >> 4)) & 0xff;
result[2] = ((b2 << 4) | (b3 >> 2)) & 0xff;
return 1;
}
else
{
b1 = decodingTable[in0];
b2 = decodingTable[in1];
b3 = decodingTable[in2];
b4 = decodingTable[in3];
if ((b1 | b2 | b3 | b4) >= 128)
throw new IOException("invalid armor");
result[0] = ((b1 << 2) | (b2 >> 4)) & 0xff;
result[1] = ((b2 << 4) | (b3 >> 2)) & 0xff;
result[2] = ((b3 << 6) | b4) & 0xff;
return 0;
}
}
/*
* Ignore missing CRC checksums.
* https://tests.sequoia-pgp.org/#ASCII_Armor suggests that missing CRC sums do not invalidate the message.
*/
private bool detectMissingChecksum = false;
Stream input;
bool start = true;
int[] outBuf = new int[3];
int bufPtr = 3;
Crc24 crc = new Crc24();
bool crcFound = false;
bool hasHeaders = true;
string header = null;
bool newLineFound = false;
bool clearText = false;
bool restart = false;
IList<string> headerList = new List<string>();
int lastC = 0;
bool isEndOfStream;
/**
* Create a stream for reading a PGP armoured message, parsing up to a header
* and then reading the data that follows.
*
* @param input
*/
public ArmoredInputStream(Stream input)
: this(input, 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 input
* @param hasHeaders true if headers are to be looked for, false otherwise.
*/
public ArmoredInputStream(Stream input, bool hasHeaders)
{
this.input = input;
this.hasHeaders = hasHeaders;
if (hasHeaders)
{
ParseHeaders();
}
start = false;
}
private bool ParseHeaders()
{
header = null;
int c;
int last = 0;
bool headerFound = false;
headerList = new List<string>();
//
// if restart we already have a header
//
if (restart)
{
headerFound = true;
}
else
{
while ((c = input.ReadByte()) >= 0)
{
if (c == '-' && (last == 0 || last == '\n' || last == '\r'))
{
headerFound = true;
break;
}
last = c;
}
}
if (headerFound)
{
StringBuilder buf = new StringBuilder("-");
bool eolReached = false;
bool crLf = false;
if (restart) // we've had to look ahead two '-'
{
buf.Append('-');
}
while ((c = input.ReadByte()) >= 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 < 1)
break;
if (headerList.Count > 0 && line.IndexOf(':') < 0)
throw new IOException("invalid armor header");
headerList.Add(line);
buf.Length = 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)
{
input.ReadByte(); // skip last \n
}
}
if (headerList.Count > 0)
{
header = (string)headerList[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 bool IsClearText()
{
return clearText;
}
/**
* @return true if the stream is actually at end of file.
*/
public bool 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.Count <= 1)
return null;
string[] hdrs = new string[headerList.Count - 1];
for (int i = 0; i != hdrs.Length; i++)
{
hdrs[i] = (string)headerList[i + 1];
}
return hdrs;
}
private int ReadIgnoreSpace()
{
int c;
do
{
c = input.ReadByte();
}
while (c == ' ' || c == '\t' || c == '\f' || c == '\u000B') ; // \u000B ~ \v
if (c >= 128)
throw new IOException("invalid armor");
return c;
}
public override int Read(byte[] buffer, int offset, int count)
{
Streams.ValidateBufferArguments(buffer, offset, count);
/*
* TODO Currently can't return partial data when exception thrown (breaking test case), so we don't inherit
* the base class implementation. Probably the reason is that throws don't mark this instance as 'failed'.
*/
int pos = 0;
while (pos < count)
{
int b = ReadByte();
if (b < 0)
break;
buffer[offset + pos++] = (byte)b;
}
return pos;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override int Read(Span<byte> buffer)
{
/*
* TODO Currently can't return partial data when exception thrown (breaking test case), so we don't inherit
* the base class implementation. Probably the reason is that throws don't mark this instance as 'failed'.
*/
int pos = 0;
while (pos < buffer.Length)
{
int b = ReadByte();
if (b < 0)
break;
buffer[pos++] = (byte)b;
}
return pos;
}
#endif
public override int ReadByte()
{
if (start)
{
if (hasHeaders)
{
ParseHeaders();
}
crc.Reset();
start = false;
}
int c;
if (clearText)
{
c = input.ReadByte();
if (c == '\r' || (c == '\n' && lastC != '\r'))
{
newLineFound = true;
}
else if (newLineFound && c == '-')
{
c = input.ReadByte();
if (c == '-') // a header, not dash escaped
{
clearText = false;
start = true;
restart = true;
}
else // a space - must be a dash escape
{
c = input.ReadByte();
}
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.Value)
{
throw new IOException("crc check failed in armored message.");
}
return ReadByte();
}
else
{
if (detectMissingChecksum)
{
throw new IOException("no crc found in armored message");
}
}
}
else if (c == '-') // end of record reached
{
while ((c = input.ReadByte()) >= 0)
{
if (c == '\n' || c == '\r')
{
break;
}
}
if (!crcFound && detectMissingChecksum)
{
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;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
input.Dispose();
}
base.Dispose(disposing);
}
/**
* Change how the stream should react if it encounters missing CRC checksum.
* The default value is false (ignore missing CRC checksums). If the behavior is set to true,
* an {@link IOException} will be thrown if a missing CRC checksum is encountered.
*
* @param detectMissing ignore missing CRC sums
*/
public virtual void SetDetectMissingCrc(bool detectMissing)
{
this.detectMissingChecksum = detectMissing;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9a86cdd2cf17a348946f31bff2c0261
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,402 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
* Basic output stream.
*/
public class ArmoredOutputStream
: BaseOutputStream
{
public static readonly string HeaderVersion = "Version";
private static readonly 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 static void Encode(
Stream outStream,
int[] data,
int len)
{
Debug.Assert(len > 0);
Debug.Assert(len < 4);
byte[] bs = new byte[4];
int d1 = data[0];
bs[0] = encodingTable[(d1 >> 2) & 0x3f];
switch (len)
{
case 1:
{
bs[1] = encodingTable[(d1 << 4) & 0x3f];
bs[2] = (byte)'=';
bs[3] = (byte)'=';
break;
}
case 2:
{
int d2 = data[1];
bs[1] = encodingTable[((d1 << 4) | (d2 >> 4)) & 0x3f];
bs[2] = encodingTable[(d2 << 2) & 0x3f];
bs[3] = (byte)'=';
break;
}
case 3:
{
int d2 = data[1];
int d3 = data[2];
bs[1] = encodingTable[((d1 << 4) | (d2 >> 4)) & 0x3f];
bs[2] = encodingTable[((d2 << 2) | (d3 >> 6)) & 0x3f];
bs[3] = encodingTable[d3 & 0x3f];
break;
}
}
outStream.Write(bs, 0, bs.Length);
}
private readonly Stream outStream;
private int[] buf = new int[3];
private int bufPtr = 0;
private Crc24 crc = new Crc24();
private int chunkCount = 0;
private int lastb;
private bool start = true;
private bool clearText = false;
private bool newLine = false;
private string type;
private static readonly string NewLine = Environment.NewLine;
private static readonly string headerStart = "-----BEGIN PGP ";
private static readonly string headerTail = "-----";
private static readonly string footerStart = "-----END PGP ";
private static readonly string footerTail = "-----";
private static string CreateVersion()
{
var assembly = Assembly.GetExecutingAssembly();
var title = assembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;
var version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
return title + " v" + version;
}
private static readonly string Version = CreateVersion();
private readonly IDictionary<string, IList<string>> m_headers;
public ArmoredOutputStream(Stream outStream)
{
this.outStream = outStream;
this.m_headers = new Dictionary<string, IList<string>>(1);
SetHeader(HeaderVersion, Version);
}
public ArmoredOutputStream(Stream outStream, IDictionary<string, string> headers)
: this(outStream)
{
foreach (var header in headers)
{
var headerList = new List<string>(1);
headerList.Add(header.Value);
m_headers[header.Key] = headerList;
}
}
/**
* Set an additional header entry. Any current value(s) under the same name will be
* replaced by the new one. A null value will clear the entry for name. *
* @param name the name of the header entry.
* @param v the value of the header entry.
*/
public void SetHeader(string name, string val)
{
if (val == null)
{
this.m_headers.Remove(name);
return;
}
if (m_headers.TryGetValue(name, out var valueList))
{
valueList.Clear();
}
else
{
valueList = new List<string>(1);
m_headers[name] = valueList;
}
valueList.Add(val);
}
/**
* Set an additional header entry. The current value(s) will continue to exist together
* with the new one. Adding a null value has no effect.
*
* @param name the name of the header entry.
* @param value the value of the header entry.
*/
public void AddHeader(string name, string val)
{
if (val == null || name == null)
return;
if (!m_headers.TryGetValue(name, out var valueList))
{
valueList = new List<string>(1);
m_headers[name] = valueList;
}
valueList.Add(val);
}
/**
* Reset the headers to only contain a Version string (if one is present).
*/
public void ResetHeaders()
{
var versions = CollectionUtilities.GetValueOrNull(m_headers, HeaderVersion);
m_headers.Clear();
if (versions != null)
{
m_headers[HeaderVersion] = versions;
}
}
/**
* Start a clear text signed message.
* @param hashAlgorithm
*/
public void BeginClearText(
HashAlgorithmTag hashAlgorithm)
{
string hash;
switch (hashAlgorithm)
{
case HashAlgorithmTag.Sha1:
hash = "SHA1";
break;
case HashAlgorithmTag.Sha256:
hash = "SHA256";
break;
case HashAlgorithmTag.Sha384:
hash = "SHA384";
break;
case HashAlgorithmTag.Sha512:
hash = "SHA512";
break;
case HashAlgorithmTag.MD2:
hash = "MD2";
break;
case HashAlgorithmTag.MD5:
hash = "MD5";
break;
case HashAlgorithmTag.RipeMD160:
hash = "RIPEMD160";
break;
default:
throw new IOException("unknown hash algorithm tag in beginClearText: " + hashAlgorithm);
}
DoWrite("-----BEGIN PGP SIGNED MESSAGE-----" + NewLine);
DoWrite("Hash: " + hash + NewLine + NewLine);
clearText = true;
newLine = true;
lastb = 0;
}
public void EndClearText()
{
clearText = false;
}
public override void WriteByte(byte value)
{
if (clearText)
{
outStream.WriteByte(value);
if (newLine)
{
if (!(value == '\n' && lastb == '\r'))
{
newLine = false;
}
if (value == '-')
{
outStream.WriteByte((byte)' ');
outStream.WriteByte((byte)'-'); // dash escape
}
}
if (value == '\r' || (value == '\n' && lastb != '\r'))
{
newLine = true;
}
lastb = value;
return;
}
if (start)
{
bool newPacket = (value & 0x40) != 0;
int tag;
if (newPacket)
{
tag = value & 0x3f;
}
else
{
tag = (value & 0x3f) >> 2;
}
switch ((PacketTag)tag)
{
case PacketTag.PublicKey:
type = "PUBLIC KEY BLOCK";
break;
case PacketTag.SecretKey:
type = "PRIVATE KEY BLOCK";
break;
case PacketTag.Signature:
type = "SIGNATURE";
break;
default:
type = "MESSAGE";
break;
}
DoWrite(headerStart + type + headerTail + NewLine);
if (m_headers.TryGetValue(HeaderVersion, out var versionHeaders))
{
WriteHeaderEntry(HeaderVersion, versionHeaders[0]);
}
foreach (var de in m_headers)
{
string k = de.Key;
if (k != HeaderVersion)
{
foreach (string v in de.Value)
{
WriteHeaderEntry(k, v);
}
}
}
DoWrite(NewLine);
start = false;
}
if (bufPtr == 3)
{
Encode(outStream, buf, bufPtr);
bufPtr = 0;
if ((++chunkCount & 0xf) == 0)
{
DoWrite(NewLine);
}
}
crc.Update(value);
buf[bufPtr++] = value & 0xff;
}
/**
* <b>Note</b>: Close() does not close the underlying stream. So it is possible to write
* multiple objects using armoring to a single stream.
*/
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (type != null)
{
DoClose();
type = null;
start = true;
}
}
base.Dispose(disposing);
}
private void DoClose()
{
if (bufPtr > 0)
{
Encode(outStream, buf, bufPtr);
}
DoWrite(NewLine + '=');
int crcV = crc.Value;
buf[0] = ((crcV >> 16) & 0xff);
buf[1] = ((crcV >> 8) & 0xff);
buf[2] = (crcV & 0xff);
Encode(outStream, buf, 3);
DoWrite(NewLine);
DoWrite(footerStart);
DoWrite(type);
DoWrite(footerTail);
DoWrite(NewLine);
outStream.Flush();
}
private void WriteHeaderEntry(
string name,
string v)
{
DoWrite(name + ": " + v + NewLine);
}
private void DoWrite(
string s)
{
byte[] bs = Strings.ToAsciiByteArray(s);
outStream.Write(bs, 0, bs.Length);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4f724f224c782c144bac2aa47960a0b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,402 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Reader for PGP objects.</remarks>
public class BcpgInputStream
: BaseInputStream
{
private Stream m_in;
private bool next = false;
private int nextB;
internal static BcpgInputStream Wrap(
Stream inStr)
{
if (inStr is BcpgInputStream)
{
return (BcpgInputStream) inStr;
}
return new BcpgInputStream(inStr);
}
private BcpgInputStream(
Stream inputStream)
{
this.m_in = inputStream;
}
public override int ReadByte()
{
if (next)
{
next = false;
return nextB;
}
return m_in.ReadByte();
}
public override int Read(byte[] buffer, int offset, int count)
{
if (!next)
return m_in.Read(buffer, offset, count);
Streams.ValidateBufferArguments(buffer, offset, count);
if (nextB < 0)
return 0;
buffer[offset] = (byte)nextB;
next = false;
return 1;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override int Read(Span<byte> buffer)
{
if (!next)
return m_in.Read(buffer);
if (nextB < 0)
return 0;
buffer[0] = (byte)nextB;
next = false;
return 1;
}
#endif
public byte[] ReadAll()
{
return Streams.ReadAll(this);
}
public void ReadFully(byte[] buffer, int offset, int count)
{
if (Streams.ReadFully(this, buffer, offset, count) < count)
throw new EndOfStreamException();
}
public void ReadFully(byte[] buffer)
{
ReadFully(buffer, 0, buffer.Length);
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public void ReadFully(Span<byte> buffer)
{
if (Streams.ReadFully(this, buffer) < buffer.Length)
throw new EndOfStreamException();
}
#endif
/// <summary>Returns the next packet tag in the stream.</summary>
public PacketTag NextPacketTag()
{
if (!next)
{
try
{
nextB = m_in.ReadByte();
}
catch (EndOfStreamException)
{
nextB = -1;
}
next = true;
}
if (nextB < 0)
return (PacketTag)nextB;
int maskB = nextB & 0x3f;
if ((nextB & 0x40) == 0) // old
{
maskB >>= 2;
}
return (PacketTag)maskB;
}
public Packet ReadPacket()
{
int hdr = this.ReadByte();
if (hdr < 0)
{
return null;
}
if ((hdr & 0x80) == 0)
{
throw new IOException("invalid header encountered");
}
bool newPacket = (hdr & 0x40) != 0;
PacketTag tag = 0;
int bodyLen = 0;
bool partial = false;
if (newPacket)
{
tag = (PacketTag)(hdr & 0x3f);
int l = this.ReadByte();
if (l < 192)
{
bodyLen = l;
}
else if (l <= 223)
{
int b = m_in.ReadByte();
bodyLen = ((l - 192) << 8) + (b) + 192;
}
else if (l == 255)
{
bodyLen = (m_in.ReadByte() << 24) | (m_in.ReadByte() << 16)
| (m_in.ReadByte() << 8) | m_in.ReadByte();
}
else
{
partial = true;
bodyLen = 1 << (l & 0x1f);
}
}
else
{
int lengthType = hdr & 0x3;
tag = (PacketTag)((hdr & 0x3f) >> 2);
switch (lengthType)
{
case 0:
bodyLen = this.ReadByte();
break;
case 1:
bodyLen = (this.ReadByte() << 8) | this.ReadByte();
break;
case 2:
bodyLen = (this.ReadByte() << 24) | (this.ReadByte() << 16)
| (this.ReadByte() << 8) | this.ReadByte();
break;
case 3:
partial = true;
break;
default:
throw new IOException("unknown length type encountered");
}
}
BcpgInputStream objStream;
if (bodyLen == 0 && partial)
{
objStream = this;
}
else
{
PartialInputStream pis = new PartialInputStream(this, partial, bodyLen);
Stream buf = new BufferedStream(pis);
objStream = new BcpgInputStream(buf);
}
switch (tag)
{
case PacketTag.Reserved:
return new InputStreamPacket(objStream);
case PacketTag.PublicKeyEncryptedSession:
return new PublicKeyEncSessionPacket(objStream);
case PacketTag.Signature:
return new SignaturePacket(objStream);
case PacketTag.SymmetricKeyEncryptedSessionKey:
return new SymmetricKeyEncSessionPacket(objStream);
case PacketTag.OnePassSignature:
return new OnePassSignaturePacket(objStream);
case PacketTag.SecretKey:
return new SecretKeyPacket(objStream);
case PacketTag.PublicKey:
return new PublicKeyPacket(objStream);
case PacketTag.SecretSubkey:
return new SecretSubkeyPacket(objStream);
case PacketTag.CompressedData:
return new CompressedDataPacket(objStream);
case PacketTag.SymmetricKeyEncrypted:
return new SymmetricEncDataPacket(objStream);
case PacketTag.Marker:
return new MarkerPacket(objStream);
case PacketTag.LiteralData:
return new LiteralDataPacket(objStream);
case PacketTag.Trust:
return new TrustPacket(objStream);
case PacketTag.UserId:
return new UserIdPacket(objStream);
case PacketTag.UserAttribute:
return new UserAttributePacket(objStream);
case PacketTag.PublicSubkey:
return new PublicSubkeyPacket(objStream);
case PacketTag.SymmetricEncryptedIntegrityProtected:
return new SymmetricEncIntegrityPacket(objStream);
case PacketTag.ModificationDetectionCode:
return new ModDetectionCodePacket(objStream);
case PacketTag.Experimental1:
case PacketTag.Experimental2:
case PacketTag.Experimental3:
case PacketTag.Experimental4:
return new ExperimentalPacket(tag, objStream);
default:
throw new IOException("unknown packet type encountered: " + tag);
}
}
public PacketTag SkipMarkerPackets()
{
PacketTag tag;
while ((tag = NextPacketTag()) == PacketTag.Marker)
{
ReadPacket();
}
return tag;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
m_in.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// 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.
/// </summary>
private class PartialInputStream
: BaseInputStream
{
private BcpgInputStream m_in;
private bool partial;
private int dataLength;
internal PartialInputStream(
BcpgInputStream bcpgIn,
bool partial,
int dataLength)
{
this.m_in = bcpgIn;
this.partial = partial;
this.dataLength = dataLength;
}
public override int ReadByte()
{
do
{
if (dataLength != 0)
{
int ch = m_in.ReadByte();
if (ch < 0)
{
throw new EndOfStreamException("Premature end of stream in PartialInputStream");
}
dataLength--;
return ch;
}
}
while (partial && ReadPartialDataLength() >= 0);
return -1;
}
public override int Read(byte[] buffer, int offset, int count)
{
Streams.ValidateBufferArguments(buffer, offset, count);
do
{
if (dataLength != 0)
{
int readLen = (dataLength > count || dataLength < 0) ? count : dataLength;
int len = m_in.Read(buffer, offset, readLen);
if (len < 1)
throw new EndOfStreamException("Premature end of stream in PartialInputStream");
dataLength -= len;
return len;
}
}
while (partial && ReadPartialDataLength() >= 0);
return 0;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override int Read(Span<byte> buffer)
{
do
{
if (dataLength != 0)
{
int count = buffer.Length;
int readLen = (dataLength > count || dataLength < 0) ? count : dataLength;
int len = m_in.Read(buffer[..readLen]);
if (len < 1)
throw new EndOfStreamException("Premature end of stream in PartialInputStream");
dataLength -= len;
return len;
}
}
while (partial && ReadPartialDataLength() >= 0);
return 0;
}
#endif
private int ReadPartialDataLength()
{
int l = m_in.ReadByte();
if (l < 0)
{
return -1;
}
partial = false;
if (l < 192)
{
dataLength = l;
}
else if (l <= 223)
{
dataLength = ((l - 192) << 8) + (m_in.ReadByte()) + 192;
}
else if (l == 255)
{
dataLength = (m_in.ReadByte() << 24) | (m_in.ReadByte() << 16)
| (m_in.ReadByte() << 8) | m_in.ReadByte();
}
else
{
partial = true;
dataLength = 1 << (l & 0x1f);
}
return 0;
}
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 32f4aaeece81f6542afa03ada1c51bd4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for a PGP object.</remarks>
public abstract class BcpgObject
{
public virtual byte[] GetEncoded()
{
MemoryStream bOut = new MemoryStream();
BcpgOutputStream pOut = new BcpgOutputStream(bOut);
pOut.WriteObject(this);
return bOut.ToArray();
}
public abstract void Encode(BcpgOutputStream bcpgOut);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d642bd44be501634e945c40857b99e34
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,446 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic output stream.</remarks>
public class BcpgOutputStream
: BaseOutputStream
{
internal static BcpgOutputStream Wrap(
Stream outStr)
{
if (outStr is BcpgOutputStream)
{
return (BcpgOutputStream) outStr;
}
return new BcpgOutputStream(outStr);
}
private Stream outStr;
private byte[] partialBuffer;
private int partialBufferLength;
private int partialPower;
private int partialOffset;
private const int BufferSizePower = 16; // 2^16 size buffer on long files
/// <summary>Create a stream representing a general packet.</summary>
/// <param name="outStr">Output stream to write to.</param>
public BcpgOutputStream(
Stream outStr)
{
if (outStr == null)
throw new ArgumentNullException("outStr");
this.outStr = outStr;
}
/// <summary>Create a stream representing an old style partial object.</summary>
/// <param name="outStr">Output stream to write to.</param>
/// <param name="tag">The packet tag for the object.</param>
public BcpgOutputStream(
Stream outStr,
PacketTag tag)
{
if (outStr == null)
throw new ArgumentNullException("outStr");
this.outStr = outStr;
this.WriteHeader(tag, true, true, 0);
}
/// <summary>Create a stream representing a general packet.</summary>
/// <param name="outStr">Output stream to write to.</param>
/// <param name="tag">Packet tag.</param>
/// <param name="length">Size of chunks making up the packet.</param>
/// <param name="oldFormat">If true, the header is written out in old format.</param>
public BcpgOutputStream(
Stream outStr,
PacketTag tag,
long length,
bool oldFormat)
{
if (outStr == null)
throw new ArgumentNullException("outStr");
this.outStr = outStr;
if (length > 0xFFFFFFFFL)
{
this.WriteHeader(tag, false, true, 0);
this.partialBufferLength = 1 << BufferSizePower;
this.partialBuffer = new byte[partialBufferLength];
this.partialPower = BufferSizePower;
this.partialOffset = 0;
}
else
{
this.WriteHeader(tag, oldFormat, false, length);
}
}
/// <summary>Create a new style partial input stream buffered into chunks.</summary>
/// <param name="outStr">Output stream to write to.</param>
/// <param name="tag">Packet tag.</param>
/// <param name="length">Size of chunks making up the packet.</param>
public BcpgOutputStream(
Stream outStr,
PacketTag tag,
long length)
{
if (outStr == null)
throw new ArgumentNullException("outStr");
this.outStr = outStr;
this.WriteHeader(tag, false, false, length);
}
/// <summary>Create a new style partial input stream buffered into chunks.</summary>
/// <param name="outStr">Output stream to write to.</param>
/// <param name="tag">Packet tag.</param>
/// <param name="buffer">Buffer to use for collecting chunks.</param>
public BcpgOutputStream(
Stream outStr,
PacketTag tag,
byte[] buffer)
{
if (outStr == null)
throw new ArgumentNullException("outStr");
this.outStr = outStr;
this.WriteHeader(tag, false, true, 0);
this.partialBuffer = buffer;
uint length = (uint) 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)
{
if (bodyLen < 192)
{
outStr.WriteByte((byte)bodyLen);
}
else if (bodyLen <= 8383)
{
bodyLen -= 192;
outStr.WriteByte((byte)(((bodyLen >> 8) & 0xff) + 192));
outStr.WriteByte((byte)bodyLen);
}
else
{
outStr.WriteByte(0xff);
outStr.WriteByte((byte)(bodyLen >> 24));
outStr.WriteByte((byte)(bodyLen >> 16));
outStr.WriteByte((byte)(bodyLen >> 8));
outStr.WriteByte((byte)bodyLen);
}
}
private void WriteHeader(
PacketTag tag,
bool oldPackets,
bool partial,
long bodyLen)
{
int hdr = 0x80;
if (partialBuffer != null)
{
PartialFlushLast();
partialBuffer = null;
}
if (oldPackets)
{
hdr |= ((int) tag) << 2;
if (partial)
{
this.WriteByte((byte)(hdr | 0x03));
}
else
{
if (bodyLen <= 0xff)
{
this.WriteByte((byte) hdr);
this.WriteByte((byte)bodyLen);
}
else if (bodyLen <= 0xffff)
{
this.WriteByte((byte)(hdr | 0x01));
this.WriteByte((byte)(bodyLen >> 8));
this.WriteByte((byte)(bodyLen));
}
else
{
this.WriteByte((byte)(hdr | 0x02));
this.WriteByte((byte)(bodyLen >> 24));
this.WriteByte((byte)(bodyLen >> 16));
this.WriteByte((byte)(bodyLen >> 8));
this.WriteByte((byte)bodyLen);
}
}
}
else
{
hdr |= 0x40 | (int) tag;
this.WriteByte((byte) hdr);
if (partial)
{
partialOffset = 0;
}
else
{
this.WriteNewPacketLength(bodyLen);
}
}
}
private void PartialFlush()
{
outStr.WriteByte((byte)(0xE0 | partialPower));
outStr.Write(partialBuffer, 0, partialBufferLength);
partialOffset = 0;
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
private void PartialFlush(ref ReadOnlySpan<byte> buffer)
{
outStr.WriteByte((byte)(0xE0 | partialPower));
outStr.Write(buffer[..partialBufferLength]);
buffer = buffer[partialBufferLength..];
}
#endif
private void PartialFlushLast()
{
WriteNewPacketLength(partialOffset);
outStr.Write(partialBuffer, 0, partialOffset);
partialOffset = 0;
}
private void PartialWrite(byte[] buffer, int offset, int count)
{
Streams.ValidateBufferArguments(buffer, offset, count);
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
PartialWrite(buffer.AsSpan(offset, count));
#else
if (partialOffset == partialBufferLength)
{
PartialFlush();
}
if (count <= (partialBufferLength - partialOffset))
{
Array.Copy(buffer, offset, partialBuffer, partialOffset, count);
partialOffset += count;
return;
}
int diff = partialBufferLength - partialOffset;
Array.Copy(buffer, offset, partialBuffer, partialOffset, diff);
offset += diff;
count -= diff;
PartialFlush();
while (count > partialBufferLength)
{
Array.Copy(buffer, offset, partialBuffer, 0, partialBufferLength);
offset += partialBufferLength;
count -= partialBufferLength;
PartialFlush();
}
Array.Copy(buffer, offset, partialBuffer, 0, count);
partialOffset = count;
#endif
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
private void PartialWrite(ReadOnlySpan<byte> buffer)
{
if (partialOffset == partialBufferLength)
{
PartialFlush();
}
if (buffer.Length <= (partialBufferLength - partialOffset))
{
buffer.CopyTo(partialBuffer.AsSpan(partialOffset));
partialOffset += buffer.Length;
return;
}
int diff = partialBufferLength - partialOffset;
buffer[..diff].CopyTo(partialBuffer.AsSpan(partialOffset));
buffer = buffer[diff..];
PartialFlush();
while (buffer.Length > partialBufferLength)
{
PartialFlush(ref buffer);
}
buffer.CopyTo(partialBuffer);
partialOffset = buffer.Length;
}
#endif
private void PartialWriteByte(byte value)
{
if (partialOffset == partialBufferLength)
{
PartialFlush();
}
partialBuffer[partialOffset++] = value;
}
public override void Write(byte[] buffer, int offset, int count)
{
if (partialBuffer != null)
{
PartialWrite(buffer, offset, count);
}
else
{
outStr.Write(buffer, offset, count);
}
}
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
public override void Write(ReadOnlySpan<byte> buffer)
{
if (partialBuffer != null)
{
PartialWrite(buffer);
}
else
{
outStr.Write(buffer);
}
}
#endif
public override void WriteByte(byte value)
{
if (partialBuffer != null)
{
PartialWriteByte(value);
}
else
{
outStr.WriteByte(value);
}
}
// Additional helper methods to write primitive types
internal virtual void WriteShort(
short n)
{
this.Write(
(byte)(n >> 8),
(byte)n);
}
internal virtual void WriteInt(
int n)
{
this.Write(
(byte)(n >> 24),
(byte)(n >> 16),
(byte)(n >> 8),
(byte)n);
}
internal virtual void WriteLong(
long n)
{
this.Write(
(byte)(n >> 56),
(byte)(n >> 48),
(byte)(n >> 40),
(byte)(n >> 32),
(byte)(n >> 24),
(byte)(n >> 16),
(byte)(n >> 8),
(byte)n);
}
public void WritePacket(
ContainedPacket p)
{
p.Encode(this);
}
internal void WritePacket(
PacketTag tag,
byte[] body,
bool oldFormat)
{
this.WriteHeader(tag, oldFormat, false, body.Length);
this.Write(body);
}
public void WriteObject(
BcpgObject bcpgObject)
{
bcpgObject.Encode(this);
}
public void WriteObjects(
params BcpgObject[] v)
{
foreach (BcpgObject o in v)
{
o.Encode(this);
}
}
/// <summary>Flush the underlying stream.</summary>
public override void Flush()
{
outStr.Flush();
}
/// <summary>Finish writing out the current packet without closing the underlying stream.</summary>
public void Finish()
{
if (partialBuffer != null)
{
PartialFlushLast();
Array.Clear(partialBuffer, 0, partialBuffer.Length);
partialBuffer = null;
}
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.Finish();
outStr.Flush();
outStr.Dispose();
}
base.Dispose(disposing);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39a6c32ff29d5924cab98e7fe91434f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Generic compressed data object.</remarks>
public class CompressedDataPacket
: InputStreamPacket
{
private readonly CompressionAlgorithmTag algorithm;
internal CompressedDataPacket(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
this.algorithm = (CompressionAlgorithmTag) bcpgIn.ReadByte();
}
/// <summary>The algorithm tag value.</summary>
public CompressionAlgorithmTag Algorithm
{
get { return algorithm; }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4c0dd928f8e489c4aa84b76bfd69ed9d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic tags for compression algorithms.</remarks>
public enum CompressionAlgorithmTag
{
Uncompressed = 0, // Uncompressed
Zip = 1, // ZIP (RFC 1951)
ZLib = 2, // ZLIB (RFC 1950)
BZip2 = 3, // BZ2
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a075ed8dccc9ad04eba5fb8eb4fb1207
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic type for a PGP packet.</remarks>
public abstract class ContainedPacket
: Packet
{
public byte[] GetEncoded()
{
MemoryStream bOut = new MemoryStream();
BcpgOutputStream pOut = new BcpgOutputStream(bOut);
pOut.WritePacket(this);
return bOut.ToArray();
}
public abstract void Encode(BcpgOutputStream bcpgOut);
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5474bfdda1607be4284cc6ffa0de29e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public class Crc24
{
private const int Crc24Init = 0x0b704ce;
private const int Crc24Poly = 0x1864cfb;
private int crc = Crc24Init;
public Crc24()
{
}
public void Update(
int b)
{
crc ^= b << 16;
for (int i = 0; i < 8; i++)
{
crc <<= 1;
if ((crc & 0x1000000) != 0)
{
crc ^= Crc24Poly;
}
}
}
public int Value
{
get { return crc; }
}
public void Reset()
{
crc = Crc24Init;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c4dea685dcfa5e748bdebecb9a7bcc2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for a DSA public key.</remarks>
public class DsaPublicBcpgKey
: BcpgObject, IBcpgKey
{
private readonly MPInteger p, q, g, y;
/// <param name="bcpgIn">The stream to read the packet from.</param>
public DsaPublicBcpgKey(
BcpgInputStream bcpgIn)
{
this.p = new MPInteger(bcpgIn);
this.q = new MPInteger(bcpgIn);
this.g = new MPInteger(bcpgIn);
this.y = new MPInteger(bcpgIn);
}
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);
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObjects(p, q, g, y);
}
public BigInteger G
{
get { return g.Value; }
}
public BigInteger P
{
get { return p.Value; }
}
public BigInteger Q
{
get { return q.Value; }
}
public BigInteger Y
{
get { return y.Value; }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71cb50a82f5322245973364463bac01d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for a DSA secret key.</remarks>
public class DsaSecretBcpgKey
: BcpgObject, IBcpgKey
{
internal MPInteger x;
/**
* @param in
*/
public DsaSecretBcpgKey(
BcpgInputStream bcpgIn)
{
this.x = new MPInteger(bcpgIn);
}
public DsaSecretBcpgKey(
BigInteger x)
{
this.x = new MPInteger(x);
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObject(x);
}
/**
* @return x
*/
public BigInteger X
{
get { return x.Value; }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a0c4b07d1770444e88381fd41cd5e49
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,125 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an ECDH Public Key.</remarks>
public class ECDHPublicBcpgKey
: ECPublicBcpgKey
{
private byte reserved;
private HashAlgorithmTag hashFunctionId;
private SymmetricKeyAlgorithmTag symAlgorithmId;
/// <param name="bcpgIn">The stream to read the packet from.</param>
public ECDHPublicBcpgKey(BcpgInputStream bcpgIn)
: base(bcpgIn)
{
int length = bcpgIn.ReadByte();
if (length != 3)
throw new InvalidOperationException("KDF parameters size of 3 expected.");
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
Span<byte> kdfParameters = stackalloc byte[3];
#else
byte[] kdfParameters = new byte[3];
#endif
bcpgIn.ReadFully(kdfParameters);
reserved = kdfParameters[0];
hashFunctionId = (HashAlgorithmTag)kdfParameters[1];
symAlgorithmId = (SymmetricKeyAlgorithmTag)kdfParameters[2];
VerifyHashAlgorithm();
VerifySymmetricKeyAlgorithm();
}
public ECDHPublicBcpgKey(
DerObjectIdentifier oid,
ECPoint point,
HashAlgorithmTag hashAlgorithm,
SymmetricKeyAlgorithmTag symmetricKeyAlgorithm)
: base(oid, point)
{
reserved = 1;
hashFunctionId = hashAlgorithm;
symAlgorithmId = symmetricKeyAlgorithm;
VerifyHashAlgorithm();
VerifySymmetricKeyAlgorithm();
}
public ECDHPublicBcpgKey(
DerObjectIdentifier oid,
BigInteger point,
HashAlgorithmTag hashAlgorithm,
SymmetricKeyAlgorithmTag symmetricKeyAlgorithm)
: base(oid, point)
{
reserved = 1;
hashFunctionId = hashAlgorithm;
symAlgorithmId = symmetricKeyAlgorithm;
VerifyHashAlgorithm();
VerifySymmetricKeyAlgorithm();
}
public virtual byte Reserved
{
get { return reserved; }
}
public virtual HashAlgorithmTag HashAlgorithm
{
get { return hashFunctionId; }
}
public virtual SymmetricKeyAlgorithmTag SymmetricKeyAlgorithm
{
get { return symAlgorithmId; }
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
base.Encode(bcpgOut);
bcpgOut.WriteByte(0x3);
bcpgOut.WriteByte(reserved);
bcpgOut.WriteByte((byte)hashFunctionId);
bcpgOut.WriteByte((byte)symAlgorithmId);
}
private void VerifyHashAlgorithm()
{
switch (hashFunctionId)
{
case HashAlgorithmTag.Sha256:
case HashAlgorithmTag.Sha384:
case HashAlgorithmTag.Sha512:
break;
default:
throw new InvalidOperationException("Hash algorithm must be SHA-256 or stronger.");
}
}
private void VerifySymmetricKeyAlgorithm()
{
switch (symAlgorithmId)
{
case SymmetricKeyAlgorithmTag.Aes128:
case SymmetricKeyAlgorithmTag.Aes192:
case SymmetricKeyAlgorithmTag.Aes256:
break;
default:
throw new InvalidOperationException("Symmetric key algorithm must be AES-128 or stronger.");
}
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26a9e9688bc3c6d47bd10d3380f53397
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an ECDSA Public Key.</remarks>
public class ECDsaPublicBcpgKey
: ECPublicBcpgKey
{
/// <param name="bcpgIn">The stream to read the packet from.</param>
protected internal ECDsaPublicBcpgKey(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
}
public ECDsaPublicBcpgKey(
DerObjectIdentifier oid,
ECPoint point)
: base(oid, point)
{
}
public ECDsaPublicBcpgKey(
DerObjectIdentifier oid,
BigInteger encodedPoint)
: base(oid, encodedPoint)
{
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 95b1f455837bd00489e36360719c4475
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,103 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an EC Public Key.</remarks>
public abstract class ECPublicBcpgKey
: BcpgObject, IBcpgKey
{
internal DerObjectIdentifier oid;
internal BigInteger point;
/// <param name="bcpgIn">The stream to read the packet from.</param>
protected ECPublicBcpgKey(
BcpgInputStream bcpgIn)
{
this.oid = DerObjectIdentifier.GetInstance(Asn1Object.FromByteArray(ReadBytesOfEncodedLength(bcpgIn)));
this.point = new MPInteger(bcpgIn).Value;
}
protected ECPublicBcpgKey(
DerObjectIdentifier oid,
ECPoint point)
{
this.point = MPInteger.ToMpiBigInteger(point);
this.oid = oid;
}
protected ECPublicBcpgKey(
DerObjectIdentifier oid,
BigInteger encodedPoint)
{
this.point = encodedPoint;
this.oid = oid;
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (IOException)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
byte[] oid = this.oid.GetEncoded();
bcpgOut.Write(oid, 1, oid.Length - 1);
MPInteger point = new MPInteger(this.point);
bcpgOut.WriteObject(point);
}
public virtual BigInteger EncodedPoint
{
get { return point; }
}
public virtual DerObjectIdentifier CurveOid
{
get { return oid; }
}
protected static byte[] ReadBytesOfEncodedLength(
BcpgInputStream bcpgIn)
{
int length = bcpgIn.ReadByte();
if (length < 0)
throw new EndOfStreamException();
if (length == 0 || length == 0xFF)
throw new IOException("future extensions not yet implemented");
if (length > 127)
throw new IOException("unsupported OID");
byte[] buffer = new byte[length + 2];
bcpgIn.ReadFully(buffer, 2, buffer.Length - 2);
buffer[0] = (byte)0x06;
buffer[1] = (byte)length;
return buffer;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3e1f4884d15689f4591e3616803f41df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,59 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an EC Secret Key.</remarks>
public class ECSecretBcpgKey
: BcpgObject, IBcpgKey
{
internal readonly MPInteger m_x;
public ECSecretBcpgKey(
BcpgInputStream bcpgIn)
{
m_x = new MPInteger(bcpgIn);
}
public ECSecretBcpgKey(
BigInteger x)
{
m_x = new MPInteger(x);
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObject(m_x);
}
public virtual BigInteger X
{
get { return m_x.Value; }
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4ef2691efaa3c5244b2ba98b291be784
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public sealed class EdDsaPublicBcpgKey
: ECPublicBcpgKey
{
internal EdDsaPublicBcpgKey(BcpgInputStream bcpgIn)
: base(bcpgIn)
{
}
public EdDsaPublicBcpgKey(DerObjectIdentifier oid, ECPoint point)
: base(oid, point)
{
}
public EdDsaPublicBcpgKey(DerObjectIdentifier oid, BigInteger encodedPoint)
: base(oid, encodedPoint)
{
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 886e996d31601394ba4c3f2d691c6d68
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public sealed class EdSecretBcpgKey
: BcpgObject, IBcpgKey
{
internal readonly MPInteger m_x;
public EdSecretBcpgKey(BcpgInputStream bcpgIn)
{
m_x = new MPInteger(bcpgIn);
}
public EdSecretBcpgKey(BigInteger x)
{
m_x = new MPInteger(x);
}
public string Format => "PGP";
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObject(m_x);
}
public BigInteger X => m_x.Value;
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f1b967203f5d100409763ad04d4f89e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an ElGamal public key.</remarks>
public class ElGamalPublicBcpgKey
: BcpgObject, IBcpgKey
{
internal MPInteger p, g, y;
public ElGamalPublicBcpgKey(
BcpgInputStream bcpgIn)
{
this.p = new MPInteger(bcpgIn);
this.g = new MPInteger(bcpgIn);
this.y = new MPInteger(bcpgIn);
}
public ElGamalPublicBcpgKey(
BigInteger p,
BigInteger g,
BigInteger y)
{
this.p = new MPInteger(p);
this.g = new MPInteger(g);
this.y = new MPInteger(y);
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public BigInteger P
{
get { return p.Value; }
}
public BigInteger G
{
get { return g.Value; }
}
public BigInteger Y
{
get { return y.Value; }
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObjects(p, g, y);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 041475c7c5e3bb748a026fd2d7cb6188
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an ElGamal secret key.</remarks>
public class ElGamalSecretBcpgKey
: BcpgObject, IBcpgKey
{
internal MPInteger x;
/**
* @param in
*/
public ElGamalSecretBcpgKey(
BcpgInputStream bcpgIn)
{
this.x = new MPInteger(bcpgIn);
}
/**
* @param x
*/
public ElGamalSecretBcpgKey(
BigInteger x)
{
this.x = new MPInteger(x);
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
public BigInteger X
{
get { return x.Value; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObject(x);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04e1edef56eb0884ea6902e6e8cbd629
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for an experimental packet.</remarks>
public class ExperimentalPacket
: ContainedPacket //, PublicKeyAlgorithmTag
{
private readonly PacketTag tag;
private readonly byte[] contents;
internal ExperimentalPacket(
PacketTag tag,
BcpgInputStream bcpgIn)
{
this.tag = tag;
this.contents = bcpgIn.ReadAll();
}
public PacketTag Tag
{
get { return tag; }
}
public byte[] GetContents()
{
return (byte[]) contents.Clone();
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(tag, contents, true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7817fdb34c603bf4dab275a54bb4602f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic tags for hash algorithms.</remarks>
public enum HashAlgorithmTag
{
MD5 = 1, // MD5
Sha1 = 2, // SHA-1
RipeMD160 = 3, // RIPE-MD/160
DoubleSha = 4, // Reserved for double-width SHA (experimental)
MD2 = 5, // MD2
Tiger192 = 6, // Reserved for TIGER/192
Haval5pass160 = 7, // Reserved for HAVAL (5 pass, 160-bit)
Sha256 = 8, // SHA-256
Sha384 = 9, // SHA-384
Sha512 = 10, // SHA-512
Sha224 = 11, // SHA-224
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3374d0310a5088b4bb1b2683a58b147c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base interface for a PGP key.</remarks>
public interface IBcpgKey
{
/// <summary>
/// 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.
/// </summary>
/// <returns>"RAW" or "PGP".</returns>
string Format { get; }
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c1d668da834dae46a73cf6da424acc1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public class InputStreamPacket
: Packet
{
private readonly BcpgInputStream bcpgIn;
public InputStreamPacket(
BcpgInputStream bcpgIn)
{
this.bcpgIn = bcpgIn;
}
/// <summary>Note: you can only read from this once...</summary>
public BcpgInputStream GetInputStream()
{
return bcpgIn;
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 583e023939328f540b4958a82128dab7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Generic literal data packet.</remarks>
public class LiteralDataPacket
: InputStreamPacket
{
private int format;
private byte[] fileName;
private long modDate;
internal LiteralDataPacket(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
format = bcpgIn.ReadByte();
int len = bcpgIn.ReadByte();
fileName = new byte[len];
for (int i = 0; i != len; ++i)
{
int ch = bcpgIn.ReadByte();
if (ch < 0)
throw new IOException("literal data truncated in header");
fileName[i] = (byte)ch;
}
modDate = (((uint)bcpgIn.ReadByte() << 24)
| ((uint)bcpgIn.ReadByte() << 16)
| ((uint)bcpgIn.ReadByte() << 8)
| (uint)bcpgIn.ReadByte()) * 1000L;
}
/// <summary>The format tag value.</summary>
public int Format
{
get { return format; }
}
/// <summary>The modification time of the file in milli-seconds (since Jan 1, 1970 UTC)</summary>
public long ModificationTime
{
get { return modDate; }
}
public string FileName
{
get { return Strings.FromUtf8ByteArray(fileName); }
}
public byte[] GetRawFileName()
{
return Arrays.Clone(fileName);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bbb6795003d25704fa1af50d4a6da485
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math.EC;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>A multiple precision integer</remarks>
public sealed class MPInteger
: BcpgObject
{
private readonly BigInteger m_val;
public MPInteger(BcpgInputStream bcpgIn)
{
if (bcpgIn == null)
throw new ArgumentNullException(nameof(bcpgIn));
int lengthInBits = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
int lengthInBytes = (lengthInBits + 7) / 8;
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
Span<byte> bytes = lengthInBytes <= 512
? stackalloc byte[lengthInBytes]
: new byte[lengthInBytes];
#else
byte[] bytes = new byte[lengthInBytes];
#endif
bcpgIn.ReadFully(bytes);
m_val = new BigInteger(1, bytes);
}
public MPInteger(BigInteger val)
{
if (val == null)
throw new ArgumentNullException(nameof(val));
if (val.SignValue < 0)
throw new ArgumentException("Values must be positive", nameof(val));
m_val = val;
}
public BigInteger Value => m_val;
public override void Encode(BcpgOutputStream bcpgOut)
{
bcpgOut.WriteShort((short)m_val.BitLength);
bcpgOut.Write(m_val.ToByteArrayUnsigned());
}
internal static BigInteger ToMpiBigInteger(ECPoint point)
{
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || _UNITY_2021_2_OR_NEWER_
int encodedLength = point.GetEncodedLength(false);
Span<byte> encoding = encodedLength <= 512
? stackalloc byte[encodedLength]
: new byte[encodedLength];
point.EncodeTo(false, encoding);
#else
byte[] encoding = point.GetEncoded(false);
#endif
return new BigInteger(1, encoding);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 51c43f87142c9274cb885752c1ba2ca0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic type for a marker packet.</remarks>
public class MarkerPacket
: ContainedPacket
{
// "PGP"
byte[] marker = { (byte)0x50, (byte)0x47, (byte)0x50 };
public MarkerPacket(
BcpgInputStream bcpgIn)
{
bcpgIn.ReadFully(marker);
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.Marker, marker, true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7507f951392bc4b41bc730caddecd831
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for a modification detection code packet.</remarks>
public class ModDetectionCodePacket
: ContainedPacket
{
private readonly byte[] digest;
internal ModDetectionCodePacket(
BcpgInputStream bcpgIn)
{
if (bcpgIn == null)
throw new ArgumentNullException("bcpgIn");
this.digest = new byte[20];
bcpgIn.ReadFully(this.digest);
}
public ModDetectionCodePacket(
byte[] digest)
{
if (digest == null)
throw new ArgumentNullException("digest");
this.digest = (byte[]) digest.Clone();
}
public byte[] GetDigest()
{
return (byte[]) digest.Clone();
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.ModificationDetectionCode, digest, false);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6c3929f2a5efda46b5239155ec5c61f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Generic signature object</remarks>
public class OnePassSignaturePacket
: ContainedPacket
{
private int version;
private int sigType;
private HashAlgorithmTag hashAlgorithm;
private PublicKeyAlgorithmTag keyAlgorithm;
private long keyId;
private int nested;
internal OnePassSignaturePacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
sigType = bcpgIn.ReadByte();
hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
keyId |= (long)bcpgIn.ReadByte() << 56;
keyId |= (long)bcpgIn.ReadByte() << 48;
keyId |= (long)bcpgIn.ReadByte() << 40;
keyId |= (long)bcpgIn.ReadByte() << 32;
keyId |= (long)bcpgIn.ReadByte() << 24;
keyId |= (long)bcpgIn.ReadByte() << 16;
keyId |= (long)bcpgIn.ReadByte() << 8;
keyId |= (uint)bcpgIn.ReadByte();
nested = bcpgIn.ReadByte();
}
public OnePassSignaturePacket(
int sigType,
HashAlgorithmTag hashAlgorithm,
PublicKeyAlgorithmTag keyAlgorithm,
long keyId,
bool isNested)
{
this.version = 3;
this.sigType = sigType;
this.hashAlgorithm = hashAlgorithm;
this.keyAlgorithm = keyAlgorithm;
this.keyId = keyId;
this.nested = (isNested) ? 0 : 1;
}
public int SignatureType
{
get { return sigType; }
}
/// <summary>The encryption algorithm tag.</summary>
public PublicKeyAlgorithmTag KeyAlgorithm
{
get { return keyAlgorithm; }
}
/// <summary>The hash algorithm tag.</summary>
public HashAlgorithmTag HashAlgorithm
{
get { return hashAlgorithm; }
}
public long KeyId
{
get { return keyId; }
}
public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
using (var pOut = new BcpgOutputStream(bOut))
{
pOut.Write((byte)version, (byte)sigType, (byte)hashAlgorithm, (byte)keyAlgorithm);
pOut.WriteLong(keyId);
pOut.WriteByte((byte)nested);
}
bcpgOut.WritePacket(PacketTag.OnePassSignature, bOut.ToArray(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e7e62a0975595a0479ec420eb593573d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public abstract class OutputStreamPacket
{
private readonly BcpgOutputStream bcpgOut;
internal OutputStreamPacket(
BcpgOutputStream bcpgOut)
{
if (bcpgOut == null)
throw new ArgumentNullException("bcpgOut");
this.bcpgOut = bcpgOut;
}
public abstract BcpgOutputStream Open();
public abstract void Close();
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ab88778cc7899cb44bb4987dd4ea69cf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public class Packet
//: PacketTag
{
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f681ca9844fb3804ebdc012de2ef2e52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic PGP packet tag types.</remarks>
public enum PacketTag
{
Reserved = 0, // Reserved - a packet tag must not have this value
PublicKeyEncryptedSession = 1, // Public-Key Encrypted Session Key Packet
Signature = 2, // Signature Packet
SymmetricKeyEncryptedSessionKey = 3, // Symmetric-Key Encrypted Session Key Packet
OnePassSignature = 4, // One-Pass Signature Packet
SecretKey = 5, // Secret Key Packet
PublicKey = 6, // Public Key Packet
SecretSubkey = 7, // Secret Subkey Packet
CompressedData = 8, // Compressed Data Packet
SymmetricKeyEncrypted = 9, // Symmetrically Encrypted Data Packet
Marker = 10, // Marker Packet
LiteralData = 11, // Literal Data Packet
Trust = 12, // Trust Packet
UserId = 13, // User ID Packet
PublicSubkey = 14, // Public Subkey Packet
UserAttribute = 17, // User attribute
SymmetricEncryptedIntegrityProtected = 18, // Symmetric encrypted, integrity protected
ModificationDetectionCode = 19, // Modification detection code
Experimental1 = 60, // Private or Experimental Values
Experimental2 = 61,
Experimental3 = 62,
Experimental4 = 63
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dcaf4305fb1e4ed49a53460eb6ae9857
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Public Key Algorithm tag numbers.</remarks>
public enum PublicKeyAlgorithmTag
{
RsaGeneral = 1, // RSA (Encrypt or Sign)
RsaEncrypt = 2, // RSA Encrypt-Only
RsaSign = 3, // RSA Sign-Only
ElGamalEncrypt = 16, // Elgamal (Encrypt-Only), see [ELGAMAL]
Dsa = 17, // DSA (Digital Signature Standard)
ECDH = 18, // Reserved for Elliptic Curve (actual algorithm name)
ECDsa = 19, // Reserved for ECDSA
ElGamalGeneral = 20, // Elgamal (Encrypt or Sign)
DiffieHellman = 21, // Reserved for Diffie-Hellman (X9.42, as defined for IETF-S/MIME)
EdDsa = 22, // EdDSA - (internet draft, but appearing in use)
Experimental_1 = 100,
Experimental_2 = 101,
Experimental_3 = 102,
Experimental_4 = 103,
Experimental_5 = 104,
Experimental_6 = 105,
Experimental_7 = 106,
Experimental_8 = 107,
Experimental_9 = 108,
Experimental_10 = 109,
Experimental_11 = 110,
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a8047fe7dbc9f55498b91c5ccbc9d4e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,115 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for a PGP public key.</remarks>
public class PublicKeyEncSessionPacket
: ContainedPacket //, PublicKeyAlgorithmTag
{
private int version;
private long keyId;
private PublicKeyAlgorithmTag algorithm;
private byte[][] data;
internal PublicKeyEncSessionPacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
keyId |= (long)bcpgIn.ReadByte() << 56;
keyId |= (long)bcpgIn.ReadByte() << 48;
keyId |= (long)bcpgIn.ReadByte() << 40;
keyId |= (long)bcpgIn.ReadByte() << 32;
keyId |= (long)bcpgIn.ReadByte() << 24;
keyId |= (long)bcpgIn.ReadByte() << 16;
keyId |= (long)bcpgIn.ReadByte() << 8;
keyId |= (uint)bcpgIn.ReadByte();
algorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
switch ((PublicKeyAlgorithmTag) algorithm)
{
case PublicKeyAlgorithmTag.RsaEncrypt:
case PublicKeyAlgorithmTag.RsaGeneral:
data = new byte[][]{ new MPInteger(bcpgIn).GetEncoded() };
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.ElGamalGeneral:
MPInteger p = new MPInteger(bcpgIn);
MPInteger g = new MPInteger(bcpgIn);
data = new byte[][]{
p.GetEncoded(),
g.GetEncoded(),
};
break;
case PublicKeyAlgorithmTag.ECDH:
data = new byte[][]{ Streams.ReadAll(bcpgIn) };
break;
default:
throw new IOException("unknown PGP public key algorithm encountered");
}
}
public PublicKeyEncSessionPacket(
long keyId,
PublicKeyAlgorithmTag 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 Version
{
get { return version; }
}
public long KeyId
{
get { return keyId; }
}
public PublicKeyAlgorithmTag Algorithm
{
get { return algorithm; }
}
public byte[][] GetEncSessionKey()
{
return data;
}
public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
using (var pOut = new BcpgOutputStream(bOut))
{
pOut.WriteByte((byte)version);
pOut.WriteLong(keyId);
pOut.WriteByte((byte)algorithm);
for (int i = 0; i < data.Length; ++i)
{
pOut.Write(data[i]);
}
}
bcpgOut.WritePacket(PacketTag.PublicKeyEncryptedSession, bOut.ToArray(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 85cc1954c6d307041a1767fa723a7b52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,128 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for a PGP public key.</remarks>
public class PublicKeyPacket
: ContainedPacket //, PublicKeyAlgorithmTag
{
private int version;
private long time;
private int validDays;
private PublicKeyAlgorithmTag algorithm;
private IBcpgKey key;
internal PublicKeyPacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
time = ((uint)bcpgIn.ReadByte() << 24) | ((uint)bcpgIn.ReadByte() << 16)
| ((uint)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte();
if (version <= 3)
{
validDays = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
}
algorithm = (PublicKeyAlgorithmTag)bcpgIn.ReadByte();
switch (algorithm)
{
case PublicKeyAlgorithmTag.RsaEncrypt:
case PublicKeyAlgorithmTag.RsaGeneral:
case PublicKeyAlgorithmTag.RsaSign:
key = new RsaPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.Dsa:
key = new DsaPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt:
case PublicKeyAlgorithmTag.ElGamalGeneral:
key = new ElGamalPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.ECDH:
key = new ECDHPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.ECDsa:
key = new ECDsaPublicBcpgKey(bcpgIn);
break;
case PublicKeyAlgorithmTag.EdDsa:
key = new EdDsaPublicBcpgKey(bcpgIn);
break;
default:
throw new IOException("unknown PGP public key algorithm encountered");
}
}
/// <summary>Construct a version 4 public key packet.</summary>
public PublicKeyPacket(
PublicKeyAlgorithmTag algorithm,
DateTime time,
IBcpgKey key)
{
this.version = 4;
this.time = DateTimeUtilities.DateTimeToUnixMs(time) / 1000L;
this.algorithm = algorithm;
this.key = key;
}
public virtual int Version
{
get { return version; }
}
public virtual PublicKeyAlgorithmTag Algorithm
{
get { return algorithm; }
}
public virtual int ValidDays
{
get { return validDays; }
}
public virtual DateTime GetTime()
{
return DateTimeUtilities.UnixMsToDateTime(time * 1000L);
}
public virtual IBcpgKey Key
{
get { return key; }
}
public virtual byte[] GetEncodedContents()
{
MemoryStream bOut = new MemoryStream();
BcpgOutputStream pOut = new BcpgOutputStream(bOut);
pOut.WriteByte((byte) version);
pOut.WriteInt((int) time);
if (version <= 3)
{
pOut.WriteShort((short) validDays);
}
pOut.WriteByte((byte) algorithm);
pOut.WriteObject((BcpgObject)key);
return bOut.ToArray();
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.PublicKey, GetEncodedContents(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4978f79fa76141d49b9b2130137082f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for a PGP public subkey</remarks>
public class PublicSubkeyPacket
: PublicKeyPacket
{
internal PublicSubkeyPacket(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
}
/// <summary>Construct a version 4 public subkey packet.</summary>
public PublicSubkeyPacket(
PublicKeyAlgorithmTag algorithm,
DateTime time,
IBcpgKey key)
: base(algorithm, time, key)
{
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.PublicSubkey, GetEncodedContents(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0b1aa5a45da55614991fa91a2ea17148
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an RSA public key.</remarks>
public class RsaPublicBcpgKey
: BcpgObject, IBcpgKey
{
private readonly MPInteger n, e;
/// <summary>Construct an RSA public key from the passed in stream.</summary>
public RsaPublicBcpgKey(
BcpgInputStream bcpgIn)
{
this.n = new MPInteger(bcpgIn);
this.e = new MPInteger(bcpgIn);
}
/// <param name="n">The modulus.</param>
/// <param name="e">The public exponent.</param>
public RsaPublicBcpgKey(
BigInteger n,
BigInteger e)
{
this.n = new MPInteger(n);
this.e = new MPInteger(e);
}
public BigInteger PublicExponent
{
get { return e.Value; }
}
public BigInteger Modulus
{
get { return n.Value; }
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObjects(n, e);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ffa063fd89c8f804089fe50ad3921cc1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,119 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Base class for an RSA secret (or priate) key.</remarks>
public class RsaSecretBcpgKey
: BcpgObject, IBcpgKey
{
private readonly MPInteger d, p, q, u;
private readonly BigInteger expP, expQ, crt;
public RsaSecretBcpgKey(
BcpgInputStream bcpgIn)
{
this.d = new MPInteger(bcpgIn);
this.p = new MPInteger(bcpgIn);
this.q = new MPInteger(bcpgIn);
this.u = new MPInteger(bcpgIn);
this.expP = d.Value.Remainder(p.Value.Subtract(BigInteger.One));
this.expQ = d.Value.Remainder(q.Value.Subtract(BigInteger.One));
this.crt = BigIntegers.ModOddInverse(p.Value, q.Value);
}
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 ArgumentException("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(BigIntegers.ModOddInverse(q, p));
this.expP = d.Remainder(p.Subtract(BigInteger.One));
this.expQ = d.Remainder(q.Subtract(BigInteger.One));
this.crt = BigIntegers.ModOddInverse(p, q);
}
public BigInteger Modulus
{
get { return p.Value.Multiply(q.Value); }
}
public BigInteger PrivateExponent
{
get { return d.Value; }
}
public BigInteger PrimeP
{
get { return p.Value; }
}
public BigInteger PrimeQ
{
get { return q.Value; }
}
public BigInteger PrimeExponentP
{
get { return expP; }
}
public BigInteger PrimeExponentQ
{
get { return expQ; }
}
public BigInteger CrtCoefficient
{
get { return crt; }
}
/// <summary>The format, as a string, always "PGP".</summary>
public string Format
{
get { return "PGP"; }
}
/// <summary>Return the standard PGP encoding of the key.</summary>
public override byte[] GetEncoded()
{
try
{
return base.GetEncoded();
}
catch (Exception)
{
return null;
}
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteObjects(d, p, q, u);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e4508a3c4cd43cb4082a991038ce0545
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,147 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>The string to key specifier class.</remarks>
public class S2k
: BcpgObject
{
private const int ExpBias = 6;
public const int Simple = 0;
public const int Salted = 1;
public const int SaltedAndIterated = 3;
public const int GnuDummyS2K = 101;
public const int GnuProtectionModeNoPrivateKey = 1;
public const int GnuProtectionModeDivertToCard = 2;
internal int type;
internal HashAlgorithmTag algorithm;
internal byte[] iv;
internal int itCount = -1;
internal int protectionMode = -1;
internal S2k(
Stream inStr)
{
type = inStr.ReadByte();
algorithm = (HashAlgorithmTag) inStr.ReadByte();
//
// if this happens we have a dummy-S2k packet.
//
if (type != GnuDummyS2K)
{
if (type != 0)
{
iv = new byte[8];
if (Streams.ReadFully(inStr, iv, 0, iv.Length) < iv.Length)
throw new EndOfStreamException();
if (type == 3)
{
itCount = inStr.ReadByte();
}
}
}
else
{
inStr.ReadByte(); // G
inStr.ReadByte(); // N
inStr.ReadByte(); // U
protectionMode = inStr.ReadByte(); // protection mode
}
}
public S2k(
HashAlgorithmTag algorithm)
{
this.type = 0;
this.algorithm = algorithm;
}
public S2k(
HashAlgorithmTag algorithm,
byte[] iv)
{
this.type = 1;
this.algorithm = algorithm;
this.iv = iv;
}
public S2k(
HashAlgorithmTag algorithm,
byte[] iv,
int itCount)
{
this.type = 3;
this.algorithm = algorithm;
this.iv = iv;
this.itCount = itCount;
}
public virtual int Type
{
get { return type; }
}
/// <summary>The hash algorithm.</summary>
public virtual HashAlgorithmTag HashAlgorithm
{
get { return algorithm; }
}
/// <summary>The IV for the key generation algorithm.</summary>
public virtual byte[] GetIV()
{
return Arrays.Clone(iv);
}
/// <summary>The iteration count</summary>
public virtual long IterationCount
{
get { return (16 + (itCount & 15)) << ((itCount >> 4) + ExpBias); }
}
/// <summary>The protection mode - only if GnuDummyS2K</summary>
public virtual int ProtectionMode
{
get { return protectionMode; }
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WriteByte((byte) type);
bcpgOut.WriteByte((byte) algorithm);
if (type != GnuDummyS2K)
{
if (type != 0)
{
bcpgOut.Write(iv);
}
if (type == 3)
{
bcpgOut.WriteByte((byte) itCount);
}
}
else
{
bcpgOut.WriteByte((byte) 'G');
bcpgOut.WriteByte((byte) 'N');
bcpgOut.WriteByte((byte) 'U');
bcpgOut.WriteByte((byte) protectionMode);
}
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: abfc948ea0289364dadb631d98b29e61
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,174 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for a PGP secret key.</remarks>
public class SecretKeyPacket
: ContainedPacket //, PublicKeyAlgorithmTag
{
public const int UsageNone = 0x00;
public const int UsageChecksum = 0xff;
public const int UsageSha1 = 0xfe;
private PublicKeyPacket pubKeyPacket;
private readonly byte[] secKeyData;
private int s2kUsage;
private SymmetricKeyAlgorithmTag encAlgorithm;
private S2k s2k;
private byte[] iv;
internal SecretKeyPacket(
BcpgInputStream bcpgIn)
{
if (this is SecretSubkeyPacket)
{
pubKeyPacket = new PublicSubkeyPacket(bcpgIn);
}
else
{
pubKeyPacket = new PublicKeyPacket(bcpgIn);
}
s2kUsage = bcpgIn.ReadByte();
if (s2kUsage == UsageChecksum || s2kUsage == UsageSha1)
{
encAlgorithm = (SymmetricKeyAlgorithmTag) bcpgIn.ReadByte();
s2k = new S2k(bcpgIn);
}
else
{
encAlgorithm = (SymmetricKeyAlgorithmTag) s2kUsage;
}
if (!(s2k != null && s2k.Type == S2k.GnuDummyS2K && s2k.ProtectionMode == 0x01))
{
if (s2kUsage != 0)
{
if (((int) encAlgorithm) < 7)
{
iv = new byte[8];
}
else
{
iv = new byte[16];
}
bcpgIn.ReadFully(iv);
}
}
secKeyData = bcpgIn.ReadAll();
}
public SecretKeyPacket(
PublicKeyPacket pubKeyPacket,
SymmetricKeyAlgorithmTag encAlgorithm,
S2k s2k,
byte[] iv,
byte[] secKeyData)
{
this.pubKeyPacket = pubKeyPacket;
this.encAlgorithm = encAlgorithm;
if (encAlgorithm != SymmetricKeyAlgorithmTag.Null)
{
this.s2kUsage = UsageChecksum;
}
else
{
this.s2kUsage = UsageNone;
}
this.s2k = s2k;
this.iv = Arrays.Clone(iv);
this.secKeyData = secKeyData;
}
public SecretKeyPacket(
PublicKeyPacket pubKeyPacket,
SymmetricKeyAlgorithmTag encAlgorithm,
int s2kUsage,
S2k s2k,
byte[] iv,
byte[] secKeyData)
{
this.pubKeyPacket = pubKeyPacket;
this.encAlgorithm = encAlgorithm;
this.s2kUsage = s2kUsage;
this.s2k = s2k;
this.iv = Arrays.Clone(iv);
this.secKeyData = secKeyData;
}
public SymmetricKeyAlgorithmTag EncAlgorithm
{
get { return encAlgorithm; }
}
public int S2kUsage
{
get { return s2kUsage; }
}
public byte[] GetIV()
{
return Arrays.Clone(iv);
}
public S2k S2k
{
get { return s2k; }
}
public PublicKeyPacket PublicKeyPacket
{
get { return pubKeyPacket; }
}
public byte[] GetSecretKeyData()
{
return secKeyData;
}
public byte[] GetEncodedContents()
{
MemoryStream bOut = new MemoryStream();
BcpgOutputStream pOut = new BcpgOutputStream(bOut);
pOut.Write(pubKeyPacket.GetEncodedContents());
pOut.WriteByte((byte) s2kUsage);
if (s2kUsage == UsageChecksum || s2kUsage == UsageSha1)
{
pOut.WriteByte((byte) encAlgorithm);
pOut.WriteObject(s2k);
}
if (iv != null)
{
pOut.Write(iv);
}
if (secKeyData != null && secKeyData.Length > 0)
{
pOut.Write(secKeyData);
}
return bOut.ToArray();
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.SecretKey, GetEncodedContents(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5a0959cf27a501f4298786b0bd9b10be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic packet for a PGP secret key.</remarks>
public class SecretSubkeyPacket
: SecretKeyPacket
{
internal SecretSubkeyPacket(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
}
public SecretSubkeyPacket(
PublicKeyPacket pubKeyPacket,
SymmetricKeyAlgorithmTag encAlgorithm,
S2k s2k,
byte[] iv,
byte[] secKeyData)
: base(pubKeyPacket, encAlgorithm, s2k, iv, secKeyData)
{
}
public SecretSubkeyPacket(
PublicKeyPacket pubKeyPacket,
SymmetricKeyAlgorithmTag encAlgorithm,
int s2kUsage,
S2k s2k,
byte[] iv,
byte[] secKeyData)
: base(pubKeyPacket, encAlgorithm, s2kUsage, s2k, iv, secKeyData)
{
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.SecretSubkey, GetEncodedContents(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a71e0ececac4a645a427b6d001a363b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,466 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Collections.Generic;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Date;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Generic signature packet.</remarks>
public class SignaturePacket
: ContainedPacket
{
private int version;
private int signatureType;
private long creationTime;
private long keyId;
private PublicKeyAlgorithmTag keyAlgorithm;
private HashAlgorithmTag hashAlgorithm;
private MPInteger[] signature;
private byte[] fingerprint;
private SignatureSubpacket[] hashedData;
private SignatureSubpacket[] unhashedData;
private byte[] signatureEncoding;
internal SignaturePacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
if (version == 3 || version == 2)
{
// int l =
bcpgIn.ReadByte();
signatureType = bcpgIn.ReadByte();
creationTime = (((long)bcpgIn.ReadByte() << 24) | ((long)bcpgIn.ReadByte() << 16)
| ((long)bcpgIn.ReadByte() << 8) | (uint)bcpgIn.ReadByte()) * 1000L;
keyId |= (long)bcpgIn.ReadByte() << 56;
keyId |= (long)bcpgIn.ReadByte() << 48;
keyId |= (long)bcpgIn.ReadByte() << 40;
keyId |= (long)bcpgIn.ReadByte() << 32;
keyId |= (long)bcpgIn.ReadByte() << 24;
keyId |= (long)bcpgIn.ReadByte() << 16;
keyId |= (long)bcpgIn.ReadByte() << 8;
keyId |= (uint)bcpgIn.ReadByte();
keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
}
else if (version == 4)
{
signatureType = bcpgIn.ReadByte();
keyAlgorithm = (PublicKeyAlgorithmTag) bcpgIn.ReadByte();
hashAlgorithm = (HashAlgorithmTag) bcpgIn.ReadByte();
int hashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
byte[] hashed = new byte[hashedLength];
bcpgIn.ReadFully(hashed);
//
// read the signature sub packet data.
//
SignatureSubpacketsParser sIn = new SignatureSubpacketsParser(
new MemoryStream(hashed, false));
var v = new List<SignatureSubpacket>();
SignatureSubpacket sub;
while ((sub = sIn.ReadPacket()) != null)
{
v.Add(sub);
}
hashedData = v.ToArray();
foreach (var p in hashedData)
{
if (p is IssuerKeyId issuerKeyId)
{
keyId = issuerKeyId.KeyId;
}
else if (p is SignatureCreationTime sigCreationTime)
{
creationTime = DateTimeUtilities.DateTimeToUnixMs(sigCreationTime.GetTime());
}
}
int unhashedLength = (bcpgIn.ReadByte() << 8) | bcpgIn.ReadByte();
byte[] unhashed = new byte[unhashedLength];
bcpgIn.ReadFully(unhashed);
sIn = new SignatureSubpacketsParser(new MemoryStream(unhashed, false));
v.Clear();
while ((sub = sIn.ReadPacket()) != null)
{
v.Add(sub);
}
unhashedData = v.ToArray();
foreach (var p in unhashedData)
{
if (p is IssuerKeyId issuerKeyId)
{
keyId = issuerKeyId.KeyId;
}
}
}
else
{
Streams.Drain(bcpgIn);
throw new UnsupportedPacketVersionException("unsupported version: " + version);
}
fingerprint = new byte[2];
bcpgIn.ReadFully(fingerprint);
switch (keyAlgorithm)
{
case PublicKeyAlgorithmTag.RsaGeneral:
case PublicKeyAlgorithmTag.RsaSign:
MPInteger v = new MPInteger(bcpgIn);
signature = new MPInteger[1]{ v };
break;
case PublicKeyAlgorithmTag.Dsa:
MPInteger r = new MPInteger(bcpgIn);
MPInteger s = new MPInteger(bcpgIn);
signature = new MPInteger[2]{ r, s };
break;
case PublicKeyAlgorithmTag.ElGamalEncrypt: // yep, this really does happen sometimes.
case PublicKeyAlgorithmTag.ElGamalGeneral:
MPInteger p = new MPInteger(bcpgIn);
MPInteger g = new MPInteger(bcpgIn);
MPInteger y = new MPInteger(bcpgIn);
signature = new MPInteger[3]{ p, g, y };
break;
case PublicKeyAlgorithmTag.ECDsa:
case PublicKeyAlgorithmTag.EdDsa:
MPInteger ecR = new MPInteger(bcpgIn);
MPInteger ecS = new MPInteger(bcpgIn);
signature = new MPInteger[2]{ ecR, ecS };
break;
default:
if (keyAlgorithm < PublicKeyAlgorithmTag.Experimental_1 || keyAlgorithm > PublicKeyAlgorithmTag.Experimental_11)
throw new IOException("unknown signature key algorithm: " + keyAlgorithm);
signature = null;
MemoryStream bOut = new MemoryStream();
int ch;
while ((ch = bcpgIn.ReadByte()) >= 0)
{
bOut.WriteByte((byte) ch);
}
signatureEncoding = bOut.ToArray();
break;
}
}
/**
* 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,
PublicKeyAlgorithmTag keyAlgorithm,
HashAlgorithmTag 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,
PublicKeyAlgorithmTag keyAlgorithm,
HashAlgorithmTag 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,
PublicKeyAlgorithmTag keyAlgorithm,
HashAlgorithmTag 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();
}
}
public int Version
{
get { return version; }
}
public int SignatureType
{
get { return signatureType; }
}
/**
* return the keyId
* @return the keyId that created the signature.
*/
public long KeyId
{
get { return keyId; }
}
/**
* return the signature trailer that must be included with the data
* to reconstruct the signature
*
* @return byte[]
*/
public byte[] GetSignatureTrailer()
{
if (version == 3)
{
long time = creationTime / 1000L;
byte[] trailer = new byte[5];
trailer[0] = (byte)signatureType;
trailer[1] = (byte)(time >> 24);
trailer[2] = (byte)(time >> 16);
trailer[3] = (byte)(time >> 8);
trailer[4] = (byte)(time );
return trailer;
}
MemoryStream sOut = new MemoryStream();
sOut.WriteByte((byte)Version);
sOut.WriteByte((byte)SignatureType);
sOut.WriteByte((byte)KeyAlgorithm);
sOut.WriteByte((byte)HashAlgorithm);
// Mark position an reserve two bytes for length
long lengthPosition = sOut.Position;
sOut.WriteByte(0x00);
sOut.WriteByte(0x00);
SignatureSubpacket[] hashed = GetHashedSubPackets();
for (int i = 0; i != hashed.Length; i++)
{
hashed[i].Encode(sOut);
}
ushort dataLength = Convert.ToUInt16(sOut.Position - lengthPosition - 2);
uint hDataLength = Convert.ToUInt32(sOut.Position);
sOut.WriteByte((byte)Version);
sOut.WriteByte(0xff);
sOut.WriteByte((byte)(hDataLength >> 24));
sOut.WriteByte((byte)(hDataLength >> 16));
sOut.WriteByte((byte)(hDataLength >> 8));
sOut.WriteByte((byte)(hDataLength ));
// Reset position and fill in length
sOut.Position = lengthPosition;
sOut.WriteByte((byte)(dataLength >> 8));
sOut.WriteByte((byte)(dataLength ));
return sOut.ToArray();
}
public PublicKeyAlgorithmTag KeyAlgorithm
{
get { return keyAlgorithm; }
}
public HashAlgorithmTag HashAlgorithm
{
get { 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)
{
return (byte[]) signatureEncoding.Clone();
}
MemoryStream bOut = new MemoryStream();
BcpgOutputStream bcOut = new BcpgOutputStream(bOut);
foreach (MPInteger sigObj in signature)
{
try
{
bcOut.WriteObject(sigObj);
}
catch (IOException e)
{
throw new Exception("internal error: " + e);
}
}
return bOut.ToArray();
}
public SignatureSubpacket[] GetHashedSubPackets()
{
return hashedData;
}
public SignatureSubpacket[] GetUnhashedSubPackets()
{
return unhashedData;
}
/// <summary>Return the creation time in milliseconds since 1 Jan., 1970 UTC.</summary>
public long CreationTime
{
get { return creationTime; }
}
public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
using (var pOut = new BcpgOutputStream(bOut))
{
pOut.WriteByte((byte)version);
if (version == 3 || version == 2)
{
byte nextBlockLength = 5;
pOut.Write(nextBlockLength, (byte)signatureType);
pOut.WriteInt((int)(creationTime / 1000L));
pOut.WriteLong(keyId);
pOut.Write((byte)keyAlgorithm, (byte)hashAlgorithm);
}
else if (version == 4)
{
pOut.Write((byte)signatureType, (byte)keyAlgorithm, (byte)hashAlgorithm);
EncodeLengthAndData(pOut, GetEncodedSubpackets(hashedData));
EncodeLengthAndData(pOut, GetEncodedSubpackets(unhashedData));
}
else
{
throw new IOException("unknown version: " + version);
}
pOut.Write(fingerprint);
if (signature != null)
{
pOut.WriteObjects(signature);
}
else
{
pOut.Write(signatureEncoding);
}
}
bcpgOut.WritePacket(PacketTag.Signature, bOut.ToArray(), true);
}
private static void EncodeLengthAndData(
BcpgOutputStream pOut,
byte[] data)
{
pOut.WriteShort((short) data.Length);
pOut.Write(data);
}
private static byte[] GetEncodedSubpackets(
SignatureSubpacket[] ps)
{
MemoryStream sOut = new MemoryStream();
foreach (SignatureSubpacket p in ps)
{
p.Encode(sOut);
}
return sOut.ToArray();
}
private void SetCreationTime()
{
foreach (SignatureSubpacket p in hashedData)
{
if (p is SignatureCreationTime signatureCreationTime)
{
creationTime = DateTimeUtilities.DateTimeToUnixMs(signatureCreationTime.GetTime());
break;
}
}
}
public static SignaturePacket FromByteArray(byte[] data)
{
BcpgInputStream input = BcpgInputStream.Wrap(new MemoryStream(data));
return new SignaturePacket(input);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cb04d6068460cbb4dbaacebe957d550d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,119 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic type for a PGP Signature sub-packet.</remarks>
public class SignatureSubpacket
{
private readonly SignatureSubpacketTag type;
private readonly bool critical;
private readonly bool isLongLength;
internal byte[] data;
protected internal SignatureSubpacket(
SignatureSubpacketTag type,
bool critical,
bool isLongLength,
byte[] data)
{
this.type = type;
this.critical = critical;
this.isLongLength = isLongLength;
this.data = data;
}
public SignatureSubpacketTag SubpacketType
{
get { return type; }
}
public bool IsCritical()
{
return critical;
}
public bool IsLongLength()
{
return isLongLength;
}
/// <summary>Return the generic data making up the packet.</summary>
public byte[] GetData()
{
return (byte[]) data.Clone();
}
public void Encode(
Stream os)
{
int bodyLen = data.Length + 1;
if (isLongLength)
{
os.WriteByte(0xff);
os.WriteByte((byte)(bodyLen >> 24));
os.WriteByte((byte)(bodyLen >> 16));
os.WriteByte((byte)(bodyLen >> 8));
os.WriteByte((byte)bodyLen);
}
else
{
if (bodyLen < 192)
{
os.WriteByte((byte)bodyLen);
}
else if (bodyLen <= 8383)
{
bodyLen -= 192;
os.WriteByte((byte)(((bodyLen >> 8) & 0xff) + 192));
os.WriteByte((byte)bodyLen);
}
else
{
os.WriteByte(0xff);
os.WriteByte((byte)(bodyLen >> 24));
os.WriteByte((byte)(bodyLen >> 16));
os.WriteByte((byte)(bodyLen >> 8));
os.WriteByte((byte)bodyLen);
}
}
if (critical)
{
os.WriteByte((byte)(0x80 | (int) type));
}
else
{
os.WriteByte((byte) type);
}
os.Write(data, 0, data.Length);
}
public override int GetHashCode()
{
return (critical ? 1 : 0) + 7 * (int)type + 49 * Arrays.GetHashCode(data);
}
public override bool Equals(object obj)
{
if (obj == this)
return true;
SignatureSubpacket other = obj as SignatureSubpacket;
if (null == other)
return false;
return this.type == other.type
&& this.critical == other.critical
&& Arrays.AreEqual(this.data, other.data);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 12485b706aefe7f49b22c4d8185ca603
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
* Basic PGP signature sub-packet tag types.
*/
public enum SignatureSubpacketTag
{
CreationTime = 2, // signature creation time
ExpireTime = 3, // signature expiration time
Exportable = 4, // exportable certification
TrustSig = 5, // trust signature
RegExp = 6, // regular expression
Revocable = 7, // revocable
KeyExpireTime = 9, // key expiration time
Placeholder = 10, // placeholder for backward compatibility
PreferredSymmetricAlgorithms = 11, // preferred symmetric algorithms
RevocationKey = 12, // revocation key
IssuerKeyId = 16, // issuer key ID
NotationData = 20, // notation data
PreferredHashAlgorithms = 21, // preferred hash algorithms
PreferredCompressionAlgorithms = 22, // preferred compression algorithms
KeyServerPreferences = 23, // key server preferences
PreferredKeyServer = 24, // preferred key server
PrimaryUserId = 25, // primary user id
PolicyUrl = 26, // policy URL
KeyFlags = 27, // key flags
SignerUserId = 28, // signer's user id
RevocationReason = 29, // reason for revocation
Features = 30, // features
SignatureTarget = 31, // signature target
EmbeddedSignature = 32 // embedded signature
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 53dafaf5eabe775429e939e53176f906
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,139 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg.Sig;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
* reader for signature sub-packets
*/
public class SignatureSubpacketsParser
{
private readonly Stream input;
public SignatureSubpacketsParser(
Stream input)
{
this.input = input;
}
public SignatureSubpacket ReadPacket()
{
int l = input.ReadByte();
if (l < 0)
return null;
int bodyLen = 0;
bool isLongLength = false;
if (l < 192)
{
bodyLen = l;
}
else if (l <= 223)
{
bodyLen = ((l - 192) << 8) + (input.ReadByte()) + 192;
}
else if (l == 255)
{
isLongLength = true;
bodyLen = (input.ReadByte() << 24) | (input.ReadByte() << 16)
| (input.ReadByte() << 8) | input.ReadByte();
}
else
{
throw new IOException("unexpected length header");
}
int tag = input.ReadByte();
if (tag < 0)
throw new EndOfStreamException("unexpected EOF reading signature sub packet");
if (bodyLen <= 0)
throw new EndOfStreamException("out of range data found in 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(input, data);
bool isCritical = ((tag & 0x80) != 0);
SignatureSubpacketTag type = (SignatureSubpacketTag)(tag & 0x7f);
if (bytesRead != data.Length)
{
switch (type)
{
case SignatureSubpacketTag.CreationTime:
data = CheckData(data, 4, bytesRead, "Signature Creation Time");
break;
case SignatureSubpacketTag.IssuerKeyId:
data = CheckData(data, 8, bytesRead, "Issuer");
break;
case SignatureSubpacketTag.KeyExpireTime:
data = CheckData(data, 4, bytesRead, "Signature Key Expiration Time");
break;
case SignatureSubpacketTag.ExpireTime:
data = CheckData(data, 4, bytesRead, "Signature Expiration Time");
break;
default:
throw new EndOfStreamException("truncated subpacket data.");
}
}
switch (type)
{
case SignatureSubpacketTag.CreationTime:
return new SignatureCreationTime(isCritical, isLongLength, data);
case SignatureSubpacketTag.KeyExpireTime:
return new KeyExpirationTime(isCritical, isLongLength, data);
case SignatureSubpacketTag.ExpireTime:
return new SignatureExpirationTime(isCritical, isLongLength, data);
case SignatureSubpacketTag.Revocable:
return new Revocable(isCritical, isLongLength, data);
case SignatureSubpacketTag.Exportable:
return new Exportable(isCritical, isLongLength, data);
case SignatureSubpacketTag.IssuerKeyId:
return new IssuerKeyId(isCritical, isLongLength, data);
case SignatureSubpacketTag.TrustSig:
return new TrustSignature(isCritical, isLongLength, data);
case SignatureSubpacketTag.PreferredCompressionAlgorithms:
case SignatureSubpacketTag.PreferredHashAlgorithms:
case SignatureSubpacketTag.PreferredSymmetricAlgorithms:
return new PreferredAlgorithms(type, isCritical, isLongLength, data);
case SignatureSubpacketTag.KeyFlags:
return new KeyFlags(isCritical, isLongLength, data);
case SignatureSubpacketTag.PrimaryUserId:
return new PrimaryUserId(isCritical, isLongLength, data);
case SignatureSubpacketTag.SignerUserId:
return new SignerUserId(isCritical, isLongLength, data);
case SignatureSubpacketTag.NotationData:
return new NotationData(isCritical, isLongLength, data);
case SignatureSubpacketTag.RevocationReason:
return new RevocationReason(isCritical, isLongLength, data);
case SignatureSubpacketTag.RevocationKey:
return new RevocationKey(isCritical, isLongLength, data);
}
return new SignatureSubpacket(type, isCritical, isLongLength, data);
}
private byte[] CheckData(byte[] data, int expected, int bytesRead, string name)
{
if (bytesRead != expected)
throw new EndOfStreamException("truncated " + name + " subpacket data.");
return Arrays.CopyOfRange(data, 0, expected);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f94273b5bb4519448ab9101989a9972f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <remarks>Basic type for a symmetric key encrypted packet.</remarks>
public class SymmetricEncDataPacket
: InputStreamPacket
{
public SymmetricEncDataPacket(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d668c9021b14934a98a3f736b472714
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
public class SymmetricEncIntegrityPacket
: InputStreamPacket
{
internal readonly int version;
internal SymmetricEncIntegrityPacket(
BcpgInputStream bcpgIn)
: base(bcpgIn)
{
version = bcpgIn.ReadByte();
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d8627069cfc6bc419d3f2d253d4230f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,27 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
* Basic tags for symmetric key algorithms
*/
public enum SymmetricKeyAlgorithmTag
{
Null = 0, // Plaintext or unencrypted data
Idea = 1, // IDEA [IDEA]
TripleDes = 2, // Triple-DES (DES-EDE, as per spec -168 bit key derived from 192)
Cast5 = 3, // Cast5 (128 bit key, as per RFC 2144)
Blowfish = 4, // Blowfish (128 bit key, 16 rounds) [Blowfish]
Safer = 5, // Safer-SK128 (13 rounds) [Safer]
Des = 6, // Reserved for DES/SK
Aes128 = 7, // Reserved for AES with 128-bit key
Aes192 = 8, // Reserved for AES with 192-bit key
Aes256 = 9, // Reserved for AES with 256-bit key
Twofish = 10, // Reserved for Twofish
Camellia128 = 11, // Reserved for AES with 128-bit key
Camellia192 = 12, // Reserved for AES with 192-bit key
Camellia256 = 13 // Reserved for AES with 256-bit key
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63ce06623f4338246b0618b822b1cf2f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,92 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/**
* Basic type for a symmetric encrypted session key packet
*/
public class SymmetricKeyEncSessionPacket
: ContainedPacket
{
private int version;
private SymmetricKeyAlgorithmTag encAlgorithm;
private S2k s2k;
private readonly byte[] secKeyData;
public SymmetricKeyEncSessionPacket(
BcpgInputStream bcpgIn)
{
version = bcpgIn.ReadByte();
encAlgorithm = (SymmetricKeyAlgorithmTag) bcpgIn.ReadByte();
s2k = new S2k(bcpgIn);
secKeyData = bcpgIn.ReadAll();
}
public SymmetricKeyEncSessionPacket(
SymmetricKeyAlgorithmTag encAlgorithm,
S2k s2k,
byte[] secKeyData)
{
this.version = 4;
this.encAlgorithm = encAlgorithm;
this.s2k = s2k;
this.secKeyData = secKeyData;
}
/**
* @return int
*/
public SymmetricKeyAlgorithmTag EncAlgorithm
{
get { return encAlgorithm; }
}
/**
* @return S2k
*/
public S2k S2k
{
get { return s2k; }
}
/**
* @return byte[]
*/
public byte[] GetSecKeyData()
{
return secKeyData;
}
/**
* @return int
*/
public int Version
{
get { return version; }
}
public override void Encode(BcpgOutputStream bcpgOut)
{
MemoryStream bOut = new MemoryStream();
using (var pOut = new BcpgOutputStream(bOut))
{
pOut.Write((byte)version, (byte)encAlgorithm);
pOut.WriteObject(s2k);
if (secKeyData != null && secKeyData.Length > 0)
{
pOut.Write(secKeyData);
}
}
bcpgOut.WritePacket(PacketTag.SymmetricKeyEncryptedSessionKey, bOut.ToArray(), true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 821a5a072ef823e4ba584738d06f922a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
/// <summary>Basic type for a trust packet.</summary>
public class TrustPacket
: ContainedPacket
{
private readonly byte[] levelAndTrustAmount;
public TrustPacket(
BcpgInputStream bcpgIn)
{
MemoryStream bOut = new MemoryStream();
int ch;
while ((ch = bcpgIn.ReadByte()) >= 0)
{
bOut.WriteByte((byte) ch);
}
levelAndTrustAmount = bOut.ToArray();
}
public TrustPacket(
int trustCode)
{
this.levelAndTrustAmount = new byte[]{ (byte) trustCode };
}
public byte[] GetLevelAndTrustAmount()
{
return (byte[]) levelAndTrustAmount.Clone();
}
public override void Encode(
BcpgOutputStream bcpgOut)
{
bcpgOut.WritePacket(PacketTag.Trust, levelAndTrustAmount, true);
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58e56486c7a6faf4685209440e004728
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,34 @@
#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.Runtime.Serialization;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
{
[Serializable]
public class UnsupportedPacketVersionException
: Exception
{
public UnsupportedPacketVersionException()
: base()
{
}
public UnsupportedPacketVersionException(string message)
: base(message)
{
}
public UnsupportedPacketVersionException(string message, Exception innerException)
: base(message, innerException)
{
}
protected UnsupportedPacketVersionException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
#pragma warning restore
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 06b7809f4ba6a494fa1a848f8e38d3f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More