source: murachi/esteidfirefoxplugin/common/keychain-tool.m @ c4dd8d1

Last change on this file since c4dd8d1 was 7d3ae3e, checked in by antonioaraujob <aaraujo@…>, 9 years ago

Agregados archivos fuentes del complemento esteidfirefoxplugin de Estonia para firmar electrónicamente un hash.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Estonian ID card plugin for web browsers
3 *
4 * Copyright (C) 2010-2011 Codeborne <info@codeborne.com>
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 *
20 */
21
22#include <stdio.h>
23#include <Security/Security.h>
24
25void secOp(OSStatus result) {
26        if (!result) return;
27        CFStringRef error = SecCopyErrorMessageString(result, NULL);
28        printf("error: %s (%li)\n", CFStringGetCStringPtr(error, CFStringGetFastestEncoding(error)), (long)result);
29        CFRelease(error);
30        exit(1);
31}
32
33int main(int argc, char **argv) {
34       
35        SecKeychainRef keychain;
36        secOp(SecKeychainOpen("login.keychain", &keychain));
37        printf("keychain: %p\n", keychain);
38       
39        SecKeychainSearchRef searchRef;
40        SecItemClass itemClass = kSecGenericPasswordItemClass;
41        secOp(SecKeychainSearchCreateFromAttributes(keychain, itemClass, NULL, &searchRef));
42        for (;;) {
43                SecKeychainItemRef item;
44                OSStatus result = SecKeychainSearchCopyNext(searchRef, &item);
45                if (result == errSecItemNotFound) {
46                        break;
47                }
48                secOp(result);
49               
50                SecKeychainRef keychain;
51                secOp(SecKeychainItemCopyKeychain(item, &keychain));
52
53                SecKeychainAttributeInfo *info;
54                secOp(SecKeychainAttributeInfoForItemID(keychain, CSSM_DL_DB_RECORD_GENERIC_PASSWORD, &info));
55               
56                SecKeychainAttributeList *attrList;
57                secOp(SecKeychainItemCopyAttributesAndData(item, info, &itemClass, &attrList, NULL, NULL));
58               
59                for (int i = 0; i < info->count; i++) {
60                        uint32 n = OSSwapHostToBigInt32(info->tag[i]);
61                        char *p = (char *)&n;
62                        if (strncmp("type", p,  4)) continue;
63                        SecKeychainAttribute *attribute = &attrList->attr[i];
64                        if (!attribute->length || !attribute->data) continue;
65                        int len = attribute->length / sizeof(UInt32);
66                        if (len != 1 && strncmp("iprf", (char *)attribute->data, 4)) continue;
67                        printf("item %p type: iprf, deleting!\n", item);
68                        SecKeychainItemDelete(item);
69                }
70        }
71        printf("done\n");
72        CFRelease(searchRef);
73        CFRelease(keychain);
74        return 0;
75}
Note: See TracBrowser for help on using the repository browser.