Skip to content
This repository was archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
JDK 1.4 compatibility fixes
Browse files Browse the repository at this point in the history
fixed typo in test.
  • Loading branch information
dghgit committed May 5, 2017
1 parent 66939f6 commit 3e6ed23
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ant/build.regexp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

regexp: <[A-Z?][^>@]*[a-zA-Z0-9\\[\\]]>|<[A-Z]>
regexp: <[A-Z?][^>@]*[a-zA-Z0-9\\]]>|<[A-Z]>|<[a-z][^>@]*[a-z\\]]>

1 change: 1 addition & 0 deletions ant/jdk14.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
</fileset>
<fileset dir="pg/src/test/java" />
<fileset dir="pkix/src/test/java" >
<exclude name="**/est/**/*.java" />
<exclude name="**/TimeStampTokenInfoUnitTest.java"/>
</fileset>
<fileset dir="mail/src/test/java" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ public void testEmbeddedMultiParser()
verifySigners(s.getCertificates(), s.getSignerInfos());
}

public void testPSSVarientSalt()
public void testPSSVariantSalt()
throws Exception
{
MimeMessage message = loadMessage("openssl-signed-sha256-non-default-salt-length.eml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Signature createSignature(AlgorithmIdentifier sigAlgId)
{
ASN1Sequence seq = ASN1Sequence.getInstance(sigAlgId.getParameters());

if (seq != null && seq.size() != 0)
if (notDefaultPSSParams(seq))
{
try
{
Expand Down Expand Up @@ -484,4 +484,31 @@ String getKeyAlgorithmName(ASN1ObjectIdentifier oid)

return oid.getId();
}

// for our purposes default includes varient digest with salt the same size as digest
private boolean notDefaultPSSParams(ASN1Sequence seq)
throws GeneralSecurityException
{
if (seq == null || seq.size() == 0)
{
return false;
}

RSASSAPSSparams pssParams = RSASSAPSSparams.getInstance(seq);

if (!pssParams.getMaskGenAlgorithm().getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1))
{
return true;
}

// same digest for sig and MGF1
if (!pssParams.getHashAlgorithm().equals(AlgorithmIdentifier.getInstance(pssParams.getMaskGenAlgorithm().getParameters())))
{
return true;
}

MessageDigest digest = createDigest(pssParams.getHashAlgorithm());

return pssParams.getSaltLength().intValue() != digest.getDigestLength();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ protected PSSSignatureSpi(
super(name);

this.signer = signer;
this.mgfDigest = digest;

if (digest != null)
{
this.saltLength = digest.getDigestSize();
this.mgfDigest = digest;
}
else
{
Expand All @@ -107,11 +107,11 @@ protected PSSSignatureSpi(
super(name);

this.signer = signer;
this.mgfDigest = digest;


if (digest != null)
{
this.saltLength = digest.getDigestSize();
this.mgfDigest = digest;
}
else
{
Expand All @@ -137,6 +137,12 @@ protected void engineInitVerify(
throw new InvalidKeyException("Supplied key is not a RSAPublicKey instance");
}

if (mgfDigest == null)
{
mgfDigest = new SHA1Digest();
setupContentDigest();
}

pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength);
pss.init(false,
RSAUtil.generatePublicKeyParameter((RSAPublicKey)publicKey));
Expand All @@ -152,6 +158,12 @@ protected void engineInitSign(
throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
}

if (mgfDigest == null)
{
mgfDigest = new SHA1Digest();
setupContentDigest();
}

pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength);
pss.init(true, new ParametersWithRandom(RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey), random));
}
Expand All @@ -165,6 +177,12 @@ protected void engineInitSign(
throw new InvalidKeyException("Supplied key is not a RSAPrivateKey instance");
}

if (mgfDigest == null)
{
mgfDigest = new SHA1Digest();
setupContentDigest();
}

pss = new org.bouncycastle.crypto.signers.PSSSigner(signer, contentDigest, mgfDigest, saltLength);
pss.init(true, RSAUtil.generatePrivateKeyParameter((RSAPrivateKey)privateKey));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.cryptopro.ECGOST3410NamedCurves;
import org.bouncycastle.asn1.gm.GMNamedCurves;
import org.bouncycastle.asn1.nist.NISTNamedCurves;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.sec.SECNamedCurves;
Expand Down Expand Up @@ -306,6 +307,10 @@ public static X9ECParameters getNamedCurveByOid(
{
params = TeleTrusTNamedCurves.getByOID(oid);
}
if (params == null)
{
params = GMNamedCurves.getByOID(oid);
}
}

return params;
Expand Down

0 comments on commit 3e6ed23

Please sign in to comment.