Skip to content

Commit

Permalink
Merge branch 'master' into netstandard
Browse files Browse the repository at this point in the history
  • Loading branch information
clairernovotny committed Oct 19, 2021
2 parents 3a02c29 + cf7722d commit 0abe968
Show file tree
Hide file tree
Showing 97 changed files with 2,561 additions and 1,334 deletions.
4 changes: 2 additions & 2 deletions crypto/NBuild.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project name="bccrypto-csharp" default="compile-release" basedir=".">

<!-- Source control properties -->
<property name="GITURL" value="bcgit@git.bouncycastle.org:bc-csharp" />
<property name="GITURL" value="ssh://git@gitlab.cryptoworkshop.com:1022/root/bc-csharp" />
<property name="GITCMD" value="C:/Program Files/Git/bin/git.exe" />

<property name="api-debugpath" value="./api/bin/debug" />
Expand All @@ -16,7 +16,7 @@
<property name="dist-path" value="./dist"/>

<!-- Version -->
<property name="version" value="1.8.10"/>
<property name="version" value="1.9.0"/>
<property name="name" value="BouncyCastle.Crypto"/>

<property name="OPTIONAL_STRONG_NAME" value="" />
Expand Down
28 changes: 28 additions & 0 deletions crypto/Readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ <h3><a class="mozTocH3" name="mozTocId685176"></a>Contents:<br/></h3>
<li>
<a href="#mozTocId3413">Notes:</a>
<ol>
<li>
<a href="#mozTocId85325">Release 1.9.0</a>
<li>
<a href="#mozTocId85324">Release 1.8.10</a>
<li>
Expand Down Expand Up @@ -308,6 +310,32 @@ <h3><a class="mozTocH3" name="mozTocId358608"></a>For first time users.</h3>
<hr style="WIDTH: 100%; HEIGHT: 2px">
<h3><a class="mozTocH3" name="mozTocId3413"></a>Notes:</h3>

<h4><a class="mozTocH4" name="mozTocId85325"></a>Release 1.9.0, Sunday October 17, 2021</h4>

<h5>Defects Fixed</h5>
<ul>
<li>Key sizes are now checked strictly in TwofishEngine.</li>
<li>Fixed bzip2 compression of empty contents.</li>
<li>Handle CRL with no NextUpdate properly during CertPath validation.</li>
<li>Skip marker packets when reading various PGP data.</li>
<li>Ignore PGP signatures with invalid version.</li>
</ul>
<h5>Additional Features and Functionality</h5>
<ul>
<li>A new TLS API (Org.BouncyCastle.Tls) now replaces the old one (Org.BouncyCastle.Crypto.Tls), which
should be considered obsolete. The new API includes support for TLS 1.3.</li>
<li>Added support for Format Preserving Encryption.</li>
<li>Added support for ParallelHash and TupleHash.</li>
<li>Added support for the ARIA cipher.</li>
</ul>
<h5>Additional Notes</h5>
<ul>
<li>
See the (cumulative) list of GitHub pull requests that we have accepted at
<a href="https://github.com/bcgit/bc-csharp/pulls?q=is%3Apr+is%3Aclosed">bcgit/bc-csharp</a>.
</li>
</ul>

<h4><a class="mozTocH4" name="mozTocId85324"></a>Release 1.8.10, Tuesday February 16, 2021</h4>

<h5>Defects Fixed</h5>
Expand Down
45 changes: 35 additions & 10 deletions crypto/crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "src\bcpg\UnsupportedPacketVersionException.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "src\bcpg\UserAttributePacket.cs"
SubType = "Code"
Expand Down Expand Up @@ -14588,11 +14593,6 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\crypto\tls\test\MockPskTls13Client.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\crypto\tls\test\MockPskTlsClient.cs"
SubType = "Code"
Expand Down Expand Up @@ -14633,11 +14633,6 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\crypto\tls\test\PskTls13ClientTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\crypto\tls\test\PskTlsClientTest.cs"
SubType = "Code"
Expand Down Expand Up @@ -14983,6 +14978,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\openpgp\test\PgpSignatureInvalidVersionIgnoredTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\openpgp\test\PGPSignatureTest.cs"
SubType = "Code"
Expand Down Expand Up @@ -15428,6 +15428,16 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\MockPskTls13Client.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\MockPskTls13Server.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\MockPskTlsClient.cs"
SubType = "Code"
Expand Down Expand Up @@ -15473,6 +15483,16 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\PskTls13ClientTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\PskTls13ServerTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\PskTlsClientTest.cs"
SubType = "Code"
Expand All @@ -15483,6 +15503,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\Tls13PskProtocolTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\tls\test\TlsClientTest.cs"
SubType = "Code"
Expand Down
142 changes: 72 additions & 70 deletions crypto/src/asn1/ASN1StreamParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ public class Asn1StreamParser

private readonly byte[][] tmpBuffers;

public Asn1StreamParser(
Stream inStream)
: this(inStream, Asn1InputStream.FindLimit(inStream))
public Asn1StreamParser(Stream input)
: this(input, Asn1InputStream.FindLimit(input))
{
}

public Asn1StreamParser(
Stream inStream,
int limit)
{
if (!inStream.CanRead)
throw new ArgumentException("Expected stream to be readable", "inStream");

this._in = inStream;
this._limit = limit;
this.tmpBuffers = new byte[16][];
public Asn1StreamParser(byte[] encoding)
: this(new MemoryStream(encoding, false), encoding.Length)
{
}

public Asn1StreamParser(
byte[] encoding)
: this(new MemoryStream(encoding, false), encoding.Length)
public Asn1StreamParser(Stream input, int limit)
: this(input, limit, new byte[16][])
{
}
}

internal Asn1StreamParser(Stream input, int limit, byte[][] tmpBuffers)
{
if (!input.CanRead)
throw new ArgumentException("Expected stream to be readable", "input");

this._in = input;
this._limit = limit;
this.tmpBuffers = tmpBuffers;
}

internal IAsn1Convertible ReadIndef(int tagValue)
internal IAsn1Convertible ReadIndef(int tagValue)
{
// Note: INDEF => CONSTRUCTED

Expand Down Expand Up @@ -142,71 +143,72 @@ public virtual IAsn1Convertible ReadObject()
if (!isConstructed)
throw new IOException("indefinite-length primitive encoding encountered");

IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in, _limit);
Asn1StreamParser sp = new Asn1StreamParser(indIn, _limit);
IndefiniteLengthInputStream indIn = new IndefiniteLengthInputStream(_in, _limit);
Asn1StreamParser sp = new Asn1StreamParser(indIn, _limit, tmpBuffers);

if ((tag & Asn1Tags.Application) != 0)
{
return new BerApplicationSpecificParser(tagNo, sp);
}
int tagClass = tag & Asn1Tags.Private;
if (0 != tagClass)
{
if ((tag & Asn1Tags.Application) != 0)
return new BerApplicationSpecificParser(tagNo, sp);

if ((tag & Asn1Tags.Tagged) != 0)
{
return new BerTaggedObjectParser(true, tagNo, sp);
}
return new BerTaggedObjectParser(true, tagNo, sp);
}

return sp.ReadIndef(tagNo);
return sp.ReadIndef(tagNo);
}
else
{
DefiniteLengthInputStream defIn = new DefiniteLengthInputStream(_in, length, _limit);

if ((tag & Asn1Tags.Application) != 0)
{
return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());
}

if ((tag & Asn1Tags.Tagged) != 0)
{
return new BerTaggedObjectParser(isConstructed, tagNo, new Asn1StreamParser(defIn));
}
int tagClass = tag & Asn1Tags.Private;
if (0 != tagClass)
{
if ((tag & Asn1Tags.Application) != 0)
return new DerApplicationSpecific(isConstructed, tagNo, defIn.ToArray());

return new BerTaggedObjectParser(isConstructed, tagNo,
new Asn1StreamParser(defIn, defIn.Remaining, tmpBuffers));
}

if (!isConstructed)
{
// Some primitive encodings can be handled by parsers too...
switch (tagNo)
{
case Asn1Tags.OctetString:
return new DerOctetStringParser(defIn);
}

if (isConstructed)
{
// TODO There are other tags that may be constructed (e.g. BitString)
switch (tagNo)
{
case Asn1Tags.OctetString:
//
// yes, people actually do this...
//
return new BerOctetStringParser(new Asn1StreamParser(defIn));
case Asn1Tags.Sequence:
return new DerSequenceParser(new Asn1StreamParser(defIn));
case Asn1Tags.Set:
return new DerSetParser(new Asn1StreamParser(defIn));
case Asn1Tags.External:
return new DerExternalParser(new Asn1StreamParser(defIn));
default:
throw new IOException("unknown tag " + tagNo + " encountered");
try
{
return Asn1InputStream.CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
}
}
catch (ArgumentException e)
{
throw new Asn1Exception("corrupted stream detected", e);
}
}

// Some primitive encodings can be handled by parsers too...
switch (tagNo)
{
case Asn1Tags.OctetString:
return new DerOctetStringParser(defIn);
}
Asn1StreamParser sp = new Asn1StreamParser(defIn, defIn.Remaining, tmpBuffers);

try
{
return Asn1InputStream.CreatePrimitiveDerObject(tagNo, defIn, tmpBuffers);
}
catch (ArgumentException e)
// TODO There are other tags that may be constructed (e.g. BitString)
switch (tagNo)
{
throw new Asn1Exception("corrupted stream detected", e);
}
case Asn1Tags.OctetString:
//
// yes, people actually do this...
//
return new BerOctetStringParser(sp);
case Asn1Tags.Sequence:
return new DerSequenceParser(sp);
case Asn1Tags.Set:
return new DerSetParser(sp);
case Asn1Tags.External:
return new DerExternalParser(sp);
default:
throw new IOException("unknown tag " + tagNo + " encountered");
}
}
}

Expand Down
49 changes: 20 additions & 29 deletions crypto/src/asn1/Asn1Encodable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,36 @@ public abstract class Asn1Encodable
public const string Der = "DER";
public const string Ber = "BER";

public byte[] GetEncoded()
public virtual void EncodeTo(Stream output)
{
MemoryStream bOut = new MemoryStream();
Asn1OutputStream aOut = new Asn1OutputStream(bOut);

aOut.WriteObject(this);

return bOut.ToArray();
ToAsn1Object().EncodeTo(output);
}

public byte[] GetEncoded(
string encoding)
{
if (encoding.Equals(Der))
{
MemoryStream bOut = new MemoryStream();
DerOutputStream dOut = new DerOutputStream(bOut);

if (this is Asn1Set)
{
dOut.WriteObject(new DerSet((this as Asn1Set).elements));
}
else
{
dOut.WriteObject(this);
}
public virtual void EncodeTo(Stream output, string encoding)
{
ToAsn1Object().EncodeTo(output, encoding);
}

return bOut.ToArray();
}
public byte[] GetEncoded()
{
MemoryStream bOut = new MemoryStream();
EncodeTo(bOut);
return bOut.ToArray();
}

return GetEncoded();
}
public byte[] GetEncoded(string encoding)
{
MemoryStream bOut = new MemoryStream();
EncodeTo(bOut, encoding);
return bOut.ToArray();
}

/**
/**
* Return the DER encoding of the object, null if the DER encoding can not be made.
*
* @return a DER byte array, null otherwise.
*/
public byte[] GetDerEncoded()
public byte[] GetDerEncoded()
{
try
{
Expand Down
Loading

0 comments on commit 0abe968

Please sign in to comment.