ICU 64.2
64.2
|
Unicode Security and Spoofing Detection, C API. More...
#include "unicode/utypes.h"
#include "unicode/uset.h"
#include "unicode/parseerr.h"
#include "unicode/localpointer.h"
#include "unicode/unistr.h"
#include "unicode/uniset.h"
Go to the source code of this file.
Namespaces | |
icu | |
File coll.h. | |
Typedefs | |
typedef struct USpoofChecker | USpoofChecker |
typedef for C of USpoofChecker More... | |
typedef struct USpoofCheckResult | USpoofCheckResult |
typedef enum USpoofChecks | USpoofChecks |
Enum for the kinds of checks that USpoofChecker can perform. More... | |
typedef enum URestrictionLevel | URestrictionLevel |
Constants from UAX #39 for use in uspoof_setRestrictionLevel, and for returned identifier restriction levels in check results. More... | |
Functions | |
USpoofChecker * | uspoof_open (UErrorCode *status) |
Create a Unicode Spoof Checker, configured to perform all checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT. More... | |
USpoofChecker * | uspoof_openFromSerialized (const void *data, int32_t length, int32_t *pActualLength, UErrorCode *pErrorCode) |
Open a Spoof checker from its serialized form, stored in 32-bit-aligned memory. More... | |
USpoofChecker * | uspoof_openFromSource (const char *confusables, int32_t confusablesLen, const char *confusablesWholeScript, int32_t confusablesWholeScriptLen, int32_t *errType, UParseError *pe, UErrorCode *status) |
Open a Spoof Checker from the source form of the spoof data. More... | |
void | uspoof_close (USpoofChecker *sc) |
Close a Spoof Checker, freeing any memory that was being held by its implementation. More... | |
USpoofChecker * | uspoof_clone (const USpoofChecker *sc, UErrorCode *status) |
Clone a Spoof Checker. More... | |
U_STABLE void U_EXPORT2 | uspoof_setChecks (USpoofChecker *sc, int32_t checks, UErrorCode *status) |
Specify the bitmask of checks that will be performed by uspoof_check. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_getChecks (const USpoofChecker *sc, UErrorCode *status) |
Get the set of checks that this Spoof Checker has been configured to perform. More... | |
U_STABLE void U_EXPORT2 | uspoof_setRestrictionLevel (USpoofChecker *sc, URestrictionLevel restrictionLevel) |
Set the loosest restriction level allowed for strings. More... | |
U_STABLE URestrictionLevel U_EXPORT2 | uspoof_getRestrictionLevel (const USpoofChecker *sc) |
Get the Restriction Level that will be tested if the checks include USPOOF_RESTRICTION_LEVEL. More... | |
U_STABLE void U_EXPORT2 | uspoof_setAllowedLocales (USpoofChecker *sc, const char *localesList, UErrorCode *status) |
Limit characters that are acceptable in identifiers being checked to those normally used with the languages associated with the specified locales. More... | |
U_STABLE const char *U_EXPORT2 | uspoof_getAllowedLocales (USpoofChecker *sc, UErrorCode *status) |
Get a list of locales for the scripts that are acceptable in strings to be checked. More... | |
U_STABLE void U_EXPORT2 | uspoof_setAllowedChars (USpoofChecker *sc, const USet *chars, UErrorCode *status) |
Limit the acceptable characters to those specified by a Unicode Set. More... | |
U_STABLE const USet *U_EXPORT2 | uspoof_getAllowedChars (const USpoofChecker *sc, UErrorCode *status) |
Get a USet for the characters permitted in an identifier. More... | |
U_STABLE void U_EXPORT2 | uspoof_setAllowedUnicodeSet (USpoofChecker *sc, const icu::UnicodeSet *chars, UErrorCode *status) |
Limit the acceptable characters to those specified by a Unicode Set. More... | |
U_STABLE const icu::UnicodeSet *U_EXPORT2 | uspoof_getAllowedUnicodeSet (const USpoofChecker *sc, UErrorCode *status) |
Get a UnicodeSet for the characters permitted in an identifier. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_check (const USpoofChecker *sc, const UChar *id, int32_t length, int32_t *position, UErrorCode *status) |
Check the specified string for possible security issues. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_checkUTF8 (const USpoofChecker *sc, const char *id, int32_t length, int32_t *position, UErrorCode *status) |
Check the specified string for possible security issues. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_checkUnicodeString (const USpoofChecker *sc, const icu::UnicodeString &id, int32_t *position, UErrorCode *status) |
Check the specified string for possible security issues. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_check2 (const USpoofChecker *sc, const UChar *id, int32_t length, USpoofCheckResult *checkResult, UErrorCode *status) |
Check the specified string for possible security issues. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_check2UTF8 (const USpoofChecker *sc, const char *id, int32_t length, USpoofCheckResult *checkResult, UErrorCode *status) |
Check the specified string for possible security issues. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_check2UnicodeString (const USpoofChecker *sc, const icu::UnicodeString &id, USpoofCheckResult *checkResult, UErrorCode *status) |
Check the specified string for possible security issues. More... | |
U_STABLE USpoofCheckResult *U_EXPORT2 | uspoof_openCheckResult (UErrorCode *status) |
Create a USpoofCheckResult, used by the uspoof_check2 class of functions to return information about the identifier. More... | |
U_STABLE void U_EXPORT2 | uspoof_closeCheckResult (USpoofCheckResult *checkResult) |
Close a USpoofCheckResult, freeing any memory that was being held by its implementation. More... | |
U_NAMESPACE_END U_STABLE int32_t U_EXPORT2 | uspoof_getCheckResultChecks (const USpoofCheckResult *checkResult, UErrorCode *status) |
Indicates which of the spoof check(s) have failed. More... | |
U_STABLE URestrictionLevel U_EXPORT2 | uspoof_getCheckResultRestrictionLevel (const USpoofCheckResult *checkResult, UErrorCode *status) |
Gets the restriction level that the text meets, if the USPOOF_RESTRICTION_LEVEL check was enabled; otherwise, undefined. More... | |
U_STABLE const USet *U_EXPORT2 | uspoof_getCheckResultNumerics (const USpoofCheckResult *checkResult, UErrorCode *status) |
Gets the set of numerics found in the string, if the USPOOF_MIXED_NUMBERS check was enabled; otherwise, undefined. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_areConfusable (const USpoofChecker *sc, const UChar *id1, int32_t length1, const UChar *id2, int32_t length2, UErrorCode *status) |
Check the whether two specified strings are visually confusable. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_areConfusableUTF8 (const USpoofChecker *sc, const char *id1, int32_t length1, const char *id2, int32_t length2, UErrorCode *status) |
A version of uspoof_areConfusable accepting strings in UTF-8 format. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_areConfusableUnicodeString (const USpoofChecker *sc, const icu::UnicodeString &s1, const icu::UnicodeString &s2, UErrorCode *status) |
A version of uspoof_areConfusable accepting UnicodeStrings. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_getSkeleton (const USpoofChecker *sc, uint32_t type, const UChar *id, int32_t length, UChar *dest, int32_t destCapacity, UErrorCode *status) |
Get the "skeleton" for an identifier. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_getSkeletonUTF8 (const USpoofChecker *sc, uint32_t type, const char *id, int32_t length, char *dest, int32_t destCapacity, UErrorCode *status) |
Get the "skeleton" for an identifier. More... | |
U_I18N_API icu::UnicodeString &U_EXPORT2 | uspoof_getSkeletonUnicodeString (const USpoofChecker *sc, uint32_t type, const icu::UnicodeString &id, icu::UnicodeString &dest, UErrorCode *status) |
Get the "skeleton" for an identifier. More... | |
U_STABLE const USet *U_EXPORT2 | uspoof_getInclusionSet (UErrorCode *status) |
Get the set of Candidate Characters for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms. More... | |
U_STABLE const USet *U_EXPORT2 | uspoof_getRecommendedSet (UErrorCode *status) |
Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms. More... | |
U_STABLE const icu::UnicodeSet *U_EXPORT2 | uspoof_getInclusionUnicodeSet (UErrorCode *status) |
Get the set of Candidate Characters for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms. More... | |
U_STABLE const icu::UnicodeSet *U_EXPORT2 | uspoof_getRecommendedUnicodeSet (UErrorCode *status) |
Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms. More... | |
U_STABLE int32_t U_EXPORT2 | uspoof_serialize (USpoofChecker *sc, void *data, int32_t capacity, UErrorCode *status) |
Serialize the data for a spoof detector into a chunk of memory. More... | |
Unicode Security and Spoofing Detection, C API.
This class, based on Unicode Technical Report #36 and Unicode Technical Standard #39, has two main functions:
Although originally designed as a method for flagging suspicious identifier strings such as URLs, USpoofChecker
has a number of other practical use cases, such as preventing attempts to evade bad-word content filters.
The functions of this class are exposed as C API, with a handful of syntactical conveniences for C++.
The following example shows how to use USpoofChecker
to check for confusability between two strings:
The call to uspoof_open creates a USpoofChecker
object; the call to uspoof_setChecks enables confusable checking and disables all other checks; the call to uspoof_areConfusable performs the confusability test; and the following line extracts the result out of the return value. For best performance, the instance should be created once (e.g., upon application startup), and the efficient uspoof_areConfusable method can be used at runtime.
The type LocalUSpoofCheckerPointer is exposed for C++ programmers. It will automatically call uspoof_close when the object goes out of scope:
UTS 39 defines two strings to be confusable if they map to the same skeleton string. A skeleton can be thought of as a "hash code". uspoof_getSkeleton computes the skeleton for a particular string, so the following snippet is equivalent to the example above:
If you need to check if a string is confusable with any string in a dictionary of many strings, rather than calling uspoof_areConfusable many times in a loop, uspoof_getSkeleton can be used instead, as shown below:
Note: Since the Unicode confusables mapping table is frequently updated, confusable skeletons are not guaranteed to be the same between ICU releases. We therefore recommend that you always compute confusable skeletons at runtime and do not rely on creating a permanent, or difficult to update, database of skeletons.
The following snippet shows a minimal example of using USpoofChecker
to perform spoof detection on a string:
As in the case for confusability checking, it is good practice to create one USpoofChecker
instance at startup, and call the cheaper uspoof_check online. We specify the set of allowed characters to be those with type RECOMMENDED or INCLUSION, according to the recommendation in UTS 39.
In addition to uspoof_check, the function uspoof_checkUTF8 is exposed for UTF8-encoded char* strings, and uspoof_checkUnicodeString is exposed for C++ programmers.
If the USPOOF_AUX_INFO check is enabled, a limited amount of information on why a string failed the checks is available in the returned bitmask. For complete information, use the uspoof_check2 class of functions with a USpoofCheckResult parameter:
C++ users can take advantage of a few syntactical conveniences. The following snippet is functionally equivalent to the one above:
The return value is a bitmask of the checks that failed. In this case, there was one check that failed: USPOOF_RESTRICTION_LEVEL, corresponding to the fifth bit (16). The possible checks are:
RESTRICTION_LEVEL
: flags strings that violate the Restriction Level test as specified in UTS 39; in most cases, this means flagging strings that contain characters from multiple different scripts. INVISIBLE
: flags strings that contain invisible characters, such as zero-width spaces, or character sequences that are likely not to display, such as multiple occurrences of the same non-spacing mark. CHAR_LIMIT
: flags strings that contain characters outside of a specified set of acceptable characters. See uspoof_setAllowedChars and uspoof_setAllowedLocales. MIXED_NUMBERS
: flags strings that contain digits from multiple different numbering systems. These checks can be enabled independently of each other. For example, if you were interested in checking for only the INVISIBLE and MIXED_NUMBERS conditions, you could do:
Here is an example in C++ showing how to compute the restriction level of a string:
The code '0x50000000' corresponds to the restriction level USPOOF_MINIMALLY_RESTRICTIVE. Since USPOOF_MINIMALLY_RESTRICTIVE is weaker than USPOOF_MODERATELY_RESTRICTIVE, the string fails the check.
Note: The Restriction Level is the most powerful of the checks. The full logic is documented in UTS 39, but the basic idea is that strings are restricted to contain characters from only a single script, except that most scripts are allowed to have Latin characters interspersed. Although the default restriction level is HIGHLY_RESTRICTIVE
, it is recommended that users set their restriction level to MODERATELY_RESTRICTIVE
, which allows Latin mixed with all other scripts except Cyrillic, Greek, and Cherokee, with which it is often confusable. For more details on the levels, see UTS 39 or URestrictionLevel. The Restriction Level test is aware of the set of allowed characters set in uspoof_setAllowedChars. Note that characters which have script code COMMON or INHERITED, such as numbers and punctuation, are ignored when computing whether a string has multiple scripts.
A USpoofChecker
instance may be used repeatedly to perform checks on any number of identifiers.
Thread Safety: The test functions for checking a single identifier, or for testing whether two identifiers are possible confusable, are thread safe. They may called concurrently, from multiple threads, using the same USpoofChecker instance.
More generally, the standard ICU thread safety rules apply: functions that take a const USpoofChecker parameter are thread safe. Those that take a non-const USpoofChecker are not thread safe..
Definition in file uspoof.h.
typedef enum URestrictionLevel URestrictionLevel |
Constants from UAX #39 for use in uspoof_setRestrictionLevel, and for returned identifier restriction levels in check results.
typedef struct USpoofChecker USpoofChecker |
typedef struct USpoofCheckResult USpoofCheckResult |
typedef enum USpoofChecks USpoofChecks |
Enum for the kinds of checks that USpoofChecker can perform.
These enum values are used both to select the set of checks that will be performed, and to report results from the check function.
enum URestrictionLevel |
Constants from UAX #39 for use in uspoof_setRestrictionLevel, and for returned identifier restriction levels in check results.
Enumerator | |
---|---|
USPOOF_ASCII | All characters in the string are in the identifier profile and all characters in the string are in the ASCII range.
|
USPOOF_SINGLE_SCRIPT_RESTRICTIVE | The string classifies as ASCII-Only, or all characters in the string are in the identifier profile and the string is single-script, according to the definition in UTS 39 section 5.1.
|
USPOOF_HIGHLY_RESTRICTIVE | The string classifies as Single Script, or all characters in the string are in the identifier profile and the string is covered by any of the following sets of scripts, according to the definition in UTS 39 section 5.1:
This is the default restriction in ICU.
|
USPOOF_MODERATELY_RESTRICTIVE | The string classifies as Highly Restrictive, or all characters in the string are in the identifier profile and the string is covered by Latin and any one other Recommended or Aspirational script, except Cyrillic, Greek, and Cherokee.
|
USPOOF_MINIMALLY_RESTRICTIVE | All characters in the string are in the identifier profile. Allow arbitrary mixtures of scripts.
|
USPOOF_UNRESTRICTIVE | Any valid identifiers, including characters outside of the Identifier Profile.
|
USPOOF_RESTRICTION_LEVEL_MASK | Mask for selecting the Restriction Level bits from the return value of uspoof_check.
|
USPOOF_UNDEFINED_RESTRICTIVE | An undefined restriction level.
|
enum USpoofChecks |
Enum for the kinds of checks that USpoofChecker can perform.
These enum values are used both to select the set of checks that will be performed, and to report results from the check function.
Enumerator | |
---|---|
USPOOF_SINGLE_SCRIPT_CONFUSABLE | When performing the two-string uspoof_areConfusable test, this flag in the return value indicates that the two strings are visually confusable and that they are from the same script, according to UTS 39 section 4.
|
USPOOF_MIXED_SCRIPT_CONFUSABLE | When performing the two-string uspoof_areConfusable test, this flag in the return value indicates that the two strings are visually confusable and that they are not from the same script, according to UTS 39 section 4.
|
USPOOF_WHOLE_SCRIPT_CONFUSABLE | When performing the two-string uspoof_areConfusable test, this flag in the return value indicates that the two strings are visually confusable and that they are not from the same script but both of them are single-script strings, according to UTS 39 section 4.
|
USPOOF_CONFUSABLE | Enable this flag in uspoof_setChecks to turn on all types of confusables. You may set the checks to some subset of SINGLE_SCRIPT_CONFUSABLE, MIXED_SCRIPT_CONFUSABLE, or WHOLE_SCRIPT_CONFUSABLE to make uspoof_areConfusable return only those types of confusables.
|
USPOOF_ANY_CASE | This flag is deprecated and no longer affects the behavior of SpoofChecker.
|
USPOOF_RESTRICTION_LEVEL | Check that an identifier is no looser than the specified RestrictionLevel. The default if uspoof_setRestrictionLevel is not called is HIGHLY_RESTRICTIVE. If USPOOF_AUX_INFO is enabled the actual restriction level of the identifier being tested will also be returned by uspoof_check().
|
USPOOF_SINGLE_SCRIPT | Check that an identifier contains only characters from a single script (plus chars from the common and inherited scripts.) Applies to checks of a single identifier check only.
|
USPOOF_INVISIBLE | Check an identifier for the presence of invisible characters, such as zero-width spaces, or character sequences that are likely not to display, such as multiple occurrences of the same non-spacing mark. This check does not test the input string as a whole for conformance to any particular syntax for identifiers. |
USPOOF_CHAR_LIMIT | Check that an identifier contains only characters from a specified set of acceptable characters. See uspoof_setAllowedChars and uspoof_setAllowedLocales. Note that a string that fails this check will also fail the USPOOF_RESTRICTION_LEVEL check. |
USPOOF_MIXED_NUMBERS | Check that an identifier does not mix numbers from different numbering systems. For more information, see UTS 39 section 5.3.
|
USPOOF_HIDDEN_OVERLAY | Check that an identifier does not have a combining character following a character in which that combining character would be hidden; for example 'i' followed by a U+0307 combining dot. More specifically, the following characters are forbidden from preceding a U+0307:
In addition, combining characters are allowed between the above characters and U+0307 except those with combining class 0 or combining class "Above" (230, same class as U+0307). This list and the number of combing characters considered by this check may grow over time.
|
USPOOF_ALL_CHECKS | Enable all spoof checks.
|
USPOOF_AUX_INFO | Enable the return of auxillary (non-error) information in the upper bits of the check results value. If this "check" is not enabled, the results of uspoof_check will be zero when an identifier passes all of the enabled checks. If this "check" is enabled, (uspoof_check() & USPOOF_ALL_CHECKS) will be zero when an identifier passes all checks.
|
U_STABLE int32_t U_EXPORT2 uspoof_areConfusable | ( | const USpoofChecker * | sc, |
const UChar * | id1, | ||
int32_t | length1, | ||
const UChar * | id2, | ||
int32_t | length2, | ||
UErrorCode * | status | ||
) |
Check the whether two specified strings are visually confusable.
If the strings are confusable, the return value will be nonzero, as long as USPOOF_CONFUSABLE was enabled in uspoof_setChecks().
The bits in the return value correspond to flags for each of the classes of confusables applicable to the two input strings. According to UTS 39 section 4, the possible flags are:
If one or more of the above flags were not listed in uspoof_setChecks(), this function will never report that class of confusable. The check USPOOF_CONFUSABLE enables all three flags.
sc | The USpoofChecker |
id1 | The first of the two identifiers to be compared for confusability. The strings are in UTF-16 format. |
length1 | the length of the first identifer, expressed in 16 bit UTF-16 code units, or -1 if the string is nul terminated. |
id2 | The second of the two identifiers to be compared for confusability. The identifiers are in UTF-16 format. |
length2 | The length of the second identifiers, expressed in 16 bit UTF-16 code units, or -1 if the string is nul terminated. |
status | The error code, set if an error occurred while attempting to perform the check. Confusability of the identifiers is not reported here, but through this function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_areConfusableUnicodeString | ( | const USpoofChecker * | sc, |
const icu::UnicodeString & | s1, | ||
const icu::UnicodeString & | s2, | ||
UErrorCode * | status | ||
) |
A version of uspoof_areConfusable accepting UnicodeStrings.
sc | The USpoofChecker |
s1 | The first of the two identifiers to be compared for confusability. The strings are in UTF-8 format. |
s2 | The second of the two identifiers to be compared for confusability. The strings are in UTF-8 format. |
status | The error code, set if an error occurred while attempting to perform the check. Confusability of the identifiers is not reported here, but through this function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_areConfusableUTF8 | ( | const USpoofChecker * | sc, |
const char * | id1, | ||
int32_t | length1, | ||
const char * | id2, | ||
int32_t | length2, | ||
UErrorCode * | status | ||
) |
A version of uspoof_areConfusable accepting strings in UTF-8 format.
sc | The USpoofChecker |
id1 | The first of the two identifiers to be compared for confusability. The strings are in UTF-8 format. |
length1 | the length of the first identifiers, in bytes, or -1 if the string is nul terminated. |
id2 | The second of the two identifiers to be compared for confusability. The strings are in UTF-8 format. |
length2 | The length of the second string in bytes, or -1 if the string is nul terminated. |
status | The error code, set if an error occurred while attempting to perform the check. Confusability of the strings is not reported here, but through this function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_check | ( | const USpoofChecker * | sc, |
const UChar * | id, | ||
int32_t | length, | ||
int32_t * | position, | ||
UErrorCode * | status | ||
) |
Check the specified string for possible security issues.
The text to be checked will typically be an identifier of some sort. The set of checks to be performed is specified with uspoof_setChecks().
sc | The USpoofChecker |
id | The identifier to be checked for possible security issues, in UTF-16 format. |
length | the length of the string to be checked, expressed in 16 bit UTF-16 code units, or -1 if the string is zero terminated. |
position | Deprecated in ICU 51. Always returns zero. Originally, an out parameter for the index of the first string position that failed a check. This parameter may be NULL. |
status | The error code, set if an error occurred while attempting to perform the check. Spoofing or security issues detected with the input string are not reported here, but through the function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_check2 | ( | const USpoofChecker * | sc, |
const UChar * | id, | ||
int32_t | length, | ||
USpoofCheckResult * | checkResult, | ||
UErrorCode * | status | ||
) |
Check the specified string for possible security issues.
The text to be checked will typically be an identifier of some sort. The set of checks to be performed is specified with uspoof_setChecks().
sc | The USpoofChecker |
id | The identifier to be checked for possible security issues, in UTF-16 format. |
length | the length of the string to be checked, or -1 if the string is zero terminated. |
checkResult | An instance of USpoofCheckResult to be filled with details about the identifier. Can be NULL. |
status | The error code, set if an error occurred while attempting to perform the check. Spoofing or security issues detected with the input string are not reported here, but through the function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_check2UnicodeString | ( | const USpoofChecker * | sc, |
const icu::UnicodeString & | id, | ||
USpoofCheckResult * | checkResult, | ||
UErrorCode * | status | ||
) |
Check the specified string for possible security issues.
The text to be checked will typically be an identifier of some sort. The set of checks to be performed is specified with uspoof_setChecks().
sc | The USpoofChecker |
id | A identifier to be checked for possible security issues. |
checkResult | An instance of USpoofCheckResult to be filled with details about the identifier. Can be NULL. |
status | The error code, set if an error occurred while attempting to perform the check. Spoofing or security issues detected with the input string are not reported here, but through the function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_check2UTF8 | ( | const USpoofChecker * | sc, |
const char * | id, | ||
int32_t | length, | ||
USpoofCheckResult * | checkResult, | ||
UErrorCode * | status | ||
) |
Check the specified string for possible security issues.
The text to be checked will typically be an identifier of some sort. The set of checks to be performed is specified with uspoof_setChecks().
This version of uspoof_check accepts a USpoofCheckResult, which returns additional information about the identifier. For more information, see uspoof_openCheckResult.
sc | The USpoofChecker |
id | A identifier to be checked for possible security issues, in UTF8 format. |
length | the length of the string to be checked, or -1 if the string is zero terminated. |
checkResult | An instance of USpoofCheckResult to be filled with details about the identifier. Can be NULL. |
status | The error code, set if an error occurred while attempting to perform the check. Spoofing or security issues detected with the input string are not reported here, but through the function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_checkUnicodeString | ( | const USpoofChecker * | sc, |
const icu::UnicodeString & | id, | ||
int32_t * | position, | ||
UErrorCode * | status | ||
) |
Check the specified string for possible security issues.
The text to be checked will typically be an identifier of some sort. The set of checks to be performed is specified with uspoof_setChecks().
sc | The USpoofChecker |
id | A identifier to be checked for possible security issues. |
position | Deprecated in ICU 51. Always returns zero. Originally, an out parameter for the index of the first string position that failed a check. This parameter may be NULL. |
status | The error code, set if an error occurred while attempting to perform the check. Spoofing or security issues detected with the input string are not reported here, but through the function's return value. |
U_STABLE int32_t U_EXPORT2 uspoof_checkUTF8 | ( | const USpoofChecker * | sc, |
const char * | id, | ||
int32_t | length, | ||
int32_t * | position, | ||
UErrorCode * | status | ||
) |
Check the specified string for possible security issues.
The text to be checked will typically be an identifier of some sort. The set of checks to be performed is specified with uspoof_setChecks().
sc | The USpoofChecker |
id | A identifier to be checked for possible security issues, in UTF8 format. |
length | the length of the string to be checked, or -1 if the string is zero terminated. |
position | Deprecated in ICU 51. Always returns zero. Originally, an out parameter for the index of the first string position that failed a check. This parameter may be NULL. |
status | The error code, set if an error occurred while attempting to perform the check. Spoofing or security issues detected with the input string are not reported here, but through the function's return value. If the input contains invalid UTF-8 sequences, a status of U_INVALID_CHAR_FOUND will be returned. |
USpoofChecker* uspoof_clone | ( | const USpoofChecker * | sc, |
UErrorCode * | status | ||
) |
Clone a Spoof Checker.
The clone will be set to perform the same checks as the original source.
sc | The source USpoofChecker |
status | The error code, set if this function encounters a problem. |
void uspoof_close | ( | USpoofChecker * | sc | ) |
Close a Spoof Checker, freeing any memory that was being held by its implementation.
U_STABLE void U_EXPORT2 uspoof_closeCheckResult | ( | USpoofCheckResult * | checkResult | ) |
Close a USpoofCheckResult, freeing any memory that was being held by its implementation.
checkResult | The instance of USpoofCheckResult to close |
U_STABLE const USet* U_EXPORT2 uspoof_getAllowedChars | ( | const USpoofChecker * | sc, |
UErrorCode * | status | ||
) |
Get a USet for the characters permitted in an identifier.
This corresponds to the limits imposed by the Set Allowed Characters functions. Limitations imposed by other checks will not be reflected in the set returned by this function.
The returned set will be frozen, meaning that it cannot be modified by the caller.
Ownership of the returned set remains with the Spoof Detector. The returned set will become invalid if the spoof detector is closed, or if a new set of allowed characters is specified.
sc | The USpoofChecker |
status | The error code, set if this function encounters a problem. |
U_STABLE const char* U_EXPORT2 uspoof_getAllowedLocales | ( | USpoofChecker * | sc, |
UErrorCode * | status | ||
) |
Get a list of locales for the scripts that are acceptable in strings to be checked.
If no limitations on scripts have been specified, an empty string will be returned.
uspoof_setAllowedChars() will reset the list of allowed to be empty.
The format of the returned list is the same as that supplied to uspoof_setAllowedLocales(), but returned list may not be identical to the originally specified string; the string may be reformatted, and information other than languages from the originally specified locales may be omitted.
sc | The USpoofChecker |
status | The error code, set if this function encounters a problem. |
U_STABLE const icu::UnicodeSet* U_EXPORT2 uspoof_getAllowedUnicodeSet | ( | const USpoofChecker * | sc, |
UErrorCode * | status | ||
) |
Get a UnicodeSet for the characters permitted in an identifier.
This corresponds to the limits imposed by the Set Allowed Characters / UnicodeSet functions. Limitations imposed by other checks will not be reflected in the set returned by this function.
The returned set will be frozen, meaning that it cannot be modified by the caller.
Ownership of the returned set remains with the Spoof Detector. The returned set will become invalid if the spoof detector is closed, or if a new set of allowed characters is specified.
sc | The USpoofChecker |
status | The error code, set if this function encounters a problem. |
U_NAMESPACE_END U_STABLE int32_t U_EXPORT2 uspoof_getCheckResultChecks | ( | const USpoofCheckResult * | checkResult, |
UErrorCode * | status | ||
) |
Indicates which of the spoof check(s) have failed.
The value is a bitwise OR of the constants for the tests in question: USPOOF_RESTRICTION_LEVEL, USPOOF_CHAR_LIMIT, and so on.
checkResult | The instance of USpoofCheckResult created by uspoof_openCheckResult |
status | The error code, set if an error occurred. |
U_STABLE const USet* U_EXPORT2 uspoof_getCheckResultNumerics | ( | const USpoofCheckResult * | checkResult, |
UErrorCode * | status | ||
) |
Gets the set of numerics found in the string, if the USPOOF_MIXED_NUMBERS check was enabled; otherwise, undefined.
The set will contain the zero digit from each decimal number system found in the input string. Ownership of the returned USet remains with the USpoofCheckResult. The USet will be free'd when uspoof_closeCheckResult is called.
checkResult | The instance of USpoofCheckResult created by uspoof_openCheckResult |
status | The error code, set if an error occurred. |
U_STABLE URestrictionLevel U_EXPORT2 uspoof_getCheckResultRestrictionLevel | ( | const USpoofCheckResult * | checkResult, |
UErrorCode * | status | ||
) |
Gets the restriction level that the text meets, if the USPOOF_RESTRICTION_LEVEL check was enabled; otherwise, undefined.
checkResult | The instance of USpoofCheckResult created by uspoof_openCheckResult |
status | The error code, set if an error occurred. |
U_STABLE int32_t U_EXPORT2 uspoof_getChecks | ( | const USpoofChecker * | sc, |
UErrorCode * | status | ||
) |
Get the set of checks that this Spoof Checker has been configured to perform.
sc | The USpoofChecker |
status | The error code, set if this function encounters a problem. |
U_STABLE const USet* U_EXPORT2 uspoof_getInclusionSet | ( | UErrorCode * | status | ) |
Get the set of Candidate Characters for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
The returned set is frozen. Ownership of the set remains with the ICU library; it must not be deleted by the caller.
status | The error code, set if a problem occurs while creating the set. |
U_STABLE const icu::UnicodeSet* U_EXPORT2 uspoof_getInclusionUnicodeSet | ( | UErrorCode * | status | ) |
Get the set of Candidate Characters for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
The returned set is frozen. Ownership of the set remains with the ICU library; it must not be deleted by the caller.
status | The error code, set if a problem occurs while creating the set. |
U_STABLE const USet* U_EXPORT2 uspoof_getRecommendedSet | ( | UErrorCode * | status | ) |
Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
The returned set is frozen. Ownership of the set remains with the ICU library; it must not be deleted by the caller.
status | The error code, set if a problem occurs while creating the set. |
U_STABLE const icu::UnicodeSet* U_EXPORT2 uspoof_getRecommendedUnicodeSet | ( | UErrorCode * | status | ) |
Get the set of characters from Recommended Scripts for Inclusion in Identifiers, as defined in http://unicode.org/Public/security/latest/xidmodifications.txt and documented in http://www.unicode.org/reports/tr39/, Unicode Security Mechanisms.
The returned set is frozen. Ownership of the set remains with the ICU library; it must not be deleted by the caller.
status | The error code, set if a problem occurs while creating the set. |
U_STABLE URestrictionLevel U_EXPORT2 uspoof_getRestrictionLevel | ( | const USpoofChecker * | sc | ) |
Get the Restriction Level that will be tested if the checks include USPOOF_RESTRICTION_LEVEL.
U_STABLE int32_t U_EXPORT2 uspoof_getSkeleton | ( | const USpoofChecker * | sc, |
uint32_t | type, | ||
const UChar * | id, | ||
int32_t | length, | ||
UChar * | dest, | ||
int32_t | destCapacity, | ||
UErrorCode * | status | ||
) |
Get the "skeleton" for an identifier.
Skeletons are a transformation of the input identifier; Two identifiers are confusable if their skeletons are identical. See Unicode UAX #39 for additional information.
Using skeletons directly makes it possible to quickly check whether an identifier is confusable with any of some large set of existing identifiers, by creating an efficiently searchable collection of the skeletons.
sc | The USpoofChecker |
type | Deprecated in ICU 58. You may pass any number. Originally, controlled which of the Unicode confusable data tables to use. |
id | The input identifier whose skeleton will be computed. |
length | The length of the input identifier, expressed in 16 bit UTF-16 code units, or -1 if the string is zero terminated. |
dest | The output buffer, to receive the skeleton string. |
destCapacity | The length of the output buffer, in 16 bit units. The destCapacity may be zero, in which case the function will return the actual length of the skeleton. |
status | The error code, set if an error occurred while attempting to perform the check. |
U_I18N_API icu::UnicodeString& U_EXPORT2 uspoof_getSkeletonUnicodeString | ( | const USpoofChecker * | sc, |
uint32_t | type, | ||
const icu::UnicodeString & | id, | ||
icu::UnicodeString & | dest, | ||
UErrorCode * | status | ||
) |
Get the "skeleton" for an identifier.
Skeletons are a transformation of the input identifier; Two identifiers are confusable if their skeletons are identical. See Unicode UAX #39 for additional information.
Using skeletons directly makes it possible to quickly check whether an identifier is confusable with any of some large set of existing identifiers, by creating an efficiently searchable collection of the skeletons.
sc | The USpoofChecker. |
type | Deprecated in ICU 58. You may pass any number. Originally, controlled which of the Unicode confusable data tables to use. |
id | The input identifier whose skeleton will be computed. |
dest | The output identifier, to receive the skeleton string. |
status | The error code, set if an error occurred while attempting to perform the check. |
U_STABLE int32_t U_EXPORT2 uspoof_getSkeletonUTF8 | ( | const USpoofChecker * | sc, |
uint32_t | type, | ||
const char * | id, | ||
int32_t | length, | ||
char * | dest, | ||
int32_t | destCapacity, | ||
UErrorCode * | status | ||
) |
Get the "skeleton" for an identifier.
Skeletons are a transformation of the input identifier; Two identifiers are confusable if their skeletons are identical. See Unicode UAX #39 for additional information.
Using skeletons directly makes it possible to quickly check whether an identifier is confusable with any of some large set of existing identifiers, by creating an efficiently searchable collection of the skeletons.
sc | The USpoofChecker |
type | Deprecated in ICU 58. You may pass any number. Originally, controlled which of the Unicode confusable data tables to use. |
id | The UTF-8 format identifier whose skeleton will be computed. |
length | The length of the input string, in bytes, or -1 if the string is zero terminated. |
dest | The output buffer, to receive the skeleton string. |
destCapacity | The length of the output buffer, in bytes. The destCapacity may be zero, in which case the function will return the actual length of the skeleton. |
status | The error code, set if an error occurred while attempting to perform the check. Possible Errors include U_INVALID_CHAR_FOUND for invalid UTF-8 sequences, and U_BUFFER_OVERFLOW_ERROR if the destination buffer is too small to hold the complete skeleton. |
USpoofChecker* uspoof_open | ( | UErrorCode * | status | ) |
Create a Unicode Spoof Checker, configured to perform all checks except for USPOOF_LOCALE_LIMIT and USPOOF_CHAR_LIMIT.
Note that additional checks may be added in the future, resulting in the changes to the default checking behavior.
status | The error code, set if this function encounters a problem. |
U_STABLE USpoofCheckResult* U_EXPORT2 uspoof_openCheckResult | ( | UErrorCode * | status | ) |
Create a USpoofCheckResult, used by the uspoof_check2 class of functions to return information about the identifier.
Information includes:
The data held in a USpoofCheckResult is cleared whenever it is passed into a new call of uspoof_check2.
status | The error code, set if this function encounters a problem. |
USpoofChecker* uspoof_openFromSerialized | ( | const void * | data, |
int32_t | length, | ||
int32_t * | pActualLength, | ||
UErrorCode * | pErrorCode | ||
) |
Open a Spoof checker from its serialized form, stored in 32-bit-aligned memory.
Inverse of uspoof_serialize(). The memory containing the serialized data must remain valid and unchanged as long as the spoof checker, or any cloned copies of the spoof checker, are in use. Ownership of the memory remains with the caller. The spoof checker (and any clones) must be closed prior to deleting the serialized data.
data | a pointer to 32-bit-aligned memory containing the serialized form of spoof data |
length | the number of bytes available at data; can be more than necessary |
pActualLength | receives the actual number of bytes at data taken up by the data; can be NULL |
pErrorCode | ICU error code |
USpoofChecker* uspoof_openFromSource | ( | const char * | confusables, |
int32_t | confusablesLen, | ||
const char * | confusablesWholeScript, | ||
int32_t | confusablesWholeScriptLen, | ||
int32_t * | errType, | ||
UParseError * | pe, | ||
UErrorCode * | status | ||
) |
Open a Spoof Checker from the source form of the spoof data.
The input corresponds to the Unicode data file confusables.txt as described in Unicode UAX #39. The syntax of the source data is as described in UAX #39 for this file, and the content of this file is acceptable input.
The character encoding of the (char *) input text is UTF-8.
confusables | a pointer to the confusable characters definitions, as found in file confusables.txt from unicode.org. |
confusablesLen | The length of the confusables text, or -1 if the input string is zero terminated. |
confusablesWholeScript | Deprecated in ICU 58. No longer used. |
confusablesWholeScriptLen | Deprecated in ICU 58. No longer used. |
errType | In the event of an error in the input, indicates which of the input files contains the error. The value is one of USPOOF_SINGLE_SCRIPT_CONFUSABLE or USPOOF_WHOLE_SCRIPT_CONFUSABLE, or zero if no errors are found. |
pe | In the event of an error in the input, receives the position in the input text (line, offset) of the error. |
status | an in/out ICU UErrorCode. Among the possible errors is U_PARSE_ERROR, which is used to report syntax errors in the input. |
U_STABLE int32_t U_EXPORT2 uspoof_serialize | ( | USpoofChecker * | sc, |
void * | data, | ||
int32_t | capacity, | ||
UErrorCode * | status | ||
) |
Serialize the data for a spoof detector into a chunk of memory.
The flattened spoof detection tables can later be used to efficiently instantiate a new Spoof Detector.
The serialized spoof checker includes only the data compiled from the Unicode data tables by uspoof_openFromSource(); it does not include include any other state or configuration that may have been set.
sc | the Spoof Detector whose data is to be serialized. |
data | a pointer to 32-bit-aligned memory to be filled with the data, can be NULL if capacity==0 |
capacity | the number of bytes available at data, or 0 for preflighting |
status | an in/out ICU UErrorCode; possible errors include:
|
U_STABLE void U_EXPORT2 uspoof_setAllowedChars | ( | USpoofChecker * | sc, |
const USet * | chars, | ||
UErrorCode * | status | ||
) |
Limit the acceptable characters to those specified by a Unicode Set.
Any previously specified character limit is is replaced by the new settings. This includes limits on characters that were set with the uspoof_setAllowedLocales() function.
The USPOOF_CHAR_LIMIT test is automatically enabled for this USpoofChecker by this function.
sc | The USpoofChecker |
chars | A Unicode Set containing the list of characters that are permitted. Ownership of the set remains with the caller. The incoming set is cloned by this function, so there are no restrictions on modifying or deleting the USet after calling this function. |
status | The error code, set if this function encounters a problem. |
U_STABLE void U_EXPORT2 uspoof_setAllowedLocales | ( | USpoofChecker * | sc, |
const char * | localesList, | ||
UErrorCode * | status | ||
) |
Limit characters that are acceptable in identifiers being checked to those normally used with the languages associated with the specified locales.
Any previously specified list of locales is replaced by the new settings.
A set of languages is determined from the locale(s), and from those a set of acceptable Unicode scripts is determined. Characters from this set of scripts, along with characters from the "common" and "inherited" Unicode Script categories will be permitted.
Supplying an empty string removes all restrictions; characters from any script will be allowed.
The USPOOF_CHAR_LIMIT test is automatically enabled for this USpoofChecker when calling this function with a non-empty list of locales.
The Unicode Set of characters that will be allowed is accessible via the uspoof_getAllowedChars() function. uspoof_setAllowedLocales() will replace any previously applied set of allowed characters.
Adjustments, such as additions or deletions of certain classes of characters, can be made to the result of uspoof_setAllowedLocales() by fetching the resulting set with uspoof_getAllowedChars(), manipulating it with the Unicode Set API, then resetting the spoof detectors limits with uspoof_setAllowedChars().
sc | The USpoofChecker |
localesList | A list list of locales, from which the language and associated script are extracted. The locales are comma-separated if there is more than one. White space may not appear within an individual locale, but is ignored otherwise. The locales are syntactically like those from the HTTP Accept-Language header. If the localesList is empty, no restrictions will be placed on the allowed characters. |
status | The error code, set if this function encounters a problem. |
U_STABLE void U_EXPORT2 uspoof_setAllowedUnicodeSet | ( | USpoofChecker * | sc, |
const icu::UnicodeSet * | chars, | ||
UErrorCode * | status | ||
) |
Limit the acceptable characters to those specified by a Unicode Set.
Any previously specified character limit is is replaced by the new settings. This includes limits on characters that were set with the uspoof_setAllowedLocales() function.
The USPOOF_CHAR_LIMIT test is automatically enabled for this USoofChecker by this function.
sc | The USpoofChecker |
chars | A Unicode Set containing the list of characters that are permitted. Ownership of the set remains with the caller. The incoming set is cloned by this function, so there are no restrictions on modifying or deleting the UnicodeSet after calling this function. |
status | The error code, set if this function encounters a problem. |
U_STABLE void U_EXPORT2 uspoof_setChecks | ( | USpoofChecker * | sc, |
int32_t | checks, | ||
UErrorCode * | status | ||
) |
Specify the bitmask of checks that will be performed by uspoof_check.
Calling this method overwrites any checks that may have already been enabled. By default, all checks are enabled.
To enable specific checks and disable all others, the "whitelisted" checks should be ORed together. For example, to fail strings containing characters outside of the set specified by uspoof_setAllowedChars and also strings that contain digits from mixed numbering systems:
To disable specific checks and enable all others, the "blacklisted" checks should be ANDed away from ALL_CHECKS. For example, if you are not planning to use the uspoof_areConfusable functionality, it is good practice to disable the CONFUSABLE check:
Note that methods such as uspoof_setAllowedChars, uspoof_setAllowedLocales, and uspoof_setRestrictionLevel will enable certain checks when called. Those methods will OR the check they enable onto the existing bitmask specified by this method. For more details, see the documentation of those methods.
sc | The USpoofChecker |
checks | The set of checks that this spoof checker will perform. The value is a bit set, obtained by OR-ing together values from enum USpoofChecks. |
status | The error code, set if this function encounters a problem. |
U_STABLE void U_EXPORT2 uspoof_setRestrictionLevel | ( | USpoofChecker * | sc, |
URestrictionLevel | restrictionLevel | ||
) |
Set the loosest restriction level allowed for strings.
The default if this is not called is USPOOF_HIGHLY_RESTRICTIVE. Calling this method enables the USPOOF_RESTRICTION_LEVEL and USPOOF_MIXED_NUMBERS checks, corresponding to Sections 5.1 and 5.2 of UTS 39. To customize which checks are to be performed by uspoof_check, see uspoof_setChecks.
sc | The USpoofChecker |
restrictionLevel | The loosest restriction level allowed. |