Skip to content

Commit

Permalink
Merge branch 'master' into fix-segmentationfaults-and-notsynchronized…
Browse files Browse the repository at this point in the history
…items
  • Loading branch information
rui-rafael-lastpass committed May 13, 2024
2 parents 354f9b9 + 977d16e commit b6076e3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
4 changes: 4 additions & 0 deletions endpoints-share.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ int lastpass_share_move(const struct session *session,
NULL);
}

if (session->feature_flag.url_logging_enabled) {
http_post_add_params(&params, "recordUrl", url, NULL);
}

reply = http_post_lastpass_param_set("lastpass/api.php",
session, NULL,
&params);
Expand Down
27 changes: 25 additions & 2 deletions endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ void lastpass_remove_account(enum blobsync sync, unsigned const char key[KDF_HAS
if (account->share)
http_post_add_params(&params, "sharedfolderid", account->share->id, NULL);

_cleanup_free_ char *url = NULL;
if (session->feature_flag.url_logging_enabled) {
bytes_to_hex((unsigned char *) account->url, &url, strlen(account->url));
http_post_add_params(&params, "recordUrl", url, NULL);
}

++blob->version;
upload_queue_enqueue(sync, key, session, "show_website.php", &params);
}
Expand Down Expand Up @@ -233,6 +239,11 @@ void lastpass_update_account(enum blobsync sync, unsigned const char key[KDF_HAS
"data", fields,
NULL);
}

if (session->feature_flag.url_logging_enabled) {
http_post_add_params(&params, "recordUrl", url, NULL);
}

upload_queue_enqueue(sync, key, session, "show_website.php", &params);

out_free_params:
Expand Down Expand Up @@ -268,6 +279,12 @@ void lastpass_log_access(enum blobsync sync, const struct session *session, unsi
if (account->share)
http_post_add_params(&params, "sharedfolderid", account->share->id, NULL);

_cleanup_free_ char *url = NULL;
if (session->feature_flag.url_logging_enabled) {
bytes_to_hex((unsigned char *) account->url, &url, strlen(account->url));
http_post_add_params(&params, "recordUrl", url, NULL);
}

upload_queue_enqueue(sync, key, session, "loglogin.php", &params);

free(params.argv);
Expand Down Expand Up @@ -411,7 +428,7 @@ int lastpass_upload(const struct session *session,
list_for_each_entry(account, accounts, list) {
char *name_param, *grouping_param;
char *url_param, *username_param, *password_param;
char *fav_param, *extra_param;
char *fav_param, *extra_param, *record_url_param;
char *url = NULL;
bytes_to_hex((unsigned char *) account->url, &url,
strlen(account->url));
Expand All @@ -423,6 +440,7 @@ int lastpass_upload(const struct session *session,
xasprintf(&password_param, "password%d", index);
xasprintf(&fav_param, "fav%d", index);
xasprintf(&extra_param, "extra%d", index);
xasprintf(&record_url_param, "recordUrl%d", index);

if (session->feature_flag.url_encryption_enabled) {
http_post_add_params(&params,
Expand All @@ -446,6 +464,10 @@ int lastpass_upload(const struct session *session,
NULL);
}

if (session->feature_flag.url_logging_enabled) {
http_post_add_params(&params, record_url_param, url, NULL);
}

index++;
}

Expand All @@ -459,7 +481,8 @@ int lastpass_upload(const struct session *session,
starts_with(params.argv[i], "username") ||
starts_with(params.argv[i], "password") ||
starts_with(params.argv[i], "fav") ||
starts_with(params.argv[i], "extra")) {
starts_with(params.argv[i], "extra") ||
starts_with(params.argv[i], "recordUrl")) {
free(params.argv[i]);
}
else if (starts_with(params.argv[i], "url")) {
Expand Down
23 changes: 20 additions & 3 deletions feature-flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,37 @@
#include "config.h"
#include <string.h>

#define SESSION_FF_URL_ENCRYPTION "session_ff_url_encryption"
#define SESSION_FF_URL_LOGGING "session_ff_url_logging"

void feature_flag_load_xml_attr(struct feature_flag *feature_flag, xmlDoc *doc, xmlAttrPtr attr) {
if (!xmlStrcmp(attr->name, BAD_CAST "url_encryption")) {
feature_flag->url_encryption_enabled = !strcmp((char *)xmlNodeListGetString(doc, attr->children, 1), "1");
}

if (!xmlStrcmp(attr->name, BAD_CAST "url_logging")) {
feature_flag->url_logging_enabled = !strcmp((char *)xmlNodeListGetString(doc, attr->children, 1), "1");
}
}

void feature_flag_save(const struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]) {
config_write_encrypted_string("session_ff_url_encryption", feature_flag->url_encryption_enabled ? "1" : "0", key);
config_write_encrypted_string(SESSION_FF_URL_ENCRYPTION, feature_flag->url_encryption_enabled ? "1" : "0", key);
config_write_encrypted_string(SESSION_FF_URL_LOGGING, feature_flag->url_logging_enabled ? "1" : "0", key);
}

void feature_flag_load(struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]) {
char * ff_url_encryption = config_read_encrypted_string("session_ff_url_encryption", key);

char *ff_url_encryption = config_read_encrypted_string(SESSION_FF_URL_ENCRYPTION, key);
if (ff_url_encryption != NULL) {
feature_flag->url_encryption_enabled = !strcmp(ff_url_encryption, "1");
}

char *ff_url_logging = config_read_encrypted_string(SESSION_FF_URL_LOGGING, key);
if (ff_url_logging != NULL) {
feature_flag->url_logging_enabled = !strcmp(ff_url_logging, "1");
}
}

void feature_flag_cleanup() {
config_unlink(SESSION_FF_URL_ENCRYPTION);
config_unlink(SESSION_FF_URL_LOGGING);
}
2 changes: 2 additions & 0 deletions feature-flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

struct feature_flag {
bool url_encryption_enabled;
bool url_logging_enabled;
};

void feature_flag_load_xml_attr(struct feature_flag *feature_flag, xmlDoc *doc, xmlAttrPtr attr);
void feature_flag_save(const struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]);
void feature_flag_load(struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]);
void feature_flag_cleanup();

#endif
3 changes: 3 additions & 0 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ void session_kill()
config_unlink("session_privatekey");
config_unlink("session_server");
config_unlink("plaintext_key");

feature_flag_cleanup();

agent_kill();
upload_queue_kill();
}
2 changes: 2 additions & 0 deletions xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ unsigned long long xml_login_check(const char *buf, struct session *session)
versionstr = (char *)xmlNodeListGetString(doc, attr->children, 1);
version = strtoull(versionstr, NULL, 10);
}

feature_flag_load_xml_attr(&session->feature_flag, doc, attr);
}
}
out:
Expand Down

0 comments on commit b6076e3

Please sign in to comment.