Changeset 256016 in webkit


Ignore:
Timestamp:
Feb 7, 2020 2:42:37 AM (4 years ago)
Author:
youenn@apple.com
Message:

Mandate UUID version 4 for mDNS ICE candidates
https://bugs.webkit.org/show_bug.cgi?id=207329

Reviewed by Alex Christensen.

Source/WebCore:

Ignore ICE candidates if they are mDNS but not UUID version 4.
Covered by existing tests relying on mDNS to do the connection.

  • Modules/mediastream/PeerConnectionBackend.cpp:

(WebCore::shouldIgnoreCandidate):
(WebCore::PeerConnectionBackend::addIceCandidate):

Source/WebKit:

  • NetworkProcess/webrtc/NetworkMDNSRegister.cpp:

(WebKit::NetworkMDNSRegister::registerMDNSName):
Remove the count at the end of the mDNS name to make it a fully version 4 UUID.

Source/WTF:

Add a routine to validate version 4 UUID.

  • wtf/UUID.cpp:

(WTF::isHexadecimalCharacter):
(WTF::isVersion4UUID):

  • wtf/UUID.h:
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r256011 r256016  
     12020-02-07  youenn fablet  <youenn@apple.com>
     2
     3        Mandate UUID version 4 for mDNS ICE candidates
     4        https://bugs.webkit.org/show_bug.cgi?id=207329
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add a routine to validate version 4 UUID.
     9
     10        * wtf/UUID.cpp:
     11        (WTF::isHexadecimalCharacter):
     12        (WTF::isVersion4UUID):
     13        * wtf/UUID.h:
     14
    1152020-02-07  Yusuke Suzuki  <ysuzuki@apple.com>
    216
  • trunk/Source/WTF/wtf/UUID.cpp

    r254046 r256016  
    8282}
    8383
     84static inline bool isHexadecimalCharacter(UChar character)
     85{
     86    return (character >= '0' && character <= '9')
     87        || (character >= 'a' && character <= 'f')
     88        || (character >= 'A' && character <= 'F');
     89}
     90
     91bool isVersion4UUID(StringView value)
     92{
     93    // Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx with hexadecimal digits for x and one of 8, 9, A, or B for y.
     94    if (value.length() != 36)
     95        return false;
     96
     97    for (auto cptr = 0; cptr < 36; ++cptr) {
     98        if (cptr == 8 || cptr == 13 || cptr == 18 || cptr == 23) {
     99            if (value[cptr] != '-')
     100                return false;
     101            continue;
     102        }
     103        if (cptr == 14) {
     104            if (value[cptr] != '4')
     105                return false;
     106            continue;
     107        }
     108        if (cptr == 19) {
     109            auto y = value[cptr];
     110            if (y != '8' && y != '9' && y != 'a' && y != 'A' && y != 'b' && y != 'B')
     111                return false;
     112            continue;
     113        }
     114        if (!isHexadecimalCharacter(value[cptr]))
     115            return false;
     116    }
     117    return true;
     118}
     119
    84120} // namespace WTF
  • trunk/Source/WTF/wtf/UUID.h

    r241733 r256016  
    3535namespace WTF {
    3636
     37class StringView;
     38
    3739// Creates a UUID that consists of 32 hexadecimal digits and returns its canonical form.
    3840// The canonical form is displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters.
     
    4749
    4850WTF_EXPORT_PRIVATE String bootSessionUUIDString();
     51WTF_EXPORT_PRIVATE bool isVersion4UUID(StringView);
    4952
    5053}
  • trunk/Source/WebCore/ChangeLog

    r256014 r256016  
     12020-02-07  youenn fablet  <youenn@apple.com>
     2
     3        Mandate UUID version 4 for mDNS ICE candidates
     4        https://bugs.webkit.org/show_bug.cgi?id=207329
     5
     6        Reviewed by Alex Christensen.
     7
     8        Ignore ICE candidates if they are mDNS but not UUID version 4.
     9        Covered by existing tests relying on mDNS to do the connection.
     10
     11        * Modules/mediastream/PeerConnectionBackend.cpp:
     12        (WebCore::shouldIgnoreCandidate):
     13        (WebCore::PeerConnectionBackend::addIceCandidate):
     14
    1152020-02-07  Tomoki Imai  <Tomoki.Imai@sony.com>
    216
  • trunk/Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp

    r256009 r256016  
    4747#include "RTCTrackEvent.h"
    4848#include "RuntimeEnabledFeatures.h"
     49#include <wtf/UUID.h>
    4950#include <wtf/text/StringBuilder.h>
    5051#include <wtf/text/StringConcatenateNumbers.h>
     
    303304}
    304305
    305 static String extractIPAddres(const String& sdp)
    306 {
    307     ASSERT(sdp.contains(" host "));
     306static String extractIPAddress(const String& sdp)
     307{
    308308    unsigned counter = 0;
    309309    for (auto item : StringView { sdp }.split(' ')) {
     
    314314}
    315315
     316static inline bool shouldIgnoreIceCandidate(const RTCIceCandidate& iceCandidate)
     317{
     318    auto address = extractIPAddress(iceCandidate.candidate());
     319    if (!address.endsWithIgnoringASCIICase(".local"_s))
     320        return false;
     321
     322    if (!WTF::isVersion4UUID(StringView { address }.substring(0, address.length() - 6))) {
     323        RELEASE_LOG_ERROR(WebRTC, "mDNS candidate is not a Version 4 UUID");
     324        return true;
     325    }
     326    return false;
     327}
     328
    316329void PeerConnectionBackend::addIceCandidate(RTCIceCandidate* iceCandidate, DOMPromiseDeferred<void>&& promise)
    317330{
     
    328341        return;
    329342    }
     343
     344    if (shouldIgnoreIceCandidate(*iceCandidate)) {
     345        promise.resolve();
     346        return;
     347    }
     348
    330349    m_addIceCandidatePromise = WTF::makeUnique<DOMPromiseDeferred<void>>(WTFMove(promise));
    331350    doAddIceCandidate(*iceCandidate);
     
    451470            m_pendingICECandidates.append(PendingICECandidate { String { sdp }, WTFMove(mid), sdpMLineIndex, WTFMove(serverURL) });
    452471            if (RuntimeEnabledFeatures::sharedFeatures().webRTCMDNSICECandidatesEnabled()) {
    453                 auto ipAddress = extractIPAddres(sdp);
     472                auto ipAddress = extractIPAddress(sdp);
    454473                // We restrict to IPv4 candidates for now.
    455474                if (ipAddress.contains('.'))
  • trunk/Source/WebKit/ChangeLog

    r256013 r256016  
     12020-02-07  youenn fablet  <youenn@apple.com>
     2
     3        Mandate UUID version 4 for mDNS ICE candidates
     4        https://bugs.webkit.org/show_bug.cgi?id=207329
     5
     6        Reviewed by Alex Christensen.
     7
     8        * NetworkProcess/webrtc/NetworkMDNSRegister.cpp:
     9        (WebKit::NetworkMDNSRegister::registerMDNSName):
     10        Remove the count at the end of the mDNS name to make it a fully version 4 UUID.
     11
    1122020-02-07  Patrick Griffis  <pgriffis@igalia.com>
    213
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkMDNSRegister.cpp

    r249980 r256016  
    127127        service = iterator->value;
    128128
    129     String name = makeString(createCanonicalUUIDString(), pendingRegistrationRequestCount, ".local");
     129    String name = makeString(createCanonicalUUIDString(), ".local");
    130130
    131131    auto ip = inet_addr(ipAddress.utf8().data());
Note: See TracChangeset for help on using the changeset viewer.