git ssb

7+

dinoworm 🐛 / patchcore



Commit 8949e8dbfc5ddb4b87f2c9508980de7c0f848e7b

Merge pull request #60 from ssbc/add-private-blobs

 add `private` option to blob.html.input for encrypted blobs
Matt McKegg authored on 4/13/2018, 4:19:54 AM
GitHub committed on 4/13/2018, 4:19:54 AM
Parent: e9bb4e285f6ed74c209f836552ac3cc01c7822c6
Parent: beef767c0ae0cb59f9f2de9b646e34b89c0e43a7

Files changed

blob/html/input.jschanged
message/html/markdown.jschanged
package-lock.jsonchanged
package.jsonchanged
blob/html/input.jsView
@@ -1,13 +1,20 @@
11 var h = require('mutant/h')
2 +var resolve = require('mutant/resolve')
3 +var onceTrue = require('mutant/once-true')
24 var pull = require('pull-stream')
35 var mime = require('simple-mime')('application/octect-stream')
46 var split = require('split-buffer')
57 var nest = require('depnest')
8 +var Defer = require('pull-defer')
9 +var BoxStream = require('pull-box-stream')
10 +var crypto = require('crypto')
11 +var zeros = Buffer.alloc(24, 0)
612
713 module.exports = {
814 needs: nest({
9- 'sbot.async.addBlob': 'first'
15 + 'sbot.obs.connection': 'first'
16 +
1017 }),
1118 gives: nest('blob.html.input'),
1219 create: function (api) {
1320 return nest('blob.html.input', function FileInput (onAdded, opts = {}) {
@@ -49,9 +56,12 @@
4956 function next (file) {
5057 var reader = new global.FileReader()
5158 reader.onload = function () {
5259 var stream = pull.values(split(new Buffer(reader.result), 64 * 1024))
53- api.sbot.async.addBlob(stream, function (err, blob) {
60 + pull(stream, AddBlob({
61 + connection: api.sbot.obs.connection,
62 + encrypt: resolve(opts.private)
63 + }, (err, blob) => {
5464 if (err) return console.error(err)
5565 onAdded({
5666 link: blob,
5767 name: fileName,
@@ -59,9 +69,9 @@
5969 type: mimeType
6070 })
6171
6272 ev.target.value = ''
63- })
73 + }))
6474 }
6575 reader.readAsArrayBuffer(file)
6676 }
6777 }
@@ -157,4 +167,56 @@
157167
158168 ctx.drawImage(img, -img.width / 2, -img.height / 2)
159169 return canvas
160170 }
171 +
172 +function AddBlob ({connection, encrypt = false}, cb) {
173 + var stream = Defer.sink()
174 + onceTrue(connection, sbot => {
175 + if (encrypt) {
176 + // FROM: https://github.com/ssbc/ssb-secret-blob/blob/master/index.js
177 + // here we need to hash something twice, first, hash the plain text to use as the
178 + // key. This has the benefit of encrypting deterministically - the same file will
179 + // have the same hash. This can be used to deduplicate storage, but has privacy
180 + // implications. I do it here just because it's early days and this makes testing
181 + // easier.
182 +
183 + stream.resolve(Hash(function (err, buffers, key) {
184 + if (err) return cb(err)
185 + pull(
186 + pull.once(Buffer.concat(buffers)),
187 + BoxStream.createBoxStream(key, zeros),
188 + Hash(function (err, buffers, hash) {
189 + if (err) return cb(err)
190 + var id = '&' + hash.toString('base64') + '.sha256'
191 + pull(
192 + pull.values(buffers),
193 + sbot.blobs.add(id, function (err) {
194 + if (err) return cb(err)
195 + sbot.blobs.push(id, function (err) {
196 + if (err) return cb(err)
197 + cb(null, id + '?unbox=' + key.toString('base64') + '.boxs')
198 + })
199 + })
200 + )
201 + })
202 + )
203 + }))
204 + } else {
205 + stream.resolve(sbot.blobs.add(cb))
206 + }
207 + })
208 + return stream
209 +}
210 +
211 +function Hash (cb) {
212 + var hash = crypto.createHash('sha256')
213 + var buffers = []
214 + var hasher = pull.drain(function (data) {
215 + data = typeof data === 'string' ? new Buffer(data) : data
216 + buffers.push(data)
217 + hash.update(data)
218 + }, function (err) {
219 + cb(err, buffers, hash.digest())
220 + })
221 + return hasher
222 +}
message/html/markdown.jsView
@@ -41,9 +41,9 @@
4141 : api.emoji.sync.url(emoji)
4242 return renderEmoji(emoji, url)
4343 },
4444 toUrl: (id) => {
45- if (id[0] == '&') return api.blob.sync.url(id)
45 + if (id.startsWith('&')) return api.blob.sync.url(id)
4646 if (mentions[id]) {
4747 return mentions[id]
4848 } else if (ref.isLink(id) || id.startsWith('#') || id.startsWith('?')) {
4949 return id
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 106810 bytes
New file size: 106810 bytes
package.jsonView
@@ -1,7 +1,7 @@
11 {
22 "name": "patchcore",
3- "version": "1.24.0",
3 + "version": "1.24.1",
44 "description": "minimal core for ssb clients",
55 "main": "index.js",
66 "scripts": {
77 "start": "electro example",
@@ -43,9 +43,11 @@
4343 "human-time": "0.0.1",
4444 "mutant": "^3.21.2",
4545 "mutant-pull-reduce": "^1.1.0",
4646 "pull-abortable": "^4.1.0",
47 + "pull-box-stream": "~1.0.13",
4748 "pull-cat": "^1.1.11",
49 + "pull-defer": "~0.2.2",
4850 "pull-reconnect": "0.0.3",
4951 "pull-stream": "^3.5.0",
5052 "scuttle-blog": "^1.0.0",
5153 "simple-mime": "^0.1.0",

Built with git-ssb-web