Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import androidx.annotation.NonNull;

import com.auth0.android.guardian.sdk.networking.RequestFactory;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.RSAPublicKey;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -84,11 +87,17 @@ private static String createProofOfPossessionAssertion(HttpUrl url, PrivateKey p
claims.put("jti", UUID.randomUUID().toString());
claims.put("iat", currentTime);

Algorithm alg = Algorithm.RSA256(null, (RSAPrivateKey) privateKey);
return JWT.create()
.withHeader(headers)
.withPayload(claims)
.sign(alg);
try {
Gson gson = new GsonBuilder().create();
String headerAndPayload = base64UrlSafeEncode(gson.toJson(headers).getBytes())
+ "." + base64UrlSafeEncode(gson.toJson(claims).getBytes());
Signature signer = Signature.getInstance("SHA256withRSA");
signer.initSign(privateKey);
signer.update(headerAndPayload.getBytes());
return headerAndPayload + "." + base64UrlSafeEncode(signer.sign());
} catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException exception) {
throw new GuardianException("Unable to generate the signed DPoP assertion", exception);
}
}

/**
Expand Down