ãã¹ã¯ã¼ããæå·åãã¦å®å
¨ã« iPhone/iPad ã¸ä¿ç®¡ããã。iOS ã¯ãã®ç¨éã®çºã« Keychain Services ãæä¾ãã¦ãã。ä»å㯠Keychain Services ã«ã¤ãã¦èª¿ã¹ã¦ã¿ã。ãªãã¡ã¬ã³ã¹ã®å
容ã«å ã、ç¬èªã«èª¿æ»・æ¤è¨¼ããçµæãã¾ã¨ãã¦ãã。åä½ç¢ºèªã®çºã®ãµã³ãã«ã GitHub ã«ç½®ãã¦ããã。
- æ¦è¦
- å©ç¨æ¹æ³
2.1 API
2.2 æ¤ç´¢æ¡ä»¶(query)
2.3 å±æ§å¤(attributes)
2.4 ã¯ã©ã¹
2.5 å±æ§ã®ç¨®é¡
2.6 ã¦ãã¼ã¯ãã¼
2.7 kSecAttrAccessible
2.8 ã¨ã©ã¼ã³ã¼ã
- ã¢ã¯ã»ã¹å¶å¾¡
3.1 Keychain Access Group(ã°ã«ã¼ã)
3.2 ã¢ããªã±ã¼ã·ã§ã³ã®æå±ã°ã«ã¼ã
3.3 ã°ã«ã¼ãã®å¤æ´
3.4 ã°ã«ã¼ãã®å½åã«ã¼ã«
3.5 ããã©ã«ãã°ã«ã¼ãã®æ±ºå®ã«ã¼ã«
3.6 ã¢ã¤ãã ç»é²æã«æå®å¯è½ãªã°ã«ã¼ã
3.7 ã·ãã¥ã¬ã¼ã¿ã«ãããã°ã«ã¼ã
3.8 ã°ã«ã¼ãè¨å®ã®ä¾
- éçº・éç¨æ
å ±
4.1 API å©ç¨æ¹æ³
4.2 å®æ©ã¨ã·ãã¥ã¬ã¼ã¿ã§ã®éã
4.3 ã¢ããªãåé¤ããå ´åã®æå
- ãµã³ãã«
5.1 ç»é²・æ´æ°
5.2 åé¤
5.3 æ¤ç´¢(ãã¹ã¯ã¼ãåå¾)
5.4 æ¤ç´¢(å
¨ã¢ã¤ãã åå¾)
- éç¨ä¸ã®æ³¨æç¹
- ã½ã¼ã¹ã³ã¼ã
- åèæ
å ±
- ä»é²
ãªã iOS 㧠Keychain Services ã使ç¨ããå ´å、ããã¤ãéè¦ãªæ³¨æç¹ããã。ãããã¯「6. éç¨ä¸ã®æ³¨æç¹」ã«ç°¡åã«ã¾ã¨ããã®ã§åç
§ãããã。
1. æ¦è¦
Keychain Services ã¯ãã¹ã¯ã¼ããç§å¯éµ、証ææ¸ãªã©ãä¿åããå®å
¨ãªã¹ãã¬ã¼ã¸ã¨ãããæä½ããAPIãæä¾ãã¦ãã。ã¹ãã¬ã¼ã¸ã¯æå·åããã¦ãã¦ãã¹ã¯ã¼ã(keychain password)ã«ãã£ã¦ä¿è·ããã¦ãã。ãã®ãã¹ã¯ã¼ããç¡ãéãã¹ãã¬ã¼ã¸å
ã®æ
å ±ãå©ç¨(復å·å)ãããã¨ã¯ã§ããªã。Keychain Services ã§ã¯æ ¼ç´ãã¦ãããã¹ã¯ã¼ããç§å¯éµ、証ææ¸ã®æ
å ±ãã¢ã¤ãã ã¨å¼ãã§ãã。Keychain Services ã¯ãããè¤æ°ã®ã¢ã¤ãã ã管çã、ç»é²、å¤æ´、åé¤、æ¤ç´¢ããããã® API ãæä¾ãã¦ãã。
Mac OS X、iOS å
±ã«ãã®ãµã¼ãã¹ã¯ãµãã¼ãããã¦ããã、ãã©ãããã©ã¼ã ã«ãã£ã¦ä½¿ãæ¹ãè¥å¹²ç°ãªã。
ãã©ãã
ãã©ã¼ã | ä»ã¢ããªã®
æ
å ±ã¸
ã¢ã¯ã»ã¹ | å©ç¨æãã¹ã¯ã¼ãè¦æ±
(keychain password) | ãã¹ã¯ã¼ãæå®æ¹æ³
(keychain password) | 主ã«ä½¿ç¨ããAPI |
Mac OS X | ◯ | æ±ãããã
※è¨å®ã«ãã | ã¦ã¼ã¶æå® | SecKeychainç³» |
iOS | △ | æ±ããããªã | ã·ã¹ãã èªåçæ | SecItemç³» |
ä»ã¢ããªã±ã¼ã·ã§ã³ãæ ¼ç´ãã Keychain Services å
ã®æ
å ±ã¸ã®ã¢ã¯ã»ã¹
Mac OS X ã®å ´åã¯ã¦ã¼ã¶ã許å¯ãä¸ããã°ä»ã®ã¢ããªã±ã¼ã·ã§ã³ã®æ
å ±ã¸ã¢ã¯ã»ã¹ãããã¨ãã§ãã。ä¸æ¹、iOS ã®å ´å、ã¢ããªã±ã¼ã·ã§ã³ã¯èªèº«ãä¿åããæ
å ±ã®ã¿ã¢ã¯ã»ã¹ãè¡ãã。ä»ã®ã¢ããªã±ã¼ã·ã§ã³ã®æ
å ±ã¸ã¯åºæ¬çã«ã¢ã¯ã»ã¹ãããã¨ãã§ããªã。ãã ãåããããã¸ã§ãã³ã°ãããã¡ã¤ã«ã使ã£ã¦ãã«ããããã¢ããªã¯è¨å®ã«ããæ
å ±ãå
±æãããã¨ãã§ãã(å¾è¿°)。
iOS ã§ã®ç¹è¨äºé
- iOS ã«ã¯åä¸ã®ãã¼ãã§ã¼ã³ã®ã¿åå¨ãã(Mac OS X ã¯è¤æ°)。
- iOS ã®å ´å、PCæ¥ç¶æã«ã¹ãã¬ã¼ã¸ã®å
容ã¯æå·åãããã¾ã¾ããã¯ã¢ããããã。ããã復å·åãããã¹ã¯ã¼ã(keychain password)ã¯ããã¯ã¢ãããããªã(iOSããã¤ã¹ã®ä¸ããå¤ã«æã¡åºãããªã)。
- Keychain Service ã¯ãããã¸ã§ãã³ã°ãã¡ã¤ã«ã®æ
å ±ãå©ç¨ãã。ãã®çº、ã¢ããªã±ã¼ã·ã§ã³ããã¼ã¸ã§ã³ã¢ããããå ´å、åããããã¸ã§ãã³ã°ãã¡ã¤ã«ã使ããã¨ãæ¨å¥¨ããã。[*1]
[*1] ã¢ã¯ã»ã¹æ¨©éã決å®ãã Keychain Access Group ã®å¤ã«ããã©ã«ãã§ãããã¸ã§ãã³ã°ãã¡ã¤ã«ã§å®ç¾©ããã App Identifier ã使ç¨ãããçº。
2. å©ç¨æ¹æ³
2.1 API
Security.framework ã§æä¾ãããä¸è¨ã®ï¼ã¤ã®APIã使ç¨ã㦠Keychain Services ã¸ã¢ã¯ã»ã¹ãã。
SecItemAdd (CFDictionaryRef attributes, CFTypeRef* result);
SecItemUpdate (CFDictionaryRef query, CFDictionary attributes);
SecItemDelete (CFDictionaryRef query);
SecItemCopyMatching(CFDictionaryRef query, CFTypeRef* result);
Keychain Services Reference - Functions
2.2 æ¤ç´¢æ¡ä»¶(query)
APIã®å¼æ° query ã¯、Keychain Services å
ã®ã¢ã¤ãã ãæ¤ç´¢ããã、æ´æ°å¯¾è±¡ã®ã¢ã¤ãã ãæå®ããæã®æ¡ä»¶ã¨ãã¦ä½¿ç¨ãã。åé¤ããå ´åã®åé¤å¯¾è±¡ã®ã¢ã¤ãã ããã® query ã§ç¹å®ãã。
ä¾)CFDictionaryRef query
|--kSecClass = kSecClassGenericPassword // ãã¹ã¯ã¼ãã¯ã©ã¹ãæå®
|--kSecAttrAccount = @"hashiguchi" // ã¢ã«ã¦ã³ã
|--kSecRetrunAttributes = kCFBooleanTrue // çµæã CFDictionaryåã§åãåã
ä¸è¨ã SecItemCopyMatchingã®ç¬¬ä¸å¼æ°ã¸æ¸¡ãã¨、第äºå¼æ°ã§çµæãåãåããã¨ãã§ãã。ã¾ã SecItemUpdate ã§ã®æ´æ°å¯¾è±¡ã®æå®、SecItemDelete ã§ã®åé¤å¯¾è±¡ãæå®ããã®ã«ã使ããã。
æ¤ç´¢ã§ä½¿ãããã¼ã¯æ¬¡ã®ãããªãã®ããã。
Search Keys
ãã¼ | å
容 |
kSecMatchPolicy | SecPolicyRefãæ¡ä»¶ã¨ãã
※証ææ¸ã§ä½¿ç¨ |
kSecMatchItemList | æå®ããé
åãæ¤ç´¢å¯¾è±¡ã«ã§ãã。ã¾ã persistent reference ãã normalreference ã¸ã®å¤æã persistent reference ãæå®ããåé¤ãªã©ã®ç¨éã§ãå©ç¨。 |
kSecMatchSearchList | ※ä¸æ(ãªãã¡ã¬ã³ã¹ã«èª¬æãªã)。kCFBooleanTrue ãè¨å®ãã¦ã¿ããçµæã«å¤åãªã。 |
kSecMatchIssuers | X.500 Issuer(証ææ¸çºè¡è
)ãé
åã§æå®ãã
※証ææ¸ã§ä½¿ç¨ |
kSecMatchEmailAddressIfPresent | RFC822ã§å®ç¾©ãããemailãæå®ãã
※証ææ¸ã§ä½¿ç¨ |
kSecMatchSubjectContains | X.500 Subject(証ææ¸åå¾è
)ã®é¨åä¸è´æååãæå®ãã
※証ææ¸ã§ä½¿ç¨ |
kSecMatchCaseInsensitive | æååæ¯è¼æã®å¤§æåå°æååºå¥ã®æç¡ |
kSecMatchTrustedOnly | ä¿¡é ¼ã§ããèªè¨¼å±ã«çºè¡ããã¦ãã証ææ¸ãã©ãããæå®
※証ææ¸ã§ä½¿ç¨ãã |
kSecMatchValidOnDate | 証ææ¸ã®æå¹æéãæå®
※証ææ¸ã§ä½¿ç¨ãã |
kSecMatchLimit | çµæã§ä¸åº¦ã«åå¾ããæ大件æ°ãæå® |
kSecMatchLimitOne | çµæï¼ä»¶ã®ã¿ãåå¾ãã(ããã©ã«ãåä½) |
kSecMatchLimitAll | çµæãã¹ã¦ãåå¾ãã(件æ°ç¡å¶é) |
æ¤ç´¢çµæã§åãåãããå¤ã®ç¨®é¡・åãããããã query ã«è¨å®ãã¦ãã。è¨å®å¯è½ãªãã¼ã¯æ¬¡ã®éã。
ãã¼ | å | å¤ | çµæä¾(NSLogåºåä¾) |
kSecReturnData | CFDataRef | ãã¹ã¯ã¼ã | <62706c69 73743030 ... |
kSecReturnAttributes | CFDictionaryRef | å±æ§å¤ | {
acct = hashiguchi;
agrp = test;
gena = <70617373 776f7264>;
pdmn = ak;
svce = SampleService;
} |
kSecReturnRef | ä¸è¨ã®ãããã(ã¯ã©ã¹ã«ä¾å)
SecKeychainItemRef
SecKeyRef
SecCertificateRef
SecIdentityRef
CFDataRef | ※ã¯ã©ã¹ã«ä¾å | ※kSecClassGenericPasswordã§ã¯æ»ãå¤ãªã |
kSecReturnPersistentRef | CFDataRef | ãã£ã¹ã¯ä¸ã«æ ¼ç´ããããªãã¸ã§ã¯ãã¸ã®åç
§、ãããã¯å¥ããã»ã¹ã¨ã®å
±æãªãã¸ã§ã¯ãã¸ã®åç
§ã表ã(※詳細æªèª¿æ»)。 | <67656e70 00000000 00000001> |
ä¸è¨ãã¼ã«å¤ CFBooleanTrue ãæå®ããã¨æå¹ã«ãªã。ãªãè¤æ°æå®ããå ´å、ãã¹ã¦ã®çµæã CFDictionaryRef ã«æ ¼ç´ããã¦æ»ããã。
(ä¾)
{
acct = ddddd;
agrp = test;
class = genp;
pdmn = ak;
svce = "";
"v_Data" = <64>
"v_PersistentRef" = <67656e70 00000000 00000018>;
}
"v_Data" ã kSecReturnData ã«、"v_PersistentRef" ã kSecReturnPersistentRef ã«、ãã以å¤ã¯ kSecReturnAttributes ã対å¿ãã¦ãã。
2.3 å±æ§å¤(attributes)
APIã®å¼æ° attributes ã¯、æ°è¦ç»é²ãæ´æ°ããã¢ã¤ãã ã®æ
å ±ãæå®ããç¨éã§ä½¿ç¨ãã。æ¤ç´¢çµæãåãå½¢å¼ã§åãåã。
ä¾)CFDictionaryRef attributes
|--kSecClass = kSecClassGenericPassword // ãã¹ã¯ã¼ãã¯ã©ã¹ãæå®
|--kSecAttrAccount = @"hashiguchi" // ã¢ã«ã¦ã³ã
|--kSecValueData = [@"Jusdf087" dataWithEncoding:NSUTF8StringEncoding] // ãã¹ã¯ã¼ã
|--kSecAttrDescription = @"Item description"
|--kSecAttrService = @"Service"
|--kSecAttrComment = @"Your comment here."
ä¸è¨ã SecItemAdd ã®ç¬¬ä¸å¼æ°ã¸æ¸¡ãã¨ãã®å
容ã Keychain Services ã¸ç»é²ããã。ä¿åãããæ
å ±(ãã¹ã¯ã¼ãã証ææ¸)㯠kSevValueData ããã¼ã«ã㦠NSDataåã§æ¸¡ã。æ¢ã«åãã¢ã«ã¦ã³ããåå¨ããå ´åã¯éè¤ã¨ã©ã¼(-25299:errSecDuplicateItem)ã¨ãªã。
2.4 ã¯ã©ã¹
ã¢ã¤ãã ã®ç¨®é¡ã¯ kSecClass å±æ§ã§æå®ãã。ãã®ç¨®é¡ã®ãã¨ãã¯ã©ã¹ã¨å¼ã³、ã¯ã©ã¹ã¯æ¬¡ã®ï¼ç¨®é¡ãç¨æããã¦ãã。
kSecClassGenericPassword | ãã¹ã¯ã¼ã |
kSecClassInternetPassword | ã¤ã³ã¿ã¼ããããã¹ã¯ã¼ã |
kSecClassCertificate | 証ææ¸ |
kSecClassKey | æå·éµ(ç§å¯éµ、å
¬ééµãªã©) |
kSecClassIdentity | ç§å¯éµä»ã証ææ¸ |
Keychain Services ã¸æ ¼ç´ããã¢ã¤ãã ã¯ãã®ããããã®ã¯ã©ã¹ã«åé¡ãã。ä¸è¬çãªã¢ããªã±ã¼ã·ã§ã³ã§ã¯ kSecClassGenericPassword ã使ãããã¨æããã。
2.5 å±æ§ã®ç¨®é¡
è¨å®å¯è½ãªå±æ§ã®ç¨®é¡ã¯ç¨éã«å¿ãã¦æ§ã
ãªãã®ãç¨æããã¦ãã。
Attribute item
ãããå
¨ã¦ã使ãããããã§ã¯ãªã、ã¯ã©ã¹ã«ãã£ã¦ä½¿ãå±æ§å¤ã決ã¾ã£ã¦ãã。ä¾ãã° kSecClassGenericPassword ã®å ´å、次ã®å±æ§å¤ãæ±ããã¨ãã§ãã。
ãã¼ | æå³ | å¤ã®å |
kSecAttrAccessible | ã¢ã¯ã»ã¹å¶ç´ãªãã·ã§ã³ | CFTypeRef |
kSecAttrAccessGroup | ã¢ã¯ã»ã¹ã°ã«ã¼ã | CFStringRef |
kSecAttrCreationDate | ã¢ã¤ãã ä½ææ¥ | CFStringRef |
kSecAttrModificationDate | ã¢ã¤ãã æ´æ°æ¥æ | CFStringRef |
kSecAttrDescription | ã¢ã¤ãã ã®èª¬æ | CFStringRef |
kSecAttrComment | ã³ã¡ã³ã | CFStringRef |
kSecAttrCreator | ä½æã¢ããª(ï¼æå) | CFNumberRef |
kSecAttrType | ã¢ã¤ãã ã¿ã¤ã(ï¼æå) | CFNumberRef |
kSecAttrLabel | ã¦ã¼ã¶ã¸è¡¨ç¤ºããæåå(ã©ãã«) | CFStringRef |
kSecAttrIsInvisible | ä¸å¯è¦å±æ§(å©ç¨ã¯ã¢ããªæ¬¡ç¬¬) | CFStringRef |
kSecAttrIsNegative | ç¡å¹å±æ§(å©ç¨ã¯ã¢ããªæ¬¡ç¬¬) | CFStringRef |
kSecAttrAccount | ã¢ã«ã¦ã³ã(ãã°ã¤ã³IDãªã©) | CFStringRef |
kSecAttrService | ãµã¼ãã¹å(Application Identifierãªã©) | CFStringRef |
kSecAttrGeneric | å©ç¨ç®çãèªç±ãªæ
å ± | CFDataRef |
ä¸è¨ã¯åºæ¬çã«ããã°ã©ã ã§è¨å®ããå¿
è¦ããã。ä¾ãã°ã¢ã¤ãã ä½ææ¥æ kSecAttrCreationDate ã¯èªåçã«è¨å®ããã訳ã§ã¯ãªã。ãªã kSecAttrAccessGroup ã¯æå®ããªãå ´å、èªåçã«ããã©ã«ãå¤ãè¨å®ããã(å¾è¿°)。
2.6 ã¦ãã¼ã¯ãã¼
æ¤ç´¢æã«ããï¼ã¤ã®ã¢ã¤ãã ãç¹å®ãããã¼(ã¦ãã¼ã¯ãã¼)㯠kSecClassGenericPassword ã®å ´å、次ã®ï¼ã¤ã§æ§æããã¦ãã
[*1]。
- kSecAttrAccount
- kSecAttrService
[*1] ããã¥ã¡ã³ãã«æ¸ããã¦ããããã§ã¯ãªã調æ»ã®çµæããå¤æãã。
kSecAttrService ã®å¤ãç°ãªãã°åã kSecAttrAccount ã®å¤ããã¤ã¢ã¤ãã ãç»é²ãããã¨ãã§ãã。ã¾ã kSecAttrService ã¯ç»é²æã«çç¥ãããã¨ãã§ãã¦、kSecAttrAccount ã ãã§éç¨ãããã¨ãã§ãã。ãã®å ´åã¯åã kSecAttrAccount ã®å¤ã¯è¤æ°ç»é²ã§ããªã(ç»é²æã«éè¤ã¨ã©ã¼ã¨ãªã)。
Keychain Services Programming Guide ã®ãµã³ãã«ãªã©ã§è¨å®ããã¦ãã kSecAttrGeneric ã¯ã¦ãã¼ã¯ãã¼ã®æ§æã«ã¯å
¥ããªã。ãã®çº、kSecAttrAccount ã®å¤ãåãã§、kSecAttrGeneric ã®å¤ãç°ãªãã¢ã¤ãã ã®ç»é²ã¯ã§ããªã(ãã¯ãéè¤ã¨ã©ã¼ã¨ãªã)。ãã ãæ¤ç´¢ãã¼ã¨ãã¦ã¯æå¹ã«åãã®ã§、ããã°ã©ã å
ã§ã®ãã¼ã®ç¨éãåé¡ã表ãæ¤ç´¢ã¿ã°ã®ãããªç¨éã§å©ç¨ãããã¨ãã§ãã。
2.7 kSecAttrAccessible
kSecAttrAccessibleå±æ§ãè¨å®ãããã¨ã§ Keychain Services å
ã«æ ¼ç´ããæ
å ±ã¸ã®ã¢ã¯ã»ã¹ã«å¶éãå ãããã¨ãã§ãã。
ãã¼ | ã¢ã¯ã»ã¹æ¡ä»¶ | æ¨å¥¨ç¨é | ãªã¹ãã¢ã®å¯å¦ |
kSecAttrAccessibleAfterFirstUnlock | åèµ·åå¾æåã®ã¢ã³ããã¯ä»¥é
次ã®åèµ·åã¾ã§ | ããã¯ã°ã©ã¦ã³ã
ã¢ããªã±ã¼ã·ã§ã³ | ◯ |
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly | åèµ·åå¾æåã®ã¢ã³ããã¯ä»¥é
次ã®åèµ·åã¾ã§ | ããã¯ã°ã©ã¦ã³ã
ã¢ããªã±ã¼ã·ã§ã³ | × |
kSecAttrAccessibleAlways | ãªã
(常ã«ã¢ã¯ã»ã¹å¯) | ã¢ããªã±ã¼ã·ã§ã³ã§ã®
å©ç¨ã¯æ¨å¥¨ãããªã | ◯ |
kSecAttrAccessibleAlwaysThisDeviceOnly | ãªã
(常ã«ã¢ã¯ã»ã¹å¯) | ã¢ããªã±ã¼ã·ã§ã³ã§ã®
å©ç¨ã¯æ¨å¥¨ãããªã | × |
kSecAttrAccessibleWhenUnlocked | ããã¤ã¹ã
ã¢ã³ããã¯ãããç¶æ
| ãã©ã¢ã°ã©ã¦ã³ã
ã¢ããªã±ã¼ã·ã§ã³ | ◯ |
kSecAttrAccessibleWhenUnlockedThisDeviceOnly | ããã¤ã¹ã
ã¢ã³ããã¯ãããç¶æ
| ãã©ã¢ã°ã©ã¦ã³ã
ã¢ããªã±ã¼ã·ã§ã³ | × |
- ããã¤ã¹ã®ç¶æ
(ããã¯、ã¢ã³ããã¯)ã®ä»、PCã¸ããã¯ã¢ãããããã¼ã¿ããªã¹ãã¢ããæã®å¯¾è±¡ã«å«ãããã©ãããæå®ãããã¨ãã§ãã。
- ããã©ã«ã(æªæå®æ)㯠kSecAttrAccessibleWhenUnlocked ã¨ãªã£ã¦ãã。ããã¯ã°ã©ã¦ã³ãã§åä½ããã¢ããªã®å ´å、ããã¯ç¶æ
(ã¹ãªã¼ãæ)ã«ã¯ã¢ã¯ã»ã¹ã§ããªãã®ã§æ³¨æ。ããã¯ç¶æ
ã§ãå©ç¨ãããå ´å㯠kSecAttrAccessibleAfterFirstUnlock ãæ示çã«æå®ãã。
2.8 ã¨ã©ã¼ã³ã¼ã
API ã®æ»ãå¤(ã¨ã©ã¼ã³ã¼ã)ã¯ãªãã¡ã¬ã³ã¹ã§å®ç¾©ããã¦ãã。
Keychain Services Reference
åAPIã®æ»ãå¤ã¯、0 (errSecSuccess) ãªãæ£å¸¸çµäº、ãã以å¤ã¯ã¨ã©ã¼。
3. ã¢ã¯ã»ã¹å¶å¾¡
3.1 Keychain Access Group
Keychain Services ã§æ±ãããã¢ã¤ãã ã¯å±æ§ kSecAttrAccessGroup ã®å¤ã«ãã£ã¦ã¢ã¯ã»ã¹ã®å¯å¦ãå¶å¾¡ããã¦ãã。ãã®å±æ§å¤ã§ç¤ºãããæååã Keychain Access Group(以ä¸、ã°ã«ã¼ã)ã¨å¼ã¶。ã¢ããªã±ã¼ã·ã§ã³ã¯ã¢ã¯ã»ã¹å¯¾è±¡ã®ã¢ã¤ãã ã¨åãã°ã«ã¼ãã«æå±ãã¦ããå¿
è¦ããã。ã¢ããªã±ã¼ã·ã§ã³ã¨ç°ãªãã°ã«ã¼ãã«æå±ãã¦ããã¢ã¤ãã ã¯æ¤ç´¢ã«ãããããªã。ä¾ãã°ããã¢ã¤ãã ã®å±æ§ kSecAttrAccessGroup ã« "GFDZH8DCX.com.xcatsan.keyChainsSample" ã¨è¨å®ããã¦ããå ´å、ãã®ã¢ã¤ãã ã¸ã¢ã¯ã»ã¹ãããã¨ãã§ããã¢ããªã±ã¼ã·ã§ã³ã¯ã°ã«ã¼ã "GFDZH8DCX.com.xcatsan.keyChainsSample" ã«æå±ãã¦ããå¿
è¦ããã。
ã¤ã¡ã¼ã¸:
3.2 ã¢ããªã±ã¼ã·ã§ã³ã®æå±ã°ã«ã¼ã
é常ã¢ããªã±ã¼ã·ã§ã³ã¯ application-identifer ã§å®ç¾©ãããã°ã«ã¼ãã«æå±ãã¦ãã。application-identifier ã¯ããã©ã«ãã§ã¯ $(AppIdentifierPrefix)$(CFBundleIdentifier) ã¨ãã¦å®ç¾©ããã。$(AppIdentifierPrefix) ã¯ãããã¸ã§ãã³ã°ãã¡ã¤ã«ã® App Identifier ã®ã¢ã¹ã¿ãªã¹ã¯"*"ã®å·¦å´ã®è±æ°å、$(CFBundleIdentier)㯠Info.plist ã§å®ç¾©ããã¦ããã¢ããªã±ã¼ã·ã§ã³èå¥åãæã。
application-identifier ã®ä¾
GFDZH8DCX.com.xcatsan.keyChainsSample
ãããã¸ã§ãã³ã°ãããã¡ã¤ã«ã® App Identifier ã®ä¾
ã¢ã¤ãã ãç»é²ããæã«ã¯ããã©ã«ãã§ã¢ããªã±ã¼ã·ã§ã³ãæå±ãã application-identifer ã kSecAttrAccessGroup ã«è¨å®ããã。ãã®çº、ã¢ããªã±ã¼ã·ã§ã³èªèº«ãç»é²ããã¢ã¤ãã ãå¾ããèªã¿åºããã¨ãã§ãã。
ãªãå¾è¿°ãã Entitlements.plistãã¡ã¤ã«ã®ä½æããã¨ãã®ããã©ã«ãå¤ãå¤ãããã¨ãã§ãã。
3.3 Keychain Access Group ã®å¤æ´
Keychain Access Group ã®ããã©ã«ãå¤ã¯ application-identifier ã使ãããã、Entitlements.plistãã¡ã¤ã«
[*1] ãç¨æãããã¨ã§ Keychain Access Group ã®ããã©ã«ãå¤ãã¢ããªã±ã¼ã·ã§ã³ã§å¤ãããã¨ãã§ãã。ã¾ããã®ãã¡ã¤ã«ã«ã°ã«ã¼ããè¤æ°æ¢è¿°ãããã¨ã§、ã¢ããªã±ã¼ã·ã§ã³ãæå±ããã°ã«ã¼ããè¤æ°å®ç¾©ãããã¨ãã§ãã。以ä¸、plistãã¡ã¤ã«ã®ä½ææé 。
[*1] plistãã¡ã¤ã«ã®ååã¯èªç±ã«ä»ãããã¨ãã§ãã¦ãªãã¡ã¬ã³ã¹ã§ã¯ä¾ã¨ã㦠keychain-access-groupslplist ãä¸ãããã¦ãã。ãã ã³ã¼ãç½²åã®ç¨éãªã©ã§ãã®ãã¡ã¤ã«ãä½æããã±ã¼ã¹ããã、Keychain Access Group å°ç¨ã®è¨å®ãã¡ã¤ã«ã¨ããããã§ã¯ãªã。ãã®çº、ããã§ã¯ç¬èªã®ãã¡ã¤ã«åã§ã¯ãªãæ¨æºçã«ä½¿ããã Entitlements.plist ã使ç¨ãã。
1. Entitlements.plistãã¡ã¤ã«ã®ä½æ
plist å½¢å¼ã®ãã¡ã¤ã«ãä½æãã。ä½æã¯æåã§ãå¯è½ã ã Xcode ã®æ°è¦ä½æã«ãã³ãã¬ã¼ã(Code Signing > Entitlements)ãç¨æããã¦ããã®ã§ããã使ãã®ãè¯ãã ãã。
ãã³ãã¬ã¼ãããä½æããããã¡ã¤ã«ã®å
容ã¯æ¬¡ã®éã。
ãã®ä¸ã® keychain-access-groups(é
å)ã¸æå±ããã°ã«ã¼ããåæãã¦ãã。
2. ãã¡ã¤ã«ã®è¨å®
Xcode ããã¸ã§ã¯ãã®ã¿ã¼ã²ããã®æ
å ±ãéã「ãã«ã」ã¿ãå
ã®「ã³ã¼ãç½²å権é」(å¤æ°:CODE_SIGN_ENTITLEMENTS)ã« 1.ã§ä½æãããã¡ã¤ã«åãæå®ãã。
1. 㧠Xcode ã®ãã³ãã¬ã¼ããã Entitlements.plist ãä½æããå ´å、ãã®è¨å®ã¯èªåçã«è¡ããã。
ãã¨ã¯ãã«ãããã°ãã。
3.4 Keychain Access Group ã®å½åã«ã¼ã«
Keychain Access Group ã§æå®ããæååã«ã¯æ¬¡ã®å½åã«ã¼ã«ããã。
ãããã¸ã§ãã³ã°ãã¡ã¤ã«ã§å®ç¾©ããã App Identifier ã¨åæ¹ä¸è´ãã
ä¾ãã°、App Identifier ã "GFDZH8DCX.*" ã®å ´å、æå®å¯è½ãªã°ã«ã¼ãåã¯æ¬¡ã®ããã«ãªã。
GFDZH8DCX.xcatsan.com.KeychainSample
GFDZH8DCX.xcatsan.com.KeychainSample.temporary
GFDZH8DCX.mikeneko
ãã®ã«ã¼ã«ãæºããããªãå ´åã¯ã¢ã¤ãã ç»é²æã«ã¨ã©ã¼ã¨ãªã£ãã、å®æ©ã¸ã®ã¤ã³ã¹ãã¼ã«æã«ã¨ã©ã¼ã¨ãªã。
ä¾ãã°、Entitlements.plist ãã¡ã¤ã«ã® keychain-access-groups ã«ä¸è¨ã«ã¼ã«ã«åããªãæååãæå®ããå ´å、å®æ©ã¸ã¤ã³ã¹ãã¼ã«ããã¨ãã« "The executable was signed with invalid entitlements." ã¨ã©ã¼ã表示ããã。
ãã®ã«ã¼ã«ã¯ã»ãã¥ãªãã£ä¸ã®çç±ã«ãããã®ã§、ããã«ãããããã¸ã§ãã³ã°ãã¡ã¤ã«ãç°ãªãä»ã®ã¢ããªã±ã¼ã·ã§ã³ãç»é²ããã¢ã¤ãã ã®èªã¿åºããã§ããªããªã£ã¦ãã(ã·ãã¥ã¬ã¼ã¿ã¯ãã®ã«ã¼ã«ãé©ç¨ãããªãã®ã§ä»ã¢ããªã±ã¼ã·ã§ã³ã®ã¢ã¤ãã ãèªã¿åºãã¦ãã)。
3.5 ããã©ã«ãã°ã«ã¼ãã®æ±ºå®ã«ã¼ã«
kSecAttrAccessGroup ãæå®ããã« SecItemAdd ã§ã¢ã¤ãã ãç»é²ããå ´å、ãã®ã¢ã¤ãã ã® kSecAttrAccessGroup ã«è¨å®ãããå¤ã¯æ¬¡ã®é çªã§è©ä¾¡ããã。
- kSecAttrAccessGroup
- Entitlements.plist/keychain-access-groups
- application-identifier
1. SecItemAdd ã®ç¬¬ä¸å¼æ°ã§æ¸¡ã (CFDictionaryRef)attributes ã« kSecAttrAccessGroup ãè¨å®ããã¦ããå ´åã¯、ãã®å¤ã使ããã。
2. 1ã®è¨å®ãç¡ãå ´åã¯、ãã«ãæè¨å® CODE_SIGN_ENTITLEMENTS ã§æå®ããããã¡ã¤ã«(Entitlement.plist)ã«è¨è¼ããã keychain-access-groups é
åã®ï¼çªç®ã®å¤ã使ããã。
3. 1ã¨2ãå
±ã«è¨å®ããã¦ããªãå ´åã¯、application-identifer ã®å¤ã使ããã。application-identifier 㯠$(AppIdentifierPrefix)$(CFBundleIdentifier) ã¨ãã¦å®ç¾©ããã。
3.6 ã¢ã¤ãã ç»é²æã«æå®å¯è½ãªã°ã«ã¼ã
SecItemAdd ã§æ示çã« kSecAttrAccessGroup ãæå®ããå ´å、æå®ã§ããã°ã«ã¼ãå㯠Entitlements.plist ãã¡ã¤ã«ã® keychain-access-groups é
åå
ã«å«ã¾ããã、ããã㯠application-identifier ã¨ä¸è´ããå¿
è¦ããã。ãã®ã«ã¼ã«ã«å¾ããªãæååã kSecAttrAccessGroup ã«è¨å®ãã¦ã¢ã¤ãã ãç»é²(SecItemAdd)ãããã¨ããå ´å、ã¨ã©ã¼ã¨ãªã(ã³ã¼ã -25243)。 ä¾ãã°ã¢ããªã±ã¼ã·ã§ã³ã® application-identifier ã "GFDZH8DCX.com.xcatsan.keyChainsSample" ã«ãããããã "AADZH1DGX.com.apple.Mail" ãæå®ããã¨ã¨ã©ã¼ã«ãªã。
3.7 ã·ãã¥ã¬ã¼ã¿ã«ãããã°ã«ã¼ã
ã·ãã¥ã¬ã¼ã¿ã®å ´åã¯å®æ©ã¨ç°ãªã Keychain Access Group ã¯å¸¸ã« "test" ã¨ãªã(Entitlements.plist ãç¡è¦ããã)。ã·ãã¥ã¬ã¼ã¿ä¸ã§åä½ããã¢ããªã±ã¼ã·ã§ã³ã¯ãã¹ã¦ "test"ã°ã«ã¼ãã«æå±ããã®ã§、ä»ã®ã¢ããªã±ã¼ã·ã§ã³ãç»é²ããã¢ã¤ãã ã¸ã¢ã¯ã»ã¹ãããã¨ãã§ãã。
3.8 ã°ã«ã¼ãè¨å®ã®ä¾
åæ
App Identifier: GFDZH8PDDD.*
application-identifier: GFDZH8PDDD.com.yourcompany.KeyChainApp
[1] Entitlements.plist ãªã
[1]-1 ç»é²æã®ããã©ã«ãã°ã«ã¼ã
"GFDZH8PDDD.com.yourcompany.KeyChainApp";
[1]-2 ç»é²æã«æå®å¯è½ãªã°ã«ã¼ã
"GFDZH8PDDD.com.yourcompany.KeyChainApp";
[1]-3 ã¢ã¯ã»ã¹å¯è½ãªã°ã«ã¼ãä¾
"GFDZH8PDDD.com.yourcompany.KeyChainApp";
[1]-4 ã¢ã¯ã»ã¹ä¸å¯ãªã°ã«ã¼ãä¾
"GFDZH8PDDD.";
"GFDZH8PDDD.com.yourcompany.OtherApp";
"XJ7GS56DBA.com.apple.MailApp";
(解説)Entitlements.plist ãç¨æããªãä¸è¬çãªãã¿ã¼ã³。ãã®å ´å㯠application-identifier ãç»é²æã®ããã©ã«ãã°ã«ã¼ãã¨ãªã。ã¾ãã¢ã¯ã»ã¹ã§ããã®ã¯ application-identifier ã®ã¿。
[2] Entitlements.plist ãã
keychain-access-groups:
GFDZH8PDDD.private
GFDZH8PDDD.com.yourcompany.share
[2]-1 ç»é²æã®ããã©ã«ãã°ã«ã¼ã
"GFDZH8PDDD.private";
[2]-2 ç»é²æã«æå®å¯è½ãªã°ã«ã¼ã
"GFDZH8PDDD.private"
"GFDZH8PDDD.com.yourcompany.share"
"GFDZH8PDDD.com.yourcompany.KeyChainApp"
[2]-3 ã¢ã¯ã»ã¹å¯è½ãªã°ã«ã¼ãä¾
"GFDZH8PDDD.private";
"GFDZH8PDDD.com.yourcompany.share";
"GFDZH8PDDD.com.yourcompany.KeyChainApp";
[2]-4 ã¢ã¯ã»ã¹ä¸å¯ãªã°ã«ã¼ãä¾
"GFDZH8PDDD.other";
"GFDZH8PDDD.com.yourcompany.OtherApp";
"XJ7GS56DBA.com.apple.MailApp";
(解説)application-identifier ã¯å¿
ãã¢ã¯ã»ã¹å¯è½ãªã°ã«ã¼ãã«å
¥ã(ãã ãããã©ã«ã決å®æã®åªå
é ä½ã¯ä¸çªä½ã)。
4. éçº・éç¨æ
å ±
4.1 API å©ç¨æ¹æ³
API ãå©ç¨ããã«ããã£ã¦ã¯ Xcode ã®ããã¸ã§ã¯ãã« Security.framework ã追å ãã。
ã¾ã Security/Scurity.h ãã¤ã³ãã¼ããã¦ãã。
4.2 å®æ©ã¨ã·ãã¥ã¬ã¼ã¿ã§ã®éã
- å®æ©ã®å ´å㯠Keychain Service ãªãã¡ã¬ã³ã¹ã®èª¬æã®éãä»ã¢ããªã®æ
å ±ã¯èªã¿åºããªã。ãããã·ãã¥ã¬ã¼ã¿ã®å ´åã¯ãã®å¶éããªãèªã¿åºããå¯è½ã¨ãªã£ã¦ãã。ãã¨ãã° kSecClassGenericPassword ã ããæ¡ä»¶ã«ã㦠SecItemCopyMatching ã§æ¤ç´¢ããããã¨ãã®ã¢ããªä»¥å¤ã§ç»é²ãããæ
å ±ãåå¾ã§ãã。
- ã·ãã¥ã¬ã¼ã¿ã®å ´å、kSecAttrAccessGroup ã®è¨å®ã¯ã§ããªã。常㫠"test" ã¨ãªã(ã ããä¸è¨ã®æ§ãªæåã¨ãªã)。å®æ©ã®å ´åã¯ããã©ã«ã㧠$(AppIdentifierPrefix)$(CFBundleIdentifier) ã¨ãªã。
(ä¾)GFDZH8DCX.com.xcatsan.keyChainsSample
4.3 ã¢ããªãåé¤ããå ´åã®æå
Keychain Service ã«ç»é²ãããæ
å ±ã¯、å®æ©・ã·ãã¥ã¬ã¼ã¿å
±ã«ã¢ããªãåé¤ãã¦ãæ®ã。åã³ã¢ããªãã¤ã³ã¹ãã¼ã«ããã¨ä»¥åã®æ
å ±ãèªã¿åºããã¨ãåºæ¥ã。
5. ãµã³ãã«
Keychain Services 㸠ID、ãã¹ã¯ã¼ãã®çµãä¿å、æ´æ°、æ¤ç´¢、åé¤ãããµã³ãã«ãä½ã£ã¦ã¿ã。
çµæã¯ãããã°ã³ã³ã½ã¼ã«ã«è¡¨ç¤ºããã。dump ãã¿ã³ãæ¼ãã¨ç¾å¨ç»é²ãããã¹ã¦ã®ã¢ã¤ãã æ
å ±ã表示ãã。
ã½ã¼ã¹ã³ã¼ãã¯ç解ãããããåªå
ããã¦ããã¨åé·ã«ãã¦ãã。以ä¸ã«ããããã®æä½ã®å¦çãè¦ã¦ãã。
5.1 ç»é²・æ´æ°
æåã«ãã°ã¤ã³IDããã¼ã«ãã¦ç»é²æ¸ã¿ãã©ãããã§ãã¯ãã。ç»é²æ¸ã¿ã®å ´åã¯ãã¹ã¯ã¼ãã®ã¿ SecItemUpdate ã§æ´æ°ãã。ç»é²ãã¾ã ã®å ´å㯠SecItemAdd ã使ãæ°è¦ã«ç»é²ãã。
- (IBAction)update:(id)sender
{
NSMutableDictionary* attributes = nil;
NSMutableDictionary* query = [NSMutableDictionary dictionary];
NSData* passwordData = [self.password.text dataUsingEncoding:NSUTF8StringEncoding];
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[query setObject:(id)self.loginId.text forKey:(id)kSecAttrAccount];
[query setObject:SERVICE_NAME forKey:(id)kSecAttrService];
[query setObject:[IDENTIFIER dataUsingEncoding:NSUTF8StringEncoding] forKey:(id)kSecAttrGeneric];
OSStatus err = SecItemCopyMatching((CFDictionaryRef)query, NULL);
if (err == noErr) {
// update item
NSLog(@"SecItemCopyMatching: noErr");
attributes = [NSMutableDictionary dictionary];
[attributes setObject:passwordData forKey:(id)kSecValueData];
[attributes setObject:[NSDate date] forKey:(id)kSecAttrModificationDate];
err = SecItemUpdate((CFDictionaryRef)query, (CFDictionaryRef)attributes);
if (err == noErr) {
NSLog(@"SecItemUpdate: noErr");
} else {
NSLog(@"SecItemUpdate: error(%d)", err);
}
} else if (err = errSecItemNotFound) {
// add new item
NSLog(@"SecItemCopyMatching: errSecItemNotFound");
attributes = [NSMutableDictionary dictionary];
[attributes setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[attributes setObject:(id)self.loginId.text forKey:(id)kSecAttrAccount];
[attributes setObject:passwordData forKey:(id)kSecValueData];
err = SecItemAdd((CFDictionaryRef)attributes, NULL);
if (err == noErr) {
NSLog(@"SecItemAdd: noErr");
} else {
NSLog(@"SecItemAdd: error(%d)", err);
}
} else {
NSLog(@"SecItemCopyMatching: error(%d)", err);
}
}
é
åã渡ããã¨ãã§ããã®ã§ä¸åº¦ã«è¤æ°ã®ã¢ã¤ãã ãç»é²ãããã¨ãã§ãã。
5.2 åé¤
åé¤ãããã¢ã¤ãã ã®æ¡ä»¶ã queryã«è¨å®ã、SecItemDelete ã¸æ¸¡ã。
- (IBAction)delete:(id)sender
{
NSMutableDictionary* query = [NSMutableDictionary dictionary];
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[query setObject:(id)self.loginId.text forKey:(id)kSecAttrAccount];
OSStatus err = SecItemDelete((CFDictionaryRef)query);
if (err == noErr) {
NSLog(@"SecItemDelete: noErr");
} else {
NSLog(@"SecItemDelete: error(%d)", err);
}
}
query ã«ä¸è´ããã¢ã¤ãã ã¯ãã¹ã¦(è¤æ°)åé¤ããã。
5.3 æ¤ç´¢(ãã¹ã¯ã¼ãåå¾)
query ã«æ¡ä»¶ãç¨æã SecItemCopyMatching ã¸æ¸¡ãã¦çµæãåå¾ãã。
- (IBAction)getPassword:(id)sender
{
NSMutableDictionary* query = [NSMutableDictionary dictionary];
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[query setObject:(id)self.loginId.text forKey:(id)kSecAttrAccount];
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
NSData* passwordData = nil;
OSStatus err = SecItemCopyMatching((CFDictionaryRef)query,
(CFTypeRef*)&passwordData);
if (err == noErr) {
NSLog(@"SecItemCopyMatching: noErr");
self.password.text = [[[NSString alloc] initWithData:passwordData
encoding:NSUTF8StringEncoding] autorelease];
} else if(err = errSecItemNotFound) {
NSLog(@"SecItemCopyMatching: errSecItemNotFound");
} else {
NSLog(@"SecItemCopyMatching: error(%d)", err);
}
}
5.4 æ¤ç´¢(å
¨ã¢ã¤ãã åå¾)
SecItemCopyMatching ã® query ã« kSecMatchLimitAll ãã»ããããã¨æ¡ä»¶ã«åããã¹ã¦ã®ã¢ã¤ãã ãåå¾ãããã¨ãã§ãã。æ¡ä»¶ã¯ã¯ã©ã¹ã®ã¿ãæå®ãã¦ãã。ã¾ããã®å ´åã®æ»ãå¤ result ã®å㯠CFArray ã¨ãªã。
- (IBAction)dump:(id)sender
{
NSMutableDictionary* query = [NSMutableDictionary dictionary];
[query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
[query setObject:(id)kSecMatchLimitAll forKey:(id)kSecMatchLimit];
CFArrayRef result = nil;
OSStatus err = SecItemCopyMatching((CFDictionaryRef)query,(CFTypeRef*)&result);
if (err == noErr) {
NSLog(@"SecItemCopyMatching: noErr");
NSLog(@"%@", result);
} else if(err = errSecItemNotFound) {
NSLog(@"SecItemCopyMatching: errSecItemNotFound");
} else {
NSLog(@"SecItemCopyMatching: error(%d)", err);
}
}
ä¸è¨ã¯åºåä¾(å®æ© iOS4.2.1/3GS)。ãã®ãã㪠dumpã¡ã½ãããç¨æãã¦ããã¨ãããã°ã®æã«å½¹ç«ã¤。
KeyChainsSampe[4108:307] (
{
acct = hashi;
agrp = "GFDZH8DCX.com.xcatsan.keyChainsSample";
pdmn = ak;
svce = "";
},
{
acct = mikeneko;
agrp = "GFDZH8DCX.com.xcatsan.keyChainsSample";
pdmn = ak;
svce = "";
},
{
acct = hashi;
agrp = "GFDZH8DCX.com.xcatsan.keyChainsSample";
cdat = "2011-02-04 05:14:45 +0000";
desc = "This is a password";
gena = <70617373 776f7264>;
mdat = "2011-02-04 05:14:45 +0000";
pdmn = ak;
svce = SampleService;
}
)
ãã¼ã¯ï¼æåã«ç縮ãããæååã使ããã¦ãã。ã·ã³ãã«ã¨ã®å¯¾å¿ã¯å½æ稿ã®ä»é²ãåç
§ã®ãã¨。
6. ã½ã¼ã¹ã³ã¼ã
GitHub ããã©ãã。
KeyChainsSampe at 2011-02-06 from xcatsan/iOS-Sample-Code - GitHub
7. éç¨ä¸ã®æ³¨æç¹
Keychain Services ãéç¨ããã«ããã£ã¦ã¯æ¬¡ã®ç¹ã«æ³¨æããå¿
è¦ããã。
ãããã¸ã§ãã³ã°ãã¡ã¤ã«ãå¤æ´ããªã
「3. ã¢ã¯ã»ã¹å¶å¾¡」ã§èª¬æããããã«、Keychain Services å
ã®ã¢ã¤ãã ã¸ã®ã¢ã¯ã»ã¹å¯å¦ã決ãã Keychain Access Group ã¯ãããã¸ã§ãã³ã°ãã¡ã¤ã«å
ã® App Identifier ã«ä¾åãã。ç°ãªã App Identifier ã§ç»é²ãããã¢ã¤ãã ã¸ã¯ã¢ã¯ã»ã¹ãããã¨ãã§ããªã。ãã¼ã¸ã§ã³ã¢ããæã«ãããã¸ã§ãã³ã°ãã¡ã¤ã«ãå¤ããå ´å、App Identifier ãå¤ããã¨åã®ãã¼ã¸ã§ã³ã§ç»é²ããã¢ã¤ãã ãæ°ãããã¼ã¸ã§ã³ã§ã¯å©ç¨ã§ããªã、ã¨ãã£ãåé¡ãèµ·ãã。
ããã¯ã°ã©ã¦ã³ãã¢ããªã±ã¼ã·ã§ã³ã¯é©å㪠kSecAttrAccessible ãè¨å®ãã
「2. å©ç¨æ¹æ³ - kSecAttrAccessbile」ã§èª¬æããããã«、ããã©ã«ãã§ã¯ iOSããã¤ã¹ã®ããã¯ãå¤ããç¶æ
(ã¤ã¾ãã¦ã¼ã¶ãæä½ãã¦ããæ)ã§ããã¢ã¤ãã ã¸ã¢ã¯ã»ã¹ã§ããªãããã«ãªã£ã¦ãã。ããã¯ä¸ã«ã¢ã¤ãã ã¸ã¢ã¯ã»ã¹ãããããªããã¯ã°ã©ã¦ã³ãã¢ããªã±ã¼ã·ã§ã³ã®å ´å、ã¢ã¤ãã ã® kSecAttrAccesible å±æ§ã®å¤ã kSecAttrAccessibleAfterFirstUnlock(ããã㯠kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly)ã«è¨å®ãã¦ããå¿
è¦ããã。
8. åèæ
å ±
Keychain Services Programming Guide: Introduction
Keychain Service ã®æ¦è¦、ãµã³ãã«ã³ã¼ããªã©。
Keychain Services Reference
SecItemç³»é¢æ°ãªãã¡ã¬ã³ã¹。
Keychain Services Reference
Mac OS X ç¨ Keychain Service Reference(SecItemç³»é¢æ°、SecKeychainç³»é¢æ°ã®ãªãã¡ã¬ã³ã¹)。
Simple iPhone Keychain Access - Blog - Use Your Loaf
SecItemç³»é¢æ°ã®ä½¿ãæ¹ã解説ããã¦ãã。
(æ§) Cocoaã®æ¥ã
: Keychain Services èª¿æ» (1) æ
å ±åé
éå»ã« Mac OS X ã§èª¿æ»ããæã®è¨é²ãªã©(äºåæ°åç¶ãé£è¼)。
ããã¯ãããiPhoneãï¼åã§ãããã³ã°…ã¹ãã¼ããã©ã³ã¯ãã¯ãé»è©±ãããªããã¨ãå¿ããã«:å½å
・æµ·å¤æ
å ±ããè¦ãã『ä¼æ¥ã®WEBæ´»ç¨æ³』:ITmedia ãªã«ã¿ããã£ã・ããã°
jailbreak ããã iPhone ãªãå°ç¨ãã¼ã«ã使ã Keychain Serviceså
ã®ãã¼ã¿ãèªã¿åºããã¨ãã§ããããã。æåã«è§¦ããããã« iOS ã®å ´å、Keychain Servicesç¨ã®ãã¹ã¯ã¼ãã¯(ã¦ã¼ã¶ã§ã¯ãªã)iOS èªèº«ã管çããçº、ä¾ãã°ãããæ ¼ç´ãããå ´æãç¹å®ã§ããã°ãã¹ã¯ã¼ãã解æãããã¨ã¯é£ãããªããããããªã(ãããªããã«è¦ã¤ãã/ã¢ã¯ã»ã¹ã§ãããããªé
ç½®ã¯ãã¦ããªãã¨ã¯æãã。ã§ã rootãåãããã°ã©ãã ãã。)。
9. ä»é²
å±æ§ãã¼ã®æåå
å±æ§ãã¼ã®ã·ã³ãã«ã¨å®éã®æååã¨ã®å¯¾å¿è¡¨。
kSecAttrAccessible | pdmn |
kSecAttrCreationDate | cdat |
kSecAttrModificationDate | mdat |
kSecAttrDescription | desc |
kSecAttrComment | icmt |
kSecAttrCreator | crtr |
kSecAttrType | type |
kSecAttrLabel | labl |
kSecAttrIsInvisible | invi |
kSecAttrIsNegative | nega |
kSecAttrAccount | acct |
kSecAttrService | svce |
kSecAttrGeneric | gena |
kSecAttrSecurityDomain | sdmn |
kSecAttrServer | srvr |
kSecAttrProtocol | ptcl |
kSecAttrAuthenticationType | atyp |
kSecAttrPort | port |
kSecAttrPath | path |
kSecAttrSubject | subj |
kSecAttrIssuer | issr |
kSecAttrSerialNumber | slnr |
kSecAttrSubjectKeyID | skid |
kSecAttrPublicKeyHash | pkhh |
kSecAttrCertificateType | ctyp |
kSecAttrCertificateEncoding | cenc |
kSecAttrKeyClass | kcls |
kSecAttrApplicationLabel | klbl |
kSecAttrIsPermanent | perm |
kSecAttrApplicationTag | atag |
kSecAttrKeyType | type |
kSecAttrKeySizeInBits | bsiz |
kSecAttrEffectiveKeySize | esiz |
kSecAttrCanEncrypt | encr |
kSecAttrCanDecrypt | decr |
kSecAttrCanDerive | drve |
kSecAttrCanSign | sign |
kSecAttrCanVerify | vrfy |
kSecAttrCanWrap | wrap |
kSecAttrCanUnwrap | unwp |
kSecAttrAccessGroup | agrp |
kSecAttrAccessible ã®æåå
kSecAttrAccessibleAfterFirstUnlock | ck |
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly | cku |
kSecAttrAccessibleAlways | dk |
kSecAttrAccessibleAlwaysThisDeviceOnly | dku |
kSecAttrAccessibleWhenUnlocked | ak |
kSecAttrAccessibleWhenUnlockedThisDeviceOnly | aku |
- - - -
ããã¾ã§èªãã æ¹ã®ä¸ã§ Keychain Services ãã¢ããªéã®æ
å ±å
±æã®ç¨éã«ä½¿ãããã¨ã«æ°ãã¤ãã人ããããããããªã。çãã¯ååã¤ã¨ã¹ã§ååãã¼(å¶éããã)。次åãã®æ¹æ³ã«ã¤ãã¦è§£èª¬ãã。