Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed May 10, 2024
2 parents de615c9 + 630575a commit fb3ce6d
Show file tree
Hide file tree
Showing 38 changed files with 3,238 additions and 1,007 deletions.
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;
}
}
}
}
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;
}
}
}
}
Loading

0 comments on commit fb3ce6d

Please sign in to comment.