use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.
the class SettingsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_settings, container, false);
Button doneButton = (Button) root.findViewById(R.id.doneButton);
final Fragment self = this;
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MainActivity activity = (MainActivity) getActivity();
activity.postCurrentActivePageView();
getActivity().getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom).hide(self).commit();
}
});
TextView versionText = (TextView) root.findViewById(R.id.versionText);
try {
PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
versionText.setText(packageInfo.versionName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
ImageButton deleteButton = (ImageButton) root.findViewById(R.id.deleteButton);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalAuthentication.requestAuthentication(getActivity(), "Destroy key pair permanently?", "You will have to generate a new key pair and re-add it to services like GitHub.", () -> new Thread(() -> {
try {
new Analytics(getContext()).postEvent("keypair", "destroy", null, null, false);
EventBus.getDefault().post(new TeamService.RequestTeamOperation(Sigchain.RequestableTeamOperation.leave(), C.background(getContext())));
Silo.shared(getContext()).unpairAll();
KeyManager.deleteAllMeKeyPairs(getContext());
new MeStorage(getContext()).delete();
new JoinTeamProgress(getContext()).resetAndDeleteTeam(getContext());
new CreateTeamProgress(getContext()).reset();
startActivity(new Intent(getContext(), OnboardingActivity.class));
} catch (Exception e) {
e.printStackTrace();
}
}).start());
}
});
Button contactButton = (Button) root.findViewById(R.id.contactUsButton);
contactButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:hello@krypt.co?subject=Krypton%20Feedback&body=");
intent.setData(data);
startActivity(intent);
}
});
Button softwareButton = (Button) root.findViewById(R.id.softwareButton);
softwareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://krypt.co/app/open-source-libraries/"));
startActivity(browserIntent);
}
});
Button privacyButton = (Button) root.findViewById(R.id.privacyButton);
privacyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://krypt.co/app/privacy/"));
startActivity(browserIntent);
}
});
SwitchCompat disableAnalyticsSwitch = (SwitchCompat) root.findViewById(R.id.disableAnalyticsSwitch);
disableAnalyticsSwitch.setChecked(new Analytics(getContext()).isDisabled());
disableAnalyticsSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
new Analytics(getContext()).setAnalyticsDisabled(isChecked);
}
});
SwitchCompat enableApprovedNotifications = (SwitchCompat) root.findViewById(R.id.enableAutoApproveNotificationsSwitch);
enableApprovedNotifications.setChecked(new Settings(getContext()).approvedNotificationsEnabled());
enableApprovedNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
new Settings(getContext()).setApprovedNotificationsEnabled(isChecked);
}
});
SwitchCompat silenceNotifications = (SwitchCompat) root.findViewById(R.id.silenceNotificationsSwitch);
silenceNotifications.setChecked(new Settings(getContext()).silenceNotifications());
silenceNotifications.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
new Settings(getContext()).setSilenceNotifications(isChecked);
}
});
ImageButton exportLogsButton = (ImageButton) root.findViewById(R.id.exportLogsButton);
exportLogsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String token = AuditLogContentProvider.setToken(v.getContext());
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Krypton Audit Log");
sendIntent.setType("application/x-sqlite3");
Uri auditLogUriWithToken = AuditLogContentProvider.getAuditLogURIWithToken();
if (auditLogUriWithToken == null) {
return;
}
sendIntent.putExtra(Intent.EXTRA_STREAM, auditLogUriWithToken);
startActivity(sendIntent);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(v.getContext(), "Error exporting audit log: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
Button editKnownHostsButton = (Button) root.findViewById(R.id.editKnownHostsButton);
editKnownHostsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getView().setTranslationZ(0);
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
KnownHostsFragment knownHostsFragment = new KnownHostsFragment();
transaction.setCustomAnimations(R.anim.enter_from_bottom, R.anim.delayed).replace(R.id.fragmentOverlay, knownHostsFragment).commit();
new Analytics(getActivity().getApplicationContext()).postPageView("KnownHostsEdit");
}
});
return root;
}
use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.
the class Silo method handle.
private void handle(Pairing pairing, Request request, String communicationMedium) throws Unrecoverable {
// Allow 15 minutes of clock skew
if (Math.abs(request.unixSeconds - (System.currentTimeMillis() / 1000)) > CLOCK_SKEW_TOLERANCE_SECONDS) {
throw new ProtocolException("invalid request time");
}
if (request.body instanceof UnpairRequest) {
unpair(pairing, false);
new Analytics(context).postEvent("device", "unpair", "request", null, false);
}
synchronized ((Silo.class.getName() + request.requestID).intern()) {
if (sendCachedResponseIfPresent(pairing, request)) {
return;
}
}
EventBus.getDefault().post(new TeamService.UpdateTeamHomeDataIfOutdated(context));
lastRequestTimeSeconds.put(pairing, System.currentTimeMillis() / 1000);
if (Policy.isApprovedNow(this, context, pairing, request)) {
respondToRequest(pairing, request, true);
} else {
if (Policy.requestApproval(context, pairing, request)) {
new Analytics(context).postEvent(request.analyticsCategory(), "requires approval", communicationMedium, null, false);
}
if (request.sendACK != null && request.sendACK) {
Response ackResponse = Response.with(request);
ackResponse.ackResponse = new AckResponse();
send(pairing, ackResponse);
}
}
}
use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.
the class Silo method respondToRequest.
public void respondToRequest(Pairing pairing, Request request, boolean requestAllowed) throws Unrecoverable {
// Fine-grained locking allows performing signatures in parallel
synchronized ((Silo.class.getName() + request.requestID).intern()) {
synchronized (Silo.class) {
if (sendCachedResponseIfPresent(pairing, request)) {
return;
}
}
Response response = Response.with(request);
Analytics analytics = new Analytics(context);
if (analytics.isDisabled()) {
response.trackingID = "disabled";
} else {
response.trackingID = analytics.getClientID();
}
request.body.visit(new RequestBody.Visitor<Void, Unrecoverable>() {
@Override
public Void visit(MeRequest meRequest) throws CryptoException {
response.meResponse = new MeResponse(meStorage.loadWithUserID(meRequest.userID()));
return null;
}
@Override
public Void visit(SignRequest signRequest) throws Unrecoverable {
signRequest.validate();
response.signResponse = new SignResponse();
if (requestAllowed) {
try {
SSHKeyPairI key = MeStorage.getOrLoadKeyPair(context);
if (MessageDigest.isEqual(signRequest.publicKeyFingerprint, key.publicKeyFingerprint())) {
if (signRequest.verifyHostName()) {
String hostName = signRequest.hostAuth.hostNames[0];
String hostKey = Base64.encodeAsString(signRequest.hostAuth.hostKey);
synchronized (databaseLock) {
List<KnownHost> matchingKnownHosts = dbHelper.getKnownHostDao().queryForEq("host_name", hostName);
try {
Sigchain.NativeResult<List<Sigchain.PinnedHost>> teamPinnedHosts = TeamDataProvider.getPinnedKeysByHost(context, hostName);
if (teamPinnedHosts.success != null) {
for (Sigchain.PinnedHost pinnedHost : teamPinnedHosts.success) {
matchingKnownHosts.add(new KnownHost(pinnedHost.host, co.krypt.krypton.crypto.Base64.encode(pinnedHost.publicKey), 0));
}
}
} catch (Native.NotLinked e) {
e.printStackTrace();
}
if (matchingKnownHosts.size() == 0) {
dbHelper.getKnownHostDao().create(new KnownHost(hostName, hostKey, System.currentTimeMillis() / 1000));
broadcastKnownHostsChanged();
} else {
boolean foundKnownHost = false;
List<String> pinnedPublicKeys = new ArrayList<>();
for (KnownHost pinnedHost : matchingKnownHosts) {
pinnedPublicKeys.add(pinnedHost.publicKey);
if (pinnedHost.publicKey.equals(hostKey)) {
foundKnownHost = true;
break;
}
}
if (!foundKnownHost) {
throw new MismatchedHostKeyException(pinnedPublicKeys, "Expected " + pinnedPublicKeys.toString() + " received " + hostKey);
}
}
}
}
String algo = signRequest.algo();
if ((key instanceof RSASSHKeyPair) && request.semVer().lessThan(Versions.KR_SUPPORTS_RSA_SHA256_512)) {
algo = "ssh-rsa";
}
response.signResponse.signature = key.signDigestAppendingPubkey(signRequest.data, algo);
SSHSignatureLog log = new SSHSignatureLog(signRequest.data, true, signRequest.command, signRequest.user(), signRequest.firstHostnameIfExists(), System.currentTimeMillis() / 1000, signRequest.verifyHostName(), JSON.toJson(signRequest.hostAuth), pairing.getUUIDString(), pairing.workstationName);
co.krypt.krypton.team.log.Log teamLog = co.krypt.krypton.team.log.Log.fromSSHRequest(pairing, request, signRequest, co.krypt.krypton.team.log.Log.Body.SSH.Result.signature(response.signResponse.signature));
EventBus.getDefault().post(new TeamService.EncryptLog(C.background(context), teamLog));
pairingStorage.appendToSSHLog(log);
Notifications.notifySuccess(context, pairing, request, log);
if (signRequest.verifiedHostNameOrDefault("unknown host").equals("me.krypt.co")) {
Intent sshMeIntent = new Intent(TestSSHFragment.SSH_ME_ACTION);
LocalBroadcastManager.getInstance(context).sendBroadcast(sshMeIntent);
}
if (signRequest.hostAuth == null) {
new Analytics(context).postEvent("host", "unknown", null, null, false);
} else if (!signRequest.verifyHostName()) {
new Analytics(context).postEvent("host", "unverified", null, null, false);
}
} else {
Log.e(TAG, Base64.encodeAsString(signRequest.publicKeyFingerprint) + " != " + Base64.encodeAsString(key.publicKeyFingerprint()));
response.signResponse.error = "unknown key fingerprint";
}
} catch (SQLException e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
response.signResponse.error = "SQL error: " + e.getMessage() + "\n" + sw.toString();
e.printStackTrace();
} catch (MismatchedHostKeyException e) {
response.signResponse.error = "host public key mismatched";
if (signRequest.hostAuth.hostKey != null) {
co.krypt.krypton.team.log.Log teamLog = co.krypt.krypton.team.log.Log.fromSSHRequest(pairing, request, signRequest, co.krypt.krypton.team.log.Log.Body.SSH.Result.hostMismatch(e.pinnedPublicKeys.toArray(new String[] {})));
EventBus.getDefault().post(new TeamService.EncryptLog(C.background(context), teamLog));
}
Notifications.notifyReject(context, pairing, request, "Host public key mismatched.");
e.printStackTrace();
}
} else {
response.signResponse.error = "rejected";
co.krypt.krypton.team.log.Log teamLog = co.krypt.krypton.team.log.Log.fromSSHRequest(pairing, request, signRequest, co.krypt.krypton.team.log.Log.Body.SSH.Result.userRejected());
EventBus.getDefault().post(new TeamService.EncryptLog(C.background(context), teamLog));
pairingStorage.appendToSSHLog(new SSHSignatureLog(signRequest.data, false, signRequest.command, signRequest.user(), signRequest.firstHostnameIfExists(), System.currentTimeMillis() / 1000, signRequest.verifyHostName(), JSON.toJson(signRequest.hostAuth), pairing.getUUIDString(), pairing.workstationName));
}
return null;
}
@Override
public Void visit(GitSignRequest gitSignRequest) throws Unrecoverable {
if (requestAllowed) {
try {
SSHKeyPairI key = MeStorage.getOrLoadKeyPair(context);
new MeStorage(context).loadWithUserID(UserID.parse(gitSignRequest.userID));
co.krypt.krypton.team.log.Log.Body.GitSignatureResult gitSignatureResult = new co.krypt.krypton.team.log.Log.Body.GitSignatureResult();
co.krypt.krypton.log.Log log = gitSignRequest.body.visit(new GitSignRequestBody.Visitor<co.krypt.krypton.log.Log, Exception>() {
@Override
public co.krypt.krypton.log.Log visit(CommitInfo commit) throws Unrecoverable {
byte[] signature = SignableUtils.signBinaryDocument(commit, key, HashAlgorithm.SHA512);
response.gitSignResponse = new GitSignResponse(signature, null);
gitSignatureResult.signature = signature;
GitCommitSignatureLog commitLog = new GitCommitSignatureLog(pairing, commit, new AsciiArmor(AsciiArmor.HeaderLine.SIGNATURE, AsciiArmor.backwardsCompatibleHeaders(request.semVer()), signature).toString());
pairings().appendToCommitLogs(commitLog);
return commitLog;
}
@Override
public co.krypt.krypton.log.Log visit(TagInfo tag) throws Unrecoverable {
byte[] signature = SignableUtils.signBinaryDocument(tag, key, HashAlgorithm.SHA512);
response.gitSignResponse = new GitSignResponse(signature, null);
gitSignatureResult.signature = signature;
GitTagSignatureLog tagLog = new GitTagSignatureLog(pairing, tag, new AsciiArmor(AsciiArmor.HeaderLine.SIGNATURE, AsciiArmor.backwardsCompatibleHeaders(request.semVer()), signature).toString());
pairings().appendToTagLogs(tagLog);
return tagLog;
}
});
co.krypt.krypton.team.log.Log teamLog = co.krypt.krypton.team.log.Log.fromGitRequest(pairing, request, gitSignRequest, gitSignatureResult);
EventBus.getDefault().post(new TeamService.EncryptLog(C.background(context), teamLog));
Notifications.notifySuccess(context, pairing, request, log);
} catch (Exception e) {
e.printStackTrace();
response.gitSignResponse = new GitSignResponse(null, "unknown error");
}
} else {
response.gitSignResponse = new GitSignResponse(null, "rejected");
gitSignRequest.body.visit(new GitSignRequestBody.Visitor<Void, RuntimeException>() {
@Override
public Void visit(CommitInfo commit) throws RuntimeException {
pairings().appendToCommitLogs(new GitCommitSignatureLog(pairing, commit, null));
return null;
}
@Override
public Void visit(TagInfo tag) throws RuntimeException {
pairings().appendToTagLogs(new GitTagSignatureLog(pairing, tag, null));
return null;
}
});
co.krypt.krypton.team.log.Log teamLog = co.krypt.krypton.team.log.Log.fromGitRequest(pairing, request, gitSignRequest, co.krypt.krypton.team.log.Log.Body.GitSignatureResult.userRejected());
EventBus.getDefault().post(new TeamService.EncryptLog(C.background(context), teamLog));
}
return null;
}
@Override
public Void visit(UnpairRequest unpairRequest) throws Unrecoverable {
// Processed in handle()
return null;
}
@Override
public Void visit(HostsRequest hostsRequest) throws Unrecoverable {
HostsResponse hostsResponse = new HostsResponse();
synchronized (databaseLock) {
try {
List<SSHSignatureLog> sshLogs = dbHelper.getSSHSignatureLogDao().queryBuilder().groupByRaw("user, host_name").query();
List<UserAndHost> userAndHosts = new LinkedList<>();
for (SSHSignatureLog log : sshLogs) {
UserAndHost userAndHost = new UserAndHost();
userAndHost.user = log.user;
userAndHost.host = log.hostName;
userAndHosts.add(userAndHost);
}
HostInfo hostInfo = new HostInfo();
UserAndHost[] userAndHostsArray = new UserAndHost[userAndHosts.size()];
userAndHosts.toArray(userAndHostsArray);
hostInfo.hosts = userAndHostsArray;
List<UserID> userIDs = meStorage.getUserIDs();
List<String> userIDStrings = new LinkedList<>();
for (UserID userID : userIDs) {
userIDStrings.add(userID.toString());
}
String[] userIDArray = new String[userIDs.size()];
userIDStrings.toArray(userIDArray);
hostInfo.pgpUserIDs = userIDArray;
hostsResponse.hostInfo = hostInfo;
} catch (SQLException e1) {
hostsResponse.error = "sql exception";
}
}
response.hostsResponse = hostsResponse;
return null;
}
@Override
public Void visit(ReadTeamRequest readTeamRequest) throws Unrecoverable {
SuccessOrTaggedErrorResult<JsonObject> result = new SuccessOrTaggedErrorResult<>();
response.readTeamResponse = result;
if (requestAllowed) {
try {
Sigchain.NativeResult<JsonObject> readToken = TeamDataProvider.signReadToken(context, readTeamRequest.publicKey);
if (readToken.success != null) {
result.success = readToken.success;
} else {
result.error = readToken.error;
}
} catch (Native.NotLinked e) {
e.printStackTrace();
result.error = e.getMessage();
}
} else {
response.readTeamResponse.error = "rejected";
}
return null;
}
@Override
public Void visit(LogDecryptionRequest logDecryptionRequest) throws Unrecoverable {
SuccessOrTaggedErrorResult<JsonObject> result = new SuccessOrTaggedErrorResult<>();
response.logDecryptionResponse = result;
if (requestAllowed) {
try {
Sigchain.NativeResult<JsonObject> unwrappedKey = TeamDataProvider.unwrapKey(context, logDecryptionRequest.wrappedKey);
if (unwrappedKey.success != null) {
result.success = unwrappedKey.success;
} else {
result.error = unwrappedKey.error;
}
} catch (Native.NotLinked e) {
e.printStackTrace();
result.error = e.getMessage();
}
} else {
response.logDecryptionResponse.error = "rejected";
}
return null;
}
@Override
public Void visit(TeamOperationRequest teamOperationRequest) throws Unrecoverable {
SuccessOrTaggedErrorResult<Sigchain.TeamOperationResponse> result = new SuccessOrTaggedErrorResult<>();
response.teamOperationResponse = result;
if (requestAllowed) {
try {
Sigchain.NativeResult<Sigchain.TeamOperationResponse> nativeResult = TeamDataProvider.requestTeamOperation(context, teamOperationRequest.operation);
if (nativeResult.success != null) {
response.teamOperationResponse.success = nativeResult.success;
} else {
response.teamOperationResponse.error = nativeResult.error;
}
} catch (Native.NotLinked e) {
e.printStackTrace();
result.error = e.getMessage();
}
} else {
response.teamOperationResponse.error = "rejected";
}
return null;
}
});
response.snsEndpointARN = SNSTransport.getInstance(context).getEndpointARN();
synchronized (Silo.class) {
try {
if (responseDiskCacheByRequestID != null && !responseDiskCacheByRequestID.isClosed()) {
DiskLruCache.Editor cacheEditor = responseDiskCacheByRequestID.edit(request.requestIDCacheKey(pairing));
cacheEditor.set(0, JSON.toJson(response));
cacheEditor.commit();
responseDiskCacheByRequestID.flush();
}
} catch (IOException e) {
e.printStackTrace();
throw new Unrecoverable(e);
}
responseMemCacheByRequestID.put(request.requestIDCacheKey(pairing), response);
}
send(pairing, response);
}
}
use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.
the class Policy method onAction.
public static void onAction(final Context context, final String requestID, final String action) {
Log.i(TAG, action + " requestID " + requestID);
final Pair<Pairing, Request> pairingAndRequest;
// Lock manually to prevent deadlock from Silo
synchronized (Policy.class) {
pairingAndRequest = pendingRequestCache.remove(requestID);
}
if (pairingAndRequest == null) {
Log.e(TAG, "requestID " + requestID + " not pending");
return;
}
Silo silo = Silo.shared(context);
OpenDatabaseHelper db = silo.pairings().dbHelper;
Notifications.clearRequest(context, pairingAndRequest.second);
switch(action) {
case APPROVE_ONCE:
try {
silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, true);
new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background approve", "once", null, false);
} catch (Exception e) {
e.printStackTrace();
}
break;
case APPROVE_ALL_TEMPORARILY:
try {
pairingAndRequest.second.body.visit(new RequestBody.Visitor<Void, Unrecoverable>() {
@Override
public Void visit(MeRequest meRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(SignRequest signRequest) throws Unrecoverable {
try {
Approval.approveSSHAnyHost(db, pairingAndRequest.first.uuid);
} catch (IOException | SQLException e) {
throw new Unrecoverable(e);
}
return null;
}
@Override
public Void visit(GitSignRequest gitSignRequest) throws Unrecoverable {
gitSignRequest.body.visit(new GitSignRequestBody.Visitor<Void, Unrecoverable>() {
@Override
public Void visit(CommitInfo commit) throws Unrecoverable {
try {
Approval.approveGitCommitSignatures(db, pairingAndRequest.first.uuid);
} catch (IOException | SQLException e) {
throw new Unrecoverable(e);
}
return null;
}
@Override
public Void visit(TagInfo tag) throws Unrecoverable {
try {
Approval.approveGitTagSignatures(db, pairingAndRequest.first.uuid);
} catch (IOException | SQLException e) {
throw new Unrecoverable(e);
}
return null;
}
});
return null;
}
@Override
public Void visit(UnpairRequest unpairRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(HostsRequest hostsRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(ReadTeamRequest readTeamRequest) throws Unrecoverable {
try {
Approval.approveReadTeamData(db, pairingAndRequest.first.uuid);
} catch (IOException | SQLException e) {
throw new Unrecoverable(e);
}
return null;
}
@Override
public Void visit(LogDecryptionRequest logDecryptionRequest) throws Unrecoverable {
try {
Approval.approveReadTeamData(db, pairingAndRequest.first.uuid);
} catch (IOException | SQLException e) {
throw new Unrecoverable(e);
}
return null;
}
@Override
public Void visit(TeamOperationRequest teamOperationRequest) throws Unrecoverable {
return null;
}
});
silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, true);
new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background approve", "time", (int) temporaryApprovalSeconds(context, pairingAndRequest.second), false);
} catch (Exception e) {
e.printStackTrace();
}
break;
case APPROVE_THIS_TEMPORARILY:
try {
pairingAndRequest.second.body.visit(new RequestBody.Visitor<Void, Unrecoverable>() {
@Override
public Void visit(MeRequest meRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(SignRequest signRequest) throws Unrecoverable {
String user = signRequest.user();
if (signRequest.hostNameVerified && signRequest.hostAuth.hostNames.length > 0) {
try {
Approval.approveSSHUserHost(db, pairingAndRequest.first.uuid, user, signRequest.hostAuth.hostNames[0]);
} catch (IOException | SQLException e) {
throw new Unrecoverable(e);
}
}
return null;
}
@Override
public Void visit(GitSignRequest gitSignRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(UnpairRequest unpairRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(HostsRequest hostsRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(ReadTeamRequest readTeamRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(LogDecryptionRequest logDecryptionRequest) throws Unrecoverable {
return null;
}
@Override
public Void visit(TeamOperationRequest teamOperationRequest) throws Unrecoverable {
return null;
}
});
silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, true);
new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background approve this", "time", (int) temporaryApprovalSeconds(context, pairingAndRequest.second), false);
} catch (Exception e) {
e.printStackTrace();
}
case REJECT:
try {
silo.respondToRequest(pairingAndRequest.first, pairingAndRequest.second, false);
new Analytics(context).postEvent(pairingAndRequest.second.analyticsCategory(), "background reject", null, null, false);
} catch (Unrecoverable e) {
e.printStackTrace();
}
break;
}
}
use of co.krypt.krypton.analytics.Analytics in project krypton-android by kryptco.
the class MeFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_me, container, false);
profileEmail = (EditText) v.findViewById(R.id.profileEmail);
profileEmail.setText("loading...");
profileEmail.setTextColor(getResources().getColor(R.color.appGray, null));
profileEmail.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int keyCode, KeyEvent event) {
v.clearFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
onEmailChanged(v.getText().toString());
return false;
}
});
profileEmail.setOnFocusChangeListener((v1, hasFocus) -> {
if (!hasFocus) {
EditText editText = (EditText) v1;
new Thread(() -> onEmailChanged(editText.getText().toString())).start();
}
});
githubButton = v.findViewById(R.id.githubButton);
digitaloceanButton = v.findViewById(R.id.digitaloceanButton);
awsButton = v.findViewById(R.id.awsButton);
addKeyCommandTextView = v.findViewById(R.id.addKeyTextView);
githubButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addKeyCommandTextView.setText("$ kr github");
githubButton.setTextColor(getResources().getColor(R.color.appGreen));
digitaloceanButton.setTextColor(getResources().getColor(R.color.appGray));
awsButton.setTextColor(getResources().getColor(R.color.appGray));
new Analytics(getContext()).postEvent("add key", "GitHub", null, null, false);
}
});
digitaloceanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addKeyCommandTextView.setText("$ kr digitalocean");
digitaloceanButton.setTextColor(getResources().getColor(R.color.appGreen));
githubButton.setTextColor(getResources().getColor(R.color.appGray));
awsButton.setTextColor(getResources().getColor(R.color.appGray));
new Analytics(getContext()).postEvent("add key", "DigitalOcean", null, null, false);
}
});
awsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addKeyCommandTextView.setText("$ kr aws");
awsButton.setTextColor(getResources().getColor(R.color.appGreen));
githubButton.setTextColor(getResources().getColor(R.color.appGray));
digitaloceanButton.setTextColor(getResources().getColor(R.color.appGray));
new Analytics(getContext()).postEvent("add key", "AWS", null, null, false);
}
});
shareButton = (ImageButton) v.findViewById(R.id.shareButton);
EventBus.getDefault().register(this);
EventBus.getDefault().post(new IdentityService.GetProfile(getContext()));
return v;
}
Aggregations