nemiah / phpFinTS

PHP library to communicate with FinTS/HBCI servers
MIT License
130 stars 39 forks source link

FlickerTan: comdirect: Wrong length of TAN Challenge expected: 0 - found: 3680 - only Version 1.4 supported #411

Closed strtob closed 1 year ago

strtob commented 1 year ago

Hi,

I have no luck to generate a phototan code:

                // Challenge Image for PhotoTan/ChipTan
                if ($tanRequest->getChallengeHhdUc())
                {
                    try {
                        $flicker        = new \Fhp\Model\FlickerTan\TanRequestChallengeFlicker($tanRequest->getChallengeHhdUc());
                        echo 'There is a challenge flicker.' . PHP_EOL;
                        // save or output svg
                        $flickerPattern = $flicker->getFlickerPattern();
                        // other renderers can be implemented with this pattern
                        $svg            = new \Fhp\Model\FlickerTan\SvgRenderer($flickerPattern);
                        echo $svg->getImage();

ends with: InvalidArgumentException Wrong length of TAN Challenge expected: 0 - found: 3680 - only Version 1.4 supported

` in /vendor/nemiah/php-fints/lib/Fhp/Model/FlickerTan/TanRequestChallengeFlicker.php at line 42

}

private function parseChallenge(): void
{
    $reducedChallenge = trim(str_replace(' ', '', $this->challenge));
    // length of whole challenge (without lc) max 255 | encoding: base 10
    $lc = (int) substr($reducedChallenge, 0, 3);
    $reducedChallenge = substr($reducedChallenge, 3);
    if (strlen($reducedChallenge) !== $lc) {
        throw new InvalidArgumentException("Wrong length of TAN Challenge expected: $lc - found: ". strlen($reducedChallenge). ' - only Version 1.4 supported');
    `

print_r($tanRequest->getChallengeHhdUc()); returns me:

`Fhp\Syntax\Bin Object ( [string:protected] => image/pnge�PNG 

IHDR����|.,IDATx�흡nU��++����x^���m�AౕMx�Z���@ ����C�����=����L�٬�5��{�����8��R���4�RK)����XJi,�4�RJc)����XJ)����RJc)����v������ΦG�M�Ό�g�ɓ'ӻw��߿/�XWWW���o�c/����t}}=�X���������6����f:::�p���\�����u~~������k��:==u�{=6@c��r�k����( ��ph,�Cci,���XNJ�����ׯ_O�?�BSmU>|��>}���z�����gp���Tj�>}���Rj �XJi,��4�~k�?���fa����4��;������}=���[������t�̓nO��w���Z8�S�:����O���C����\ �u�R�2��it�xz�RA�����!�����_L )::h���X+�9M#��e��B�����=� �t�J�H�c��Ŵ�����/o���1���4R�X�1-������c�L�4��:��_L )::h���X+��Tp��E*��p�>�i۰T�5�X1]�R9 ��C�� KE�Xc��E*�

It seems there is a problem to convert the png, but I'm new to fints - any ideas would really appreaciate!

Thanks a lot, Tobi

strtob commented 1 year ago

I've sovled the problem.

The problem was, that throw new InvalidArgumentException is not explicit defined. The are lot of different packages with the same class (in my project). Therefore, you need the path that the exception will catched. Maybe a better way to return a result with message that should be handled.

Best, Tobi

lukas-staab commented 1 year ago

It returned a QR-Tan (probably) not a Flicker TAN, so I am a bit confused right now, how better defining a exception fixed something for you. Care to do a PR?

strtob commented 1 year ago

You're right, was some starting problem at my side. I'm not finished to implement this completely in my project, but this work is awesome and I really want to thank you for sharing!