Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Bump librepass client to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Feb 27, 2024
1 parent e821c61 commit bf6ed57
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.bastiaanjansen.otp.TOTPGenerator
import com.google.gson.Gson
import dev.medzik.android.components.SecondaryText
import dev.medzik.android.components.navigate
Expand All @@ -28,7 +27,8 @@ import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.ui.Screen
import dev.medzik.librepass.types.cipher.Cipher
import dev.medzik.librepass.types.cipher.data.CipherLoginData
import java.net.URI
import dev.medzik.otp.OTPParser
import dev.medzik.otp.TOTPGenerator

@Composable
fun CipherEditFieldsLogin(
Expand Down Expand Up @@ -173,7 +173,8 @@ fun CipherEditFieldsLogin(
val checkOtp =
!cipher.loginData?.twoFactor.isNullOrEmpty() &&
runCatching {
TOTPGenerator.fromURI(URI(cipher.loginData?.twoFactor)).now()
val params = OTPParser.parse(cipher.loginData?.twoFactor)
TOTPGenerator.now(params)
}.isFailure

TextInputFieldBase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import dev.medzik.librepass.android.utils.StoreKey
import dev.medzik.librepass.android.utils.showErrorToast
import dev.medzik.librepass.client.Server
import dev.medzik.librepass.client.api.AuthClient
import dev.medzik.librepass.utils.fromHexString
import dev.medzik.librepass.utils.fromHex
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -90,7 +90,7 @@ fun LoginScreen(
)
viewModel.credentialRepository.insert(credentialsDb)

viewModel.vault.aesKey = credentials.aesKey.fromHexString()
viewModel.vault.aesKey = credentials.aesKey.fromHex()

viewModel.credentialRepository.update(
credentialsDb.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.bastiaanjansen.otp.TOTPGenerator
import dev.medzik.android.components.LoadingButton
import dev.medzik.android.components.getString
import dev.medzik.android.components.rememberMutable
Expand All @@ -35,9 +34,10 @@ import dev.medzik.librepass.android.utils.showErrorToast
import dev.medzik.librepass.types.cipher.Cipher
import dev.medzik.librepass.types.cipher.CipherType
import dev.medzik.librepass.types.cipher.data.PasswordHistory
import dev.medzik.otp.OTPParser
import dev.medzik.otp.TOTPGenerator
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.net.URI
import java.util.Date

@Composable
Expand Down Expand Up @@ -92,7 +92,8 @@ fun CipherEditScreen(
(
cipher.loginData!!.twoFactor.isNullOrEmpty() ||
runCatching {
TOTPGenerator.fromURI(URI(cipher.loginData?.twoFactor)).now()
val params = OTPParser.parse(cipher.loginData?.twoFactor)
TOTPGenerator.now(params)
}.isSuccess
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.OpenInNew
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.History
Expand Down Expand Up @@ -39,7 +40,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.navigation.NavController
import com.bastiaanjansen.otp.TOTPGenerator
import dev.medzik.android.components.BaseDialog
import dev.medzik.android.components.SecondaryText
import dev.medzik.android.components.getString
Expand All @@ -56,9 +56,10 @@ import dev.medzik.librepass.android.ui.components.TopBarBackIcon
import dev.medzik.librepass.android.utils.SHORTEN_NAME_LENGTH
import dev.medzik.librepass.android.utils.shorten
import dev.medzik.librepass.types.cipher.CipherType
import dev.medzik.otp.OTPParser
import dev.medzik.otp.TOTPGenerator
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.net.URI
import java.text.SimpleDateFormat
import java.util.Locale

Expand All @@ -78,13 +79,14 @@ fun CipherViewScreen(

LaunchedEffect(scope) {
if (cipher.type == CipherType.Login && !cipher.loginData?.twoFactor.isNullOrEmpty()) {
totpCode = TOTPGenerator.fromURI(URI(cipher.loginData?.twoFactor)).now()
val params = OTPParser.parse(cipher.loginData?.twoFactor)
totpCode = TOTPGenerator.now(params)

scope.launch {
while (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) {
delay(30 * 1000)

totpCode = TOTPGenerator.fromURI(URI(cipher.loginData?.twoFactor)).now()
totpCode = TOTPGenerator.now(params)
}
}
}
Expand Down Expand Up @@ -422,7 +424,7 @@ fun CipherField(
}
}) {
Icon(
imageVector = Icons.Default.OpenInNew,
imageVector = Icons.AutoMirrored.Filled.OpenInNew,
contentDescription = null
)
}
Expand Down
23 changes: 14 additions & 9 deletions app/src/main/java/dev/medzik/librepass/android/utils/Exception.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dev.medzik.librepass.android.BuildConfig
import dev.medzik.librepass.android.R
import dev.medzik.librepass.client.errors.ApiException
import dev.medzik.librepass.client.errors.ClientException
import dev.medzik.librepass.responses.ResponseError
import dev.medzik.librepass.errors.ServerError

/** Log exception if debugging is enabled. */
fun Exception.debugLog() {
Expand Down Expand Up @@ -43,14 +43,19 @@ fun Exception.showErrorToast(context: Context) {
}

fun ApiException.getTranslatedErrorMessage(context: Context): String {
return when (responseError) {
ResponseError.INVALID_CREDENTIALS -> context.getString(R.string.API_Error_INVALID_CREDENTIALS)
ResponseError.RE_LOGIN_REQUIRED -> context.getString(R.string.API_Error_RE_LOGIN_REQUIRED)
ResponseError.EMAIL_NOT_VERIFIED -> context.getString(R.string.API_Error_EMAIL_NOT_VERIFIED)
ResponseError.TOO_MANY_REQUESTS -> context.getString(R.string.API_Error_TOO_MANY_REQUESTS)
ResponseError.DATABASE_DUPLICATED_KEY -> context.getString(R.string.API_Error_DATABASE_DUPLICATED_KEY)
ResponseError.UNEXPECTED_SERVER_ERROR -> context.getString(R.string.API_Error_UNEXPECTED_SERVER_ERROR)
ResponseError.CIPHER_TOO_LARGE -> context.getString(R.string.API_Error_CIPHER_TOO_LARGE)
return when (getServerError()) {
// ServerError.CipherNotFound -> context.getString(R.string.CipherNotFound)
// ServerError.CollectionNotFound -> context.getString(R.string.CollectionNotFound)
ServerError.Database -> context.getString(R.string.Database)
ServerError.Duplicated -> context.getString(R.string.Duplicated)
ServerError.EmailNotVerified -> context.getString(R.string.EmailNotVerified)
ServerError.InvalidBody -> context.getString(R.string.InvalidBody)
ServerError.InvalidSharedSecret -> context.getString(R.string.InvalidCredentials)
ServerError.InvalidToken -> context.getString(R.string.InvalidToken)
// ServerError.InvalidTwoFactor -> context.getString(R.string.InvalidTwoFactor)
// ServerError.NotFound -> context.getString(R.string.NotFound)
ServerError.RateLimit -> context.getString(R.string.RateLimit)

else -> message
}
}
7 changes: 0 additions & 7 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
<item quantity="many"/>
<item quantity="other">%d ساعة</item>
</plurals>
<string name="API_Error_EMAIL_NOT_VERIFIED">يرجى التحقق من عنوان البريد الإلكتروني الخاص بك</string>
<string name="API_Error_DATABASE_DUPLICATED_KEY">مفتاح مكرر في قاعدة بيانات الخادم</string>
<string name="API_Error_CIPHER_TOO_LARGE">–التشفير كبير جدًا</string>
<plurals name="minutes">
<item quantity="zero"/>
<item quantity="one">%d دقيقة</item>
Expand All @@ -19,18 +16,14 @@
<item quantity="many"/>
<item quantity="other">%d دقيقة</item>
</plurals>
<string name="API_Error_INVALID_CREDENTIALS">بيانات الاعتماد غير صالحة</string>
<string name="BiometricSetup_Subtitle">قم بتشغيل المصادقة البيومترية</string>
<string name="BiometricSetup_Button_Cancel">يلغي</string>
<string name="AddField">إضافة حقل</string>
<string name="BiometricUnlock_Button_UsePassword">استخدم كلمة المرور</string>
<string name="AddServer">أضف الخادم</string>
<string name="API_Error_RE_LOGIN_REQUIRED">مطلوب إعادة تسجيل الدخول</string>
<string name="BiometricSetup_Title">يثبت</string>
<string name="AddNewCipher">إضافة شفرة جديدة</string>
<string name="Add">إضافة</string>
<string name="API_Error_TOO_MANY_REQUESTS">العديد من الطلبات</string>
<string name="API_Error_UNEXPECTED_SERVER_ERROR">خطأ خادم غير متوقع</string>
<string name="DeleteAccount">حذف الحساب</string>
<string name="Error_EncryptionError">خطأ في التشفير/فك التشفير</string>
<string name="CardNumber">رقم البطاقة</string>
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,17 @@
<string name="ConfirmPassword">Passwort bestätigen</string>
<string name="ChangePassword">Passwort ändern</string>
<string name="AddField">Feld hinzufügen</string>
<string name="API_Error_EMAIL_NOT_VERIFIED">Bitte bestätigen Sie Ihre E-Mail-Adresse</string>
<string name="API_Error_DATABASE_DUPLICATED_KEY">Doppelter Schlüssel in der Serverdatenbank</string>
<string name="CardholderName">Karteninhabername</string>
<string name="Add">Hinzufügen</string>
<string name="CipherType_SecureNote">Sicherer Hinweis</string>
<string name="BiometricUnlock_Button_UsePassword">Passwort verwenden</string>
<string name="API_Error_TOO_MANY_REQUESTS">Zu viele Anfragen</string>
<string name="API_Error_CIPHER_TOO_LARGE">Cipher ist zu groß</string>
<string name="CipherType_Card">Kartendaten</string>
<string name="BiometricUnlock_Title">Entsperren</string>
<string name="AddServer">Server hinzufügen</string>
<string name="API_Error_INVALID_CREDENTIALS">Ungültige Anmeldeinformationen</string>
<string name="API_Error_RE_LOGIN_REQUIRED">Erneute Anmeldung erforderlich</string>
<string name="BiometricUnlock_Subtitle">Bitte authentifizieren Sie sich</string>
<string name="ConfirmNewPassword">Neues Passwort bestätigen</string>
<string name="BiometricSetup_Title">Einrichtung</string>
<string name="AddNewCipher">Neue Cipher hinzufügen</string>
<string name="API_Error_UNEXPECTED_SERVER_ERROR">Unerwarteter Serverfehler</string>
<string name="VerificationCode">Verifikationscode (TOTP)</string>
<string name="Error_InvalidURI">URI Adresse ist ungültig</string>
<string name="CardDetails">Kartendetails</string>
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="API_Error_CIPHER_TOO_LARGE">Cipher बहुत बड़ा है</string>
<string name="API_Error_DATABASE_DUPLICATED_KEY">सर्वर डेटाबेस में डुप्लिकेट कुंजी</string>
<string name="API_Error_EMAIL_NOT_VERIFIED">कृपया अपना ई-मेल सत्यापित करें</string>
<string name="API_Error_TOO_MANY_REQUESTS">बहुत सारे अनुरोध</string>
<string name="API_Error_UNEXPECTED_SERVER_ERROR">अनपेक्षित सर्वर त्रुटि</string>
<string name="Add">जोड़ें</string>
<string name="BiometricUnlock_Subtitle">कृपया स्वयं को प्रमाणित करें</string>
<string name="BiometricUnlock_Title">अनलॉक</string>
Expand Down Expand Up @@ -72,14 +67,12 @@
<item quantity="one">%d घंटा</item>
<item quantity="other">%d घंटे</item>
</plurals>
<string name="API_Error_INVALID_CREDENTIALS">अमान्य क्रेडेंशियल</string>
<string name="AddNewCipher">नया cipher जोड़ें</string>
<string name="AuthenticationKey">प्रमाणीकरण URI (TOTP)</string>
<string name="BiometricSetup_Subtitle">बायोमेट्रिक प्रमाणीकरण चालू करें</string>
<string name="BiometricUnlock_Button_UsePassword">पासवर्ड का प्रयोग करें</string>
<string name="Notes">टिप्पणियाँ</string>
<string name="Toast_PleaseVerifyYourEmail">कृपया अपना ई-मेल पता सत्यापित करें</string>
<string name="API_Error_RE_LOGIN_REQUIRED">पुनः लॉगिन आवश्यक है</string>
<string name="AddServer">सर्वर जोड़े</string>
<string name="BiometricSetup_Title">सेटअप</string>
<string name="OldPassword">पुराना पासवर्ड</string>
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/values-nb-rNO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
<item quantity="one">%d minutt</item>
<item quantity="other">%d minutter</item>
</plurals>
<string name="API_Error_CIPHER_TOO_LARGE">For stort chiffer</string>
<string name="API_Error_DATABASE_DUPLICATED_KEY">Duplikatnøkkel i tjenerdatabase</string>
<string name="API_Error_EMAIL_NOT_VERIFIED">Bekreft din e-postadresse</string>
<string name="API_Error_INVALID_CREDENTIALS">Ugydlige identitetsdetaljer</string>
<string name="API_Error_RE_LOGIN_REQUIRED">Du må logge inn igjen</string>
<string name="API_Error_TOO_MANY_REQUESTS">For mange forespørsler</string>
<string name="API_Error_UNEXPECTED_SERVER_ERROR">Uventet tjenerfeil</string>
<string name="Add">Legg til</string>
<string name="AddField">Legg til felt</string>
<string name="AddNewCipher">Legg til nytt chiffer</string>
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
<item quantity="many">%d godzin</item>
<item quantity="other">%d godzin</item>
</plurals>
<string name="API_Error_CIPHER_TOO_LARGE">Szyft jest zbyt długi</string>
<string name="API_Error_DATABASE_DUPLICATED_KEY">Zduplikowany klucz w bazie danych serwera</string>
<string name="API_Error_EMAIL_NOT_VERIFIED">Zweryfikuj swój adres e-mail</string>
<string name="API_Error_INVALID_CREDENTIALS">Nieprawidłowe dane uwierzytelniające</string>
<string name="API_Error_RE_LOGIN_REQUIRED">Wymagane jest ponowne zalogowanie</string>
<string name="API_Error_TOO_MANY_REQUESTS">Zbyt wiele żądań</string>
<string name="API_Error_UNEXPECTED_SERVER_ERROR">Nieoczekiwany błąd serwera</string>
<string name="Add">Dodaj</string>
<string name="AddField">Dodaj pole</string>
<string name="AddNewCipher">Dodaj nowy szyft</string>
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
<item quantity="one">%d hour</item>
<item quantity="other">%d hours</item>
</plurals>
<string name="API_Error_CIPHER_TOO_LARGE">Cipher is too large</string>
<string name="API_Error_DATABASE_DUPLICATED_KEY">Duplicated key in server database</string>
<string name="API_Error_EMAIL_NOT_VERIFIED">Please verify your e-mail address</string>
<string name="API_Error_INVALID_CREDENTIALS">Invalid credentials</string>
<string name="API_Error_RE_LOGIN_REQUIRED">Re-login required</string>
<string name="API_Error_TOO_MANY_REQUESTS">Too many requests</string>
<string name="API_Error_UNEXPECTED_SERVER_ERROR">Unexpected server error</string>
<string name="Add">Add</string>
<string name="AddField">Add field</string>
<string name="AddNewCipher">Add new cipher</string>
Expand Down Expand Up @@ -110,4 +103,14 @@
<string name="BiometricKeyInvalidated">Biometric key has been invalidated by Android</string>
<string name="NewEmail">New e-mail address</string>
<string name="ChangeEmail">Change e-mail address</string>
<string name="CipherNotFound">Cipher not found</string>
<string name="CollectionNotFound">Collection not found</string>
<string name="Database">Unknown server database error</string>
<string name="Duplicated">Duplicated</string>
<string name="EmailNotVerified">Please verify your e-mail address</string>
<string name="InvalidBody">Invalid API request</string>
<string name="InvalidCredentials">Invalid credentials</string>
<string name="InvalidToken">Invalid login token</string>
<string name="RateLimit">Too many requests</string>
<string name="SendEmail">Internal server error - Failed to send email</string>
</resources>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ hilt = "1.2.0"
coil-compose = "2.6.0"
google-material = "1.11.0"
kotlinx-coroutines = "1.8.0"
librepass-client = "1.4.1"
librepass-client = "1.5.0"
medzik-libcrypto = "1.2.0"
process-phoenix = "2.1.2"

Expand Down

0 comments on commit bf6ed57

Please sign in to comment.