Skip to content

Commit

Permalink
fix base64 decoder to use urlsafedecoder
Browse files Browse the repository at this point in the history
Signed-off-by: mineme0110 <[email protected]>
  • Loading branch information
mineme0110 committed Jun 11, 2024
1 parent 409a8cc commit d6eb1ae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
didResolverService <- ZIO.service[JwtDidResolver]
credentialsClaimsValidationResult <- p.attachments.head.data match {
case Base64(data) =>
val base64Decoded = new String(java.util.Base64.getDecoder.decode(data))
val base64Decoded = new String(java.util.Base64.getUrlDecoder.decode(data))
val maybePresentationOptions: Either[PresentationError, Option[
org.hyperledger.identus.pollux.core.model.presentation.Options
]] =
Expand Down Expand Up @@ -836,7 +836,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
didResolverService <- ZIO.service[JwtDidResolver]
credentialsClaimsValidationResult <- p.attachments.head.data match {
case Base64(data) =>
val base64Decoded = new String(java.util.Base64.getDecoder.decode(data))
val base64Decoded = new String(java.util.Base64.getUrlDecoder.decode(data))
val verifiedClaims = for {
presentation <- ZIO.succeed(PresentationCompact.unsafeFromCompact(base64Decoded))
iss <- ZIO.fromEither(presentation.iss)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object PresentationStatus {
case Some(p) =>
p.attachments.head.data match {
case Base64(data) =>
val base64Decoded = new String(java.util.Base64.getDecoder.decode(data))
val base64Decoded = new String(java.util.Base64.getUrlDecoder.decode(data))
Seq(base64Decoded)
case any => ???
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ private class CredentialServiceImpl(
.find(_.format.contains(IssueCredentialOfferFormat.Anoncred.name))
.map(_.data)
.flatMap {
case Base64(value) => Some(new String(java.util.Base64.getDecoder.decode(value)))
case Base64(value) => Some(new String(java.util.Base64.getUrlDecoder.decode(value)))
case _ => None
}
)
Expand Down Expand Up @@ -1548,7 +1548,7 @@ private class CredentialServiceImpl(
jwt <- attachmentDescriptor.data match
case Base64(b64) =>
ZIO.succeed {
val base64Decoded = new String(java.util.Base64.getDecoder.decode(b64))
val base64Decoded = new String(java.util.Base64.getUrlDecoder.decode(b64))
JWT(base64Decoded)
}
case _ => ZIO.fail(UnexpectedError(s"Attachment doesn't contain Base64Data: ${record.id}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,12 @@ private class PresentationServiceImpl(
PresentationError.PresentationDecodingError,
Seq[CredentialCompact]
] = issuedCredentials.map { signedCredential =>
println("******signedCredential***********")
println(signedCredential)
println("*******signedCredential**********")
decode[org.hyperledger.identus.mercury.model.Base64](signedCredential)
.flatMap(x =>
Right(CredentialCompact.unsafeFromCompact(new String(java.util.Base64.getDecoder.decode(x.base64))))
Right(CredentialCompact.unsafeFromCompact(new String(java.util.Base64.getUrlDecoder.decode(x.base64))))
)
.left
.map(err => PresentationDecodingError(s"JsonData decoding error: $err"))
Expand All @@ -525,6 +528,9 @@ private class PresentationServiceImpl(
import io.circe.parser.decode
import io.circe.syntax._
import java.util.Base64
println("*****************")
println(requestPresentation.attachments.head)
println("*****************")

val result: Either[PresentationDecodingError, SDJwtPresentation] =
requestPresentation.attachments.headOption
Expand Down Expand Up @@ -574,7 +580,7 @@ private class PresentationServiceImpl(
] =
issuedCredentials.map { signedCredential =>
decode[org.hyperledger.identus.mercury.model.Base64](signedCredential)
.flatMap(x => Right(new String(java.util.Base64.getDecoder.decode(x.base64))))
.flatMap(x => Right(new String(java.util.Base64.getUrlDecoder.decode(x.base64))))
.flatMap(x => Right(JwtVerifiableCredentialPayload(JWT(x))))
.left
.map(err => PresentationDecodingError(s"JsonData decoding error: $err"))
Expand Down

0 comments on commit d6eb1ae

Please sign in to comment.