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 Aug 25, 2024
2 parents 6e4c5dc + 9329e5c commit f7a3de2
Show file tree
Hide file tree
Showing 34 changed files with 1,669 additions and 64 deletions.

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFNTBfBgkqhkiG9w0BBQ0wUjAxBgkqhkiG9w0BBQwwJAQQdOaEUfD0sZWtUR11
xwgn0gICCAAwDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEBaNXSfwUjF5SS7n
ce1JFoUEggTQ6eV+IsckiVP7I9VTldLkpP5OKB8brmw5t20fO11HyCnqkkhooR2b
t2fBj4fWv0IRUe266L+fVs7AOngjkWfezEvGR6nte4pNXEFrOwt/U8A6IYZXBdA5
dvqs6VMPHbjQ8CufVLGvksuYFQVRcGy0rk1DH2Of44GU4X0GtROlFFJnkmfZhVPS
Hx2MXXGQ02Ko1i1eKoEGgvmSAsDcPijiX96DKlQZJ4YMtI/8rRsdvNJsJ2beyZDa
T3aJMmSSBF92mS2dtS21DwjzEu8utquguYA0KYzjZM9onOuBEEUifam8Fjnvlui6
beQJya4zldoA6QZPSd2PUAP6l1U/d8UXqcisjzArDZDmRu58dPxn4rs0NgTOIO8h
fEUIvfS+wuknff1b/wdGnwXkXoeSrrjS9dhP9KVU1SJ/FWKc6BY+P+JmE5vLjAtn
AmbyZhXY0jX7ZHFh0z0y1y1fTIXL1aj4iB+cUwhJ1ZdlGkT5HdG4ts/oTGCnpB6O
F1GvGyhprmtjp/dspLH5ha0I+4aTn46yFpnBNyg8w9c2+xj8Jiqy9J/ppVtPdhxt
wrE1/ThUGIWUTsbGbLW87WIrZq6IlSGtztbxAMYxXoe4solYueE3pI3eYFzgnBcq
T6Byktr71gt9AGD/N/p+Kk5RM4JT8XpQjLjz9TlmsGpJzUoBGeG6KFLs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0qmyF8zNuffTOiSS8/V6Cf7CntuPWjSuVf1EVP
MH6KkSjceLZ99Y7bvl7KKvQ4Kj5Bp27PwlRvtYbfCUmQEG8=
-----END CERTIFICATE-----
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Esf;
using Org.BouncyCastle.Asn1.Ess;
Expand Down Expand Up @@ -79,7 +80,11 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons.Bouncycastle.X509;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.Tsp;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Operators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Security.Certificates;
Expand Down Expand Up @@ -1127,6 +1132,11 @@ public bool IsNullExtension(IX509Extension ext) {
public bool IsNull(IAsn1Encodable encodable) {
return ((Asn1EncodableBC)encodable).GetEncodable() == null;
}

/// <summary><inheritDoc/></summary>
public RNGCryptoServiceProvider GetSecureRandom() {
return new RNGCryptoServiceProvider();
}

/// <summary><inheritDoc/></summary>
public IX509Extension CreateExtension(bool b, IDerOctetString octetString) {
Expand Down Expand Up @@ -1170,6 +1180,30 @@ public string CreateEndDate(IX509Certificate certificate) {
return certificate.GetEndDateTime();
}

/// <summary><inheritDoc/></summary>
public byte[] GenerateHKDF(byte[] inputKey, byte[] salt, byte[] info) {
HkdfBytesGenerator hkdfBytesGenerator = new HkdfBytesGenerator(new Sha256Digest());
HkdfParameters hkdfParameters = new HkdfParameters(inputKey, salt, info);
hkdfBytesGenerator.Init(hkdfParameters);
byte[] hkdf = new byte[32];
hkdfBytesGenerator.GenerateBytes(hkdf, 0, 32);

return hkdf;
}

/// <summary><inheritDoc/></summary>
public byte[] GenerateHMACSHA256Token(byte[] key, byte[] data) {
HMACSHA256 mac = new HMACSHA256(key);
return mac.ComputeHash(data);
}

/// <summary><inheritDoc/></summary>
public byte[] GenerateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) {
IWrapper wrapper = new AesWrapEngine();
wrapper.Init(true, new KeyParameter(kek));
return wrapper.Wrap(key, 0, key.Length);
}

//\cond DO_NOT_DOCUMENT
internal class BouncyCastlePasswordFinder : IPasswordFinder {
private readonly char[] password;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using iText.Bouncycastleconnector.Logs;
using iText.Commons.Bouncycastle;
using iText.Commons.Bouncycastle.Asn1;
Expand Down Expand Up @@ -702,6 +703,10 @@ public bool IsNull(IAsn1Encodable encodable) {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}

public RNGCryptoServiceProvider GetSecureRandom() {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}

public byte[] CreateCipherBytes(IX509Certificate x509Certificate, byte[] abyte0, IAlgorithmIdentifier algorithmidentifier) {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}
Expand All @@ -721,5 +726,17 @@ public IBouncyCastleUtil GetBouncyCastleUtil() {
public string CreateEndDate(IX509Certificate certificate) {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}

public byte[] GenerateHKDF(byte[] inputKey, byte[] salt, byte[] info) {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}

public byte[] GenerateHMACSHA256Token(byte[] key, byte[] data) {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}

public byte[] GenerateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) {
throw new NotSupportedException(BouncyCastleLogMessageConstant.BOUNCY_CASTLE_DEPENDENCY_MUST_PRESENT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using iText.Bouncycastle.Security;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Esf;
Expand Down Expand Up @@ -1187,6 +1188,11 @@ public bool IsNullExtension(IX509Extension ext) {
public bool IsNull(IAsn1Encodable encodable) {
return ((Asn1EncodableBCFips)encodable).GetEncodable() == null;
}

/// <summary><inheritDoc/></summary>
public RNGCryptoServiceProvider GetSecureRandom() {
return new RNGCryptoServiceProvider();
}

/// <summary><inheritDoc/></summary>
public IX509Extension CreateExtension(bool b, IDerOctetString octetString) {
Expand Down Expand Up @@ -1216,17 +1222,6 @@ public void IsEncryptionFeatureSupported(int encryptionType, bool withCertificat
}
}

/// <summary><inheritDoc/></summary>
public SecureRandom GetSecureRandom() {
byte[] personalizationString = Strings.ToUtf8ByteArray("some personalization string");
SecureRandom entropySource = new SecureRandom();
return CryptoServicesRegistrar.CreateService(FipsDrbg.Sha512)
.FromEntropySource(entropySource,true)
.SetPersonalizationString(personalizationString).Build(
entropySource.GenerateSeed(256 / (2 * 8)), true,
Strings.ToByteArray("number only used once"));
}

/// <summary><inheritDoc/></summary>
public IBouncyCastleUtil GetBouncyCastleUtil() {
return BOUNCY_CASTLE_UTIL;
Expand All @@ -1236,6 +1231,22 @@ public IBouncyCastleUtil GetBouncyCastleUtil() {
public string CreateEndDate(IX509Certificate certificate) {
return certificate.GetEndDateTime();
}

/// <summary><inheritDoc/></summary>
public byte[] GenerateHKDF(byte[] inputKey, byte[] salt, byte[] info) {
throw new NotSupportedException("HKDF algorithm is not supported in bouncy-castle FIPS mode.");
}

/// <summary><inheritDoc/></summary>
public byte[] GenerateHMACSHA256Token(byte[] key, byte[] data) {
HMACSHA256 mac = new HMACSHA256(key);
return mac.ComputeHash(data);
}

/// <summary><inheritDoc/></summary>
public byte[] GenerateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek) {
throw new NotSupportedException("Encrypted key generation with AES256 is not supported in bouncy-castle FIPS mode.");
}

private IX509Certificate ReadPemCertificate(PushbackStream pushbackStream) {
using (TextReader file = new StreamReader(pushbackStream)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using iText.Bouncycastlefips.Cert;
using iText.Commons.Bouncycastle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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;
using iText.Commons.Exceptions;

namespace iText.Bouncycastlefips
{
public class UnsupportedEncryptionFeatureException : ITextException
{
public class UnsupportedEncryptionFeatureException : ITextException {
public const String ENCRYPTION_WITH_CERTIFICATE_ISNT_SUPPORTED_IN_FIPS =
"Encryption with certificated is currently not supported in Bouncy Castle FIPS mode.";

public UnsupportedEncryptionFeatureException(string msg): base(msg)
{
public UnsupportedEncryptionFeatureException(string msg): base(msg) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ You should have received a copy of the GNU Affero General Public License
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Fips;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities;

namespace iText.Bouncycastlefips.Crypto.Generators {
/// <summary>
Expand All @@ -40,9 +42,16 @@ public class RsaKeyPairGeneratorBCFips : IRsaKeyPairGenerator {
/// <see cref="FipsRsa.KeyPairGenerator"/>.
/// </summary>
public RsaKeyPairGeneratorBCFips() {
byte[] personalizationString = Strings.ToUtf8ByteArray("some personalization string");
SecureRandom entropySource = new SecureRandom();
SecureRandom secureRandomForGenerator = CryptoServicesRegistrar.CreateService(FipsDrbg.Sha512)
.FromEntropySource(entropySource,true)
.SetPersonalizationString(personalizationString).Build(
entropySource.GenerateSeed(256 / (2 * 8)), true,
Strings.ToByteArray("number only used once"));
this.generator = CryptoServicesRegistrar.CreateGenerator(
new FipsRsa.KeyGenerationParameters(BigInteger.ValueOf(0x10001), 2048),
new BouncyCastleFipsFactory().GetSecureRandom());
secureRandomForGenerator);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using iText.Commons.Bouncycastle.Asn1;
using iText.Commons.Bouncycastle.Asn1.Cms;
using iText.Commons.Bouncycastle.Asn1.Esf;
Expand Down Expand Up @@ -1580,7 +1581,18 @@ IX509V3CertificateGenerator CreateJcaX509v3CertificateBuilder(IX509Certificate s
/// </returns>
bool IsNullExtension(IX509Extension extNonce);

/// <summary>
/// Check if provided encodable wrapper wraps null.
/// </summary>
/// <param name="encodable">encodable wrapper to be checked</param>
/// <returns>true if provided encodable wrapper wraps null, false otherwise</returns>
bool IsNull(IAsn1Encodable encodable);

/// <summary>
/// Get SecureRandom implementation from the factory.
/// </summary>
/// <returns>SecureRandom implementation</returns>
RNGCryptoServiceProvider GetSecureRandom();

/// <summary>
/// Create
Expand Down Expand Up @@ -1635,5 +1647,30 @@ IX509V3CertificateGenerator CreateJcaX509v3CertificateBuilder(IX509Certificate s
/// <param name="certificate">certificate to get end date</param>
/// <returns>The end date of the certificate</returns>
string CreateEndDate(IX509Certificate certificate);

/// <summary>
/// Generates byte array based on extract-and-expand key derivation function, using provided parameters.
/// </summary>
/// <param name="inputKey">byte[] input key material</param>
/// <param name="salt">byte[] salt</param>
/// <param name="info">byte[] info</param>
/// <returns>byte[] key derivation function result.</returns>
byte[] GenerateHKDF(byte[] inputKey, byte[] salt, byte[] info);

/// <summary>
/// Generates byte array based MAC token according to HMACSHA256 algorithm.
/// </summary>
/// <param name="key">MAC key</param>
/// <param name="data">data to be encrypted</param>
/// <returns>byte array based MAC token.</returns>
byte[] GenerateHMACSHA256Token(byte[] key, byte[] data);

/// <summary>
/// Generates encrypted key based on AES256 without padding wrapping algorithm.
/// </summary>
/// <param name="key">key to be encrypted</param>
/// <param name="kek">key encryption key to be used</param>
/// <returns>encrypted key.</returns>
byte[] GenerateEncryptedKeyWithAES256NoPad(byte[] key, byte[] kek);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using iText.Commons.Bouncycastle.Cert;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You should have received a copy of the GNU Affero General Public License
using iText.Commons;
using iText.Commons.Bouncycastle;
using iText.Commons.Bouncycastle.Crypto;
using iText.Commons.Utils;
using iText.Kernel.Exceptions;
using iText.Kernel.Logs;

Expand Down Expand Up @@ -94,6 +95,22 @@ public virtual void SetHashKeyForNextObject(int objNumber, int objGeneration) {
public abstract OutputStreamEncryption GetEncryptionStream(Stream os);

public abstract IDecryptor GetDecryptor();

/// <summary>
/// Gets encryption key for a particular object/generation.
/// </summary>
/// <returns>encryption key for a particular object/generation.</returns>
public byte[] GetNextObjectKey() {
return JavaUtil.ArraysCopyOf(nextObjectKey, nextObjectKey.Length);
}

/// <summary>
/// Gets global encryption key.
/// </summary>
/// <returns>global encryption key.</returns>
public byte[] GetMkey() {
return JavaUtil.ArraysCopyOf(mkey, mkey.Length);
}

private void SafeInitMessageDigest() {
try {
Expand Down
6 changes: 6 additions & 0 deletions itext/itext.kernel/itext/kernel/events/PdfDocumentEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public class PdfDocumentEvent : Event {
/// </remarks>
public const String END_PAGE = "EndPdfPage";

/// <summary>Dispatched before writer is flushed to a document.</summary>
public const String END_WRITER_FLUSH = "EndWriterFlush";

/// <summary>Dispatched after writer is flushed to a document.</summary>
public const String START_DOCUMENT_CLOSING = "StartDocumentClosing";

/// <summary>The PdfPage associated with this event.</summary>
protected internal PdfPage page;

Expand Down
Loading

0 comments on commit f7a3de2

Please sign in to comment.