Compare commits
2 Commits
87a802e210
...
f25616328d
Author | SHA1 | Date | |
---|---|---|---|
|
f25616328d | ||
|
fc415265de |
1
main.go
1
main.go
@ -279,6 +279,7 @@ func nodeCreate(w http.ResponseWriter, r *http.Request) {// {{{
|
|||||||
})
|
})
|
||||||
}// }}}
|
}// }}}
|
||||||
func nodeUpdate(w http.ResponseWriter, r *http.Request) {// {{{
|
func nodeUpdate(w http.ResponseWriter, r *http.Request) {// {{{
|
||||||
|
log.Println("/node/update")
|
||||||
var err error
|
var err error
|
||||||
var session Session
|
var session Session
|
||||||
|
|
||||||
|
@ -54,7 +54,11 @@ export class NodeUI extends Component {
|
|||||||
let page = ''
|
let page = ''
|
||||||
switch(this.page.value) {
|
switch(this.page.value) {
|
||||||
case 'node':
|
case 'node':
|
||||||
if(node.ID > 0) {
|
if(node.ID == 0) {
|
||||||
|
page = html`
|
||||||
|
${children.length > 0 ? html`<div class="child-nodes">${children}</div>` : html``}
|
||||||
|
`
|
||||||
|
} else {
|
||||||
let padlock = ''
|
let padlock = ''
|
||||||
if(node.CryptoKeyID > 0)
|
if(node.CryptoKeyID > 0)
|
||||||
padlock = html`<img src="/images/${window._VERSION}/padlock-black.svg" style="height: 24px;" />`
|
padlock = html`<img src="/images/${window._VERSION}/padlock-black.svg" style="height: 24px;" />`
|
||||||
@ -209,7 +213,8 @@ export class NodeUI extends Component {
|
|||||||
}//}}}
|
}//}}}
|
||||||
saveNode() {//{{{
|
saveNode() {//{{{
|
||||||
let content = this.nodeContent.current.contentDiv.current.value
|
let content = this.nodeContent.current.contentDiv.current.value
|
||||||
this.node.value.save(content, ()=>this.props.app.nodeModified.value = false)
|
this.node.value.setContent(content)
|
||||||
|
this.node.value.save(()=>this.props.app.nodeModified.value = false)
|
||||||
}//}}}
|
}//}}}
|
||||||
renameNode() {//{{{
|
renameNode() {//{{{
|
||||||
let name = prompt("New name")
|
let name = prompt("New name")
|
||||||
@ -299,7 +304,7 @@ class NodeContent extends Component {
|
|||||||
textarea.parentNode.dataset.replicatedValue = textarea.value
|
textarea.parentNode.dataset.replicatedValue = textarea.value
|
||||||
}//}}}
|
}//}}}
|
||||||
unlock() {//{{{
|
unlock() {//{{{
|
||||||
let pass = prompt("Password")
|
let pass = prompt(`Password for "${this.props.model.description}"`)
|
||||||
if(!pass)
|
if(!pass)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -397,21 +402,21 @@ export class Node {
|
|||||||
})
|
})
|
||||||
.catch(this.app.responseError)
|
.catch(this.app.responseError)
|
||||||
}//}}}
|
}//}}}
|
||||||
async save(content, callback) {//{{{
|
async save(callback) {//{{{
|
||||||
let update_content = content
|
try {
|
||||||
/*
|
await this.#encrypt()
|
||||||
* XXX - fix encrypting when saving
|
|
||||||
if(this.CryptoKeyID != 0)
|
|
||||||
update_content = await this.#encrypt(content)
|
|
||||||
*/
|
|
||||||
|
|
||||||
this.app.request('/node/update', {
|
let req = {
|
||||||
NodeID: this.ID,
|
NodeID: this.ID,
|
||||||
Content: update_content,
|
Content: this._content,
|
||||||
CryptoKeyID: this.CryptoKeyID,
|
CryptoKeyID: this.CryptoKeyID,
|
||||||
})
|
}
|
||||||
|
this.app.request('/node/update', req)
|
||||||
.then(callback)
|
.then(callback)
|
||||||
.catch(this.app.responseError)
|
.catch(this.app.responseError)
|
||||||
|
} catch (err) {
|
||||||
|
this.app.responseError(err)
|
||||||
|
}
|
||||||
}//}}}
|
}//}}}
|
||||||
rename(name, callback) {//{{{
|
rename(name, callback) {//{{{
|
||||||
this.app.request('/node/rename', {
|
this.app.request('/node/rename', {
|
||||||
@ -454,30 +459,26 @@ export class Node {
|
|||||||
})
|
})
|
||||||
}//}}}
|
}//}}}
|
||||||
content() {//{{{
|
content() {//{{{
|
||||||
if(this.CryptoKeyID != 0 && !this._decrypted) {
|
if(this.CryptoKeyID != 0 && !this._decrypted)
|
||||||
this.#decrypt()
|
this.#decrypt()
|
||||||
}
|
|
||||||
return this._content
|
return this._content
|
||||||
}//}}}
|
}//}}}
|
||||||
|
setContent(new_content) {//{{{
|
||||||
async encrypt(obj_key) {//{{{
|
this._content = new_content
|
||||||
if(obj_key.ID != this.CryptoKeyID)
|
if(this.CryptoKeyID == 0)
|
||||||
throw('Invalid key')
|
// Logic behind plaintext not being decrypted is that
|
||||||
|
// only encrypted values can be in a decrypted state.
|
||||||
let crypto = new Crypto(obj_key.key)
|
|
||||||
this._decrypted = false
|
this._decrypted = false
|
||||||
|
else
|
||||||
let counter = await obj_key.counter()
|
this._decrypted = true
|
||||||
|
}//}}}
|
||||||
this.content = sjcl.codec.base64.fromBits(
|
async setCryptoKey(new_key) {//{{{
|
||||||
crypto.encrypt(
|
return this.#encrypt(true, new_key)
|
||||||
sjcl.codec.utf8String.toBits(this.content),
|
|
||||||
counter,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}//}}}
|
}//}}}
|
||||||
#decrypt() {//{{{
|
#decrypt() {//{{{
|
||||||
|
if(this.CryptoKeyID == 0 || this._decrypted)
|
||||||
|
return
|
||||||
|
|
||||||
let obj_key = this.app.nodeUI.current.getKey(this.CryptoKeyID)
|
let obj_key = this.app.nodeUI.current.getKey(this.CryptoKeyID)
|
||||||
if(obj_key === null || obj_key.ID != this.CryptoKeyID)
|
if(obj_key === null || obj_key.ID != this.CryptoKeyID)
|
||||||
throw('Invalid key')
|
throw('Invalid key')
|
||||||
@ -485,7 +486,7 @@ export class Node {
|
|||||||
// Ask user to unlock key first
|
// Ask user to unlock key first
|
||||||
var pass = null
|
var pass = null
|
||||||
while(pass || obj_key.status() == 'locked') {
|
while(pass || obj_key.status() == 'locked') {
|
||||||
pass = prompt("Password")
|
pass = prompt(`Password for "${obj_key.description}"`)
|
||||||
if(!pass)
|
if(!pass)
|
||||||
throw new Error(`Key "${obj_key.description}" is locked`)
|
throw new Error(`Key "${obj_key.description}" is locked`)
|
||||||
|
|
||||||
@ -506,10 +507,25 @@ export class Node {
|
|||||||
crypto.decrypt(this._content)
|
crypto.decrypt(this._content)
|
||||||
)
|
)
|
||||||
}//}}}
|
}//}}}
|
||||||
/*
|
async #encrypt(change_key = false, new_key = null) {//{{{
|
||||||
async #encrypt(content) {//{{{
|
// Nothing to do if not changing key and already encrypted.
|
||||||
let obj_key = this.app.nodeUI.current.getKey(this.CryptoKeyID)
|
if(!change_key && this.CryptoKeyID != 0 && !this._decrypted)
|
||||||
if(obj_key === null || obj_key.ID != this.CryptoKeyID)
|
return this._content
|
||||||
|
|
||||||
|
let content = this.content()
|
||||||
|
|
||||||
|
// Changing key to no encryption or already at no encryption -
|
||||||
|
// set to not decrypted (only encrypted values can be
|
||||||
|
// decrypted) and return plain value.
|
||||||
|
if((change_key && new_key === null) || (!change_key && this.CryptoKeyID == 0)) {
|
||||||
|
this._decrypted = false
|
||||||
|
this.CryptoKeyID = 0
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
let key_id = change_key ? new_key.ID : this.CryptoKeyID
|
||||||
|
let obj_key = this.app.nodeUI.current.getKey(key_id)
|
||||||
|
if(obj_key === null || obj_key.ID != key_id)
|
||||||
throw('Invalid key')
|
throw('Invalid key')
|
||||||
|
|
||||||
if(obj_key.status() == 'locked')
|
if(obj_key.status() == 'locked')
|
||||||
@ -518,9 +534,11 @@ export class Node {
|
|||||||
let crypto = new Crypto(obj_key.key)
|
let crypto = new Crypto(obj_key.key)
|
||||||
let content_bits = sjcl.codec.utf8String.toBits(content)
|
let content_bits = sjcl.codec.utf8String.toBits(content)
|
||||||
let counter = await this.app.nodeUI.current.keyCounter()
|
let counter = await this.app.nodeUI.current.keyCounter()
|
||||||
return crypto.encrypt(content_bits, counter, true)
|
this.CryptoKeyID = obj_key.ID
|
||||||
|
this._content = crypto.encrypt(content_bits, counter, true)
|
||||||
|
this._decrypted = false
|
||||||
|
return this._content
|
||||||
}//}}}
|
}//}}}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Menu extends Component {
|
class Menu extends Component {
|
||||||
@ -681,38 +699,26 @@ class NodeProperties extends Component {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
}//}}}
|
}//}}}
|
||||||
save() {//{{{
|
async save() {//{{{
|
||||||
let nodeui = this.props.nodeui
|
let nodeui = this.props.nodeui
|
||||||
let node = nodeui.node.value
|
let node = nodeui.node.value
|
||||||
|
|
||||||
// Find the actual key object used for encryption
|
// Find the actual key object used for encryption
|
||||||
let encrypt_key = nodeui.getKey(this.selected_key_id)
|
let new_key = nodeui.getKey(this.selected_key_id)
|
||||||
let decrypt_key = nodeui.getKey(node.CryptoKeyID)
|
let current_key = nodeui.getKey(node.CryptoKeyID)
|
||||||
|
|
||||||
if(decrypt_key && decrypt_key.status() == 'locked') {
|
if(current_key && current_key.status() == 'locked') {
|
||||||
alert("Decryption key is locked and can not be used.")
|
alert("Decryption key is locked and can not be used.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if(encrypt_key && encrypt_key.status() == 'locked') {
|
if(new_key && new_key.status() == 'locked') {
|
||||||
alert("Key is locked and can not be used.")
|
alert("Key is locked and can not be used.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently not encrypted - encrypt with new key.
|
await node.setCryptoKey(new_key)
|
||||||
let crypto = new Crypto(selected_key.key)
|
node.save(()=>this.props.nodeui.showPage('node'))
|
||||||
if(node.CryptoKeyID == 0) {
|
|
||||||
let encrypted = crypto.encrypt(
|
|
||||||
sjcl.codec.utf8String.toBits(node.Content()),
|
|
||||||
1n,
|
|
||||||
)
|
|
||||||
console.log(encrypted)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
crypto.encrypt(
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
}//}}}
|
}//}}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user