This commit is contained in:
Mark Nadal 2019-01-16 10:28:16 -08:00
parent 535d6569fc
commit 6c08ebaea3
7 changed files with 43 additions and 60 deletions

2
gun.js
View File

@ -1804,7 +1804,7 @@
});
});
setTimeout(function(){
root.on('out', {put: send, '#': root.ask(ack), I: root.$});
root.on('out', {put: send, '#': root.ask(ack)});
},1);
}

3
gun.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -50,11 +50,11 @@
// signature handles data output, it is a proxy to the security function.
function signature(msg){
if(msg.user){
if((msg._||noop).user){
return this.to.next(msg);
}
var ctx = this.as;
msg.user = ctx.user;
(msg._||(msg._=function(){})).user = ctx.user;
security.call(this, msg);
}
@ -95,9 +95,9 @@
each.pubs(val, key, node, soul); return;
}
if('~' === soul.slice(0,1) && 2 === (tmp = soul.slice(1)).split('.').length){ // special case, account data for a public key.
each.pub(val, key, node, soul, tmp, msg.user); return;
each.pub(val, key, node, soul, tmp, (msg._||noop).user); return;
}
each.any(val, key, node, soul, msg.user); return;
each.any(val, key, node, soul, (msg._||noop).user); return;
return each.end({err: "No other data allowed!"});
};
each.alias = function(val, key, node, soul){ // Example: {_:#~@, ~@alice: {#~@alice}}
@ -116,7 +116,7 @@
return each.end({err: "Account must match!"});
}
check['user'+soul+key] = 1;
if(msg.I && user && user.is && pub === user.is.pub){
if(Gun.is(msg.$) && user && user.is && pub === user.is.pub){
SEA.sign(SEA.opt.prep(tmp = SEA.opt.parse(val), key, node, soul), (user._).sea, function(data){ var rel;
if(u === data){ return each.end({err: SEA.err || 'Pub signature fail.'}) }
if(rel = Gun.val.link.is(val)){
@ -141,20 +141,12 @@
});
};
each.any = function(val, key, node, soul, user){ var tmp, pub;
if(!user || !user.is){
if(tmp = SEA.opt.pub(soul)){
check['any'+soul+key] = 1;
SEA.verify(SEA.opt.pack(val,key,node,soul), pub = tmp, function(data){ var rel;
data = SEA.opt.unpack(data, key, node);
if(u === data){ return each.end({err: "Mismatched owner on '" + key + "'."}) } // thanks @rogowski !
if((rel = Gun.val.link.is(data)) && pub === SEA.opt.pub(rel)){
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
}
check['any'+soul+key] = 0;
each.end({ok: 1});
});
if(!(pub = SEA.opt.pub(soul))){
if(at.opt.secure){
each.end({err: "Soul is missing public key at '" + key + "'."});
return;
}
// TODO: Ask community if should auto-sign non user-graph data.
check['any'+soul+key] = 1;
at.on('secure', function(msg){ this.off();
check['any'+soul+key] = 0;
@ -164,38 +156,33 @@
//each.end({err: "Data cannot be modified."});
return;
}
if(!(tmp = SEA.opt.pub(soul))){
if(at.opt.secure){
each.end({err: "Soul is missing public key at '" + key + "'."});
if(Gun.is(msg.$) && user && user.is && pub === user.is.pub){
/*var other = Gun.obj.map(at.sea.own[soul], function(v, p){
if((user.is||{}).pub !== p){ return p }
});
if(other){
each.any(val, key, node, soul);
return;
}
// TODO: Ask community if should auto-sign non user-graph data.
check['any'+soul+key] = 0;
each.end({ok: 1});
}*/
check['any'+soul+key] = 1;
SEA.sign(SEA.opt.prep(tmp = SEA.opt.parse(val), key, node, soul), (user._).sea, function(data){
if(u === data){ return each.end({err: 'My signature fail.'}) }
node[key] = JSON.stringify({':': SEA.opt.unpack(data.m), '~': data.s});
check['any'+soul+key] = 0;
each.end({ok: 1});
}, {check: SEA.opt.pack(tmp, key, node, soul), raw: 1});
return;
}
if(!msg.I){ // only sign data put out from this instance.
each.any(val, key, node, soul);
return;
}
if((pub = tmp) !== (user.is||noop).pub){
each.any(val, key, node, soul);
return;
}
/*var other = Gun.obj.map(at.sea.own[soul], function(v, p){
if((user.is||{}).pub !== p){ return p }
});
if(other){
each.any(val, key, node, soul);
return;
}*/
check['any'+soul+key] = 1;
SEA.sign(SEA.opt.prep(tmp = SEA.opt.parse(val), key, node, soul), (user._).sea, function(data){
if(u === data){ return each.end({err: 'My signature fail.'}) }
node[key] = JSON.stringify({':': SEA.opt.unpack(data.m), '~': data.s});
SEA.verify(SEA.opt.pack(val,key,node,soul), pub, function(data){ var rel;
data = SEA.opt.unpack(data, key, node);
if(u === data){ return each.end({err: "Mismatched owner on '" + key + "'."}) } // thanks @rogowski !
if((rel = Gun.val.link.is(data)) && pub === SEA.opt.pub(rel)){
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
}
check['any'+soul+key] = 0;
each.end({ok: 1});
}, {check: SEA.opt.pack(tmp, key, node, soul), raw: 1});
});
}
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?
if(each.err){ return }
@ -207,7 +194,7 @@
if(Gun.obj.map(check, function(no){
if(no){ return true }
})){ return }
msg.user = at.user; // already been through firewall, does not need to again on out.
(msg._||{}).user = at.user || security; // already been through firewall, does not need to again on out.
to.next(msg);
};
Gun.obj.map(msg.put, each.node);
@ -248,7 +235,7 @@
}
}
SEA.opt.shuffle_attack = 1546329600000; // Jan 1, 2019
var noop = {}, u;
var noop = function(){}, u;
var fl = Math.floor; // TODO: Still need to fix inconsistent state issue.
var rel_is = Gun.val.rel.is;
// TODO: Potential bug? If pub/priv key starts with `-`? IDK how possible.

View File

@ -36,7 +36,7 @@ Gun.on('create', function(root){
root.on('out', function(msg){
if(msg.lS){ return }
if(msg.I && msg.put && !msg['@'] && !empty(opt.peers)){
if(Gun.is(msg.$) && msg.put && !msg['@'] && !empty(opt.peers)){
id = msg['#'];
Gun.graph.is(msg.put, null, map);
if(!to){ to = setTimeout(flush, opt.wait || 1) }
@ -112,7 +112,7 @@ Gun.on('create', function(root){
return; // Hmm, what if we have peers but we are disconnected?
}
//console.log("lS get", lex, data);
root.on('in', {'@': msg['#'], put: Gun.graph.node(data), how: 'lS', lS: msg.I});
root.on('in', {'@': msg['#'], put: Gun.graph.node(data), how: 'lS', lS: msg.$ || root.$});
};
Gun.debug? setTimeout(to,1) : to();
});

View File

@ -14,8 +14,8 @@ function Mesh(ctx){
if((tmp = msg['@'])
&& (tmp = ctx.dup.s[tmp])
&& (tmp = tmp.it)
&& tmp.mesh){
mesh.say(msg, tmp.mesh.via, 1);
&& tmp._){
mesh.say(msg, (tmp._).via, 1);
tmp['##'] = msg['##'];
return;
}
@ -47,9 +47,9 @@ function Mesh(ctx){
(tmp = dup.s)[hash] = tmp[id];
}
}
(msg.mesh = function(){}).via = peer;
(msg._ = function(){}).via = peer;
if((tmp = msg['><'])){
msg.mesh.to = Type.obj.map(tmp.split(','), function(k,i,m){m(k,true)});
(msg._).to = Type.obj.map(tmp.split(','), function(k,i,m){m(k,true)});
}
if(msg.dam){
if(tmp = mesh.hear[msg.dam]){
@ -57,7 +57,6 @@ function Mesh(ctx){
}
return;
}
ctx.on('in', msg);
return;
@ -88,7 +87,7 @@ function Mesh(ctx){
}
var tmp, wire = peer.wire || ((opt.wire) && opt.wire(peer)), msh, raw;// || open(peer, ctx); // TODO: Reopen!
if(!wire){ return }
msh = msg.mesh || empty;
msh = (msg._) || empty;
if(peer === msh.via){ return }
if(!(raw = msh.raw)){ raw = mesh.raw(msg) }
if((tmp = msg['@'])
@ -139,7 +138,7 @@ function Mesh(ctx){
mesh.raw = function(msg){
if(!msg){ return '' }
var dup = ctx.dup, msh = msg.mesh || {}, put, hash, tmp;
var dup = ctx.dup, msh = (msg._) || {}, put, hash, tmp;
if(tmp = msh.raw){ return tmp }
if(typeof msg === 'string'){ return msg }
if(msg['@'] && (tmp = msg.put)){

View File

@ -16,7 +16,6 @@ Gun.chain.chain = function(sub){
function output(msg){
var put, get, at = this.as, back = at.back, root = at.root, tmp;
if(!msg.I){ msg.I = at.$ }
if(!msg.$){ msg.$ = at.$ }
this.to.next(msg);
if(get = msg.get){
@ -272,7 +271,6 @@ function ack(msg, ev){
at.on('in', {get: at.get, put: Gun.val.link.ify(get['#']), $: at.$, '@': msg['@']});
return;
}
msg.$ = at.root.$;
Gun.on.put(msg, at.root.$);
}
var empty = {}, u;

View File

@ -86,7 +86,7 @@ function use(msg){
//else if(!cat.async && msg.put !== at.put && root.stop && root.stop[at.id]){ return } root.stop && (root.stop[at.id] = true);
//root.stop && (root.stop.ID = root.stop.ID || Gun.text.random(2));
//root.stop && (root.stop.id = root.stop.id || Gun.text.random(2));
//if((tmp = root.stop) && (tmp = tmp[at.id] || (tmp[at.id] = {})) && tmp[cat.id]){ return } tmp && (tmp[cat.id] = true);
if(eve.seen && at.id && eve.seen[at.id]){ return eve.to.next(msg) }
//if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution?