mirror of
https://github.com/openziti/desktop-edge-win.git
synced 2026-10-13 00:02:50 +00:00
sync UI with test code and start adding errors
This commit is contained in:
@@ -36,7 +36,6 @@ namespace ZitiDesktopEdge {
|
||||
public delegate void ErrorOccurred(string message);
|
||||
public event ErrorOccurred OnError;
|
||||
private string[] _codes = new string[0];
|
||||
DataClient serviceClient = (DataClient)Application.Current.Properties["ServiceClient"];
|
||||
private ZitiIdentity _identity;
|
||||
|
||||
public MFAScreen() {
|
||||
@@ -189,14 +188,15 @@ namespace ZitiDesktopEdge {
|
||||
}
|
||||
|
||||
async private void ToggleRecovery(object sender, MouseButtonEventArgs e) {
|
||||
serviceClient = (DataClient)Application.Current.Properties["ServiceClient"];
|
||||
if (AuthRecoveryArea.Visibility==Visibility.Visible) {
|
||||
GenerateMFACodes(null, null);
|
||||
AuthRecoveryArea.Visibility = Visibility.Collapsed;
|
||||
AuthCodeArea.Visibility = Visibility.Visible;
|
||||
ToggleType.Content = "Use Recovery Code";
|
||||
AuthSubTitle.Content = "Enter your authorization code";
|
||||
Auth1.Focus();
|
||||
} else {
|
||||
ReturnMFACodes(null, null);
|
||||
AuthRecoveryArea.Visibility = Visibility.Visible;
|
||||
AuthCodeArea.Visibility = Visibility.Collapsed;
|
||||
ToggleType.Content = "Use Auth Code";
|
||||
@@ -205,6 +205,7 @@ namespace ZitiDesktopEdge {
|
||||
}
|
||||
}
|
||||
async private void ReturnMFACodes(object sender, MouseButtonEventArgs e) {
|
||||
DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"];
|
||||
string code = Auth1.Text + Auth2.Text + Auth3.Text + Auth4.Text + Auth5.Text + Auth6.Text; //jeremyfix
|
||||
Logger.Debug("AuthMFA successful.");
|
||||
MfaRecoveryCodesResponse getcodes = await serviceClient.ReturnMFACodes(this._identity.Fingerprint, code);
|
||||
@@ -214,6 +215,7 @@ namespace ZitiDesktopEdge {
|
||||
Logger.Error("PAYLOAD: {0}", getcodes.Payload);
|
||||
}
|
||||
async private void GenerateMFACodes(object sender, MouseButtonEventArgs e) {
|
||||
DataClient serviceClient = serviceClient = (DataClient)Application.Current.Properties["ServiceClient"];
|
||||
string code = Rec1.Text + Rec2.Text + Rec3.Text + Rec4.Text + Rec5.Text + Rec6.Text; //jeremyfix
|
||||
MfaRecoveryCodesResponse gencodes = await serviceClient.GenerateMFACodes(this._identity.Fingerprint, code);
|
||||
if (gencodes.Code != 0) {
|
||||
|
||||
+16
-9
@@ -31,6 +31,7 @@ package cziti
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openziti/desktop-edge-win/service/ziti-tunnel/dto"
|
||||
"strings"
|
||||
"unsafe"
|
||||
@@ -39,6 +40,7 @@ import (
|
||||
type mfaCodes struct {
|
||||
codes []string
|
||||
fingerprint string
|
||||
err error
|
||||
}
|
||||
|
||||
var codes = make(chan mfaCodes)
|
||||
@@ -125,7 +127,6 @@ func ziti_mfa_cb_go(_ C.ziti_context, status C.int, fingerprintP *C.char) {
|
||||
ActionEvent: dto.MFA_AUTH_RESPONSE,
|
||||
Fingerprint: fp,
|
||||
IsVerified: false,
|
||||
//ProvisioningUrl: url,
|
||||
RecoveryCodes: nil,
|
||||
}
|
||||
|
||||
@@ -143,7 +144,7 @@ func ziti_mfa_cb_go(_ C.ziti_context, status C.int, fingerprintP *C.char) {
|
||||
goapi.BroadcastEvent(m)
|
||||
}
|
||||
|
||||
func ReturnMfaCodes(id *ZIdentity, fingerprint string, code string) []string {
|
||||
func ReturnMfaCodes(id *ZIdentity, fingerprint string, code string) ([]string, error) {
|
||||
ccode := C.CString(code)
|
||||
defer C.free(unsafe.Pointer(ccode))
|
||||
cfp := C.CString(fingerprint)
|
||||
@@ -155,30 +156,33 @@ func ReturnMfaCodes(id *ZIdentity, fingerprint string, code string) []string {
|
||||
log.Errorf("xxxx ReturnMfaCodesc: %v %v", fingerprint, rtn)
|
||||
if fingerprint != rtn.fingerprint {
|
||||
log.Warnf("unexpected condition correlating mfa codes returned! %s != %s", fingerprint, rtn.fingerprint)
|
||||
return emptyCodes
|
||||
return emptyCodes, rtn.err
|
||||
}
|
||||
return rtn.codes
|
||||
return rtn.codes, rtn.err
|
||||
}
|
||||
|
||||
//export ziti_mfa_recovery_codes_cb_return
|
||||
func ziti_mfa_recovery_codes_cb_return(_ C.ziti_context, status C.int, recoveryCodes **C.char, fingerprintP *C.char) {
|
||||
log.Errorf("xxxx ReturnMfaCodesb: %v %p", status, fingerprintP)
|
||||
fp := C.GoString((*C.char)(fingerprintP))
|
||||
var ego error
|
||||
var theCodes []string
|
||||
if status != C.ZITI_OK {
|
||||
e := C.ziti_errorstr(status)
|
||||
ego := C.GoString(e)
|
||||
ego = fmt.Errorf("%s", C.GoString(e))
|
||||
log.Errorf("Error encounted when returning mfa recovery codes: %v", ego)
|
||||
} else {
|
||||
theCodes = populateStringSlice(recoveryCodes)
|
||||
ego = nil
|
||||
}
|
||||
codes <- mfaCodes{
|
||||
codes: theCodes,
|
||||
fingerprint: fp,
|
||||
err: ego,
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateMfaCodes(id *ZIdentity, fingerprint string, code string) []string {
|
||||
func GenerateMfaCodes(id *ZIdentity, fingerprint string, code string) ([]string, error) {
|
||||
ccode := C.CString(code)
|
||||
defer C.free(unsafe.Pointer(ccode))
|
||||
cfp := C.CString(fingerprint)
|
||||
@@ -190,9 +194,9 @@ func GenerateMfaCodes(id *ZIdentity, fingerprint string, code string) []string {
|
||||
log.Errorf("xxxx GenerateMfaCodesc: %v %v", fingerprint, rtn)
|
||||
if fingerprint != rtn.fingerprint {
|
||||
log.Warnf("unexpected condition correlating mfa codes when regenerating! %s != %s", fingerprint, rtn.fingerprint)
|
||||
return emptyCodes
|
||||
return emptyCodes, rtn.err
|
||||
}
|
||||
return rtn.codes
|
||||
return rtn.codes, rtn.err
|
||||
}
|
||||
|
||||
//export ziti_mfa_recovery_codes_cb_generate
|
||||
@@ -200,16 +204,19 @@ func ziti_mfa_recovery_codes_cb_generate(_ C.ziti_context, status C.int, recover
|
||||
log.Errorf("xxxx GenerateMfaCodesb: %v == %p ==", status, fingerprintP)
|
||||
fp := C.GoString((*C.char)(fingerprintP))
|
||||
var theCodes []string
|
||||
var ego error
|
||||
if status != C.ZITI_OK {
|
||||
e := C.ziti_errorstr(status)
|
||||
ego := C.GoString(e)
|
||||
ego = fmt.Errorf("%s", C.GoString(e))
|
||||
log.Errorf("Error encountedziti_ar_mfa_cb when generating mfa recovery codes: %v", ego)
|
||||
} else {
|
||||
theCodes = populateStringSlice(recoveryCodes)
|
||||
ego = nil
|
||||
}
|
||||
codes <- mfaCodes{
|
||||
codes: theCodes,
|
||||
fingerprint: fp,
|
||||
err: ego,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -504,14 +504,23 @@ func serveIpc(conn net.Conn) {
|
||||
|
||||
func generateMfaCodes(out *json.Encoder, fingerprint string, totpOrRecoveryCode string) {
|
||||
id := rts.Find(fingerprint)
|
||||
codes := cziti.GenerateMfaCodes(id.CId, fingerprint, totpOrRecoveryCode)
|
||||
respond(out, dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: codes})
|
||||
codes, err := cziti.GenerateMfaCodes(id.CId, fingerprint, totpOrRecoveryCode)
|
||||
//respond(out, dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: codes})
|
||||
if err == nil {
|
||||
respond(out, dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: codes})
|
||||
} else {
|
||||
respondWithError(out, "msg", MFA_FAILED_TO_RETURN_CODES, err)
|
||||
}
|
||||
}
|
||||
|
||||
func returnMfaCodes(out *json.Encoder, fingerprint string, totpOrRecoveryCode string) {
|
||||
id := rts.Find(fingerprint)
|
||||
codes := cziti.ReturnMfaCodes(id.CId, fingerprint, totpOrRecoveryCode)
|
||||
respond(out, dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: codes})
|
||||
codes, err := cziti.ReturnMfaCodes(id.CId, fingerprint, totpOrRecoveryCode)
|
||||
if err == nil {
|
||||
respond(out, dto.Response{Message: "success", Code: SUCCESS, Error: "", Payload: codes})
|
||||
} else {
|
||||
respondWithError(out, "msg", MFA_FAILED_TO_RETURN_CODES, err)
|
||||
}
|
||||
}
|
||||
|
||||
func enableMfa(out *json.Encoder, fingerprint string) {
|
||||
|
||||
@@ -58,6 +58,9 @@ const (
|
||||
ERROR_DISCONNECTING_ID = 50
|
||||
IDENTITY_NOT_FOUND = 1000
|
||||
|
||||
MFA_FAILED_TO_GENERATE_CODES = 200
|
||||
MFA_FAILED_TO_RETURN_CODES = 201
|
||||
|
||||
DEFAULT_REFRESH_INTERVAL = 10
|
||||
|
||||
cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
|
||||
|
||||
Reference in New Issue
Block a user