Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Do not reuse KeyPair context to generate second key pair #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Jakuje
Copy link

@Jakuje Jakuje commented Sep 1, 2021

This occasionally fails with java.lang.ArrayIndexOutOfBoundsException
when the ECDSA key starts with 0 and the length is trimmed in
setBigInteger() of ByteContainer for the first key pair and the second
one does not fit.

Backtraces collected from OpenSC testsuite were sometimes very
different, but all point to this place:

Error:  testGenerateSecretECDH(com.licel.jcardsim.crypto.KeyAgreementImplTest)  Time elapsed: 0.2 s  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at javacard.framework.Util.arrayCopy(Unknown Source)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:122)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:99)
	at com.licel.jcardsim.crypto.ByteContainer.setBigInteger(ByteContainer.java:87)
	at com.licel.jcardsim.crypto.ECPrivateKeyImpl.setParameters(ECPrivateKeyImpl.java:57)
	at com.licel.jcardsim.crypto.KeyPairImpl.genKeyPair(KeyPairImpl.java:93)
	at javacard.security.KeyPair.genKeyPair(Unknown Source)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecret(KeyAgreementImplTest.java:119)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecretECDH(KeyAgreementImplTest.java:56)
Error:  Errors:
Error:    com.licel.jcardsim.crypto.KeyAgreementImplTest#testGenerateSecretECDH ArrayIndexOutOfBoundsException

Jakuje added a commit to Jakuje/OpenSC that referenced this pull request Sep 1, 2021
Jakuje added a commit to Jakuje/OpenSC that referenced this pull request Sep 2, 2021
Jakuje referenced this pull request in Jakuje/jcardsim Sep 3, 2021
This occasionally fails with java.lang.ArrayIndexOutOfBoundsException
when the ECDSA key starts with 0 and the length is trimmed in
setBigInteger() of ByteContainer for the first key pair and the second
one does not fit.

Backtraces collected from OpenSC testsuite were sometimes very
different, but all point to this place:

Error:  testGenerateSecretECDH(com.licel.jcardsim.crypto.KeyAgreementImplTest)  Time elapsed: 0.2 s  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at javacard.framework.Util.arrayCopy(Unknown Source)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:122)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:99)
	at com.licel.jcardsim.crypto.ByteContainer.setBigInteger(ByteContainer.java:87)
	at com.licel.jcardsim.crypto.ECPrivateKeyImpl.setParameters(ECPrivateKeyImpl.java:57)
	at com.licel.jcardsim.crypto.KeyPairImpl.genKeyPair(KeyPairImpl.java:93)
	at javacard.security.KeyPair.genKeyPair(Unknown Source)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecret(KeyAgreementImplTest.java:119)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecretECDH(KeyAgreementImplTest.java:56)

Error:  Errors:
Error:    com.licel.jcardsim.crypto.KeyAgreementImplTest#testGenerateSecretECDH ArrayIndexOutOfBoundsException
Jakuje added a commit to Jakuje/OpenSC that referenced this pull request Sep 8, 2021
Jakuje added a commit to OpenSC/OpenSC that referenced this pull request Sep 8, 2021
This occasionally fails with java.lang.ArrayIndexOutOfBoundsException
when the ECDSA key starts with 0 and the length is trimmed in
setBigInteger() of ByteContainer for the first key pair and the second
one does not fit.

Backtraces collected from OpenSC testsuite were sometimes very
different, but all point to this place:

Error:  testGenerateSecretECDH(com.licel.jcardsim.crypto.KeyAgreementImplTest)  Time elapsed: 0.2 s  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at javacard.framework.Util.arrayCopy(Unknown Source)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:122)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:99)
	at com.licel.jcardsim.crypto.ByteContainer.setBigInteger(ByteContainer.java:87)
	at com.licel.jcardsim.crypto.ECPrivateKeyImpl.setParameters(ECPrivateKeyImpl.java:57)
	at com.licel.jcardsim.crypto.KeyPairImpl.genKeyPair(KeyPairImpl.java:93)
	at javacard.security.KeyPair.genKeyPair(Unknown Source)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecret(KeyAgreementImplTest.java:119)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecretECDH(KeyAgreementImplTest.java:56)

Error:  Errors:
Error:    com.licel.jcardsim.crypto.KeyAgreementImplTest#testGenerateSecretECDH ArrayIndexOutOfBoundsException

[ERROR] testGenerateSecretDH(com.licel.jcardsim.crypto.KeyAgreementImplTest)  Time elapsed: 0.023 s  <<< ERROR!
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at javacard.framework.Util.arrayCopy(Unknown Source)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:122)
	at com.licel.jcardsim.crypto.ByteContainer.setBytes(ByteContainer.java:99)
	at com.licel.jcardsim.crypto.ByteContainer.setBigInteger(ByteContainer.java:90)
	at com.licel.jcardsim.crypto.DHPrivateKeyImpl.setParameters(DHPrivateKeyImpl.java:45)
	at com.licel.jcardsim.crypto.KeyPairImpl.genKeyPair(KeyPairImpl.java:93)
	at javacard.security.KeyPair.genKeyPair(Unknown Source)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.generateSecretDH(KeyAgreementImplTest.java:86)
	at com.licel.jcardsim.crypto.KeyAgreementImplTest.testGenerateSecretDH(KeyAgreementImplTest.java:71)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant