Commit a3b1b488 authored by Josh Ji's avatar Josh Ji

support for ask/identity v2

parent b4794503
Pipeline #5344 failed with stage
...@@ -40,6 +40,6 @@ public class GetAssertion { ...@@ -40,6 +40,6 @@ public class GetAssertion {
public ResponseEntity<Response> finishMakeCredential(@RequestParam("data") String data){ public ResponseEntity<Response> finishMakeCredential(@RequestParam("data") String data){
logger.info("data : {}", data); logger.info("data : {}", data);
logger.info("Finish Get Assertion"); logger.info("Finish Get Assertion");
return ResponseEntity.ok(new Response(true, "Login Successfully")); return ResponseEntity.ok(new Response(true, "Login Successfully", ""));
} }
} }
...@@ -119,8 +119,12 @@ public class MakeCredential { ...@@ -119,8 +119,12 @@ public class MakeCredential {
identityFromIDP = "JoshJi"; identityFromIDP = "JoshJi";
}else { }else {
extensions = extractExtensions(attestationObjectBytes); extensions = extractExtensions(attestationObjectBytes);
identityFromIDP = askIDP(extensions[0], extensions[1]); if(extensions.length==1){
logger.info("identityFromIDP : {}", identityFromIDP); identityFromIDP=extensions[0];
}else{
identityFromIDP = askIDP(extensions);
logger.info("identityFromIDP : {}", identityFromIDP);
}
} }
RegistrationRequest registrationRequest = new RegistrationRequest(attestationObjectBytes, clientDataJSONBytes); RegistrationRequest registrationRequest = new RegistrationRequest(attestationObjectBytes, clientDataJSONBytes);
...@@ -140,7 +144,7 @@ public class MakeCredential { ...@@ -140,7 +144,7 @@ public class MakeCredential {
user.getUserName(), user.getUserName(),
rawId)); rawId));
return ResponseEntity.ok().body(new Response(true, "Successfully created credential@@"+identityFromIDP)); return ResponseEntity.ok().body(new Response(true, "Successfully created credential", identityFromIDP));
} }
private String[] extractExtensions(byte[] attestationObjectBytes){ private String[] extractExtensions(byte[] attestationObjectBytes){
...@@ -159,31 +163,52 @@ public class MakeCredential { ...@@ -159,31 +163,52 @@ public class MakeCredential {
for (DataItem item : extensions) for (DataItem item : extensions)
logger.info("extensions : {}", item); logger.info("extensions : {}", item);
byte[][] extensionSendsOut = new byte[2][]; String[] params = new String[extensions.size()];
extensionSendsOut[0] = ((ByteString) extensions.get(0)).getBytes();
extensionSendsOut[1] = ((ByteString) extensions.get(1)).getBytes(); for (int i = 0; i < extensions.size(); i++) {
params[i] = HexUtil.encodeToString(((ByteString)extensions.get(i)).getBytes());
logger.info(params[i]);
}
// byte[][] extensionSendsOut = new byte[extensions.size()][];
// extensionSendsOut[0] = ((ByteString) extensions.get(0)).getBytes();
// extensionSendsOut[1] = ((ByteString) extensions.get(1)).getBytes();
//
// hmac = HexUtil.encodeToString(extensionSendsOut[0]); // param 1 : hmac
// Cx = HexUtil.encodeToString(extensionSendsOut[1]); // param 2 : Cx
hmac = HexUtil.encodeToString(extensionSendsOut[0]); // param 1 : hmac return params;
Cx = HexUtil.encodeToString(extensionSendsOut[1]); // param 2 : Cx
} catch (CborException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return new String[]{"PII_NOT_SUPPORT"};
} }
return new String[]{hmac, Cx};
} }
@Autowired @Autowired
Environment env; Environment env;
private String askIDP(String hmac, String Cx){ private String askIDP(String[] param){
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
String idp_addr = env.getProperty("server.idp.url"); String idp_addr = env.getProperty("server.idp.url");
String uri = idp_addr + "api/idp/askIdentity";
HashMap<String, String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
String base64hmac = Base64Util.encodeToString(HexUtil.decode(hmac)); String uri = idp_addr;
String base64Cx = Base64Util.encodeToString(HexUtil.decode(Cx)); switch (param.length){
map.put("HMAC_base64", base64hmac); case 2:{
map.put("Cx_base64", base64Cx); uri += "api/idp/askIdentity";
map.put("HMAC_base64", Base64Util.encodeToString(HexUtil.decode(param[0])));
map.put("Cx_base64", Base64Util.encodeToString(HexUtil.decode(param[1])));
break;
}
case 4:{
uri += "api/idp/askIdentityV2";
map.put("nonce_base64", Base64Util.encodeToString(HexUtil.decode(param[0])));
map.put("idHash_base64", Base64Util.encodeToString(HexUtil.decode(param[1])));
map.put("cE_base64", Base64Util.encodeToString(HexUtil.decode(param[2])));
map.put("HMAC_base64", Base64Util.encodeToString(HexUtil.decode(param[3])));
break;
}
}
return restTemplate.postForObject(uri, map, String.class); return restTemplate.postForObject(uri, map, String.class);
} }
} }
...@@ -5,10 +5,12 @@ package com.example.rpserver.model; ...@@ -5,10 +5,12 @@ package com.example.rpserver.model;
public class Response { public class Response {
private boolean success; private boolean success;
private String message; private String message;
private String identity;
public Response(boolean success, String message){ public Response(boolean success, String message, String identity){
this.success = success; this.success = success;
this.message = message; this.message = message;
this.identity=identity;
} }
public boolean isSuccess() { public boolean isSuccess() {
...@@ -26,4 +28,11 @@ public class Response { ...@@ -26,4 +28,11 @@ public class Response {
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
public String getIdentity() {
return identity;
}
public void setIdentity(String identity) {
this.identity = identity;
}
} }
...@@ -445,9 +445,9 @@ function makeCredential(advancedOptions) { ...@@ -445,9 +445,9 @@ function makeCredential(advancedOptions) {
console.log(parameters); console.log(parameters);
if (parameters && parameters.success) { if (parameters && parameters.success) {
const msg = parameters.message.split("@@")[0] const msg = parameters.message
showSuccessMsg(msg); showSuccessMsg(msg);
document.forms['profile']['id_from_idp'].value=parameters.message.split("@@")[1] document.forms['profile']['id_from_idp'].value=parameters.identity
document.forms['profile'].submit() document.forms['profile'].submit()
fetchCredentials(); fetchCredentials();
} else { } else {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<!--navbar--> <!--navbar-->
<nav class="navbar bg-light navbar-light"> <nav class="navbar bg-light navbar-light">
<div class="container-fluid"> <div class="container-fluid">
<a href="#" class="navbar-brand"> <a href="/" class="navbar-brand">
<!-- <img src="img/logo1.png" alt="Taiwan Tech Logo" class="navbar-brand" style="height: 40pt">--> <!-- <img src="img/logo1.png" alt="Taiwan Tech Logo" class="navbar-brand" style="height: 40pt">-->
FIDO DEMO FIDO DEMO
</a> </a>
...@@ -86,7 +86,13 @@ ...@@ -86,7 +86,13 @@
Welcome! Welcome!
</h2> </h2>
<hr> <hr>
<img src="img/avatar1.jpg" alt="Avatar1"> <img src="img/avatar1.jpg" alt="Avatar1" id="avatar">
<input type="hidden" id="id_from_idp" th:value="${id_from_idp}">
<script>
if(document.getElementById("id_from_idp").value==="PII_NOT_SUPPORT"){
document.getElementById("avatar").src="img/question_mark.jpg"
}
</script>
<h3 class="p-3">Name: </h3> <h3 class="p-3">Name: </h3>
<h3 class="p-3" th:text="${id_from_idp}">Josh Ji</h3> <h3 class="p-3" th:text="${id_from_idp}">Josh Ji</h3>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment