@@ -684,94 +684,97 @@ std::unique_ptr<AsyncStatus> Validator::get_public_keys_from_web_continue(
684684 if (!cget_status.m_done ) {
685685 return std::move (status);
686686 }
687- if (cget_status.m_status_code != 200 ) {
688- if (status->m_oauth_fallback ) {
689- throw IssuerLookupException (" Failed to retrieve metadata provider "
690- " information for issuer." );
691- } else {
692- status->m_oauth_fallback = true ;
693- status->m_cget .reset (new internal::SimpleCurlGet ());
694- cget_status =
695- status->m_cget ->perform_start (status->m_oauth_metadata_url );
696- if (!cget_status.m_done ) {
697- return std::move (status);
687+ if (cget_status.m_status_code != 200 ) {
688+ if (status->m_oauth_fallback ) {
689+ throw IssuerLookupException (
690+ " Failed to retrieve metadata provider "
691+ " information for issuer." );
692+ } else {
693+ status->m_oauth_fallback = true ;
694+ status->m_cget .reset (new internal::SimpleCurlGet ());
695+ cget_status = status->m_cget ->perform_start (
696+ status->m_oauth_metadata_url );
697+ if (!cget_status.m_done ) {
698+ return std::move (status);
699+ }
700+ return get_public_keys_from_web_continue (std::move (status));
698701 }
699- return get_public_keys_from_web_continue (std::move (status));
700702 }
703+ status->m_cget ->get_data (buffer, len);
704+ std::string metadata (buffer, len);
705+ picojson::value json_obj;
706+ auto err = picojson::parse (json_obj, metadata);
707+ if (!err.empty ()) {
708+ throw JsonException (" JSON parse failure when downloading from "
709+ " the metadata URL " +
710+ status->m_cget ->get_url () + " : " + err);
711+ }
712+ if (!json_obj.is <picojson::object>()) {
713+ throw JsonException (" Metadata resource " +
714+ status->m_cget ->get_url () +
715+ " contains "
716+ " improperly-formatted JSON." );
717+ }
718+ auto top_obj = json_obj.get <picojson::object>();
719+ auto iter = top_obj.find (" jwks_uri" );
720+ if (iter == top_obj.end () || (!iter->second .is <std::string>())) {
721+ throw JsonException (" Metadata resource " +
722+ status->m_cget ->get_url () +
723+ " is missing 'jwks_uri' string value" );
724+ }
725+ auto jwks_uri = iter->second .get <std::string>();
726+ status->m_has_metadata = true ;
727+ status->m_state = AsyncStatus::DOWNLOAD_PUBLIC_KEY;
728+ status->m_cget .reset (new internal::SimpleCurlGet ());
729+ status->m_cget ->perform_start (jwks_uri);
730+ // This should also fall through the next state
701731 }
702- status->m_cget ->get_data (buffer, len);
703- std::string metadata (buffer, len);
704- picojson::value json_obj;
705- auto err = picojson::parse (json_obj, metadata);
706- if (!err.empty ()) {
707- throw JsonException (
708- " JSON parse failure when downloading from the metadata URL " +
709- status->m_cget ->get_url () + " : " + err);
710- }
711- if (!json_obj.is <picojson::object>()) {
712- throw JsonException (" Metadata resource " +
713- status->m_cget ->get_url () +
714- " contains "
715- " improperly-formatted JSON." );
716- }
717- auto top_obj = json_obj.get <picojson::object>();
718- auto iter = top_obj.find (" jwks_uri" );
719- if (iter == top_obj.end () || (!iter->second .is <std::string>())) {
720- throw JsonException (" Metadata resource " +
721- status->m_cget ->get_url () +
722- " is missing 'jwks_uri' string value" );
723- }
724- auto jwks_uri = iter->second .get <std::string>();
725- status->m_has_metadata = true ;
726- status->m_state = AsyncStatus::DOWNLOAD_PUBLIC_KEY;
727- status->m_cget .reset (new internal::SimpleCurlGet ());
728- status->m_cget ->perform_start (jwks_uri);
729- // This should also fall through the next state
730- }
731732
732- case AsyncStatus::DOWNLOAD_PUBLIC_KEY: {
733- auto cget_status = status->m_cget ->perform_continue ();
734- if (!cget_status.m_done ) {
735- return std::move (status);
736- }
737- if (cget_status.m_status_code != 200 ) {
738- throw IssuerLookupException (" Failed to retrieve the issuer's key set" );
739- }
733+ case AsyncStatus::DOWNLOAD_PUBLIC_KEY: {
734+ auto cget_status = status->m_cget ->perform_continue ();
735+ if (!cget_status.m_done ) {
736+ return std::move (status);
737+ }
738+ if (cget_status.m_status_code != 200 ) {
739+ throw IssuerLookupException (
740+ " Failed to retrieve the issuer's key set" );
741+ }
740742
741- status->m_cget ->get_data (buffer, len);
742- auto metadata = std::string (buffer, len);
743- picojson::value json_obj;
744- auto err = picojson::parse (json_obj, metadata);
745- if (!err.empty ()) {
746- throw JsonException (" JSON parse failure when downloading from the "
747- " public key URL " +
748- status->m_cget ->get_url () + " : " + err);
743+ status->m_cget ->get_data (buffer, len);
744+ auto metadata = std::string (buffer, len);
745+ picojson::value json_obj;
746+ auto err = picojson::parse (json_obj, metadata);
747+ if (!err.empty ()) {
748+ throw JsonException (
749+ " JSON parse failure when downloading from the "
750+ " public key URL " +
751+ status->m_cget ->get_url () + " : " + err);
752+ }
753+ status->m_cget .reset ();
754+
755+ auto now = std::time (NULL );
756+ // TODO: take expiration time from the cache-control header in the
757+ // response.
758+
759+ int next_update_delta =
760+ configurer::Configuration::get_next_update_delta ();
761+ int expiry_delta = configurer::Configuration::get_expiry_delta ();
762+ status->m_next_update = now + next_update_delta;
763+ status->m_expires = now + expiry_delta;
764+ status->m_keys = json_obj;
765+ status->m_continue_fetch = false ;
766+ status->m_done = true ;
767+ status->m_state = AsyncStatus::DONE;
749768 }
750- status->m_cget .reset ();
751-
752- auto now = std::time (NULL );
753- // TODO: take expiration time from the cache-control header in the
754- // response.
755-
756- int next_update_delta =
757- configurer::Configuration::get_next_update_delta ();
758- int expiry_delta = configurer::Configuration::get_expiry_delta ();
759- status->m_next_update = now + next_update_delta;
760- status->m_expires = now + expiry_delta;
761- status->m_keys = json_obj;
762- status->m_continue_fetch = false ;
763- status->m_done = true ;
764- status->m_state = AsyncStatus::DONE;
765- }
766- case AsyncStatus::DONE:
767- status->m_done = true ;
768-
769- } // Switch
770- return std::move (status);
769+ case AsyncStatus::DONE:
770+ status->m_done = true ;
771+
772+ } // Switch
773+ return std::move (status);
771774 } catch (const CurlException &e) {
772775 // Rethrow CURL errors during issuer key fetch as IssuerLookupException
773776 // (unless it's already an IssuerLookupException)
774- if (dynamic_cast <const IssuerLookupException*>(&e)) {
777+ if (dynamic_cast <const IssuerLookupException *>(&e)) {
775778 throw ;
776779 }
777780 throw IssuerLookupException (e.what ());
0 commit comments