summaryrefslogtreecommitdiff
path: root/cpp/test/IceSSL/configuration/Util.h
blob: e34fa3c4e86d3f0845faf38cb648fad33a4a9ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <IceSSL/IceSSL.h>

#ifdef ICE_USE_SECURE_TRANSPORT

#include <Security/Security.h>

namespace Test
{

int
getcwd(std::string& cwd)
{
    char cwdbuf[PATH_MAX];
    if(::getcwd(cwdbuf, PATH_MAX) == NULL)
    {
        return -1;
    }
    cwd = cwdbuf;
    return 0;
}

}

void
removeKeychain(const std::string& keychainPath, const std::string& password)
{
    //
    // KeyChain path is relative to the current working directory.
    //
    std::string path = keychainPath;
    if(path.find("/") != 0)
    {
        std::string cwd;
        if(Test::getcwd(cwd) == 0)
        {
            path = std::string(cwd) + '/' + path;
        }
    }
    
    SecKeychainRef keychain;
    OSStatus err = SecKeychainOpen(path.c_str(),  &keychain);
    if(err == noErr)
    {
        err = SecKeychainUnlock(keychain, password.size(), password.c_str(), true);
        if(err == noErr)
        {
            err = SecKeychainDelete(keychain);
        }
        CFRelease(keychain);
    }
}
#endif