Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

fix(open from existing): create encrypted core from unencrypted core #104

Merged
merged 3 commits into from
May 26, 2022

Conversation

Nuhvi
Copy link
Contributor

@Nuhvi Nuhvi commented May 23, 2022

same logic in core.session() added to core._openFromExisting with one
difference; new core will override existing.encryption

Allows hypercore-protocol/corestore-next#17 to pass

index.js Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
@Nuhvi Nuhvi force-pushed the encrypted-from-existing branch 2 times, most recently from dedf073 to 31605ad Compare May 23, 2022 10:49
@mafintosh
Copy link
Collaborator

@nazeh hmm somehow this got a ton of unrelated changes bundled into it

same logic in core.session() added to core._openFromExisting with one
difference; new core will override existing.encryption

Closes hypercore-protocol/corestore-next#17
@Nuhvi
Copy link
Contributor Author

Nuhvi commented May 23, 2022

@mafintosh My bad, solved now. The function is not simplified as you suggested, but close enough

if (!opts.encryptionKey) return
// Only override the block encryption if its either not already set or if
// the caller provided a different key.
if (!core.encryption || !b4a.equals(core.encryption.key, opts.encryptionKey)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kasperisager is there actually ever a case where core.encryption is not set here? this is a freshly minted session no?

Copy link
Contributor

Choose a reason for hiding this comment

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

The only case should be if the root session is unencrypted, no?

Copy link
Collaborator

Choose a reason for hiding this comment

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

but core is always the session isn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

the core variable here

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, and only the root session initializes block encryption. From there it's passed to other sessions. If the root session is unencrypted, session.encryption will be null, in this case core.encryption.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything I need to do here?

@mafintosh mafintosh merged commit 3318dfd into hypercore-protocol:master May 26, 2022
mafintosh pushed a commit that referenced this pull request May 26, 2022
…104)

same logic in core.session() added to core._openFromExisting with one
difference; new core will override existing.encryption

Closes hypercore-protocol/corestore-next#17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants