2015-06-22 18:50:56 +02:00
|
|
|
/* Copyright 2015 OpenMarket Ltd
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2015-06-27 01:15:23 +02:00
|
|
|
#ifndef OLM_ACCOUNT_HH_
|
|
|
|
#define OLM_ACCOUNT_HH_
|
2015-06-11 19:03:22 +02:00
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
#include "olm/list.hh"
|
|
|
|
#include "olm/crypto.hh"
|
|
|
|
#include "olm/error.hh"
|
2015-06-11 19:03:22 +02:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
namespace olm {
|
2015-06-11 19:03:22 +02:00
|
|
|
|
|
|
|
|
2015-07-07 17:42:03 +02:00
|
|
|
struct IdentityKeys {
|
|
|
|
Ed25519KeyPair ed25519_key;
|
|
|
|
Curve25519KeyPair curve25519_key;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct OneTimeKey {
|
2015-06-11 19:03:22 +02:00
|
|
|
std::uint32_t id;
|
|
|
|
Curve25519KeyPair key;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static std::size_t const MAX_ONE_TIME_KEYS = 100;
|
|
|
|
|
2015-07-07 10:01:38 +02:00
|
|
|
|
2015-06-11 19:03:22 +02:00
|
|
|
struct Account {
|
2015-07-07 17:42:03 +02:00
|
|
|
IdentityKeys identity_keys;
|
|
|
|
List<OneTimeKey, MAX_ONE_TIME_KEYS> one_time_keys;
|
2015-06-12 15:09:41 +02:00
|
|
|
ErrorCode last_error;
|
2015-06-11 19:03:22 +02:00
|
|
|
|
|
|
|
/** Number of random bytes needed to create a new account */
|
|
|
|
std::size_t new_account_random_length();
|
|
|
|
|
|
|
|
/** Create a new account. Returns NOT_ENOUGH_RANDOM if the number of random
|
|
|
|
* bytes is too small. */
|
2015-06-12 15:09:41 +02:00
|
|
|
std::size_t new_account(
|
2015-06-11 19:03:22 +02:00
|
|
|
uint8_t const * random, std::size_t random_length
|
|
|
|
);
|
|
|
|
|
2015-07-07 17:42:03 +02:00
|
|
|
/** Number of bytes needed to output the identity keys for this account */
|
|
|
|
std::size_t get_identity_json_length(
|
|
|
|
std::size_t user_id_length,
|
|
|
|
std::size_t device_id_length,
|
|
|
|
std::uint64_t valid_after_ts,
|
|
|
|
std::uint64_t valid_until_ts
|
|
|
|
);
|
|
|
|
|
|
|
|
/** Output the identity keys for this account as JSON in the following
|
|
|
|
* format.
|
|
|
|
*
|
|
|
|
* 14 "{\"algorithms\":"
|
|
|
|
* 30 "[\"m.olm.curve25519-aes-sha256\""
|
|
|
|
* 15 "],\"device_id\":\""
|
|
|
|
* ? <device identifier>
|
|
|
|
* 22 "\",\"keys\":{\"curve25519:"
|
|
|
|
* 4 <base64 characters>
|
|
|
|
* 3 "\":\""
|
|
|
|
* 43 <base64 characters>
|
|
|
|
* 11 "\",\"ed25519:"
|
|
|
|
* 4 <base64 characters>
|
|
|
|
* 3 "\":\""
|
|
|
|
* 43 <base64 characters>
|
|
|
|
* 14 "\"},\"user_id\":\""
|
|
|
|
* ? <user identifier>
|
|
|
|
* 19 "\",\"valid_after_ts\":"
|
|
|
|
* ? <digits>
|
|
|
|
* 18 ",\"valid_until_ts\":"
|
|
|
|
* ? <digits>
|
|
|
|
* 16 ",\"signatures\":{\""
|
|
|
|
* ? <user identifier>
|
|
|
|
* 1 "/"
|
|
|
|
* ? <device identifier>
|
|
|
|
* 12 "\":{\"ed25519:"
|
|
|
|
* 4 <base64 characters>
|
|
|
|
* 3 "\":\""
|
|
|
|
* 86 <base64 characters>
|
|
|
|
* 4 "\"}}}"
|
|
|
|
*/
|
|
|
|
std::size_t get_identity_json(
|
|
|
|
std::uint8_t const * user_id, std::size_t user_id_length,
|
|
|
|
std::uint8_t const * device_id, std::size_t device_id_length,
|
|
|
|
std::uint64_t valid_after_ts,
|
|
|
|
std::uint64_t valid_until_ts,
|
2015-07-08 12:16:00 +02:00
|
|
|
std::uint8_t * identity_json, std::size_t identity_json_length
|
2015-07-07 17:42:03 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
OneTimeKey const * lookup_key(
|
2015-07-08 15:53:25 +02:00
|
|
|
Curve25519PublicKey const & public_key
|
2015-06-12 15:09:41 +02:00
|
|
|
);
|
2015-06-22 12:02:42 +02:00
|
|
|
|
|
|
|
std::size_t remove_key(
|
|
|
|
std::uint32_t id
|
|
|
|
);
|
2015-06-12 17:15:37 +02:00
|
|
|
};
|
2015-06-12 15:09:41 +02:00
|
|
|
|
2015-06-11 19:03:22 +02:00
|
|
|
|
2015-06-12 17:15:37 +02:00
|
|
|
std::size_t pickle_length(
|
|
|
|
Account const & value
|
|
|
|
);
|
2015-06-11 19:03:22 +02:00
|
|
|
|
2015-06-12 17:15:37 +02:00
|
|
|
|
|
|
|
std::uint8_t * pickle(
|
|
|
|
std::uint8_t * pos,
|
|
|
|
Account const & value
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
std::uint8_t const * unpickle(
|
|
|
|
std::uint8_t const * pos, std::uint8_t const * end,
|
|
|
|
Account & value
|
|
|
|
);
|
2015-06-11 19:03:22 +02:00
|
|
|
|
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
} // namespace olm
|
2015-06-11 19:03:22 +02:00
|
|
|
|
2015-06-27 01:15:23 +02:00
|
|
|
#endif /* OLM_ACCOUNT_HH_ */
|