git ssb

16+

cel / patchfoo



Commit fc800407c0f45352ee533769fe96a8c339501a34

Decrypt message with unbox key query parameter

cel committed on 10/2/2018, 8:03:58 AM
Parent: 7ef25848b38465fe70b65ab91bf905ae927d4d7c

Files changed

lib/app.jschanged
lib/render.jschanged
lib/serve.jschanged
package.jsonchanged
lib/app.jsView
@@ -6,8 +6,9 @@
66 var pull = require('pull-stream')
77 var multicb = require('multicb')
88 var paramap = require('pull-paramap')
99 var Contacts = require('ssb-contact')
10 +var PrivateBox = require('private-box')
1011 var About = require('./about')
1112 var Follows = require('./follows')
1213 var Serve = require('./serve')
1314 var Render = require('./render')
@@ -103,13 +104,29 @@
103104 var logPrefix = '[' + pkg.name + ']'
104105 App.prototype.log = console.log.bind(console, logPrefix)
105106 App.prototype.error = console.error.bind(console, logPrefix)
106107
107-App.prototype.unboxMsg = function (msg, cb) {
108 +App.prototype.unboxContentWithKey = function (content, key, cb) {
109 + if (!key) return this.unboxContent(content, cb)
110 + var data
111 + try {
112 + var contentBuf = new Buffer(content.replace(/\.box.*$/, ''), 'base64')
113 + var keyBuf = new Buffer(key, 'base64')
114 + console.error(key, keyBuf.length)
115 + data = PrivateBox.multibox_open_body(contentBuf, keyBuf)
116 + if (!data) return cb(new Error('failed to decrypt'))
117 + data = JSON.parse(data.toString('utf8'))
118 + } catch(e) {
119 + return cb(new Error(e.stack || e))
120 + }
121 + cb(null, data)
122 +}
123 +
124 +App.prototype.unboxMsgWithKey = function (msg, key, cb) {
108125 var self = this
109126 var c = msg && msg.value && msg.value.content
110127 if (typeof c !== 'string') cb(null, msg)
111- else self.unboxContent(c, function (err, content) {
128 + else self.unboxContentWithKey(c, key, function (err, content) {
112129 if (err) {
113130 self.error('unbox:', err)
114131 return cb(null, msg)
115132 } else if (!content) {
@@ -124,8 +141,12 @@
124141 cb(null, m)
125142 })
126143 }
127144
145 +App.prototype.unboxMsg = function (msg, cb) {
146 + return this.unboxMsgWithKey(msg, null, cb)
147 +}
148 +
128149 App.prototype.search = function (opts) {
129150 var fsearch = this.sbot.fulltext && this.sbot.fulltext.search
130151 if (fsearch) return fsearch(opts)
131152 var search = this.sbot.search && this.sbot.search.query
lib/render.jsView
@@ -221,11 +221,15 @@
221221 return this.opts.base + 'zip/' + href.substr(11)
222222 }
223223 switch (href[0]) {
224224 case '%':
225- if (!u.isRef(href)) return false
225 + var parts = href.split('?')
226 + var hash = parts.shift()
227 + var query = parts.join('?')
228 + if (!u.isRef(hash)) return false
226229 return this.opts.base +
227- (this.opts.encode_msgids ? encodeURIComponent(href) : href)
230 + (this.opts.encode_msgids ? encodeURIComponent(hash) : hash)
231 + + (query ? '?' + query : '')
228232 case '@':
229233 if (!u.isRef(href.replace(/\?.*/, ''))) return false
230234 return this.opts.base + href
231235 case '&':
lib/serve.jsView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 113700 bytes
New file size: 113991 bytes
package.jsonView
@@ -15,8 +15,9 @@
1515 "hyperscript": "^2.0.2",
1616 "jpeg-autorotate": "^3.0.0",
1717 "mime-types": "^2.1.12",
1818 "multicb": "^1.2.1",
19 + "private-box": "^0.3.0",
1920 "pull-box-stream": "^1.0.12",
2021 "pull-cat": "^1.1.11",
2122 "pull-catch": "^1.0.0",
2223 "pull-hyperscript": "^0.2.2",

Built with git-ssb-web