diff options
Diffstat (limited to 'OpenKeychain')
3 files changed, 105 insertions, 42 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateGithubFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateGithubFragment.java index b30fc091e..de3493e0a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateGithubFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdCreateGithubFragment.java @@ -26,12 +26,13 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.net.URI; import java.net.URL; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; +import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -44,20 +45,34 @@ import org.json.JSONObject; import org.sufficientlysecure.keychain.BuildConfig; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.linked.LinkedAttribute; +import org.sufficientlysecure.keychain.linked.resources.GithubResource; +import org.sufficientlysecure.keychain.operations.results.EditKeyResult; +import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; +import org.sufficientlysecure.keychain.service.SaveKeyringParcel; +import org.sufficientlysecure.keychain.ui.base.CryptoOperationFragment; import org.sufficientlysecure.keychain.ui.widget.StatusIndicator; import org.sufficientlysecure.keychain.util.Log; -public class LinkedIdCreateGithubFragment extends Fragment { +public class LinkedIdCreateGithubFragment extends CryptoOperationFragment<SaveKeyringParcel,EditKeyResult> { ViewAnimator mButtonContainer; StatusIndicator mStatus1, mStatus2, mStatus3; + byte[] mFingerprint; + long mMasterKeyId; + private SaveKeyringParcel mSaveKeyringParcel; + public static LinkedIdCreateGithubFragment newInstance() { return new LinkedIdCreateGithubFragment(); } + public LinkedIdCreateGithubFragment() { + super(null); + } + @Override @NonNull public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.linked_create_github_fragment, container, false); @@ -83,6 +98,9 @@ public class LinkedIdCreateGithubFragment extends Fragment { super.onResume(); LinkedIdWizard wizard = (LinkedIdWizard) getActivity(); + mFingerprint = wizard.mFingerprint; + mMasterKeyId = wizard.mMasterKeyId; + final String oAuthCode = wizard.oAuthGetCode(); final String oAuthState = wizard.oAuthGetState(); if (oAuthCode == null) { @@ -90,6 +108,8 @@ public class LinkedIdCreateGithubFragment extends Fragment { return; } + final String gistText = GithubResource.generate(wizard, mFingerprint); + Log.d(Constants.TAG, "got code: " + oAuthCode); new AsyncTask<Void,Void,JSONObject>() { @@ -137,7 +157,7 @@ public class LinkedIdCreateGithubFragment extends Fragment { } mStatus1.setDisplayedChild(2); - step2PostGist(result.optString("access_token")); + step2PostGist(result.optString("access_token"), gistText); } }.execute(); @@ -177,7 +197,7 @@ public class LinkedIdCreateGithubFragment extends Fragment { } - private void step2PostGist(final String accessToken) { + private void step2PostGist(final String accessToken, final String gistText) { mStatus2.setDisplayedChild(1); @@ -189,7 +209,7 @@ public class LinkedIdCreateGithubFragment extends Fragment { long timer = System.currentTimeMillis(); JSONObject file = new JSONObject(); - file.put("content", "hello!"); + file.put("content", gistText); JSONObject files = new JSONObject(); files.put("file1.txt", file); @@ -230,12 +250,57 @@ public class LinkedIdCreateGithubFragment extends Fragment { return; } - mStatus2.setDisplayedChild(2); + try { + String gistId = result.getString("id"); + JSONObject owner = result.getJSONObject("owner"); + String gistLogin = owner.getString("login"); + + URI uri = URI.create("https://gist.github.com/" + gistLogin + "/" + gistId); + GithubResource resource = GithubResource.create(uri); + + mStatus2.setDisplayedChild(2); + step3EditKey(resource); + + } catch (JSONException e) { + mStatus2.setDisplayedChild(3); + e.printStackTrace(); + } + } }.execute(); } + private void step3EditKey(GithubResource resource) { + + mStatus3.setDisplayedChild(1); + + WrappedUserAttribute ua = LinkedAttribute.fromResource(resource).toUserAttribute(); + mSaveKeyringParcel = new SaveKeyringParcel(mMasterKeyId, mFingerprint); + mSaveKeyringParcel.mAddUserAttribute.add(ua); + + cryptoOperation(); + + } + + @Nullable + @Override + public SaveKeyringParcel createOperationInput() { + // if this is null, the cryptoOperation silently aborts - which is what we want in that case + return mSaveKeyringParcel; + } + + @Override + public void onCryptoOperationSuccess(EditKeyResult result) { + mStatus3.setDisplayedChild(2); + } + + @Override + public void onCryptoOperationError(EditKeyResult result) { + result.createNotify(getActivity()).show(this); + mStatus3.setDisplayedChild(3); + } + private static JSONObject jsonHttpRequest(String url, JSONObject params, String accessToken) throws IOException { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index 2fb6384b2..3441bb399 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -138,16 +138,14 @@ public class LinkedIdWizard extends BaseActivity { super.onNewIntent(intent); Uri uri = intent.getData(); - if (uri != null) { - Log.d(Constants.TAG, "received oauth uri: " + uri); + Log.d(Constants.TAG, "received oauth uri: " + uri); + if (mOAuthState != null && uri != null) { String state = uri.getQueryParameter("state"); if (!mOAuthState.equalsIgnoreCase(state)) { - Notify.create(this, "Authentication Error!", Style.ERROR).show(); + Notify.create(this, "OAuth State Error!", Style.ERROR).show(); return; } mOAuthCode = uri.getQueryParameter("code"); - } else { - Log.d(Constants.TAG, "received oauth uri: null"); } } diff --git a/OpenKeychain/src/main/res/layout/view_key_fragment.xml b/OpenKeychain/src/main/res/layout/view_key_fragment.xml index f060636a2..5bf36f564 100644 --- a/OpenKeychain/src/main/res/layout/view_key_fragment.xml +++ b/OpenKeychain/src/main/res/layout/view_key_fragment.xml @@ -10,37 +10,6 @@ android:paddingTop="16dp"> <android.support.v7.widget.CardView - android:id="@+id/card_view" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_gravity="center" - card_view:cardBackgroundColor="?attr/colorCardViewBackground" - card_view:cardCornerRadius="4dp" - card_view:cardElevation="2dp" - card_view:cardUseCompatPadding="true"> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical"> - - <TextView - style="@style/CardViewHeader" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/section_user_ids" /> - - <org.sufficientlysecure.keychain.ui.widget.FixedListView - android:id="@+id/view_key_user_ids" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="4dp" /> - - </LinearLayout> - - </android.support.v7.widget.CardView> - - <android.support.v7.widget.CardView android:id="@+id/card_linked_ids" android:transitionName="card_linked_ids" android:layout_gravity="center" @@ -95,6 +64,37 @@ </android.support.v7.widget.CardView> <android.support.v7.widget.CardView + android:id="@+id/card_view" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + card_view:cardBackgroundColor="?attr/colorCardViewBackground" + card_view:cardCornerRadius="4dp" + card_view:cardElevation="2dp" + card_view:cardUseCompatPadding="true"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical"> + + <TextView + style="@style/CardViewHeader" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/section_user_ids" /> + + <org.sufficientlysecure.keychain.ui.widget.FixedListView + android:id="@+id/view_key_user_ids" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="4dp" /> + + </LinearLayout> + + </android.support.v7.widget.CardView> + + <android.support.v7.widget.CardView android:id="@+id/linked_system_contact_card" android:layout_width="match_parent" android:layout_height="wrap_content" |