docs: Update the certificate APIs
This commit is contained in:
parent
c5bfac1969
commit
9ca022c98a
4 changed files with 84 additions and 26 deletions
|
@ -252,7 +252,7 @@ void App::AllowCertificateError(
|
|||
bool prevent_default = Emit("certificate-error",
|
||||
WebContents::CreateFrom(isolate(), web_contents),
|
||||
request_url,
|
||||
cert_error,
|
||||
net::ErrorToString(cert_error),
|
||||
ssl_info.cert,
|
||||
callback);
|
||||
|
||||
|
|
|
@ -131,6 +131,35 @@ Returns:
|
|||
|
||||
Emitted when a new [browserWindow](browser-window.md) is created.
|
||||
|
||||
### Event: 'certificate-error'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `webContents` [WebContents](web-contents.md)
|
||||
* `url` URL
|
||||
* `error` String - The error code
|
||||
* `certificate` Object
|
||||
* `data` Buffer - PEM encoded data
|
||||
* `issuerName` String
|
||||
* `callback` Function
|
||||
|
||||
Emitted when failed to verify the `certificate` for `url`, to trust the
|
||||
certificate you should prevent the default behavior with
|
||||
`event.preventDefault()` and call `callback(true)`.
|
||||
|
||||
```javascript
|
||||
session.on('certificate-error', function(event, webContents, url, error, certificate, callback) {
|
||||
if (url == "https://github.com") {
|
||||
// Verification logic.
|
||||
event.preventDefault();
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Event: 'select-client-certificate'
|
||||
|
||||
Returns:
|
||||
|
|
|
@ -34,31 +34,6 @@ session.on('will-download', function(event, item, webContents) {
|
|||
});
|
||||
```
|
||||
|
||||
### Event: 'untrusted-certificate'
|
||||
|
||||
* `event` Event
|
||||
* `hostname` String
|
||||
* `certificate` Object
|
||||
* `data` Buffer - PEM encoded data
|
||||
* `issuerName` String
|
||||
* `callback` Function
|
||||
|
||||
Emitted when failed to verify the `certificate` for `hostname`, to trust the
|
||||
certificate you should prevent the default behavior with
|
||||
`event.preventDefault()` and call `callback(true)`.
|
||||
|
||||
```js
|
||||
session.on('verify-certificate', function(event, hostname, certificate, callback) {
|
||||
if (hostname == "github.com") {
|
||||
// Verification logic.
|
||||
event.preventDefault();
|
||||
callback(true);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
The `session` object has the following methods:
|
||||
|
@ -245,3 +220,24 @@ window.webContents.session.enableNetworkEmulation({offline: true});
|
|||
|
||||
Disables any network emulation already active for the `session`. Resets to
|
||||
the original network configuration.
|
||||
|
||||
### `session.setCertificateVerifyProc(proc)`
|
||||
|
||||
* `proc` Function
|
||||
|
||||
Sets the certificate verify proc for `session`, the `proc` will be called with
|
||||
`proc(hostname, certificate, callback)` whenever a server certificate
|
||||
verification is requested. Calling `callback(true)` accepts the certificate,
|
||||
calling `callback(false)` rejects it.
|
||||
|
||||
Calling `setCertificateVerifyProc(null)` will revert back to default certificate
|
||||
verify proc.
|
||||
|
||||
```javascript
|
||||
myWindow.webContents.session.setCertificateVerifyProc(function(hostname, cert, callback) {
|
||||
if (hostname == 'github.com')
|
||||
callback(true);
|
||||
else
|
||||
callback(false);
|
||||
});
|
||||
```
|
||||
|
|
|
@ -167,6 +167,39 @@ Emitted when DevTools is closed.
|
|||
|
||||
Emitted when DevTools is focused / opened.
|
||||
|
||||
### Event: 'certificate-error'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `url` URL
|
||||
* `error` String - The error code
|
||||
* `certificate` Object
|
||||
* `data` Buffer - PEM encoded data
|
||||
* `issuerName` String
|
||||
* `callback` Function
|
||||
|
||||
Emitted when failed to verify the `certificate` for `url`.
|
||||
|
||||
The usage is the same with [the `certificate-error` event of
|
||||
`app`](app.md#event-certificate-error).
|
||||
|
||||
### Event: 'select-client-certificate'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `url` URL
|
||||
* `certificateList` [Objects]
|
||||
* `data` Buffer - PEM encoded data
|
||||
* `issuerName` String - Issuer's Common Name
|
||||
* `callback` Function
|
||||
|
||||
Emitted when a client certificate is requested.
|
||||
|
||||
The usage is the same with [the `select-client-certificate` event of
|
||||
`app`](app.md#event-select-client-certificate).
|
||||
|
||||
### Event: 'login'
|
||||
|
||||
Returns:
|
||||
|
|
Loading…
Reference in a new issue