Skip to content

Commit

Permalink
Merge pull request #41 from hegocre/enhancement/debug-logging
Browse files Browse the repository at this point in the history
Add debug logging
  • Loading branch information
hegocre authored Nov 24, 2023
2 parents b42fe36 + 1c9eef0 commit e396307
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 33 deletions.
53 changes: 45 additions & 8 deletions app/src/main/java/com/hegocre/nextcloudpasswords/api/FoldersApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hegocre.nextcloudpasswords.api

import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.data.folder.DeletedFolder
import com.hegocre.nextcloudpasswords.data.folder.Folder
import com.hegocre.nextcloudpasswords.data.folder.NewFolder
Expand Down Expand Up @@ -56,10 +57,19 @@ class FoldersApi private constructor(private var server: Server) {
Result.Success(Json.decodeFromString(body))
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -101,10 +111,19 @@ class FoldersApi private constructor(private var server: Server) {
Result.Success(Unit)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -146,10 +165,19 @@ class FoldersApi private constructor(private var server: Server) {
Result.Success(Unit)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -190,10 +218,19 @@ class FoldersApi private constructor(private var server: Server) {
Result.Success(Unit)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hegocre.nextcloudpasswords.api

import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.data.password.DeletedPassword
import com.hegocre.nextcloudpasswords.data.password.NewPassword
import com.hegocre.nextcloudpasswords.data.password.Password
Expand Down Expand Up @@ -57,10 +58,19 @@ class PasswordsApi private constructor(private var server: Server) {
Result.Success(Json.decodeFromString(body))
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -102,10 +112,19 @@ class PasswordsApi private constructor(private var server: Server) {
Result.Success(Unit)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -147,10 +166,19 @@ class PasswordsApi private constructor(private var server: Server) {
Result.Success(Unit)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -191,10 +219,19 @@ class PasswordsApi private constructor(private var server: Server) {
Result.Success(Unit)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/hegocre/nextcloudpasswords/api/ServiceApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hegocre.nextcloudpasswords.api

import android.util.Log
import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.data.password.GeneratedPassword
import com.hegocre.nextcloudpasswords.utils.Error
import com.hegocre.nextcloudpasswords.utils.OkHttpRequest
Expand Down Expand Up @@ -52,10 +53,19 @@ class ServiceApi private constructor(private val server: Server) {
Result.Success(Json.decodeFromString<GeneratedPassword>(body).password)
}
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down
33 changes: 29 additions & 4 deletions app/src/main/java/com/hegocre/nextcloudpasswords/api/SessionApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hegocre.nextcloudpasswords.api

import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.api.encryption.PWDv1Challenge
import com.hegocre.nextcloudpasswords.api.exceptions.ClientDeauthorizedException
import com.hegocre.nextcloudpasswords.api.exceptions.PWDv1ChallengeMasterKeyInvalidException
Expand Down Expand Up @@ -37,9 +38,15 @@ class SessionApi private constructor(private var server: Server) {
password = server.password
)
}
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
return Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
return Result.Error(0)
}

Expand All @@ -58,6 +65,9 @@ class SessionApi private constructor(private var server: Server) {
} else Result.Error(Error.API_BAD_RESPONSE)

} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
}
}
Expand Down Expand Up @@ -110,10 +120,19 @@ class SessionApi private constructor(private var server: Server) {

Result.Success(Pair(xSessionCode, body))
} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}
}
Expand Down Expand Up @@ -143,6 +162,9 @@ class SessionApi private constructor(private var server: Server) {

code == 200
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
false
}
}
Expand Down Expand Up @@ -172,6 +194,9 @@ class SessionApi private constructor(private var server: Server) {

code == 200
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hegocre.nextcloudpasswords.api

import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.data.serversettings.ServerSettings
import com.hegocre.nextcloudpasswords.utils.Error
import com.hegocre.nextcloudpasswords.utils.OkHttpRequest
Expand Down Expand Up @@ -43,10 +44,19 @@ class SettingsApi private constructor(private val server: Server) {
}

} catch (e: SocketTimeoutException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.API_TIMEOUT)
} catch (ex: SSLHandshakeException) {
} catch (e: SSLHandshakeException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.SSL_HANDSHAKE_EXCEPTION)
} catch (ex: Exception) {
} catch (e: Exception) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
Result.Error(Error.UNKNOWN)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hegocre.nextcloudpasswords.api.encryption
import com.goterl.lazysodium.interfaces.Box
import com.goterl.lazysodium.interfaces.PwHash
import com.goterl.lazysodium.interfaces.SecretBox
import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.api.exceptions.SodiumDecryptionException
import com.hegocre.nextcloudpasswords.utils.LazySodiumUtils
import okio.internal.commonToUtf8String
Expand Down Expand Up @@ -36,7 +37,10 @@ data class CSEv1Keychain(
val encryptedJson = try {
val keysObj = obj.getJSONObject("keys")
keysObj.getString("CSEv1r1")
} catch (ex: JSONException) {
} catch (e: JSONException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
return ""
}

Expand Down Expand Up @@ -87,7 +91,10 @@ data class CSEv1Keychain(

val keyObject = try {
obj.getJSONObject("keys")
} catch (ex: JSONException) {
} catch (e: JSONException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
JSONObject()
}

Expand All @@ -101,7 +108,10 @@ data class CSEv1Keychain(

val current = try {
obj.getString("current")
} catch (ex: JSONException) {
} catch (e: JSONException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
""
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.hegocre.nextcloudpasswords.api.encryption
import com.goterl.lazysodium.interfaces.Box
import com.goterl.lazysodium.interfaces.GenericHash
import com.goterl.lazysodium.interfaces.PwHash
import com.hegocre.nextcloudpasswords.BuildConfig
import com.hegocre.nextcloudpasswords.api.exceptions.PWDv1ChallengeMasterKeyNeededException
import com.hegocre.nextcloudpasswords.api.exceptions.PWDv1ChallengePasswordException
import com.hegocre.nextcloudpasswords.api.exceptions.SodiumDecryptionException
Expand Down Expand Up @@ -103,7 +104,10 @@ data class PWDv1Challenge(
val saltsArray = try {
val challengeObj = obj.getJSONObject("challenge")
challengeObj.getJSONArray("salts")
} catch (ex: JSONException) {
} catch (e: JSONException) {
if (BuildConfig.DEBUG) {
e.printStackTrace()
}
JSONArray()
}

Expand Down
Loading

0 comments on commit e396307

Please sign in to comment.