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

Added hasBackend() method to check if functioning backend is available, returns backend info on success #7

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

Conversation

martinrebane
Copy link

No description provided.

@martinpaljak
Copy link
Contributor

You can use debug() for the same purpose, but keep in mind that the presence of a backend implementation does not mean that there is a possibility to get a signature: for example, a plugin with PKCS#11 implementation (Linux, OSX) can fail if there is no PKCS#11 component installed and would currently fail while asking for a certificate. You can check if debug() does not contain "No implementation" as a workaround, I don't think that the API needs to grow a method of checking for implementation.

@martinpaljak
Copy link
Contributor

Would looking for a needle in the debug() string be sufficient for your use case?

@martinrebane
Copy link
Author

Yes, checking for the needle would work, this was my first idea:

hwcrypto.debug().then(
            function (result) {
                        if (result.indexOf("No implementation") > -1) {
                                   console.log("No real backend..");
                        }
            },
            function (err) {
                        console.log(err);
            }
);

But this code looks like (and is) an ugly hack because hwcrypto provides backend of type NoBackend if there is no real backend. I would have to search for error condition in the happy path (success scenario).

Other thing is that if hwcrypto debug() method should change some day, this code will break and whoever debugs it, will loose lots of hair as it would fail silently. This behavior is not reflected in the API.

The reason why we would like to see such probing function is customer service. If we can decently detect whether a real backend is available or not, then half of the problems could be solved by clients themselves (we can give them exact error message and HOWTO) and 95% of signing related client support requests could be solved by customer support. Cases where they have browser backend, but PKCS#11 component is not installed, would be automatically separated from cases where there is no backend.

Technically yes, it would not make much sense to add such method, but from user's perspective exact and timely error message is as important as signing itself.

@martinpaljak
Copy link
Contributor

Okay. "Having timely and exact error messages" is a requirement that makes sense.

From technical perspective: debug() is supposed to always resolve to a string. What about adding a "documented / recommended way of detecting something"? A "check" method for the publicly stable API is not what I would like to add, it could be an "internal method" (like debug()) but then again, it could be a documented way of using an existing API to get the same result. Adding a "check() -> boolean" internal method that does the same could also be a possibility, to save integrators from typing.

@martinrebane
Copy link
Author

Yes, documented internal method would be fine. Code would also be much cleaner than just using string search.

@martinpaljak martinpaljak added this to the 0.1.0 milestone Jan 25, 2017
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.

2 participants