From 9917a9882eff675567007194661df57450016c89 Mon Sep 17 00:00:00 2001 From: Jeffrey Armstrong Date: Fri, 6 May 2022 12:53:08 -0400 Subject: Login and session tracking now works via Gemini. Need to restrict operations in Gemini based on request auth levels still. --- captain/gemini.f90 | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'captain/gemini.f90') diff --git a/captain/gemini.f90 b/captain/gemini.f90 index 6070dbe..7e849d6 100644 --- a/captain/gemini.f90 +++ b/captain/gemini.f90 @@ -26,7 +26,7 @@ implicit none private public :: handle_request - + contains subroutine read_request(ssl, req) @@ -127,7 +127,7 @@ contains use iso_c_binding, only: c_ptr use jessl, only: ssl_write use logging - use server_response, only: GEMINI_CODE_SUCCESS + use gemini_codes implicit none type(c_ptr)::ssl @@ -148,7 +148,7 @@ contains subroutine write_redirect(ssl, url) use iso_c_binding, only: c_ptr - use server_response, only: GEMINI_CODE_REDIRECT + use gemini_codes implicit none type(c_ptr)::ssl @@ -158,21 +158,26 @@ contains end subroutine write_redirect - subroutine write_input_request(ssl, msg) + subroutine write_input_request(ssl, msg, code) use iso_c_binding, only: c_ptr - use server_response, only: GEMINI_CODE_INPUT + use gemini_codes implicit none type(c_ptr)::ssl character(*), intent(in)::msg + integer, intent(in), optional::code - call write_status(ssl, GEMINI_CODE_INPUT, msg) + if(present(code)) then + call write_status(ssl, code, msg) + else + call write_status(ssl, GEMINI_CODE_INPUT, msg) + end if end subroutine write_input_request subroutine write_failure(ssl) use iso_c_binding, only: c_ptr - use server_response, only: GEMINI_CODE_PERMFAIL + use gemini_codes implicit none type(c_ptr)::ssl @@ -211,7 +216,9 @@ contains use external_handling, only: external_request_gemini, external_request_titan use api_handling use logging + use m_uuid, only: UUID_LENGTH use server_response + use gemini_codes implicit none ! For our TLS connection @@ -227,7 +234,7 @@ contains ! Requested file character(1024)::text_request - character(32)::first + character(UUID_LENGTH+8)::first integer::rendered_unit, ioerror @@ -307,6 +314,18 @@ contains end if else + + ! Check for leading session + if(first(1:8) == "session-") then + + ! Set the token in the request to the leading session id + call req%set_token(first(9:len(first))) + + ! Remove the first path component + call req%remove_first_path_component() + + end if + if(req%protocol == "gemini") then resp = external_request_gemini(req) @@ -320,8 +339,8 @@ contains call write_log("Handling response", LOG_DEBUG) ! Handle the response select case(resp%code) - case(GEMINI_CODE_INPUT) - call write_input_request(ssl, resp%message) + case(GEMINI_CODE_INPUT, GEMINI_CODE_INPUT_PW) + call write_input_request(ssl, resp%message, code=resp%code) case(GEMINI_CODE_REDIRECT) call write_redirect(ssl, resp%url) -- cgit v1.2.3