feat: add libse
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -7,6 +7,11 @@ debug/
|
||||
target/
|
||||
.idea/
|
||||
|
||||
libse.a
|
||||
se.swiftdoc
|
||||
se.swiftmodule
|
||||
se.swiftsourceinfo
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
@@ -20,7 +25,8 @@ target/
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
2
justfile
2
justfile
@@ -9,3 +9,5 @@ build:
|
||||
build-no-features:
|
||||
cargo build --release --no-default-features
|
||||
|
||||
compile-libse-static:
|
||||
cd swift && swiftc se.swift -emit-module -emit-library -static
|
||||
|
||||
64
swift/se.swift
Normal file
64
swift/se.swift
Normal file
@@ -0,0 +1,64 @@
|
||||
// import Swift
|
||||
import Foundation
|
||||
// import Security
|
||||
import CryptoKit
|
||||
import LocalAuthentication
|
||||
|
||||
func is_support_secure_enclave() -> Bool {
|
||||
let se = SecureEnclave.isAvailable
|
||||
print("Supports SE: \(se)")
|
||||
return se
|
||||
}
|
||||
|
||||
enum StringError: Error {
|
||||
case base64error
|
||||
}
|
||||
|
||||
|
||||
// // var error: Unmanaged<CFError>? = nil;
|
||||
// // guard
|
||||
// // let accessCtrl = SecAccessControlCreateWithFlags(
|
||||
// // nil,
|
||||
// // kSecAttrAccessibleWhenUnlockedThisDeviceOnly,
|
||||
// // [.privateKeyUsage, .biometryCurrentSet],
|
||||
// // &error
|
||||
// // ) else {
|
||||
// // throw error!.takeRetainedValue() as Swift.Error
|
||||
// // }
|
||||
// // var privateKeyReference = try CryptoKit.SecureEnclave.P256.KeyAgreement.PrivateKey.init(
|
||||
// // accessControl: accessCtrl
|
||||
// // );
|
||||
// // var dataRepresentation = privateKeyReference.dataRepresentation;
|
||||
//
|
||||
// guard let dataRepresentation = Data(base64Encoded: "BIIB2DGCAdQwgfUMAnJrMYHuMAsMA2JpZAQElxyY8jBIDANwdWIEQQQOrOKfvtBWnEquk6+92hH5yxO6SN5TSIA7/kP0DMdzRlojtNQJ3RUs7uJfG/stjJ/Cza+1i+hISbAGaL0BasDPMAgMA3JrbwIBADAHD-----") else {
|
||||
// throw StringError.base64error
|
||||
// }
|
||||
//
|
||||
//
|
||||
// let context = LAContext();
|
||||
// let p = try SecureEnclave.P256.KeyAgreement.PrivateKey(
|
||||
// dataRepresentation: dataRepresentation, authenticationContext: context)
|
||||
//
|
||||
// let ephemeralSecretKey = P256.KeyAgreement.PrivateKey()
|
||||
// let sharedSecret = try ephemeralSecretKey.sharedSecretFromKeyAgreement(with: p.publicKey)
|
||||
//
|
||||
//
|
||||
// let sharedSecret2 = try p.sharedSecretFromKeyAgreement(with: ephemeralSecretKey.publicKey)
|
||||
//
|
||||
//
|
||||
//
|
||||
// // print("Private key reference: \(privateKeyReference)");
|
||||
//
|
||||
// // print("Private key reference - publicKey: \(privateKeyReference.publicKey)");
|
||||
//
|
||||
// // // print("Private key reference - publicKey - ageRecipient: \(privateKeyReference.publicKey.ageRecipient)");
|
||||
//
|
||||
// // print("Private key reference - dataRepresentation: \(privateKeyReference.dataRepresentation)");
|
||||
// // print("Private key reference - dataRepresentation: \(privateKeyReference.dataRepresentation.base64EncodedString())");
|
||||
//
|
||||
// // https://www.andyibanez.com/posts/cryptokit-secure-enclave/
|
||||
//
|
||||
//
|
||||
//
|
||||
// print("Shared secret: \(sharedSecret)")
|
||||
// print("Shared secret: \(sharedSecret2)")
|
||||
Reference in New Issue
Block a user