Skip to content

Commit

Permalink
Updated keys loading logic (#177)
Browse files Browse the repository at this point in the history
* Updated keys loading logic

* Version update
  • Loading branch information
oleksandrsarapulovgl authored Aug 3, 2021
1 parent 1f4e521 commit ec9684b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,24 @@ class VerifierRepositoryImpl @Inject constructor(
val tokenFormatted = if (resumeToken == -1L) "" else resumeToken.toString()
val response = apiService.getCertUpdate(tokenFormatted, url)

if (!response.isSuccessful || response.code() == HttpURLConnection.HTTP_NO_CONTENT) {
Timber.d("No content")
return
}

val headers = response.headers()
val responseKid = headers[HEADER_KID]
val newResumeToken = headers[HEADER_RESUME_TOKEN]
val responseStr = response.body()?.stringSuspending() ?: return

if (validCertList.contains(responseKid) && isKidValid(responseKid, responseStr)) {
Timber.d("Cert KID verified")
val key = Key(kid = responseKid!!, key = keyStoreCryptor.encrypt(responseStr)!!)
db.keyDao().insert(key)
}

newResumeToken?.let {
val newToken = it.toLong()
preferences.resumeToken = newToken
fetchCertificate(url, newToken)
if (response.isSuccessful && response.code() == HttpURLConnection.HTTP_OK) {
val headers = response.headers()
val responseKid = headers[HEADER_KID]
val newResumeToken = headers[HEADER_RESUME_TOKEN]
val responseStr = response.body()?.stringSuspending() ?: return

if (validCertList.contains(responseKid) && isKidValid(responseKid, responseStr)) {
Timber.d("Cert KID verified")
val key = Key(kid = responseKid!!, key = keyStoreCryptor.encrypt(responseStr)!!)
db.keyDao().insert(key)

preferences.resumeToken = resumeToken

newResumeToken?.let {
val newToken = it.toLong()
fetchCertificate(url, newToken)
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ object Config {
const val targetSdk = 29
val javaVersion = JavaVersion.VERSION_1_8

const val versionCode = 19
const val versionName = "1.1.11"
const val versionCode = 20
const val versionName = "1.1.12"

const val androidTestInstrumentation = "androidx.test.runner.AndroidJUnitRunner"
const val proguardConsumerRules = "consumer-rules.pro"
Expand Down

0 comments on commit ec9684b

Please sign in to comment.