property ${manifest.type} (expected ${type})` ); return null; } if (manifest.name !== name) { Cu.reportError( `Native manifest ${path} has name property ${manifest.name} (expected ${name})` ); return null; } if ( type === "stdio" && AppConstants.platform != "win" && !PathUtils.isAbsolute(manifest.path) ) { // manifest.path is defined for type "stdio" and "pkcs11". // stdio requires an absolute path on Linux and macOS, // pkcs11 also accepts relative paths. Cu.reportError( `Native manifest ${path} has relative path value ${manifest.path} (expected absolute path)` ); return null; } if ( manifest.allowed_extensions && !manifest.allowed_extensions.includes(context.extension.id) ) { Cu.reportError( `This extension does not have permission to use native manifest ${path}` ); return null; } return manifest; }, async _tryPath(type, path, name, context, logIfNotFound) { let manifest; try { manifest = await IOUtils.readJSON(path); } catch (ex) { if (ex instanceof SyntaxError && ex.message.startsWith("JSON.parse:")) { Cu.reportError(`Error parsing native manifest ${path}: ${ex.message}`); return null; } if (DOMException.isInstance(ex) && ex.name == "NotFoundError") { if (logIfNotFound) { Cu.reportError( `Error reading native manifest file ${path}: file is referenced in the registry but does not exist` ); } return null; } Cu.reportError(ex); return null; } manifest = await this.parseManifest(type, path, name, context, manifest); return manifest; }, async _tryPaths(type, name, dirs, context) { for (let dir of dirs) { let path = PathUtils.join(dir, TYPES[type], `${name}.json`); let manifest = await this._tryPath(type, path, name, context, false); if (manifest) { return { path, manifest }; } } return null; }, /** * Search for a valid native manifest of the given type and name. * The directories searched and rules for manifest validation are all * detailed in the Native Manifests documentation. * * @param {string} type The type, one of: "pkcs11", "stdio" or "storage". * @param {string} name The name of the manifest to search for. * @param {object} context A context object as expected by Schemas.normalize. * @returns {object} The contents of the validated manifest, or null if * no valid manifest can be found for this type and name. */ lookupManifest(type, name, context) { return this.init().then(() => this._lookup(type, name, context)); }, }; PK