Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy chrome.pkcs11 extension api #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>ping://settings/exte
<message name="IDS_EXTENSION_PROMPT_WARNING_IPFS_PRIVATE" desc="Permisson string for access to private ipfs api.">
Read and modify IPFS settings
</message>
<message name="IDS_EXTENSION_PROMPT_WARNING_PKCS11" desc="Permisson string for access to PKCS11 api.">
Sign documents using a hardware security module
</message>
<message name="IDS_LOCATION_BAR_ONION_AVAILABLE" desc="Button in location bar to indicate onion available site to open a new tab in tor window.">
.onion
</message>
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ source_set("extensions") {
"brave_theme_event_router.h",
"updater/brave_update_client_config.cc",
"updater/brave_update_client_config.h",
"api/pkcs11_api.cc",
"api/pkcs11_api.h",
]

deps = [
Expand Down
46 changes: 46 additions & 0 deletions browser/extensions/api/pkcs11_api.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/extensions/api/pkcs11_api.h"

#include <memory>
#include <string>

#include "base/logging.h"
#include "base/json/json_writer.h"
#include "base/values.h"
#include "brave/common/extensions/api/pkcs11.h"

namespace extensions {
namespace api {

ExtensionFunction::ResponseAction Pkcs11InstallModuleFunction::Run() {
absl::optional<pkcs11::InstallModule::Params> params =
pkcs11::InstallModule::Params::Create(args());
EXTENSION_FUNCTION_VALIDATE(params);

LOG(INFO) << "Setting path: " << params->path << " for PKCS11 module.";

return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction Pkcs11SetPinFunction::Run() {
absl::optional<pkcs11::SetPin::Params> params =
pkcs11::SetPin::Params::Create(args());
EXTENSION_FUNCTION_VALIDATE(params);

LOG(INFO) << "Setting pin: " << params->pin << " for PKCS11 login.";

return RespondNow(NoArguments());
}

ExtensionFunction::ResponseAction Pkcs11GetSignatureFunction::Run() {
const std::string signature = "sample_signature";

return RespondNow(WithArguments(signature));
}

} // namespace api
} // namespace extensions
47 changes: 47 additions & 0 deletions browser/extensions/api/pkcs11_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_EXTENSIONS_API_PKCS11_API_H_
#define BRAVE_BROWSER_EXTENSIONS_API_PKCS11_API_H_

#include "extensions/browser/extension_function.h"

namespace extensions {
namespace api {

class Pkcs11InstallModuleFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("pkcs11.installModule", UNKNOWN)

protected:
~Pkcs11InstallModuleFunction() override {}

ResponseAction Run() override;
};

class Pkcs11SetPinFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("pkcs11.setPin", UNKNOWN)

protected:
~Pkcs11SetPinFunction() override {}

ResponseAction Run() override;
};

class Pkcs11GetSignatureFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("pkcs11.getSignature", UNKNOWN)

protected:
~Pkcs11GetSignatureFunction() override {}

ResponseAction Run() override;
};

} // namespace api
} // namespace extensions

#endif // BRAVE_BROWSER_EXTENSIONS_API_PKCS11_API_H_
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ constexpr APIPermissionInfo::InitInfo brave_permissions_to_register[] = {
{APIPermissionID::kIpfs, "ipfs",
APIPermissionInfo::kFlagImpliesFullURLAccess},
{APIPermissionID::kIpfsPrivate, "ipfsPrivate",
APIPermissionInfo::kFlagImpliesFullURLAccess}};
APIPermissionInfo::kFlagImpliesFullURLAccess},
{APIPermissionID::kPkcs11, "pkcs11"},
};

// Merges Brave and Chrormium constant arrays to final list of permissions.
template <typename T, size_t N>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ChromePermissionMessageRule::GetAllRules() {
rules.push_back({IDS_EXTENSION_PROMPT_WARNING_IPFS_PRIVATE,
{APIPermissionID::kIpfsPrivate},
{}});
rules.push_back({IDS_EXTENSION_PROMPT_WARNING_PKCS11,
{APIPermissionID::kPkcs11},
{}});
return rules;
}

Expand Down
3 changes: 2 additions & 1 deletion chromium_src/extensions/common/mojom/api_permission_id.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module extensions.mojom;
[BraveExtend]
enum APIPermissionID {
kIpfs = 750,
kIpfsPrivate = 751
kIpfsPrivate = 751,
kPkcs11 = 911
};
1 change: 1 addition & 0 deletions common/extensions/api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ brave_extensions_api_schema_sources = [
"brave_theme.json",
"greaselion.json",
"rewards_notifications.json",
"pkcs11.json"
]

if (enable_ipfs) {
Expand Down
6 changes: 5 additions & 1 deletion common/extensions/api/_api_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,9 @@
"matches": [
"chrome://newtab/*"
]
}]
}],
"pkcs11": {
"dependencies": ["permission:pkcs11"],
"contexts": ["blessed_extension"]
}
}
5 changes: 5 additions & 0 deletions common/extensions/api/_permission_features.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
"allowlist": [
"21070F3D60711361C1210B870439BE49B5D995F4" // Ethereum Remote Client extension
]
},
"pkcs11": {
"channel": "stable",
"extension_types": ["extension", "legacy_packaged_app"]
}
}

58 changes: 58 additions & 0 deletions common/extensions/api/pkcs11.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

[
{
"namespace": "pkcs11",
"description": "Use the <code>chrome.pkcs11</code> API to sign data using crypto token",
"compiler_options": {
"implemented_in": "brave/browser/extensions/api/pkcs11_api.h"
},
"functions": [
{
"name": "installModule",
"type": "function",
"description": "Set PKCS11 module path",
"parameters": [
{
"name": "path",
"type": "string",
"description": "system path of PKCS11 library"
}
]
},
{
"name": "setPin",
"type": "function",
"description": "Set pin to login into crypto token",
"parameters": [
{
"name": "pin",
"type": "string",
"description": "Pin to login into crypto token"
}
]
},
{
"name": "getSignature",
"type": "function",
"description": "Get signature for signed document",
"parameters": [
{
"name": "callback",
"type": "function",
"description": "Function called when signature for document is fetched",
"parameters": [
{
"name": "signature",
"type": "string",
"description": "signed signature"
}
]
}
]
}
]
}
]
Loading