fix initial request and some cleaning

This commit is contained in:
Matt Hill
2021-09-14 18:45:34 -06:00
committed by Aiden McClelland
parent 9825d66ef3
commit 3dae1a540b
7 changed files with 45 additions and 55 deletions

View File

@@ -18822,9 +18822,7 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": { "requires": {}
"ajv": "^8.0.0"
}
}, },
"tslib": { "tslib": {
"version": "2.3.0", "version": "2.3.0",
@@ -18904,9 +18902,7 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": { "requires": {}
"ajv": "^8.0.0"
}
} }
} }
}, },
@@ -18967,9 +18963,7 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": { "requires": {}
"ajv": "^8.0.0"
}
} }
} }
}, },
@@ -19079,9 +19073,7 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": { "requires": {}
"ajv": "^8.0.0"
}
} }
} }
}, },
@@ -20919,9 +20911,7 @@
"resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.0.tgz",
"integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==", "integrity": "sha512-USH2jBb+C/hIpwD2iRjp0pe0k+MvzG0mlSn/FIdCgQhUb9ALPRjt2KIQdfZDS9r0ZIeUAg7gOu9KL0PFqGqr5Q==",
"dev": true, "dev": true,
"requires": { "requires": {}
"ajv": "^8.0.0"
}
} }
} }
}, },
@@ -21536,9 +21526,7 @@
"integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==", "integrity": "sha512-Brah4Uo5/U8v76c6euTwtjVFFaVishwnJrQBYpev1JRh4vjA1F4HY3UzQez41YUCszUCXKagG8v6eVRBHV1gkw==",
"dev": true, "dev": true,
"peer": true, "peer": true,
"requires": { "requires": {}
"ajv": "^8.0.0"
}
}, },
"alphanum-sort": { "alphanum-sort": {
"version": "1.0.2", "version": "1.0.2",

View File

@@ -29,7 +29,11 @@ const routes: Routes = [
@NgModule({ @NgModule({
imports: [ imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules }) RouterModule.forRoot(routes, {
scrollPositionRestoration: 'enabled',
preloadingStrategy: PreloadAllModules,
useHash: true,
})
], ],
exports: [RouterModule] exports: [RouterModule]
}) })

View File

@@ -15,10 +15,10 @@ export class ProductKeyPage {
constructor( constructor(
private readonly navCtrl: NavController, private readonly navCtrl: NavController,
private stateService: StateService, private readonly stateService: StateService,
private apiService: ApiService, private readonly apiService: ApiService,
private loadingCtrl: LoadingController, private readonly loadingCtrl: LoadingController,
private httpService: HttpService private readonly httpService: HttpService
) {} ) {}
async submit () { async submit () {
@@ -30,8 +30,8 @@ export class ProductKeyPage {
await loader.present() await loader.present()
try { try {
const state = await this.apiService.verifyProductKey(this.productKey)
this.httpService.productKey = this.productKey this.httpService.productKey = this.productKey
const state = await this.apiService.verifyProductKey()
if(state['is-recovering']) { if(state['is-recovering']) {
await this.navCtrl.navigateForward(`/loading`, { animationDirection: 'forward', animation: iosTransitionAnimation }) await this.navCtrl.navigateForward(`/loading`, { animationDirection: 'forward', animation: iosTransitionAnimation })
} else if (!!state['tor-address']) { } else if (!!state['tor-address']) {

View File

@@ -1,9 +1,7 @@
import { Subject } from 'rxjs' import { Subject } from 'rxjs'
export abstract class ApiService { export abstract class ApiService {
protected error$: Subject<string> = new Subject(); abstract verifyProductKey (): Promise<VerifyProductKeyRes>;
watchError$ = this.error$.asObservable();
abstract verifyProductKey (key: string): Promise<VerifyProductKeyRes>;
abstract getDrives (): Promise<DiskInfo[]>; abstract getDrives (): Promise<DiskInfo[]>;
abstract getDataTransferProgress (): Promise<TransferProgressRes>; abstract getDataTransferProgress (): Promise<TransferProgressRes>;
abstract verifyRecoveryPassword (logicalname: string, password: string): Promise<boolean>; abstract verifyRecoveryPassword (logicalname: string, password: string): Promise<boolean>;

View File

@@ -9,7 +9,6 @@ import * as pbkdf2 from 'pbkdf2'
providedIn: 'root', providedIn: 'root',
}) })
export class HttpService { export class HttpService {
private unauthorizedApiResponse$ = new Subject()
fullUrl: string fullUrl: string
productKey: string productKey: string
@@ -20,32 +19,25 @@ export class HttpService {
this.fullUrl = `${window.location.protocol}//${window.location.hostname}:${port}` this.fullUrl = `${window.location.protocol}//${window.location.hostname}:${port}`
} }
watchUnauth$ (): Observable<{ }> {
return this.unauthorizedApiResponse$.asObservable()
}
async rpcRequest<T> (body: RPCOptions): Promise<T> { async rpcRequest<T> (body: RPCOptions): Promise<T> {
const httpOpts = { const httpOpts = {
method: Method.POST, method: Method.POST,
body, body,
url: `this.fullUrl`, url: this.fullUrl,
} }
const res = await this.httpRequest<RPCResponse<T>>(httpOpts) const res = await this.httpRequest<RPCResponse<T>>(httpOpts)
if (isRpcError(res)) { if (isRpcError(res)) throw new RpcError(res.error)
if (res.error.code === 34) this.unauthorizedApiResponse$.next(true)
throw new RpcError(res.error)
}
if (isRpcSuccess(res)) return res.result if (isRpcSuccess(res)) return res.result
} }
async httpRequest<T> (httpOpts: { async httpRequest<T> (httpOpts: {
body: RPCOptions; body: RPCOptions;
url: string; url: string;
}): Promise<T> { }): Promise<T> {
const urlIsRelative = httpOpts.url.startsWith('/') const urlIsRelative = httpOpts.url.startsWith('/')
const url = urlIsRelative ? const url = urlIsRelative ?
@@ -54,15 +46,13 @@ export class HttpService {
const options = { const options = {
responseType: 'arraybuffer', responseType: 'arraybuffer',
body: await AES_CTR.encryptPbkdf2( this.productKey, encodeUtf8( JSON.stringify(httpOpts.body))), body: await AES_CTR.encryptPbkdf2(this.productKey, encodeUtf8( JSON.stringify(httpOpts.body))),
observe: 'events', observe: 'events',
reportProgress: false, reportProgress: false,
headers: { headers: {
'Content-Encoding': 'aesctr256', 'Content-Encoding': 'aesctr256',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
// one minute
timeout: 60000,
} as any } as any
const req = this.http.post(url, httpOpts.body, options) const req = this.http.post(url, httpOpts.body, options)
@@ -157,7 +147,7 @@ export interface HttpOptions {
params?: HttpParams | { params?: HttpParams | {
[param: string]: string | string[] [param: string]: string | string[]
} }
responseType?: 'json' | 'text' responseType?: 'json' | 'text' | 'arrayBuffer'
withCredentials?: boolean withCredentials?: boolean
body?: any body?: any
timeout?: number timeout?: number

View File

@@ -11,35 +11,40 @@ export class LiveApiService extends ApiService {
private readonly http: HttpService private readonly http: HttpService
) { super() } ) { super() }
async verifyProductKey() { async verifyProductKey () {
return this.http.rpcRequest<VerifyProductKeyRes>({ return this.http.rpcRequest<VerifyProductKeyRes>({
method: 'setup.status', method: 'setup.status',
params: {} params: {}
}) })
} }
async getDataTransferProgress() { async getDataTransferProgress () {
return this.http.rpcRequest<TransferProgressRes>({ return this.http.rpcRequest<TransferProgressRes>({
method: 'setup.recovery.status', method: 'setup.recovery.status',
params: {} params: {}
}) })
} }
async getDrives() { async getDrives () {
return this.http.rpcRequest<DiskInfo[]>({ return this.http.rpcRequest<DiskInfo[]>({
method: 'setup.disk.list', method: 'setup.disk.list',
params: {} params: {}
}) })
} }
async verifyRecoveryPassword(logicalname, password) { async verifyRecoveryPassword (logicalname: string, password: string) {
return this.http.rpcRequest<boolean>({ return this.http.rpcRequest<boolean>({
method: 'setup.recovery.test-password', method: 'setup.recovery.test-password',
params: {logicalname, password} params: {logicalname, password}
}) })
} }
async setupEmbassy (setupInfo) { async setupEmbassy (setupInfo: {
'embassy-logicalname': string,
'embassy-password': string
'recovery-logicalname'?: string,
'recovery-password'?: string
}) {
return this.http.rpcRequest<SetupEmbassyRes>({ return this.http.rpcRequest<SetupEmbassyRes>({
method: 'setup.execute', method: 'setup.execute',
params: setupInfo params: setupInfo

View File

@@ -11,7 +11,7 @@ export class MockApiService extends ApiService {
super() super()
} }
async verifyProductKey(key) { async verifyProductKey () {
await pauseFor(2000) await pauseFor(2000)
return { return {
"is-recovering": false, "is-recovering": false,
@@ -19,7 +19,7 @@ export class MockApiService extends ApiService {
} }
} }
async getDataTransferProgress() { async getDataTransferProgress () {
tries = Math.min(tries + 1, 4) tries = Math.min(tries + 1, 4)
return { return {
'bytes-transfered': tries, 'bytes-transfered': tries,
@@ -27,7 +27,7 @@ export class MockApiService extends ApiService {
} }
} }
async getDrives() { async getDrives () {
return [ return [
{ {
vendor: 'Vendor', vendor: 'Vendor',
@@ -102,7 +102,7 @@ export class MockApiService extends ApiService {
] ]
} }
async getRecoveryDrives() { async getRecoveryDrives () {
await pauseFor(2000) await pauseFor(2000)
return [ return [
{ {
@@ -118,12 +118,17 @@ export class MockApiService extends ApiService {
] ]
} }
async verifyRecoveryPassword(logicalname, password) { async verifyRecoveryPassword (logicalname: string, password: string) {
await pauseFor(2000) await pauseFor(2000)
return password.length > 8 return password.length > 8
} }
async setupEmbassy (setupInfo) { async setupEmbassy (setupInfo: {
'embassy-logicalname': string,
'embassy-password': string
'recovery-logicalname'?: string,
'recovery-password'?: string
}) {
await pauseFor(2000) await pauseFor(2000)
return { "tor-address": 'asdfasdfasdf.onion' } return { "tor-address": 'asdfasdfasdf.onion' }
} }