nsIDNService.h (3508B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef nsIDNService_h__ 7 #define nsIDNService_h__ 8 9 #include "nsIIDNService.h" 10 11 #include "mozilla/RWLock.h" 12 #include "mozilla/intl/UnicodeScriptCodes.h" 13 #include "mozilla/net/IDNBlocklistUtils.h" 14 #include "mozilla/Span.h" 15 #include "nsTHashSet.h" 16 17 class nsIPrefBranch; 18 19 //----------------------------------------------------------------------------- 20 // nsIDNService 21 //----------------------------------------------------------------------------- 22 23 namespace mozilla::net { 24 enum ScriptCombo : int32_t; 25 } 26 27 class nsIDNService final : public nsIIDNService { 28 public: 29 NS_DECL_THREADSAFE_ISUPPORTS 30 NS_DECL_NSIIDNSERVICE 31 32 nsIDNService(); 33 34 nsresult Init(); 35 36 protected: 37 virtual ~nsIDNService(); 38 39 private: 40 void InitCJKSlashConfusables(); 41 void InitCJKIdeographs(); 42 void InitDigitConfusables(); 43 void InitCyrillicLatinConfusables(); 44 void InitThaiLatinConfusables(); 45 46 public: 47 /** 48 * Determine whether a label is considered safe to display to the user 49 * according to the algorithm defined in UTR 39. 50 * 51 * For the ASCII-only profile, returns false for all labels containing 52 * non-ASCII characters. 53 * 54 * For the other profiles, returns false for labels containing any of 55 * the following: 56 * 57 * Characters in scripts other than the "recommended scripts" and 58 * "aspirational scripts" defined in 59 * http://www.unicode.org/reports/tr31/#Table_Recommended_Scripts 60 * and http://www.unicode.org/reports/tr31/#Aspirational_Use_Scripts 61 * This includes codepoints that are not defined as Unicode 62 * characters 63 * 64 * Illegal combinations of scripts (@see illegalScriptCombo) 65 * 66 * Numbers from more than one different numbering system 67 * 68 * Sequences of the same non-spacing mark 69 * 70 * Both simplified-only and traditional-only Chinese characters 71 * XXX this test was disabled by bug 857481 72 */ 73 bool IsLabelSafe(mozilla::Span<const char32_t> aLabel, 74 mozilla::Span<const char32_t> aTLD); 75 76 private: 77 /** 78 * Determine whether a combination of scripts in a single label is 79 * permitted according to the algorithm defined in UTR 39. 80 * 81 * All characters in each identifier must be from a single script, 82 * or from the combinations: 83 * Latin + Han + Hiragana + Katakana; 84 * Latin + Han + Bopomofo; or 85 * Latin + Han + Hangul 86 */ 87 bool illegalScriptCombo(mozilla::intl::Script script, 88 mozilla::net::ScriptCombo& savedScript); 89 90 bool isCJKSlashConfusable(char32_t aChar); 91 bool isCJKIdeograph(char32_t aChar); 92 93 nsTArray<mozilla::net::BlocklistRange> mIDNBlocklist; 94 95 // Confusables that we would like to check for IDN spoofing detection. 96 nsTHashSet<char32_t> mCJKSlashConfusables; 97 nsTHashSet<char32_t> mCJKIdeographs; 98 nsTHashSet<char32_t> mDigitConfusables; 99 nsTHashSet<char32_t> mCyrillicLatinConfusables; 100 nsTHashSet<char32_t> mThaiLatinConfusables; 101 }; 102 103 extern "C" MOZ_EXPORT bool mozilla_net_is_label_safe(const char32_t* aLabel, 104 size_t aLabelLen, 105 const char32_t* aTld, 106 size_t aTldLen); 107 108 #endif // nsIDNService_h__