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

Basic authentication using HMAC for federates joining a federation #105

Merged
merged 46 commits into from
Dec 21, 2022

Conversation

hokeun
Copy link
Member

@hokeun hokeun commented Aug 31, 2022

This PR is a submodule PR of the PR lf-lang/lingua-franca#1432 and is the first step towards resolving lf-lang/lingua-franca#1146. Both PRs should be merged to work.

Overall information is also in lf-lang/lingua-franca#1432. This PR details the HMAC authentication implementation.

This PR is about the RTI.c and federate.c authentication implementation.

The main idea of security is not to send the federation ID in plain text, by using it as an HMAC key.

3-Way Handshake

1. RTI_HELLO (RTI -> Federate)

The RTI sends a RTI_HELLO message to the federate when TCP connection is established. The message is in this order:

  • One byte equal to MSG_TYPE_RTI_RESPONSE.
  • Eight bytes for randomly created RTI's nonce.

2. FED_RESPONSE (Federate -> RTI)

The federate sends a response message to the RTI. It creates it's own nonce, and makes a HMAC tag using the federate ID as the key. The message is in the following order:

  • One byte equal to MSG_TYPE_FED_RESPONSE.
  • Eight bytes for federate's nonce.
  • Two bytes for the federate ID.
  • 32 bytes for HMAC tag based on SHA256.

The HMAC tag is composed of the following order:

  • One byte equal to MSG_TYPE_FED_RESPONSE.
  • Two bytes for the federate ID.
  • Eight bytes for received RTI's nonce.

3. RTI_RESPONSE (RTI -> Federate)

The RTI sends a response message to the federate. It checks the received HMAC created by the federate, and also makes a HMAC tag. The message is in the following order:

  • One byte equal to MSG_TYPE_RTI_RESPONSE.
  • 32 bytes for HMAC tag based on SHA256.

The HMAC tag is composed of the following order:

  • One byte equal to MSG_TYPE_RTI_RESPONSE.
  • Eight bytes for received federate's nonce.

Federate Check

The federate finally checks the received HMAC created by the RTI.

Discussion

The 3-way handshake protocol does not change the existing federation id check process. receive_and_check_fed_id_message() still always happen after the 3-way handshake. So, the auth:true option only enables the 3-way handshake. Changing the protocol will be discussed at the future.

Also, the auth:true option will be changed from boolean to string in future.

Copy link
Contributor

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

I realize this is a draft, but it doesn't seem to perform any authentication. Guess this isn't ready for review?

core/federated/federate.c Show resolved Hide resolved
core/federated/RTI/rti.c Outdated Show resolved Hide resolved
@hokeun
Copy link
Member Author

hokeun commented Sep 4, 2022

I realize this is a draft, but it doesn't seem to perform any authentication. Guess this isn't ready for review?

Thanks, @edwardalee for checking! You're right, this is not ready for review yet. I created this draft so that I can easily share my progress with others using Files Changed tap. I'll surely let you know when this is ready for review!

@Jakio815 Jakio815 changed the title Add basic authentication using HMAC for federates joining a federation Draft: Add basic authentication using HMAC for federates joining a federation Oct 30, 2022
@Jakio815

This comment was marked as duplicate.

with:
runtime-ref: ${{ github.ref }}
compiler-ref: ${{ needs.fetch-lf.outputs.ref }}
scheduler: GEDF_NP_CI

lf-adaptive:
needs: fetch-lf
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@master
uses: lf-lang/lingua-franca/.github/workflows/c-tests.yml@auth
with:
Copy link
Collaborator

Choose a reason for hiding this comment

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

These changes are only for CI tests.

@Jakio815 Jakio815 marked this pull request as ready for review November 22, 2022 02:31
@Jakio815 Jakio815 changed the title Draft: Add basic authentication using HMAC for federates joining a federation Add basic authentication using HMAC for federates joining a federation Nov 22, 2022
Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

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

This looks good to me. Though I think that we might want to enable security by default and provide the option to disable it for whatever reason...

include/core/federated/net_common.h Outdated Show resolved Hide resolved
@Jakio815 Jakio815 merged commit b439413 into main Dec 21, 2022
@Jakio815 Jakio815 deleted the security branch December 30, 2022 23:53
@lhstrh lhstrh changed the title Add basic authentication using HMAC for federates joining a federation Basic authentication using HMAC for federates joining a federation Jan 26, 2023
@petervdonovan petervdonovan added the feature New feature label Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants