Skip to content

Commit

Permalink
handle new verify API response using JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 1, 2024
1 parent 6ca93bf commit 2c1e9aa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions app/src/main/java/app/attestation/auditor/RemoteVerifyJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import androidx.preference.PreferenceManager;

import com.google.common.io.CharStreams;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
Expand All @@ -32,6 +34,9 @@
import java.util.concurrent.Future;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import app.attestation.auditor.AttestationProtocol.AttestationResult;

public class RemoteVerifyJob extends JobService {
Expand Down Expand Up @@ -184,12 +189,8 @@ public boolean onStartJob(final JobParameters params) {
final int responseCode = connection.getResponseCode();
if (responseCode == 200) {
try (final InputStream postResponse = connection.getInputStream()) {
final BufferedReader postReader = new BufferedReader(new InputStreamReader(postResponse));
final String[] tokens = postReader.readLine().split(" ");
if (tokens.length < 2) {
throw new GeneralSecurityException("missing fields");
}
final int interval = Integer.parseInt(tokens[1]);
final JSONObject response = new JSONObject(CharStreams.toString(new InputStreamReader(postResponse)));
final int interval = response.getInt("verifyInterval");
preferences.edit().remove(KEY_SUBSCRIBE_KEY).putInt(KEY_INTERVAL, interval).apply();
schedule(context, interval);
}
Expand All @@ -199,7 +200,7 @@ public boolean onStartJob(final JobParameters params) {
}
throw new IOException("response code: " + responseCode);
}
} catch (final GeneralSecurityException | IOException | NumberFormatException e) {
} catch (final GeneralSecurityException | IOException | JSONException e) {
Log.e(TAG, "remote verify failure", e);
exceptionMessage = e.toString();
failure = true;
Expand Down

0 comments on commit 2c1e9aa

Please sign in to comment.