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 audio encryption/decryption utilities #573

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

skheyfets-asapp
Copy link
Contributor

Added:

  • Key derivation functions (DeriveKeyFrom*) from string and byte array which derive the same keys as client-sdk-js with the same inputs
  • Encryption/Decryption utilities for audio packets which encrypt/decrypt using AES-GCM 128bit and compatible with client-sdk-js
  • Decryption utility will also drop the server injected frames

Changed:

  • TrackPublicationOptions struct to support passing the Encryption Type (already part of protocol)
  • LocalParticipant.PublishTrack() to pass the encryption type from TrackPublicationOptions into signaling
  • Room to store sifTrailer from joinResponse so that sifTrailer can be passed later to Decryption utility

@CLAassistant
Copy link

CLAassistant commented Dec 9, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@lukasIO lukasIO left a comment

Choose a reason for hiding this comment

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

nice, this lgtm!

encryption.go Outdated Show resolved Hide resolved
@davidzhao davidzhao merged commit 5963330 into livekit:main Dec 13, 2024
2 checks passed
Copy link
Contributor

@boks1971 boks1971 left a comment

Choose a reason for hiding this comment

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

lgtm, some question inline. Sorry for the late review.

unencrypted_audio_bytes = 1
)

var ErrIncorrectKeyLength = errors.New("incorrect key length for encryption/decryption")
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, very late on this review. In case you get a chance, suggest a style like

var (
    Err1 =
    Err2 =
)

That makes it easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I can change in the next PR, I was going to add example on how to use the utilities separately.


key, err := DeriveKeyFromBytes(inputSecret)
assert.Nil(t, err)
assert.Equal(t, expectedKey, key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we switch these to require package? LK has been using it in other repos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, I'll have a look

copy(cipherText, sample[cipherTextStart:cipherTextStart+cipherTextLength])

// setup AES
aesCipher, err := aes.NewCipher(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any performance penalty to creating this for every sample? Can this be created in track context and re-used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to keep it as separate and self-contained as possible without the need to instantiate anything separately to use it. I believe the AES operations are highly optimized in Go with the use of Go Assembler, but I'll see if I can run a quick benchmark with and without the cipher reuse.

@skheyfets-asapp skheyfets-asapp deleted the sk_add_encryption branch December 16, 2024 17:03
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.

5 participants