mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
make things work
This commit is contained in:
parent
8c22514b73
commit
ef2380da76
@ -46,10 +46,10 @@ object KeyPairUtilities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getUserED25519KeyPair(context: Context): KeyPair? {
|
fun getUserED25519KeyPair(context: Context): KeyPair? {
|
||||||
val hexEncodedED25519PublicKey = IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_PUBLIC_KEY) ?: return null
|
val base64EncodedED25519PublicKey = IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_PUBLIC_KEY) ?: return null
|
||||||
val hexEncodedED25519SecretKey = IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_SECRET_KEY) ?: return null
|
val base64EncodedED25519SecretKey = IdentityKeyUtil.retrieve(context, IdentityKeyUtil.ED25519_SECRET_KEY) ?: return null
|
||||||
val ed25519PublicKey = Key.fromBase64String(hexEncodedED25519PublicKey)
|
val ed25519PublicKey = Key.fromBytes(Base64.decode(base64EncodedED25519PublicKey))
|
||||||
val ed25519SecretKey = Key.fromBase64String(hexEncodedED25519SecretKey)
|
val ed25519SecretKey = Key.fromBytes(Base64.decode(base64EncodedED25519SecretKey))
|
||||||
return KeyPair(ed25519PublicKey, ed25519SecretKey)
|
return KeyPair(ed25519PublicKey, ed25519SecretKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,11 +23,11 @@ private typealias Path = List<Snode>
|
|||||||
/**
|
/**
|
||||||
* See the "Onion Requests" section of [The Session Whitepaper](https://arxiv.org/pdf/2002.04609.pdf) for more information.
|
* See the "Onion Requests" section of [The Session Whitepaper](https://arxiv.org/pdf/2002.04609.pdf) for more information.
|
||||||
*/
|
*/
|
||||||
public object OnionRequestAPI {
|
object OnionRequestAPI {
|
||||||
private val pathFailureCount = mutableMapOf<Path, Int>()
|
private val pathFailureCount = mutableMapOf<Path, Int>()
|
||||||
private val snodeFailureCount = mutableMapOf<Snode, Int>()
|
private val snodeFailureCount = mutableMapOf<Snode, Int>()
|
||||||
public var guardSnodes = setOf<Snode>()
|
var guardSnodes = setOf<Snode>()
|
||||||
public var paths: List<Path> // Not a set to ensure we consistently show the same path to the user
|
var paths: List<Path> // Not a set to ensure we consistently show the same path to the user
|
||||||
get() = SnodeAPI.database.getOnionRequestPaths()
|
get() = SnodeAPI.database.getOnionRequestPaths()
|
||||||
set(newValue) {
|
set(newValue) {
|
||||||
if (newValue.isEmpty()) {
|
if (newValue.isEmpty()) {
|
||||||
@ -41,19 +41,19 @@ public object OnionRequestAPI {
|
|||||||
/**
|
/**
|
||||||
* The number of snodes (including the guard snode) in a path.
|
* The number of snodes (including the guard snode) in a path.
|
||||||
*/
|
*/
|
||||||
private val pathSize = 3
|
private const val pathSize = 3
|
||||||
/**
|
/**
|
||||||
* The number of times a path can fail before it's replaced.
|
* The number of times a path can fail before it's replaced.
|
||||||
*/
|
*/
|
||||||
private val pathFailureThreshold = 2
|
private const val pathFailureThreshold = 1
|
||||||
/**
|
/**
|
||||||
* The number of times a snode can fail before it's replaced.
|
* The number of times a snode can fail before it's replaced.
|
||||||
*/
|
*/
|
||||||
private val snodeFailureThreshold = 2
|
private const val snodeFailureThreshold = 1
|
||||||
/**
|
/**
|
||||||
* The number of paths to maintain.
|
* The number of paths to maintain.
|
||||||
*/
|
*/
|
||||||
public val targetPathCount = 2 // A main path and a backup path for the case where the target snode is in the main path
|
const val targetPathCount = 2 // A main path and a backup path for the case where the target snode is in the main path
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of guard snodes required to maintain `targetPathCount` paths.
|
* The number of guard snodes required to maintain `targetPathCount` paths.
|
||||||
@ -67,9 +67,9 @@ public object OnionRequestAPI {
|
|||||||
class InsufficientSnodesException : Exception("Couldn't find enough snodes to build a path.")
|
class InsufficientSnodesException : Exception("Couldn't find enough snodes to build a path.")
|
||||||
|
|
||||||
private data class OnionBuildingResult(
|
private data class OnionBuildingResult(
|
||||||
internal val guardSnode: Snode,
|
val guardSnode: Snode,
|
||||||
internal val finalEncryptionResult: EncryptionResult,
|
val finalEncryptionResult: EncryptionResult,
|
||||||
internal val destinationSymmetricKey: ByteArray
|
val destinationSymmetricKey: ByteArray
|
||||||
)
|
)
|
||||||
|
|
||||||
internal sealed class Destination {
|
internal sealed class Destination {
|
||||||
@ -406,9 +406,11 @@ public object OnionRequestAPI {
|
|||||||
} else {
|
} else {
|
||||||
handleUnspecificError()
|
handleUnspecificError()
|
||||||
}
|
}
|
||||||
|
} else if (destination is Destination.Server && exception.statusCode == 400) {
|
||||||
|
Log.d("Loki","Destination server returned ${exception.statusCode}")
|
||||||
} else if (message == "Loki Server error") {
|
} else if (message == "Loki Server error") {
|
||||||
// Do nothing
|
Log.d("Loki", "message was $message")
|
||||||
} else {
|
} else { // Only drop snode/path if not receiving above two exception cases
|
||||||
handleUnspecificError()
|
handleUnspecificError()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,7 +440,7 @@ public object OnionRequestAPI {
|
|||||||
*
|
*
|
||||||
* `publicKey` is the hex encoded public key of the user the call is associated with. This is needed for swarm cache maintenance.
|
* `publicKey` is the hex encoded public key of the user the call is associated with. This is needed for swarm cache maintenance.
|
||||||
*/
|
*/
|
||||||
public fun sendOnionRequest(request: Request, server: String, x25519PublicKey: String, target: String = "/loki/v3/lsrpc", isJSONRequired: Boolean = true): Promise<Map<*, *>, Exception> {
|
fun sendOnionRequest(request: Request, server: String, x25519PublicKey: String, target: String = "/loki/v3/lsrpc", isJSONRequired: Boolean = true): Promise<Map<*, *>, Exception> {
|
||||||
val headers = request.getHeadersForOnionRequest()
|
val headers = request.getHeadersForOnionRequest()
|
||||||
val url = request.url()
|
val url = request.url()
|
||||||
val urlAsString = url.toString()
|
val urlAsString = url.toString()
|
||||||
|
@ -19,21 +19,7 @@ class LokiServiceCipher(localAddress: SignalServiceAddress, private val signalPr
|
|||||||
private val userPrivateKey get() = signalProtocolStore.identityKeyPair.privateKey.serialize()
|
private val userPrivateKey get() = signalProtocolStore.identityKeyPair.privateKey.serialize()
|
||||||
|
|
||||||
override fun decrypt(envelope: SignalServiceEnvelope, ciphertext: ByteArray): Plaintext {
|
override fun decrypt(envelope: SignalServiceEnvelope, ciphertext: ByteArray): Plaintext {
|
||||||
// return if (envelope.isFallbackMessage) decryptFallbackMessage(envelope, ciphertext) else super.decrypt(envelope, ciphertext)
|
return if (envelope.isFallbackMessage) decryptFallbackMessage(envelope, ciphertext) else super.decrypt(envelope, ciphertext)
|
||||||
|
|
||||||
return when {
|
|
||||||
envelope.isUnidentifiedSender -> {
|
|
||||||
//AC: Messages come unencrypted (for refactoring time being).
|
|
||||||
val transportDetails = PushTransportDetails(FallbackSessionCipher.sessionVersion)
|
|
||||||
val unpaddedMessageBody = transportDetails.getStrippedPaddingMessageBody(ciphertext)
|
|
||||||
val metadata = Metadata(envelope.source, envelope.sourceDevice, envelope.timestamp, false)
|
|
||||||
return Plaintext(metadata, unpaddedMessageBody)
|
|
||||||
}
|
|
||||||
envelope.isFallbackMessage ->
|
|
||||||
decryptFallbackMessage(envelope, ciphertext)
|
|
||||||
else ->
|
|
||||||
super.decrypt(envelope, ciphertext)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decryptFallbackMessage(envelope: SignalServiceEnvelope, ciphertext: ByteArray): Plaintext {
|
private fun decryptFallbackMessage(envelope: SignalServiceEnvelope, ciphertext: ByteArray): Plaintext {
|
||||||
|
Loading…
Reference in New Issue
Block a user