use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class MemberEnterEmail method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.fragment_teams_invite_inperson_member_enter_email, container, false);
email = v.findViewById(R.id.memberEmailInPerson);
email.setText("loading...");
email.setTextColor(getResources().getColor(R.color.appGray, null));
email.setEnabled(false);
Email.colorValidEmail(email);
nextButton = v.findViewById(R.id.inpersonEmailNext);
nextButton.setOnClickListener(b -> {
EventBus.getDefault().unregister(this);
nextButton.setEnabled(false);
new Thread(() -> {
try {
new MeStorage(getContext()).setEmail(email.getText().toString().trim());
} catch (CryptoException e) {
co.krypt.krypton.uiutils.Error.shortToast(getContext(), "Failed to set email: " + e.getMessage());
e.printStackTrace();
return;
}
getActivity().runOnUiThread(() -> Transitions.beginSlide(this).replace(R.id.fragmentOverlay, new MemberQR()).addToBackStack(null).commitAllowingStateLoss());
}).start();
});
nextButton.setEnabled(false);
EventBus.getDefault().register(this);
EventBus.getDefault().post(new GetProfile(getContext()));
return v;
}
use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class Log method fromSSHRequest.
public static Log fromSSHRequest(Pairing pairing, Request req, SignRequest signRequest, Body.SSH.Result res) {
Log log = new Log();
log.session = new Session();
log.session.deviceName = pairing.workstationName;
try {
log.session.workstationPublicKeyDoubleHash = SHA256.digest(SHA256.digest(pairing.workstationPublicKey));
} catch (CryptoException e) {
log.session.workstationPublicKeyDoubleHash = new byte[] {};
e.printStackTrace();
}
log.unixSeconds = req.unixSeconds;
Body body = new Body();
body.ssh = new Body.SSH();
if (signRequest.hostNameVerified && signRequest.hostAuth.hostNames.length > 0) {
Body.SSH.HostAuthorization hostAuthorization = new Body.SSH.HostAuthorization();
hostAuthorization.host = signRequest.hostAuth.hostNames[0];
hostAuthorization.publicKey = signRequest.hostAuth.hostKey;
hostAuthorization.signature = signRequest.hostAuth.signature;
body.ssh.hostAuthorization = hostAuthorization;
}
body.ssh.sessionData = signRequest.data;
body.ssh.user = signRequest.user();
body.ssh.result = res;
log.body = body;
return log;
}
use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class Log method fromGitRequest.
public static Log fromGitRequest(Pairing pairing, Request req, GitSignRequest gitSignRequest, Body.GitSignatureResult res) {
Log log = new Log();
log.session = new Session();
log.session.deviceName = pairing.workstationName;
try {
log.session.workstationPublicKeyDoubleHash = SHA256.digest(SHA256.digest(pairing.workstationPublicKey));
} catch (CryptoException e) {
log.session.workstationPublicKeyDoubleHash = new byte[] {};
e.printStackTrace();
}
log.unixSeconds = req.unixSeconds;
Body body = new Body();
gitSignRequest.body.visit(new GitSignRequestBody.Visitor<Void, RuntimeException>() {
@Override
public Void visit(CommitInfo commit) throws RuntimeException {
Body.GitCommitSignature gitCommitSignature = new Body.GitCommitSignature();
gitCommitSignature.tree = commit.tree;
gitCommitSignature.author = commit.author;
gitCommitSignature.committer = commit.committer;
gitCommitSignature.message = commit.message;
gitCommitSignature.messageString = commit.validatedMessageStringOrError();
if (commit.mergeParents != null) {
gitCommitSignature.parents = commit.mergeParents.toArray(new String[] {});
} else {
gitCommitSignature.parents = new String[] {};
}
gitCommitSignature.result = res;
body.gitCommit = gitCommitSignature;
return null;
}
@Override
public Void visit(TagInfo tag) throws RuntimeException {
Body.GitTagSignature gitTagSignature = new Body.GitTagSignature();
gitTagSignature.message = tag.message;
gitTagSignature.messageString = tag.validatedMessageStringOrError();
gitTagSignature.tag = tag.tag;
gitTagSignature.tagger = tag.tagger;
gitTagSignature.object = tag.object;
gitTagSignature.type = tag.type;
body.gitTag = gitTagSignature;
return null;
}
});
log.body = body;
return log;
}
use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class Silo method unpair.
public void unpair(Pairing pairing, boolean sendResponse) {
if (sendResponse) {
Response unpairResponse = new Response();
unpairResponse.requestID = "";
unpairResponse.unpairResponse = new UnpairResponse();
try {
send(pairing, unpairResponse);
} catch (CryptoException | TransportException e) {
e.printStackTrace();
}
}
synchronized (pairingsLock) {
pairingStorage.unpair(pairing);
activePairingsByUUID.remove(pairing.uuid);
SQSPoller poller = pollers.remove(pairing);
if (poller != null) {
poller.stop();
}
bluetoothTransport.remove(pairing);
}
}
use of co.krypt.krypton.exception.CryptoException in project krypton-android by kryptco.
the class OnboardingVerifyEmailFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_teams_onboarding_verify_email, container, false);
Button cancelButton = rootView.findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(v -> {
progress.reset();
getActivity().finish();
});
ProgressBar progressBar = rootView.findViewById(R.id.progressBar);
progressBar.setAlpha(0);
Button changeButton = rootView.findViewById(R.id.changeButton);
changeButton.setEnabled(false);
Button resendButton = rootView.findViewById(R.id.resendButton);
resendButton.setEnabled(false);
ConstraintLayout checkYourEmailContainer = rootView.findViewById(R.id.checkYourEmailContainer);
checkYourEmailContainer.setAlpha(0);
AppCompatTextView teamName = rootView.findViewById(R.id.teamName);
teamName.setText(progress.getTeamOnboardingData().name);
emailEditText = rootView.findViewById(R.id.profileEmail);
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
Runnable focusEmail = () -> {
emailEditText.setEnabled(true);
emailEditText.requestFocus();
if (imm != null) {
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
progressBar.animate().alpha(0).setDuration(500).start();
};
focusEmail.run();
Runnable requestEmailChallenge = () -> {
emailEditText.setEnabled(false);
emailEditText.clearFocus();
if (imm != null) {
imm.hideSoftInputFromWindow(emailEditText.getWindowToken(), 0);
}
progressBar.animate().alpha(1).setDuration(1000).start();
final String email = emailEditText.getEditableText().toString();
new Thread(() -> {
MeStorage meStorage = Silo.shared(getContext()).meStorage();
try {
meStorage.setEmail(email);
} catch (CryptoException e) {
Error.shortToast(getContext(), "Failed to set email: " + e.getMessage());
e.printStackTrace();
return;
}
Profile me = meStorage.load();
progress.updateTeamData((s, d) -> {
if (s.equals(CreateStage.VERIFY_EMAIL) || s.equals(CreateStage.EMAIL_CHALLENGE_SENT)) {
d.creatorProfile = me;
Log.i(TAG, "requesting email challenge...");
try {
final Sigchain.NativeResult<JsonObject> result = TeamDataProvider.requestEmailChallenge(getContext(), email);
emailEditText.post(() -> {
if (result.success != null) {
Log.i(TAG, "request email challenge success");
progressBar.animate().alpha(0).setDuration(500).start();
checkYourEmailContainer.animate().alpha(1).setDuration(1000).start();
changeButton.setEnabled(true);
resendButton.setEnabled(true);
} else {
Log.i(TAG, "request email challenge failure: " + result.error);
Error.shortToast(getContext(), "Error sending email: " + result.error);
focusEmail.run();
}
});
if (result.success != null) {
return CreateStage.EMAIL_CHALLENGE_SENT;
} else {
return s;
}
} catch (Native.NotLinked notLinked) {
notLinked.printStackTrace();
}
}
return s;
});
}).start();
};
emailEditText.setOnEditorActionListener((v, i, ev) -> {
requestEmailChallenge.run();
return false;
});
emailEditText.setOnFocusChangeListener((view, b) -> {
if (view.isEnabled() && !b) {
requestEmailChallenge.run();
}
});
resendButton.setOnClickListener(v -> {
requestEmailChallenge.run();
});
changeButton.setOnClickListener(v -> {
focusEmail.run();
});
Button submitButton = rootView.findViewById(R.id.submitButton);
submitButton.setEnabled(false);
submitButton.setAlpha(0);
submitButton.setOnClickListener(v -> {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
fragmentManager.beginTransaction().setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_right, R.anim.exit_to_left).replace(R.id.fragment_teams, new OnboardingLoadTeamFragment()).commitNowAllowingStateLoss();
}
});
EventBus.getDefault().register(this);
EventBus.getDefault().post(new IdentityService.GetProfile(getContext()));
return rootView;
}
Aggregations