ph4r05 / javacard-gradle-template

JavaCard project template for building CAP and running JCardSim with gradle + coverage
MIT License
50 stars 23 forks source link

Not getting random results #8

Closed kategray closed 4 years ago

kategray commented 5 years ago

The application works fine, however, when running the unit tests, I get the same result each time:

Gradle suite > Gradle test > tests.AppletTest.hello STANDARD_OUT
    Connecting to card... Done.
    --> [00C00000080000000000000000] 13
    <-- 51373E8B6FDEC284DB569204CA13D2CAA23BD1D85DCAB02A0E3D50461E73F1BB 9000 (32)
    ResponseAPDU: 34 bytes, SW=9000

Looking through the source code, I see that random.generateData is generating into tmpBuffer, then copied into the APDU buffer. As this is part of the process() function (which should be executed separately every time the tests are run), shouldn't the output be random? The implementation in jCardSim seems to be based off bouncycastle, so I would expect it to actually be random.

ph4r05 commented 4 years ago

The reason is the JCardSim uses a static seed for randomness generated by the RandomData API. I think the main reason is the test reproducibility. One can reseed the generator with another seed.

ph4r05 commented 4 years ago

I noticed that you @kategray already addressed this in the issue https://github.com/licel/jcardsim/issues/139 and created a PR https://github.com/licel/jcardsim/pull/141.

I decided to preserve backward compatibility and created another PR https://github.com/licel/jcardsim/pull/155 which is already merged in my fork https://github.com/ph4r05/jcardsim which is published in the maven repo as 3.0.5.11.