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

Update Network and Application key at start of KeyUpdate #477

Closed
eanderlind opened this issue Mar 19, 2023 · 5 comments · Fixed by #517
Closed

Update Network and Application key at start of KeyUpdate #477

eanderlind opened this issue Mar 19, 2023 · 5 comments · Fixed by #517
Labels
question Further information is requested

Comments

@eanderlind
Copy link

Is there a way for application to create updates of NetworkKey and ApplicationKey for use in KeyUpdate procedure?
The api in

func add(applicationKey: Data, withIndex index: KeyIndex? = nil, name: String) throws -> ApplicationKey {

recreates a key at same index, while we instead want to invoke the (internal access) didSet on the existing key.
The same api also limits binding to the first Netkey, however it looks like once we have an Appkey we can rebind it using

Hopefully just didn't find correct api.

@philips77
Copy link
Member

Hi,
Yes, it is possible. For that you have to send ConfigNetKeyUpdate or ConfigAppKeyUpdate message to [local Node](

func sendToLocalNode(_ message: ConfigMessage) throws -> MessageHandle {
, just like to any other Node.

The message will be handled here:

if networkKey.phase == .normalOperation {
// Update the key data (observer will set the `oldKey` automatically).
networkKey.key = request.key
// And mark the key in the local Node as updated.
localNode.update(networkKeyWithIndex: keyIndex)
}
return ConfigNetKeyStatus(confirm: networkKey)

Setting the key in line 141 does the following:
public internal(set) var key: Data {
willSet {
oldKey = key
oldNetworkId = networkId
oldKeys = keys
}
didSet {
phase = .keyDistribution
regenerateKeyDerivatives()
}
}

The update(networkKeyWithIndex sets the updated flag in the Node's key list:
/// Marks the Network Key in the Node as updated.
///
/// - parameter networkKeyIndex: The Network Key index to add.
func update(networkKeyWithIndex networkKeyIndex: KeyIndex) {
if let key = netKeys[networkKeyIndex] {
key.updated = true
meshNetwork?.timestamp = Date()
}
}

@philips77 philips77 added the question Further information is requested label Mar 20, 2023
@philips77
Copy link
Member

You may find some info here: #314

@eanderlind
Copy link
Author

Thanks - that explains the 2nd half of the process. The remaining part is how to instantiate the two messages with the new key. Looks like only way is to generate a newkey bytestring and then hand craft a msg using the ConfigNetKeyUpdate(parameters:Data) initializer.

Not intuitive, but we will try it out... Thanks. Closing the issue since there is a workaround.

@philips77
Copy link
Member

Great that you pointed it out. That needs improvement. I'll fix it in the next (big!) release.

@philips77
Copy link
Member

@eanderlind I fixed the API. The 2 config messages now allow to pass the new key as Data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants