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

Commit

Permalink
compatibility updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dghgit committed Jun 28, 2018
1 parent b6dc3e5 commit c5473a3
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ant/jdk13.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<exclude name="**/est/**/*.java" />
</fileset>
<fileset dir="pg/src/main/java">
<exclude name="**/keybox/*.java" />
</fileset>
<fileset dir="mail/src/main/java">
<exclude name="**/ValidateSignedMail.java" />
Expand Down Expand Up @@ -132,6 +133,7 @@
<exclude name="**/jce/provider/test/AEADTest.java" />
</fileset>
<fileset dir="prov/src/test/java">
<exclude name="**/GOST3410KeyPairTest.java" />
<exclude name="**/MQVTest.java" />
<exclude name="**/ECDSA5Test.java" />
<exclude name="**/NamedCurveTest.java" />
Expand Down Expand Up @@ -217,6 +219,7 @@
<fileset dir="core/src/main/jdk1.4" includes="**/*.java" />
<fileset dir="prov/src/main/jdk1.4" includes="**/*.java" >
<exclude name="**/LDAP*.java" />
<exclude name="**/rsa/PSSParamSpec.java" />
</fileset>
<fileset dir="pkix/src/main/jdk1.4" includes="**/*.java" />
<fileset dir="pg/src/main/jdk1.4" includes="**/*.java" />
Expand Down
10 changes: 8 additions & 2 deletions ant/jdk14.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
<exclude name="**/ntru/**/*.java" />
<exclude name="**/xmss/**/*.java" />
</fileset>
<fileset dir="pg/src/main/java" />
<fileset dir="pg/src/main/java" >
<exclude name="**/keybox/**/*.java" />
</fileset>
<fileset dir="pkix/src/main/java" >
<exclude name="**/est/**/*.java" />
</fileset>
Expand Down Expand Up @@ -69,7 +71,10 @@
<exclude name="**/pqc/**/XMS*.java" />
<exclude name="**/GetInstanceTest.java" />
</fileset>
<fileset dir="pg/src/test/java" />
<fileset dir="pg/src/test/java" >
<exclude name="**/keybox/**/*.java" />
<exclude name="**/gpg/test/*.java" />
</fileset>
<fileset dir="pkix/src/test/java" >
<exclude name="**/est/**/*.java" />
<exclude name="**/TimeStampTokenInfoUnitTest.java"/>
Expand All @@ -80,6 +85,7 @@
<exclude name="**/DetDSATest.java" />
<exclude name="**/ECDSA5Test.java" />
<exclude name="**/CRL5Test.java" />
<exclude name="**/GOST3410KeyPairTest.java" />
<exclude name="**/NamedCurveTest.java" />
<exclude name="**/X509LDAPCertStoreTest.java" />
<exclude name="**/X509StoreTest.java" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
Expand Down Expand Up @@ -330,17 +331,15 @@ public Signature createRawSignature(AlgorithmIdentifier algorithm)
// RFC 4056
// When the id-RSASSA-PSS algorithm identifier is used for a signature,
// the AlgorithmIdentifier parameters field MUST contain RSASSA-PSS-params.
/*
if (algorithm.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
{
AlgorithmParameters params = helper.createAlgorithmParameters(algName);

AlgorithmParametersUtils.loadParameters(params, algorithm.getParameters());

PSSParameterSpec spec = (PSSParameterSpec)params.getParameterSpec(PSSParameterSpec.class);
AlgorithmParameterSpec spec = params.getParameterSpec(AlgorithmParameterSpec.class);
sig.setParameter(spec);
}
*/
}
catch (Exception e)
{
Expand Down Expand Up @@ -378,7 +377,7 @@ private static String getDigestName(ASN1ObjectIdentifier oid)
String name = MessageDigestUtils.getDigestName(oid);

int dIndex = name.indexOf('-');
if (dIndex > 0)
if (dIndex > 0 && !name.startsWith("SHA3"))
{
return name.substring(0, dIndex) + name.substring(dIndex + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected byte[] engineGetEncoded()
protected byte[] engineGetEncoded(
String format)
{
if (this.isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
{
return engineGetEncoded();
}
Expand Down Expand Up @@ -116,6 +116,8 @@ protected String engineToString()
public static class PSS
extends AlgorithmParametersSpi
{
PSSParamSpec currentSpec;

/**
* Return the PKCS#1 ASN.1 structure RSASSA-PSS-params.
*/
Expand All @@ -124,7 +126,8 @@ protected byte[] engineGetEncoded()
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
RSASSAPSSparams pssP = new RSASSAPSSparams(RSASSAPSSparams.DEFAULT_HASH_ALGORITHM, RSASSAPSSparams.DEFAULT_MASK_GEN_FUNCTION, new ASN1Integer(20), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
PSSParamSpec pssSpec = (PSSParamSpec)currentSpec;
RSASSAPSSparams pssP = new RSASSAPSSparams(RSASSAPSSparams.DEFAULT_HASH_ALGORITHM, RSASSAPSSparams.DEFAULT_MASK_GEN_FUNCTION, new ASN1Integer(pssSpec.getSaltLength()), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);

dOut.writeObject(pssP);
dOut.close();
Expand All @@ -149,14 +152,24 @@ protected AlgorithmParameterSpec localEngineGetParameterSpec(
Class paramSpec)
throws InvalidParameterSpecException
{
if (paramSpec == PSSParamSpec.class && currentSpec != null)
{
return currentSpec;
}

throw new InvalidParameterSpecException("unknown parameter spec passed to PSS parameters object.");
}

protected void engineInit(
AlgorithmParameterSpec paramSpec)
throws InvalidParameterSpecException
{
throw new InvalidParameterSpecException("Not implemented");
if (!(paramSpec instanceof PSSParamSpec))
{
throw new InvalidParameterSpecException("PSSParameterSpec required to initialise an PSS algorithm parameters object");
}

this.currentSpec = (PSSParamSpec)paramSpec;
}

protected void engineInit(
Expand All @@ -166,7 +179,11 @@ protected void engineInit(
try
{
RSASSAPSSparams pssP = RSASSAPSSparams.getInstance(params);
String hashName = org.bouncycastle.jcajce.util.MessageDigestUtils.getDigestName(
pssP.getHashAlgorithm().getAlgorithm());

currentSpec = new PSSParamSpec(
pssP.getSaltLength().intValue(), hashName);
}
catch (ClassCastException e)
{
Expand All @@ -183,7 +200,7 @@ protected void engineInit(
String format)
throws IOException
{
if (this.isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))
{
engineInit(params);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.bouncycastle.jcajce.provider.asymmetric.rsa;


import java.security.spec.AlgorithmParameterSpec;

class PSSParamSpec
implements AlgorithmParameterSpec
{
private final String digName;
private final int saltLength;

public PSSParamSpec(int saltLength, String digName)
{
this.saltLength = saltLength;
this.digName = digName;
}

public int getSaltLength()
{
return saltLength;
}

public String getDigestName()
{
return digName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class PSSSignatureSpi
extends Signature
{
private AlgorithmParameters engineParams;
private PSSParamSpec paramSpec;
private AsymmetricBlockCipher signer;
private Digest contentDigest;
private Digest mgfDigest;
Expand Down Expand Up @@ -274,7 +275,88 @@ protected void engineSetParameter(
AlgorithmParameterSpec params)
throws InvalidParameterException
{
throw new InvalidParameterException("Only PSSParameterSpec supported");
if (params instanceof PSSParamSpec)
{
PSSParamSpec newParamSpec = (PSSParamSpec)params;

this.engineParams = null;
this.paramSpec = newParamSpec;
this.saltLength = paramSpec.getSaltLength();

boolean isSha3 = false;
if (paramSpec instanceof PSSParamSpec)
{
isSha3 = ((PSSParamSpec)paramSpec).getDigestName().startsWith("SHA3");
}

if (mgfDigest == null)
{
switch (saltLength)
{
case 20:
this.mgfDigest = new SHA1Digest();
break;
case 28:
if (isSha3)
{
this.mgfDigest = new SHA3Digest(224);
}
else
{
this.mgfDigest = new SHA224Digest();
}
break;
case 32:
if (isSha3)
{
this.mgfDigest = new SHA3Digest(256);
}
else
{
this.mgfDigest = new SHA256Digest();
}
break;
case 48:
if (isSha3)
{
this.mgfDigest = new SHA3Digest(384);
}
else
{
this.mgfDigest = new SHA384Digest();
}
break;
case 64:
if (isSha3)
{
this.mgfDigest = new SHA3Digest(512);
}
else
{
this.mgfDigest = new SHA512Digest();
}
break;
default:
if (saltLength <= 20)
{
this.mgfDigest = new SHA1Digest();
}
else if (saltLength <= 28)
{
this.mgfDigest = new SHA224Digest();
}
else if (saltLength <= 32)
{
this.mgfDigest = new SHA256Digest();
}
}
setupContentDigest();
}
}
else
{
throw new InvalidParameterException("Only PSSParamSpec supported");
}
}

protected AlgorithmParameters engineGetParameters()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.asn1.x9.X9ObjectIdentifiers;
import org.bouncycastle.crypto.CryptoServicesRegistrar;
import org.bouncycastle.crypto.PBEParametersGenerator;
import org.bouncycastle.crypto.digests.SHA512Digest;
import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.bouncycastle.asn1.x509.SubjectKeyIdentifier;
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
import org.bouncycastle.asn1.x509.X509ObjectIdentifiers;
import org.bouncycastle.crypto.CryptoServicesRegistrar;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.SHA1Digest;
import org.bouncycastle.jcajce.PKCS12Key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bouncycastle.crypto.BlockCipher;
import org.bouncycastle.crypto.BufferedBlockCipher;
import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.CryptoServicesRegistrar;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.crypto.OutputLengthException;
Expand Down

0 comments on commit c5473a3

Please sign in to comment.