Bug 1287937 - Remove obsolete mac-specific code from modules/libmar/verify/MacVerifyCrypto.cpp and mozglue/misc/StackWalk.cpp. r=spohl.
authorstefanh@inbox.com
Sat, 23 Jul 2016 00:29:04 +0200
changeset 306341 0353590d4e05a2d4c87cf5c9c95cbe59d13b1919
parent 306340 e28c3a6965243e23829f5543c06e2888793c4318
child 306342 083f8587e25b972fac83003741cd9b7a8d1e4e8d
push id79839
push userstefanh@inbox.com
push dateSat, 23 Jul 2016 09:45:02 +0000
treeherdermozilla-inbound@0353590d4e05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1287937
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1287937 - Remove obsolete mac-specific code from modules/libmar/verify/MacVerifyCrypto.cpp and mozglue/misc/StackWalk.cpp. r=spohl.
modules/libmar/verify/MacVerifyCrypto.cpp
mozglue/misc/StackWalk.cpp
--- a/modules/libmar/verify/MacVerifyCrypto.cpp
+++ b/modules/libmar/verify/MacVerifyCrypto.cpp
@@ -33,111 +33,19 @@ extern "C" {
                                                   CFStringRef key,
                                                   CFTypeRef value,
                                                   CFErrorRef* error);
   SecTransformSetAttributeFunc SecTransformSetAttributePtr = NULL;
 #ifdef __cplusplus
 }
 #endif
 
-#define MAC_OS_X_VERSION_10_7_HEX 0x00001070
-
-static int sOnLionOrLater = -1;
-
-static bool OnLionOrLater()
-{
-  if (sOnLionOrLater < 0) {
-    SInt32 major = 0, minor = 0;
-
-    CFURLRef url =
-      CFURLCreateWithString(kCFAllocatorDefault,
-                            CFSTR("file:///System/Library/CoreServices/SystemVersion.plist"),
-                            NULL);
-    CFReadStreamRef stream =
-      CFReadStreamCreateWithFile(kCFAllocatorDefault, url);
-    CFReadStreamOpen(stream);
-    CFDictionaryRef sysVersionPlist = (CFDictionaryRef)
-      CFPropertyListCreateWithStream(kCFAllocatorDefault,
-                                     stream, 0, kCFPropertyListImmutable,
-                                     NULL, NULL);
-    CFReadStreamClose(stream);
-    CFRelease(stream);
-    CFRelease(url);
-
-    CFStringRef versionString = (CFStringRef)
-      CFDictionaryGetValue(sysVersionPlist, CFSTR("ProductVersion"));
-    CFArrayRef versions =
-      CFStringCreateArrayBySeparatingStrings(kCFAllocatorDefault,
-                                             versionString, CFSTR("."));
-    CFIndex count = CFArrayGetCount(versions);
-    if (count > 0) {
-      CFStringRef component = (CFStringRef) CFArrayGetValueAtIndex(versions, 0);
-      major = CFStringGetIntValue(component);
-      if (count > 1) {
-        component = (CFStringRef) CFArrayGetValueAtIndex(versions, 1);
-        minor = CFStringGetIntValue(component);
-      }
-    }
-    CFRelease(sysVersionPlist);
-    CFRelease(versions);
-
-    if (major < 10) {
-      sOnLionOrLater = 0;
-    } else {
-      int version = 0x1000 + (minor << 4);
-      sOnLionOrLater = version >= MAC_OS_X_VERSION_10_7_HEX ? 1 : 0;
-    }
-  }
-
-  return sOnLionOrLater > 0 ? true : false;
-}
-
-static bool sCssmInitialized = false;
-static CSSM_VERSION sCssmVersion = {2, 0};
-static const CSSM_GUID sMozCssmGuid =
-  { 0x9243121f, 0x5820, 0x4b41,
-    { 0xa6, 0x52, 0xba, 0xb6, 0x3f, 0x9d, 0x3d, 0x7f }};
-static CSSM_CSP_HANDLE sCspHandle = CSSM_INVALID_HANDLE;
-
-void* cssmMalloc (CSSM_SIZE aSize, void* aAllocRef) {
-  (void)aAllocRef;
-  return malloc(aSize);
-}
-
-void cssmFree (void* aPtr, void* aAllocRef) {
-  (void)aAllocRef;
-  free(aPtr);
-  return;
-}
-
-void* cssmRealloc (void* aPtr, CSSM_SIZE aSize, void* aAllocRef) {
-  (void)aAllocRef;
-  return realloc(aPtr, aSize);
-}
-
-void* cssmCalloc (uint32 aNum, CSSM_SIZE aSize, void* aAllocRef) {
-  (void)aAllocRef;
-  return calloc(aNum, aSize);
-}
-
-static CSSM_API_MEMORY_FUNCS cssmMemFuncs = {
-    &cssmMalloc,
-    &cssmFree,
-    &cssmRealloc,
-    &cssmCalloc,
-    NULL
- };
-
 CryptoX_Result
 CryptoMac_InitCryptoProvider()
 {
-  if (!OnLionOrLater()) {
-    return CryptoX_Success;
-  }
-
   if (!SecTransformCreateReadTransformWithReadStreamPtr) {
     SecTransformCreateReadTransformWithReadStreamPtr =
       (SecTransformCreateReadTransformWithReadStreamFunc)
         dlsym(RTLD_DEFAULT, "SecTransformCreateReadTransformWithReadStream");
   }
   if (!SecTransformExecutePtr) {
     SecTransformExecutePtr = (SecTransformExecuteFunc)
       dlsym(RTLD_DEFAULT, "SecTransformExecute");
@@ -166,109 +74,46 @@ CryptoMac_VerifyBegin(CryptoX_SignatureH
     return CryptoX_Error;
   }
 
   void* inputData = CFDataCreateMutable(kCFAllocatorDefault, 0);
   if (!inputData) {
     return CryptoX_Error;
   }
 
-  if (!OnLionOrLater()) {
-    CSSM_DATA_PTR cssmData = (CSSM_DATA_PTR)malloc(sizeof(CSSM_DATA));
-    if (!cssmData) {
-      CFRelease(inputData);
-      return CryptoX_Error;
-    }
-    cssmData->Data = (uint8*)inputData;
-    cssmData->Length = 0;
-    *aInputData = cssmData;
-    return CryptoX_Success;
-  }
-
   *aInputData = inputData;
   return CryptoX_Success;
 }
 
 CryptoX_Result
 CryptoMac_VerifyUpdate(CryptoX_SignatureHandle* aInputData, void* aBuf,
                        unsigned int aLen)
 {
   if (aLen == 0) {
     return CryptoX_Success;
   }
   if (!aInputData || !*aInputData) {
     return CryptoX_Error;
   }
 
-  CFMutableDataRef inputData;
-  if (!OnLionOrLater()) {
-    inputData = (CFMutableDataRef)((CSSM_DATA_PTR)*aInputData)->Data;
-    ((CSSM_DATA_PTR)*aInputData)->Length += aLen;
-  } else {
-    inputData = (CFMutableDataRef)*aInputData;
-  }
+  CFMutableDataRef inputData = (CFMutableDataRef)*aInputData;
 
   CFDataAppendBytes(inputData, (const uint8*)aBuf, aLen);
   return CryptoX_Success;
 }
 
 CryptoX_Result
 CryptoMac_LoadPublicKey(const unsigned char* aCertData,
                         unsigned int aDataSize,
                         CryptoX_PublicKey* aPublicKey)
 {
   if (!aCertData || aDataSize == 0 || !aPublicKey) {
     return CryptoX_Error;
   }
   *aPublicKey = NULL;
-
-  if (!OnLionOrLater()) {
-    if (!sCspHandle) {
-      CSSM_RETURN rv;
-      if (!sCssmInitialized) {
-        CSSM_PVC_MODE pvcPolicy = CSSM_PVC_NONE;
-        rv = CSSM_Init(&sCssmVersion,
-                       CSSM_PRIVILEGE_SCOPE_PROCESS,
-                       &sMozCssmGuid,
-                       CSSM_KEY_HIERARCHY_NONE,
-                       &pvcPolicy,
-                       NULL);
-        if (rv != CSSM_OK) {
-          return CryptoX_Error;
-        }
-        sCssmInitialized = true;
-      }
-
-      rv = CSSM_ModuleLoad(&gGuidAppleCSP,
-                           CSSM_KEY_HIERARCHY_NONE,
-                           NULL,
-                           NULL);
-      if (rv != CSSM_OK) {
-        return CryptoX_Error;
-      }
-
-      CSSM_CSP_HANDLE cspHandle;
-      rv = CSSM_ModuleAttach(&gGuidAppleCSP,
-                             &sCssmVersion,
-                             &cssmMemFuncs,
-                             0,
-                             CSSM_SERVICE_CSP,
-                             0,
-                             CSSM_KEY_HIERARCHY_NONE,
-                             NULL,
-                             0,
-                             NULL,
-                             &cspHandle);
-      if (rv != CSSM_OK) {
-        return CryptoX_Error;
-      }
-      sCspHandle = cspHandle;
-    }
-  }
-
   CFDataRef certData = CFDataCreate(kCFAllocatorDefault,
                                     aCertData,
                                     aDataSize);
   if (!certData) {
     return CryptoX_Error;
   }
 
   SecCertificateRef cert = SecCertificateCreateWithData(kCFAllocatorDefault,
@@ -294,56 +139,16 @@ CryptoMac_VerifySignature(CryptoX_Signat
                           const unsigned char* aSignature,
                           unsigned int aSignatureLen)
 {
   if (!aInputData || !*aInputData || !aPublicKey || !*aPublicKey ||
       !aSignature || aSignatureLen == 0) {
     return CryptoX_Error;
   }
 
-  if (!OnLionOrLater()) {
-    if (!sCspHandle) {
-      return CryptoX_Error;
-    }
-
-    CSSM_KEY* publicKey;
-    OSStatus status = SecKeyGetCSSMKey((SecKeyRef)*aPublicKey,
-                                       (const CSSM_KEY**)&publicKey);
-    if (status) {
-      return CryptoX_Error;
-    }
-
-    CSSM_CC_HANDLE ccHandle;
-    if (CSSM_CSP_CreateSignatureContext(sCspHandle,
-                                        CSSM_ALGID_SHA1WithRSA,
-                                        NULL,
-                                        publicKey,
-                                        &ccHandle) != CSSM_OK) {
-      return CryptoX_Error;
-    }
-
-    CryptoX_Result result = CryptoX_Error;
-    CSSM_DATA signatureData;
-    signatureData.Data = (uint8*)aSignature;
-    signatureData.Length = aSignatureLen;
-    CSSM_DATA inputData;
-    inputData.Data =
-      CFDataGetMutableBytePtr((CFMutableDataRef)
-                                (((CSSM_DATA_PTR)*aInputData)->Data));
-    inputData.Length = ((CSSM_DATA_PTR)*aInputData)->Length;
-    if (CSSM_VerifyData(ccHandle,
-                        &inputData,
-                        1,
-                        CSSM_ALGID_NONE,
-                        &signatureData) == CSSM_OK) {
-      result = CryptoX_Success;
-    }
-    return result;
-  }
-
   CFDataRef signatureData = CFDataCreate(kCFAllocatorDefault,
                                          aSignature, aSignatureLen);
   if (!signatureData) {
     return CryptoX_Error;
   }
 
   CFErrorRef error;
   SecTransformRef verifier =
@@ -387,32 +192,22 @@ CryptoMac_VerifySignature(CryptoX_Signat
 void
 CryptoMac_FreeSignatureHandle(CryptoX_SignatureHandle* aInputData)
 {
   if (!aInputData || !*aInputData) {
     return;
   }
 
   CFMutableDataRef inputData = NULL;
-  if (OnLionOrLater()) {
-    inputData = (CFMutableDataRef)*aInputData;
-  } else {
-    inputData = (CFMutableDataRef)((CSSM_DATA_PTR)*aInputData)->Data;
-  }
+  inputData = (CFMutableDataRef)*aInputData;
 
   CFRelease(inputData);
-  if (!OnLionOrLater()) {
-    free((CSSM_DATA_PTR)*aInputData);
-  }
 }
 
 void
 CryptoMac_FreePublicKey(CryptoX_PublicKey* aPublicKey)
 {
   if (!aPublicKey || !*aPublicKey) {
     return;
   }
-  if (!OnLionOrLater() && sCspHandle != CSSM_INVALID_HANDLE) {
-    CSSM_ModuleDetach(sCspHandle);
-    sCspHandle = CSSM_INVALID_HANDLE;
-  }
+
   CFRelease((SecKeyRef)*aPublicKey);
 }
--- a/mozglue/misc/StackWalk.cpp
+++ b/mozglue/misc/StackWalk.cpp
@@ -90,35 +90,16 @@ stack_callback(uint32_t aFrameNumber, vo
   // following check for gCriticalAddress.mAddr is critical.
   if (gCriticalAddress.mAddr || dladdr(aPc, &info) == 0  ||
       !info.dli_sname || strcmp(info.dli_sname, name) != 0) {
     return;
   }
   gCriticalAddress.mAddr = aPc;
 }
 
-#if defined(MOZ_WIDGET_COCOA) && defined(DEBUG)
-#define MAC_OS_X_VERSION_10_7_HEX 0x00001070
-
-static int32_t OSXVersion()
-{
-  static int32_t gOSXVersion = 0x0;
-  if (gOSXVersion == 0x0) {
-    OSErr err = ::Gestalt(gestaltSystemVersion, (SInt32*)&gOSXVersion);
-    MOZ_ASSERT(err == noErr);
-  }
-  return gOSXVersion;
-}
-
-static bool OnLionOrLater()
-{
-  return (OSXVersion() >= MAC_OS_X_VERSION_10_7_HEX);
-}
-#endif
-
 static void
 my_malloc_logger(uint32_t aType,
                  uintptr_t aArg1, uintptr_t aArg2, uintptr_t aArg3,
                  uintptr_t aResult, uint32_t aNumHotFramesToSkip)
 {
   static bool once = false;
   if (once) {
     return;
@@ -165,22 +146,16 @@ StackWalkInitCriticalAddress()
   r = pthread_mutex_lock(&mutex);
   MOZ_ASSERT(r == 0);
   struct timespec abstime = { 0, 1 };
   r = pthread_cond_timedwait_relative_np(&cond, &mutex, &abstime);
 
   // restore the previous malloc logger
   malloc_logger = old_malloc_logger;
 
-  // On Lion, malloc is no longer called from pthread_cond_*wait*. This prevents
-  // us from finding the address, but that is fine, since with no call to malloc
-  // there is no critical address.
-#ifdef MOZ_WIDGET_COCOA
-  MOZ_ASSERT(OnLionOrLater() || gCriticalAddress.mAddr != nullptr);
-#endif
   MOZ_ASSERT(r == ETIMEDOUT);
   r = pthread_mutex_unlock(&mutex);
   MOZ_ASSERT(r == 0);
   r = pthread_mutex_destroy(&mutex);
   MOZ_ASSERT(r == 0);
   r = pthread_cond_destroy(&cond);
   MOZ_ASSERT(r == 0);
 }