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
69 changed files
with
933 additions
and
1,449 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
312 changes: 312 additions & 0 deletions
312
itext.tests/itext.pdfua.tests/itext/pdfua/PdfUASignerTest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
itext.tests/itext.pdfua.tests/itext/pdfua/PemFileHelper.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 System.IO; | ||
using System.Linq; | ||
using iText.Bouncycastleconnector; | ||
using iText.Commons.Bouncycastle; | ||
using iText.Commons.Bouncycastle.Cert; | ||
using iText.Commons.Bouncycastle.Crypto; | ||
using iText.Commons.Bouncycastle.Openssl; | ||
|
||
namespace iText.Pdfua { | ||
public sealed class PemFileHelper { | ||
private static readonly IBouncyCastleFactory FACTORY = BouncyCastleFactoryCreator.GetFactory(); | ||
|
||
private PemFileHelper() { | ||
// Empty constructor. | ||
} | ||
|
||
public static IX509Certificate[] ReadFirstChain(String pemFileName) { | ||
return ReadCertificates(pemFileName).ToArray(); | ||
} | ||
|
||
public static IPrivateKey ReadFirstKey(String pemFileName, char[] keyPass) { | ||
return ReadPrivateKey(pemFileName, keyPass); | ||
} | ||
|
||
public static List<IX509Certificate> InitStore(String pemFileName) { | ||
IX509Certificate[] chain = ReadFirstChain(pemFileName); | ||
return chain.Length > 0 ? new List<IX509Certificate> { chain[0] } : chain.ToList(); | ||
} | ||
|
||
private static IList<IX509Certificate> ReadCertificates(String pemFileName) { | ||
using (TextReader file = new StreamReader(pemFileName)) { | ||
IPemReader parser = FACTORY.CreatePEMParser(file, null); | ||
Object readObject = parser.ReadObject(); | ||
IList<IX509Certificate> certificates = new List<IX509Certificate>(); | ||
while (readObject != null) { | ||
if (readObject is IX509Certificate) { | ||
certificates.Add((IX509Certificate)readObject); | ||
} | ||
readObject = parser.ReadObject(); | ||
} | ||
return certificates; | ||
} | ||
} | ||
|
||
private static IPrivateKey ReadPrivateKey(String pemFileName, char[] keyPass) { | ||
using (TextReader file = new StreamReader(pemFileName)) { | ||
IPemReader parser = FACTORY.CreatePEMParser(file, keyPass); | ||
Object readObject = parser.ReadObject(); | ||
while (!(readObject is IPrivateKey) && readObject != null) { | ||
readObject = parser.ReadObject(); | ||
} | ||
return (IPrivateKey)readObject; | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
itext.tests/itext.pdfua.tests/resources/itext/pdfua/certificates/sign.pem
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,55 @@ | ||
-----BEGIN EN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ti6U9RZbgRBq9WeEbVTOdHZEn9QN8wVxpVz2H | ||
csEocPezL80gI8rdVRlLO+igI7HqUZZTZwv25s5rQFj9fOo9/35gR6GXcYdSfezn | ||
W4j9Q9Cb7S042hrKC2Qkhaoz+m68Ic9eNEGTiHOYZ5aLkHX4K38Bqxq7+rgi6eao | ||
lao6UpnLOurZF5Fm+LEqsfFx+zbIHGJFIb22Y6zy01c9pKiAi77TJxEVC6WCE0dS | ||
j1ywvdT1i1oZzDYBWnqJ0fczddbsc1/5gcvsj4sCFuRhP1KBpsTO3h4cG8TS/vKw | ||
0rhljSsLbYnlKsguneNg4bb7tw2n5rCxGSkXaLgrfpexoxh5rHIr9Bcd9uTBhojE | ||
xykqIG3LevcAn3+hAdEdvcwF0Ck/v4r/xXD3+pGKHbDR/076KKjWe6uR/Il3pegi | ||
6QU95NNyWDNOsolv8fogsJzdjhYVONQlpavHRSWT95Jkrli9k0sfyDCKNLX/+142 | ||
plFVHH9RQJfcrHFmJV40p96oeGKfiC0TTix45lM2QM3tF7Im2ajzCBchacAJFktH | ||
DtaYeMcMLiJBvmv5Cb9gEkyUJ1QyTQIe+XUaFkSz9dfvQMsghRgYcUpD4IGleeWQ | ||
70A0miyvu+y1mZpLe7qGsBugN8pjkbnqfPv/B2+7LPYT3JabW0Q9OMbmktEG6cjM | ||
zim5Vq3EiCgEkI+G4lmdVF0dHhweCQzd88RfWjLyrsh8NcFy15jxaHaxw9llrB0A | ||
oIhX8e8RBiqW5xD2PtNl1spO2m2kpCjfOKD4TOnxU+/c8Cbd25DgtZs= | ||
-----END ENCRYPTED PRIVATE KEY----- | ||
-----BEGIN CERTIFICATE----- | ||
MIIEMDCCAxigAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwPTELMAkGA1UEBhMCQkUx | ||
DjAMBgNVBAoMBWlUZXh0MR4wHAYDVQQDDBVpVGV4dFRlc3RJbnRlcm1lZGlhdGUw | ||
IBcNMjAwMTAxMDAwMDAwWhgPMjQwMDAxMDEwMDA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BCZW4UdcjwCNsI/9wC8CRpM90vw3e8MjKvm5KeVza3HydkIk/YU | ||
h5M+5J1AcqgSUw1RHvRXhMoZ2/tOahoLawc4hU/6Fd5l2sxxxh7Vu/Ls5cQkLd5N | ||
PSpcpByOAzCUAOcAWcBLlzdH5tS5GN69B+oKYBPDJYaSpRSWfljLcVfhr0F2Nuyb | ||
JmtSs8hoiKFv+faCcWRnYnCpKxStc/bkMXosoTW6RU51wD+v4KI0BxXwfIv5UT6G | ||
GoBJOuvldIX6xGU3GbcCyQzm5VA= | ||
-----END CERTIFICATE----- |
Binary file added
BIN
+3.88 KB
itext.tests/itext.pdfua.tests/resources/itext/pdfua/certificates/signCertRsa01.p12
Binary file not shown.
Oops, something went wrong.