skinparam sequenceMessageAlign direction
skinparam WrapWidth 300
skinparam minClassWidth 150
skinparam BoxPadding 1
skinparam ParticipantPadding 50
skinparam sequenceReferenceHeaderBackgroundColor palegreen
scale max 2048 width

skinparam sequence {
ArrowColor black
ArrowFontSize 17
ActorBorderColor black
LifeLineBorderColor black
LifeLineBackgroundColor Gainsboro

ParticipantBorderColor Motivation
ParticipantBackgroundColor Motivation
ParticipantFontSize 20
ParticipantFontColor black
ParticipantBorderColor Black
ParticipantBackgroundColor MOTIVATION

ActorBackgroundColor Gainsboro
ActorFontColor black
ActorFontSize 20
}

autonumber

actor oa as "Akteur in der Rolle\nOrg-Admin"
  box <size:19>Endgerät</size> #WhiteSmoke
  participant wb as "Frontend des \nRegistrierungs-Dienstes"
  participant au as "Authenticator"
  end box
participant ko as "Konnektor"
participant rd as "Registrierungs-Dienst \n(Relying Party)"
participant ip as "zentraler \nIDP-Dienst"

oa -> wb: Organisation authentisieren 

 activate wb
wb -> rd:POST I_Registration
 |||
 activate rd
      opt#LightGrey #AliceBlue <size:16>Download des IDP Discovery Dokumentes</size>
          |||        
            rd -> ip:""GET {HOSTNAME]}/.well-known/openid-configuration""
            activate ip
            ip --> rd:signierte Base64-kodierte openid-configuration 
            deactivate ip
            rd -> rd:Prüfung der Signatur der openid-configuration
          |||
          end
|||
rd->rd: Erzeuge PKCE (Code verifier und challenge) \n""code_challenge""\n""code_challenge_method""

     
|||
rd->rd: Erstellung der Authentication Request URL\nmit den Request Parametern \n""challenge_path=""\n""{authorization_endpoint}&{client_id}&...""
        |||

rd --> wb: Redirect zu Authentication Request URL 
 deactivate rd

        wb -> au: Aufruf Deeplink \nauthenticator://?challenge_path=\n{Authentication Request URL} 
        activate au        
          opt#LightGrey #AliceBlue <size:16>Download des IDP Discovery Dokumentes</size>
          |||        
            au -> ip:GET [HOSTNAME]/.well-known/openid-configuration
            activate ip
            ip --> au:signierte base64 kodierte openid-configuration 
            deactivate ip
            au -> au:Prüfung der Signatur der openid-configuration
          |||
          end
        |||
        au -> ip: GET {Authentication Request URL}
        activate ip
        ip -> ip: SESSION_ID anlegen
        ip -> ip: Erstellung der Authentication challenge
                
        ip -> au: Authentication challenge
        deactivate ip
        |||
        group#LightGrey #LightBlue <size:16>Signieren der Challenge mit Konnektor-Operationen</size>
        |||
          au -> ko: ""getCards(Aufrufkontext)""
           activate ko
          ko --> au: Status, Liste der verfügbaren Smartkarten
          au -> au: Auswahl der gesteckten SMC-B --> CardHandle
          |||
          au -> ko: ""GetPinStatus (Aufrufkontext, CardHandle,""\n""PinType (PIN.SMC))""
          ko --> au: Status, PinStatus
          |||
            opt#LightGrey #AliceBlue <size:16>Karte nicht freigeschaltet </size>
              au -> ko: ""VerifyPin (Aufrufkontext, CardHandle,""\n""PinType (PIN.SMC))""
              ko --> oa: Aufforderung der PIN-Eingabe
              oa -> ko: PIN-Eingabe
              ko --> au: Status
            |||
            end
          au -> ko: ""ExternalAuthenticate""\n""(Aufrufkontext, CardHandle,""\n""C.HCI.AUT, Authentication challenge)""
          ko --> au: Signierte Authentication challenge
        |||
        end
          deactivate ko
        |||
        au -> au: Verschlüsselung der signierten Authentication challenge mit dem \nöffentlichen Schlüssel PuK_IDP_ENC vom IDP-Dienst
        au ->ip: Authentication challenge, C.HCI.AUT der SMC-B übertragen
        activate ip
        ip -> ip: Entschlüsselung mit PuK_IDP_SIG\ndes IDP-Dienstes\nund Validierung der Signierten challenge\nanhand des im x5c-Header mitgelieferten\nAuthentifizierungszertifikats
        ip -> ip: Erstellung des AUTHORIZATION_CODE
        ip --> au: Redirect zur redirect_uri\ndes Registrierungs-Dienstes\nmit AUTHORIZATION_CODE
          deactivate ip
        au --> wb: Redirect zur redirect_uri\ndes Registrierungs-Dienstes\nmit AUTHORIZATION_CODE
          deactivate au
        |||
        wb -> rd: GET /redirect_uri?code={AUTHORIZATION_CODE}
          activate rd
        rd -> rd: Erzeugung AES256-"Token-Key"
        rd -> rd: KEY_VERIFIER mit PUK_IDP_ENC verschlüsseln
        rd -> ip: POST {token_endpoint}\n(AUTHORIZATION_CODE, KEY_VERIFIER)
         activate ip
        ip -> ip: AUTHORIZATION_CODE\nentschlüsseln und\nValidierung mittels PUK_IDP_SIG\ndes Authorization-Endpunktes
        ip -> ip: Entschlüsselung und Validierung\ndes KEY_VERIFIER
        ip -> ip: Erzeugung des ID_TOKEN und\nSignieren mittels PrK_IDP_SIG\nsowie Verschlüsselung mittels Token-Key
        ip --> rd: ID_TOKEN
         deactivate ip
        rd -> rd:  Entschlüsselung des Token\nmit Token-Key und Validierung\nmit PUK_IDP_SIG
        rd -> rd: Prüfung der im Token\nenthaltenen ProfessionOID
        rd --> wb: Status der Authentisierung
         deactivate rd
        wb --> oa: Organisation erfolgreich Authentifiziert
@enduml
