Giter Site home page Giter Site logo

bat-client's People

Contributors

bsclifton avatar diracdeltas avatar evq avatar fardog avatar mrose17 avatar nejczdovc avatar riastradh-brave avatar ryanml avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bat-client's Issues

bat-client requires seed type of Uint8Array if provided via state on init

Currently storage and (de)serialization of bat-client state, is handled by browser-laptop. Unfortunately this means we are exposing some internal concerns to browser-laptop.

One such concern is that the cryptographic seed is internally stored as a Uint8Array. Standard JSON serialization via JSON.stringify/JSON.parse is not invertible on Uint8Array objects. Since browser-laptop uses JSON.stringify for storing the seed, it needs to perform conditional fixup to ensure that it passes a Uint8Array to bat-client on init. https://github.com/brave/browser-laptop/blob/f6992aadba9c681302fe1cec3d0e28e222b3f62c/app/browser/api/ledger.js#L1590

That fixup is not currently being performed during restore of newClient which is used for continuing transition from BTC->BAT, causing brave/browser-laptop#11673

security checks are failing

npm run test shows a security error:

> nsp check

(+) 1 vulnerabilities found
┌───────────────┬─────────────────────────────────────────────────────────────┐
│               │ Large gzip Denial of Service                                │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Name          │ superagent                                                  │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ CVSS          │ 3.7 (Low)                                                   │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Installed     │ 3.5.2                                                       │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Vulnerable    │ <3.7.0                                                      │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Patched       │ >=3.7.0                                                     │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ Path          │ [email protected] > [email protected] > [email protected]          │
├───────────────┼─────────────────────────────────────────────────────────────┤
│ More Info     │ https://nodesecurity.io/advisories/479                      │
└───────────────┴─────────────────────────────────────────────────────────────┘

public key recovery may be unsafe (depends on buffer allocation method)

publicKey: self.uint8tohex(new Uint8Array(Buffer.from(octets.buffer, octets.length / 2)))

the correctness of this code depends on how Niceware does buffer allocation. for instance, this works the way we want it to:

var n = Buffer.alloc(4)
new Uint8Array(Buffer.from(n.buffer, n.length / 2)) // returns Uint8Array [ 0, 0 ] as expected

however, this code gives completely different results:

 n = new Buffer([0,0,0,0])
new Uint8Array(Buffer.from(n.buffer, n.length / 2)) // returns a 8190 length Uint8Array!

this is because the .buffer property refers to the ArrayBuffer property referenced by the Buffer at construction time. In the latter case, .buffer is the internal memory pool of the Buffer, which has default size 8192 bytes in node.

since Niceware's buffer allocation may change at any time, this code should not depend on it working the way it does right now.

Handle BAT-client recovery failure

Description

Handle BAT-client recovery failure

Steps to Reproduce

  1. Install/upgrade to 0.19.39
  2. Launch brave from console with LEDGER_VERBOSE=true
  3. Ensure wallet is created
  4. Click advanced setting, recover your wallet
  5. Don't enter any values, click recover, ensure recovery failed message is showed, console logs the error

Actual result:

[ response for GET https://ledger.mercury.basicattentiontoken.org/v2/wallet/941ec251-3187-41fc-b10b-13bd62f6e2df?balance=true&refresh=true&amount=25&altcurrency=BAT ]
>>> HTTP/1.1 503
>>> cache-control: no-cache, no-store
>>> connection: keep-alive
>>> content-length: 506
>>> content-type: text/html; charset=utf-8
>>> date: Wed, 11 Oct 2017 07:33:19 GMT
>>> server: Cowboy
>>>
>>> <!DOCTYPE html>
>>>     <html>
>>>       <head>
>>>             <meta name="viewport" content="width=device-width, initial-scale=1">
>>>             <meta charset="utf-8">
>>>             <title>Application Error</title>
>>>             <style media="screen">
>>>               html,body,iframe {
>>>                     margin: 0;
>>>                     padding: 0;
>>>               }
>>>               html,body {
>>>                     height: 100%;
>>>                     overflow: hidden;
>>>               }
>>>               iframe {
>>>                     width: 100%;
>>>                     height: 100%;
>>>                     border: 0;
>>>               }
>>>             </style>
>>>       </head>
>>>       <body>
>>>             <iframe src="//www.herokucdn.com/error-pages/application-error.html"></iframe>
>>>       </body>
>>>     </html>
+++ busyP=true
<<< GET https://mercury-proxy.privateinternetaccess.com/v2/surveyor/voting/FSgBEh6UD%2Fw3Akir95Fz5h8n5Un6n%2FxudYsegnqkxAF/6a0af783a6240d18354e414b4e7beb9
<<< content-type: application/json; charset=utf-8
<<< accept-encoding:
<<<

Expected result:
Should handle the recovery scenario properly
Reproduces how often: [What percentage of the time does it reproduce?]
100%

Brave Version

about:brave info:

Brave 0.19.39
rev ebcd280
Muon 4.4.27

Reproducible on current live release:

N/A

Additional Information

cc : @evq @NejcZdovc @mrose17

set up travis

this repo now has tests! it should run the tests and require passing tests for merge

422 - persona credential exists

Per brave/browser-laptop#11495 (comment)
Ran into an issue while testing that PR... Here's what I did:

  • created branch new v1 wallet using Brave 0.18.x
  • switch to the PR branch / rm node_modules / npm install / etc and pointed it at the 0.18.x session
  • wallet upgrade shows as in progress 👍
  • I quit and relaunched a few times- I verified that ledger-newstate.json gets persisted before and after after sync 👍
  • I seem to be getting an error now, HTTP code 422
<<< POST https://ledger.mercury.basicattentiontoken.org/v2/registrar/persona/1ed2a2b0748089c8ccd81e7dac8c893
<<< content-type: application/json; charset=utf-8
<<< accept-encoding:
<<<
<<< {
<<<   "requestType": "httpSignature",
<<<   "request": {
<<<     "headers": {
<<<       "digest": "SHA-256=oe2fifEDcfI96boPcKaUUhe/HKWiuzyoBs10Gm+S4bg=",
<<<       "signature": "keyId=\"primary\",algorithm=\"ed25519\",headers=\"digest\",signature=\"vglrshpOIBjtoW6OBmW70pH7/RFK7vwzY+a3a9rDdwGxIU9VTBgj0Snm2AEHrqQUuR3mA+EX817oh/z/607FCg==\""
<<<     },
<<<     "body": {
<<<       "label": "4123099f-47e4-48ad-bc9f-6cdffebd81ed",
<<<       "currency": "BAT",
<<<       "publicKey": "429fb47298b7b058030c3d1bca1ca587585a81b1e47f0ecc9436e04306210043"
<<<     },
<<<     "octets": "{\"currency\":\"BAT\",\"label\":\"4123099f-47e4-48ad-bc9f-6cdffebd81ed\",\"publicKey\":\"429fb47298b7b058030c3d1bca1ca587585a81b1e47f0ecc9436e04306210043\"}"
<<<   },
<<<   "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.basicattentiontoken.org/v2/registrar/persona/1ed2a2b0748089c8ccd81e7dac8c893 ]
>>> HTTP/1.1 422
>>> cache-control: no-cache
>>> connection: keep-alive
>>> content-length: 120
>>> content-type: application/json; charset=utf-8
>>> date: Fri, 13 Oct 2017 06:02:22 GMT
>>> server: Cowboy
>>> vary: accept-encoding
>>> via: 1.1 vegur
>>> x-rate-limit-limit: 60
>>> x-rate-limit-remaining: 59
>>> x-rate-limit-reset: 1507874601
>>>
>>> {"statusCode":422,"error":"Unprocessable Entity","message":"persona credential exists: 1ed2a2b0748089c8ccd81e7dac8c893"}
ledger client error(3): {}
Error: HTTP response 422 for POST /v2/registrar/persona/1ed2a2b0748089c8ccd81e7dac8c893
    at request.request (/Users/clifton/Documents/browser-laptop/app/browser/api/ledger.js:1491:9)
    at Function.defaultSession.webRequest.fetch (/Users/clifton/Documents/browser-laptop/js/lib/request.js:55:5)

look for HTTP code 410 in response to PUT /v2/wallet/{paymentId}

if the PUT call to /v2/wallet/{paymentId} sees HTTP code 410 immediately prior to https://github.com/brave-intl/bat-client/blob/master/index.js#L936 this indicates that the earlier call at https://github.com/brave-intl/bat-client/blob/master/index.js#L936 to get the current surveyor information is no longer valid.

instead of invoking the callback with an error, the client should fetch the new current surveyor and try again. however, to avoid looping, it should do this at most once.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.