private void resume() { try { final PepperClient pepperClientCandidate = new PepperClient( DeviceType.MOBILE, getPreference("server_url"), getPreference("user_name"), SecurityService.systemDecrypt( ConversionUtil.base64ToBytes(getPreference("device_totp_secret_encrypted")))); if (pepperClientCandidate.isAvailable()) { pepperClient = pepperClientCandidate; final String fireBaseToken = FirebaseInstanceId.getInstance().getToken(); if (fireBaseToken != null) { pepperClient.processCommand("register firebase token " + fireBaseToken); } } else { showToast("Server is not available."); return; } } catch (final Exception e) { LOGGER.error("Error creating client and connecting to server.", e); showToast( "Error connecting to server " + e.getClass().getSimpleName() + " : " + e.getMessage()); } dozing = false; paused = false; RemoteControlReceiver.setMainActivity(this); audioManager.registerMediaButtonEventReceiver(remoteControlResponder); speechController = new SpeechController(this, this); }
private void process() { try { DOMConfigurator.configure("log4j.xml"); consoleReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Master password:"******"Invalid password"); } } if (!new File(PRIVATE_KEY_FILE_PATH).exists()) { final KeyPair keyPair = SecurityUtil.generateKeyPairKey(); FileUtil.writeFile( PRIVATE_KEY_FILE_PATH, SecurityService.systemKeyEncrypt(keyPair.getPrivate().getEncoded())); FileUtil.writeFile( PUBLIC_KEY_FILE_PATH, ConversionUtil.bytesToBase64(keyPair.getPublic().getEncoded()) .getBytes(Constants.UTF_8)); System.out.println( "Public key: " + ConversionUtil.bytesToBase64(keyPair.getPublic().getEncoded())); } if (!new File(ACCOUNT_NAME_FILE_PATH).exists()) { System.out.println("Account name:"); final String accountName = readLine(); FileUtil.writeFile(ACCOUNT_NAME_FILE_PATH, accountName.getBytes(Constants.UTF_8)); } final String account = new String(FileUtil.readFile(ACCOUNT_NAME_FILE_PATH), Constants.UTF_8); if (!new File(TOTP_SECRET_FILE_PATH).exists()) { System.out.println("TOTP secret:"); final String totpSecretBase64 = readLine(); final PrivateKey privateKey = SecurityUtil.getPrivateKey( SecurityService.systemKeyDecrypt(FileUtil.readFile(PRIVATE_KEY_FILE_PATH))); final byte[] totpSecretBytesEncrypted = ConversionUtil.base64ToBytes(totpSecretBase64); final byte[] totpSecretBytes = SecurityUtil.decryptAsymmetric( SecurityService.SYSTEM_KEY_ENCRYPTION_IV, privateKey, totpSecretBytesEncrypted); if (totpSecretBytes.length != 20) { System.out.println("Incorrect TOTP secret length: " + totpSecretBytes.length); System.exit(1); } final byte[] totpSecretEncryptedBytes = SecurityService.systemEncrypt(totpSecretBytes); FileUtil.writeFile(TOTP_SECRET_FILE_PATH, totpSecretEncryptedBytes); } final byte[] totpSecret = SecurityService.systemDecrypt(FileUtil.readFile(TOTP_SECRET_FILE_PATH)); System.out.println("Started."); final PepperClient client = new PepperClient(DeviceType.COMPUTER, "http://127.0.0.1:8090/", account, totpSecret); while (true) { try { final String line = readLine(); if (line.equals("exit") || line.equals("quit")) { break; } final String responseUtterance = client.processCommand(line); System.out.println(responseUtterance); } catch (final Exception e) { LOGGER.error("Error contacting server.", e); System.out.println("error"); } } } catch (final Throwable t) { LOGGER.error("Pepper exited due to unexpected throwable:", t); } }