Skip to content

Commit

Permalink
Identity deletion token & bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Jan 8, 2025
1 parent 0b72902 commit fdcc33d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
13 changes: 9 additions & 4 deletions backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ route.POST('/event', {
console.info(`new user: ${name}=${deserializedHEAD.contractID} (${ip})`)
}
}
const deletionToken = request.headers['shelter-deletion-token']
if (deletionToken) {
await sbp('chelonia/db/set', `_private_deletionToken_${deserializedHEAD.contractID}`, deletionToken)
}
}
// Store size information
await sbp('backend/server/updateSize', deserializedHEAD.contractID, Buffer.byteLength(request.payload))
Expand Down Expand Up @@ -569,13 +573,14 @@ route.POST('/deleteContract/{hash}', {
const { hash } = request.params
const strategy = request.auth.strategy
if (!hash || hash.startsWith('_private')) return Boom.notFound()
const owner = await sbp('chelonia/db/get', `_private_owner_${hash}`)
if (!owner) {
return Boom.notFound()
}

switch (strategy) {
case 'chel-shelter': {
const owner = await sbp('chelonia/db/get', `_private_owner_${hash}`)
if (!owner) {
return Boom.notFound()
}

let ultimateOwner = owner
let count = 0
// Walk up the ownership tree
Expand Down
5 changes: 3 additions & 2 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,18 @@ sbp('sbp/selectors/register', {
const kvKeys = await sbp('chelonia/db/get', kvIndexKey)
if (kvKeys) {
await kvKeys.split('\x00').map((key) => {
return sbp('chelonia/db/delete', key)
return sbp('chelonia/db/delete', `_private_kv_${cid}_${key}`)
})
}
await sbp('chelonia/db/delete', kvIndexKey)

await sbp('chelonia/db/delete', `_private_rid_${cid}`)
await sbp('chelonia/db/delete', `_private_owner_${cid}`)
await sbp('chelonia/db/delete', `_private_size_${cid}`)
await sbp('chelonia/db/delete', `_private_deletionToken_${cid}`)
await removeFromIndexFactory(kvIndexKey)(cid)
await removeFromIndexFactory(`_private_resources_${owner}`)(cid)

await sbp('chelonia/db/delete', `_private_hidx=${cid}#0`)
await sbp('chelonia/db/set', cid, '')

await sbp('chelonia/db/delete', `_private_cheloniaState_${cid}`)
Expand Down
20 changes: 17 additions & 3 deletions frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { EVENT_HANDLED } from '~/shared/domains/chelonia/events.js'
import { findKeyIdByName } from '~/shared/domains/chelonia/utils.js'
// Using relative path to crypto.js instead of ~-path to workaround some esbuild bug
import type { Key } from '../../../shared/domains/chelonia/crypto.js'
import { CURVE25519XSALSA20POLY1305, EDWARDS25519SHA512BATCH, deserializeKey, keyId, keygen, serializeKey } from '../../../shared/domains/chelonia/crypto.js'
import { CURVE25519XSALSA20POLY1305, EDWARDS25519SHA512BATCH, deserializeKey, generateSalt, keyId, keygen, serializeKey } from '../../../shared/domains/chelonia/crypto.js'
import { handleFetchResult } from '../utils/misc.js'
import { encryptedAction, groupContractsByType, syncContractsInOrder } from './utils.js'

Expand Down Expand Up @@ -194,6 +194,8 @@ export default (sbp('sbp/selectors/register', {
const IPK = typeof wIPK === 'string' ? deserializeKey(wIPK) : wIPK
const IEK = typeof wIEK === 'string' ? deserializeKey(wIEK) : wIEK

const deletionToken = generateSalt()

// Create the necessary keys to initialise the contract
const CSK = keygen(EDWARDS25519SHA512BATCH)
const CEK = keygen(CURVE25519XSALSA20POLY1305)
Expand Down Expand Up @@ -221,6 +223,7 @@ export default (sbp('sbp/selectors/register', {
const CEKs = encryptedOutgoingDataWithRawKey(IEK, serializeKey(CEK, true))
const PEKs = encryptedOutgoingDataWithRawKey(CEK, serializeKey(PEK, true))
const SAKs = encryptedOutgoingDataWithRawKey(IEK, serializeKey(SAK, true))
const encryptedDeletionToken = encryptedOutgoingDataWithRawKey(IEK, deletionToken)

// Before creating the contract, put all keys into transient store
await sbp('chelonia/storeSecretKeys',
Expand All @@ -232,7 +235,13 @@ export default (sbp('sbp/selectors/register', {
try {
await sbp('chelonia/out/registerContract', {
contractName: 'gi.contracts/identity',
publishOptions,
publishOptions: {
...publishOptions,
headers: {
...publishOptions?.headers,
'shelter-deletion-token': deletionToken
}
},
signingKeyId: IPKid,
actionSigningKeyId: CSKid,
actionEncryptionKeyId: PEKid,
Expand Down Expand Up @@ -367,7 +376,12 @@ export default (sbp('sbp/selectors/register', {
// finalPicture is set after OP_CONTRACT is sent, which is after
// calling 'chelonia/out/registerContract' here. We use a getter for
// `picture` so that the action sent has the correct value
attributes: { username, email, get picture () { return finalPicture } }
attributes: {
username,
email,
get picture () { return finalPicture },
encryptedDeletionToken
}
},
namespaceRegistration: username
})
Expand Down

0 comments on commit fdcc33d

Please sign in to comment.