-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stores generated key to macOS keychain
- Loading branch information
1 parent
608b75b
commit b25e4f7
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
fn main() { | ||
match std::env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() { | ||
"macos" => { | ||
println!("cargo::rustc-link-lib=framework=CoreFoundation"); | ||
println!("cargo::rustc-link-lib=framework=Security"); | ||
println!("cargo::rerun-if-changed=src/key/store/default.m"); | ||
|
||
cc::Build::new() | ||
.file("src/key/store/default.m") | ||
.compile("warpffi") | ||
} | ||
_ => {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#import <CoreFoundation/CoreFoundation.h> | ||
#import <Security/Security.h> | ||
|
||
#import <string.h> | ||
|
||
int default_store_store_key(const UInt8 *id, const UInt8 *key, const char *tag) { | ||
CFMutableDictionaryRef attrs; | ||
CFDataRef bin; | ||
CFStringRef str; | ||
OSStatus status; | ||
|
||
// Setup attributes, | ||
attrs = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); | ||
|
||
CFDictionarySetValue(attrs, kSecClass, kSecClassKey); | ||
|
||
bin = CFDataCreateWithBytesNoCopy(NULL, key, 16, kCFAllocatorNull); | ||
CFDictionarySetValue(attrs, kSecValueData, bin); | ||
CFRelease(bin); | ||
|
||
str = CFStringCreateWithCStringNoCopy(NULL, "Warp File Key", kCFStringEncodingUTF8, kCFAllocatorNull); | ||
CFDictionarySetValue(attrs, kSecAttrLabel, str); | ||
CFRelease(str); | ||
|
||
bin = CFDataCreateWithBytesNoCopy(NULL, id, 16, kCFAllocatorNull); | ||
CFDictionarySetValue(attrs, kSecAttrApplicationLabel, bin); | ||
CFRelease(bin); | ||
|
||
bin = CFDataCreateWithBytesNoCopy(NULL, (const UInt8 *)tag, strlen(tag), kCFAllocatorNull); | ||
CFDictionarySetValue(attrs, kSecAttrApplicationTag, bin); | ||
CFRelease(bin); | ||
|
||
CFDictionarySetValue(attrs, kSecAttrIsPermanent, kCFBooleanTrue); | ||
CFDictionarySetValue(attrs, kSecAttrSynchronizable, kCFBooleanTrue); | ||
CFDictionarySetValue(attrs, kSecUseDataProtectionKeychain, kCFBooleanTrue); | ||
CFDictionarySetValue(attrs, kSecAttrAccessible, kSecAttrAccessibleAfterFirstUnlock); | ||
CFDictionarySetValue(attrs, kSecAttrKeyClass, kSecAttrKeyClassSymmetric); | ||
|
||
// Store key. | ||
status = SecItemAdd(attrs, nil); | ||
CFRelease(attrs); | ||
|
||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters