Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ab0899b
initial
bourgeoa Apr 16, 2023
d84ea71
some lint
bourgeoa Apr 16, 2023
ec9e90b
updates
bourgeoa Apr 16, 2023
490a364
getBlankMsg
bourgeoa Apr 16, 2023
1911313
getPrivateKey
bourgeoa Apr 17, 2023
1d8b733
key exists
bourgeoa Apr 17, 2023
6df03c8
add first test
bourgeoa Apr 17, 2023
109c494
resolve typescript issues
bourgeoa Apr 17, 2023
2da93f8
tests generate keys with node crypto in setup
bourgeoa Apr 18, 2023
6c8461c
keys.test.ts
bourgeoa Apr 18, 2023
94b70b5
signature.test.ts
bourgeoa Apr 19, 2023
c5b2fb8
updates
bourgeoa Apr 21, 2023
20175fe
update package-lock.json
bourgeoa Apr 21, 2023
a5809dd
missing awaits
bourgeoa Apr 25, 2023
9f7a01d
package-lock.json
bourgeoa Apr 25, 2023
cd2500d
separated helpers for testing
SharonStrats Apr 26, 2023
5975073
updates message.js
bourgeoa Apr 26, 2023
8ec0833
refactored to smaller parts
SharonStrats Apr 27, 2023
9c84c1e
create keys and improvements
bourgeoa Apr 27, 2023
96e84cf
package-lock.json
bourgeoa Apr 27, 2023
2166356
update keyUrl with space:storage
bourgeoa Apr 29, 2023
eed9bea
add key container ACL
bourgeoa Apr 30, 2023
3652e5c
update setAcl key container
bourgeoa May 1, 2023
c239a13
trying to mock store fetcher load function
SharonStrats May 3, 2023
0ba702c
Update src/chat/keys.ts
bourgeoa May 3, 2023
ef25bb1
adding testing to docs
SharonStrats May 4, 2023
098e8a7
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 4, 2023
89f16fa
update get podRoot, use NamedNode
bourgeoa May 5, 2023
67289c6
Merge branch 'chat-proof' of https://github.com/solidos/solid-ui into…
bourgeoa May 5, 2023
8eed263
skip failing keys.test.ts
bourgeoa May 5, 2023
11c883a
mocked load
SharonStrats May 6, 2023
beea007
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 6, 2023
282702e
more cleaning
bourgeoa May 6, 2023
17005e6
Merge branch 'chat-proof' of https://github.com/solidos/solid-ui into…
bourgeoa May 6, 2023
0202734
more NamedNode
bourgeoa May 7, 2023
a6ef582
some cleaning
bourgeoa May 7, 2023
a573676
refactored function names
SharonStrats May 10, 2023
4370b23
added tests
SharonStrats May 10, 2023
0493bdd
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 10, 2023
69ecfab
created a keyhelper dir
SharonStrats May 10, 2023
18070a0
split files up for easier testing
SharonStrats May 10, 2023
aa51d1d
readmes for testing
SharonStrats May 10, 2023
830468e
key file tests
SharonStrats May 10, 2023
50ca84d
keys testing
SharonStrats May 10, 2023
a1b9ed4
updated testing readme
SharonStrats May 10, 2023
70090f2
added tests
SharonStrats May 17, 2023
27b35f4
acl refactor and tests
SharonStrats May 17, 2023
d02c4c2
key tests
SharonStrats May 17, 2023
f7310cd
fixed broken test
SharonStrats May 17, 2023
85020be
access data test
SharonStrats May 17, 2023
12e3adb
Update test/unit/README.md
SharonStrats May 17, 2023
3f1ead6
Update test/unit/README.md
SharonStrats May 17, 2023
90c87cc
Update test/unit/README.md
SharonStrats May 17, 2023
47a7934
Update test/unit/README.md
SharonStrats May 17, 2023
4bbe4cc
Update test/unit/README.md
SharonStrats May 17, 2023
0a40d64
Update test/unit/README.md
SharonStrats May 17, 2023
ea3f761
Update test/unit/README.md
SharonStrats May 17, 2023
15b7da3
rename deleteKey to deleteKeyAcl
bourgeoa May 18, 2023
7506217
getPodRoot returns NamedNode
bourgeoa May 18, 2023
998e1dd
move privateKey to /settings/keys/privateKey.ttl
bourgeoa May 18, 2023
cb30461
replace pop with slice
bourgeoa May 18, 2023
3576458
Update test/unit/README.md
SharonStrats May 20, 2023
d527997
testing
SharonStrats May 22, 2023
0829883
Merge branch 'chat-proof' of https://github.com/SolidOS/solid-ui into…
SharonStrats May 22, 2023
2da9b5c
remove testing debug msg
SharonStrats May 22, 2023
9ee704c
fix lint error
SharonStrats May 22, 2023
3d362e6
restore PUT on 404
bourgeoa May 24, 2023
027eefb
use solid ontology
bourgeoa May 24, 2023
840c347
removed commented out code
SharonStrats May 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 81 additions & 38 deletions dist/solid-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -37875,6 +37875,11 @@ function _getPublicKey() {
function getPrivateKey(_x2) {
return _getPrivateKey.apply(this, arguments);
}
/**
* key container ACL
* @param me
* @returns aclBody
*/
function _getPrivateKey() {
_getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(webId) {
var publicKeyDoc, privateKeyDoc, publicKey, privateKey, validPublicKey, del, add, newPublicKey, keyContainer;
Expand Down Expand Up @@ -37948,47 +37953,86 @@ function _getPrivateKey() {
return _getPrivateKey.apply(this, arguments);
}
var keyContainerAclBody = function keyContainerAclBody(me) {
var aclBody = "\n@prefix : <#>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix key: <./>.\n\n:ReadWrite\n a acl:Authorization;\n acl:accessTo key:;\n acl:agent <".concat(me, ">;\n acl:mode acl:Read, acl:Write.\n:Read\n a acl:Authorization;\n acl:accessTo key:;\n acl:default key:;\n acl:agentClass foaf:Agent;\n acl:mode acl:Read.\n");
var aclBody = "\n@prefix : <#>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix key: <./>.\n\n:ReadWrite\n a acl:Authorization;\n acl:accessTo key:;\n acl:default key:;\n acl:agent <".concat(me, ">;\n acl:mode acl:Read, acl:Write.\n");
return aclBody;
};

/**
* Read only ACL
* @param keyDoc
* @param me
* @returns aclBody
*/
var keyAclBody = function keyAclBody(keyDoc, me) {
var keyAgent = 'acl:agentClass foaf:Agent'; // publicKey
if (me !== null && me !== void 0 && me.length) keyAgent = "acl:agent <".concat(me, ">"); // privateKey
var aclBody = "\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n<#Read>\n a acl:Authorization;\n ".concat(keyAgent, ";\n acl:accessTo <").concat(keyDoc.split('/').pop(), ">;\n acl:mode acl:Read, acl:Control. # NSS issue: missing acl link header with READ only\n");
var aclBody = "\n@prefix foaf: <http://xmlns.com/foaf/0.1/>.\n@prefix acl: <http://www.w3.org/ns/auth/acl#>.\n<#Read>\n a acl:Authorization;\n ".concat(keyAgent, ";\n acl:accessTo <").concat(keyDoc.split('/').pop(), ">;\n acl:mode acl:Read.\n");
return aclBody;
};

/**
* set ACL
* @param keyDoc
* @param aclBody
*/
function setAcl(_x3, _x4) {
return _setAcl.apply(this, arguments);
}
/**
* delete acl if keydoc exists
* create/edit keyDoc
* set keyDoc acl
*/
function _setAcl() {
_setAcl = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(keyDoc, aclBody) {
var keyAclDoc, aclResponse;
var keyAclDoc, response, aclResponse;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return _solidLogic.store.fetcher.load(keyDoc);
case 2:
// FIXME: check the Why value on this quad:
debug.log(_solidLogic.store.statementsMatching($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl')));
keyAclDoc = _solidLogic.store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'));
if (keyAclDoc) {
_context3.next = 5;
_context3.next = 6;
break;
}
throw new Error('Key ACL doc not found!');
case 5:
_context3.next = 7;
case 6:
_context3.prev = 6;
_context3.next = 9;
return _solidLogic.store.fetcher.webOperation('DELETE', keyAclDoc.value);
case 9:
response = _context3.sent;
// this may fail if webId is not an owner
debug.log('delete ' + keyAclDoc.value + ' ' + response.status); // should test 404 and 2xx
_context3.next = 18;
break;
case 13:
_context3.prev = 13;
_context3.t0 = _context3["catch"](6);
if (!(_context3.t0.response.status !== 404)) {
_context3.next = 17;
break;
}
throw new Error(_context3.t0);
case 17:
debug.log('delete ' + keyAclDoc.value + ' ' + _context3.t0.response.status); // should test 404 and 2xx
case 18:
_context3.next = 20;
return _solidLogic.store.fetcher.webOperation('PUT', keyAclDoc.value, {
data: aclBody,
contentType: 'text/turtle'
});
case 7:
case 20:
aclResponse = _context3.sent;
case 8:
case 21:
case "end":
return _context3.stop();
}
}, _callee3);
}, _callee3, null, [[6, 13]]);
}));
return _setAcl.apply(this, arguments);
}
Expand All @@ -38004,56 +38048,55 @@ function _saveKey() {
while (1) switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return _solidLogic.store.updater.updateMany(del, add);
case 2:
_context4.next = 4;
return _solidLogic.store.fetcher.load(keyDoc);
case 4:
_context4.prev = 4;
case 2:
_context4.prev = 2;
// get keyAcldoc
keyAclDoc = _solidLogic.store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'));
if (keyAclDoc) {
_context4.next = 8;
if (!keyAclDoc) {
_context4.next = 17;
break;
}
throw new Error("".concat(keyDoc, " ACL doc not found!"));
case 8:
_context4.prev = 8;
_context4.next = 11;
_context4.prev = 5;
_context4.next = 8;
return _solidLogic.store.fetcher.webOperation('DELETE', keyAclDoc.value);
case 11:
case 8:
response = _context4.sent;
// this may fail if webId is not an owner
debug.log('delete ' + keyAclDoc.value + ' ' + response.status); // should test 404 and 2xx
_context4.next = 20;
_context4.next = 17;
break;
case 15:
_context4.prev = 15;
_context4.t0 = _context4["catch"](8);
case 12:
_context4.prev = 12;
_context4.t0 = _context4["catch"](5);
if (!(_context4.t0.response.status !== 404)) {
_context4.next = 19;
_context4.next = 16;
break;
}
throw new Error(_context4.t0);
case 19:
case 16:
debug.log('delete ' + keyAclDoc.value + ' ' + _context4.t0.response.status); // should test 404 and 2xx
case 20:
case 17:
_context4.next = 19;
return _solidLogic.store.updater.updateMany(del, add);
case 19:
// or a promise store.updater.update ?
// create READ only ACL
aclBody = keyAclBody(keyDoc, me);
_context4.next = 23;
_context4.next = 22;
return setAcl(keyDoc, aclBody);
case 23:
_context4.next = 28;
case 22:
_context4.next = 27;
break;
case 25:
_context4.prev = 25;
_context4.t1 = _context4["catch"](4);
case 24:
_context4.prev = 24;
_context4.t1 = _context4["catch"](2);
throw new Error(_context4.t1);
case 28:
case 27:
case "end":
return _context4.stop();
}
}, _callee4, null, [[4, 25], [8, 15]]);
}, _callee4, null, [[2, 24], [5, 12]]);
})();
});
return _saveKey.apply(this, arguments);
Expand Down Expand Up @@ -47332,8 +47375,8 @@ Object.defineProperty(exports, "__esModule", ({
}));
exports.versionInfo = void 0;
var versionInfo = {
buildTime: '2023-04-30T18:20:26Z',
commit: '2166356d833035248d9cab576a91a9db267c426f',
buildTime: '2023-05-01T17:58:14Z',
commit: 'eed9bea818c9a1a52b4631274b5251b239530355',
npmInfo: {
'solid-ui': '2.4.27',
npm: '8.19.4',
Expand Down
2 changes: 1 addition & 1 deletion dist/solid-ui.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/solid-ui.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/solid-ui.min.js.map

Large diffs are not rendered by default.

93 changes: 48 additions & 45 deletions src/chat/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,16 @@ export async function getPrivateKey (webId: string) {
await saveKey(publicKeyDoc, del, add)
}
const keyContainer = privateKeyDoc.substring(0, privateKeyDoc.lastIndexOf('/') + 1)
await setAcl(keyContainer, keyContainerAclBody(webId))
/* debug.log('new key pair ' + webId)
debug.log('newPrivateKey-1 ' + privateKey)
debug.log('newPublicKey-1 ' + publicKey) */
/* debug.log('del')
debug.log(del)
debug.log('add')
debug.log(add) */
// await store.updater.updateMany(del, add)
// TODO create READ ACL's
// await setAcl() // depends on which key has been updated
await setAcl(keyContainer, keyContainerAclBody(webId)) // includes DELETE and PUT
}
return privateKey as string
}

/**
* key container ACL
* @param me
* @returns aclBody
*/
const keyContainerAclBody = (me: string) => {
const aclBody = `
@prefix : <#>.
Expand All @@ -96,18 +91,19 @@ const keyContainerAclBody = (me: string) => {
:ReadWrite
a acl:Authorization;
acl:accessTo key:;
acl:default key:;
acl:agent <${me}>;
acl:mode acl:Read, acl:Write.
:Read
a acl:Authorization;
acl:accessTo key:;
acl:default key:;
acl:agentClass foaf:Agent;
acl:mode acl:Read.
`
return aclBody
}

/**
* Read only ACL
* @param keyDoc
* @param me
* @returns aclBody
*/
const keyAclBody = (keyDoc, me) => {
let keyAgent = 'acl:agentClass foaf:Agent' // publicKey
if (me?.length) keyAgent = `acl:agent <${me}>` // privateKey
Expand All @@ -118,61 +114,68 @@ const keyAclBody = (keyDoc, me) => {
a acl:Authorization;
${keyAgent};
acl:accessTo <${keyDoc.split('/').pop()}>;
acl:mode acl:Read, acl:Control. # NSS issue: missing acl link header with READ only
acl:mode acl:Read.
`
return aclBody
}

/**
* set ACL
* @param keyDoc
* @param aclBody
*/
async function setAcl (keyDoc, aclBody) {
// Some servers don't present a Link http response header
// if the container doesn't exist yet, so refetch the container
// now that it has been created:
// if the container doesn't exist yet, so refetch the resource
await store.fetcher.load(keyDoc)

// FIXME: check the Why value on this quad:
debug.log(store.statementsMatching($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl')))
const keyAclDoc = store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'))
if (!keyAclDoc) {
throw new Error('Key ACL doc not found!')
}

/* let keyAgent = `acl:agent <${me}>;\n` // privateKey
if (!me?.length) keyAgent = `acl:agent <${me}>;\n` + ' acl:agentClass foaf:Agent' // publicKey NSS issue
const aclBody = `
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
<#Read>
a acl:Authorization;
acl:agent <${me}>;
${keyAgent};
acl:accessTo <${keyDoc.split('/').pop()}>;
acl:mode acl:Read, acl:Control. # NSS issue: missing acl link header with READ only
` */
// delete READ only keyAclDoc. This is possible if the webId is an owner
try {
const response = await store.fetcher.webOperation('DELETE', keyAclDoc.value) // this may fail if webId is not an owner
debug.log('delete ' + keyAclDoc.value + ' ' + response.status) // should test 404 and 2xx
} catch (err) {
if (err.response.status !== 404) { throw new Error(err) }
debug.log('delete ' + keyAclDoc.value + ' ' + err.response.status) // should test 404 and 2xx
}

const aclResponse = await store.fetcher.webOperation('PUT', keyAclDoc.value, {
data: aclBody,
contentType: 'text/turtle'
})
}

/**
* delete acl if keydoc exists
* create/edit keyDoc
* set keyDoc acl
*/
async function saveKey (keyDoc, del, add, me = '') {
// save key
await store.updater.updateMany(del, add) // or a promise store.updater.update ?
await store.fetcher.load(keyDoc)

// delete keyAclDoc
try {
// get keyAcldoc
const keyAclDoc = store.any($rdf.sym(keyDoc), $rdf.sym('http://www.iana.org/assignments/link-relations/acl'))
if (!keyAclDoc) {
throw new Error(`${keyDoc} ACL doc not found!`)
}
// delete READ only keyAclDoc. This is possible if the webId is an owner
try {
const response = await store.fetcher.webOperation('DELETE', keyAclDoc.value) // this may fail if webId is not an owner
debug.log('delete ' + keyAclDoc.value + ' ' + response.status) // should test 404 and 2xx
} catch (err) {
if (err.response.status !== 404) { throw new Error(err) }
debug.log('delete ' + keyAclDoc.value + ' ' + err.response.status) // should test 404 and 2xx
if (keyAclDoc) {
// delete READ only keyAclDoc. This is possible if the webId is an owner
try {
const response = await store.fetcher.webOperation('DELETE', keyAclDoc.value) // this may fail if webId is not an owner
debug.log('delete ' + keyAclDoc.value + ' ' + response.status) // should test 404 and 2xx
} catch (err) {
if (err.response.status !== 404) { throw new Error(err) }
debug.log('delete ' + keyAclDoc.value + ' ' + err.response.status) // should test 404 and 2xx
}
}

// save key
await store.updater.updateMany(del, add) // or a promise store.updater.update ?

// create READ only ACL
const aclBody = keyAclBody(keyDoc, me)
await setAcl(keyDoc, aclBody)
Expand Down