mirrored from https://www.bouncycastle.org/repositories/bc-java
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '22-add-support-for-rfc-9579' into 'main'
add support for rfc 9579 Closes #22 See merge request root/bc-java!61
- Loading branch information
Showing
6 changed files
with
582 additions
and
6 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
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
43 changes: 43 additions & 0 deletions
43
pkix/src/main/java/org/bouncycastle/pkcs/bc/BcPKCS12PBMac1CalculatorBuilder.java
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,43 @@ | ||
package org.bouncycastle.pkcs.bc; | ||
|
||
import org.bouncycastle.asn1.pkcs.PBKDF2Params; | ||
import org.bouncycastle.asn1.pkcs.PBMAC1Params; | ||
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; | ||
import org.bouncycastle.asn1.x509.AlgorithmIdentifier; | ||
import org.bouncycastle.operator.MacCalculator; | ||
import org.bouncycastle.operator.OperatorCreationException; | ||
import org.bouncycastle.pkcs.PKCS12MacCalculatorBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
public class BcPKCS12PBMac1CalculatorBuilder | ||
implements PKCS12MacCalculatorBuilder | ||
{ | ||
private final PBMAC1Params pbmac1Params; | ||
private PBKDF2Params pbkdf2Params = null; | ||
|
||
public BcPKCS12PBMac1CalculatorBuilder(PBMAC1Params pbeMacParams) throws IOException | ||
{ | ||
this.pbmac1Params = pbeMacParams; | ||
if (PKCSObjectIdentifiers.id_PBKDF2.equals(pbeMacParams.getKeyDerivationFunc().getAlgorithm())) | ||
{ | ||
this.pbkdf2Params = PBKDF2Params.getInstance(pbeMacParams.getKeyDerivationFunc().getParameters()); | ||
if (pbkdf2Params.getKeyLength() == null) | ||
{ | ||
throw new IOException("Key length must be present when using PBMAC1."); | ||
} | ||
} | ||
// TODO handle other cases | ||
} | ||
|
||
@Override | ||
public AlgorithmIdentifier getDigestAlgorithmIdentifier() | ||
{ | ||
return new AlgorithmIdentifier(PKCSObjectIdentifiers.id_PBMAC1, pbmac1Params); | ||
} | ||
|
||
public MacCalculator build(final char[] password) throws OperatorCreationException | ||
{ | ||
return PKCS12PBEUtils.createPBMac1Calculator(pbmac1Params, pbkdf2Params, password); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
pkix/src/main/java/org/bouncycastle/pkcs/bc/BcPKCS12PBMac1CalculatorBuilderProvider.java
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,46 @@ | ||
package org.bouncycastle.pkcs.bc; | ||
|
||
import org.bouncycastle.asn1.pkcs.PBMAC1Params; | ||
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; | ||
import org.bouncycastle.asn1.x509.AlgorithmIdentifier; | ||
import org.bouncycastle.operator.MacCalculator; | ||
import org.bouncycastle.operator.OperatorCreationException; | ||
import org.bouncycastle.pkcs.PKCS12MacCalculatorBuilder; | ||
import org.bouncycastle.pkcs.PKCS12MacCalculatorBuilderProvider; | ||
|
||
import java.io.IOException; | ||
|
||
public class BcPKCS12PBMac1CalculatorBuilderProvider | ||
implements PKCS12MacCalculatorBuilderProvider | ||
{ | ||
public PKCS12MacCalculatorBuilder get(final AlgorithmIdentifier algorithmIdentifier) | ||
{ | ||
return new PKCS12MacCalculatorBuilder() | ||
{ | ||
public MacCalculator build(final char[] password) | ||
throws OperatorCreationException | ||
{ | ||
if (!PKCSObjectIdentifiers.id_PBMAC1.equals(algorithmIdentifier.getAlgorithm())) | ||
{ | ||
throw new OperatorCreationException("protection algorithm not PB mac based"); | ||
} | ||
|
||
BcPKCS12PBMac1CalculatorBuilder bldr; | ||
try | ||
{ | ||
bldr = new BcPKCS12PBMac1CalculatorBuilder(PBMAC1Params.getInstance(algorithmIdentifier.getParameters())); | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new OperatorCreationException("invalid parameters in protection algorithm: " + e.getMessage()); | ||
} | ||
return bldr.build(password); | ||
} | ||
|
||
public AlgorithmIdentifier getDigestAlgorithmIdentifier() | ||
{ | ||
return new AlgorithmIdentifier(algorithmIdentifier.getAlgorithm(), algorithmIdentifier.getParameters()); | ||
} | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.