mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-23 14:36:44 +02:00
sync server: Don't hash client_id for salt (#3250)
We don't know why we're doing this step so we probably shouldn't. Cryptography isn't magic and extra steps are harmful in that they obscure the important parts.
This commit is contained in:
parent
fa21835001
commit
082b6084fa
10 changed files with 11 additions and 17 deletions
|
@ -6,7 +6,7 @@ The `origin` *should* be an HTTPS endpoint on general principle, but nothing in
|
||||||
The replica identifies itself to the server using a `client_id` in the form of a UUID.
|
The replica identifies itself to the server using a `client_id` in the form of a UUID.
|
||||||
This value is passed with every request in the `X-Client-Id` header, in its dashed-hex format.
|
This value is passed with every request in the `X-Client-Id` header, in its dashed-hex format.
|
||||||
|
|
||||||
The salt used in key derivation is the SHA256 hash of the 16-byte form of the client ID.
|
The salt used in key derivation is the 16-byte client ID.
|
||||||
|
|
||||||
## AddVersion
|
## AddVersion
|
||||||
|
|
||||||
|
|
|
@ -205,7 +205,6 @@ impl From<Sealed> for Vec<u8> {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use ring::digest;
|
|
||||||
|
|
||||||
fn make_salt() -> Vec<u8> {
|
fn make_salt() -> Vec<u8> {
|
||||||
Cryptor::gen_salt().unwrap()
|
Cryptor::gen_salt().unwrap()
|
||||||
|
@ -333,9 +332,7 @@ mod test {
|
||||||
let version_id = Uuid::parse_str("b0517957-f912-4d49-8330-f612e73030c4").unwrap();
|
let version_id = Uuid::parse_str("b0517957-f912-4d49-8330-f612e73030c4").unwrap();
|
||||||
let encryption_secret = b"b4a4e6b7b811eda1dc1a2693ded".to_vec();
|
let encryption_secret = b"b4a4e6b7b811eda1dc1a2693ded".to_vec();
|
||||||
let client_id = Uuid::parse_str("0666d464-418a-4a08-ad53-6f15c78270cd").unwrap();
|
let client_id = Uuid::parse_str("0666d464-418a-4a08-ad53-6f15c78270cd").unwrap();
|
||||||
let salt = dbg!(digest::digest(&digest::SHA256, client_id.as_ref()))
|
let salt = client_id.as_ref().to_vec();
|
||||||
.as_ref()
|
|
||||||
.to_vec();
|
|
||||||
(version_id, salt, encryption_secret)
|
(version_id, salt, encryption_secret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ def gen(
|
||||||
version_id=version_id, client_id=client_id, encryption_secret=encryption_secret,
|
version_id=version_id, client_id=client_id, encryption_secret=encryption_secret,
|
||||||
app_id=1, version=1):
|
app_id=1, version=1):
|
||||||
# first, generate the encryption key
|
# first, generate the encryption key
|
||||||
salt = hashlib.sha256(uuid.UUID(client_id).bytes).digest()
|
salt = uuid.UUID(client_id).bytes
|
||||||
key = pbkdf2.PBKDF2(
|
key = pbkdf2.PBKDF2(
|
||||||
encryption_secret,
|
encryption_secret,
|
||||||
salt,
|
salt,
|
||||||
|
|
|
@ -3,7 +3,6 @@ use crate::server::{
|
||||||
AddVersionResult, GetVersionResult, HistorySegment, Server, Snapshot, SnapshotUrgency,
|
AddVersionResult, GetVersionResult, HistorySegment, Server, Snapshot, SnapshotUrgency,
|
||||||
VersionId,
|
VersionId,
|
||||||
};
|
};
|
||||||
use ring::digest;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -29,11 +28,10 @@ impl SyncServer {
|
||||||
/// identify this client to the server. Multiple replicas synchronizing the same task history
|
/// identify this client to the server. Multiple replicas synchronizing the same task history
|
||||||
/// should use the same client_id.
|
/// should use the same client_id.
|
||||||
pub fn new(origin: String, client_id: Uuid, encryption_secret: Vec<u8>) -> Result<SyncServer> {
|
pub fn new(origin: String, client_id: Uuid, encryption_secret: Vec<u8>) -> Result<SyncServer> {
|
||||||
let salt = dbg!(digest::digest(&digest::SHA256, client_id.as_ref()));
|
|
||||||
Ok(SyncServer {
|
Ok(SyncServer {
|
||||||
origin,
|
origin,
|
||||||
client_id,
|
client_id,
|
||||||
cryptor: Cryptor::new(salt, &Secret(encryption_secret.to_vec()))?,
|
cryptor: Cryptor::new(client_id, &Secret(encryption_secret.to_vec()))?,
|
||||||
agent: ureq::AgentBuilder::new()
|
agent: ureq::AgentBuilder::new()
|
||||||
.timeout_connect(Duration::from_secs(10))
|
.timeout_connect(Duration::from_secs(10))
|
||||||
.timeout_read(Duration::from_secs(60))
|
.timeout_read(Duration::from_secs(60))
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
k_Я╔uз▄x9ФmЙшg╦└┬%j╜[с5щ+╧k≤В╓╪/│
|
IµNκuΘ
|
||||||
|
;“Ζ<E2809C>^¤Ό<C2A4>Ά9Iκ±<CEBA>Δ‰·οη©<CEB7>iοbΐ›
|
|
@ -1 +1 @@
|
||||||
[<5B>+Æ¢BÞÞYök‹Ch58-éJóCî¢<Ø<>š¬ô)Å›
|
ذ<EFBFBD>h<>Xةم.<2E>ٌEI<45>/ا
جاB<D8A7>ً<EFBFBD>ش
<1D>حو
|
|
@ -1 +1 @@
|
||||||
ιΏYΖΐ#π_D<15><>υ>Ο½ά<C2BD>jή<6A>Ο3FσΖ#–<>BΔQ
|
YÎ|<7C>zJuâŃľKąçzFń]Ŕáň¨bCxÎŢ<19>
|
|
@ -1,2 +1 @@
|
||||||
テP*トレヲ\嵓搖`SナUワ<55>キ~<7E>Wcサ`ン戛ニン
|
Ss΄“ίL΄‚|π:=<3D>“Λ";ό—Ρ<>²¥5οJK™=ν
|
||||||
オ
|
|
|
@ -1,2 +1 @@
|
||||||
cl<EFBFBD>;<3B>L+ѩ<><D1A9>'p<>f?
|
czاyةنّ3ىâ2في•ˆج6رLzôعAà};„Bإ6@
|
||||||
jn<0E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>v<EFBFBD><1D>O\<5C><>
|
|
|
@ -1 +1 @@
|
||||||
Êx-÷ãàLh¿Aí4?A¸°T3çQ¦Ñe‰R«VW•±
|
t<>`&<12>ار_)س<>ه<EFBFBD><D987>ا<18><>g<>r}<7D>-<2D>Z<EFBFBD><5A>s
|
Loading…
Add table
Add a link
Reference in a new issue