SlideShare a Scribd company logo
IOS KEYCHAIN
HappyMan
2014/12/30
What is KeyChain
• Keychain is an encrypted container where you
can store secured information like passwords,
certificates, identities, …etc.
• In iOS, each application has its own keychain.
• To share the data between apps, they should
have the same Access Group in code signing
entitlements.
Accessing password-protected services
using a keychain in OS X
Accessing
an Internet
server using
iPhone
Keychain
Services
• KeyChain 是 iOS 提供的一種安全保存私密資
料的方式,整個系統的 keychain 被保存在
隱秘的位置
(/private/var/Keychains/keychain-2.db),
其中保存的資料是經過加密的。
優點
• 每個組( keychain-access-groups )之間資料存
取隔離,沒有權限的 app無法讀取他人資料,
保證資料的安全
• 全域性統一儲存,即使刪除 app , keychain
中的資料依然存在,下次重新安裝app還能
存取
• 存儲後的資料會加密
• 同一個組的 app 可以共享 keychain 中的資
料
缺點
• 刪除 app 後不會清除 keychain 裡的資料,
如果儲存密碼等敏感性資料有一定的風險。
(越獄後 keychain 能被導出來)
實作API
• 新增:SecItemAdd
• 尋找:SecItemCopyMatching
• 更新:SecItemUpdate
• 移除:SecItemDelete
準備資料
• -(NSMutableDictionary *) prepareDict:(NSString *)key
• {
• NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
• [dict setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
•
• NSData *encodedKey = [key dataUsingEncoding:NSUTF8StringEncoding];
• [dict setObject:encodedKey forKey:(__bridge id)kSecAttrGeneric];
• [dict setObject:encodedKey forKey:(__bridge id)kSecAttrAccount];
• [dict setObject:service forKey:(__bridge id)kSecAttrService];
• [dict setObject:(__bridge id)kSecAttrAccessibleAlwaysThisDeviceOnly forKey:(__bridge
id)kSecAttrAccessible];
•
• return dict;
• }
新增
• -(BOOL) insert:(NSString *)key :(NSData *)data
• {
• NSMutableDictionary *dict =[self prepareDict:key];
• [dict setObject:data forKey:(__bridge id)kSecValueData];
•
• OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dict,
NULL);
• if(errSecSuccess != status) {
• NSLog(@"Unable add item with key = %@ error:
%d",key,(int)status);
• }
• return (status == errSecSuccess);
• }
尋找
• -(NSData*) find:(NSString *)key
• {
• NSMutableDictionary *dict = [self prepareDict:key];
• [dict setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
• [dict setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
• CFTypeRef result = NULL;
• OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dict,&result);
•
• if(status != errSecSuccess) {
• NSLog(@"Unable to fetch item for key %@ with error: %d",key,(int)status);
• return nil;
• }
•
• return (__bridge NSData *)result;
• }
更新
• -(BOOL) update:(NSString*)key :(NSData *)data
• {
• NSMutableDictionary *dictKey =[self prepareDict:key];
•
• NSMutableDictionary *dictUpdate =[[NSMutableDictionary alloc] init];
• [dictUpdate setObject:data forKey:(__bridge id)kSecValueData];
•
• OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)dictKey, (__bridge
CFDictionaryRef)dictUpdate);
• if(status != errSecSuccess) {
• NSLog(@"Unable add update with key = %@ error: %d",key,(int)status);
• }
• return (status == errSecSuccess);
• }
移除
• -(BOOL) remove:(NSString *)key
• {
• NSMutableDictionary *dict = [self prepareDict:key];
• OSStatus status = SecItemDelete((__bridge
CFDictionaryRef)dict);
• if(status != errSecSuccess) {
• NSLog(@"Unable to remove item for key %@ with error:
%d",key,(int)status);
• }
• return (status == errSecSuccess);
• }
開源
• SSKeychain
https://github.com/soffes/sskeychain
Star: 1730 (2014/12/30)
• SFHFKeychainUtils
https://github.com/kamiro/SFHFKeychainUtils
Star: 60 (2014/12/30)
• Me: 2 projects
Demo
• https://github.com/happymanx/KeyChainTest
– 1). Initialization of the class
– 2). How to Add an item to keychain
– 3). Find an item in the keychain
– 4). Update an item in the keychain
– 5). Remove an item from keychain
參考
• iOS KeyChain Tutorial
http://hayageek.com/ios-keychain-tutorial/
• Securing and Encrypting Data on iOS
http://code.tutsplus.com/tutorials/securing-and-
encrypting-data-on-ios--mobile-21263
• Basic Security in iOS 5 – Part 1
http://www.raywenderlich.com/6475/basic-
security-in-ios-5-tutorial-part-1
• Basic Security in iOS 5 – Part 2
http://www.raywenderlich.com/6603/basic-
security-in-ios-5-tutorial-part-2
參考
• iOS Keychain: Sharing data between apps
http://shaune.com.au/ios-keychain-sharing-data-
between-apps/
• Keychain Group Access
http://useyourloaf.com/blog/2010/04/03/keycha
in-group-access.html
• 將密碼儲存於 KeyChain
http://wp.me/p1my2P-3S0
• KeyChain 使用與共享數據
http://blog.csdn.net/ibcker/article/details/24839
143
Apple連結
• Keychain Services Programming Guide
https://developer.apple.com/library/mac/docum
entation/Security/Conceptual/keychainServConc
epts/
• Keychain Services Reference
https://developer.apple.com/library/mac/docum
entation/Security/Reference/keychainservices/
• #WWDC14 session 711 - Keychain and
Authentication with Touch ID

More Related Content

What's hot

John the ripper & hydra password cracking tool
John the ripper & hydra password cracking toolJohn the ripper & hydra password cracking tool
John the ripper & hydra password cracking tool
Md. Raquibul Hoque
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Geeks Anonymes
 
Foreman Single Sign-On Made Easy with Keycloak
Foreman Single Sign-On Made Easy with KeycloakForeman Single Sign-On Made Easy with Keycloak
Foreman Single Sign-On Made Easy with Keycloak
Nikhil Kathole
 
CEHv9 : module 15 - hacking mobile platforms
CEHv9 : module 15 - hacking mobile platformsCEHv9 : module 15 - hacking mobile platforms
CEHv9 : module 15 - hacking mobile platforms
teknetir
 
iOS Development - A Beginner Guide
iOS Development - A Beginner GuideiOS Development - A Beginner Guide
iOS Development - A Beginner Guide
Andri Yadi
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
iOS Security and Encryption
iOS Security and EncryptioniOS Security and Encryption
iOS Security and Encryption
Urvashi Kataria
 
Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
Paul V. Novarese
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
Chandan Kumar Rana
 
An introduction to SSH
An introduction to SSHAn introduction to SSH
An introduction to SSH
nussbauml
 
Android組込み開発基礎コース Armadillo-440編
Android組込み開発基礎コース Armadillo-440編Android組込み開発基礎コース Armadillo-440編
Android組込み開発基礎コース Armadillo-440編
OESF Education
 
Ethical hacking
Ethical hackingEthical hacking
Ethical hacking
AKSHAY KHATRI
 
Hacking and securing ios applications
Hacking and securing ios applicationsHacking and securing ios applications
Hacking and securing ios applications
Satish b
 
Module 02 ftk imager
Module 02 ftk imagerModule 02 ftk imager
Module 02 ftk imager
ParminderKaurBScHons
 
Introduction to Metasploit
Introduction to MetasploitIntroduction to Metasploit
Introduction to Metasploit
GTU
 
AndroidとSELinux
AndroidとSELinuxAndroidとSELinux
AndroidとSELinux
android sola
 
package mangement
package mangementpackage mangement
package mangement
ARYA TM
 
Mobile Security 101
Mobile Security 101Mobile Security 101
Mobile Security 101
Lookout
 
PHP Security
PHP SecurityPHP Security
PHP Security
Mindfire Solutions
 
Desktop and Server Security
Desktop and Server SecurityDesktop and Server Security
Desktop and Server Security
Abhinit Kumar Sharma
 

What's hot (20)

John the ripper & hydra password cracking tool
John the ripper & hydra password cracking toolJohn the ripper & hydra password cracking tool
John the ripper & hydra password cracking tool
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Foreman Single Sign-On Made Easy with Keycloak
Foreman Single Sign-On Made Easy with KeycloakForeman Single Sign-On Made Easy with Keycloak
Foreman Single Sign-On Made Easy with Keycloak
 
CEHv9 : module 15 - hacking mobile platforms
CEHv9 : module 15 - hacking mobile platformsCEHv9 : module 15 - hacking mobile platforms
CEHv9 : module 15 - hacking mobile platforms
 
iOS Development - A Beginner Guide
iOS Development - A Beginner GuideiOS Development - A Beginner Guide
iOS Development - A Beginner Guide
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
 
iOS Security and Encryption
iOS Security and EncryptioniOS Security and Encryption
iOS Security and Encryption
 
Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
An introduction to SSH
An introduction to SSHAn introduction to SSH
An introduction to SSH
 
Android組込み開発基礎コース Armadillo-440編
Android組込み開発基礎コース Armadillo-440編Android組込み開発基礎コース Armadillo-440編
Android組込み開発基礎コース Armadillo-440編
 
Ethical hacking
Ethical hackingEthical hacking
Ethical hacking
 
Hacking and securing ios applications
Hacking and securing ios applicationsHacking and securing ios applications
Hacking and securing ios applications
 
Module 02 ftk imager
Module 02 ftk imagerModule 02 ftk imager
Module 02 ftk imager
 
Introduction to Metasploit
Introduction to MetasploitIntroduction to Metasploit
Introduction to Metasploit
 
AndroidとSELinux
AndroidとSELinuxAndroidとSELinux
AndroidとSELinux
 
package mangement
package mangementpackage mangement
package mangement
 
Mobile Security 101
Mobile Security 101Mobile Security 101
Mobile Security 101
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
Desktop and Server Security
Desktop and Server SecurityDesktop and Server Security
Desktop and Server Security
 

Viewers also liked

Security and Encryption on iOS
Security and Encryption on iOSSecurity and Encryption on iOS
Security and Encryption on iOS
Graham Lee
 
iOS Application Exploitation
iOS Application ExploitationiOS Application Exploitation
iOS Application Exploitation
Positive Hack Days
 
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC GroupA (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
EC-Council
 
Introduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason ShapiroIntroduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason Shapiro
Mobile March
 
Power of linked list
Power of linked listPower of linked list
Power of linked list
Peter Hlavaty
 
iOS Application Penetation Test
iOS Application Penetation TestiOS Application Penetation Test
iOS Application Penetation Test
JongWon Kim
 
iOS Application Security
iOS Application SecurityiOS Application Security
iOS Application Security
Egor Tolstoy
 
IOS Encryption Systems
IOS Encryption SystemsIOS Encryption Systems
IOS Encryption Systems
Peter Teufl
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
Peter Hlavaty
 
Reverse Engineering iOS apps
Reverse Engineering iOS appsReverse Engineering iOS apps
Reverse Engineering iOS apps
Max Bazaliy
 
Layer architecture of ios (1)
Layer architecture of ios (1)Layer architecture of ios (1)
Layer architecture of ios (1)
dwipalp
 
Android vs ios System Architecture in OS perspective
Android vs ios System Architecture in OS perspectiveAndroid vs ios System Architecture in OS perspective
Android vs ios System Architecture in OS perspective
Raj Pratim Bhattacharya
 
Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
Massimo Oliviero
 
Apple iOS Report
Apple iOS ReportApple iOS Report
Apple iOS Report
Chetan Gowda
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
Harry Lovylife
 
Apple iOS
Apple iOSApple iOS
Apple iOS
Chetan Gowda
 
iOS platform
iOS platformiOS platform
iOS platform
maya_slides
 
Srinumanne ios operating system ppt
Srinumanne ios operating system pptSrinumanne ios operating system ppt
Srinumanne ios operating system ppt
Srinu Manne
 

Viewers also liked (18)

Security and Encryption on iOS
Security and Encryption on iOSSecurity and Encryption on iOS
Security and Encryption on iOS
 
iOS Application Exploitation
iOS Application ExploitationiOS Application Exploitation
iOS Application Exploitation
 
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC GroupA (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
A (not-so-quick) Primer on iOS Encryption David Schuetz - NCC Group
 
Introduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason ShapiroIntroduction to Core Data - Jason Shapiro
Introduction to Core Data - Jason Shapiro
 
Power of linked list
Power of linked listPower of linked list
Power of linked list
 
iOS Application Penetation Test
iOS Application Penetation TestiOS Application Penetation Test
iOS Application Penetation Test
 
iOS Application Security
iOS Application SecurityiOS Application Security
iOS Application Security
 
IOS Encryption Systems
IOS Encryption SystemsIOS Encryption Systems
IOS Encryption Systems
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
 
Reverse Engineering iOS apps
Reverse Engineering iOS appsReverse Engineering iOS apps
Reverse Engineering iOS apps
 
Layer architecture of ios (1)
Layer architecture of ios (1)Layer architecture of ios (1)
Layer architecture of ios (1)
 
Android vs ios System Architecture in OS perspective
Android vs ios System Architecture in OS perspectiveAndroid vs ios System Architecture in OS perspective
Android vs ios System Architecture in OS perspective
 
Architecting iOS Project
Architecting iOS ProjectArchitecting iOS Project
Architecting iOS Project
 
Apple iOS Report
Apple iOS ReportApple iOS Report
Apple iOS Report
 
Presentation on iOS
Presentation on iOSPresentation on iOS
Presentation on iOS
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
iOS platform
iOS platformiOS platform
iOS platform
 
Srinumanne ios operating system ppt
Srinumanne ios operating system pptSrinumanne ios operating system ppt
Srinumanne ios operating system ppt
 

Similar to iOS Keychain 介紹

Local Authentication par Pierre-Alban Toth
Local Authentication par Pierre-Alban TothLocal Authentication par Pierre-Alban Toth
Local Authentication par Pierre-Alban Toth
CocoaHeads France
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
Petr Dvorak
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
smn-automate
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
Petr Dvorak
 
7.3. iCloud keychain-2
7.3. iCloud keychain-27.3. iCloud keychain-2
7.3. iCloud keychain-2
defconmoscow
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Yandex
 
React Native Course - Data Storage . pdf
React Native Course - Data Storage . pdfReact Native Course - Data Storage . pdf
React Native Course - Data Storage . pdf
AlvianZachryFaturrah
 
iOS5 NewStuff
iOS5 NewStuffiOS5 NewStuff
iOS5 NewStuff
deenna_vargilz
 
iOS secure app development
iOS secure app developmentiOS secure app development
iOS secure app development
Dusan Klinec
 
Azure Low Lands 2019 - Building secure cloud applications with Azure Key Vault
Azure Low Lands 2019 - Building secure cloud applications with Azure Key VaultAzure Low Lands 2019 - Building secure cloud applications with Azure Key Vault
Azure Low Lands 2019 - Building secure cloud applications with Azure Key Vault
Tom Kerkhove
 
6.1. iCloud keychain and iOS 7 data protection
6.1. iCloud keychain and iOS 7 data protection6.1. iCloud keychain and iOS 7 data protection
6.1. iCloud keychain and iOS 7 data protection
defconmoscow
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
Satoshi Asano
 
Managing your secrets in a cloud environment
Managing your secrets in a cloud environmentManaging your secrets in a cloud environment
Managing your secrets in a cloud environment
Taswar Bhatti
 
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
kadalisrikanth
 
Synapse india iphone apps presentation oncracking and analyzing apple icloud
Synapse india iphone apps  presentation oncracking and analyzing apple icloudSynapse india iphone apps  presentation oncracking and analyzing apple icloud
Synapse india iphone apps presentation oncracking and analyzing apple icloud
SynapseIndiaiPhoneApps
 
Azure Key Vault - Getting Started
Azure Key Vault - Getting StartedAzure Key Vault - Getting Started
Azure Key Vault - Getting Started
Taswar Bhatti
 
Django cryptography
Django cryptographyDjango cryptography
Django cryptography
Erik LaBianca
 
Intelligent Cloud Conference 2018 - Building secure cloud applications with A...
Intelligent Cloud Conference 2018 - Building secure cloud applications with A...Intelligent Cloud Conference 2018 - Building secure cloud applications with A...
Intelligent Cloud Conference 2018 - Building secure cloud applications with A...
Tom Kerkhove
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical Stuff
Petr Dvorak
 
Techdays Finland 2018 - Building secure cloud applications with Azure Key Vault
Techdays Finland 2018 - Building secure cloud applications with Azure Key VaultTechdays Finland 2018 - Building secure cloud applications with Azure Key Vault
Techdays Finland 2018 - Building secure cloud applications with Azure Key Vault
Tom Kerkhove
 

Similar to iOS Keychain 介紹 (20)

Local Authentication par Pierre-Alban Toth
Local Authentication par Pierre-Alban TothLocal Authentication par Pierre-Alban Toth
Local Authentication par Pierre-Alban Toth
 
FI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS BasicsFI MUNI 2012 - iOS Basics
FI MUNI 2012 - iOS Basics
 
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
CocoaHeads PDX 2014 01 23 : CoreData and iCloud Improvements iOS7 / OSX Maver...
 
MFF UK - Introduction to iOS
MFF UK - Introduction to iOSMFF UK - Introduction to iOS
MFF UK - Introduction to iOS
 
7.3. iCloud keychain-2
7.3. iCloud keychain-27.3. iCloud keychain-2
7.3. iCloud keychain-2
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
 
React Native Course - Data Storage . pdf
React Native Course - Data Storage . pdfReact Native Course - Data Storage . pdf
React Native Course - Data Storage . pdf
 
iOS5 NewStuff
iOS5 NewStuffiOS5 NewStuff
iOS5 NewStuff
 
iOS secure app development
iOS secure app developmentiOS secure app development
iOS secure app development
 
Azure Low Lands 2019 - Building secure cloud applications with Azure Key Vault
Azure Low Lands 2019 - Building secure cloud applications with Azure Key VaultAzure Low Lands 2019 - Building secure cloud applications with Azure Key Vault
Azure Low Lands 2019 - Building secure cloud applications with Azure Key Vault
 
6.1. iCloud keychain and iOS 7 data protection
6.1. iCloud keychain and iOS 7 data protection6.1. iCloud keychain and iOS 7 data protection
6.1. iCloud keychain and iOS 7 data protection
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
 
Managing your secrets in a cloud environment
Managing your secrets in a cloud environmentManaging your secrets in a cloud environment
Managing your secrets in a cloud environment
 
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
Secureerasurecodebasedcloudstoragesystemwithsecuredataforwarding
 
Synapse india iphone apps presentation oncracking and analyzing apple icloud
Synapse india iphone apps  presentation oncracking and analyzing apple icloudSynapse india iphone apps  presentation oncracking and analyzing apple icloud
Synapse india iphone apps presentation oncracking and analyzing apple icloud
 
Azure Key Vault - Getting Started
Azure Key Vault - Getting StartedAzure Key Vault - Getting Started
Azure Key Vault - Getting Started
 
Django cryptography
Django cryptographyDjango cryptography
Django cryptography
 
Intelligent Cloud Conference 2018 - Building secure cloud applications with A...
Intelligent Cloud Conference 2018 - Building secure cloud applications with A...Intelligent Cloud Conference 2018 - Building secure cloud applications with A...
Intelligent Cloud Conference 2018 - Building secure cloud applications with A...
 
iOS 2 - The practical Stuff
iOS 2 - The practical StuffiOS 2 - The practical Stuff
iOS 2 - The practical Stuff
 
Techdays Finland 2018 - Building secure cloud applications with Azure Key Vault
Techdays Finland 2018 - Building secure cloud applications with Azure Key VaultTechdays Finland 2018 - Building secure cloud applications with Azure Key Vault
Techdays Finland 2018 - Building secure cloud applications with Azure Key Vault
 

More from ShengWen Chiou

iOS Extension
iOS ExtensioniOS Extension
iOS Extension
ShengWen Chiou
 
FMDB 研究
FMDB 研究FMDB 研究
FMDB 研究
ShengWen Chiou
 
Realm 研究
Realm 研究Realm 研究
Realm 研究
ShengWen Chiou
 
Crashlytics 使用教學
Crashlytics 使用教學Crashlytics 使用教學
Crashlytics 使用教學
ShengWen Chiou
 
DBAccess 研究
DBAccess 研究DBAccess 研究
DBAccess 研究
ShengWen Chiou
 
Xamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class LibraryXamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class Library
ShengWen Chiou
 
Xamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class LibraryXamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class Library
ShengWen Chiou
 
iBeacon 相關應用
iBeacon 相關應用iBeacon 相關應用
iBeacon 相關應用
ShengWen Chiou
 
Xamarin 研究
Xamarin 研究Xamarin 研究
Xamarin 研究
ShengWen Chiou
 
What’s New In watch OS
What’s New In watch OSWhat’s New In watch OS
What’s New In watch OS
ShengWen Chiou
 
Apple Watch Feature
Apple Watch FeatureApple Watch Feature
Apple Watch Feature
ShengWen Chiou
 
Symbolicate Crash 使用教學
Symbolicate Crash 使用教學Symbolicate Crash 使用教學
Symbolicate Crash 使用教學
ShengWen Chiou
 
Apple Watch Specifications
Apple Watch SpecificationsApple Watch Specifications
Apple Watch Specifications
ShengWen Chiou
 
Apple Watch UI Elements
Apple Watch UI ElementsApple Watch UI Elements
Apple Watch UI Elements
ShengWen Chiou
 
Apple Watch Human Interface Guidelines
Apple Watch Human Interface GuidelinesApple Watch Human Interface Guidelines
Apple Watch Human Interface Guidelines
ShengWen Chiou
 
Quickblox Study
Quickblox StudyQuickblox Study
Quickblox Study
ShengWen Chiou
 
Auto layout 介紹
Auto layout 介紹Auto layout 介紹
Auto layout 介紹
ShengWen Chiou
 
iOS Touch ID 介紹
iOS Touch ID 介紹iOS Touch ID 介紹
iOS Touch ID 介紹
ShengWen Chiou
 
CocoaPods 使用教學
CocoaPods 使用教學CocoaPods 使用教學
CocoaPods 使用教學
ShengWen Chiou
 

More from ShengWen Chiou (20)

iOS Extension
iOS ExtensioniOS Extension
iOS Extension
 
FMDB 研究
FMDB 研究FMDB 研究
FMDB 研究
 
Realm 研究
Realm 研究Realm 研究
Realm 研究
 
Crashlytics 使用教學
Crashlytics 使用教學Crashlytics 使用教學
Crashlytics 使用教學
 
DBAccess 研究
DBAccess 研究DBAccess 研究
DBAccess 研究
 
Xamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class LibraryXamarin.iOS中引用第三方Objective-C的Class Library
Xamarin.iOS中引用第三方Objective-C的Class Library
 
Xamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class LibraryXamarin.iOS中引用自製Objective-C的Class Library
Xamarin.iOS中引用自製Objective-C的Class Library
 
iBeacon 相關應用
iBeacon 相關應用iBeacon 相關應用
iBeacon 相關應用
 
Xamarin 研究
Xamarin 研究Xamarin 研究
Xamarin 研究
 
What’s New In watch OS
What’s New In watch OSWhat’s New In watch OS
What’s New In watch OS
 
Apple Watch Feature
Apple Watch FeatureApple Watch Feature
Apple Watch Feature
 
Symbolicate Crash 使用教學
Symbolicate Crash 使用教學Symbolicate Crash 使用教學
Symbolicate Crash 使用教學
 
Apple Watch Specifications
Apple Watch SpecificationsApple Watch Specifications
Apple Watch Specifications
 
Apple Watch UI Elements
Apple Watch UI ElementsApple Watch UI Elements
Apple Watch UI Elements
 
Apple Watch Human Interface Guidelines
Apple Watch Human Interface GuidelinesApple Watch Human Interface Guidelines
Apple Watch Human Interface Guidelines
 
AppleDoc 使用教學
AppleDoc 使用教學AppleDoc 使用教學
AppleDoc 使用教學
 
Quickblox Study
Quickblox StudyQuickblox Study
Quickblox Study
 
Auto layout 介紹
Auto layout 介紹Auto layout 介紹
Auto layout 介紹
 
iOS Touch ID 介紹
iOS Touch ID 介紹iOS Touch ID 介紹
iOS Touch ID 介紹
 
CocoaPods 使用教學
CocoaPods 使用教學CocoaPods 使用教學
CocoaPods 使用教學
 

Recently uploaded

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 

Recently uploaded (20)

OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 

iOS Keychain 介紹

  • 2. What is KeyChain • Keychain is an encrypted container where you can store secured information like passwords, certificates, identities, …etc. • In iOS, each application has its own keychain. • To share the data between apps, they should have the same Access Group in code signing entitlements.
  • 5. • KeyChain 是 iOS 提供的一種安全保存私密資 料的方式,整個系統的 keychain 被保存在 隱秘的位置 (/private/var/Keychains/keychain-2.db), 其中保存的資料是經過加密的。
  • 6. 優點 • 每個組( keychain-access-groups )之間資料存 取隔離,沒有權限的 app無法讀取他人資料, 保證資料的安全 • 全域性統一儲存,即使刪除 app , keychain 中的資料依然存在,下次重新安裝app還能 存取 • 存儲後的資料會加密 • 同一個組的 app 可以共享 keychain 中的資 料
  • 7. 缺點 • 刪除 app 後不會清除 keychain 裡的資料, 如果儲存密碼等敏感性資料有一定的風險。 (越獄後 keychain 能被導出來)
  • 8.
  • 9. 實作API • 新增:SecItemAdd • 尋找:SecItemCopyMatching • 更新:SecItemUpdate • 移除:SecItemDelete
  • 10. 準備資料 • -(NSMutableDictionary *) prepareDict:(NSString *)key • { • NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; • [dict setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass]; • • NSData *encodedKey = [key dataUsingEncoding:NSUTF8StringEncoding]; • [dict setObject:encodedKey forKey:(__bridge id)kSecAttrGeneric]; • [dict setObject:encodedKey forKey:(__bridge id)kSecAttrAccount]; • [dict setObject:service forKey:(__bridge id)kSecAttrService]; • [dict setObject:(__bridge id)kSecAttrAccessibleAlwaysThisDeviceOnly forKey:(__bridge id)kSecAttrAccessible]; • • return dict; • }
  • 11. 新增 • -(BOOL) insert:(NSString *)key :(NSData *)data • { • NSMutableDictionary *dict =[self prepareDict:key]; • [dict setObject:data forKey:(__bridge id)kSecValueData]; • • OSStatus status = SecItemAdd((__bridge CFDictionaryRef)dict, NULL); • if(errSecSuccess != status) { • NSLog(@"Unable add item with key = %@ error: %d",key,(int)status); • } • return (status == errSecSuccess); • }
  • 12. 尋找 • -(NSData*) find:(NSString *)key • { • NSMutableDictionary *dict = [self prepareDict:key]; • [dict setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit]; • [dict setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData]; • CFTypeRef result = NULL; • OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)dict,&result); • • if(status != errSecSuccess) { • NSLog(@"Unable to fetch item for key %@ with error: %d",key,(int)status); • return nil; • } • • return (__bridge NSData *)result; • }
  • 13. 更新 • -(BOOL) update:(NSString*)key :(NSData *)data • { • NSMutableDictionary *dictKey =[self prepareDict:key]; • • NSMutableDictionary *dictUpdate =[[NSMutableDictionary alloc] init]; • [dictUpdate setObject:data forKey:(__bridge id)kSecValueData]; • • OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)dictKey, (__bridge CFDictionaryRef)dictUpdate); • if(status != errSecSuccess) { • NSLog(@"Unable add update with key = %@ error: %d",key,(int)status); • } • return (status == errSecSuccess); • }
  • 14. 移除 • -(BOOL) remove:(NSString *)key • { • NSMutableDictionary *dict = [self prepareDict:key]; • OSStatus status = SecItemDelete((__bridge CFDictionaryRef)dict); • if(status != errSecSuccess) { • NSLog(@"Unable to remove item for key %@ with error: %d",key,(int)status); • } • return (status == errSecSuccess); • }
  • 15. 開源 • SSKeychain https://github.com/soffes/sskeychain Star: 1730 (2014/12/30) • SFHFKeychainUtils https://github.com/kamiro/SFHFKeychainUtils Star: 60 (2014/12/30) • Me: 2 projects
  • 16. Demo • https://github.com/happymanx/KeyChainTest – 1). Initialization of the class – 2). How to Add an item to keychain – 3). Find an item in the keychain – 4). Update an item in the keychain – 5). Remove an item from keychain
  • 17. 參考 • iOS KeyChain Tutorial http://hayageek.com/ios-keychain-tutorial/ • Securing and Encrypting Data on iOS http://code.tutsplus.com/tutorials/securing-and- encrypting-data-on-ios--mobile-21263 • Basic Security in iOS 5 – Part 1 http://www.raywenderlich.com/6475/basic- security-in-ios-5-tutorial-part-1 • Basic Security in iOS 5 – Part 2 http://www.raywenderlich.com/6603/basic- security-in-ios-5-tutorial-part-2
  • 18. 參考 • iOS Keychain: Sharing data between apps http://shaune.com.au/ios-keychain-sharing-data- between-apps/ • Keychain Group Access http://useyourloaf.com/blog/2010/04/03/keycha in-group-access.html • 將密碼儲存於 KeyChain http://wp.me/p1my2P-3S0 • KeyChain 使用與共享數據 http://blog.csdn.net/ibcker/article/details/24839 143
  • 19. Apple連結 • Keychain Services Programming Guide https://developer.apple.com/library/mac/docum entation/Security/Conceptual/keychainServConc epts/ • Keychain Services Reference https://developer.apple.com/library/mac/docum entation/Security/Reference/keychainservices/ • #WWDC14 session 711 - Keychain and Authentication with Touch ID