Add support for SSL Client Authentication
Currently phantomjs is not able to provide a client certificate for secured pages. I think the QT code is able to create SSL sockets using a client key and certificate. The only missing part is some configuration options and some handling to feed the QSslConfiguration.
I propose some configuration options like:
--ssl-client-certificate-file Similar to --ssl-certificates-path, but should just point to a single certificate file. As PEM seems to be used as format, the certificate file might contain a secret key as well.
--ssl-client-key-file Needed in case client certificate file does not contain a key.
--ssl-client-key-passphrase The passphrase to decode the secret key.
A preview of the patch can be found at https://github.com/ffray/phantomjs/tree/ssl-client-auth.
what's left? is this good for a pull request?
Hi Tristan,
sorry for being late on your comment! I think the fix is ok, but maybe one might want to review that code first, as I didn't write any code in C / C++ for almost 8 years and I'm totally unaware of the used libraries. Any hints on whether the code is OK or needs some changes is welcome.
Best regards,
Florian
i am newbie to phantomjs and would like to know how to set the --ssl-certificates-path option. Essentially I have my CA certificate as a .cer file in my local system file structure. Do i need to set the absolute file path for my .cer file for this option. I could not find much information on the value for this option. Any help or pointer is highly appreciated.
Thank you ffray. I need so much these functionalities.
@ariya any reason not to merge this? Would love to see this in the next release of PhantomJS!
Unfortunately without this feature I cannot use PhantomJS on my project.
Hi, can someone review the code and merge this PR please!! It's more then 2 years since it has been submitted. @ariya Can you have a look?
Thank you! Landed in https://github.com/ariya/phantomjs/commit/54a54dc0687a4b93562285d4f632dcafe2c7bf4f!
Could you please add an example to use the feature ?
Still not merged into main branch, no releases with this patch to get it tested either.. any chance someone could compile this and let us test it?
It is in the master branch - https://github.com/ariya/phantomjs/commit/e4c0d9fa5c3da1148d17c758e2f6cc54560ba4ca
With the latest windows download (downloaded earlier today) of version 2.0.0. using these new options generates errors: "Error: Unknown option: ssl-client-certificates-file", the options also do not display with --help parameters and neither are they listed on http://phantomjs.org/api/command-line.html
The file was compiled on 4th february this year - i'll guess the compiled versions have not yet been updated? is there a bleeding edge release i can find anywhere?
@JernejL yes, this feature will be in 2.0.1 release. You can find nightly build for Windows here - https://www.dropbox.com/sh/e70k5w2ymq4m417/AAAVK-w_CPO6DX_-AZWP6TRka?dl=0 I update it once per week.
Sorry for being a pain, but is there any chance to get 2.0.1. earlier? i would really need it and will be able to help out with testing the features before release too.
Edit: i got the link, testing now.
Vitallium: thank you, i've done some testing and came to some possible bug / issue:
2015-08-07T09:19:20 [DEBUG] Network - Resource request error: 99 ( "Unable to init SSL Context: " ) URL: "https://removed"
command line:
phantomjs.exe --ignore-ssl-errors=true --cookies-file=R:\phantom\bin\cookies.txt --ssl-certificates-path=R:\phantom\bin --ssl-client-certificate-file=R:\phantom\bin\cert.crt --debug=true test.js
debug shows the ssl section properly:
2015-08-07T09:26:09 [DEBUG] 18 sslProtocol : "default" 2015-08-07T09:26:09 [DEBUG] 19 sslCiphers : "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:DH E-RSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:RC4-SHA:RC4-MD5" 2015-08-07T09:26:09 [DEBUG] 20 sslCertificatesPath : "R:\phantom\bin/*" 2015-08-07T09:26:09 [DEBUG] 21 sslClientCertificateFile : "R:\phantom\bin\cert.crt" 2015-08-07T09:26:09 [DEBUG] 22 sslClientKeyFile : "" 2015-08-07T09:26:09 [DEBUG] 23 sslClientKeyPassphrase : ""
User and all other certificates are base64 encoded PEM files.
I've followed the error to this: http://stackoverflow.com/questions/14989135/qt-downloading-a-file-doesnt-work And then downloaded this + put it into phantomjs bin folder: https://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8k_WIN32.zip&can=2&q=
I copied the dlls and it did not appear to change anything.
Using process monitor i can see phantomjs reading the certificate file i specified, but it does not appear to attempt to read any other ssl certificates in the directory.
However in debug one thing stands out - "sslCertificatesPath : "R:\phantom\bin/*"" shows a forward slash instead of backslash in the end, if i specify --ssl-certificates-path=R:\phantom\bin or --ssl-certificates-path=R:\phantom\bin\ in both cases it'll output a forward slash in the debug output - perhaps this could be a issue / bug in windows build and causes it to not be able to iterate the target directory for certificates?
Could you please file a new issue?
Done: https://github.com/ariya/phantomjs/issues/13472