Conversation
The struct `KeyId` was extracted to wrap the primitive type but it was not being used in the `auth::Key` struct.
7867f4e to
7cdd63e
Compare
|
Hi @da2ce7 @WarmBeer, I want to decouple authentication (the Key is valid) from authorization (the peer can get the whitelisted torrent) in the new HTTP Axum implementation. The pub async fn authenticate_request(&self, info_hash: &InfoHash, key: &Option<KeyId>) -> Result<(), Error> {
// no authentication needed in public mode
if self.is_public() {
return Ok(());
}
// check if auth_key is set and valid
if self.is_private() {
match key {
Some(key) => {
if let Err(e) = self.verify_auth_key(key).await {
return Err(Error::PeerKeyNotValid {
key_id: key.clone(),
source: (Arc::new(e) as Arc<dyn std::error::Error + Send + Sync>).into(),
});
}
}
None => {
return Err(Error::PeerNotAuthenticated {
location: Location::caller(),
});
}
}
}
// check if info_hash is whitelisted
if self.is_whitelisted() && !self.is_info_hash_whitelisted(info_hash).await {
return Err(Error::TorrentNotWhitelisted {
info_hash: *info_hash,
location: Location::caller(),
});
}
Ok(())
}That's fine, but I want to use directly the pub async fn verify_auth_key(&self, key_id: &KeyId) -> Result<(), auth::Error> {
match self.keys.read().await.get(key_id) {
None => Err(auth::Error::UnableToReadKey {
location: Location::caller(),
key_id: Box::new(key_id.clone()),
}),
Some(key) => auth::verify(key),
}
}This was a pending refactor to use the The refactor is ready to review. |
The struct
KeyIdwas extracted to wrap the primitive type, but it was not being used in theauth::Keystruct yet.Keybefore this PR:After this PR:
auth::KeyIdin theauth::Keystruct.auth::Keytoauth::ExpiringKey.