This repository was archived by the owner on Apr 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Migration from irma_api_server to irmago server #1
Open
rolandgroen
wants to merge
1
commit into
privacybydesign:master
Choose a base branch
from
EdiaEducationTechnology:irmago-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * This page renders the IRMA JWT validation request | ||
| * | ||
| * @author Olav Morken, UNINETT AS. | ||
| * @package SimpleSAMLphp | ||
| **/ | ||
|
|
||
| use \Firebase\JWT\JWT; | ||
|
|
||
|
|
||
| function get_jwt_key($source) { | ||
| $filename = \SimpleSAML\Utils\Config::getCertPath($source->jwt_privatekeyfile); | ||
| $pk = openssl_pkey_get_private("file://$filename"); | ||
| if ($pk === false) | ||
| throw new Exception("Failed to load signing key"); | ||
| return $pk; | ||
| } | ||
|
|
||
| function get_jwt($source) { | ||
| $sprequest = [ | ||
| "sub" => "verification_request", | ||
| "iss" => $source->issuer_id, | ||
| "iat" => time(), | ||
| "sprequest" => [ | ||
| "validity" => 60, | ||
| "request" => [ | ||
| "content" => $source->requested_attributes | ||
| ] | ||
| ] | ||
| ]; | ||
| return JWT::encode($sprequest, get_jwt_key($source), "RS256", $source->issuer_id); | ||
| } | ||
|
|
||
| if (!array_key_exists('AuthState', $_REQUEST)) { | ||
| throw new SimpleSAML_Error_BadRequest('Missing AuthState parameter.'); | ||
| } | ||
| $authStateId = $_REQUEST['AuthState']; | ||
|
|
||
| $state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_authirma_Auth_Source_IRMA::STAGEID); | ||
| assert('array_key_exists(sspmod_authirma_Auth_Source_IRMA::AUTHID, $state)'); | ||
| $source = SimpleSAML_Auth_Source::getById($state[sspmod_authirma_Auth_Source_IRMA::AUTHID]); | ||
| if ($source === NULL) { | ||
| throw new Exception('Could not find authentication source with id ' . $state[sspmod_authirma_Auth_Source_IRMA::AUTHID]); | ||
| } | ||
|
|
||
| $verification_jwt = get_jwt($source); | ||
| $irma_api_server = $source->irma_api_server; | ||
| $url = $source->irma_api_server . "/session"; | ||
| // use key 'http' even if you send the request to https://... | ||
| $options = array( | ||
| 'http' => array( | ||
| 'header' => "Content-type: text/plain\r\n", | ||
| 'method' => 'POST', | ||
| 'content' => $verification_jwt | ||
| ) | ||
| ); | ||
| $context = stream_context_create($options); | ||
| $result = file_get_contents($url, false, $context); | ||
|
|
||
| header("Content-Type: application/json"); | ||
|
|
||
| echo $result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,36 @@ | ||
| $(function() { | ||
| var success_fun = function(data) { | ||
| console.log("IRMA authentication successful, submitting form"); | ||
| $("#jwt_result").attr("value", data); | ||
| $("form#irma_result_form").submit(); | ||
| }; | ||
| var cancel_fun = function(data) { | ||
| console.log("Authentication cancelled!"); | ||
| $("#irma_msg").html('<div class="alert alert-warning" role="alert">IRMA authentication cancelled.</div>'); | ||
| } | ||
| $(function () { | ||
| var success_fun = function (data) { | ||
| console.log("IRMA authentication successful, submitting form"); | ||
| $("#jwt_result").attr("value", data); | ||
| $("form#irma_result_form").submit(); | ||
| }; | ||
| var cancel_fun = function (data) { | ||
| console.log("Authentication cancelled!"); | ||
| $("#irma_msg").html('<div class="alert alert-warning" role="alert">IRMA authentication cancelled.</div>'); | ||
| }; | ||
|
|
||
| var error_fun = function(data) { | ||
| console.log("Authentication failed!"); | ||
| console.log("Error data:", data); | ||
| $("#irma_msg").html('<div class="alert alert-danger" role="alert">The IRMA authentication has failed.</div>'); | ||
| } | ||
| var error_fun = function (data) { | ||
| console.log("Authentication failed!"); | ||
| console.log("Error data:", data); | ||
| $("#irma_msg").html('<div class="alert alert-danger" role="alert">The IRMA authentication has failed.</div>'); | ||
| }; | ||
|
|
||
| $("#irma_btn").on("click", function() { | ||
| console.log("Button clicked"); | ||
| IRMA.verify(verification_jwt, success_fun, cancel_fun, error_fun); | ||
| $("#irma_btn").on("click", function () { | ||
| console.log("Button clicked"); | ||
| $.getJSON('get_irma_session.php?AuthState=' + authStateId, function (data) { | ||
| var irma_session = data.sessionPtr; | ||
| var irma_token = data.token; | ||
| var promise = irma.handleSession(irma_session); | ||
| promise.then(function (data) { | ||
| if (data === 'DONE') { | ||
| $.get(irma_api_server + '/session/' + irma_token + '/getproof', function (result_jwt) { | ||
| success_fun(result_jwt); | ||
| }); | ||
| } else { | ||
| cancel_fun(data); | ||
| } | ||
| }); | ||
| promise.catch(error_fun); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the rationale here for wanting to switch to generic errors instead of the IRMA specific ones?