28#include <wx/weakref.h>
52 if( !lock.owns_lock() )
54 wxLogTrace(
traceGit,
"Credential prompt opens without an address, the repository is busy" );
59 git_remote* remote =
nullptr;
61 if( git_remote_lookup( &remote, aCommon->
GetRepo(), remoteName.utf8_string().c_str() ) != GIT_OK )
67 if(
const char* url = git_remote_url( remote ) )
73static bool askerGone(
const wxWeakRef<wxWindow>& aParent,
bool aHadParent )
82 for( wxWindow* window = aParent.get(); window; window = window->GetParent() )
84 if( window->IsBeingDeleted() || wxTheApp->IsScheduledForDestruction( window ) )
114 const wxString& aExplanation )
119 wxString shownUsername = identity.
username;
121 if( shownUsername.IsEmpty() && aProject )
124 wxWeakRef<wxWindow> parent( aParent );
129 return refusal( parent, aParent !=
nullptr );
149 wxLogTrace(
traceGit,
"Credential prompt discarded, the remote changed while it was open" );
150 DisplayInfoMessage( aParent,
_(
"The remote changed while this window was open. Try the operation again." ) );
151 return refusal( parent, aParent !=
nullptr );
161 [parent](
bool aStored )
163 if( !aStored && parent )
165 DisplayInfoMessage( parent, _(
"The credentials could not be saved to the system keychain, "
166 "so they are kept for this session only." ) );
171 if(
askerGone( parent, aParent !=
nullptr ) )
179 aProject->GetLocalSettings().m_GitRepoUsername = dlg.GetUsername();
181 if( ssh && !dlg.GetSSHKey().IsEmpty() )
182 aProject->GetLocalSettings().m_GitSSHKey = dlg.GetSSHKey();
185 aProject->GetLocalSettings().m_GitRepoType = ssh ? wxS(
"ssh" ) : wxS(
"https" );
188 return PROMPT_ANSWER::ACCEPTED;
193 bool aRetriedAfterTrust )
195 wxWeakRef<wxWindow> parent( aParent );
196 wxString host = aFailure.
host;
198 if( aFailure.
port != 22 )
199 host << wxS(
":" ) << aFailure.
port;
204 return refusal( parent, aParent !=
nullptr );
211 question =
_(
"%s is already known by a different key type. The key it presented has fingerprint "
212 "SHA256:%s. Connect and remember this key too?" );
216 question =
_(
"This is the first time connecting to %s. Its key fingerprint is SHA256:%s. Connect and "
217 "remember this server?" );
222 _(
"Verify Server" ), wxYES_NO | wxNO_DEFAULT | wxICON_WARNING | wxCENTER );
223 dlg.SetYesNoLabels(
_(
"&Connect" ),
_(
"Cancel" ) );
225 if( dlg.ShowModal() != wxID_YES ||
askerGone( parent, aParent !=
nullptr ) )
226 return refusal( parent, aParent !=
nullptr );
231 wxString::Format(
_(
"The key for %s could not be saved, so the connection was not "
232 "made. Check that your .ssh folder can be written to." ),
235 return refusal( parent, aParent !=
nullptr );
300 for( wxWindow* window = aWindow; window; window = window->GetParent() )
302 if( wxFrame* frame =
dynamic_cast<wxFrame*
>( window ) )
316 for( wxWindow* window : wxTopLevelWindows )
337 git_signature* signature =
nullptr;
338 identity.
configured = git_signature_default( &signature, aCommon.
GetRepo() ) == GIT_OK;
345 const wxString& aUserName )
351 if(
config.authorName.IsEmpty() )
354 if(
config.authorEmail.IsEmpty() )
358 if(
config.authorName.IsEmpty() )
359 config.authorName = aUserName;
368bool identitySessionCurrent(
EDA_BASE_FRAME* aFrame,
const std::shared_ptr<KIGIT_COMMON>& aCommon )
370 return aFrame && !aFrame->IsBeingDeleted() && aCommon && !aCommon->IsShuttingDown() && aCommon->GetRepo()
381 if( !identitySessionCurrent( aFrame, aCommon ) )
384 wxWeakRef<EDA_BASE_FRAME> frame( aFrame );
385 wxWeakRef<wxWindow> parent( aParent );
398 if( !parent || parent->IsBeingDeleted() || !identitySessionCurrent( frame.get(), aCommon ) )
406 if( !lock.owns_lock() )
409 if( !identitySessionCurrent( frame.get(), aCommon ) )
412 saved = aCommon->SetUserConfig(
config.authorName,
config.authorEmail );
421 aCommon->NotifyRefreshListeners();
429 if( !identitySessionCurrent( aFrame, aCommon ) )
KIGIT_COMMON::GIT_CONN_TYPE GetConnType() const
wxString GetPassword() const
wxString GetUsername() const
wxString GetSSHKey() const
bool SaveCredentials() const
Ask for the name and email to record commits with.
wxString GetAuthorName() const
wxString GetEmail() const
The base frame for deriving all KiCad main window classes.
virtual bool GetConfigString(GIT_CONFIG_HANDLER *aHandler, const wxString &aKey, wxString &aValue)=0
The project's git session.
wxString GetAcceptedSSHKey() const
The encrypted key the server last accepted for this remote, so the credential prompt asks for the rig...
void SyncRemoteUrl(const wxString &aRawUrl)
Bind the session to the URL a transfer is about to connect to.
wxString GetRemote() const
wxString GetRemoteNameOrDefault() const
Returns GetRemotename() when non-empty, otherwise "origin".
git_repository * GetRepo() const
CREDENTIAL_IDENTITY GetCredentialIdentity() const
std::unique_lock< std::mutex > TryLockActionFor(std::chrono::milliseconds aWait)
TryLockAction that keeps trying for aWait before giving up.
bool ApplyPromptedCredentials(const CREDENTIAL_IDENTITY &aFor, const PROMPTED_CREDENTIALS &aEntered)
Apply what the prompt collected, unless the session has moved to another remote since aFor was taken.
static constexpr std::chrono::milliseconds ACTION_LOCK_WAIT
Long enough for a status read to finish, short enough that a window does not look hung.
wxString GetFirstOfferedSSHKey() const
The key the next attempt will try first, for the credential prompt to show.
static REMOTE_URL ParseRemoteURL(const wxString &aURL)
bool SecretRead() const
False while the keyring has not been read for the current remote.
KISTATUSBAR is a wxStatusBar suitable for Kicad manager.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
bool HasKiway() const
Safety check before asking for the Kiway reference.
virtual COMMON_SETTINGS * GetCommonSettings() const
bool m_GitIntegrationDisabled
If true, KiCad will not use Git integration for this project even if a .git directory exists.
wxString m_GitRepoUsername
Container for project specific data.
virtual std::shared_ptr< KIGIT_COMMON > GetGitCommon() const
This project's Git session, created empty on first use.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
Base window classes and related definitions.
GIT_BACKEND * GetGitBackend()
static KIGIT::PROMPT_ANSWER refusal(const wxWeakRef< wxWindow > &aParent, bool aHadParent)
static wxString initialSSHKey(KIGIT_COMMON *aCommon, PROJECT *aProject)
static void resolveMissingRemote(KIGIT_COMMON *aCommon)
static bool askerGone(const wxWeakRef< wxWindow > &aParent, bool aHadParent)
const wxChar *const traceGit
Flag to enable Git debugging output.
constexpr int MAX_CREDENTIAL_PROMPTS
Keyring reads and credential prompts that may follow a request's failures before one is reported inst...
void ClearSyncWarnings(wxWindow *aWindow)
Clear the background fetch's warnings from the frame holding aWindow.
APIEXPORT bool IsOfferableSSHKey(const wxString &aKey)
Whether aKey can be offered to a server.
APIEXPORT bool AddKnownHost(const HOST_KEY_FAILURE &aKey)
Append the refused key to KnownHostsPath(), creating the file and its folder when missing.
GitUserConfig ResolveGitIdentity(const GIT_IDENTITY &aIdentity, const COMMON_SETTINGS::GIT &aPreferences, const wxString &aUserName)
Fill missing values from custom preferences, then use the OS user name if needed.
@ ABANDONED
The parent closed while the prompt was up, so the caller must not touch it.
constexpr const wxChar * SYNC_WARNING_SOURCE
The status bar source under which background fetch failures are listed.
@ OTHER_KEY_TYPE
Entries name the host only with keys of other types.
GIT_IDENTITY ReadGitIdentity(KIGIT_COMMON &aCommon)
Read on a worker while holding the session's action lock.
bool EnsureGitIdentity(wxWindow *aParent, EDA_BASE_FRAME *aFrame, const std::shared_ptr< KIGIT_COMMON > &aCommon, const GIT_IDENTITY &aIdentity)
Open the same editor when the worker snapshot has no usable Git identity.
std::unique_lock< std::mutex > WaitForActionLock(KIGIT_COMMON &aCommon, wxWindow *aParent)
TryLockAction that first waits a moment for a status read or fetch to let go.
TRANSFER_RETRY AnswerTransferFailure(wxWindow *aParent, const std::weak_ptr< bool > &aAlive, KIGIT_COMMON *aCommon, PROJECT *aProject, const TRANSFER_FAILURE &aFailure, bool aRetriedAfterTrust, int &aPrompts)
Answer a failed transfer the way every window does.
PROMPT_ANSWER PromptForCredentials(wxWindow *aParent, KIGIT_COMMON *aCommon, PROJECT *aProject=nullptr, const wxString &aExplanation=wxEmptyString)
Ask the user for the credentials of the session's remote and apply them to the session.
PROMPT_ANSWER PromptToTrustHost(wxWindow *aParent, const HOST_KEY_FAILURE &aFailure, bool aRetriedAfterTrust)
Ask whether to trust a server seen for the first time, and remember its key when the user agrees.
APIEXPORT bool MayOfferTrust(const HOST_KEY_FAILURE &aFailure, bool aRetriedAfterTrust)
Whether the user may be asked to trust a refused key.
TRANSFER_RETRY
What a window does after AnswerTransferFailure.
@ RETRY_TRUSTED
Run it again, now that the server's key is trusted.
@ GONE
The window closed during a prompt, so the caller must not touch it.
@ CANCELLED
Stop and say so, the user cancelled the transfer or a prompt.
@ RETRY
Run the transfer again.
@ REPORT
Show the failure.
@ HOST_DECLINED
Stop without a message, the user chose not to trust the server.
APIEXPORT wxString HostKeyRefusalMessage(const HOST_KEY_FAILURE &aFailure)
Why a key the user may not trust was refused, and what to do next.
bool EditGitIdentity(wxWindow *aParent, EDA_BASE_FRAME *aFrame, const std::shared_ptr< KIGIT_COMMON > &aCommon, const GIT_IDENTITY &aIdentity)
Edit the repository's author and refresh Git views after saving.
APIEXPORT wxString KnownHostsPath()
The known_hosts file libgit2 checks host keys against. Empty when it has no home folder.
std::unique_ptr< git_signature, decltype([](git_signature *aSignature) { git_signature_free(aSignature); })> GitSignaturePtr
A unique pointer for git_signature objects with automatic cleanup.
std::unique_ptr< git_remote, decltype([](git_remote *aRemote) { git_remote_free(aRemote); })> GitRemotePtr
A unique pointer for git_remote objects with automatic cleanup.
PGM_BASE & Pgm()
The global program "get" accessor.
Repository values and whether Git can use them to record a commit.
A server key the connection refused, for the UI to offer to trust or to report.
wxString fingerprint
SHA256 in unpadded base64, as ssh shows it after "SHA256:".
Why a transfer to a remote failed.
bool cancelled
The user cancelled the transfer.
std::optional< HOST_KEY_FAILURE > hostKey
The server's key is unknown or has changed.
bool authFailure
The remote refused every credential offered.
wxString error
Shown above the credential fields.
The remote the credential prompt was opened for.
What the credential prompt collected.
std::optional< wxString > username
wxLogTrace helper definitions.