@ankitp5/capacitor-ssl-pinning
Version:
Check/pin SSL certificates
79 lines (72 loc) • 3.63 kB
JavaScript
var capacitorSSLCertificateChecker = (function (exports, core) {
'use strict';
/**
* Import the `registerPlugin` method from the Capacitor core library.
* This method is used to register a custom plugin.
*/
/**
* Register the `SSLCertificateChecker` plugin.
* - The first argument is the plugin's name as used in native platforms.
* - The second argument is an optional configuration object, where a web implementation is dynamically imported.
*/
const SSLCertificateChecker = core.registerPlugin('SSLCertificateChecker', {
/**
* Provide a web implementation of the `SSLCertificateChecker` plugin.
* The implementation is dynamically imported to optimize performance.
* @returns A promise that resolves to an instance of `SSLCertificateCheckerWeb`.
*/
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.SSLCertificateCheckerWeb()),
});
/**
* This module provides a web implementation of the SSLCertificateCheckerPlugin.
* The functionality is limited in a web context due to the lack of SSL certificate inspection capabilities in browsers.
*
* The implementation adheres to the SSLCertificateCheckerPlugin interface but provides fallback behavior
* because browsers do not allow direct inspection of SSL certificate details.
*/
/**
* Web implementation of the SSLCertificateCheckerPlugin interface.
*
* This class is intended to be used in a browser environment and handles scenarios where SSL certificate
* checking is unsupported. It implements the methods defined by the SSLCertificateCheckerPlugin
* interface but returns standardized error responses to indicate the lack of functionality in web contexts.
*/
class SSLCertificateCheckerWeb extends core.WebPlugin {
/**
* Checks the SSL certificate for a given URL.
*
* This method is a placeholder for SSL certificate validation functionality.
* In a web environment, this is not supported due to browser security restrictions.
*
* @param options - An object containing the `url` to check.
* Example: `{ url: 'https://example.com' }`
*
* @returns A promise that rejects with a standardized error message indicating
* that the method is not implemented.
*
* @throws {CapacitorException} Always throws an exception with code `Unimplemented`.
*/
async checkCertificate(options) {
// Always throw an error since the feature is unavailable in this context.
throw this.createUnimplementedError();
}
/**
* Creates a standardized exception for unimplemented methods.
*
* This utility method centralizes the creation of exceptions for functionality that is not supported
* on the current platform, ensuring consistency in error reporting.
*
* @returns {CapacitorException} An exception with the code `Unimplemented` and a descriptive message.
*/
createUnimplementedError() {
return new core.CapacitorException('This plugin method is not implemented on this platform.', core.ExceptionCode.Unimplemented);
}
}
var web = /*#__PURE__*/Object.freeze({
__proto__: null,
SSLCertificateCheckerWeb: SSLCertificateCheckerWeb
});
exports.SSLCertificateChecker = SSLCertificateChecker;
return exports;
})({}, capacitorExports);
//# sourceMappingURL=plugin.js.map