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 Feb 19, 2021
2 parents e9d7b87 + cc7fbb6 commit 5928123
Show file tree
Hide file tree
Showing 52 changed files with 2,063 additions and 736 deletions.
2 changes: 1 addition & 1 deletion crypto/License.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h2>The Bouncy Castle Cryptographic C#&reg; API</h2>
<h3>License:</h3>
The Bouncy Castle License<br>
Copyright (c) 2000-2020 The Legion of the Bouncy Castle Inc.
Copyright (c) 2000-2021 The Legion of the Bouncy Castle Inc.
(https://www.bouncycastle.org)<br>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), to deal in the
Expand Down
2 changes: 1 addition & 1 deletion crypto/NBuild.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<property name="dist-path" value="./dist"/>

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

<property name="OPTIONAL_STRONG_NAME" value="" />
Expand Down
19 changes: 18 additions & 1 deletion 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="#mozTocId85324">Release 1.8.10</a>
<li>
<a href="#mozTocId85323">Release 1.8.9</a>
<li>
Expand Down Expand Up @@ -306,6 +308,21 @@ <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="mozTocId85324"></a>Release 1.8.10, Tuesday February 16, 2021</h4>

<h5>Defects Fixed</h5>
<ul>
<li>Fixed CMS signature verification for RSASSA-PSS when signed attributes are not present.</li>
<li>The output size for SHAKE128 (SHAKE256) when used as a fixed-length digest is now 256 (512) bits (also applies to cSHAKE).</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="mozTocId85323"></a>Release 1.8.9, Tuesday December 8, 2020</h4>

<h5>Defects Fixed</h5>
Expand All @@ -314,7 +331,7 @@ <h5>Defects Fixed</h5>
</ul>
<h5>Additional Features and Functionality</h5>
<ul>
<li>Added CSHAKE digest and KMAC.</li>
<li>Added cSHAKE digest and KMAC.</li>
<li>Added support for PKCS#5 Scheme 2 to Pkcs12Store.</li>
<li>Improved performance for GCM.</li>
</ul>
Expand Down
5 changes: 5 additions & 0 deletions crypto/crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13761,6 +13761,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\util\test\TestRandomData.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "test\src\util\test\UncloseableStream.cs"
SubType = "Code"
Expand Down
6 changes: 6 additions & 0 deletions crypto/src/asn1/DerEnumerated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ public BigInteger Value
get { return new BigInteger(bytes); }
}

public bool HasValue(int x)
{
return (bytes.Length - start) <= 4
&& DerInteger.IntValue(bytes, start, DerInteger.SignExtSigned) == x;
}

public bool HasValue(BigInteger x)
{
return null != x
Expand Down
12 changes: 12 additions & 0 deletions crypto/src/asn1/DerInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ public BigInteger Value
get { return new BigInteger(bytes); }
}

public bool HasValue(int x)
{
return (bytes.Length - start) <= 4
&& IntValue(bytes, start, SignExtSigned) == x;
}

public bool HasValue(long x)
{
return (bytes.Length - start) <= 8
&& LongValue(bytes, start, SignExtSigned) == x;
}

public bool HasValue(BigInteger x)
{
return null != x
Expand Down
23 changes: 17 additions & 6 deletions crypto/src/asn1/cms/AuthEnvelopedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ public AuthEnvelopedData(

this.originatorInfo = originatorInfo;

// TODO
// "There MUST be at least one element in the collection."
this.recipientInfos = recipientInfos;
if (this.recipientInfos.Count < 1)
throw new ArgumentException("AuthEnvelopedData requires at least 1 RecipientInfo");

this.authEncryptedContentInfo = authEncryptedContentInfo;

// TODO
// "The authAttrs MUST be present if the content type carried in
// EncryptedContentInfo is not id-data."
this.authAttrs = authAttrs;
if (!authEncryptedContentInfo.ContentType.Equals(CmsObjectIdentifiers.Data))
{
if (authAttrs == null || authAttrs.Count < 1)
throw new ArgumentException("authAttrs must be present with non-data content");
}

this.mac = mac;

Expand All @@ -49,10 +54,11 @@ private AuthEnvelopedData(
{
int index = 0;

// TODO
// "It MUST be set to 0."
Asn1Object tmp = seq[index++].ToAsn1Object();
version = (DerInteger)tmp;
version = DerInteger.GetInstance(tmp);
if (!version.HasValue(0))
throw new ArgumentException("AuthEnvelopedData version number must be 0");

tmp = seq[index++].ToAsn1Object();
if (tmp is Asn1TaggedObject)
Expand All @@ -61,9 +67,10 @@ private AuthEnvelopedData(
tmp = seq[index++].ToAsn1Object();
}

// TODO
// "There MUST be at least one element in the collection."
recipientInfos = Asn1Set.GetInstance(tmp);
if (recipientInfos.Count < 1)
throw new ArgumentException("AuthEnvelopedData requires at least 1 RecipientInfo");

tmp = seq[index++].ToAsn1Object();
authEncryptedContentInfo = EncryptedContentInfo.GetInstance(tmp);
Expand All @@ -76,9 +83,13 @@ private AuthEnvelopedData(
}
else
{
// TODO
// "The authAttrs MUST be present if the content type carried in
// EncryptedContentInfo is not id-data."
if (!authEncryptedContentInfo.ContentType.Equals(CmsObjectIdentifiers.Data))
{
if (authAttrs == null || authAttrs.Count < 1)
throw new ArgumentException("authAttrs must be present with non-data content");
}
}

mac = Asn1OctetString.GetInstance(tmp);
Expand Down
10 changes: 7 additions & 3 deletions crypto/src/asn1/cms/AuthEnvelopedDataParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public class AuthEnvelopedDataParser
private DerInteger version;
private IAsn1Convertible nextObject;
private bool originatorInfoCalled;
private EncryptedContentInfoParser authEncryptedContentInfoParser;

public AuthEnvelopedDataParser(
Asn1SequenceParser seq)
{
this.seq = seq;

// TODO
// "It MUST be set to 0."
this.version = (DerInteger)seq.ReadObject();
if (!version.HasValue(0))
throw new Asn1ParsingException("AuthEnvelopedData version number must be 0");
}

public DerInteger Version
Expand Down Expand Up @@ -85,7 +87,8 @@ public EncryptedContentInfoParser GetAuthEncryptedContentInfo()
{
Asn1SequenceParser o = (Asn1SequenceParser) nextObject;
nextObject = null;
return new EncryptedContentInfoParser(o);
authEncryptedContentInfoParser = new EncryptedContentInfoParser(o);
return authEncryptedContentInfoParser;
}

return null;
Expand All @@ -105,9 +108,10 @@ public Asn1SetParser GetAuthAttrs()
return (Asn1SetParser)((Asn1TaggedObjectParser)o).GetObjectParser(Asn1Tags.Set, false);
}

// TODO
// "The authAttrs MUST be present if the content type carried in
// EncryptedContentInfo is not id-data."
if (!authEncryptedContentInfoParser.ContentType.Equals(CmsObjectIdentifiers.Data))
throw new Asn1ParsingException("authAttrs must be present with non-data content");

return null;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/asn1/cms/EnvelopedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static int CalculateVersion(OriginatorInfo originatorInfo, Asn1Set recipi
{
RecipientInfo ri = RecipientInfo.GetInstance(o);

if (ri.Version.IntValueExact != 0)
if (!ri.Version.HasValue(0))
{
return 2;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/asn1/cms/SignedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private bool CheckForVersion3(
{
SignerInfo s = SignerInfo.GetInstance(obj);

if (s.Version.IntValueExact == 3)
if (s.Version.HasValue(3))
{
return true;
}
Expand Down
3 changes: 1 addition & 2 deletions crypto/src/asn1/icao/LDSSecurityObject.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Math;

Expand Down Expand Up @@ -62,7 +61,7 @@ private LdsSecurityObject(
e.MoveNext();
Asn1Sequence datagroupHashSeq = Asn1Sequence.GetInstance(e.Current);

if (version.Value.Equals(BigInteger.One))
if (version.HasValue(1))
{
e.MoveNext();
versionInfo = LdsVersionInfo.GetInstance(e.Current);
Expand Down
6 changes: 2 additions & 4 deletions crypto/src/asn1/pkcs/EncryptedData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ private EncryptedData(
if (seq.Count != 2)
throw new ArgumentException("Wrong number of elements in sequence", "seq");

int version = ((DerInteger)seq[0]).IntValueExact;
if (version != 0)
{
DerInteger version = (DerInteger)seq[0];
if (!version.HasValue(0))
throw new ArgumentException("sequence not version 0");
}

this.data = (Asn1Sequence) seq[1];
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/asn1/pkcs/Pfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Pfx(
Asn1Sequence seq)
{
DerInteger version = DerInteger.GetInstance(seq[0]);
if (version.IntValueExact != 3)
if (!version.HasValue(3))
throw new ArgumentException("wrong version for PFX PDU");

this.contentInfo = ContentInfo.GetInstance(seq[1]);
Expand Down
40 changes: 29 additions & 11 deletions crypto/src/asn1/x509/AttributeCertificateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,31 @@ public static AttributeCertificateInfo GetInstance(
private AttributeCertificateInfo(
Asn1Sequence seq)
{
if (seq.Count < 7 || seq.Count > 9)
if (seq.Count < 6 || seq.Count > 9)
{
throw new ArgumentException("Bad sequence size: " + seq.Count);
}

this.version = DerInteger.GetInstance(seq[0]);
this.holder = Holder.GetInstance(seq[1]);
this.issuer = AttCertIssuer.GetInstance(seq[2]);
this.signature = AlgorithmIdentifier.GetInstance(seq[3]);
this.serialNumber = DerInteger.GetInstance(seq[4]);
this.attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[5]);
this.attributes = Asn1Sequence.GetInstance(seq[6]);
int start;
if (seq[0] is DerInteger) // in version 1 certs version is DEFAULT v1(0)
{
this.version = DerInteger.GetInstance(seq[0]);
start = 1;
}
else
{
this.version = new DerInteger(0);
start = 0;
}

this.holder = Holder.GetInstance(seq[start]);
this.issuer = AttCertIssuer.GetInstance(seq[start + 1]);
this.signature = AlgorithmIdentifier.GetInstance(seq[start + 2]);
this.serialNumber = DerInteger.GetInstance(seq[start + 3]);
this.attrCertValidityPeriod = AttCertValidityPeriod.GetInstance(seq[start + 4]);
this.attributes = Asn1Sequence.GetInstance(seq[start + 5]);

for (int i = 7; i < seq.Count; i++)
for (int i = start + 6; i < seq.Count; i++)
{
Asn1Encodable obj = (Asn1Encodable) seq[i];

Expand Down Expand Up @@ -136,9 +147,16 @@ public X509Extensions Extensions
*/
public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(version, holder, issuer, signature, serialNumber,
attrCertValidityPeriod, attributes);
Asn1EncodableVector v = new Asn1EncodableVector(9);

if (!version.HasValue(0))
{
v.Add(version);
}

v.Add(holder, issuer, signature, serialNumber, attrCertValidityPeriod, attributes);
v.AddOptional(issuerUniqueID, extensions);

return new DerSequence(v);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/asn1/x509/GeneralSubtree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public override Asn1Object ToAsn1Object()
{
Asn1EncodableVector v = new Asn1EncodableVector(baseName);

if (minimum != null && minimum.Value.SignValue != 0)
if (minimum != null && !minimum.HasValue(0))
{
v.Add(new DerTaggedObject(false, 0, minimum));
}
Expand Down
14 changes: 7 additions & 7 deletions crypto/src/asn1/x509/Holder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace Org.BouncyCastle.Asn1.X509
*
* <pre>
* subject CHOICE {
* baseCertificateID [0] IssuerSerial,
* baseCertificateID [0] EXPLICIT IssuerSerial,
* -- associated with a Public Key Certificate
* subjectName [1] GeneralNames },
* subjectName [1] EXPLICIT GeneralNames },
* -- associated with a name
* </pre>
* </p>
Expand Down Expand Up @@ -74,10 +74,10 @@ public Holder(
switch (tagObj.TagNo)
{
case 0:
baseCertificateID = IssuerSerial.GetInstance(tagObj, false);
baseCertificateID = IssuerSerial.GetInstance(tagObj, true);
break;
case 1:
entityName = GeneralNames.GetInstance(tagObj, false);
entityName = GeneralNames.GetInstance(tagObj, true);
break;
default:
throw new ArgumentException("unknown tag in Holder");
Expand Down Expand Up @@ -228,7 +228,7 @@ public override Asn1Object ToAsn1Object()
{
if (version == 1)
{
Asn1EncodableVector v = new Asn1EncodableVector();
Asn1EncodableVector v = new Asn1EncodableVector(3);
v.AddOptionalTagged(false, 0, baseCertificateID);
v.AddOptionalTagged(false, 1, entityName);
v.AddOptionalTagged(false, 2, objectDigestInfo);
Expand All @@ -237,10 +237,10 @@ public override Asn1Object ToAsn1Object()

if (entityName != null)
{
return new DerTaggedObject(false, 1, entityName);
return new DerTaggedObject(true, 1, entityName);
}

return new DerTaggedObject(false, 0, baseCertificateID);
return new DerTaggedObject(true, 0, baseCertificateID);
}
}
}
Loading

0 comments on commit 5928123

Please sign in to comment.