Changeset 226224 in webkit


Ignore:
Timestamp:
Dec 21, 2017 9:18:31 AM (6 years ago)
Author:
Brent Fulgham
Message:

Adopt new secure coding APIs in WebCore
https://bugs.webkit.org/show_bug.cgi?id=178484
<rdar://problem/34837193>

Reviewed by Eric Carlson.

Source/WebCore:

Switch to new NSKeyed[Un]Archiver methods that use NSSecureCoding by default.

Most of the new API is wrapped in a set of convenience methods so we can
build without the new API on older systems.

No change in behavior.

  • editing/cocoa/EditorCocoa.mm:

(WebCore::archivedDataForAttributedString): Use new convenience method
to archive the string object.

  • platform/ios/PlatformPasteboardIOS.mm:

(WebCore::PlatformPasteboard::write): Use new secure API.
(WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): Ditto.

Source/WebCore/PAL:

Due to <rdar://problem/31376830 we cannot used SecureCoding on NSAttributedString
in some cases. Add a macro for OS revisions that do not support secure coding,
and use the standard unarchive operation for NSAttributedString in those cases.

Rename 'insecurelyUnarchiveObjectOfClassFromData' to 'insecurelyUnarchiveObjectFromData',
and move it earlier in the file so that it can be reused in 'unarchivedObjectOfClassFromData'.

  • pal/spi/cocoa/NSKeyedArchiverSPI.h:

(insecurelyUnarchiveObjectFromData): Renamed from insecurelyUnarchiveObjectOfClassFromData.
(unarchivedObjectOfClassFromData): Renamed from 'securelyUnarchiveObjectOfClassFromData' and
modified to use 'insecurelyUnarchiveObjectFromData'.
(securelyUnarchiveObjectOfClassFromData): Deleted.
(insecurelyUnarchiveObjectOfClassFromData): Deleted.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r226221 r226224  
     12017-12-21  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Adopt new secure coding APIs in WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=178484
     5        <rdar://problem/34837193>
     6
     7        Reviewed by Eric Carlson.
     8
     9        Switch to new NSKeyed[Un]Archiver methods that use NSSecureCoding by default.
     10
     11        Most of the new API is wrapped in a set of convenience methods so we can
     12        build without the new API on older systems.
     13
     14        No change in behavior.
     15
     16        * editing/cocoa/EditorCocoa.mm:
     17        (WebCore::archivedDataForAttributedString): Use new convenience method
     18        to archive the string object.
     19        * platform/ios/PlatformPasteboardIOS.mm:
     20        (WebCore::PlatformPasteboard::write): Use new secure API.
     21        (WebCore::PlatformPasteboard::typesSafeForDOMToReadAndWrite const): Ditto.
     22
    1232017-12-21  Zalan Bujtas  <zalan@apple.com>
    224
  • trunk/Source/WebCore/PAL/ChangeLog

    r226218 r226224  
     12017-12-21  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Adopt new secure coding APIs in WebCore
     4        https://bugs.webkit.org/show_bug.cgi?id=178484
     5        <rdar://problem/34837193>
     6
     7        Reviewed by Eric Carlson.
     8
     9        Due to <rdar://problem/31376830 we cannot used SecureCoding on NSAttributedString
     10        in some cases. Add a macro for OS revisions that do not support secure coding,
     11        and use the standard unarchive operation for NSAttributedString in those cases.
     12
     13        Rename 'insecurelyUnarchiveObjectOfClassFromData' to 'insecurelyUnarchiveObjectFromData',
     14        and move it earlier in the file so that it can be reused in 'unarchivedObjectOfClassFromData'.
     15
     16        * pal/spi/cocoa/NSKeyedArchiverSPI.h:
     17        (insecurelyUnarchiveObjectFromData): Renamed from insecurelyUnarchiveObjectOfClassFromData.
     18        (unarchivedObjectOfClassFromData): Renamed from 'securelyUnarchiveObjectOfClassFromData' and
     19        modified to use 'insecurelyUnarchiveObjectFromData'.
     20        (securelyUnarchiveObjectOfClassFromData): Deleted.
     21        (insecurelyUnarchiveObjectOfClassFromData): Deleted.
     22
    1232017-12-21  Jeremy Jones  <jeremyj@apple.com>
    224
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/NSKeyedArchiverSPI.h

    r225309 r226224  
    3131
    3232#define USE_SECURE_ARCHIVER_API ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101302 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110200) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 40200) || (PLATFORM(TVOS) && __TV_OS_VERSION_MIN_REQUIRED >= 110200))
     33
     34#define USE_SECURE_ARCHIVER_FOR_ATTRIBUTED_STRING ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101302 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) || (PLATFORM(WATCHOS) && __WATCH_OS_VERSION_MIN_REQUIRED >= 50000) || (PLATFORM(TVOS) && __TV_OS_VERSION_MIN_REQUIRED >= 120000))
    3335
    3436#if USE(SECURE_ARCHIVER_API)
     
    8385}
    8486
    85 inline id _Nullable securelyUnarchiveObjectOfClassFromData(Class _Nonnull cls, NSData * _Nonnull data)
    86 {
    87 #if USE(SECURE_ARCHIVER_API)
    88     NSError *error;
    89     id value = [NSKeyedUnarchiver unarchivedObjectOfClass:cls fromData:data error:&error];
    90     if (!data)
    91         LOG_ERROR("Unable to unarchive data: %@", error);
    92     return value;
    93 #else
    94     UNUSED_PARAM(cls);
    95     return [NSKeyedUnarchiver unarchiveObjectWithData:data];
    96 #endif
    97 }
    98 
    99 inline id _Nullable insecurelyUnarchiveObjectOfClassFromData(NSData * _Nonnull data)
     87inline id _Nullable insecurelyUnarchiveObjectFromData(NSData * _Nonnull data)
    10088{
    10189#pragma clang diagnostic push
     
    10391    return [NSKeyedUnarchiver unarchiveObjectWithData:data];
    10492#pragma clang diagnostic pop
     93}
     94
     95inline id _Nullable unarchivedObjectOfClassFromData(Class _Nonnull cls, NSData * _Nonnull data)
     96{
     97#if USE(SECURE_ARCHIVER_API)
     98#if !USE(SECURE_ARCHIVER_FOR_ATTRIBUTED_STRING)
     99    // Remove this code when the fix from <rdar://problem/31376830> is deployed to all relevant build targets.
     100    if (cls == [NSAttributedString class])
     101        return insecurelyUnarchiveObjectFromData(data);
     102#endif
     103    NSError *error;
     104    id value = [NSKeyedUnarchiver unarchivedObjectOfClass:cls fromData:data error:&error];
     105    if (!value)
     106        LOG_ERROR("Unable to unarchive data: %@", error);
     107    return value;
     108#else
     109    UNUSED_PARAM(cls);
     110    return insecurelyUnarchiveObjectFromData(data);
     111#endif
    105112}
    106113
  • trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm

    r226213 r226224  
    11/*
    2  * Copyright (C) 2006-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    143143        return nullptr;
    144144
    145     return SharedBuffer::create(insecurelyArchivedDataWithRootObject(attributedString));
     145    return SharedBuffer::create(securelyArchivedDataWithRootObject(attributedString));
    146146}
    147147
  • trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm

    r225276 r226224  
    266266
    267267    if (content.dataInAttributedStringFormat) {
    268         NSAttributedString *attributedString = insecurelyUnarchiveObjectOfClassFromData(content.dataInAttributedStringFormat->createNSData().get());
     268        NSAttributedString *attributedString = unarchivedObjectOfClassFromData([NSAttributedString class], content.dataInAttributedStringFormat->createNSData().get());
    269269        if (attributedString)
    270270            [representationsToRegister addRepresentingObject:attributedString];
     
    381381            continue;
    382382
    383         NSDictionary *teamDataObject = insecurelyUnarchiveObjectOfClassFromData(provider.teamData);
     383        NSDictionary *teamDataObject = unarchivedObjectOfClassFromData([NSDictionary class], provider.teamData);
    384384        if (!teamDataObject)
    385385            continue;
     
    446446            for (auto& type : data.orderedTypes)
    447447                [typesAsNSArray addObject:type];
    448             [representationsToRegister setTeamData:insecurelyArchivedDataWithRootObject(@{ @(originKeyForTeamData) : data.origin, @(customTypesKeyForTeamData) : typesAsNSArray })];
     448            [representationsToRegister setTeamData:securelyArchivedDataWithRootObject(@{ @(originKeyForTeamData) : data.origin, @(customTypesKeyForTeamData) : typesAsNSArray })];
    449449            [representationsToRegister addData:serializedSharedBuffer.get() forType:@(PasteboardCustomData::cocoaType())];
    450450        }
Note: See TracChangeset for help on using the changeset viewer.