Beispiel #1
0
Status
loginServerUpdatePinPackage(const Login &login,
                            DataSlice DID, DataSlice LPIN1, const std::string &pinPackage,
                            time_t ali)
{
    const auto url = ABC_SERVER_ROOT "/account/pinpackage/update";

    // format the ali
    char szALI[DATETIME_LENGTH];
    strftime(szALI, DATETIME_LENGTH, "%Y-%m-%dT%H:%M:%S", gmtime(&ali));

    // Encode those:
    JsonPtr json(json_pack("{ss, ss, ss, ss, ss, ss}",
                           ABC_SERVER_JSON_L1_FIELD, base64Encode(login.lobby.authId()).c_str(),
                           ABC_SERVER_JSON_LP1_FIELD, base64Encode(login.authKey()).c_str(),
                           ABC_SERVER_JSON_DID_FIELD, base64Encode(DID).c_str(),
                           ABC_SERVER_JSON_LPIN1_FIELD, base64Encode(LPIN1).c_str(),
                           JSON_ACCT_PIN_PACKAGE, pinPackage.c_str(),
                           ABC_SERVER_JSON_ALI_FIELD, szALI));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply.body));
    ABC_CHECK(replyJson.ok());

    return Status();
}
Beispiel #2
0
Status
ServerRequestJson::setup(const Login &login)
{
    ABC_CHECK(setup(login.store));
    ABC_CHECK(passwordAuthSet(base64Encode(login.passwordAuth())));
    return Status();
}
Beispiel #3
0
Status
ServerRequestJson::setup(const Login &login)
{
    ABC_CHECK(setup(login.lobby));
    ABC_CHECK(authKeySet(base64Encode(login.authKey())));
    return Status();
}
Beispiel #4
0
Status
JsonBox::decrypt(DataChunk &result, DataSlice key)
{
    DataChunk nonce;
    ABC_CHECK(nonceOk());
    ABC_CHECK(base16Decode(nonce, this->nonce()));

    DataChunk cyphertext;
    ABC_CHECK(cyphertextOk());
    ABC_CHECK(base64Decode(cyphertext, this->cyphertext()));

    switch (type())
    {
    case AES256_CBC_AIRBITZ:
    {
        ABC_CHECK_OLD(ABC_CryptoDecryptAES256Package(result,
                      cyphertext, key, nonce,
                      &error));
        return Status();
    }

    default:
        return ABC_ERROR(ABC_CC_DecryptError, "Unknown encryption type");
    }
}
Beispiel #5
0
Status
loginServerGetPinPackage(DataSlice DID, DataSlice LPIN1, std::string &result,
                         AuthError &authError)
{
    const auto url = ABC_SERVER_ROOT "/v1/account/pinpackage/get";
    ServerRequestJson json;
    ABC_CHECK(json.set(ABC_SERVER_JSON_DID_FIELD, base64Encode(DID)));
    ABC_CHECK(json.set(ABC_SERVER_JSON_LPIN1_FIELD, base64Encode(LPIN1)));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply, &authError));

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_STRING(package, "pin_package", nullptr)
    } resultJson(replyJson.results());

    ABC_CHECK(resultJson.packageOk());
    result = resultJson.package();
    return Status();
}
Beispiel #6
0
Status
loginServerChangePassword(const Login &login,
                          DataSlice newLP1, DataSlice newLRA1,
                          const CarePackage &carePackage, const LoginPackage &loginPackage)
{
    const auto url = ABC_SERVER_ROOT "/account/password/update";
    JsonPtr json(json_pack("{ss, ss, ss, ss, ss}",
                           ABC_SERVER_JSON_L1_FIELD,      base64Encode(login.lobby.authId()).c_str(),
                           ABC_SERVER_JSON_LP1_FIELD,     base64Encode(login.authKey()).c_str(),
                           ABC_SERVER_JSON_NEW_LP1_FIELD, base64Encode(newLP1).c_str(),
                           ABC_SERVER_JSON_CARE_PACKAGE_FIELD,  carePackage.encode().c_str(),
                           ABC_SERVER_JSON_LOGIN_PACKAGE_FIELD, loginPackage.encode().c_str()));
    if (newLRA1.size())
    {
        json_object_set_new(json.get(), ABC_SERVER_JSON_NEW_LRA1_FIELD,
                            json_string(base64Encode(newLRA1).c_str()));
    }

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply.body));
    ABC_CHECK(replyJson.ok());

    return Status();
}
Beispiel #7
0
Status
loginServerOtpStatus(const Login &login, bool &on, long &timeout)
{
    const auto url = ABC_SERVER_ROOT "/v1/otp/status";
    ServerRequestJson json;
    ABC_CHECK(json.setup(login));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    struct ResultJson:
        public JsonObject
    {
        ABC_JSON_CONSTRUCTORS(ResultJson, JsonObject)
        ABC_JSON_BOOLEAN(on, "on", false)
        ABC_JSON_INTEGER(timeout, "otp_timeout", 0)
    } resultJson(replyJson.results());

    on = resultJson.on();
    if (on)
    {
        ABC_CHECK(resultJson.timeoutOk());
        timeout = resultJson.timeout();
    }
    return Status();
}
Beispiel #8
0
Status
ServerRequestJson::setup(const LoginStore &store)
{
    ABC_CHECK(userIdSet(base64Encode(store.userId())));
    if (store.otpKey())
        ABC_CHECK(otpSet(store.otpKey()->totp()));
    return Status();
}
Status
accountCategoriesRemove(const Account &account, const std::string &category)
{
    AccountCategories categories;
    ABC_CHECK(accountCategoriesLoad(categories, account));
    categories.erase(category);
    ABC_CHECK(accountCategoriesSave(account, categories));
    return Status();
}
Status
Account::load()
{
    // If the sync dir doesn't exist, create it:
    ABC_CHECK(syncEnsureRepo(dir(), login.lobby.dir() + "tmp/", login.syncKey()));

    ABC_CHECK(wallets.load());
    return Status();
}
Status
Account::sync(bool &dirty)
{
    ABC_CHECK(syncRepo(dir(), login.syncKey(), dirty));
    if (dirty)
        ABC_CHECK(load());

    return Status();
}
Beispiel #12
0
Status
Login::loadOffline()
{
    ABC_CHECK(store.paths(paths, true));

    LoginPackage loginPackage;
    ABC_CHECK(loginPackage.load(paths.loginPackagePath()));
    ABC_CHECK(loginPackage.passwordAuthBox().decrypt(passwordAuth_, dataKey_));

    // Look for an existing rootKeyBox:
    JsonBox rootKeyBox;
    if (fileExists(paths.rootKeyPath()))
    {
        ABC_CHECK(rootKeyBox.load(paths.rootKeyPath()));
    }
    else
    {
        // Try asking the server:
        AuthJson authJson;
        LoginReplyJson loginJson;
        ABC_CHECK(authJson.loginSet(*this));
        ABC_CHECK(loginServerLogin(loginJson, authJson));
        ABC_CHECK(loginJson.save(*this));
        rootKeyBox = loginJson.rootKeyBox();
    }
    // Otherwise, there just isn't one.

    // Extract the rootKey:
    if (rootKeyBox.ok())
        ABC_CHECK(rootKeyBox.decrypt(rootKey_, dataKey_));
    else
        ABC_CHECK(rootKeyUpgrade());

    return Status();
}
Beispiel #13
0
Status
loginServerPasswordSet(AuthJson authJson,
                       DataSlice passwordAuth,
                       JsonPtr passwordKeySnrp,
                       JsonPtr passwordBox,
                       JsonPtr passwordAuthBox)
{
    const auto url = ABC_SERVER_ROOT "/v2/login/password";

    JsonSnrp passwordAuthSnrp;
    ABC_CHECK(passwordAuthSnrp.snrpSet(usernameSnrp()));

    JsonObject dataJson;
    ABC_CHECK(dataJson.set("passwordAuth", base64Encode(passwordAuth)));
    ABC_CHECK(dataJson.set("passwordAuthSnrp", passwordAuthSnrp));
    ABC_CHECK(dataJson.set("passwordKeySnrp", passwordKeySnrp));
    ABC_CHECK(dataJson.set("passwordBox", passwordBox));
    ABC_CHECK(dataJson.set("passwordAuthBox", passwordAuthBox));
    ABC_CHECK(authJson.set("data", dataJson));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "PUT", authJson.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    return Status();
}
Status
watcherSave(Wallet &self)
{
    Watcher *watcher = nullptr;
    ABC_CHECK(watcherFind(watcher, self));

    auto data = watcher->serialize();;
    ABC_CHECK(fileSave(data, watcherPath(self)));

    return Status();
}
Beispiel #15
0
Status
Login::update()
{
    AuthJson authJson;
    LoginReplyJson loginJson;
    ABC_CHECK(authJson.loginSet(*this));
    ABC_CHECK(loginServerLogin(loginJson, authJson));
    ABC_CHECK(loginJson.save(*this));

    return Status();
}
Beispiel #16
0
Status
Wallet::createNew(std::shared_ptr<Wallet> &result, Account &account,
                  const std::string &name, int currency)
{
    std::string id;
    ABC_CHECK(randomUuid(id));
    std::shared_ptr<Wallet> out(new Wallet(account, id));
    ABC_CHECK(out->createNew(name, currency));

    result = std::move(out);
    return Status();
}
Beispiel #17
0
Status
Wallet::sync(bool &dirty)
{
    ABC_CHECK(syncRepo(syncDir(), syncKey_, dirty));
    if (dirty)
    {
        std::lock_guard<std::mutex> lock(mutex_);
        ABC_CHECK(loadSync());
    }

    return Status();
}
Beispiel #18
0
Status
Wallet::nameSet(const std::string &name)
{
    std::lock_guard<std::mutex> lock(mutex_);

    name_ = name;
    NameJson json;
    ABC_CHECK(json.nameSet(name));
    ABC_CHECK(json.save(syncDir() + WALLET_NAME_FILENAME, dataKey()));

    return Status();
}
Beispiel #19
0
Status
Wallet::currencySet(int currency)
{
    std::lock_guard<std::mutex> lock(mutex_);

    currency_ = currency;
    CurrencyJson currencyJson;
    ABC_CHECK(currencyJson.currencySet(currency));
    ABC_CHECK(currencyJson.save(syncDir() + WALLET_CURRENCY_FILENAME, dataKey()));

    return Status();
}
Beispiel #20
0
Status
loginServerRecovery2Delete(AuthJson authJson)
{
    const auto url = ABC_SERVER_ROOT "/v2/login/recovery2";

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "DELETE", authJson.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    return Status();
}
Beispiel #21
0
Status
Login::createNew(std::shared_ptr<Login> &result,
                 LoginStore &store, const char *password)
{
    DataChunk dataKey;
    ABC_CHECK(randomData(dataKey, DATA_KEY_LENGTH));
    std::shared_ptr<Login> out(new Login(store, dataKey));
    ABC_CHECK(out->createNew(password));

    result = std::move(out);
    return Status();
}
Beispiel #22
0
Status
loginServerOtpPending(std::list<DataChunk> users, std::list<bool> &isPending)
{
    const auto url = ABC_SERVER_ROOT "/v1/otp/pending/check";

    std::string param;
    std::map<std::string, bool> userMap;
    std::list<std::string> usersEncoded;
    for (const auto &u : users)
    {
        std::string username = base64Encode(u);
        param += (username + ",");
        userMap[username] = false;
        usersEncoded.push_back(username);
    }
    JsonObject json;
    ABC_CHECK(json.set("l1s", param));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    JsonArray arrayJson = replyJson.results();
    size_t size = arrayJson.size();
    for (size_t i = 0; i < size; i++)
    {
        json_t *pJSON_Row = arrayJson[i].get();
        if (!pJSON_Row || !json_is_object(pJSON_Row))
            return ABC_ERROR(ABC_CC_JSONError, "Error parsing JSON array element object");

        json_t *pJSON_Value = json_object_get(pJSON_Row, "login");
        if (!pJSON_Value || !json_is_string(pJSON_Value))
            return ABC_ERROR(ABC_CC_JSONError, "Error otp/pending/login JSON");
        std::string username(json_string_value(pJSON_Value));

        pJSON_Value = json_object_get(pJSON_Row, ABC_SERVER_JSON_OTP_PENDING);
        if (!pJSON_Value || !json_is_boolean(pJSON_Value))
            return ABC_ERROR(ABC_CC_JSONError, "Error otp/pending/pending JSON");
        if (json_is_true(pJSON_Value))
        {
            userMap[username] = json_is_true(pJSON_Value);
        }
    }
    isPending.clear();
    for (auto &username: usersEncoded)
    {
        isPending.push_back(userMap[username]);
    }

    return Status();
}
static Status
watcherLoad(Wallet &self)
{
    Watcher *watcher = nullptr;
    ABC_CHECK(watcherFind(watcher, self));

    DataChunk data;
    ABC_CHECK(fileLoad(data, watcherPath(self)));
    if (!watcher->load(data))
        return ABC_ERROR(ABC_CC_Error, "Unable to load serialized watcher");

    return Status();
}
Beispiel #24
0
Status
loginServerGetQuestions(JsonPtr &result)
{
    const auto url = ABC_SERVER_ROOT "/v1/questions";

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    result = replyJson.results();
    return Status();
}
Beispiel #25
0
Status
loginServerLobbyGet(JsonPtr &result, const std::string &id)
{
    const auto url = ABC_SERVER_ROOT "/v2/lobby/" + id;

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().get(reply, url));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    result = replyJson.results();
    return Status();
}
Beispiel #26
0
Status
JsonBox::encrypt(DataSlice data, DataSlice key)
{
    DataChunk nonce;
    AutoU08Buf cyphertext;
    ABC_CHECK_OLD(ABC_CryptoEncryptAES256Package(data, key,
                  &cyphertext, nonce, &error));

    ABC_CHECK(typeSet(AES256_CBC_AIRBITZ));
    ABC_CHECK(nonceSet(base16Encode(nonce)));
    ABC_CHECK(cyphertextSet(base64Encode(cyphertext)));

    return Status();
}
Beispiel #27
0
Status
loginServerAvailable(const LoginStore &store)
{
    const auto url = ABC_SERVER_ROOT "/v1/account/available";
    ServerRequestJson json;
    ABC_CHECK(json.setup(store));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    return Status();
}
Beispiel #28
0
Status
loginServerCreateChildLogin(AuthJson authJson, JsonPtr loginJson)
{
    const auto url = ABC_SERVER_ROOT "/v2/login/create";

    ABC_CHECK(authJson.set("data", loginJson));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "PUT", authJson.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    return Status();
}
Beispiel #29
0
Status
loginServerOtpResetCancelPending(const Login &login)
{
    const auto url = ABC_SERVER_ROOT "/v1/otp/pending/cancel";
    ServerRequestJson json;
    ABC_CHECK(json.setup(login));

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().post(reply, url, json.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply));

    return Status();
}
Beispiel #30
0
Status
loginServerLogin(LoginReplyJson &result, AuthJson authJson,
                 AuthError *authError)
{
    const auto url = ABC_SERVER_ROOT "/v2/login";

    HttpReply reply;
    ABC_CHECK(AirbitzRequest().request(reply, url, "GET", authJson.encode()));
    ServerReplyJson replyJson;
    ABC_CHECK(replyJson.decode(reply, authError));

    result = replyJson.results();
    return Status();
}