Fix hebe registration
This commit is contained in:
parent
d85a85235f
commit
522241b5de
6 changed files with 35 additions and 32 deletions
|
@ -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<T>(
|
|||
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<T>(
|
|||
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")),
|
||||
)
|
||||
|
|
|
@ -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<StudentInfo> {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -25,6 +25,7 @@ internal class RepositoryManager(
|
|||
private val json by lazy {
|
||||
Json {
|
||||
explicitNulls = false
|
||||
encodeDefaults = true
|
||||
ignoreUnknownKeys = true
|
||||
coerceInputValues = true
|
||||
isLenient = true
|
||||
|
|
Loading…
Reference in a new issue