intent api: restore key
This commit is contained in:
parent
bb7ffd9692
commit
1060c69623
|
@ -70,6 +70,7 @@ import org.torproject.android.ui.ImageProgressView;
|
|||
import org.torproject.android.ui.PromoAppsActivity;
|
||||
import org.torproject.android.ui.Rotate3dAnimation;
|
||||
import org.torproject.android.ui.hiddenservices.HiddenServicesActivity;
|
||||
import org.torproject.android.ui.hiddenservices.backup.BackupUtils;
|
||||
import org.torproject.android.ui.hiddenservices.providers.HSContentProvider;
|
||||
import org.torproject.android.vpn.VPNEnableActivity;
|
||||
|
||||
|
@ -559,7 +560,11 @@ public class OrbotMainActivity extends AppCompatActivity
|
|||
stopVpnService();
|
||||
}
|
||||
|
||||
private void enableHiddenServicePort(String hsName, final int hsPort, int hsRemotePort, final String backupToPackage, final String keyZipPath) throws RemoteException, InterruptedException {
|
||||
private void enableHiddenServicePort(
|
||||
String hsName, final int hsPort, int hsRemotePort,
|
||||
final String backupToPackage, final Uri hsKeyPath
|
||||
) throws RemoteException, InterruptedException {
|
||||
|
||||
String onionHostname = null;
|
||||
|
||||
if (hsName == null)
|
||||
|
@ -620,13 +625,12 @@ public class OrbotMainActivity extends AppCompatActivity
|
|||
if (onion != null && onion.getCount() > 0) {
|
||||
hostname = onion.getString(onion.getColumnIndex(HSContentProvider.HiddenService.NAME));
|
||||
nResult.putExtra("hs_host", hostname);
|
||||
/* TODO
|
||||
|
||||
if (hsKeyPath != null) {
|
||||
BackupUtils hsutils = new BackupUtils(getApplicationContext());
|
||||
if (keyZipPath != null && keyZipPath.length() > 0) {
|
||||
// hsutils.restoreZipBackup(hsPort, keyZipPath);
|
||||
hsutils.restoreKeyBackup(hsPort, hsKeyPath);
|
||||
requestTorRereadConfig();
|
||||
}
|
||||
*/
|
||||
|
||||
if (backupToPackage != null && backupToPackage.length() > 0) {
|
||||
String servicePath = getFilesDir() + "/" + TorServiceConstants.HIDDEN_SERVICES_DIR + "/hs" + hsPort;
|
||||
|
@ -682,7 +686,7 @@ public class OrbotMainActivity extends AppCompatActivity
|
|||
final int hiddenServiceRemotePort = intent.getIntExtra("hs_onion_port", -1);
|
||||
final String hiddenServiceName = intent.getStringExtra("hs_name");
|
||||
final String backupToPackage = intent.getStringExtra("hs_backup_to_package");
|
||||
final String keyZipPath = intent.getStringExtra("hs_key_path");
|
||||
final Uri mKeyUri = intent.getData();
|
||||
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
|
||||
|
@ -692,7 +696,7 @@ public class OrbotMainActivity extends AppCompatActivity
|
|||
try {
|
||||
enableHiddenServicePort(
|
||||
hiddenServiceName, hiddenServicePort,
|
||||
hiddenServiceRemotePort, backupToPackage, keyZipPath
|
||||
hiddenServiceRemotePort, backupToPackage, mKeyUri
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.content.ContentResolver;
|
|||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
@ -15,8 +17,11 @@ import org.torproject.android.ui.hiddenservices.storage.ExternalStorage;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -204,4 +209,24 @@ public class BackupUtils {
|
|||
|
||||
Toast.makeText(mContext, R.string.backup_restored, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
public void restoreKeyBackup(int hsPort, Uri hsKeyPath) {
|
||||
String keyFilePath = mHSBasePath + "/hs" + hsPort + "/private_key";
|
||||
|
||||
try {
|
||||
ParcelFileDescriptor mInputPFD = mContext.getContentResolver().openFileDescriptor(hsKeyPath, "r");
|
||||
InputStream fileStream = new FileInputStream(mInputPFD.getFileDescriptor());
|
||||
OutputStream file = new FileOutputStream(keyFilePath);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = fileStream.read(buffer)) > 0) {
|
||||
file.write(buffer, 0, length);
|
||||
}
|
||||
file.close();
|
||||
|
||||
} catch (IOException | NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue