Bug 722553 - uniformize JPakeClientStage error handling. r=rnewman
authorNick Alexander <nalexander@mozilla.com>
Fri, 02 Mar 2012 17:36:15 -0800
changeset 88470 6f1239da8d0ed2217c4af69b67b9bea4d94ab66d
parent 88469 df9a4129745e16853fd0dfaceaa9c2f4a0e8b303
child 88471 f9fe533c1e8eb446cc633692822b5839835593aa
push id157
push userMs2ger@gmail.com
push dateWed, 07 Mar 2012 19:27:10 +0000
reviewersrnewman
bugs722553
milestone13.0a1
Bug 722553 - uniformize JPakeClientStage error handling. r=rnewman
mobile/android/base/sync/jpake/stage/ComputeKeyVerificationStage.java
mobile/android/base/sync/jpake/stage/GetChannelStage.java
mobile/android/base/sync/jpake/stage/GetRequestStage.java
mobile/android/base/sync/jpake/stage/PutRequestStage.java
mobile/android/base/sync/jpake/stage/VerifyPairingStage.java
--- a/mobile/android/base/sync/jpake/stage/ComputeKeyVerificationStage.java
+++ b/mobile/android/base/sync/jpake/stage/ComputeKeyVerificationStage.java
@@ -16,16 +16,17 @@ import org.mozilla.gecko.sync.setup.Cons
 public class ComputeKeyVerificationStage extends JPakeStage {
 
   @Override
   public void execute(JPakeClient jClient) {
     Logger.debug(LOG_TAG, "Computing verification to send.");
     if (jClient.myKeyBundle == null) {
       Logger.error(LOG_TAG, "KeyBundle has not been set; aborting.");
       jClient.abort(Constants.JPAKE_ERROR_INTERNAL);
+      return;
     }
     try {
       jClient.jOutgoing = computeKeyVerification(jClient.myKeyBundle, jClient.mySignerId);
     } catch (UnsupportedEncodingException e) {
       Logger.error(LOG_TAG, "Failure in key verification.", e);
       jClient.abort(Constants.JPAKE_ERROR_INVALID);
       return;
     } catch (CryptoException e) {
--- a/mobile/android/base/sync/jpake/stage/GetChannelStage.java
+++ b/mobile/android/base/sync/jpake/stage/GetChannelStage.java
@@ -47,34 +47,39 @@ public class GetChannelStage extends JPa
         Logger.debug(LOG_TAG, "Using channel " + channel);
         jClient.makeAndDisplayPin(channel);
 
         jClient.runNextStage();
       }
 
       @Override
       public void handleFailure(String error) {
+        Logger.error(LOG_TAG, "Got HTTP failure: " + error);
         jClient.abort(error);
+        return;
       }
 
       @Override
       public void handleError(Exception e) {
         Logger.error(LOG_TAG, "Threw HTTP exception.", e);
         jClient.abort(Constants.JPAKE_ERROR_CHANNEL);
+        return;
       }
     };
 
     try {
       makeChannelRequest(callbackDelegate, jClient.jpakeServer + "new_channel", jClient.clientId);
     } catch (URISyntaxException e) {
       Logger.error(LOG_TAG, "Incorrect URI syntax.", e);
       jClient.abort(Constants.JPAKE_ERROR_INVALID);
+      return;
     } catch (Exception e) {
       Logger.error(LOG_TAG, "Unexpected exception.", e);
       jClient.abort(Constants.JPAKE_ERROR_INTERNAL);
+      return;
     }
   }
 
   private void makeChannelRequest(final GetChannelStageDelegate callbackDelegate, String getChannelUrl, final String clientId) throws URISyntaxException {
     final BaseResource httpResource = new BaseResource(getChannelUrl);
     httpResource.delegate = new SyncResourceDelegate(httpResource) {
 
       @Override
--- a/mobile/android/base/sync/jpake/stage/GetRequestStage.java
+++ b/mobile/android/base/sync/jpake/stage/GetRequestStage.java
@@ -68,23 +68,26 @@ public class GetRequestStage extends JPa
         }
         Logger.debug(LOG_TAG, "incoming message: " + jClient.jIncoming.toJSONString());
 
         jClient.runNextStage();
       }
 
       @Override
       public void handleFailure(String error) {
+        Logger.error(LOG_TAG, "Got HTTP failure: " + error);
         jClient.abort(error);
+        return;
       }
 
       @Override
       public void handleError(Exception e) {
         Logger.error(LOG_TAG, "Threw HTTP exception.", e);
         jClient.abort(Constants.JPAKE_ERROR_NETWORK);
+        return;
       }
     };
 
     Resource httpRequest;
     try {
       httpRequest = createGetRequest(callbackDelegate, jClient);
     } catch (URISyntaxException e) {
       Logger.error(LOG_TAG, "Incorrect URI syntax.", e);
--- a/mobile/android/base/sync/jpake/stage/PutRequestStage.java
+++ b/mobile/android/base/sync/jpake/stage/PutRequestStage.java
@@ -53,40 +53,45 @@ public class PutRequestStage extends JPa
         Logger.debug(LOG_TAG, "Pause for 2 * pollInterval before continuing.");
         // There's no point in returning early here since the next step will
         // always be a GET, so let's pause for twice the poll interval.
         timer.schedule(runNextStage, 2 * jClient.jpakePollInterval);
       }
 
       @Override
       public void handleFailure(String error) {
+        Logger.error(LOG_TAG, "Got HTTP failure: " + error);
         jClient.abort(error);
+        return;
       }
 
       @Override
       public void handleError(Exception e) {
         Logger.error(LOG_TAG, "HTTP exception.", e);
         jClient.abort(Constants.JPAKE_ERROR_NETWORK);
+        return;
       }
     };
 
     // Create PUT request.
     Resource putRequest;
     try {
       putRequest = createPutRequest(callbackDelegate, jClient);
     } catch (URISyntaxException e) {
       Logger.error(LOG_TAG, "URISyntaxException", e);
       jClient.abort(Constants.JPAKE_ERROR_CHANNEL);
       return;
     }
 
     try {
       putRequest.put(JPakeClient.jsonEntity(jClient.jOutgoing.object));
     } catch (UnsupportedEncodingException e) {
-      e.printStackTrace();
+      Logger.error(LOG_TAG, "UnsupportedEncodingException", e);
+      jClient.abort(Constants.JPAKE_ERROR_INTERNAL);
+      return;
     }
     Logger.debug(LOG_TAG, "Outgoing message: " + jClient.jOutgoing.toJSONString());
   }
 
   private Resource createPutRequest(final PutRequestStageDelegate callbackDelegate, final JPakeClient jpakeClient) throws URISyntaxException {
     BaseResource httpResource = new BaseResource(jpakeClient.channelUrl);
     httpResource.delegate = new SyncResourceDelegate(httpResource) {
 
--- a/mobile/android/base/sync/jpake/stage/VerifyPairingStage.java
+++ b/mobile/android/base/sync/jpake/stage/VerifyPairingStage.java
@@ -49,16 +49,17 @@ public class VerifyPairingStage extends 
     }
     if (correctPairing) {
       Logger.debug(LOG_TAG, "Keys verified successfully.");
       jClient.paired = true;
       jClient.onPaired();
     } else {
       Logger.error(LOG_TAG, "Keys don't match.");
       jClient.abort(Constants.JPAKE_ERROR_KEYMISMATCH);
+      return;
     }
   }
 
   /*
    * Helper function to verify an incoming ciphertext and IV against derived
    * keyBundle.
    *
    * (Made 'public' for testing and is a stateless function.)