You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
13 KiB

/*! For license information please see 4.js.LICENSE.txt */
(window.webpackJsonp=window.webpackJsonp||[]).push([[4],{1607:function(e,t,a){"use strict";a.r(t),a.d(t,"default",(function(){return v}));var s=a(82),r=a.n(s),n=a(81),o=a.n(n),i=a(310),c=a.n(i),l=a(85),u=a(86),h=a(84),p=a.n(h),m=a(83),d=a(170),y=a(91),b=a(375),k=a(309);const f=0,_=5;class v extends o.a.PureComponent{constructor(e){super(e),r()(this,"_collectRecoveryKeyNode",e=>{this._recoveryKeyNode=e}),r()(this,"_onCopyClick",()=>{Object(b.a)(this._recoveryKeyNode)&&this.setState({copied:!0,phase:3})}),r()(this,"_onDownloadClick",()=>{const e=new Blob([this._keyBackupInfo.recovery_key],{type:"text/plain;charset=us-ascii"});c.a.saveAs(e,"recovery-key.txt"),this.setState({downloaded:!0,phase:3})}),r()(this,"_createBackup",async()=>{const{secureSecretStorage:e}=this.state;let t;this.setState({phase:4,error:null});try{e?await Object(d.b)(async()=>{t=await u.a.get().prepareKeyBackupVersion(null,{secureSecretStorage:!0}),t=await u.a.get().createKeyBackupVersion(t)}):t=await u.a.get().createKeyBackupVersion(this._keyBackupInfo),await u.a.get().scheduleAllGroupSessionsForBackup(),this.setState({phase:_})}catch(e){console.error("Error creating key backup",e),t&&u.a.get().deleteKeyBackupVersion(t.version),this.setState({error:e})}}),r()(this,"_onCancel",()=>{this.props.onFinished(!1)}),r()(this,"_onDone",()=>{this.props.onFinished(!0)}),r()(this,"_onOptOutClick",()=>{this.setState({phase:6})}),r()(this,"_onSetUpClick",()=>{this.setState({phase:f})}),r()(this,"_onSkipPassPhraseClick",async()=>{this._keyBackupInfo=await u.a.get().prepareKeyBackupVersion(),this.setState({copied:!1,downloaded:!1,phase:2})}),r()(this,"_onPassPhraseNextClick",async e=>{if(e.preventDefault(),this._passphraseField.current){if(await this._passphraseField.current.validate({allowEmpty:!1}),!this._passphraseField.current.state.valid)return this._passphraseField.current.focus(),void this._passphraseField.current.validate({allowEmpty:!1,focused:!0});this.setState({phase:1})}}),r()(this,"_onPassPhraseConfirmNextClick",async e=>{e.preventDefault(),this.state.passPhrase===this.state.passPhraseConfirm&&(this._keyBackupInfo=await u.a.get().prepareKeyBackupVersion(this.state.passPhrase),this.setState({copied:!1,downloaded:!1,phase:2}))}),r()(this,"_onSetAgainClick",()=>{this.setState({passPhrase:"",passPhraseValid:!1,passPhraseConfirm:"",phase:f})}),r()(this,"_onKeepItSafeBackClick",()=>{this.setState({phase:2})}),r()(this,"_onPassPhraseValidate",e=>{this.setState({passPhraseValid:e.valid})}),r()(this,"_onPassPhraseChange",e=>{this.setState({passPhrase:e.target.value})}),r()(this,"_onPassPhraseConfirmChange",e=>{this.setState({passPhraseConfirm:e.target.value})}),this._recoveryKeyNode=null,this._keyBackupInfo=null,this.state={secureSecretStorage:null,phase:f,passPhrase:"",passPhraseValid:!1,passPhraseConfirm:"",copied:!1,downloaded:!1},this._passphraseField=Object(n.createRef)()}async componentDidMount(){const e=u.a.get(),t=await e.doesServerSupportUnstableFeature("org.matrix.e2e_cross_signing");this.setState({secureSecretStorage:t}),t&&(this.setState({phase:4}),this._createBackup())}_renderPhasePassPhrase(){const e=l.getComponent("views.elements.DialogButtons");return o.a.createElement("form",{onSubmit:this._onPassPhraseNextClick},o.a.createElement("p",null,Object(m.a)("<b>Warning</b>: You should only set up key backup from a trusted computer.",{},{b:e=>o.a.createElement("b",null,e)})),o.a.createElement("p",null,Object(m.a)("We'll store an encrypted copy of your keys on our server. Secure your backup with a recovery passphrase.")),o.a.createElement("p",null,Object(m.a)("For maximum security, this should be different from your account password.")),o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_primaryContainer"},o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_passPhraseContainer"},o.a.createElement(k.a,{className:"mx_CreateKeyBackupDialog_passPhraseInput",onChange:this._onPassPhraseChange,minScore:4,value:this.state.passPhrase,onValidate:this._onPassPhraseValidate,fieldRef:this._passphraseField,autoFocus:!0,label:Object(m.b)("Enter a recovery passphrase"),labelEnterPassword:Object(m.b)("Enter a recovery passphrase"),labelStrongPassword:Object(m.b)("Great! This recovery passphrase looks strong enough."),labelAllowedButUnsafe:Object(m.b)("Great! This recovery passphrase looks strong enough.")}))),o.a.createElement(e,{primaryButton:Object(m.a)("Next"),onPrimaryButtonClick:this._onPassPhraseNextClick,hasCancel:!1,disabled:!this.state.passPhraseValid}),o.a.createElement("details",null,o.a.createElement("summary",null,Object(m.a)("Advanced")),o.a.createElement(y.a,{kind:"primary",onClick:this._onSkipPassPhraseClick},Object(m.a)("Set up with a recovery key"))))}_renderPhasePassPhraseConfirm(){const e=l.getComponent("elements.AccessibleButton");let t,a;this.state.passPhraseConfirm===this.state.passPhrase?(t=Object(m.a)("That matches!"),a=Object(m.a)("Use a different passphrase?")):this.state.passPhrase.startsWith(this.state.passPhraseConfirm)||(t=Object(m.a)("That doesn't match."),a=Object(m.a)("Go back to set it again."));let s=null;t&&(s=o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_passPhraseMatch"},o.a.createElement("div",null,t),o.a.createElement("div",null,o.a.createElement(e,{element:"span",className:"mx_linkButton",onClick:this._onSetAgainClick},a))));const r=l.getComponent("views.elements.DialogButtons");return o.a.createElement("form",{onSubmit:this._onPassPhraseConfirmNextClick},o.a.createElement("p",null,Object(m.a)("Please enter your recovery passphrase a second time to confirm.")),o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_primaryContainer"},o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_passPhraseContainer"},o.a.createElement("div",null,o.a.createElement("input",{type:"password",onChange:this._onPassPhraseConfirmChange,value:this.state.passPhraseConfirm,className:"mx_CreateKeyBackupDialog_passPhraseInput",placeholder:Object(m.a)("Repeat your recovery passphrase..."),autoFocus:!0})),s)),o.a.createElement(r,{primaryButton:Object(m.a)("Next"),onPrimaryButtonClick:this._onPassPhraseConfirmNextClick,hasCancel:!1,disabled:this.state.passPhrase!==this.state.passPhraseConfirm}))}_renderPhaseShowKey(){return o.a.createElement("div",null,o.a.createElement("p",null,Object(m.a)("Your recovery key is a safety net - you can use it to restore access to your encrypted messages if you forget your recovery passphrase.")),o.a.createElement("p",null,Object(m.a)("Keep a copy of it somewhere secure, like a password manager or even a safe.")),o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_primaryContainer"},o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_recoveryKeyHeader"},Object(m.a)("Your recovery key")),o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_recoveryKeyContainer"},o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_recoveryKey"},o.a.createElement("code",{ref:this._collectRecoveryKeyNode},this._keyBackupInfo.recovery_key)),o.a.createElement("div",{className:"mx_CreateKeyBackupDialog_recoveryKeyButtons"},o.a.createElement("button",{className:"mx_Dialog_primary",onClick:this._onCopyClick},Object(m.a)("Copy")),o.a.createElement("button",{className:"mx_Dialog_primary",onClick:this._onDownloadClick},Object(m.a)("Download"))))))}_renderPhaseKeepItSafe(){let e;this.state.copied?e=Object(m.a)("Your recovery key has been <b>copied to your clipboard</b>, paste it to:",{},{b:e=>o.a.createElement("b",null,e)}):this.state.downloaded&&(e=Object(m.a)("Your recovery key is in your <b>Downloads</b> folder.",{},{b:e=>o.a.createElement("b",null,e)}));const t=l.getComponent("views.elements.DialogButtons");return o.a.createElement("div",null,e,o.a.createElement("ul",null,o.a.createElement("li",null,Object(m.a)("<b>Print it</b> and store it somewhere safe",{},{b:e=>o.a.createElement("b",null,e)})),o.a.createElement("li",null,Object(m.a)("<b>Save it</b> on a USB key or backup drive",{},{b:e=>o.a.createElement("b",null,e)})),o.a.createElement("li",null,Object(m.a)("<b>Copy it</b> to your personal cloud storage",{},{b:e=>o.a.createElement("b",null,e)}))),o.a.createElement(t,{primaryButton:Object(m.a)("Continue"),onPrimaryButtonClick:this._createBackup,hasCancel:!1},o.a.createElement("button",{onClick:this._onKeepItSafeBackClick},Object(m.a)("Back"))))}_renderBusyPhase(e){const t=l.getComponent("views.elements.Spinner");return o.a.createElement("div",null,o.a.createElement(t,null))}_renderPhaseDone(){const e=l.getComponent("views.elements.DialogButtons");return o.a.createElement("div",null,o.a.createElement("p",null,Object(m.a)("Your keys are being backed up (the first backup could take a few minutes).")),o.a.createElement(e,{primaryButton:Object(m.a)("OK"),onPrimaryButtonClick:this._onDone,hasCancel:!1}))}_renderPhaseOptOutConfirm(){const e=l.getComponent("views.elements.DialogButtons");return o.a.createElement("div",null,Object(m.a)("Without setting up Secure Message Recovery, you won't be able to restore your encrypted message history if you log out or use another session."),o.a.createElement(e,{primaryButton:Object(m.a)("Set up Secure Message Recovery"),onPrimaryButtonClick:this._onSetUpClick,hasCancel:!1},o.a.createElement("button",{onClick:this._onCancel},"I understand, continue without")))}_titleForPhase(e){switch(e){case f:return Object(m.a)("Secure your backup with a recovery passphrase");case 1:return Object(m.a)("Confirm your recovery passphrase");case 6:return Object(m.a)("Warning!");case 2:case 3:return Object(m.a)("Make a copy of your recovery key");case 4:return Object(m.a)("Starting backup...");case _:return Object(m.a)("Success!");default:return Object(m.a)("Create key backup")}}render(){const e=l.getComponent("views.dialogs.BaseDialog");let t;if(this.state.error){const e=l.getComponent("views.elements.DialogButtons");t=o.a.createElement("div",null,o.a.createElement("p",null,Object(m.a)("Unable to create key backup")),o.a.createElement("div",{className:"mx_Dialog_buttons"},o.a.createElement(e,{primaryButton:Object(m.a)("Retry"),onPrimaryButtonClick:this._createBackup,hasCancel:!0,onCancel:this._onCancel})))}else switch(this.state.phase){case f:t=this._renderPhasePassPhrase();break;case 1:t=this._renderPhasePassPhraseConfirm();break;case 2:t=this._renderPhaseShowKey();break;case 3:t=this._renderPhaseKeepItSafe();break;case 4:t=this._renderBusyPhase();break;case _:t=this._renderPhaseDone();break;case 6:t=this._renderPhaseOptOutConfirm()}return o.a.createElement(e,{className:"mx_CreateKeyBackupDialog",onFinished:this.props.onFinished,title:this._titleForPhase(this.state.phase),hasCancel:[f,_].includes(this.state.phase)},o.a.createElement("div",null,t))}}r()(v,"propTypes",{onFinished:p.a.func.isRequired})},310:function(e,t,a){var s,r=r||function(e){"use strict";if(!(void 0===e||"undefined"!=typeof navigator&&/MSIE [1-9]\./.test(navigator.userAgent))){var t=e.document,a=function(){return e.URL||e.webkitURL||e},s=t.createElementNS("http://www.w3.org/1999/xhtml","a"),r="download"in s,n=/constructor/i.test(e.HTMLElement)||e.safari,o=/CriOS\/[\d]+/.test(navigator.userAgent),i=function(t){(e.setImmediate||e.setTimeout)((function(){throw t}),0)},c=function(e){setTimeout((function(){"string"==typeof e?a().revokeObjectURL(e):e.remove()}),4e4)},l=function(e){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([String.fromCharCode(65279),e],{type:e.type}):e},u=function(t,u,h){h||(t=l(t));var p,m=this,d="application/octet-stream"===t.type,y=function(){!function(e,t,a){for(var s=(t=[].concat(t)).length;s--;){var r=e["on"+t[s]];if("function"==typeof r)try{r.call(e,a||e)}catch(e){i(e)}}}(m,"writestart progress write writeend".split(" "))};if(m.readyState=m.INIT,r)return p=a().createObjectURL(t),void setTimeout((function(){var e,t;s.href=p,s.download=u,e=s,t=new MouseEvent("click"),e.dispatchEvent(t),y(),c(p),m.readyState=m.DONE}));!function(){if((o||d&&n)&&e.FileReader){var s=new FileReader;return s.onloadend=function(){var t=o?s.result:s.result.replace(/^data:[^;]*;/,"data:attachment/file;");e.open(t,"_blank")||(e.location.href=t),t=void 0,m.readyState=m.DONE,y()},s.readAsDataURL(t),void(m.readyState=m.INIT)}(p||(p=a().createObjectURL(t)),d)?e.location.href=p:e.open(p,"_blank")||(e.location.href=p);m.readyState=m.DONE,y(),c(p)}()},h=u.prototype;return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(e,t,a){return t=t||e.name||"download",a||(e=l(e)),navigator.msSaveOrOpenBlob(e,t)}:(h.abort=function(){},h.readyState=h.INIT=0,h.WRITING=1,h.DONE=2,h.error=h.onwritestart=h.onprogress=h.onwrite=h.onabort=h.onerror=h.onwriteend=null,function(e,t,a){return new u(e,t||e.name||"download",a)})}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);e.exports?e.exports.saveAs=r:null!==a(311)&&null!==a(312)&&(void 0===(s=function(){return r}.call(t,a,t,e))||(e.exports=s))},311:function(e,t){e.exports=function(){throw new Error("define cannot be used indirect")}},312:function(e,t){(function(t){e.exports=t}).call(this,{})}}]);
//# sourceMappingURL=4.js.map