forked from bcgit/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into netstandard
- Loading branch information
Showing
73 changed files
with
4,964 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using Org.BouncyCastle.Crmf; | ||
|
||
namespace Org.BouncyCastle.Asn1.Crmf | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
| ||
using Org.BouncyCastle.Cms; | ||
using Org.BouncyCastle.Asn1.Cmp; | ||
|
||
|
||
namespace Org.BouncyCastle.Cmp | ||
{ | ||
public class CertificateConfirmationContent | ||
{ | ||
private DefaultDigestAlgorithmIdentifierFinder digestAlgFinder; | ||
private CertConfirmContent content; | ||
|
||
|
||
public CertificateConfirmationContent(CertConfirmContent content) | ||
{ | ||
this.content = content; | ||
} | ||
|
||
public CertificateConfirmationContent(CertConfirmContent content, | ||
DefaultDigestAlgorithmIdentifierFinder digestAlgFinder) | ||
{ | ||
this.content = content; | ||
this.digestAlgFinder = digestAlgFinder; | ||
} | ||
|
||
public CertConfirmContent ToAsn1Structure() | ||
{ | ||
return content; | ||
} | ||
|
||
public CertificateStatus[] GetStatusMessages() | ||
{ | ||
CertStatus[] statusArray = content.ToCertStatusArray(); | ||
CertificateStatus[] ret = new CertificateStatus[statusArray.Length]; | ||
for (int i = 0; i != ret.Length; i++) | ||
{ | ||
ret[i] = new CertificateStatus(digestAlgFinder, statusArray[i]); | ||
} | ||
|
||
return ret; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System.Collections; | ||
using Org.BouncyCastle.Asn1; | ||
using Org.BouncyCastle.Asn1.Cmp; | ||
using Org.BouncyCastle.Asn1.X509; | ||
using Org.BouncyCastle.Cms; | ||
using Org.BouncyCastle.Crypto.IO; | ||
using Org.BouncyCastle.Math; | ||
using Org.BouncyCastle.Security; | ||
using Org.BouncyCastle.X509; | ||
|
||
namespace Org.BouncyCastle.Cmp | ||
{ | ||
public class CertificateConfirmationContentBuilder | ||
{ | ||
DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder(); | ||
private DefaultDigestAlgorithmIdentifierFinder digestAlgFinder; | ||
private ArrayList acceptedCerts = new ArrayList(); | ||
private ArrayList acceptedReqIds = new ArrayList(); | ||
|
||
public CertificateConfirmationContentBuilder() : this(new DefaultDigestAlgorithmIdentifierFinder()) | ||
{ | ||
|
||
} | ||
|
||
public CertificateConfirmationContentBuilder(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder) | ||
{ | ||
this.digestAlgFinder = digestAlgFinder; | ||
} | ||
|
||
public CertificateConfirmationContentBuilder AddAcceptedCertificate(X509Certificate certHolder, | ||
BigInteger certReqId) | ||
{ | ||
acceptedCerts.Add(certHolder); | ||
acceptedReqIds.Add(certReqId); | ||
return this; | ||
} | ||
|
||
public CertificateConfirmationContent Build() | ||
{ | ||
Asn1EncodableVector v = new Asn1EncodableVector(); | ||
for (int i = 0; i != acceptedCerts.Count; i++) | ||
{ | ||
X509Certificate cert = (X509Certificate) acceptedCerts[i]; | ||
BigInteger reqId = (BigInteger) acceptedReqIds[i]; | ||
|
||
|
||
|
||
AlgorithmIdentifier algorithmIdentifier = sigAlgFinder.Find(cert.SigAlgName); | ||
|
||
AlgorithmIdentifier digAlg = digestAlgFinder.find(algorithmIdentifier); | ||
if (digAlg == null) | ||
{ | ||
throw new CmpException("cannot find algorithm for digest from signature"); | ||
} | ||
|
||
DigestSink sink = new DigestSink(DigestUtilities.GetDigest(digAlg.Algorithm)); | ||
|
||
sink.Write(cert.GetEncoded()); | ||
|
||
byte[] dig = new byte[sink.Digest.GetDigestSize()]; | ||
sink.Digest.DoFinal(dig, 0); | ||
|
||
v.Add(new CertStatus(dig,reqId)); | ||
} | ||
|
||
return new CertificateConfirmationContent(CertConfirmContent.GetInstance(new DerSequence(v)), | ||
digestAlgFinder); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Org.BouncyCastle.Asn1.Cmp; | ||
using Org.BouncyCastle.Asn1.X509; | ||
using Org.BouncyCastle.Cms; | ||
using Org.BouncyCastle.Crypto.IO; | ||
using Org.BouncyCastle.Math; | ||
using Org.BouncyCastle.Security; | ||
using Org.BouncyCastle.Utilities; | ||
using Org.BouncyCastle.X509; | ||
|
||
namespace Org.BouncyCastle.Cmp | ||
{ | ||
public class CertificateStatus | ||
{ | ||
private DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder(); | ||
private DefaultDigestAlgorithmIdentifierFinder digestAlgFinder; | ||
private CertStatus certStatus; | ||
|
||
public CertificateStatus(DefaultDigestAlgorithmIdentifierFinder digestAlgFinder, CertStatus certStatus) | ||
{ | ||
this.digestAlgFinder = digestAlgFinder; | ||
this.certStatus = certStatus; | ||
} | ||
|
||
public PkiStatusInfo PkiStatusInfo | ||
{ | ||
get { return certStatus.StatusInfo; } | ||
} | ||
|
||
public BigInteger CertRequestId | ||
{ | ||
get { return certStatus.CertReqID.Value; } | ||
} | ||
|
||
public bool IsVerified(X509Certificate cert) | ||
{ | ||
|
||
AlgorithmIdentifier digAlg = digestAlgFinder.find( sigAlgFinder.Find(cert.SigAlgName)); | ||
if (digAlg == null) | ||
{ | ||
throw new CmpException("cannot find algorithm for digest from signature "+cert.SigAlgName); | ||
} | ||
|
||
DigestSink digestSink = new DigestSink(DigestUtilities.GetDigest(digAlg.Algorithm)); | ||
|
||
digestSink.Write(cert.GetEncoded()); | ||
|
||
byte[] digest = new byte[digestSink.Digest.GetDigestSize()]; | ||
digestSink.Digest.DoFinal(digest, 0); | ||
return Arrays.ConstantTimeAreEqual(certStatus.CertHash.GetOctets(), digest); | ||
} | ||
} | ||
} |
Oops, something went wrong.