2 Copyright (c) 2014, McAfee, Inc.
6 Redistribution and use in source and binary forms, with or without modification,
7 are permitted provided that the following conditions are met:
9 Redistributions of source code must retain the above copyright notice, this list
10 of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright notice, this
13 list of conditions and the following disclaimer in the documentation and/or other
14 materials provided with the distribution.
16 Neither the name of McAfee, Inc. nor the names of its contributors may be used
17 to endorse or promote products derived from this software without specific prior
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
24 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29 OF THE POSSIBILITY OF SUCH DAMAGE.
41 * \brief TWP Header File
43 * This file provides the Tizen Web Protection API functions.
46 typedef long unsigned int TWPMallocSizeT; /* Size unit */
48 struct TWPLibHandle_struct {int iDummy;};
50 typedef struct TWPLibHandle_struct *TWPLIB_HANDLE;
52 #define TWP_VER_MAX 16
54 #define TWP_META_MAX 1000
56 #define TWP_FRAMEWORK_VERSION "2.0.2"
58 #define TWPAPI_VERSION 1 /* SDK version */
60 #define TWPCONFIG_VERSION 1 /* Configure version */
62 #define TWPREQUEST_VERSION 1 /* Request version */
64 #define INVALID_TWPLIB_HANDLE ((TWPLIB_HANDLE) 0) /* Invalid web protection library interface handle. */
67 * Structure for version info of TWP Framework and Plugin
69 typedef struct TWPVerInfo_struct
71 char szFrameworkVer[TWP_VER_MAX];
72 char szPluginVer[TWP_VER_MAX];
76 * Result code used by TWP_RESULT
83 TWP_INVALID_HANDLE = 3,
84 TWP_INVALID_PARAMETER = 4,
85 TWP_INVALID_VERSION = 5,
86 TWP_INVALID_RESPONSE = 6,
88 TWP_NOT_IMPLEMENTED = 500
92 * Web site category definitions
96 TWP_Artcultureheritage,
99 TWP_Anonymizingutilities,
102 TWP_Publicinformation,
103 TWP_Potentialcriminalactivities,
105 TWP_Educationreference,
111 TWP_Governmentmilitary,
112 TWP_Potentialhackingcomputercrime,
116 TWP_Instantmessaging,
120 TWP_Informationsecurity,
127 TWP_Nonprofitadvocacyngo,
130 TWP_Provocativeattire,
136 TWP_Religionideology,
141 TWP_Sharewarefreeware,
143 TWP_Spywareadwarekeyloggers,
151 TWP_Auctionsclassifieds,
152 TWP_Forumbulletinboards,
154 TWP_Schoolcheatinginformation,
157 TWP_Visualsearchengine,
158 TWP_Technicalbusinessforums,
161 TWP_Gamecartoonviolence,
163 TWP_Personalnetworkstorage,
165 TWP_Interactivewebapplications,
167 TWP_Softwarehardware,
168 TWP_Potentialillegalsoftware,
170 TWP_Internetservices,
172 TWP_Incidentalnudity,
173 TWP_Marketingmerchandising,
178 TWP_Recreationhobbies,
180 TWP_Digitalpostcards,
181 TWP_Historicalrevisionism,
182 TWP_Technicalinformation,
185 TWP_Professionalnetworking,
186 TWP_Socialnetworking,
193 TWP_Controversialopinions,
194 TWP_Residentialipaddresses,
196 TWP_Consumerprotection,
198 TWP_Majorglobalreligions,
199 TWP_Maliciousdownloads,
200 TWP_Potentiallyunwantedprograms,
202 TWP_LastCategoryPlaceholder = 128,
203 TWP_OverallPhishing = 129,
204 TWP_OverallRiskHigh = 130,
205 TWP_OverallRiskMedium = 131,
206 TWP_OverallRiskMinimal = 132,
207 TWP_OverallRiskUnverified = 137,
208 TWP_OverallMcAfeeSecure = 138,
209 TWP_LastAttributePlaceholder = 160,
229 TWP_MinimalHigh = 14,
230 TWP_UnverifiedLow = 15,
231 TWP_UnverifiedHigh = 29,
246 /* forward declaration */
248 typedef struct TWPConfiguration *TWPConfigurationHandle;
249 typedef struct TWPResponse *TWPResponseHandle;
250 typedef struct TWPUrlRating *TWPUrlRatingHandle;
251 typedef struct TWPPolicy *TWPPolicyHandle;
252 typedef void *(*TWPFnMemAlloc)(TWPMallocSizeT size);
253 typedef void (*TWPFnMemFree)(void *address);
254 typedef long (*TWPFnRandom)(void);
255 typedef TWP_RESULT (*TWPFnRequestSetUrl)(struct TWPRequest *request, const char *pUrl,
256 unsigned int length);
257 typedef TWP_RESULT (*TWPFnRequestSetMethod)(struct TWPRequest *request, TWPSubmitMethod method);
258 typedef TWP_RESULT (*TWPFnRequestSend)(struct TWPRequest *request, TWPResponseHandle response,
259 const void *data, unsigned int length);
260 typedef TWP_RESULT (*TWPFnRequestReceive)(struct TWPRequest *request, void *buffer,
261 unsigned int buffer_length, unsigned int *length);
264 * Initialize data requested by SDK initialization
266 typedef struct TWPAPIInit
269 TWPFnMemAlloc memallocfunc;
270 TWPFnMemFree memfreefunc;
274 * Configuration which enable caller to customize the SDK
276 typedef struct TWPConfiguration
278 int config_version; /* Configuration version */
279 const char *client_id; /* Client id for cloud to qualify */
280 const char *client_key; /* Corresponding key for specific client for validation from cloud */
281 const char *host; /* Host name for cloud where SDK send request to, set to NULL for SDK to use default settings in plug-in */
282 int secure_connection; /* 1 - use secured connection (HTTPS), 0 - not secured connection. */
283 int skip_dla; /* 1 - disable DLA lookup, 0 - enable DLA lookup */
284 int obfuscate_request; /* 1 - obfuscate request data, 0 - do not obfuscate request data */
285 TWPFnRandom randomfunc; /* Caller customized random function */
289 * Request for SDK to check URL against cloud database
291 typedef struct TWPRequest
293 int request_version; /* Request version */
294 TWPFnRequestSetUrl seturlfunc; /* Callback for SDK to set URL from SDK */
295 TWPFnRequestSetMethod setmethodfunc; /* Callback for SDK to set HTTP request method */
296 TWPFnRequestSend sendfunc; /* Callback for SDK to send HTTP request */
297 TWPFnRequestReceive receivefunc; /* Callback for SDK to receive HTTP response, if caller set it to be NULL,
298 SDK will assume the HTTP request will be handled in a-synchronized manner */
305 * This is a synchronized API
307 * \param[in] pApiInit API initialization data structure.
311 TWPLIB_HANDLE TWPInitLibrary(TWPAPIInit *pApiInit);
314 * \brief Gets the version number of TWP Framework and Plugin.
316 * This is a synchronous API.
318 * \param[in] hLib instance handle obtained from a call to the TWPInitLibrary().
319 * \param[out] pszVersion Pointer to a structure containing version info.
323 TWP_RESULT TWPGetVersion(TWPLIB_HANDLE hLib, TWPVerInfo *pVerInfo);
326 * \brief Gets the meta information about the plugin
328 * This is a synchronous API.
330 * \param[in] hLib instance handle obtained from a call to the TWPInitLibrary().
331 * \param[out] pszInfo string containing meta info, pszInfo allocated by caller of size TWP_META_MAX.
335 TWP_RESULT TWPGetInfo(TWPLIB_HANDLE hLib, char *pszInfo);
341 * This is a synchronized API
344 void TWPUninitLibrary(TWPLIB_HANDLE hLib);
348 * Create TWP configuration to customize SDK
350 * This is a synchronized API
352 * \param[in] pConfigure caller configurations
353 * \param[out] phConfigure created configuration for SDK
357 TWP_RESULT TWPConfigurationCreate(TWPLIB_HANDLE hLib, TWPConfiguration *pConfigure, TWPConfigurationHandle *phConfigure);
361 * Release the configuration resources allocated by TWPConfigurationCreate
363 * This is a synchronized API
365 * \param[in] hConfigure configuration to be destroyed
369 TWP_RESULT TWPConfigurationDestroy(TWPLIB_HANDLE hLib, TWPConfigurationHandle *hConfigure);
373 * Main function for caller to check URL reputation against the cloud database
375 * This can be a synchronized API or a-synchronized API depends on the configuration from caller
378 * In this synchronous operation mode, the function invokes TWPRequest::sendfunc and
379 * TWPRequest::receivefunc, one right after the other, expecting the entire HTTP
380 * transaction to be completed between the calls. Upon successful completion, the
381 * phResponse will point to a valid response handle that can be used to analyze results.
384 * In the asynchronous mode, the function invokes TWPRequest::sendfunc and returns
385 * immediately with TWP_SUCCESS. Upon completion, phResponse is NULL. The application
386 * is supposed to complete the HTTP transaction while calling TWPResponseWrite as
387 * response data becomes available. When all data was read, TWPResponseWrite must
388 * be called again with zero data length to signal the end transaction.
390 * \param[in] hConfigure Configuration of caller
391 * \param[in] pRequest Request data structure for SDK to check with cloud
392 * \param[in] iRedirUrl 1 indicating instruct the cloud server to provide a landing page
393 * URL to which blocked URLs can be redirected.
394 * \param[in] ppUrls An array of 7 bit ASCII character strings representing URLs to obtain
397 * Note: All URLs have to be normalized before submission (see RFC 3986) and
398 * pynicoded if required.
399 * \param[in] uCount Length of the ppUrls array.
400 * \param[out] phResponse For synchronous requests, a pointer to the location where the
401 * response object handle will be stored upon completion. It can be NULL for
402 * asynchronous requests.
406 TWP_RESULT TWPLookupUrls(TWPLIB_HANDLE hLib, TWPConfigurationHandle hConfigure, TWPRequest *pRequest,
407 int iRedirUrl, const char **ppUrls, unsigned int uCount, TWPResponseHandle *phResponse);
411 * In asynchronous mode, caller will call this API to write received HTTP response data
412 * to SDK. Writing with zero data length will be taken as end of HTTP transaction for
415 * This is a synchronized API
417 * \param[in] hResponse Response handle for SDK to keep track on HTTP transaction.
418 * \param[in] pData Received HTTP response data chunk.
419 * \param[in] uLength Length of the HTTP response data.
423 TWP_RESULT TWPResponseWrite(TWPLIB_HANDLE hLib, TWPResponseHandle hResponse, const void *pData, unsigned uLength);
427 * Get web site rating by its index in URL list in the response which comply to
428 * the URL list order passed by caller in TWPLookupUrls().
430 * This is a synchronized API
432 * \param[in] hResponse Response handle created based on cloud response.
433 * \param[in] iIndex Index of the web site in request list.
434 * \param[out] phRating Rating of the specified web site.
438 TWP_RESULT TWPResponseGetUrlRatingByIndex(TWPLIB_HANDLE hLib, TWPResponseHandle hResponse, unsigned int uIndex,
439 TWPUrlRatingHandle *phRating);
443 * Get web site rating by its URL string.
445 * This is a synchronized API
447 * \param[in] hResponse Response handle created based on cloud response.
448 * \param[in] pUrl URL string
449 * \param[in] iUrlLength URL string length
450 * \param[out] hRating Rating of the specified web site
454 TWP_RESULT TWPResponseGetUrlRatingByUrl(TWPLIB_HANDLE hLib, TWPResponseHandle hResponse, const char *pUrl,
455 unsigned int uUrlLength, TWPUrlRatingHandle *hRating);
459 * Get the redirection URL for blocked URL to display to user.
461 * Blocking pages can be used by application that want to block users
462 * from navigating to a URL that violates one of the defined policies.
463 * The returned string must be deallocated by the application using
464 * TWPAPIInit::TWPFnMemFree function.
466 * \param[in] hResponse Response handle created based on cloud response.
467 * \param[in] hRating Rating handle resolved from cloud response.
468 * \param[in] hPolicy Policy handle created by caller.
469 * \param[out] ppUrl Redirection URL.
470 * \param[ou] puLength Length of redirection URL
474 TWP_RESULT TWPResponseGetRedirUrlFor(TWPLIB_HANDLE hLib, TWPResponseHandle hResponse, TWPUrlRatingHandle hRating,
475 TWPPolicyHandle hPolicy, char **ppUrl, unsigned int *puLength);
479 * Get the rating count of specified response.
481 * \param[in] hResponse Response handle created based on cloud response.
482 * \param[out] puCount Rating count.
486 TWP_RESULT TWPResponseGetUrlRatingsCount(TWPLIB_HANDLE hLib, TWPResponseHandle hResponse, unsigned int *puCount);
490 * Release resource for response handle.
492 * \param[in] hResponse Response handle created based on cloud response.
496 TWP_RESULT TWPResponseDestroy(TWPLIB_HANDLE hLib, TWPResponseHandle *hResponse);
500 * Create the policy (set of web site categories) caller want to check.
502 * \param[in] hCfg configuration handle
503 * \param[in] pCategories Web site category list
504 * \param[in] uCount Category list length.
505 * \param[out] phPolicy Policy handle.
509 TWP_RESULT TWPPolicyCreate(TWPLIB_HANDLE hLib, TWPConfigurationHandle hCfg, TWPCategories *pCategories, unsigned int uCount, TWPPolicyHandle *hPolicy);
513 * Compare the categories assigned by security vendor to the URL represented
514 * by hRating with the categories assigned to the policy handle.
516 * \param[in] hPolicy Polcy handle
517 * \param[in] hRating Rating for specific URL
518 * \param[out] piVialated non-zero if intersection found between the policy and URL rating categories.
522 TWP_RESULT TWPPolicyValidate(TWPLIB_HANDLE hLib, TWPPolicyHandle hPolicy, TWPUrlRatingHandle hRating, int *piViolated);
526 * Retrieves all categories common between the policy and URL rating.
528 * \param[in] hPolicy Policy handle.
529 * \param[in] hRating URL rating handle.
530 * \param[out] ppViolated An array of all common categories. This array is allocated by using
531 * TWPAPIInit::memallocfunc and has to be deallocated by the caller.
532 * \param[out] puLength Length of violation array.
536 TWP_RESULT TWPPolicyGetViolations(TWPLIB_HANDLE hLib, TWPPolicyHandle hPolicy, TWPUrlRatingHandle hRating,
537 TWPCategories **ppViolated, unsigned *puLength);
541 * Release resource for policy handle.
543 * \param[in] phPolicy Pointer to policy handle.
547 TWP_RESULT TWPPolicyDestroy(TWPLIB_HANDLE hLib, TWPPolicyHandle *hPolicy);
551 * Get score from URL rating data structure which is assigned by security vendor.
553 * \param[in] hRating Rating handle.
554 * \param[out] piScore URL score.
558 TWP_RESULT TWPUrlRatingGetScore(TWPLIB_HANDLE hLib, TWPUrlRatingHandle hRating, int *piScore);
562 * Get corresponding URL from rating handle.
564 * \param[in] hRating Rating handle.
565 * \param[out] ppUrl A pointer to a NULL terminated string representing
566 * the URL. The string is valid as long as the URL rating
568 * \param[out] puLength An optional pointer to the length of URL string.
572 TWP_RESULT TWPUrlRatingGetUrl(TWPLIB_HANDLE hLib, TWPUrlRatingHandle hRating, char **ppUrl,
573 unsigned int *puLength);
577 * Get DLA (Deep Link Analysis) URL
579 * \param[in] hRating Rating handle.
580 * \param[out] ppDlaUrl A ponit to a NULL terminated string representing
581 * the DLA URL. This string is valid as long as the URL rating
583 * \param[out] puLength Length of DLA URL string.
587 TWP_RESULT TWPUrlRatingGetDLAUrl(TWPLIB_HANDLE hLib, TWPUrlRatingHandle hRating, char **ppDlaUrl,
588 unsigned int *puLength);
592 * Determine whether the URL rating object has the specified category.
594 * \param[in] hRating Rating handle.
595 * \param[in] Category Category enum value.
596 * \param[out] piPresent Non-zero value indicating exists.
600 TWP_RESULT TWPUrlRatingHasCategory(TWPLIB_HANDLE hLib, TWPUrlRatingHandle hRating, TWPCategories Category,
605 * Retrives categories assigned by security vendor for the rated URL.
607 * \param[in] hRating Rating handle.
608 * \param[out] ppCategories The pointer to a variable that contains the address
609 * of the category list.
610 * \param[out] puLength Length of category list.
614 TWP_RESULT TWPUrlRatingGetCategories(TWPLIB_HANDLE hLib, TWPUrlRatingHandle hRating, TWPCategories **ppCategories,
615 unsigned int *puLength);
618 * Checks whether the URL violates the default policy and configurations.
619 * Retrieves the Risk level for all URLs and the Redirection URL is retrieved
620 * if level is greater than or equal to TWP_MediumLow score.
622 * \param[in] pUrl URL to check.
623 * \param[out] ppBlkUrl Redirection URL.
624 * \param[out] puBlkUrlLen Length of redirection URL.
625 * \param[out] pRiskLevel Risk level of the URL.
629 TWP_RESULT TWPCheckURL(TWPLIB_HANDLE hLib, const char *pUrl, char **ppBlkUrl, unsigned int *puBlkUrlLen,