Don't choke so hard on random QR codes

Fixes #4642
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-11-22 09:28:36 -08:00
parent d21fe517e4
commit 9b3457f0b2
2 changed files with 12 additions and 0 deletions

View File

@ -363,6 +363,7 @@
<string name="DeviceProvisioningActivity_content_progress_network_error">Network error.</string>
<string name="DeviceProvisioningActivity_content_progress_key_error">Invalid QR code.</string>
<string name="DeviceProvisioningActivity_sorry_you_have_too_many_devices_linked_already">Sorry, you have too many devices linked already, try removing some...</string>
<string name="DeviceActivity_sorry_this_is_not_a_valid_device_link_qr_code">Sorry, this is not a valid device link QR code.</string>
<!-- PassphrasePromptActivity -->
<string name="PassphrasePromptActivity_enter_passphrase">Enter passphrase</string>

View File

@ -6,6 +6,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.transition.TransitionInflater;
import android.util.Log;
import android.view.MenuItem;
@ -132,6 +133,7 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
private static final int NETWORK_ERROR = 2;
private static final int KEY_ERROR = 3;
private static final int LIMIT_EXCEEDED = 4;
private static final int BAD_CODE = 5;
@Override
protected Integer doInBackground(Void... params) {
@ -141,6 +143,12 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
String verificationCode = accountManager.getNewDeviceVerificationCode();
String ephemeralId = uri.getQueryParameter("uuid");
String publicKeyEncoded = uri.getQueryParameter("pub_key");
if (TextUtils.isEmpty(ephemeralId) || TextUtils.isEmpty(publicKeyEncoded)) {
Log.w(TAG, "UUID or Key is empty!");
return BAD_CODE;
}
ECPublicKey publicKey = Curve.decodePoint(Base64.decode(publicKeyEncoded), 0);
IdentityKeyPair identityKeyPair = IdentityKeyUtil.getIdentityKeyPair(context);
@ -185,6 +193,9 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
case LIMIT_EXCEEDED:
Toast.makeText(context, R.string.DeviceProvisioningActivity_sorry_you_have_too_many_devices_linked_already, Toast.LENGTH_LONG).show();
break;
case BAD_CODE:
Toast.makeText(context, R.string.DeviceActivity_sorry_this_is_not_a_valid_device_link_qr_code, Toast.LENGTH_LONG).show();
break;
}
getSupportFragmentManager().popBackStackImmediate();