Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Select Certificate

Post Reply
maerciops
Posts: 4
Joined: Tue Sep 03, 2024 2:47 pm

Select Certificate

Post by maerciops »

In Chrome, when you select a certificate, you can change just when you restart the browser. The event OnSelectCertificate is called just a once time. How can I could do select certificate in chromium many times in the same Formulary?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Select Certificate

Post by salvadordf »

Hi,

Set the GlobalCEFApp.Cache property to a writable directory and use the TChromiumCore.OnSelectClientCertificate event to select a certificate automatically.

The MiniBrowser demo has the code to let the user select a certificate but you can modify it to select it automatically :
https://github.com/salvadordf/CEF4Delphi/blob/55a70a998eeeb5dbba2e8e1db36902ffcc40ebfc/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1368
maerciops
Posts: 4
Joined: Tue Sep 03, 2024 2:47 pm

Re: Select Certificate

Post by maerciops »

I used the MiniBrowser Demo to select certificate, but my problem is when I select a certificate a once, in the next time if I need select another certificate don't work. If I want, I need to close the form and recreate it. I'll explain the steps:

- Creates the form. This form create GlobalCefApp, e so create the chromium.
- Loads URL Default.
- My customer select download to download a XML refer to a government document.
- In the first time he select the certificate, because is the way to site auth his credentials.
- So if his want download another XML to another company where the certificate is different don't work, because the first certificate selected stays.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Select Certificate

Post by salvadordf »

Try calling ClearDataForOrigin to clear the storage data for a given origin.

Code: Select all

TChromiumCore.ClearDataForOrigin('https://www.mywebsite.com', cdstAll);
This is an asynchronous function that triggers the TChromiumCore.OnDevToolsMethodResult event when it finishes executing.
maerciops
Posts: 4
Joined: Tue Sep 03, 2024 2:47 pm

Re: Select Certificate

Post by maerciops »

Yeah, I tested this method in Demo MiniBrowser: https://github.com/salvadordf/CEF4Delphi/blob/16639d5ea5d5c6d5fddaa4c771504abb4fbb7641/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1373

The ClearCache and ClearDataForOrigin but no one worked. I'm breaking my head, just works when I close the form and recreate them, Idon't know what I do. In the IE, when we used the TWEBBrowser the script "document.execCommand("ClearAuthenticationCache");" was working, but the engine of the Chromium is totally different. If you have more tips, I apreciate.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Select Certificate

Post by salvadordf »

Create an independent browser with a new request context that uses a different cache directory.

See the MDIBrowser code :
https://github.com/salvadordf/CEF4Delphi/blob/55a70a998eeeb5dbba2e8e1db36902ffcc40ebfc/demos/Delphi_VCL/MDIBrowser/uChildForm.pas#L164
maerciops
Posts: 4
Joined: Tue Sep 03, 2024 2:47 pm

Re: Select Certificate

Post by maerciops »

It's works, but the method is same. A ChildForm need to be closed to work in another ChildForm. So is the same way, a form need to be closed to it works. I tested with a ChildForm embedded in another form but the process is not closed totally so the spend of memory is huge if the customer stays clicking in new browser.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Select Certificate

Post by salvadordf »

That's the recommended way in this case :
https://stackoverflow.com/questions/66521061/requesting-client-certificate-a-second-time-with-cefsharp

Chromium should eventually stop those unused processes.
Post Reply