Skip to content

Commit

Permalink
Also install BC Provider if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jul 29, 2024
1 parent 9750d46 commit 468b9e8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions as2-lib/src/main/java/com/helger/as2lib/crypto/BCCryptoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,14 @@ public class BCCryptoHelper implements ICryptoHelper
try
{
// Try regular BC first
Class.forName ("org.bouncycastle.jce.provider.BouncyCastleProvider");
final Class <?> aBCClass = Class.forName ("org.bouncycastle.jce.provider.BouncyCastleProvider");
// Use for correct initialization
sProvName = PBCProvider.getProvider ().getName ();
if (Security.getProvider (sProvName) == null)
{
// Create and add a new one
Security.addProvider ((Provider) aBCClass.getConstructor ().newInstance ());
}
}
catch (final Exception ex1)
{
Expand Down Expand Up @@ -356,8 +361,8 @@ public MIC calculateMIC (@Nonnull final MimeBodyPart aPart,

// No need to canonicalize here - see issue #12
try (final DigestOutputStream aDigestOS = new DigestOutputStream (new NullOutputStream (), aMessageDigest);
final OutputStream aEncodedOS = AS2IOHelper.getContentTransferEncodingAwareOutputStream (aDigestOS,
sMICEncoding))
final OutputStream aEncodedOS = AS2IOHelper.getContentTransferEncodingAwareOutputStream (aDigestOS,
sMICEncoding))
{
aPart.getDataHandler ().writeTo (aEncodedOS);
}
Expand Down Expand Up @@ -456,8 +461,7 @@ public MimeBodyPart decrypt (@Nonnull final MimeBodyPart aPart,
if (DUMP_DECRYPTED_DIR_PATH != null)
{
// dump decrypted
try (
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (aDecryptedDataBodyPart.getSize ()))
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (aDecryptedDataBodyPart.getSize ()))
{
aDecryptedDataBodyPart.writeTo (aBAOS);
_dumpDecrypted (aBAOS.toByteArray ());
Expand Down Expand Up @@ -722,9 +726,9 @@ public MimeBodyPart verify (@Nonnull final MimeBodyPart aPart,
final X509Certificate aRealX509Cert = _verifyFindCertificate (aX509Cert, bUseCertificateInBodyPart, aSignedParser);

if (LOGGER.isDebugEnabled ())
LOGGER.debug (EqualsHelper.identityEqual (aRealX509Cert,
aX509Cert) ? "Verifying signature using the provided certificate (partnership)"
: "Verifying signature using the certificate contained in the MIME body part");
LOGGER.debug (EqualsHelper.identityEqual (aRealX509Cert, aX509Cert)
? "Verifying signature using the provided certificate (partnership)"
: "Verifying signature using the certificate contained in the MIME body part");

// Call before validity check to retrieve the information about the
// details outside
Expand Down

0 comments on commit 468b9e8

Please sign in to comment.