Skip to content

Conversation

@FabianScheidt
Copy link

Hi!

I came across a problem when using your library in a web server running inside of iisnode. It turns out that by default the IIS application pool identity is configured to not load a user profile. Therefore it is unable to access the certificate store. Since the error of Crypt32 is not handled properly, it causes the node process to crash without any error message in a subsequent ffi-call. This PR attempts to fix that behaviour:

CertOpenSystemStoreA returns null when it fails (see here). As stated before, this can e.g. be due to insufficient access rights to the certificate store. However, ffi returns a buffer whose truthiness will always be true. To properly catch the error and prevent the application from crashing, we need to check for null using the ref package as done with the other call to Crypt32.

My changes avoid application crashes. However, I think we should actually throw an appropriate error that can be handled by the application that uses the library. I'm happy to add that. Just let me know your thoughts!

Greetings,
Fabian

@btsimonh
Copy link
Owner

Hi Fabian,
Glad the repo is of some use! I wrote it some time ago because of stupid WAF users, but actually have very little experience of it (I have no cert issues of my own, and actually never took this to production). I will merge any PRs you feel appropriate (just let me know when you feel they are complete), and it will benefit from your real world experience.
Let me know if you ant me to merge as-is or await mods for passing the error up....
Simon

CertOpenSystemStoreA returns null when it fails. This can e.g. be due to
insufficient access rights to the certificate store. However, ffi
returns a buffer whose truthiness will always be true. To properly catch
the error and prevent the application from crashing, we need to check for
null using the ref package.
@FabianScheidt
Copy link
Author

Hi Simon,

thanks for looking at my changes! The fact that you are not using the library yourself gives me extra confidence to put this into production 😉

Joking aside: I am building a web application that has to run on a windows server and should communicate with some other internal components, that make use of corporate certificates. I looked at some other libraries that try to solve similar problems, but yours looks most straight forward to me. Since I found my configuration problem in IIS, it seems to work great so far.

As mentioned, I tweaked my code to actually throw an error when the certificate store can not be opened. I bumped the version in the package.json, so you can push it straight to npm. I think this is good enough for now, so feel free to merge the changes.

Thanks again!
Fabian

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