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-M1 (to be replaced once release 2.5 is available) * add config options for keyring file(s) and password(s) * add tests for security functions * TODO replace ProcessCommunicationResponder * build for OH 302 and 31x Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
- Loading branch information
1 parent
56b2f47
commit 4aae0a8
Showing
12 changed files
with
255 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This workflow will build a Java project with Maven | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | ||
|
||
name: Build knx addon with Maven | ||
|
||
on: | ||
push: | ||
branches: [ pr-knx-data-secure ] | ||
|
||
jobs: | ||
build302: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Java 11 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml -pl :org.openhab.binding.knx -Dohc.version=3.0.2 | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: org.openhab.binding.knx.302 | ||
path: bundles/org.openhab.binding.knx/target/org.openhab.binding.knx-*.jar | ||
|
||
build31x: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Java 11 | ||
uses: actions/setup-java@v1 | ||
with: | ||
java-version: 11 | ||
- name: Build with Maven | ||
run: mvn -B package --file pom.xml -pl :org.openhab.binding.knx | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: org.openhab.binding.knx.31x | ||
path: bundles/org.openhab.binding.knx/target/org.openhab.binding.knx-*.jar | ||
|
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-2021 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.secure.Keyring; | ||
import tuwien.auto.calimero.secure.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.