forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[knx] add initial support for KNX data secure [WIP], openhab#8872
* use Calimero library in latest version 2.5-SNAPSHOT (needs to be installed locally, mvn install) (to be replaced once a release is available) * add config options for keyring file(s) and password(s) * add tests for security functions * TODO replace ProcessCommunicationResponder, SAL required modification of Calimero lib Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
- Loading branch information
1 parent
e19c165
commit 4fe7539
Showing
11 changed files
with
234 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
....binding.knx/src/test/java/org/openhab/binding/knx/internal/security/KNXSecurityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (c) 2010-2020 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.knx.internal.security; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import tuwien.auto.calimero.GroupAddress; | ||
import tuwien.auto.calimero.IndividualAddress; | ||
import tuwien.auto.calimero.Keyring; | ||
import tuwien.auto.calimero.internal.Security; | ||
|
||
/** | ||
* | ||
* @author Simon Kaufmann - initial contribution and API | ||
* | ||
*/ | ||
public class KNXSecurityTest { | ||
|
||
@Test | ||
public void testCalimero_keyring() { | ||
final String testFile = getClass().getClassLoader().getResource("test.knxkeys").toString(); | ||
final char[] password = "habopen".toCharArray(); | ||
|
||
assertNotEquals("", testFile); | ||
Keyring keys = Keyring.load(testFile); | ||
assertTrue(keys.verifySignature(password)); | ||
|
||
System.out.println(keys.devices().toString()); | ||
System.out.println(keys.groups().toString()); | ||
System.out.println(keys.interfaces().toString()); | ||
|
||
GroupAddress ga = new GroupAddress(8, 0, 0); | ||
byte[] key800enc = keys.groups().get(ga); | ||
assertNotEquals(0, key800enc.length); | ||
byte[] key800dec = keys.decryptKey(key800enc, password); | ||
assertEquals(16, key800dec.length); | ||
|
||
IndividualAddress pa = new IndividualAddress(1, 2, 72); | ||
Keyring.Device dev = keys.devices().get(pa); | ||
// cannot check this for dummy test file, needs real device to be included | ||
// assertNotEquals(0, dev.sequenceNumber()); | ||
|
||
// currently Calimero uses _one_ static map to store all keys | ||
// -> check if this is still the case | ||
Security.defaultInstallation().useKeyring(keys, password); | ||
Map<GroupAddress, byte[]> groupKeys = Security.defaultInstallation().groupKeys(); | ||
assertEquals(3, groupKeys.size()); | ||
groupKeys.remove(ga); | ||
assertEquals(2, groupKeys.size()); | ||
Security.defaultInstallation().useKeyring(keys, password); | ||
Map<GroupAddress, byte[]> groupKeys2 = Security.defaultInstallation().groupKeys(); | ||
assertEquals(3, groupKeys2.size()); | ||
assertEquals(3, groupKeys.size()); | ||
ga = new GroupAddress(1, 0, 0); | ||
groupKeys.put(ga, new byte[1]); | ||
assertEquals(4, groupKeys2.size()); | ||
assertEquals(4, groupKeys.size()); | ||
Security.defaultInstallation().useKeyring(keys, password); | ||
assertEquals(4, groupKeys2.size()); | ||
assertEquals(4, groupKeys.size()); | ||
} | ||
} |
Oops, something went wrong.