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

feat: Implement Encryption with Hash Digest #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anushkaVerma1007
Copy link

@anushkaVerma1007 anushkaVerma1007 commented Oct 12, 2024

🚀 ### Feature: Implement Chunk-Based Data Encryption and Integrity Verification for Secure Data Transfer

Description

This pull request implements a mechanism for encrypting data in chunks before transfer and decrypting it after transfer completion as described in issue #3. The changes include the generation of a hash digest for each chunk to ensure data integrity during transmission. The changes involves:

  • Introduced AES encryption for each data chunk.
  • Added SHA-256 hash generation for each chunk.
  • Implemented verification of hash digest upon receiving data chunks.
  • Developed logic to decrypt and reassemble data after successful verification.

Related Issue

Fixes #3

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Motivation and Context

This change is required to enhance data security during transfers, addressing vulnerabilities associated with unencrypted data. Implementing encryption and integrity checks mitigates risks related to interception and tampering.

How Has This Been Tested?

  • Test Data Encryption: Created test cases to validate the AES encryption of data chunks.
  • Test Hash Generation: Verified the SHA-256 hash for each chunk.
  • Test Verification Process: Implemented tests to ensure that received data chunks could be verified against
    their hash digests.
  • Test Decryption: Checked that the decrypted data matches the original data before encryption.

Screenshots (if appropriate):

Checklist:

  • I have registered myself at Contrihub website.
  • My code follows the code style of this project.
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • Any dependent changes have been merged and published in downstream modules
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

@anushkaVerma1007
Copy link
Author

sir, Please review my pull request.

@SaiDheerajPeketi
Copy link

@anushkaVerma1007, since you are using AES, the key used on encryption side and decryption side should be the same. How is the key getting transferred between devices?

Where are the functions generateHash and verifyHash getting called on Data Block?

@SaiDheerajPeketi SaiDheerajPeketi removed the request for review from darkBlueLemon October 12, 2024 07:57
@anushkaVerma1007
Copy link
Author

@SaiDheerajPeketi , apologies for the oversight. I have implemented the generateHash and verifyHash, but not integrated. The should be generated before sending the data, and on the recievers side, it should be verfied after decryption. Is this correct approach?

@SaiDheerajPeketi
Copy link

If you are generating hash on sender's side after encryption then you have to verify before decryption on receiver's side. This would be the better approach compared to calculating hash before encryption.

@anushkaVerma1007
Copy link
Author

@SaiDheerajPeketi yes sir this is correct approach to do the task..

@Pra-San
Copy link
Member

Pra-San commented Oct 17, 2024

@anushkaVerma1007 Any updates?

@anushkaVerma1007
Copy link
Author

@Pra-San sir can I correct my implementation and submit another pull request ?

@Pra-San
Copy link
Member

Pra-San commented Oct 17, 2024

@anushkaVerma1007 you can update this PR once you are done with your implementation.

@SaiDheerajPeketi
Copy link

@anushkaVerma1007 Any updates?

@Pra-San
Copy link
Member

Pra-San commented Oct 24, 2024

@anushkaVerma1007 Transfer process is crashing with the error:
FATAL EXCEPTION: main Process: com.invincible.jedishare, PID: 31591 java.lang.IllegalStateException: AES key not initialized! at com.invincible.jedishare.data.chat.BluetoothDataTransferService$sendMessage$2.invokeSuspend(BluetoothDataTransferService.kt:146) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@dc3cdaf, Dispatchers.Main.immediate]

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.

Implement Encryption with Hash Digest for Secure Data Transfer
3 participants