Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
Prevent key reuse & enhance UI (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
amadeous authored Jan 8, 2023
1 parent 9501cb6 commit 751fa58
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pastenym",
"version": "1.2.5",
"version": "1.2.6",
"homepage": "http://pastenym.ch/",
"private": true,
"main": "index.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Texts.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class Texts extends React.Component {
}}
>
{this.state.text ? (
<Linkify as="div">
<Linkify as="div" options={{target: "_blank", rel: "noreferrer"}}>
{this.state.text}
</Linkify>
) : (
Expand Down
15 changes: 14 additions & 1 deletion src/UserInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class UserInput extends React.Component {
return mergedArray
}

/*
// do not use this
async sendBinaryMessageTo(data, payload) {
if (!this.nym) {
Expand Down Expand Up @@ -286,6 +287,7 @@ class UserInput extends React.Component {
}
return undefined
}
*/

async sendMessageTo(payload) {
if (!this.nym) {
Expand Down Expand Up @@ -372,6 +374,12 @@ class UserInput extends React.Component {
let encrypted = undefined
let nonencrypted = undefined
if (this.state.isPrivate) {
// If a key was defined before (because previous paste sent), reset it
// This will cause a new key to be generated for encryption
if (null != this.encryptor.getKey()) {
this.encryptor.resetKey()
}

encrypted = this.encryptor.encrypt(
JSON.stringify(clearObjectUser)
)
Expand All @@ -396,6 +404,11 @@ class UserInput extends React.Component {
},
}

// Reset urlId to hide SuccessUrlId component
this.setState({
urlId: undefined,
})

/*if (this.state.text.length > 0)
this.sendMessageTo(JSON.stringify(data))*/
if (encrypted || nonencrypted)
Expand Down Expand Up @@ -439,7 +452,7 @@ class UserInput extends React.Component {
this.state.urlId && !this.state.buttonSendClick ? (
<SuccessUrlId
urlId={this.state.urlId}
encKey={this.encryptor.getKey()}
encKey={this.state.isPrivate ? this.encryptor.getKey() : undefined}
/>
) : (
''
Expand Down
114 changes: 84 additions & 30 deletions src/components/SuccessUrlId.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,54 @@
import * as React from 'react'

/*
import { styled } from '@mui/material/styles';
import ArrowForwardIosSharpIcon from '@mui/icons-material/ArrowForwardIosSharp';
import MuiAccordion from '@mui/material/Accordion';
import MuiAccordionSummary from '@mui/material/AccordionSummary';
import MuiAccordionDetails from '@mui/material/AccordionDetails';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
*/
import CheckCircleIcon from '@mui/icons-material/CheckCircle'
import Alert from '@mui/joy/Alert'
import IconButton from '@mui/joy/IconButton'
import Typography from '@mui/joy/Typography'
import Link from '@mui/joy/Link'
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'

import CopyToClipBoard from './CopyToClipboard'

const SERVER_NAME = process.env.SERVER_NAME || 'https://pastenym.ch'

/*
const Accordion = styled((props) => (
<MuiAccordion disableGutters elevation={0} sx={{ backgroundColor: "blue" }} {...props} />
))(({ theme }) => ({
backgroundColor: "success",
}));
const AccordionSummary = styled((props) => (
<MuiAccordionSummary
expandIcon={<ArrowForwardIosSharpIcon sx={{ fontSize: '0.9rem' }} />}
sx={{ backgroundColor: "blue" }}
{...props}
/>
))(({ theme }) => ({
flexDirection: 'row-reverse',
'& .MuiAccordionSummary-expandIconWrapper.Mui-expanded': {
transform: 'rotate(90deg)',
},
'& .MuiAccordionSummary-content': {
marginLeft: theme.spacing(1),
},
}));
const AccordionDetails = styled((props) => (
<MuiAccordionDetails sx={{ backgroundColor: 'blue' }} {...props} />
))(({ theme }) => ({
padding: theme.spacing(2),
}));
*/

class SuccessUrlId extends React.Component {
constructor(props) {
super(props)
Expand All @@ -18,6 +57,9 @@ class SuccessUrlId extends React.Component {
url: SERVER_NAME + '/#/' + this.props.urlId.url_id,
key: this.props.encKey,
urlId: this.props.urlId.url_id,
urlWithKey: this.props.encKey && this.props.encKey.length > 0 ?
SERVER_NAME + '/#/' + this.props.urlId.url_id + '&key=' + this.props.encKey
: undefined,
copyToClipboardButton: 'Copy to clipboard',
copyToClipboardTooltipOpen: false,
ipfs: this.props.urlId.ipfs,
Expand Down Expand Up @@ -50,40 +92,52 @@ class SuccessUrlId extends React.Component {
<Typography
fontSize="13px"
sx={{ opacity: 0.8, wordBreak: 'break-word' }}
>
Your text is accessible at{' '}
>
Your text is accessible using this link:{' '}
<Link
href={this.state.url}
href={this.state.urlWithKey ? this.state.urlWithKey : this.state.url}
title="Go to your newly created paste!"
>
{this.state.url}
{this.state.urlWithKey ? this.state.urlWithKey : this.state.url}
</Link>
<CopyToClipBoard textToCopy={this.state.url} />
{this.state.key ? (
<>
{' '}
using key: <b>{this.state.key}</b>{' '}
<CopyToClipBoard textToCopy={this.state.key} />.
<br />
Or using this link:{' '}
<Link
href={
this.state.url +
'&key=' +
this.state.key
}
title="Go to your newly created paste!"
>
{this.state.url + '&key=' + this.state.key}
</Link>
<CopyToClipBoard
textToCopy={
this.state.url +
'&key=' +
this.state.key
}
/>
</>
<CopyToClipBoard textToCopy={this.state.urlWithKey ? this.state.urlWithKey : this.state.url} />
{this.state.urlWithKey ? (
/* Accordion WIP
<Accordion>
<AccordionSummary expandIcon={<ExpandMoreIcon />} >
<Typography>Or separately...</Typography>
</AccordionSummary>
<AccordionDetails>
<Typography>
Using this link:{' '}
<Link
href={this.state.url}
title="Go to your newly created paste!"
>
{this.state.url}
</Link>
<CopyToClipBoard textToCopy={this.state.url} />
and this key: <b>{this.state.key}</b>{' '}
<CopyToClipBoard textToCopy={this.state.key} />.
</Typography>
</AccordionDetails>
</Accordion>
*/
<details>
<summary>Or separately...</summary>
<p>
Using this link:{' '}
<Link
href={this.state.url}
title="Go to your newly created paste!"
>
{this.state.url}
</Link>
<CopyToClipBoard textToCopy={this.state.url} />
and this key: <b>{this.state.key}</b>{' '}
<CopyToClipBoard textToCopy={this.state.key} />.
</p>
</details>
) : (
''
)}
Expand Down
8 changes: 6 additions & 2 deletions src/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class E2EEncryptor {
this.#key = null

if (!key) {
//console.log("No key provided, will be generated...")
console.log("No key provided, will be generated...")
sjcl.random.startCollectors()
} else {
this.#key = key
//console.log(`Provided key: ${this.#key} (size: ${this.#key.length/8} bytes)`)
console.log(`Provided key: ${this.#key} (size: ${this.#key.length/8} bytes)`)
}
}

Expand Down Expand Up @@ -86,6 +86,10 @@ class E2EEncryptor {
getKey() {
return this.#key
}

resetKey() {
this.#key = null
}
}

export default E2EEncryptor

0 comments on commit 751fa58

Please sign in to comment.