diff options
author | Nemurimasu Neiro | 2010-09-06 05:11:05 +0000 |
---|---|---|
committer | McCabe Maxsted | 2010-09-10 19:01:36 -0700 |
commit | c01c71d3b22b9acb983c238b608401f7d032ef9b (patch) | |
tree | 5570956cdb04c8abccd7d4fe6aa26527ad8503be /linden/indra | |
parent | use setenv instead of putenv (diff) | |
download | meta-impy-c01c71d3b22b9acb983c238b608401f7d032ef9b.zip meta-impy-c01c71d3b22b9acb983c238b608401f7d032ef9b.tar.gz meta-impy-c01c71d3b22b9acb983c238b608401f7d032ef9b.tar.bz2 meta-impy-c01c71d3b22b9acb983c238b608401f7d032ef9b.tar.xz |
store our password in the Mac OS keychain
much more secure than XORing against a MAC address :)
Diffstat (limited to 'linden/indra')
-rw-r--r-- | linden/indra/newview/CMakeLists.txt | 2 | ||||
-rw-r--r-- | linden/indra/newview/llstartup.cpp | 45 |
2 files changed, 44 insertions, 3 deletions
diff --git a/linden/indra/newview/CMakeLists.txt b/linden/indra/newview/CMakeLists.txt index 995ef7e..313ed9f 100644 --- a/linden/indra/newview/CMakeLists.txt +++ b/linden/indra/newview/CMakeLists.txt | |||
@@ -955,11 +955,13 @@ if (DARWIN) | |||
955 | find_library(APPKIT_LIBRARY AppKit) | 955 | find_library(APPKIT_LIBRARY AppKit) |
956 | find_library(COCOA_LIBRARY Cocoa) | 956 | find_library(COCOA_LIBRARY Cocoa) |
957 | find_library(IOKIT_LIBRARY IOKit) | 957 | find_library(IOKIT_LIBRARY IOKit) |
958 | find_library(SECURITY_LIBRARY SECURITY) | ||
958 | 959 | ||
959 | set(viewer_LIBRARIES | 960 | set(viewer_LIBRARIES |
960 | ${COCOA_LIBRARY} | 961 | ${COCOA_LIBRARY} |
961 | ${AGL_LIBRARY} | 962 | ${AGL_LIBRARY} |
962 | ${IOKIT_LIBRARY} | 963 | ${IOKIT_LIBRARY} |
964 | ${SECURITY_LIBRARY} | ||
963 | ) | 965 | ) |
964 | 966 | ||
965 | # Add resource files to the project. | 967 | # Add resource files to the project. |
diff --git a/linden/indra/newview/llstartup.cpp b/linden/indra/newview/llstartup.cpp index 6622740..606262f 100644 --- a/linden/indra/newview/llstartup.cpp +++ b/linden/indra/newview/llstartup.cpp | |||
@@ -2935,17 +2935,29 @@ std::string LLStartUp::loadPasswordFromDisk() | |||
2935 | return hashed_password; | 2935 | return hashed_password; |
2936 | } | 2936 | } |
2937 | 2937 | ||
2938 | // UUID is 16 bytes, written into ASCII is 32 characters | ||
2939 | // without trailing \0 | ||
2940 | const S32 HASHED_LENGTH = 32; | ||
2941 | |||
2938 | std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, | 2942 | std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, |
2939 | "password.dat"); | 2943 | "password.dat"); |
2940 | LLFILE* fp = LLFile::fopen(filepath, "rb"); /* Flawfinder: ignore */ | 2944 | LLFILE* fp = LLFile::fopen(filepath, "rb"); /* Flawfinder: ignore */ |
2941 | if (!fp) | 2945 | if (!fp) |
2942 | { | 2946 | { |
2947 | #if LL_DARWIN | ||
2948 | UInt32 passwordLength; | ||
2949 | char *passwordData; | ||
2950 | OSStatus stat = SecKeychainFindGenericPassword(NULL, 10, "Imprudence", 0, NULL, &passwordLength, (void**)&passwordData, NULL); | ||
2951 | if (stat == noErr) | ||
2952 | { | ||
2953 | if (passwordLength == HASHED_LENGTH) | ||
2954 | hashed_password.assign(passwordData, HASHED_LENGTH); | ||
2955 | SecKeychainItemFreeContent(NULL, passwordData); | ||
2956 | } | ||
2957 | #endif | ||
2943 | return hashed_password; | 2958 | return hashed_password; |
2944 | } | 2959 | } |
2945 | 2960 | ||
2946 | // UUID is 16 bytes, written into ASCII is 32 characters | ||
2947 | // without trailing \0 | ||
2948 | const S32 HASHED_LENGTH = 32; | ||
2949 | U8 buffer[HASHED_LENGTH+1]; | 2961 | U8 buffer[HASHED_LENGTH+1]; |
2950 | 2962 | ||
2951 | if (1 != fread(buffer, HASHED_LENGTH, 1, fp)) | 2963 | if (1 != fread(buffer, HASHED_LENGTH, 1, fp)) |
@@ -2969,6 +2981,10 @@ std::string LLStartUp::loadPasswordFromDisk() | |||
2969 | { | 2981 | { |
2970 | hashed_password.assign((char*)buffer); | 2982 | hashed_password.assign((char*)buffer); |
2971 | } | 2983 | } |
2984 | #if LL_DARWIN | ||
2985 | // we're migrating to the keychain | ||
2986 | LLFile::remove(filepath); | ||
2987 | #endif | ||
2972 | 2988 | ||
2973 | return hashed_password; | 2989 | return hashed_password; |
2974 | } | 2990 | } |
@@ -2977,6 +2993,19 @@ std::string LLStartUp::loadPasswordFromDisk() | |||
2977 | // static | 2993 | // static |
2978 | void LLStartUp::savePasswordToDisk(const std::string& hashed_password) | 2994 | void LLStartUp::savePasswordToDisk(const std::string& hashed_password) |
2979 | { | 2995 | { |
2996 | #if LL_DARWIN | ||
2997 | SecKeychainItemRef keychainItem; | ||
2998 | OSStatus status = SecKeychainFindGenericPassword(NULL, 10, "Imprudence", 0, NULL, NULL, NULL, &keychainItem); | ||
2999 | if (status == noErr) | ||
3000 | { | ||
3001 | SecKeychainItemModifyAttributesAndData(keychainItem, NULL, hashed_password.length(), hashed_password.c_str()); | ||
3002 | CFRelease(keychainItem); | ||
3003 | } | ||
3004 | else | ||
3005 | { | ||
3006 | SecKeychainAddGenericPassword(NULL, 10, "Imprudence", 0, NULL, hashed_password.length(), hashed_password.c_str(), NULL); | ||
3007 | } | ||
3008 | #else | ||
2980 | std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, | 3009 | std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, |
2981 | "password.dat"); | 3010 | "password.dat"); |
2982 | LLFILE* fp = LLFile::fopen(filepath, "wb"); /* Flawfinder: ignore */ | 3011 | LLFILE* fp = LLFile::fopen(filepath, "wb"); /* Flawfinder: ignore */ |
@@ -3000,12 +3029,22 @@ void LLStartUp::savePasswordToDisk(const std::string& hashed_password) | |||
3000 | } | 3029 | } |
3001 | 3030 | ||
3002 | fclose(fp); | 3031 | fclose(fp); |
3032 | #endif | ||
3003 | } | 3033 | } |
3004 | 3034 | ||
3005 | 3035 | ||
3006 | // static | 3036 | // static |
3007 | void LLStartUp::deletePasswordFromDisk() | 3037 | void LLStartUp::deletePasswordFromDisk() |
3008 | { | 3038 | { |
3039 | #if LL_DARWIN | ||
3040 | SecKeychainItemRef keychainItem; | ||
3041 | OSStatus status = SecKeychainFindGenericPassword(NULL, 10, "Imprudence", 0, NULL, NULL, NULL, &keychainItem); | ||
3042 | if (status == noErr) | ||
3043 | { | ||
3044 | SecKeychainItemDelete(keychainItem); | ||
3045 | CFRelease(keychainItem); | ||
3046 | } | ||
3047 | #endif | ||
3009 | std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, | 3048 | std::string filepath = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, |
3010 | "password.dat"); | 3049 | "password.dat"); |
3011 | LLFile::remove(filepath); | 3050 | LLFile::remove(filepath); |