diff --git a/common/dialogs/git/dialog_git_repository.cpp b/common/dialogs/git/dialog_git_repository.cpp index 3e39dd7b3d..8ae7f0206f 100644 --- a/common/dialogs/git/dialog_git_repository.cpp +++ b/common/dialogs/git/dialog_git_repository.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -43,9 +44,6 @@ DIALOG_GIT_REPOSITORY::DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository* DIALOG_GIT_REPOSITORY_BASE( aParent ), m_repository( aRepository ), m_prevFile( wxEmptyString ), - m_tested( 0 ), - m_failedTest( false ), - m_testError( wxEmptyString ), m_tempRepo( false ) { m_txtURL->SetFocus(); @@ -69,8 +67,11 @@ DIALOG_GIT_REPOSITORY::DIALOG_GIT_REPOSITORY( wxWindow* aParent, git_repository* if( !m_txtURL->GetValue().IsEmpty() ) updateURLData(); + else + m_ConnType->SetSelection( static_cast( KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_LOCAL ) ); - SetupStandardButtons(); + + SetupStandardButtons( { { wxID_HELP, _( "Test Connection" ) } } ); Layout(); finishDialogSettings(); @@ -143,6 +144,13 @@ void DIALOG_GIT_REPOSITORY::setDefaultSSHKey() } +void DIALOG_GIT_REPOSITORY::onCbCustom( wxCommandEvent& event ) +{ + updateAuthControls(); + event.Skip(); +} + + void DIALOG_GIT_REPOSITORY::OnUpdateUI( wxUpdateUIEvent& event ) { // event.Enable( !m_txtName->GetValue().IsEmpty() && !m_txtURL->GetValue().IsEmpty() ); @@ -239,7 +247,6 @@ void DIALOG_GIT_REPOSITORY::updateURLData() if( m_txtName->GetValue().IsEmpty() ) m_txtName->SetValue( get_repo_name( repoAddress ) ); - } } else if( url.Contains( "ssh://" ) || url.Contains( "git@" ) ) @@ -263,6 +270,11 @@ void DIALOG_GIT_REPOSITORY::updateURLData() void DIALOG_GIT_REPOSITORY::OnTestClick( wxCommandEvent& event ) { + if( m_txtURL->GetValue().Trim().Trim( false ).IsEmpty() ) + return; + + wxString error; + bool success = false; git_remote* remote = nullptr; git_remote_callbacks callbacks; git_remote_init_callbacks( &callbacks, GIT_REMOTE_CALLBACKS_VERSION ); @@ -270,76 +282,31 @@ void DIALOG_GIT_REPOSITORY::OnTestClick( wxCommandEvent& event ) // We track if we have already tried to connect. // If we have, the server may come back to offer another connection // type, so we need to keep track of how many times we have tried. - m_tested = 0; - callbacks.credentials = []( git_cred** aOut, const char* aUrl, const char* aUsername, - unsigned int aAllowedTypes, void* aPayload ) -> int - { - DIALOG_GIT_REPOSITORY* dialog = static_cast( aPayload ); - - if( dialog->GetRepoType() == KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_LOCAL ) - return GIT_PASSTHROUGH; - - if( aAllowedTypes & GIT_CREDTYPE_USERNAME - && !( dialog->GetTested() & GIT_CREDTYPE_USERNAME ) ) - { - wxString username = dialog->GetUsername().Trim().Trim( false ); - git_cred_username_new( aOut, username.ToStdString().c_str() ); - dialog->GetTested() |= GIT_CREDTYPE_USERNAME; - } - else if( dialog->GetRepoType() == KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_HTTPS - && ( aAllowedTypes & GIT_CREDTYPE_USERPASS_PLAINTEXT ) - && !( dialog->GetTested() & GIT_CREDTYPE_USERPASS_PLAINTEXT ) ) - { - wxString username = dialog->GetUsername().Trim().Trim( false ); - wxString password = dialog->GetPassword().Trim().Trim( false ); - - git_cred_userpass_plaintext_new( aOut, username.ToStdString().c_str(), - password.ToStdString().c_str() ); - dialog->GetTested() |= GIT_CREDTYPE_USERPASS_PLAINTEXT; - } - else if( dialog->GetRepoType() == KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_SSH - && ( aAllowedTypes & GIT_CREDTYPE_SSH_KEY ) - && !( dialog->GetTested() & GIT_CREDTYPE_SSH_KEY ) ) - { - // SSH key authentication - wxString sshKey = dialog->GetRepoSSHPath(); - wxString sshPubKey = sshKey + ".pub"; - wxString username = dialog->GetUsername().Trim().Trim( false ); - wxString password = dialog->GetPassword().Trim().Trim( false ); - - git_cred_ssh_key_new( aOut, username.ToStdString().c_str(), - sshPubKey.ToStdString().c_str(), sshKey.ToStdString().c_str(), - password.ToStdString().c_str() ); - dialog->GetTested() |= GIT_CREDTYPE_SSH_KEY; - } - else - { - return GIT_PASSTHROUGH; - } - - return GIT_OK; - }; - - callbacks.payload = this; + KIGIT_COMMON common( m_repository ); + callbacks.credentials = credentials_cb; + callbacks.payload = &common; + common.SetPassword( m_txtPassword->GetValue() ); + common.SetUsername( m_txtUsername->GetValue() ); + common.SetSSHKey( m_fpSSHKey->GetFileName().GetFullPath() ); + common.SetConnType( static_cast( m_ConnType->GetSelection() ) ); wxString txtURL = m_txtURL->GetValue(); - git_remote_create_with_fetchspec( &remote, m_repository, "origin", txtURL.ToStdString().c_str(), + git_remote_create_with_fetchspec( &remote, m_repository, "origin", txtURL.mbc_str(), "+refs/heads/*:refs/remotes/origin/*" ); - KIGIT::GitRemotePtr remotePtr( remote ); - if( git_remote_connect( remote, GIT_DIRECTION_FETCH, &callbacks, nullptr, nullptr ) != GIT_OK ) - SetTestResult( true, git_error_last()->message ); + if( git_remote_connect( remote, GIT_DIRECTION_FETCH, &callbacks, nullptr, nullptr ) == GIT_OK ) + success = true; else - SetTestResult( false, wxEmptyString ); + error = git_error_last()->message; git_remote_disconnect( remote ); auto dlg = wxMessageDialog( this, wxEmptyString, _( "Test Connection" ), wxOK | wxICON_INFORMATION ); - if( !m_failedTest ) + if( success ) { dlg.SetMessage( _( "Connection successful" ) ); } @@ -347,7 +314,7 @@ void DIALOG_GIT_REPOSITORY::OnTestClick( wxCommandEvent& event ) { dlg.SetMessage( wxString::Format( _( "Could not connect to '%s' " ), m_txtURL->GetValue() ) ); - dlg.SetExtendedMessage( m_testError ); + dlg.SetExtendedMessage( error ); } dlg.ShowModal(); @@ -450,14 +417,18 @@ void DIALOG_GIT_REPOSITORY::updateAuthControls() if( m_ConnType->GetSelection() == static_cast( KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_SSH ) ) { - m_fpSSHKey->Enable( true ); - m_labelSSH->Enable( true ); + m_cbCustom->Enable( true ); + m_fpSSHKey->Enable( m_cbCustom->IsChecked() ); + m_txtUsername->Enable( m_cbCustom->IsChecked() ); + m_txtPassword->Enable( m_cbCustom->IsChecked() ); m_labelPass1->SetLabel( _( "SSH key password:" ) ); } else { + m_cbCustom->Enable( false ); m_fpSSHKey->Enable( false ); - m_labelSSH->Enable( false ); + m_txtUsername->Enable( true ); + m_txtPassword->Enable( true ); m_labelPass1->SetLabel( _( "Password:" ) ); setDefaultSSHKey(); } diff --git a/common/dialogs/git/dialog_git_repository.h b/common/dialogs/git/dialog_git_repository.h index e7acf269b7..14a9281efe 100644 --- a/common/dialogs/git/dialog_git_repository.h +++ b/common/dialogs/git/dialog_git_repository.h @@ -36,12 +36,6 @@ public: wxString aURL = wxEmptyString ); ~DIALOG_GIT_REPOSITORY() override; - void SetTestResult( bool aFailed, const wxString& aError ) - { - m_failedTest = aFailed; - m_testError = aError; - } - void SetRepoType( KIGIT_COMMON::GIT_CONN_TYPE aType ) { m_ConnType->SetSelection( static_cast( aType ) ); @@ -87,8 +81,6 @@ public: void SetRepoSSHPath( const wxString& aPath ) { m_fpSSHKey->SetFileName( aPath ); m_prevFile = aPath; } wxString GetRepoSSHPath() const { return m_fpSSHKey->GetFileName().GetFullPath(); } - unsigned& GetTested() { return m_tested; } - void SetEncrypted( bool aEncrypted = true ); private: @@ -100,6 +92,7 @@ private: void OnTestClick( wxCommandEvent& event ) override; void OnFileUpdated( wxFileDirPickerEvent& event ) override; + void onCbCustom( wxCommandEvent& event ) override; void setDefaultSSHKey(); @@ -115,10 +108,6 @@ private: wxString m_prevFile; - unsigned m_tested; - bool m_failedTest; - wxString m_testError; - bool m_tempRepo; wxString m_tempPath; }; diff --git a/common/dialogs/git/dialog_git_repository_base.cpp b/common/dialogs/git/dialog_git_repository_base.cpp index 7cd2447fc2..da74b93b77 100644 --- a/common/dialogs/git/dialog_git_repository_base.cpp +++ b/common/dialogs/git/dialog_git_repository_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6) +// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -30,20 +30,26 @@ DIALOG_GIT_REPOSITORY_BASE::DIALOG_GIT_REPOSITORY_BASE( wxWindow* parent, wxWind m_staticText3 = new wxStaticText( this, wxID_ANY, _("Name:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText3->Wrap( -1 ); + m_staticText3->Hide(); + fgSizer2->Add( m_staticText3, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); m_txtName = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_txtName->Hide(); + fgSizer2->Add( m_txtName, 0, wxEXPAND|wxRIGHT, 5 ); m_staticText4 = new wxStaticText( this, wxID_ANY, _("Location:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText4->Wrap( -1 ); - fgSizer2->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 ); + fgSizer2->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 ); m_txtURL = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); fgSizer2->Add( m_txtURL, 0, wxEXPAND|wxRIGHT, 5 ); m_staticText9 = new wxStaticText( this, wxID_ANY, _("Connection type:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText9->Wrap( -1 ); + m_staticText9->Hide(); + fgSizer2->Add( m_staticText9, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 ); wxBoxSizer* bSizer3; @@ -53,6 +59,8 @@ DIALOG_GIT_REPOSITORY_BASE::DIALOG_GIT_REPOSITORY_BASE( wxWindow* parent, wxWind int m_ConnTypeNChoices = sizeof( m_ConnTypeChoices ) / sizeof( wxString ); m_ConnType = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_ConnTypeNChoices, m_ConnTypeChoices, 0 ); m_ConnType->SetSelection( 0 ); + m_ConnType->Hide(); + bSizer3->Add( m_ConnType, 0, wxRIGHT, 5 ); @@ -80,23 +88,13 @@ DIALOG_GIT_REPOSITORY_BASE::DIALOG_GIT_REPOSITORY_BASE( wxWindow* parent, wxWind fgSizer21->SetFlexibleDirection( wxBOTH ); fgSizer21->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - m_labelSSH = new wxStaticText( m_panelAuth, wxID_ANY, _("SSH private key: "), wxDefaultPosition, wxDefaultSize, 0 ); - m_labelSSH->Wrap( -1 ); - fgSizer21->Add( m_labelSSH, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 ); - - wxBoxSizer* bSizer5; - bSizer5 = new wxBoxSizer( wxHORIZONTAL ); + m_cbCustom = new wxCheckBox( m_panelAuth, wxID_ANY, _("SSH private key: "), wxDefaultPosition, wxDefaultSize, 0 ); + fgSizer21->Add( m_cbCustom, 0, wxALL, 5 ); m_fpSSHKey = new wxFilePickerCtrl( m_panelAuth, wxID_ANY, wxEmptyString, _("Select SSH private key file"), _("*"), wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN ); m_fpSSHKey->SetMinSize( wxSize( 250,-1 ) ); - bSizer5->Add( m_fpSSHKey, 0, wxEXPAND|wxRIGHT, 5 ); - - m_btnTest = new wxButton( m_panelAuth, wxID_ANY, _("Test"), wxDefaultPosition, wxDefaultSize, 0 ); - bSizer5->Add( m_btnTest, 0, wxRIGHT, 5 ); - - - fgSizer21->Add( bSizer5, 0, wxEXPAND, 5 ); + fgSizer21->Add( m_fpSSHKey, 0, wxEXPAND|wxRIGHT, 5 ); m_staticText11 = new wxStaticText( m_panelAuth, wxID_ANY, _("User name:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText11->Wrap( -1 ); @@ -129,6 +127,8 @@ DIALOG_GIT_REPOSITORY_BASE::DIALOG_GIT_REPOSITORY_BASE( wxWindow* parent, wxWind m_sdbSizer->AddButton( m_sdbSizerOK ); m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizerHelp = new wxButton( this, wxID_HELP ); + m_sdbSizer->AddButton( m_sdbSizerHelp ); m_sdbSizer->Realize(); bSizerMain->Add( m_sdbSizer, 0, wxBOTTOM|wxEXPAND|wxTOP, 5 ); @@ -145,8 +145,9 @@ DIALOG_GIT_REPOSITORY_BASE::DIALOG_GIT_REPOSITORY_BASE( wxWindow* parent, wxWind this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnUpdateUI ) ); m_txtURL->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnLocationExit ), NULL, this ); m_ConnType->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnSelectConnType ), NULL, this ); + m_cbCustom->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::onCbCustom ), NULL, this ); m_fpSSHKey->Connect( wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnFileUpdated ), NULL, this ); - m_btnTest->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnTestClick ), NULL, this ); + m_sdbSizerHelp->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnTestClick ), NULL, this ); m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnOKClick ), NULL, this ); } @@ -157,8 +158,9 @@ DIALOG_GIT_REPOSITORY_BASE::~DIALOG_GIT_REPOSITORY_BASE() this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnUpdateUI ) ); m_txtURL->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnLocationExit ), NULL, this ); m_ConnType->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnSelectConnType ), NULL, this ); + m_cbCustom->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::onCbCustom ), NULL, this ); m_fpSSHKey->Disconnect( wxEVT_COMMAND_FILEPICKER_CHANGED, wxFileDirPickerEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnFileUpdated ), NULL, this ); - m_btnTest->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnTestClick ), NULL, this ); + m_sdbSizerHelp->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnTestClick ), NULL, this ); m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_GIT_REPOSITORY_BASE::OnOKClick ), NULL, this ); } diff --git a/common/dialogs/git/dialog_git_repository_base.fbp b/common/dialogs/git/dialog_git_repository_base.fbp index ff6656b201..2a2f07157d 100644 --- a/common/dialogs/git/dialog_git_repository_base.fbp +++ b/common/dialogs/git/dialog_git_repository_base.fbp @@ -191,7 +191,7 @@ 5 wxEXPAND 0 - + 2 wxBOTH 1 @@ -234,7 +234,7 @@ 1 0 - 0 + 1 wxID_ANY Name: 0 @@ -296,7 +296,7 @@ 1 0 - 0 + 1 wxID_ANY 0 @@ -332,7 +332,7 @@ 5 - wxALIGN_CENTER_VERTICAL|wxLEFT + wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT 0 1 @@ -489,7 +489,7 @@ 1 0 - 0 + 1 wxID_ANY Connection type: 0 @@ -520,11 +520,11 @@ -1 - + 5 wxEXPAND 1 - + bSizer3 wxHORIZONTAL @@ -561,7 +561,7 @@ 1 0 - 0 + 1 wxID_ANY 0 @@ -807,11 +807,77 @@ none 0 5 + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + 0 + + 0 + 0 + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 0 + 1 + + 1 + + 0 + 0 + wxID_ANY + SSH private key: + + 0 + + + 0 + + 1 + m_cbCustom + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + onCbCustom + + 5 - wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT + wxEXPAND|wxRIGHT 0 - + 1 1 1 @@ -840,16 +906,15 @@ 0 0 wxID_ANY - SSH private key: - 0 0 + Select SSH private key file 0 - + 250,-1 1 - m_labelSSH + m_fpSSHKey 1 @@ -859,167 +924,20 @@ Resizable 1 - - ; ; forward_declare + wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN + 0 + + wxFILTER_NONE + wxDefaultValidator + + + * - -1 - - - - 5 - wxEXPAND - 0 - - - bSizer5 - wxHORIZONTAL - none - - 5 - wxEXPAND|wxRIGHT - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - - - - 1 - 0 - 1 - - 1 - 0 - Dock - 0 - Left - 0 - 1 - - 1 - - 0 - 0 - wxID_ANY - - 0 - - Select SSH private key file - - 0 - 250,-1 - 1 - m_fpSSHKey - 1 - - - protected - 1 - - Resizable - 1 - - wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN - - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - * - - - - OnFileUpdated - - - - 5 - wxRIGHT - 0 - - 1 - 1 - 1 - 1 - 0 - - 0 - 0 - 0 - - - - - 1 - 0 - 1 - - 1 - - 0 - 0 - - Dock - 0 - Left - 0 - 1 - - 1 - - - 0 - 0 - wxID_ANY - Test - - 0 - - 0 - - - 0 - - 1 - m_btnTest - 1 - - - protected - 1 - - - - Resizable - 1 - - - ; ; forward_declare - 0 - - - wxFILTER_NONE - wxDefaultValidator - - - - - OnTestClick - - + OnFileUpdated @@ -1299,7 +1217,7 @@ 0 1 0 - 0 + 1 0 1 0 @@ -1307,6 +1225,7 @@ m_sdbSizer protected + OnTestClick OnOKClick diff --git a/common/dialogs/git/dialog_git_repository_base.h b/common/dialogs/git/dialog_git_repository_base.h index 837dfb9156..262a33628f 100644 --- a/common/dialogs/git/dialog_git_repository_base.h +++ b/common/dialogs/git/dialog_git_repository_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6) +// C++ code generated with wxFormBuilder (version 4.2.1-0-g80c4cb6a-dirty) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -21,12 +21,10 @@ #include #include #include +#include #include -#include -#include -#include -#include #include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -51,9 +49,8 @@ class DIALOG_GIT_REPOSITORY_BASE : public DIALOG_SHIM wxPanel* m_panelAuth; wxStaticText* m_staticText2; wxStaticLine* m_staticline2; - wxStaticText* m_labelSSH; + wxCheckBox* m_cbCustom; wxFilePickerCtrl* m_fpSSHKey; - wxButton* m_btnTest; wxStaticText* m_staticText11; wxTextCtrl* m_txtUsername; wxStaticText* m_labelPass1; @@ -61,12 +58,14 @@ class DIALOG_GIT_REPOSITORY_BASE : public DIALOG_SHIM wxStdDialogButtonSizer* m_sdbSizer; wxButton* m_sdbSizerOK; wxButton* m_sdbSizerCancel; + wxButton* m_sdbSizerHelp; // Virtual event handlers, override them in your derived class virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnLocationExit( wxFocusEvent& event ) { event.Skip(); } virtual void OnSelectConnType( wxCommandEvent& event ) { event.Skip(); } + virtual void onCbCustom( wxCommandEvent& event ) { event.Skip(); } virtual void OnFileUpdated( wxFileDirPickerEvent& event ) { event.Skip(); } virtual void OnTestClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnOKClick( wxCommandEvent& event ) { event.Skip(); } diff --git a/common/git/kicad_git_common.cpp b/common/git/kicad_git_common.cpp index b4f7899030..4900bcc2b6 100644 --- a/common/git/kicad_git_common.cpp +++ b/common/git/kicad_git_common.cpp @@ -656,6 +656,59 @@ void KIGIT_COMMON::updateConnectionType() } +int KIGIT_COMMON::HandleSSHKeyAuthentication( git_cred** aOut, const wxString& aUsername ) +{ + if( !( m_testedTypes & KIGIT_CREDENTIAL_SSH_AGENT ) ) + return HandleSSHAgentAuthentication( aOut, aUsername ); + + // SSH key authentication with password + wxString sshKey = GetNextPublicKey(); + + if( sshKey.IsEmpty() ) + { + m_testedTypes |= GIT_CREDENTIAL_SSH_KEY; + return GIT_PASSTHROUGH; + } + + wxString sshPubKey = sshKey + ".pub"; + wxString password = GetPassword(); + + if( git_credential_ssh_key_new( aOut, aUsername.mbc_str(), sshPubKey.mbc_str(), sshKey.mbc_str(), + password.mbc_str() ) != GIT_OK ) + { + wxLogTrace( traceGit, "Failed to create SSH key credential for %s: %s", + aUsername, git_error_last()->message ); + return GIT_ERROR; + } + + return GIT_OK; +} + + +int KIGIT_COMMON::HandlePlaintextAuthentication( git_cred** aOut, const wxString& aUsername ) +{ + wxString password = GetPassword(); + + git_credential_userpass_plaintext_new( aOut, aUsername.mbc_str(), password.mbc_str() ); + m_testedTypes |= GIT_CREDENTIAL_USERPASS_PLAINTEXT; + + return GIT_OK; +} + +int KIGIT_COMMON::HandleSSHAgentAuthentication( git_cred** aOut, const wxString& aUsername ) +{ + if( git_credential_ssh_key_from_agent( aOut, aUsername.mbc_str() ) != GIT_OK ) + { + wxLogTrace( traceGit, "Failed to create SSH agent credential for %s: %s", + aUsername, git_error_last()->message ); + return GIT_ERROR; + } + + m_testedTypes |= KIGIT_CREDENTIAL_SSH_AGENT; + return GIT_OK; +} + + extern "C" int fetchhead_foreach_cb( const char*, const char*, const git_oid* aOID, unsigned int aIsMerge, void* aPayload ) { @@ -789,34 +842,15 @@ extern "C" int credentials_cb( git_cred** aOut, const char* aUrl, const char* aU && ( aAllowedTypes & GIT_CREDENTIAL_USERPASS_PLAINTEXT ) && !( parent->TestedTypes() & GIT_CREDENTIAL_USERPASS_PLAINTEXT ) ) { - wxString username = parent->GetUsername().Trim().Trim( false ); - wxString password = parent->GetPassword().Trim().Trim( false ); - - git_credential_userpass_plaintext_new( aOut, username.ToStdString().c_str(), - password.ToStdString().c_str() ); - parent->TestedTypes() |= GIT_CREDENTIAL_USERPASS_PLAINTEXT; + // Plaintext authentication + return parent->HandlePlaintextAuthentication( aOut, aUsername ); } else if( parent->GetConnType() == KIGIT_COMMON::GIT_CONN_TYPE::GIT_CONN_SSH && ( aAllowedTypes & GIT_CREDENTIAL_SSH_KEY ) && !( parent->TestedTypes() & GIT_CREDENTIAL_SSH_KEY ) ) { // SSH key authentication - wxString sshKey = parent->GetNextPublicKey(); - - if( sshKey.IsEmpty() ) - { - parent->TestedTypes() |= GIT_CREDENTIAL_SSH_KEY; - return GIT_PASSTHROUGH; - } - - wxString sshPubKey = sshKey + ".pub"; - wxString username = parent->GetUsername().Trim().Trim( false ); - wxString password = parent->GetPassword().Trim().Trim( false ); - - git_credential_ssh_key_new( aOut, username.ToStdString().c_str(), - sshPubKey.ToStdString().c_str(), - sshKey.ToStdString().c_str(), - password.ToStdString().c_str() ); + return parent->HandleSSHKeyAuthentication( aOut, aUsername ); } else { diff --git a/common/git/kicad_git_common.h b/common/git/kicad_git_common.h index 560aca0448..f53c838f50 100644 --- a/common/git/kicad_git_common.h +++ b/common/git/kicad_git_common.h @@ -131,6 +131,12 @@ public: return m_publicKeys[m_nextPublicKey++]; } + int HandleSSHKeyAuthentication( git_cred** aOut, const wxString& aUsername ); + + int HandlePlaintextAuthentication( git_cred** aOut, const wxString& aUsername ); + + int HandleSSHAgentAuthentication( git_cred** aOut, const wxString& aUsername ); + protected: git_repository* m_repo; @@ -154,10 +160,13 @@ private: std::vector m_publicKeys; int m_nextPublicKey; + + // Create a dummy flag to tell if we have tested ssh agent credentials separately + // from the ssh key credentials + static const unsigned KIGIT_CREDENTIAL_SSH_AGENT = 1 << sizeof( m_testedTypes - 1 ); }; - -extern "C" int progress_cb( const char* str, int len, void* data ); +extern "C" int progress_cb( const char* str, int len, void* data ); extern "C" void clone_progress_cb( const char* str, size_t len, size_t total, void* data ); extern "C" int transfer_progress_cb( const git_transfer_progress* aStats, void* aPayload ); extern "C" int update_cb( const char* aRefname, const git_oid* aFirst, const git_oid* aSecond,