Skip to content

Commit

Permalink
[freebox] Hot fix for login to the freebox (openhab#7696)
Browse files Browse the repository at this point in the history
* [freebox] Hot fix for login to the freebox
PR openhab#7460 broke the freebox binding
* Unit test added for method hmacSha1

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored and andrewfg committed Aug 31, 2020
1 parent 9a129d4 commit b56ee70
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit b56ee70

Please sign in to comment.