Log signer ID when processing incoming activity

This commit is contained in:
silverpill 2021-12-01 15:05:17 +00:00
parent 0ec69adbe2
commit a0c0f1d092
2 changed files with 8 additions and 4 deletions

View file

@ -99,8 +99,9 @@ async fn inbox(
} else {
log::info!("received in {}: {}", request.uri().path(), activity);
};
if let Err(err) = signature_verified {
log::warn!("invalid signature: {}", err);
match signature_verified {
Ok(signer_id) => log::info!("activity signed by {}", signer_id),
Err(err) => log::warn!("invalid signature: {}", err),
};
receive_activity(&config, &db_pool, activity.into_inner()).await?;
Ok(HttpResponse::Ok().finish())

View file

@ -108,11 +108,12 @@ fn parse_http_signature(
Ok(signature_data)
}
/// Verifies HTTP signature and returns signer ID
pub async fn verify_http_signature(
config: &Config,
db_pool: &Pool,
request: &HttpRequest,
) -> Result<(), VerificationError> {
) -> Result<String, VerificationError> {
let signature_data = parse_http_signature(
request.method(),
request.uri(),
@ -151,7 +152,9 @@ pub async fn verify_http_signature(
if !is_valid_signature {
return Err(VerificationError::InvalidSignature);
}
Ok(())
let signer_id = actor_profile.actor_id(&config.instance_url())
.map_err(|_| VerificationError::ActorError("invalid profile".to_string()))?;
Ok(signer_id)
}
#[cfg(test)]