webpcsc-firebreath icon indicating copy to clipboard operation
webpcsc-firebreath copied to clipboard

running....

Open a2800276 opened this issue 11 years ago • 7 comments

I added

https://bitbucket.org/infotermoo/memopol/src/c8f93bc037ff/cmake/modules/FindPCSCLite.cmake

into cmake's Modules directory and now everything compiles, but I'm not able to access the API.

I copied the .so to ~/.mozilla/plugins, and am using the example code from:

 dist/doc/PCSCBridge.html#_initing_the_plugin

both mozilla and chrome load the plugin fine and my reader blinks. Unfortunately, I get a type error in the console:

Firefox (21.0, Ubuntu 12.04):

[18:23:44.073] TypeError: bridge.init is not a function @ http://127.0.0.1:8080/html/pcsc.bridge.html:7

Chrome (28.0.1500.52):

Uncaught TypeError: Object #<HTMLObjectElement> has no method 'init' pcsc.bridge.html:7

In Firefox, I can call bridge.getSCardAPI(); without calling init, but I'm not sure about what parameters to pass, this is what it says in the docs:

{number} SCard.EstablishContext( {
        dwScope: {number},
        hContext: {number}
    }

I'm a little confused about the notation. Also the scope defines are brought over to JS. I've tried:

var err = api.EstablishContext(0,0)

which yields:

Too many arguments

and

var ctx = api.EstablishContext(0)

yielding

Invalid argument conversion from i to N5boost10shared_ptrIN2FB5JSAPIEEE at index 1

and finally:

var err = api.EstablishContext({dwscope: bridge.SCARD_SHARE_EXCLUSIVE, hContext: 1})

which yields:

Could not convert v to m

Do you have any working example code? I would be happy to update the docs, once I figure out how everything works...

For reference: this is the html:

<html>
  <head>
    <script type="text/javascript">
        var bridge;
        function load() {
            bridge =  document.getElementById('pcscbridge');
            bridge.init();
        }
    </script>
  </head>
    <body onload="load()">
        <object id="pcscbridge" type="application/x-pcscbridge" width="0" height="0">
            <param name="onload" value="pluginLoaded" />
        </object><br />

        <!-- INSERT HTML CODE -->

    </body>
</html>

a2800276 avatar Jun 23 '13 17:06 a2800276

Yes, the documentation looks a bit outdated. We'll have to update it as well.

I retried the sample .html project, and that one seems to be working fine

https://github.com/ubinity/webpcsc-firebreath/blob/master/projects/PCSCBridge/test/test.html

(my test sequence was, for SCardAPIs : SCardEstablishContext, SCardListReaders, choose a reader, SCardConnect, SCardStatus)

(and for CAD : get readers list, power up, type APDU in the "in" box below, transmit)

ubinity avatar Jun 23 '13 17:06 ubinity

Thanks very much -- and once again -- for the quick answer!

Works like a charm, at least in Firefox. Chrome still fails, but I can live with that (at least I can try to help fix later).

Chrome error (for reference; basically, the object/plugin html element doesn't have the getTerminalAPI() and getSCardAPI() functions bound to it... the second stacktrace is just a consequence of calling EstablishContext() even though the scard global isn't initiated):

Uncaught TypeError: Object #<HTMLObjectElement> has no method 'getTerminalAPI' test.html:248
    load test.html:248
    onload test.html:323

Uncaught TypeError: Cannot call method 'EstablishContext' of undefined test.html:33
    SCard_Establish test.html:33
    onclick test.html:372

a2800276 avatar Jun 23 '13 17:06 a2800276

ok - this is weird because I'm testing on Chrome. We'll review this tomorrow and report back.

ubinity avatar Jun 23 '13 21:06 ubinity

Hi,

About doc, it is up-to-date. The doc says ""All javascript function defined in SCarsAPI take only one associative array argument and returns an error code". It seems that's it is not clear: I will give more details in the next commit and provide more samples :) For now, the test.html is a good reference. Later I hope to provide more elaborate Javascript lib on top of this low level bridge.

About Chrome and the not found methods, is the init() method found and works? I experienced some problems on the init method under Chrome, but if found all other was too. When the init method was not found in test.html page, a simple page reload (F5) often fix the issue. (I'm working on this issue).

Can you provide me your linux, Chrome, pcscd... version? and the exact sequence you do on the test.html page

C/M.

ubinity avatar Jun 24 '13 09:06 ubinity

I see the problem: if you allow the plugin to run by pressing "run this time", the "onLoad" event already fires and tries to call init. In order for the plugin to be loaded when onLoad is triggered, it's necessary to "always allow" the plugin... I'm not sure if there's an "onPluginInitiated" event or something similar you could hook into instead. A workaround could be to provide an "init plugin" button that is pressed manually and/or catch the typeerror in load() and display an error.

Cheers, -tim

System Details:

Chrome: 28.0.1500.52 Linux: Ubuntu 12.04 (in virtual box) $ pcscd -v pcsc-lite version 1.7.4. (default, installed using apt-get ...) Reader: Omnikey 5321

Loading test.html:

  • from server on 127.0.0.1:8080
  • Load url in Browser
  • Hit "Run this time"
  • Error appears in JS console

a2800276 avatar Jun 24 '13 11:06 a2800276

It seems that's it is not clear

... or I didn't read it :) ... I think what confused me was that the type indicators for other parameters were also in curly brackets (e.g. {number} ) and that establishContext was missing the closing parens.

Maybe the types would be easier to recognize like this: or in backticks

It would probably be a good idea to also refer to the test.html at the very top of the docs (and refer to the docs from the README) ...

If you would like help with any of these changes, let me know, I would be happy to lend a hand.

Cheers, -tim

a2800276 avatar Jun 24 '13 11:06 a2800276

I modified the doc to remove {} ambiguity and highlight cross references between README and doc I also modified the test.html according to your suggestion.

C/M.

ubinity avatar Jun 26 '13 10:06 ubinity