Commit e761240 1 parent ab5ebbc commit e761240 Copy full SHA for e761240
File tree 3 files changed +6
-17
lines changed
bundles/org.openhab.binding.mybmw/src
main/java/org/openhab/binding/mybmw/internal
test/java/org/openhab/binding/mybmw/internal/handler
3 files changed +6
-17
lines changed Original file line number Diff line number Diff line change 52
52
import org .openhab .binding .mybmw .internal .utils .HTTPConstants ;
53
53
import org .openhab .binding .mybmw .internal .utils .ImageProperties ;
54
54
import org .openhab .core .io .net .http .HttpClientFactory ;
55
+ import org .openhab .core .util .StringUtils ;
55
56
import org .slf4j .Logger ;
56
57
import org .slf4j .LoggerFactory ;
57
58
@@ -323,12 +324,12 @@ public synchronized boolean updateToken() {
323
324
/*
324
325
* Step 2) Calculate values for base parameters
325
326
*/
326
- String verfifierBytes = Converter . getRandomString (64 );
327
+ String verfifierBytes = StringUtils . getRandomAlphabetic (64 ). toLowerCase ( );
327
328
String codeVerifier = Base64 .getUrlEncoder ().withoutPadding ().encodeToString (verfifierBytes .getBytes ());
328
329
MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
329
330
byte [] hash = digest .digest (codeVerifier .getBytes (StandardCharsets .UTF_8 ));
330
331
String codeChallange = Base64 .getUrlEncoder ().withoutPadding ().encodeToString (hash );
331
- String stateBytes = Converter . getRandomString (16 );
332
+ String stateBytes = StringUtils . getRandomAlphabetic (16 ). toLowerCase ( );
332
333
String state = Base64 .getUrlEncoder ().withoutPadding ().encodeToString (stateBytes .getBytes ());
333
334
334
335
MultiMap <String > baseParams = new MultiMap <String >();
Original file line number Diff line number Diff line change 13
13
package org .openhab .binding .mybmw .internal .utils ;
14
14
15
15
import java .lang .reflect .Type ;
16
- import java .security .SecureRandom ;
17
16
import java .text .SimpleDateFormat ;
18
17
import java .time .LocalTime ;
19
18
import java .time .ZoneId ;
24
23
import java .util .Date ;
25
24
import java .util .List ;
26
25
import java .util .Locale ;
27
- import java .util .Random ;
28
26
import java .util .TimeZone ;
29
27
30
28
import org .eclipse .jdt .annotation .NonNullByDefault ;
@@ -249,15 +247,6 @@ public static Vehicle getConsistentVehcile(Vehicle v) {
249
247
return v ;
250
248
}
251
249
252
- public static String getRandomString (int size ) {
253
- int leftLimit = 97 ; // letter 'a'
254
- int rightLimit = 122 ; // letter 'z'
255
- Random random = new SecureRandom ();
256
-
257
- return random .ints (leftLimit , rightLimit + 1 ).limit (size )
258
- .collect (StringBuilder ::new , StringBuilder ::appendCodePoint , StringBuilder ::append ).toString ();
259
- }
260
-
261
250
public static State getLockState (boolean lock ) {
262
251
if (lock ) {
263
252
return StringType .valueOf (Constants .LOCKED );
Original file line number Diff line number Diff line change 46
46
import org .openhab .binding .mybmw .internal .utils .Constants ;
47
47
import org .openhab .binding .mybmw .internal .utils .Converter ;
48
48
import org .openhab .core .io .net .http .HttpClientFactory ;
49
+ import org .openhab .core .util .StringUtils ;
49
50
import org .slf4j .Logger ;
50
51
import org .slf4j .LoggerFactory ;
51
52
@@ -78,16 +79,14 @@ void testAuth() {
78
79
AuthQueryResponse aqr = Converter .getGson ().fromJson (firstResponse .getContentAsString (),
79
80
AuthQueryResponse .class );
80
81
81
- // String verifier_bytes = RandomStringUtils.randomAlphanumeric(64);
82
- String verifierBytes = Converter .getRandomString (64 );
82
+ String verifierBytes = StringUtils .getRandomAlphabetic (64 ).toLowerCase ();
83
83
String codeVerifier = Base64 .getUrlEncoder ().withoutPadding ().encodeToString (verifierBytes .getBytes ());
84
84
85
85
MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
86
86
byte [] hash = digest .digest (codeVerifier .getBytes (StandardCharsets .UTF_8 ));
87
87
String codeChallenge = Base64 .getUrlEncoder ().withoutPadding ().encodeToString (hash );
88
88
89
- // String state_bytes = RandomStringUtils.randomAlphanumeric(16);
90
- String stateBytes = Converter .getRandomString (16 );
89
+ String stateBytes = StringUtils .getRandomAlphabetic (16 ).toLowerCase ();
91
90
String state = Base64 .getUrlEncoder ().withoutPadding ().encodeToString (stateBytes .getBytes ());
92
91
93
92
String authUrl = aqr .gcdmBaseUrl + BimmerConstants .OAUTH_ENDPOINT ;
You can’t perform that action at this time.
0 commit comments