Skip to content

Commit

Permalink
Add local fork of the go-touchid library
Browse files Browse the repository at this point in the history
  • Loading branch information
eth-p committed Apr 23, 2023
1 parent 1170eb6 commit afb7d78
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go-touchid/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/lox/go-touchid

go 1.16
60 changes: 60 additions & 0 deletions go-touchid/touchid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package touchid

// Forked from: https://github.com/lox/go-touchid
// Commit 619cc8e578d0ef916aa29c806117c370f9d621cb
// Unknown license.

/*
#cgo CFLAGS: -x objective-c -fmodules -fblocks
#cgo LDFLAGS: -framework CoreFoundation -framework LocalAuthentication -framework Foundation
#include <stdlib.h>
#include <stdio.h>
#import <LocalAuthentication/LocalAuthentication.h>
int Authenticate(char const* reason) {
LAContext *myContext = [[LAContext alloc] init];
NSError *authError = nil;
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSString *nsReason = [NSString stringWithUTF8String:reason];
__block int result = 0;
if ([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&authError]) {
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
localizedReason:nsReason
reply:^(BOOL success, NSError *error) {
if (success) {
result = 1;
} else {
result = 2;
}
dispatch_semaphore_signal(sema);
}];
}
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
dispatch_release(sema);
return result;
}
*/
import (
"C"
)
import (
"errors"
"unsafe"
)

func Authenticate(reason string) (bool, error) {
reasonStr := C.CString(reason)
defer C.free(unsafe.Pointer(reasonStr))

result := C.Authenticate(reasonStr)
switch result {
case 1:
return true, nil
case 2:
return false, nil
}

return false, errors.New("Error occurred accessing biometrics")
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/jorgelbg/pinentry-touchid
go 1.16

replace github.com/foxcpp/go-assuan => ./go-assuan
replace github.com/lox/go-touchid => ./go-touchid

require (
github.com/enescakir/emoji v1.0.0 // indirect
Expand Down

0 comments on commit afb7d78

Please sign in to comment.