-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add btcd to the build process * Fixes * Add certs * Fix types * Get rid of buildConstants. It wasn't worth it. * Remove some Mempool value unsupported by btcd * Generate secure btcd RPC credentials and allow testnet through command line args * Handle waiting for btcd initialization on the UI * Disable Bcore-only code * Update README.md and SECURITY.md * Check-in windows binary * Fix Settings.test.ts * Fix other tests by mocking FeatureFlags and enabling Bcore in the tests * Test AwaitBtcd * Address PR review issues * Fix some TypeScript and btcd compatibility issues * Increase Jest tests timeout * Fix executable's name on Windows * Fix executable's name on Windows (take 2) * Fix executable's name on Windows (take 3)
- Loading branch information
Showing
40 changed files
with
506 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Security and Architecture | ||
|
||
Orange uses multiple processes. Some processes include npm modules while others | ||
don't. Orange is architected so that processes with npm modules are sandboxed | ||
and have very low access privileges. Processes with npm modules cannot make | ||
outbound or receive inbound connections except in a very tightly controlled | ||
manner. | ||
|
||
Only processes that don't use any 3rd party modules are allowed to communicate | ||
with Bitcoin Core. | ||
|
||
## Details on the architecture | ||
|
||
All Electron applications have 3 separate processes. The nature of these 3 | ||
processes is what enables the architecture described above. | ||
|
||
The 3 processes are called `main`, `renderer`, and `preload`. Each one of these | ||
processes is granted a different level of access privilege over the system, as | ||
described below. | ||
|
||
### The `main` process | ||
|
||
In Orange the `main` has full access over the system. It uses Node.js to talk to | ||
the file system and it can talk to the operating system. **Because `main` has | ||
this much privilege, we don't use npm modules in it.** | ||
|
||
`main` talks to Bitcoin Core. | ||
|
||
### The `renderer` process | ||
|
||
The `renderer` process is where the UI code is. | ||
|
||
The `renderer` process has no access to Node.js APIs, the filesystem, or any | ||
operating system features. The `renderer` process is also prohibited from: | ||
|
||
- making network requests | ||
- loading remote content (at run time) | ||
- opening webpages | ||
- navigating | ||
|
||
<details><summary>Some implementation details</summary> | ||
|
||
We implement the | ||
[security recommendations](https://electronjs.org/docs/tutorial/security?q=j#checklist-security-recommendations) | ||
provided by Electron. Many of these recommendations are particular to loading | ||
"remote content", that is content over the network. In Orange we disable | ||
networking completely, but we consider npm modules in the `renderer` process to | ||
be equivalent to "remote content" so we follow these recommendations as strictly | ||
as possible: | ||
|
||
- Node integration is disabled | ||
- Content isolation is enabled | ||
- Web security is enabled | ||
- A strict content security policy is provided | ||
- Running insecure content is disabled | ||
- No experimental Chromium or Blink features are used | ||
- WebView creation is disabled | ||
- Navigation is disabled | ||
- The remote module is disabled | ||
|
||
</details> | ||
|
||
### How does `renderer` get the data to display if it's sandboxed? | ||
|
||
This is where the `preload` process comes in. `preload` is the middleman between | ||
`main` and `renderer`. It relays messages between the two, but only very | ||
specific kinds of messages. | ||
|
||
### How is the communication between `renderer` and `main` secured? | ||
|
||
`main` and `renderer` use a nonce (i.e. password) to communicate with each | ||
other. This nonce is agreed upon between `main` and `renderer` only after all | ||
the npm modules have been downloaded, so remote code has no way of knowing what | ||
it is. | ||
|
||
<details><summary>Implementation details</summary> | ||
|
||
After the npm modules have been downloaded but before the Orange distributable | ||
is created, the string `__NONCE__` in the code will be replaced with a base64 | ||
encoded random bytes. Care has to be taken to make sure this nonce is only known | ||
to the local Orange code, not to the npm modules. | ||
|
||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const spawn = () => ({ | ||
on: () => null, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const featureFlags = { | ||
useBcore: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { getGlobalProcess } from "./getGlobalProcess"; | ||
|
||
export type Arguments = { | ||
datadir?: string; | ||
testnet?: string; | ||
}; | ||
|
||
const parseCommandLineArgs = () => { | ||
const globalProcess = getGlobalProcess(); | ||
const args = globalProcess.argv; | ||
const argsObj = args.reduce<Arguments>((obj, arg) => { | ||
const [name, value] = arg.split("="); | ||
|
||
/* istanbul ignore if */ | ||
if (name.substr(0, 2) === "--") { | ||
// eslint-disable-next-line no-param-reassign | ||
obj[name.substr(2) as keyof Arguments] = value || "true"; | ||
} | ||
|
||
return obj; | ||
}, {}); | ||
|
||
return argsObj; | ||
}; | ||
|
||
export const commandLineArgs = parseCommandLineArgs(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { randomBytes } from "crypto"; | ||
import { commandLineArgs } from "_m/commandLineArgs"; | ||
|
||
const username = randomBytes(16).toString("hex"); | ||
const password = randomBytes(16).toString("hex"); | ||
export const hostname = "127.0.0.1"; | ||
|
||
export const getBtcdRpcConfigurations = () => { | ||
let port = 8334; | ||
|
||
/* istanbul ignore if */ | ||
if (commandLineArgs.testnet) { | ||
port = 18334; | ||
} | ||
|
||
return { | ||
username, | ||
password, | ||
serverUrl: `http://${hostname}:${port}`, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.