Skip to content

Commit

Permalink
fix(ATL-4978): fix OOB connection (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamada147 authored Jun 23, 2023
1 parent 964e3ac commit cd18709
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.iohk.atala.prism.walletsdk.logger

import io.iohk.atala.prism.apollo.hashing.SHA256
import io.iohk.atala.prism.apollo.uuid.UUID
import org.lighthousegames.logging.logging
import java.security.MessageDigest

private const val METADATA_PRIVACY_STR = "------"
private val hashingLog = UUID.randomUUID4().toString()
Expand Down Expand Up @@ -122,7 +122,7 @@ sealed class Metadata {
}

private fun sha256Masked(input: String): String {
val sha256 = MessageDigest.getInstance("SHA-256").digest((hashingLog + input).toByteArray())
val sha256 = SHA256().digest((hashingLog + input).toByteArray())
return sha256.joinToString("") { "%02x".format(it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ class MercuryImpl(
arrayOf(KeyValue(HttpHeaders.ContentType, Typ.Encrypted.typ)),
message
)

if (result.status >= 400) {
logger.error(
"Calling api result in ${result.status} error",
arrayOf(
Metadata.PublicMetadata("statusCode", "${result.status}"),
Metadata.PublicMetadata("uri", service.serviceEndpoint.uri),
Metadata.PrivateMetadata("body", message)
)
)
}

return result.jsonString.toByteArray()
}

Expand All @@ -202,12 +214,27 @@ class MercuryImpl(
throw MercuryError.NoValidServiceFoundError()
}

val result = api.request(HttpMethod.Post.value, uri, emptyArray(), emptyArray(), message)
val result = api.request(
HttpMethod.Post.value,
uri,
emptyArray(),
emptyArray(),
message
)
if (result.status >= 400) {
logger.error(
"Calling api result in ${result.status} error",
arrayOf(
Metadata.PublicMetadata("statusCode", "${result.status}"),
Metadata.PublicMetadata("uri", uri),
Metadata.PrivateMetadata("body", message)
)
)
}
return result.jsonString.toByteArray()
}

private fun getMediatorDID(service: DIDDocument.Service?): DID? {
// TODO: Handle when service endpoint uri is HTTP or HTTPS
return service?.serviceEndpoint?.uri?.let { uri ->
if (isDID(uri)) {
castor.parseDID(uri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ class PrismAgent {
private val prismAgentScope: CoroutineScope = CoroutineScope(Dispatchers.Default)
private val api: Api
private var connectionManager: ConnectionManager
private lateinit var logger: PrismLogger
private var logger: PrismLogger

@JvmOverloads
constructor(
apollo: Apollo,
castor: Castor,
Expand Down Expand Up @@ -181,6 +182,7 @@ class PrismAgent {
}
}
)
this.logger = logger
// Pairing will be removed in the future
this.connectionManager =
ConnectionManager(mercury, castor, pluto, mediatorHandler, mutableListOf())
Expand Down Expand Up @@ -323,7 +325,7 @@ class PrismAgent {

var tmpServices = services
if (updateMediator) {
tmpServices.plus(
tmpServices = tmpServices.plus(
DIDDocument.Service(
id = DIDCOMM1,
type = arrayOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package io.iohk.atala.prism.walletsdk.prismagent.protocols.issueCredential

import io.iohk.atala.prism.walletsdk.prismagent.protocols.ProtocolType
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* https://github.com/hyperledger/aries-rfcs/tree/main/features/0453-issue-credential-v2#preview-credential
*/
@Serializable
data class CredentialPreview(val attributes: Array<Attribute>) {
data class CredentialPreview
@OptIn(ExperimentalSerializationApi::class)
@JvmOverloads
constructor(
@SerialName("schema_id")
@EncodeDefault
val schemaId: String? = null,
val attributes: Array<Attribute>
) {

@Serializable
data class Attribute(
Expand Down
3 changes: 1 addition & 2 deletions sampleapp/src/main/java/io/iohk/atala/prism/sampleapp/Sdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ class Sdk() {
// Javi's mediatorDID = DID("did:peer:2.Ez6LSiekedip45fb5uYRZ9DV1qVvf3rr6GpvTGLhw3nKJ9E7X.Vz6MksZCnX3hQVPP4wWDGe1Dzq5LCk5BnGUnPmq3YCfrPpfuk.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLmpyaWJvLmtpd2kiLCJhIjpbImRpZGNvbW0vdjIiXX0"),
// RootsID mediatorDID = DID("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0")
handler = BasicMediatorHandler(
mediatorDID = DID("did:peer:2.Ez6LSiekedip45fb5uYRZ9DV1qVvf3rr6GpvTGLhw3nKJ9E7X.Vz6MksZCnX3hQVPP4wWDGe1Dzq5LCk5BnGUnPmq3YCfrPpfuk.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLmpyaWJvLmtpd2kiLCJhIjpbImRpZGNvbW0vdjIiXX0"),
// mediatorDID = DID("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0"),
mediatorDID = DID("did:peer:2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0"),
mercury = mercury!!,
store = BasicMediatorHandler.PlutoMediatorRepositoryImpl(pluto!!)
)
Expand Down

0 comments on commit cd18709

Please sign in to comment.