forked from pipeline-foundation/itext7-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into devsecops
- Loading branch information
Showing
38 changed files
with
3,238 additions
and
1,007 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
itext.tests/itext.sign.tests/itext/signatures/testutils/client/TestCrlClientWrapper.cs
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,73 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using iText.Commons.Bouncycastle.Cert; | ||
using iText.Signatures; | ||
|
||
namespace iText.Signatures.Testutils.Client { | ||
public class TestCrlClientWrapper : ICrlClient { | ||
private readonly ICrlClient wrappedClient; | ||
|
||
private readonly IList<TestCrlClientWrapper.CrlClientCall> calls = new List<TestCrlClientWrapper.CrlClientCall | ||
>(); | ||
|
||
public TestCrlClientWrapper(ICrlClient wrappedClient) { | ||
this.wrappedClient = wrappedClient; | ||
} | ||
|
||
public virtual ICollection<byte[]> GetEncoded(IX509Certificate checkCert, String url) { | ||
ICollection<byte[]> crlBytesCollection = wrappedClient.GetEncoded(checkCert, url); | ||
IList<IX509Crl> crlResponses = new List<IX509Crl>(); | ||
foreach (byte[] crlBytes in crlBytesCollection) { | ||
try { | ||
crlResponses.Add((IX509Crl)CertificateUtil.ParseCrlFromStream(new MemoryStream(crlBytes))); | ||
} | ||
catch (Exception e) { | ||
throw new Exception("Deserializing CRL response failed", e); | ||
} | ||
} | ||
calls.Add(new TestCrlClientWrapper.CrlClientCall(checkCert, url, crlResponses)); | ||
return crlBytesCollection; | ||
} | ||
|
||
public virtual IList<TestCrlClientWrapper.CrlClientCall> GetCalls() { | ||
return calls; | ||
} | ||
|
||
public class CrlClientCall { | ||
public readonly IX509Certificate checkCert; | ||
|
||
public readonly String url; | ||
|
||
public readonly IList<IX509Crl> responses; | ||
|
||
public CrlClientCall(IX509Certificate checkCert, String url, IList<IX509Crl> responses) { | ||
this.checkCert = checkCert; | ||
this.url = url; | ||
this.responses = responses; | ||
} | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
itext.tests/itext.sign.tests/itext/signatures/testutils/client/TestOcspClientWrapper.cs
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,80 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using iText.Bouncycastleconnector; | ||
using iText.Commons.Bouncycastle; | ||
using iText.Commons.Bouncycastle.Asn1.Ocsp; | ||
using iText.Commons.Bouncycastle.Cert; | ||
using iText.Signatures; | ||
|
||
namespace iText.Signatures.Testutils.Client { | ||
public class TestOcspClientWrapper : IOcspClient { | ||
private static readonly IBouncyCastleFactory BOUNCY_CASTLE_FACTORY = BouncyCastleFactoryCreator.GetFactory | ||
(); | ||
|
||
private readonly IList<TestOcspClientWrapper.OcspClientCall> calls = new List<TestOcspClientWrapper.OcspClientCall | ||
>(); | ||
|
||
private readonly IOcspClient wrappedClient; | ||
|
||
public TestOcspClientWrapper(IOcspClient wrappedClient) { | ||
this.wrappedClient = wrappedClient; | ||
} | ||
|
||
public virtual byte[] GetEncoded(IX509Certificate checkCert, IX509Certificate issuerCert, String url) { | ||
byte[] response = wrappedClient.GetEncoded(checkCert, issuerCert, url); | ||
try { | ||
IBasicOcspResponse basicOCSPResp = BOUNCY_CASTLE_FACTORY.CreateBasicOCSPResponse(BOUNCY_CASTLE_FACTORY.CreateASN1Primitive | ||
(response)); | ||
calls.Add(new TestOcspClientWrapper.OcspClientCall(checkCert, issuerCert, url, basicOCSPResp)); | ||
} | ||
catch (System.IO.IOException e) { | ||
throw new Exception("deserializing ocsp response failed", e); | ||
} | ||
return response; | ||
} | ||
|
||
public virtual IList<TestOcspClientWrapper.OcspClientCall> GetCalls() { | ||
return calls; | ||
} | ||
|
||
public class OcspClientCall { | ||
public readonly IX509Certificate checkCert; | ||
|
||
public readonly IX509Certificate issuerCert; | ||
|
||
public readonly String url; | ||
|
||
public readonly IBasicOcspResponse response; | ||
|
||
public OcspClientCall(IX509Certificate checkCert, IX509Certificate issuerCert, String url, IBasicOcspResponse | ||
response) { | ||
this.checkCert = checkCert; | ||
this.issuerCert = issuerCert; | ||
this.url = url; | ||
this.response = response; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.