From 522241b5deeff8b4d3c0d0cac7f76933c3e6e9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= Date: Sun, 16 Apr 2023 21:01:07 +0200 Subject: [PATCH] Fix hebe registration --- .../github/wulkanowy/sdk/hebe/ApiRequest.kt | 10 +++--- .../io/github/wulkanowy/sdk/hebe/Hebe.kt | 32 ++++++++++++------- .../sdk/hebe/interceptor/SignInterceptor.kt | 2 +- .../sdk/hebe/register/RegisterRequest.kt | 2 +- .../sdk/hebe/repository/RegisterRepository.kt | 20 ++++-------- .../sdk/hebe/repository/RepositoryManager.kt | 1 + 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt index 4971ef62..f6813697 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/ApiRequest.kt @@ -2,8 +2,8 @@ package io.github.wulkanowy.sdk.hebe import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import java.time.LocalDateTime -import java.time.ZoneOffset.UTC +import java.time.ZoneId +import java.time.ZonedDateTime import java.time.format.DateTimeFormatter.ofPattern import java.util.UUID @@ -17,7 +17,7 @@ internal data class ApiRequest( val appName: String = "DzienniczekPlus 2.0", @SerialName("AppVersion") - val appVersion: String = "1.4.2", + val appVersion: String = "22.09.02 (G)", @SerialName("CertificateId") val certificateId: String, @@ -32,8 +32,8 @@ internal data class ApiRequest( val requestId: String = UUID.randomUUID().toString(), @SerialName("Timestamp") - val timestamp: Long = LocalDateTime.now().toEpochSecond(UTC), + val timestamp: Long = ZonedDateTime.now(ZoneId.of("GMT")).toInstant().toEpochMilli(), @SerialName("TimestampFormatted") - val timestampFormatted: String = LocalDateTime.now().format(ofPattern("yyyy-MM-dd hh:mm:ss")), + val timestampFormatted: String = ZonedDateTime.now(ZoneId.of("GMT")).format(ofPattern("yyyy-MM-dd hh:mm:ss")), ) diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt index b30b4f62..94291655 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/Hebe.kt @@ -64,20 +64,30 @@ class Hebe { suspend fun register(firebaseToken: String, token: String, pin: String, symbol: String): RegisterDevice { val (publicPem, privatePem, publicHash) = generateKeyPair() - val (certificatePem, certificateHash) = generateCertificate(privatePem) + this.keyId = publicHash this.privatePem = privatePem - this.keyId = certificateHash - return serviceManager.getRegisterRepository(routes.getRouteByToken(token), symbol) - .register( - firebaseToken = firebaseToken, - token = token, - pin = pin, - privatePem = privatePem, - keyId = keyId, - deviceModel = deviceModel, - ) + val envelope = serviceManager.getRegisterRepository( + baseUrl = routes.getRouteByToken(token), + symbol = symbol, + ).register( + firebaseToken = firebaseToken, + token = token, + pin = pin, + certificatePem = publicPem, + certificateId = publicHash, + deviceModel = deviceModel, + ) + + return RegisterDevice( + loginId = envelope.loginId, + restUrl = envelope.restUrl, + userLogin = envelope.userLogin, + userName = envelope.userName, + certificateHash = publicHash, + privatePem = privatePem, + ) } suspend fun getStudents(url: String, symbol: String): List { diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt index 4b514d6f..1ed2bf7c 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/interceptor/SignInterceptor.kt @@ -18,7 +18,7 @@ internal class SignInterceptor( val original = chain.request() val request = original.newBuilder() - request.header("UserAgent", "Dart/2.10 (dart:io)") + request.header("User-Agent", "Dart/2.10 (dart:io)") request.header("vOS", "Android") request.header("vDeviceModel", deviceModel) request.header("vAPI", "1") diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt index 6708bf93..71646f2b 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/register/RegisterRequest.kt @@ -14,7 +14,7 @@ internal data class RegisterRequest( val certificateThumbprint: String, @SerialName("CertificateType") - val certificateType: String = "X509", + val certificateType: String = "RSA_PEM", @SerialName("DeviceModel") val deviceModel: String, diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt index 6cde8d82..16775b5a 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RegisterRepository.kt @@ -15,12 +15,12 @@ internal class RegisterRepository(private val service: RegisterService) { token: String, pin: String, deviceModel: String, - privatePem: String, - keyId: String, - ): RegisterDevice { + certificatePem: String, + certificateId: String, + ): RegisterResponse { val response = registerDevice( - privateKey = privatePem, - certificateId = keyId, + privateKey = certificatePem, + certificateId = certificateId, deviceModel = deviceModel, firebaseToken = firebaseToken, pin = pin, @@ -33,15 +33,7 @@ internal class RegisterRepository(private val service: RegisterService) { } } - val envelope = response.envelope!! - return RegisterDevice( - loginId = envelope.loginId, - restUrl = envelope.restUrl, - userLogin = envelope.userLogin, - userName = envelope.userName, - certificateHash = keyId, - privatePem = privatePem, - ) + return response.envelope!! } private suspend fun registerDevice( diff --git a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt index 83020588..d149ae60 100644 --- a/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt +++ b/sdk-hebe/src/main/kotlin/io/github/wulkanowy/sdk/hebe/repository/RepositoryManager.kt @@ -25,6 +25,7 @@ internal class RepositoryManager( private val json by lazy { Json { explicitNulls = false + encodeDefaults = true ignoreUnknownKeys = true coerceInputValues = true isLenient = true