From f61212f185bc1b52681832e8b142904e6cd75c8f Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Tue, 19 May 2020 20:13:05 +0200 Subject: [PATCH 1/3] [freebox] Hot fix for login to the freebox PR #7460 broke the freebox binding Signed-off-by: Laurent Garnier --- .../openhab/binding/freebox/internal/api/FreeboxApiManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java index e16dc21043455..c2acb2f7a015f 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java @@ -493,7 +493,7 @@ private static String hmacSha1(String key, String value) throws FreeboxException byte[] rawHmac = mac.doFinal(value.getBytes()); // Convert raw bytes to a String - return HexUtils.bytesToHex(rawHmac); + return HexUtils.bytesToHex(rawHmac).toLowerCase(); } catch (IllegalArgumentException | NoSuchAlgorithmException | InvalidKeyException | IllegalStateException e) { throw new FreeboxException("Computing the hmac-sha1 of the challenge and the app token failed", e); } From d5a255cc561318ab9013c4ec5c1b4dbcb8349959 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Tue, 19 May 2020 22:14:28 +0200 Subject: [PATCH 2/3] Unit test added for method hmacSha1 Signed-off-by: Laurent Garnier --- .../internal/FreeboxHandlerFactory.java | 3 +- .../internal/api/FreeboxApiManager.java | 2 +- .../internal/api/FreeboxApiManagerTest.java | 33 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java index 1af9a22929ef7..ff742b211df7e 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/FreeboxHandlerFactory.java @@ -21,7 +21,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.smarthome.config.core.Configuration; @@ -95,7 +94,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { } @Override - public @Nullable Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration, + public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) { if (thingTypeUID.equals(FreeboxBindingConstants.FREEBOX_BRIDGE_TYPE_SERVER)) { return super.createThing(thingTypeUID, configuration, thingUID, null); diff --git a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java index c2acb2f7a015f..928b1e77d93af 100644 --- a/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java +++ b/bundles/org.openhab.binding.freebox/src/main/java/org/openhab/binding/freebox/internal/api/FreeboxApiManager.java @@ -479,7 +479,7 @@ private String encodeUrl(String url) throws FreeboxException { } } - private static String hmacSha1(String key, String value) throws FreeboxException { + public static String hmacSha1(String key, String value) throws FreeboxException { try { // Get an hmac_sha1 key from the raw key bytes byte[] keyBytes = key.getBytes(); diff --git a/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java b/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java new file mode 100644 index 0000000000000..038656fc044e5 --- /dev/null +++ b/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java @@ -0,0 +1,33 @@ +/** + * 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.freebox.internal.api; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author Laurent Garnier - Initial contribution + */ +@NonNullByDefault +public class FreeboxApiManagerTest { + + @Test + public void hmacSha1Test() throws Exception { + String expected = "25dad1bb5604321f12b755cc9d755d1480cf7989"; + String actual = FreeboxApiManager.hmacSha1("Token1234", "Challenge"); + Assert.assertEquals(expected, actual); + } + +} \ No newline at end of file From b958ecbe9b430c281defc9983f1db5c6ebfec7b4 Mon Sep 17 00:00:00 2001 From: Laurent Garnier Date: Tue, 19 May 2020 22:31:13 +0200 Subject: [PATCH 3/3] Newline added Signed-off-by: Laurent Garnier --- .../binding/freebox/internal/api/FreeboxApiManagerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java b/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java index 038656fc044e5..280b2a7464179 100644 --- a/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java +++ b/bundles/org.openhab.binding.freebox/src/test/java/org/openhab/binding/freebox/internal/api/FreeboxApiManagerTest.java @@ -30,4 +30,4 @@ public void hmacSha1Test() throws Exception { Assert.assertEquals(expected, actual); } -} \ No newline at end of file +}