on master help sign in
- Streamline genKeyfile view, making everything automatic
commitd593175485ec031300127407d520ce85873e4339 authorChris Johnson <chris@cjohnson.io> dateSun 31 Mar 2019, 22:12 (8 years ago) parentbdd3bc2
2 files changed+80−88
src/style/extend.css+7 src/views/GenKeyfile.js+73−88
src/style/extend.css+7
@@ -463,3 +463,10 @@ code {
463463.clickable {
464464 cursor: pointer;
465465}
466+
467+.keyfile {
468+ white-space: pre-wrap;
469+ word-break: break-word;
470+ padding: 1rem 2rem;
471+ margin-bottom: 4rem;
472+}
src/views/GenKeyfile.js+73−88
@@ -22,44 +22,14 @@ class GenKeyfile extends React.Component {
2222
2323 this.state = {
2424 keyfile: '',
25− networkSeed: ''
25+ loaded: false
2626 }
27−
28− this.handleNetworkSeedInput = this.handleNetworkSeedInput.bind(this)
29− this.handleKeyfileChange = this.handleKeyfileChange.bind(this)
30− }
31−
32− componentDidMount() {
33− this.deriveSeed()
3427 }
3528
36− async deriveSeed() {
37− const next = false
38− let seed = await attemptSeedDerivation(next, this.props)
39−
40− if (seed.getOrElse('') === '' && this.props.networkSeedCache) {
41− seed = Maybe.Just(this.props.networkSeedCache)
42− }
43−
44− this.setState({
45− networkSeed: seed.getOrElse('')
46− })
47− }
48−
49− handleNetworkSeedInput = (networkSeed) => {
50− this.setState({ networkSeed })
51− }
52−
53− handleKeyfileChange = (keyfile) => {
54− this.setState({ keyfile })
55− }
56−
57− render() {
29+ getPointDetails() {
5830 const { pointCache } = this.props
5931 const { pointCursor } = this.props
6032
61− const { keyfile, networkSeed } = this.state
62−
6333 const point = pointCursor.matchWith({
6434 Just: (pt) => pt.value,
6535 Nothing: () => {
@@ -74,6 +44,34 @@ class GenKeyfile extends React.Component {
7444
7545 const revision = parseInt(pointDetails.keyRevisionNumber)
7646
47+ return {
48+ point,
49+ pointDetails,
50+ revision
51+ }
52+ }
53+
54+ async componentDidMount() {
55+ const { point, pointDetails, revision } = this.getPointDetails();
56+ let keyfile = ''
57+
58+ const hexRegExp = /[0-9A-Fa-f]{64}/g
59+ const networkSeed = await this.deriveSeed()
60+
61+ const keysmatch = this.checkKeysMatch(networkSeed, pointDetails)
62+ const seedValid = hexRegExp.test(networkSeed)
63+
64+ if (keysmatch && seedValid) {
65+ keyfile = genKey(networkSeed, point, revision)
66+ }
67+
68+ this.setState({
69+ keyfile: keyfile,
70+ loaded: true
71+ });
72+ }
73+
74+ checkKeysMatch(networkSeed, pointDetails) {
7775 const crypub = pointDetails.encryptionKey
7876 const sgnpub = pointDetails.authenticationKey
7977
@@ -83,77 +81,64 @@ class GenKeyfile extends React.Component {
8381 crypub === addHexPrefix(crypt.public)
8482 && sgnpub === addHexPrefix(auth.public)
8583
86− const warning =
87− keyfile !== '' && keysmatch === false
88− ? <Row>
89− <Col>
90− <b>{ 'WARNING' }</b>{ ": derived key doesn't match Azimuth keys!" }
91− </Col>
92− </Row>
93− : <div />
84+ return keysmatch;
85+ }
9486
95− const hexRegExp = /[0-9A-Fa-f]{64}/g
87+ async deriveSeed() {
88+ const next = false
89+ let seed = await attemptSeedDerivation(next, this.props)
9690
97− const download =
98− keyfile !== ''
99− ? <Button
100− onClick={
101− () => {
102− let blob = new Blob([keyfile], {type:"text/plain;charset=utf-8"});
103− saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`)
104− }
105− }>
106− Download →
107− </Button>
108− : ''
109−
110− let networkSeedWarning
111−
112− if (this.state.networkSeed === '') {
113− networkSeedWarning = (
114− <P>
115− <b>Warning: </b>
116− { "No network seed detected. To generate a keyfile, you must reset your networking keys." }
117− </P>
118− )
91+ if (seed.getOrElse('') === '' && this.props.networkSeedCache) {
92+ seed = Maybe.Just(this.props.networkSeedCache)
11993 }
12094
95+ return seed.getOrElse('')
96+ }
97+
98+ render() {
99+ const { point, pointDetails, revision } = this.getPointDetails();
100+ const { keyfile, loading } = this.state
101+
121102 return (
122103 <Row>
123104 <Col className={'col-md-8'}>
124105 <H1>{ 'Generate keyfile' }</H1>
125106
126107 <P>
127− { "Generate a private key file for booting this point in Arvo." }
108+ { "Download a private key file for booting this point in Arvo." }
128109 </P>
129110
130− { networkSeedWarning }
131−
132− <Button
133− className={'mt-8'}
134− color={'blue'}
135− disabled={this.state.networkSeed === ''}
136− onClick={
137− () => {
138− if (hexRegExp.test(networkSeed)) {
139− const keyfile = genKey(networkSeed, point, revision)
140− this.setState({ keyfile })
141− }
142− }
143− }
144− >
145− { 'Generate →' }
146− </Button>
147−
148− { keyfile !== '' &&
149− <Code className="pb-5">
150− { keyfile }
151− </Code>
111+ { keyfile === '' &&
112+ <P>
113+ { "Generating keyfile..." }
114+ </P>
152115 }
153116
154− { warning }
117+ { keyfile === '' &&
118+ <P>
119+ <b>Warning: </b>
120+ { `No valid network seed detected. To generate a keyfile, you
121+ must reset your networking keys, or try logging in with your
122+ master ticket or management mnemonic` }
123+ </P>
124+ }
155125
156− { download }
126+ { keyfile !== '' &&
127+ <React.Fragment>
128+ <div className="pb-5 text-code keyfile">
129+ { keyfile }
130+ </div>
131+ <Button
132+ onClick={
133+ () => {
134+ let blob = new Blob([keyfile], {type:"text/plain;charset=utf-8"});
135+ saveAs(blob, `${ob.patp(point).slice(1)}-${revision}.key`)
136+ }
137+ }>
138+ Download →
139+ </Button>
140+ </React.Fragment>
141+ }
157142
158143 </Col>
159144 </Row>