Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AuthenticationTokenHash #1985

Merged
merged 1 commit into from
Sep 25, 2023
Merged

Conversation

tgeoghegan
Copy link
Contributor

When acting as an HTTP server, Janus only needs a hash of the aggregator authentication token to validate incoming requests, and can avoid storing the actual token. This commit adds
janus_core::auth_tokens::AuthenticationTokenHash which will be used to implement that.

Part of #1509

@tgeoghegan tgeoghegan requested a review from a team as a code owner September 25, 2023 18:30
@tgeoghegan tgeoghegan force-pushed the timg/move-auth-tokens branch from 06b3f3b to e6ab04d Compare September 25, 2023 20:44
value: &[u8; SHA256_OUTPUT_LEN],
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&URL_SAFE_NO_PAD.encode(value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It strikes me as unusual to encode a sha256 hash as base64, rather than hex, but I can't think of anything actually wrong with it.

Comment on lines +412 to +417
self.aggregator_auth_token()
.map(AuthenticationTokenHash::from)
.zip(incoming_auth_token)
.map(|(own_token_hash, incoming_token)| own_token_hash.validate(incoming_token))
.unwrap_or(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you can zip an Option.

Copy link
Contributor

@branlwyd branlwyd Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(options work as Iterators which will always have either 0 (if None) or 1 (if Some) elements, so you can do with them whatever you can do with any iterator. this enables nice tricks like this sometimes.)

@inahga
Copy link
Contributor

inahga commented Sep 25, 2023

Note that I only reviewed 2577838.

Base automatically changed from timg/move-auth-tokens to main September 25, 2023 21:32
let mut any_non_equals = false;
// First loop: consume "normal" characters, stop when we see an equals sign for padding or
// reach the end of the input.
for c in &mut iter {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use a regex here? I lean away from them normally but a small value defined by BNF-like grammar is a perfect place for a regex IMO.

I think it would be something like [-a-zA-Z0-9._~+/]+=*.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(we could also just try decoding as base64, since I suppose that's the intent -- though that does lose some non-base64 values that are allowed by the BNF, such as A=======.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I introduced this in #1978. It got moved in #1984, and it'll disappear from here once it's rebased on main. A regex sounds good, it may be able to run faster too. As described in #1978, base64-decoding would be more strict than necessary, both in terms of the character set allowed, the choice of padding vs. no padding, and limitations on length (excluding padding). I can make a follow-up PR to swap in a regex here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have called out that this PR is stacked on #1984.

When acting as an HTTP server, Janus only needs a hash of the aggregator
authentication token to validate incoming requests, and can avoid
storing the actual token. This commit adds
`janus_core::auth_tokens::AuthenticationTokenHash` which will be used to
implement that.

Part of #1509
@tgeoghegan tgeoghegan force-pushed the timg/add-authentication-token-hash branch from 2577838 to e9786db Compare September 25, 2023 23:05
@tgeoghegan tgeoghegan enabled auto-merge (squash) September 25, 2023 23:10
core/src/auth_tokens.rs Show resolved Hide resolved
@tgeoghegan tgeoghegan merged commit 868de93 into main Sep 25, 2023
9 checks passed
@tgeoghegan tgeoghegan deleted the timg/add-authentication-token-hash branch September 25, 2023 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants