Commit 4d8e8631 authored by 14699's avatar 14699

add:腾讯人脸SDK补充提交

parent f8b12d09
...@@ -15,8 +15,6 @@ yarn-error.log* ...@@ -15,8 +15,6 @@ yarn-error.log*
*.ntvs* *.ntvs*
*.njsproj *.njsproj
*.sln *.sln
plugins/cordova-plugin-hand-tencentface/src/ios/SDKExport/Libs/TuringShieldCamRisk.framework
plugins/cordova-plugin-hand-tencentface/src/ios/SDKExport/Libs/TencentCloudHuiyanSDKFace.framework
*~ *~
*.sw[mnpcod] *.sw[mnpcod]
......
framework module TencentCloudHuiyanSDKFace {
umbrella header "TencentCloudHuiyanSDKFace.h"
export *
module * { export * }
}
//
// KYCDigestComputer.h
// KYCGMSDK
//
// Created by Leon on 2023/8/24.
//
#ifndef KYCDigestComputer_h
#define KYCDigestComputer_h
#include <stdio.h>
#include <string>
namespace kycgm {
class DigestComputer {
public:
std::string computeMD5(const std::string& data);
};
} // namespace kycgm End
#endif /* KYCDigestComputer_h */
//
// kycGMTool.hpp
// gmsslv3
//
// Created by brownfeng on 2022/8/1.
//
#ifndef KYCWrapperAPI_hpp
#define KYCWrapperAPI_hpp
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wcomma"
#include "sm2.h"
#include "sm4.h"
#pragma clang diagnostic pop
namespace kycgm {
int kyc_sm2_set_public_key(SM2_KEY *sm2_key, const uint8_t public_key[64]);
int kyc_sm2_encrypt_c1c3c2(const SM2_KEY *sm2_key, const uint8_t *in, size_t inlen, uint8_t *outbuf, size_t *outlen);
//int kyc_sm4_set_encrypt_key(SM4_KEY *sm4_key, const uint8_t sm4_cipher_key[16]);
//int kyc_sm4_encrypt(const SM4_KEY *sm4_key, const uint8_t iv_data[16], const uint8_t *in_data, size_t inlen, uint8_t *outbuf, size_t *outlen);
//int kyc_sm4_set_decrypt_key(SM4_KEY *sm4_key, const uint8_t sm4_cipher_key[16]);
//int kyc_sm4_decrypt(const SM4_KEY *sm4_key, const uint8_t iv_data[16], const uint8_t *in_data, size_t inlen, uint8_t *outbuf, size_t *outlen);
}
#endif /* KYCWrapperAPI_hpp */
//
// KeyManager.h
// KYCGMSDK
//
// Created by brownfeng on 2023/8/17.
//
#ifndef KeyManager_h
#define KeyManager_h
#include <string>
#include <vector>
#include <map>
#include "json11.hpp"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wcomma"
#import <YTPoseDetector/YTFaceCheckLivePose.hpp>
#pragma clang diagnostic pop
#ifdef DEBUG
class KeyManagerTestHelper;
#endif
namespace kycgm {
class KeyManager {
public:
// 构造函数
KeyManager(youtu::YTFaceCheckLivePose* faceCheckLivePose = nullptr);
~KeyManager();
int64_t getRequestTime(const std::string& data);
bool prepare();
std::string getImg();
std::map<std::string, std::vector<uint8_t>> makeRequest(const std::string& jsonStr, bool useGM, bool testEnv);
std::vector<uint8_t> parseResponse(const uint8_t *data, size_t inlen, bool useGM);
private:
std::vector<uint8_t> sm2EncryptedKeyData(const std::string& hexPubKey);
std::string sm2EncryptedKeyHexStr(const std::string& hexPubKey);
bool sm2EncryptedKeyData(const uint8_t *publicKeyData, size_t publicKeyDataLen,
const uint8_t *content, size_t contentLen,
uint8_t *out, size_t *outlen);
std::vector<uint8_t> sm4EncryptData(const uint8_t *in, size_t inlen);
std::vector<uint8_t> sm4DecryptData(const uint8_t *data, size_t inlen);
std::string get_PoseImgMat(const std::string& jsonStr);
UIImage* imageWithCVMat(yt_tinycv::Mat3BGR frameMat);
std::string generateRandomString(size_t totalLength, size_t numLetters);
std::string bytesToHexString(const uint8_t* data, size_t length);
std::vector<uint8_t> hexStringToBytes(const std::string& hex);
int64_t getRequestTime();
std::string base64Encode(const uint8_t* inputBytes, size_t length);
std::vector<uint8_t> base64Decode(const uint8_t* inputBytes, size_t length);
private:
std::string sm4Iv;
std::string sm4Key;
youtu::YTFaceCheckLivePose* faceCheckLivePose;
std::map<std::string, kycjson11::Json> prepareJsonMap;
#ifdef DEBUG
friend class KeyManagerTestHelper;
#endif
};
} // namespace kycgm End
#endif /* KeyManager_h */
//
// TencentCloudHuiyanSDKFace.h
// Pods
//
// Created by Leon on 2022/11/14.
//
#ifndef TencentCloudHuiyanSDKFace_h
#define TencentCloudHuiyanSDKFace_h
#import <TencentCloudHuiyanSDKFace/WBFaceError.h>
#import <TencentCloudHuiyanSDKFace/WBFaceVerifyConst.h>
#import <TencentCloudHuiyanSDKFace/WBFaceVerifyCustomerService.h>
#import <TencentCloudHuiyanSDKFace/WBFaceVerifyResult.h>
#import <TencentCloudHuiyanSDKFace/WBFaceVerifySDKConfig.h>
#endif /* TencentCloudHuiyanSDKFace_h */
//
// WBCFGMSSLUtils.h
// KYCGMSDK
//
// Created by brownfeng on 2022/8/1.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
#define KYCGMSDKVersion @"0.1.2"
@interface WBCFGMSSLUtils : NSObject
+(BOOL)kycSM4Available;
#pragma mark - SM2
/**
* 传入等待加密的NSdata, 以及 public key的PEM格式字符串
*
* @param rawData 等待加密的二进制,
* @param base64PublicKey base64格式的 SM2Key, 长度88个字符, 二进制格式key长度64个字节
*
* @return 返回加密以后的raw data, SM2 密钥二进制长度不是64字节时则返回 nil
*/
+ (nullable NSData *)kycSM2EncryptData:(NSData *)rawData publicKey:(NSString *)base64PublicKey;
#pragma mark - SM4
// sm4加密时需要的密钥: key 长度 16个字节, 128bit
+ (NSData *)kycSM4GenerateKey;
// sm4加密时需要初始向量: iv 长度 16个字节, 128bit
+ (NSData *)kycSM4GenerateIv;
/*
* 传入待加密的data, 以及加密 key
*
* @param data 等待加密的二进制数据
* @param key sm4的密钥 - 16字节, 128bit!!!
* @param iv sm4加密使用的iv - 16字节, 128bit!!!
*
* @return 返回加密以后的二进制数据, key 或者 iv 不是16字节则返回 nil
*/
+ (nullable NSData *)kycSM4EncryptData:(NSData*)data key:(NSData*)keyData iv:(NSData*)ivData;
/*
* 传入待解密的二进制 data, 以及解密 key
*
* @param data 等待解密的二进制数据
* @param key sm4的密钥 - 16字节, 128bit!!!
* @param iv sm4解密使用的iv - 16字节, 128bit!!!
*
* @return 返回加密以后的二进制数据, (key 或者 iv 不是16字节)或者(data 不是 16 字节的整数倍)则返回 nil
*/
+ (nullable NSData *)kycSM4DecryptData:(NSData*)data key:(NSData*)keyData iv:(NSData*)ivData;
@end
NS_ASSUME_NONNULL_END
//
// WBCFGMWrapper+Cpp.h
// Pods
//
// Created by Leon on 2023/9/1.
//
#ifndef WBCFGMWrapper_Cpp_h
#define WBCFGMWrapper_Cpp_h
#import "WBCFGMWrapper.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wcomma"
#import <YTPoseDetector/YTFaceCheckLivePose.hpp>
#pragma clang diagnostic pop
@interface WBCFGMWrapper (Cpp)
- (instancetype)initWithPose:(youtu::YTFaceCheckLivePose *)pose;
@end
#endif /* WBCFGMWrapper_Cpp_h */
//
// WBCFGMWrapper.h
// KYCGMSDK
//
// Created by Leon on 2023/8/31.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface WBCFGMWrapper : NSObject
- (BOOL)prepare;
- (NSString *)getImg;
- (NSDictionary<NSString *, NSString *> *)makeRequest:(NSString *)jsonStr useGM:(BOOL)useGM testEnv:(BOOL)testEnv;
- (nullable NSData *)parseResponse:(NSData *)data useGM:(BOOL)useGM errorStr:(NSString * _Nullable * _Nonnull)errorStr;
@end
NS_ASSUME_NONNULL_END
//
// WBFaceError.h
// Pods
//
// Created by pp on 2017/8/15.
//
//
#import <UIKit/UIKit.h>
/*
Domain(错误出现的地方) Code Desc(描述) Reason(详细实际原因)
WBFaceErrorDomainInputParams 12000 传入参数为空 传入的xx为空
12001 传入的keyLicence不可用 传入的keyLicence不可用
12002 身份证格式不正确 身份证格式不正确
12003 使用自带对比源,传入参数错误,非base64 传入的srcPhotoString不是base64
12004 使用自带对比源,传入参数错误,超过3M 传入的srcPhotoString超过3M
12005 sdk资源引入版本不匹配 没有引入资源包或者引入的资源包版本与当前SDK版本不匹配
12006 订单号不能为0或者超过32位
12007 nonce字符串位数不为32
12008 faceid不合法,需要保证faceid与接口对应
12009 定制化SDK生成参数失败
12010 定制化参数校验错误
12011 当前版本意愿性表达服务暂不支持
WBFaceErrorDomainLoginNetwork 22100 网络异常 登陆时网络异常(请求未到达后台)
22200 网络异常 登陆时后台返回参数有误(请求到达后台)
WBFaceErrorDomainLoginServer 其他 透传后台错误码(请参考后台错误) 例如签名问题等等
WBFaceErrorDomainGetInfo 32100 网络异常 获取数字/活体类型/光线阈值,网络异常(请求未到达后台)
32200 网络异常 获取数字/活体类型/光线阈值,后台返回参数有误(请求到达后台)
WBFaceErrorDomainNativeProcess 42000 用户取消 回到后台/点击home/左上角/上传时左上角 取消
42001 网络环境不满足认证需求 无网络/2g网络
42002 权限异常,未获取权限 相机/麦克风/read phone/external storage
42003 相机运行中出错
42004 视频录制中出错 不能存/启动失败/结束失败
42005 请勿晃动人脸,保持姿势 未获取到最佳图片
42006 视频大小不满足要求 视频大小不满足要求
42007 超时 预检测/动作活体
42008 检测中人脸移出框外 活体/数字/反光
42009 光线活体本地错误
42010 风险控制超出次数 用户重试太多次
42011 没有检测到读数声音 数字活体过程中没有发声
42012 模型初始化失败
42013 意愿模块初始化失败
42015 登录态失效
42101 音频录制中出错
42102 没有检测到麦克风声音
42103 播报音频文件加载失败
42104 麦克风被占用,音频播报失败
42105 视频录制中出错
42106 音量过低,用户主动退出
42107 点头检测超时
WBFaceErrorDomainCompareNetwork 52100 网络异常 对比时,网络异常(请求未到达后台)
52200 网络异常 对比时,后台返回参数有误(请求到达后台)
WBFaceErrorDomainCompareServer 其他 透传后台错误码
*/
NS_ASSUME_NONNULL_BEGIN
/*
错误domain划分成两类:
1. 出现在登录时, 通过调用startXXXX 方法的failure block进行回调返回:
WBFaceErrorDomainInputParams, WBFaceErrorDomainLoginNetwork, WBFaceErrorDomainLoginServer
2. 人脸服务结果返回(封装在WBFaceVerifyResult中):
WBFaceErrorDomainGetInfo, WBFaceErrorDomainNativeProcess, WBFaceErrorDomainCompareNetwork, WBFaceErrorDomainCompareServer
*/
/* 登录时传入参数有误 */
UIKIT_EXTERN NSString *const WBFaceErrorDomainInputParams;
/* 登录时网络请求错误 */
UIKIT_EXTERN NSString *const WBFaceErrorDomainLoginNetwork;
/* 登录时后台拒绝登录, 具体参考后台word版本错误码, 这里直接透传 */
UIKIT_EXTERN NSString *const WBFaceErrorDomainLoginServer;
/* 拉取有效信息时候网络错误 */
UIKIT_EXTERN NSString *const WBFaceErrorDomainGetInfo;
/* native本地在活体检测中, 某些原因导致错误 */
UIKIT_EXTERN NSString *const WBFaceErrorDomainNativeProcess;
/* 上送后台比对时,网络错误 */
UIKIT_EXTERN NSString *const WBFaceErrorDomainCompareNetwork;
/* 后台比对完成,返回比对结果的错误原因*/
UIKIT_EXTERN NSString *const WBFaceErrorDomainCompareServer;
/* 后台比对未完成,返回失败的错误原因*/
UIKIT_EXTERN NSString *const WBFaceErrorDomainServerFailed;
@interface WBFaceError: NSObject
/**
错误发生的地方, 具体的发生地方由上面定义的 WBFaceErrorDomainXXXX 指定
*/
@property (nonatomic, readonly, copy) NSString *domain;
/**
每个domain中有相应的错误代码, 具体的错误代码见
*/
@property (nonatomic, readonly, assign) NSInteger code; //错误代码
@property (nonatomic, readonly, copy) NSString *desc; //获取本地化描述
@property (nonatomic, readonly, copy) NSString *reason; // 错误出现的真实原因原因
@property (nonatomic, readonly, copy) NSDictionary * _Nullable otherInfo;// 预留接口
+ (instancetype)errorWithDomain:(NSString *)domain code:(NSInteger)code desc:(NSString *)desc;
+ (instancetype)errorWithDomain:(NSString *)domain code:(NSInteger)code desc:(NSString *)desc reason:(NSString *)reason;
+ (instancetype)errorWithDomain:(NSString *)domain code:(NSInteger)code desc:(NSString *)desc reason:(NSString *)reason otherInfo:(nullable NSDictionary *)otherInfo;
@end
NS_ASSUME_NONNULL_END
//
// WBFaceVerifyConst.h
// Pods
//
// Created by pp on 2017/7/31.
//
//
#import <UIKit/UIKit.h>
#ifndef WBFaceVerifyConst_h
#define WBFaceVerifyConst_h
#define WBCloudReflectionFaceVerifyVersion @"8.1.0"
UIKIT_EXTERN NSString *const WBCloudFaceVerifySDKVersion;
/**
SDK使用的主题风格
- WBFaceVerifyThemeDarkness: 暗黑色系主题
- WBFaceVerifyThemeLightness: 明亮色系主题
- WBFaceVerifyThemeCustom: 自定义主题,通过修改bundle中的custom.json实现自定义
*/
typedef NS_ENUM(NSInteger, WBFaceVerifyTheme) {
WBFaceVerifyThemeDarkness = 0,
WBFaceVerifyThemeLightness,
WBFaceVerifyThemeCustom,
};
typedef NS_ENUM(NSInteger, WBFaceVerifyLanguage) {
WBFaceVerifyLanguage_ZH_CN = 0, //简体中文
WBFaceVerifyLanguage_ZH_HK, //繁体中文
WBFaceVerifyLanguage_EN, //英语
WBFaceVerifyLanguage_ID, //印尼语
WBFaceVerifyLanguage_JA, //日语
WBFaceVerifyLanguage_KO, //韩语
WBFaceVerifyLanguage_TH //泰语
};
typedef NS_ENUM(NSInteger, WBFaceCustomTipsLoc) {
WBFaceCustomTipsLoc_Bottom = 0, //提示语在下
WBFaceCustomTipsLoc_Top,
};
#endif /* WBFaceVerifyConst_h */
//
// WBFaceVerifyCustomerService.h
// WBFaceV2
//
// Created by tank on 25/10/2016.
// Copyright © 2016 tencent. All rights reserved.
//
/**
注意拉起页面的方式:
SDK会创建一个UIWindow覆盖在当前界面,并在新创建的UIWindow界面进行人脸认证,并且可以通过实现 wbfaceVerifyServiceGetWindowLevel 代理方法,传入创建的UIWindow的windowLevel, 传入的windowLevel必须是1~999, 默认情况如果不实现 wbfaceVerifyServiceGetWindowLevel 方法,windowLevel = UIWindowLevelNormal + 1
*/
#import <UIKit/UIKit.h>
#import "WBFaceVerifyConst.h"
#import "WBFaceVerifySDKConfig.h"
#import "WBFaceVerifyResult.h"
NS_ASSUME_NONNULL_BEGIN
// SDK在运行结束退出时候会发出通知. 具体的通知内容可以见delegate方法wbfaceVerifyCustomerServiceDidFinished:中的注释
UIKIT_EXTERN NSString *const WBFaceVerifyCustomerServiceDidFinishedNotification;
@class WBFaceVerifyCustomerService;
/**
处理刷脸回调
*/
@protocol WBFaceVerifyCustomerServiceDelegate <NSObject>
@optional
-(void)wbfaceVerifyCustomerServiceWillUploadBestImage:(UIImage *)bestImage;
@required
-(void)wbfaceVerifyCustomerServiceDidFinishedWithFaceVerifyResult:(WBFaceVerifyResult *)faceVerifyResult;
@end
@interface WBFaceVerifyCustomerService : NSObject
@property (nullable,nonatomic,weak) id<WBFaceVerifyCustomerServiceDelegate> delegate;
@property (nonatomic, assign, readonly) BOOL isService;
/*
全局唯一单例
*/
+(instancetype)sharedInstance;
/*
初始化云刷脸sdk,仅做参数初始化与登陆,不拉起刷脸页面
登陆有时效性,建议在登陆完成后success回调中拉起刷脸页面!!
登陆过程为异步操作,多次登陆以最后一次收到的结果为准!!
此SDK接口中
合作方后台开发需要通过后台接口获取sign,
然后根据自带比对源接口, 通过后台接口获取faceId!!!!(native端无需传入自带比对源图)
*** faceId为空时,启用仅活体检测服务,不做比对 !!!
注意, 请使用 dispatch_async(dispatch_get_main_queue(), ^{ }); 异步调用SDK的入口方法
@param userid 用户唯一标识, 由合作方自行定义(具体要求,参考word接入文档)
@param nonce 满足接入要求的32位随机数(具体要求,参考word接入文档)
@param sign 满足接入要求的40位签名值(具体要求,参考word接入文档)
@param appid 腾讯服务分配的appid
@param orderNo 每次人脸身份认证请求的唯一订单号: 建议为32位字符串(不超过32位)
@param apiVersion 后台api接口版本号(不是SDK的版本号),默认请填写@"1.0.0"
@param licence 腾讯给合作方派发的前端使用的licence(该licence同app当前使用的bundle id绑定)
@param faceId 合作方必须要先在获取faceId的接口里送入用户自带比对源图片信息,得到相应的faceId后,再送入sdk!!!!(参考word接入文档)
*** faceId为空时,启用仅活体检测服务,不做比对 !!!
@param sdkConfig SDK基础配置项目
@param success 服务登录成功回调,登录成功以后开始进行活体和检测服务
@param failure 服务登录失败回调,具体参考错误码文档(参考word接入文档)
*/
-(void)initSDKWithUserId:(NSString *)userid
nonce:(NSString *)nonce
sign:(NSString *)sign
appid:(NSString *)appid
orderNo:(NSString *)orderNo
apiVersion:(NSString *)apiVersion
licence:(NSString *)licence
faceId:(nullable NSString *)faceId
sdkConfig:(WBFaceVerifySDKConfig *)sdkConfig
success:(void (^)(void))success
failure:(void (^)(WBFaceError * _Nonnull error))failure;
/*
增强级SDK核身入口,注意传入的faceId不能为空,且必须为增强faceId,否则会报failure
@param userid 用户唯一标识, 由合作方自行定义(具体要求,参考word接入文档)
@param nonce 满足接入要求的32位随机数(具体要求,参考word接入文档)
@param sign 满足接入要求的40位签名值(具体要求,参考word接入文档)
@param appid 腾讯服务分配的appid
@param orderNo 每次人脸身份认证请求的唯一订单号: 建议为32位字符串(不超过32位)
@param apiVersion 后台api接口版本号(不是SDK的版本号),默认请填写@"1.0.0"
@param licence 腾讯给合作方派发的前端使用的licence(该licence同app当前使用的bundle id绑定)
@param faceId 合作方必须要先获取*增强级*faceId,再送入sdk,不允许为空(参考word接入文档)
@param sdkConfig SDK基础配置项目
@param success 服务登录成功回调,登录成功以后开始进行活体和检测服务
@param failure 服务登录失败回调,具体参考错误码文档(参考word接入文档)
*/
-(void)initAdvanceSDKWithUserId:(NSString *)userid
nonce:(NSString *)nonce
sign:(NSString *)sign
appid:(NSString *)appid
orderNo:(NSString *)orderNo
apiVersion:(NSString *)apiVersion
licence:(NSString *)licence
faceId:(nonnull NSString *)faceId
sdkConfig:(WBFaceVerifySDKConfig *)sdkConfig
success:(void (^)(void))success
failure:(void (^)(WBFaceError * _Nonnull error))failure;
/**
以上一次的登陆结果拉起刷脸页面,必须先登录再拉起刷脸页面
@return 拉起是否成功
*/
- (BOOL)startWbFaceVeirifySdk;
#pragma mark - 意愿性表达接口
/*
意愿性SDK入口,注意传入的faceId不能为空
@param userid 用户唯一标识, 由合作方自行定义(具体要求,参考word接入文档)
@param nonce 满足接入要求的32位随机数(具体要求,参考word接入文档)
@param sign 满足接入要求的40位签名值(具体要求,参考word接入文档)
@param appid 腾讯服务分配的appid
@param orderNo 每次人脸身份认证请求的唯一订单号: 建议为32位字符串(不超过32位)
@param apiVersion 后台api接口版本号(不是SDK的版本号),默认请填写@"1.0.0"
@param licence 腾讯给合作方派发的前端使用的licence(该licence同app当前使用的bundle id绑定)
@param faceId 合作方必须要先获取*增强级*faceId,再送入sdk,不允许为空(参考word接入文档)
@param sdkConfig SDK基础配置项目
@param success 服务登录成功回调,登录成功以后开始进行活体和检测服务
@param failure 服务登录失败回调,具体参考错误码文档(参考word接入文档)
*/
-(void)initWillSDKWithUserId:(NSString *)userid
nonce:(NSString *)nonce
sign:(NSString *)sign
appid:(NSString *)appid
orderNo:(NSString *)orderNo
apiVersion:(NSString *)apiVersion
licence:(NSString *)licence
faceId:(nonnull NSString *)faceId
sdkConfig:(WBFaceVerifySDKConfig *)sdkConfig
success:(void (^)(void))success
failure:(void (^)(WBFaceError * _Nonnull error))failure;
@end
NS_ASSUME_NONNULL_END
//
// WBFaceVerifyResult.h
// Pods
//
// Created by pp on 2017/8/22.
//
//
#import <UIKit/UIKit.h>
#import "WBFaceError.h"
#import "WBFaceVerifyConst.h"
@interface WBFaceWillModeResult : NSObject
/*
核身结果的对应错误码
*/
@property (nonatomic, copy, readonly) NSString *faceCode;
/*
核身结果的对应错误描述
*/
@property (nonatomic, copy, readonly) NSString *faceMsg;
/*
意愿性结果的对应错误码
*/
@property (nonatomic, copy, readonly) NSString *willCode;
/*
意愿性结果的对应错误描述
*/
@property (nonatomic, copy, readonly) NSString *willMsg;
@property (nonatomic, strong, readonly) NSURL *videoURL;
@end
@interface WBFaceSimpleModeResult : NSObject
/**
结果对应的订单号
*/
@property (nonatomic, copy, readonly) NSString *orderNo;
/**
接下来用于人脸对比的安全性参数
*/
@property (nonatomic, copy, readonly) NSString *encryptAESKey;
/**
视频编码
*/
@property (nonatomic, copy, readonly) NSString *userVideoString;
/**
使用传入publickey加密过的AES
*/
@property (nonatomic, copy, readonly) NSString *videoEncryptAESKey;
/**
用于后面进行人脸比对的数据参数
*/
@property (nonatomic, copy, readonly) NSString *identifyStr;
@end
/*
增强级结果,具体参数含义参考后台返回字段,结果为透传
*/
@interface WBFaceRiskInfo : NSObject
@property (nonatomic, copy, readonly) NSString *deviceInfoLevel;
@property (nonatomic, copy, readonly) NSString *deviceInfoTag;
@property (nonatomic, copy, readonly) NSString *riskInfoLevel;
@property (nonatomic, copy, readonly) NSString *riskInfoTag;
@end
/**
人脸服务返回结果对象
*/
@interface WBFaceVerifyResult : NSObject
/**
人脸比对结果是否通过:
YES: 表示人脸服务通过
NO: 表示人脸服务不通过
*/
@property (nonatomic, assign, readonly) BOOL isSuccess;
/**
结果对应的订单号
*/
@property (nonatomic, copy, readonly) NSString *orderNo;
/**
isSuccess == YES 时, sign有值, 通过该sign可以去后台拉取本次人脸服务的照片,视频存证
isSuccess == NO 时, sign 无意义
*/
@property (nonatomic, copy, readonly) NSString * sign;
/**
活体检测服务得分
isSuccess == YES 时, liveRate 有值:
1. liveRate 可能是 @"分数为空", 这种情况具体咨询合作方
2. float类型的字符串, 请调用 [liveRate floatValue] 获取具体分数
isSuccess == NO 时, liveRate 无意义
*/
@property (nonatomic, copy, readonly) NSString * liveRate;
/**
人脸比对服务得分
isSuccess == YES 时, similarity 有值:
1. similarity 可能是 @"分数为空", 这种情况具体咨询合作方
2. float类型的字符串, 请调用 [similarity floatValue] 获取具体分数
isSuccess == NO 时, similarity 无意义
*/
@property (nonatomic, copy, readonly) NSString * similarity;
/**
人脸比对图片之一
isSuccess == YES 时, 该属性是上送比对图片之一UIImage的base64编码字符串(图片格式是jpg)
isSuccess == NO 时, 该属性为nil
*/
@property (nonatomic, copy, readonly) NSString * userImageString;
/**
isSuccess == YES 时候, error 无意义
isSuccess == NO 时, error中存储的具体错误信息,参考 WBFaceError.h
*/
@property (nonatomic, strong, readonly) WBFaceError * error;
#pragma mark - 非标专用返回参数
@property (nonatomic, strong, readonly) WBFaceSimpleModeResult *simpleModeResult;
#pragma mark - 增强SDK专用参数
@property (nonatomic, strong, readonly) WBFaceRiskInfo *riskInfo;
#pragma mark - 意愿性SDK返回参数
@property (nonatomic, strong, readonly) WBFaceWillModeResult *willModeResult;
-(NSString *)description;
@end
//
// WBFaceVerifySDKConfig.h
// Pods
//
// Created by pp on 2017/8/2.
//
//
#import <Foundation/Foundation.h>
#import "WBFaceVerifyConst.h"
NS_ASSUME_NONNULL_BEGIN
/**
人脸识别SDK 基础配置类
*/
@interface WBFaceVerifySDKConfig : NSObject
/*
是否使用非标模式(具体含义请咨询技术支持)
!!!使用原WBCloudFaceVerifySimpleSDK切过来的,务必打开此项
默认为NO
*/
@property (nonatomic, assign) BOOL useSimpleMode;
#pragma mark - common
/**
sdk中拉起人脸活体识别界面中使用UIWindow时的windowLevel配置,默认配置是1 + UIWindowLevelNormal
如果接入放app中有其他自定义UIWindow, 为了防止界面覆盖,可以酌情设置该参数
*/
@property (nonatomic, assign) NSUInteger windowLevel;
/**
人脸识别服务结果页是否展示配置项 - 是否展示人脸对比成功界面 -> 建议关闭
default: NO
*/
@property (nonatomic, assign) BOOL showSuccessPage DEPRECATED_MSG_ATTRIBUTE("SDK 已移除结果页, 若有需要可参考 Demo 实现");
/**
人脸识别服务结果页是否展示配置项 - 是否展示人脸对比失败界面 -> 建议关闭
default: NO
*/
@property (nonatomic, assign) BOOL showFailurePage DEPRECATED_MSG_ATTRIBUTE("SDK 已移除结果页, 若有需要可参考 Demo 实现");
/**
人脸识别服务是否进行通过录像, 从而进行视频存证
default: NO
*/
@property (nonatomic, assign) BOOL recordVideo;
/**
人脸识别服务是否强制校验视频,当视频为空时报错
可能会出现在部分性能差的机型
default: NO
*/
@property (nonatomic, assign) BOOL checkVideo;
/**
是否由SDK内部处理sdk网络请求的cookie
默认值: YES
*/
@property (nonatomic, assign) BOOL manualCookie;
/**
多语言配置
默认中文,当使用其他语言时,强制静音
*/
@property (nonatomic, assign) WBFaceVerifyLanguage language;
/**
人脸识别页面中的主题风格, 需要配合不同资源包使用:
WBFaceVerifyThemeDarkness - 暗灰主题
WBFaceVerifyThemeLightness - 明亮主题
- 当前意愿性表达只支持明亮主题, 若使用了意愿性表达功能则强制设定为明亮主题
*/
@property (nonatomic, assign) WBFaceVerifyTheme theme;
/**
是否静音
默认值:YES
*/
@property (nonatomic, assign) BOOL mute;
/**
刷脸服务走iPv6协议栈
默认:YES
*/
@property (nonatomic, assign) BOOL isIpv6;
/**
是否海外用户
默认:NO
*/
@property (nonatomic, assign) BOOL isAbroad;
/**
是否打开日志上报
1打开 0关闭 -1由SDK内部决定
默认:-1
*/
@property (nonatomic, assign) NSInteger enableTrackLog DEPRECATED_ATTRIBUTE;
/*
送入自定义提示文案的位置
默认:WBFaceCustomTipsLoc_Bottom
*/
@property (nonatomic, assign) WBFaceCustomTipsLoc tipsLoc;
/*
检测过程中展示的文案
默认为空
*/
@property (nonatomic, copy) NSString *customTipsInDetect;
/*
上传过程中展示的文案
默认为空
*/
@property (nonatomic, copy) NSString *customTipsInUpload;
/*
底部提示文案,长度不超过70字
*/
@property (nonatomic, copy) NSString *bottomCustomTips;
/*
退出二次确认UI配置
*/
@property (nonatomic, copy) NSString *exitAlertTitle; //标题
@property (nonatomic, copy) NSString *exitAlertMessage; //内容
@property (nonatomic, copy) NSString *exitAlertYES; //确认按钮
@property (nonatomic, copy) NSString *exitAlertNO; //取消按钮
/*
如果有使用苹果分屏模式(UIWindowScene),打开此开关
Xcode11新建工程有使用Scene,可以参考资料自行调整
默认为NO
*/
@property (nonatomic, assign) BOOL useWindowSecene;
/// 使用 hostVC 以实现基于 Modal 的 transition, **一般不需要配置, 仅建议 native 开发者使用**
/// - IMPORTANT: **一般不需要配置, 仅建议 native 开发者使用**
@property (nonatomic, weak, nullable) UIViewController *hostVC;
/**
TencentCloudHuiyanSDKFace.bundle 的目录路径,不包含bundle本身(仅当需要自己下发资源时配置,本地资源无需配置)
!!!重要:此目录下必须包含TencentCloudHuiyanSDKFace.bundle 文件,否则无法拉起SDK
*/
@property (nonatomic, copy) NSString *bundlePath;
/**
face-tracker-v001.bundle 的目录路径
!!!重要:若有值,此目录下必须包含 face-tracker-v001.bundle 文件,否则无法拉起SDK
*/
@property (nonatomic, copy, nullable) NSString *faceTrackerBundleDirPath;
/**
face-tracker-v001.bundle 是否经过重新打包, 默认值为 NO, **一般不需要配置**
*/
@property (nonatomic) BOOL faceTrackerBundleRepackaged;
/**
是否采用增强比对服务,仅增强接口生效,仅活体服务设置为NO
默认为 NO
*/
@property (nonatomic, assign) BOOL useAdvanceCompare;
/**
APP是否只允许横屏,非强制横屏的不用设置,否则可能会出现旋转问题
@default NO
*/
@property (nonatomic, assign) BOOL forceOrientation;
#pragma mark - simple //非标特有字段,标准模式无需设置
/**
是否返回录制的视频
default: NO
*/
@property (nonatomic, assign) BOOL returnVideo;
/**
返回视频加密的公钥,如果不配置则不加密
需要recordVideo returnVideo同时为YES,才返回加密的视频内容
*/
@property (nonatomic, copy) NSString *publicKey;
/**
AES加密需要用到的IV
*/
@property (nonatomic, copy) NSString *aesIV;
#pragma mark - will //意愿性特有字段,标准模式无需设置
@property (nonatomic, assign) BOOL recordWillVideo;
@property (nonatomic, assign) BOOL checkWillVideo;
/// 播报音量,值范围(0.1,1]
@property (nonatomic, assign) float willVolume;
/// 当录制意愿视频时,是否同时返回sdk+服务端视频
@property (nonatomic, assign) BOOL uploadAndReturnWillVideo;
/// 是否允许意愿阶段使用有线耳机, 默认不允许
@property (nonatomic, assign) BOOL allowWillHeadset;
#pragma mark -
/**
默认sdk配置
*/
+(instancetype)sdkConfig;
@end
NS_ASSUME_NONNULL_END
/*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GMSSL_BASE64_H
#define GMSSL_BASE64_H
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
namespace kycgm {
#endif
typedef struct {
/* number saved in a partial encode/decode */
int num;
/*
* The length is either the output line length (in input bytes) or the
* shortest input line length that is ok. Once decoding begins, the
* length is adjusted up each time a longer line is decoded
*/
int length;
/* data to encode */
unsigned char enc_data[80];
/* number read on current line */
int line_num;
int expect_nl;
} BASE64_CTX;
# define BASE64_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
# define BASE64_DECODE_LENGTH(l) ((l+3)/4*3+80)
void base64_encode_init(BASE64_CTX *ctx);
int base64_encode_update(BASE64_CTX *ctx, const uint8_t *in, int inlen, uint8_t *out, int *outlen);
void base64_encode_finish(BASE64_CTX *ctx, uint8_t *out, int *outlen);
void base64_decode_init(BASE64_CTX *ctx);
int base64_decode_update(BASE64_CTX *ctx, const uint8_t *in, int inlen, uint8_t *out, int *outlen);
int base64_decode_finish(BASE64_CTX *ctx, uint8_t *out, int *outlen);
int base64_encode_block(unsigned char *t, const unsigned char *f, int dlen);
int base64_decode_block(unsigned char *t, const unsigned char *f, int n);
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (c) 2014 - 2020 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GMSSL_ENDIAN_H
#define GMSSL_ENDIAN_H
/* Big Endian R/W */
//#define GETU16(p) \
// ((uint16_t)(p)[0] << 8 | \
// (uint16_t)(p)[1])
#define GETU32(p) \
((uint32_t)(p)[0] << 24 | \
(uint32_t)(p)[1] << 16 | \
(uint32_t)(p)[2] << 8 | \
(uint32_t)(p)[3])
//#define GETU64(p) \
// ((uint64_t)(p)[0] << 56 | \
// (uint64_t)(p)[1] << 48 | \
// (uint64_t)(p)[2] << 40 | \
// (uint64_t)(p)[3] << 32 | \
// (uint64_t)(p)[4] << 24 | \
// (uint64_t)(p)[5] << 16 | \
// (uint64_t)(p)[6] << 8 | \
// (uint64_t)(p)[7])
// 注意:PUTU32(buf, val++) 会出错!
//#define PUTU16(p,V) \
// ((p)[0] = (uint8_t)((V) >> 8), \
// (p)[1] = (uint8_t)(V))
#define PUTU32(p,V) \
((p)[0] = (uint8_t)((V) >> 24), \
(p)[1] = (uint8_t)((V) >> 16), \
(p)[2] = (uint8_t)((V) >> 8), \
(p)[3] = (uint8_t)(V))
//#define PUTU64(p,V) \
// ((p)[0] = (uint8_t)((V) >> 56), \
// (p)[1] = (uint8_t)((V) >> 48), \
// (p)[2] = (uint8_t)((V) >> 40), \
// (p)[3] = (uint8_t)((V) >> 32), \
// (p)[4] = (uint8_t)((V) >> 24), \
// (p)[5] = (uint8_t)((V) >> 16), \
// (p)[6] = (uint8_t)((V) >> 8), \
// (p)[7] = (uint8_t)(V))
/* Little Endian R/W */
//
//#define GETU16_LE(p) (*(const uint16_t *)(p))
//#define GETU64_LE(p) (*(const uint64_t *)(p))
#define GETU32_LE(p) (*(const uint32_t *)(p))
//
//#define PUTU16_LE(p,V) *(uint16_t *)(p) = (V)
#define PUTU32_LE(p,V) *(uint32_t *)(p) = (V)
#define PUTU64_LE(p,V) *(uint64_t *)(p) = (V)
/* Rotate */
#define ROL32(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
#define ROL64(a,n) (((a)<<(n))|((a)>>(64-(n))))
//
//#define ROR32(a,n) ROL32((a),32-(n))
//#define ROR64(a,n) ROL64(a,64-n)
#endif
/*
* Copyright (c) 2021 - 2021 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GMSSL_MEM_H
#define GMSSL_MEM_H
#include <stddef.h> // where size_t from
namespace kycgm {
void memxor(void *r, const void *a, size_t len);
void gmssl_memxor(void *r, const void *a, const void *b, size_t len);
}
#endif
/*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GMSSL_SM2_H
#define GMSSL_SM2_H
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "sm3.h"
namespace kycgm {
typedef struct {
uint8_t x[32];
uint8_t y[32];
} SM2_POINT;
typedef struct {
SM2_POINT public_key;
uint8_t private_key[32];
uint8_t key_usage[4];
} SM2_KEY;
#define SM2_MAX_CIPHERTEXT_SIZE 366
#define SM2_MIN_PLAINTEXT_SIZE 1 // re-compute SM2_MIN_CIPHERTEXT_SIZE when modify
#define SM2_MAX_PLAINTEXT_SIZE 255 // re-compute SM2_MAX_CIPHERTEXT_SIZE when modify
typedef struct {
SM2_POINT point;
uint8_t hash[32];
uint8_t ciphertext_size;
uint8_t ciphertext[SM2_MAX_PLAINTEXT_SIZE];
} SM2_CIPHERTEXT;
int sm2_set_public_key(SM2_KEY *key,
const uint8_t public_key[64]); // FIXME: 这里是否应该用octets呢?这算是椭圆曲线点的一个公开格式了
int sm2_do_encrypt(const SM2_KEY *key, const uint8_t *in, size_t inlen, SM2_CIPHERTEXT *out);
int sm2_encrypt_c1c3c2(const SM2_KEY *key, const uint8_t *in, size_t inlen, uint8_t *out,
size_t *outlen);
}
#endif
/*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GMSSL_SM3_H
#define GMSSL_SM3_H
#include <string.h>
#include <stdint.h>
namespace kycgm {
#define SM3_DIGEST_SIZE 32
#define SM3_BLOCK_SIZE 64
#define SM3_STATE_WORDS 8
typedef struct {
uint32_t digest[SM3_STATE_WORDS];
uint64_t nblocks;
uint8_t block[SM3_BLOCK_SIZE];
size_t num;
} SM3_CTX;
void sm3_init(SM3_CTX *ctx);
void sm3_update(SM3_CTX *ctx, const uint8_t *data, size_t datalen);
void sm3_finish(SM3_CTX *ctx, uint8_t dgst[SM3_DIGEST_SIZE]);
};
#endif // GMSSL_SM3_H
/*
* Copyright (c) 2014 - 2021 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KYCGMSSL_SM4_H
#define KYCGMSSL_SM4_H
#include <sys/types.h>
#include <stdint.h>
#include <string.h>
namespace kycgm {
// TODO: 增加一个flag标注用于加密还是解密,使用时用assert检查这个flag
typedef struct {
uint32_t rk[32];
} SM4_KEY;
void sm4_set_encrypt_key(SM4_KEY *sm4_key, const uint8_t key[16]);
void sm4_set_decrypt_key(SM4_KEY *sm4_key, const uint8_t key[16]);
void sm4_encrypt(const SM4_KEY *sm4_key, const uint8_t in[16], uint8_t out[16]);
void sm4_cbc_encrypt(const SM4_KEY *key, const uint8_t iv[16],
const uint8_t *in, size_t nblocks, uint8_t *out);
void sm4_cbc_decrypt(const SM4_KEY *key, const uint8_t iv[16],
const uint8_t *in, size_t nblocks, uint8_t *out);
int sm4_cbc_padding_encrypt(const SM4_KEY *key, const uint8_t iv[16],
const uint8_t *in, size_t inlen,
uint8_t *out, size_t *outlen);
int sm4_cbc_padding_decrypt(const SM4_KEY *key, const uint8_t iv[16],
const uint8_t *in, size_t inlen,
uint8_t *out, size_t *outlen);
}
#endif
/* ====================================================================
* Copyright (c) 2014 - 2019 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#ifndef GMSSL_SM4_LCL_H
#define GMSSL_SM4_LCL_H
#include "sm4.h"
namespace kycgm {
extern const uint8_t SM4_S[256];
extern const uint32_t SM4_T[256];
#define S32(A) \
((SM4_S[((A) >> 24) ] << 24) ^ \
(SM4_S[((A) >> 16) & 0xff] << 16) ^ \
(SM4_S[((A) >> 8) & 0xff] << 8) ^ \
(SM4_S[((A)) & 0xff]))
#define ROUNDS(x0, x1, x2, x3, x4) \
ROUND(x0, x1, x2, x3, x4, 0); \
ROUND(x1, x2, x3, x4, x0, 1); \
ROUND(x2, x3, x4, x0, x1, 2); \
ROUND(x3, x4, x0, x1, x2, 3); \
ROUND(x4, x0, x1, x2, x3, 4); \
ROUND(x0, x1, x2, x3, x4, 5); \
ROUND(x1, x2, x3, x4, x0, 6); \
ROUND(x2, x3, x4, x0, x1, 7); \
ROUND(x3, x4, x0, x1, x2, 8); \
ROUND(x4, x0, x1, x2, x3, 9); \
ROUND(x0, x1, x2, x3, x4, 10); \
ROUND(x1, x2, x3, x4, x0, 11); \
ROUND(x2, x3, x4, x0, x1, 12); \
ROUND(x3, x4, x0, x1, x2, 13); \
ROUND(x4, x0, x1, x2, x3, 14); \
ROUND(x0, x1, x2, x3, x4, 15); \
ROUND(x1, x2, x3, x4, x0, 16); \
ROUND(x2, x3, x4, x0, x1, 17); \
ROUND(x3, x4, x0, x1, x2, 18); \
ROUND(x4, x0, x1, x2, x3, 19); \
ROUND(x0, x1, x2, x3, x4, 20); \
ROUND(x1, x2, x3, x4, x0, 21); \
ROUND(x2, x3, x4, x0, x1, 22); \
ROUND(x3, x4, x0, x1, x2, 23); \
ROUND(x4, x0, x1, x2, x3, 24); \
ROUND(x0, x1, x2, x3, x4, 25); \
ROUND(x1, x2, x3, x4, x0, 26); \
ROUND(x2, x3, x4, x0, x1, 27); \
ROUND(x3, x4, x0, x1, x2, 28); \
ROUND(x4, x0, x1, x2, x3, 29); \
ROUND(x0, x1, x2, x3, x4, 30); \
ROUND(x1, x2, x3, x4, x0, 31)
#endif
}
//
// CamRisk.h
// CamRisk
//
// Created by 徐森圣 on 2020/12/1.
// Copyright © 2020 Tencent Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <TuringShieldCamRisk/TuringCamRiskTask.h>
#import <TuringShieldCamRisk/TuringCamRiskService.h>
/**
!!!: 一、服务概览
本服务旨在对摄像头风险进行识别。由于识别引擎和预测模型均在云端,因此大多数服务均为异步接口。
!!!: 二、主要接口介绍
TuringCamRiskService
|
| 创建检测任务
|
v
TuringCamRiskTask
|
| 产生请求数据
v
NSData
更多的信息请参阅 TuringCamRiskService.h 和 TuringCamRiskTask.h中的注释
!!!: 三、一般使用范例
```objective-c
// 为服务配置上下文(可用的key有多个,这里只简单例举一个,参见TuringCamRiskContextKey中的枚举字符串)
[[TuringCamRiskService sharedService] setupContext:@{ TuringCamRiskContextAppIDKey: @"F.R.D." }];
// 创建一个检测任务
TuringCamRiskTask *task = [[TuringCamRiskService sharedService] taskForSceneID:nil];
// 为任务指定监控的视图,检测群控风险(此动作可选)
[task monitorView:[UIApplication sharedApplication].keyWindow];
// 为任务指定监控的摄像头设备,检测劫持风险(注意请提供正在使用的设备;此动作可选)
[task monitorCameraWithDevice:cameraDevice session:captureSession previewView:previewLayer];
// 获取用于请求的数据
[task queryPostDataWithCompletionHandler:^(NSData * _Nullable data, NSError * _Nullable error) {
// 如果成功,data非空,error为空;如果失败,data为空,error非空
// data可用于http post直接请求图灵盾服务
NSLog(@"data = %@, error = %@", error);
}];
```
*/
//
// TuringCamRiskService.h
// TuringShieldCamRisk
//
// Created by 徐森圣 on 2020/12/2.
// Copyright © 2020 Tencent Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <TuringShieldCamRisk/TuringServiceDefine.h>
#import <TuringShieldCamRisk/TuringServiceSettings.h>
#import <TuringShieldCamRisk/TuringCamRiskTask.h>
/// 这些常量值用于设置或获取context中的字典数据中的key。
typedef NSString * TuringCamRiskContextKey NS_EXTENSIBLE_STRING_ENUM;
/// 用于设置请求序列编号的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextRequestSequenceKey;
/// 用于设置meta data的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextMetaDataKey;
/// 用于设置接入渠道号的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextChannelKey;
/// 用于设置接入构建号的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSNumber *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextBuildNoKey;
/// 用于设置接入版本号的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextVersionKey;
/// 用于设置接入版本LC的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextLCKey;
/// 用于设置其它额外信息的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextExtraInfoKey;
/// 用于设置接入App ID的key,参见 `TuringCamRiskContextKey`。该key对应的值应为 NSString *。
extern TuringCamRiskContextKey const _Nonnull TuringCamRiskContextAppIDKey;
@interface TuringCamRiskService : NSObject
+ (void)setupTarsServerWithURL:(nonnull NSString *)URLString withChannelID:(int32_t)ChannelID TS_AVAILABLE_IF(TS_NETWORKING_TMF_SHARK_SUPPORTS);
/// 禁止直接生成实例
- (nonnull instancetype)init NS_UNAVAILABLE;
/// 所有服务均以此单例提供
+ (nonnull instancetype)sharedService;
/// 预连接服务器网络,以便加速后续请求的回应速度
+ (void)touchNetworking;
/// 设置全局回调,用于控制HTTP请求的发送
/// @param callback 该回调会回传HTTP请求所使用的request对象,修改对象属性可改变请求的行为。回调返回NO时将取消请求,否则正常执行请求。
/// @discussion 图灵盾完成一个操作可能会执行多个HTTP请求,中途改变请求的http目标后,无法确保原子操作,需要业务自行控制。
+ (void)setupTarsHTTPPostCallback:(nullable BOOL(^)(NSMutableURLRequest *_Nonnull request))callback TS_AVAILABLE_IF(TS_ALLOWS_HTTP_POST_HANDLING);
/// 设置调用相关的上下文。这些上下文由业务设置,同时回传业务的后端,用于数据稽核。
/// @param context 上下文的内容。字典中用到的key,请参考`TuringCamRiskContextKey`及其常量定义。
- (void)setupContext:(nonnull NSDictionary<TuringCamRiskContextKey, id> *)context;
/// 生成一个摄像头检测任务并接受TuringCamRiskService的管理。如果相同sceneIDID的任务已经生成,则会
/// 返回同一个任务实例,直到该实例被`- detatchTask:`释放。
/// @param sceneID 摄像头检测任务的场景ID
/// @discussion 如果sceneID为空,则该任务不会被TuringCamRiskService管理,也不需要调用
/// `- detatchTask:`释放
- (nonnull TuringCamRiskTask *)taskForSceneID:(nullable NSString *)sceneID;
/// 释放一个摄像头检测任务
/// @param task 要释放的任务实例
- (void)detatchTask:(nonnull TuringCamRiskTask *)task;
+ (nonnull NSDictionary *)SDKInfo;
@end
/// 设备实时风险标签
@interface TuringCamRiskService (RiskToken)
/// 获取实时风险标签
/// @param usingCache 是否使用缓存。YES表示由图灵盾SDK根据缓存策略,决定是否更新缓存;NO表示总是联网获取实时结果。
/// @param completion 获取结果的回调
/// @discussion 一般我们建议usingCache设置为YES。仅当在对风险检测要求特别高的场景下,才设置为NO。图灵盾SDK能有效管理缓存并确保缓存的检测安全效果,同时节省请求流量和服务计算成本。同时,由于您可能不够理解何时可以使用缓存而何时需要更新缓存,因此我们不建议客户端自行缓存我们的结果。
- (void)fetchRiskTokenUsingCache:(BOOL)usingCache WithCompletionHandler:(nonnull void(^)(NSString *_Nullable message, NSError *_Nullable error))completion TS_AVAILABLE_IF(TS_ENABLES_RISK_DETECT_FEATURE);
@end
@interface TuringCamRiskService (Debugging)
/// 设置是否使用测试服务器
/// @discussion 注意只能在未使用任何 TuringCamRiskService 的服务之前设置,否则某些正在进行中的
/// 服务可能会出现错误
@property (class, nonatomic) BOOL usesDebugServer TS_AVAILABLE_IF(__TS_OR(TS_NETWORKING_WUP_SUPPORTS, TS_NETWORKING_SHARK_SUPPORTS));
@end
//
// TuringCamRiskTask.h
// TuringShieldCamRisk
//
// Created by 徐森圣 on 2020/12/2.
// Copyright © 2020 Tencent Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
/// 摄像头检测任务
/// @example
/// ```
/// [task queryPostDataWithCompletionHandler:^(NSData * _Nullable data, NSError * _Nullable error) {
/// // error为空时可以用于发送到图灵盾服务器
/// }];
/// ```
@interface TuringCamRiskTask : NSObject
/// 禁止直接创建摄像头检测任务
- (nonnull instancetype)init NS_UNAVAILABLE;
/// 为任务指定要监控的摄像头设备及其相关信息,需要调用`-postWithCompletionHandler:`或者
/// `-queryPostDataWithCompletionHandler`之前调用。
/// @param cameraDevice 受监控的摄像头设备
/// @param session 受监控的摄像会话
/// @param previewLayer 受监控的预览图层
/// @discussion 调用该方法是可选的,但会提升检测的准确性
- (void)monitorCameraWithDevice:(nullable AVCaptureDevice *)cameraDevice session:(nullable AVCaptureSession *)session previewView:(nullable AVCaptureVideoPreviewLayer *)previewLayer;
/// 为任务指定要监控的用户界面,通常是一个用户可操作的视图,例如viewController.view,或者一个按钮
/// @param view 受监控的用户界面
/// @discussion 调用该方法是可选的,但会提升检测的准确性
- (void)monitorView:(nonnull UIView *)view;
/// 请求检测
/// @param completionHandler 请求完成的回调函数。如果正确返回,则result非空,否则error非空
/// @discussion 数据将会直接发送到图灵盾服务器,只是为了便于测试连通性而提供该接口。
- (void)postWithCompletionHandler:(nullable void(^)(NSDictionary<NSString *, id> *_Nullable result, NSError *_Nullable error))completionHandler;
/// 生成用于请求的数据包
/// @param completionHandler 请求完成的回调函数。如果正确返回,则data非空,否则error非空
- (void)queryPostDataWithCompletionHandler:(nonnull void(^)(NSData *_Nullable data, NSError *_Nullable error))completionHandler;
/// 任务的场景ID
@property (nonatomic, copy, readonly, nonnull) NSString *scene;
@end
//
// TuringServiceDefine.h
// TuringShield
//
// Created by 徐森圣 on 2018/3/13.
// Copyright © 2018年 Tecent Inc. All rights reserved.
//
// $$api_level=TS_TURING_SHIELD_OPEN_API_LEVEL$$
//
//
#ifndef __TURING_SERVICE_DEFINE_H__
#define __TURING_SERVICE_DEFINE_H__
#import "TuringServiceSettings.h"
#define TS_OBJECT_CLASS(name) TS_CLASS_##name
#define TS_OBJECT_IMPL(name) TS_REAL_##name
#define TS_OBJECT_DECL(name) \
@protocol TS_OBJECT_CLASS(name) <NSObject> \
@end \
typedef NSObject<TS_OBJECT_CLASS(name)> *name##_t
#define TS_OBJECT_DECL_SUBCLASS(name, super) \
@protocol TS_OBJECT_CLASS(name) <TS_OBJECT_CLASS(super)> \
@end \
typedef NSObject<TS_OBJECT_CLASS(name)> *name##_t
#if defined(__cplusplus)
#define TS_BEGIN_DECLS extern "C" {
#define TS_END_DECLS }
#else
#define TS_BEGIN_DECLS
#define TS_END_DECLS
#endif
TS_OBJECT_DECL(ts_object);
/**
将浮点类型的秒数转换为长整数类型的毫秒数
@param sec 秒数,需要为double类型
@return 毫秒数,long long类型
*/
#define SEC_TO_MSEC(sec) (int64_t)( (sec) * 1000ll )
/**
如果condition的定义为0或未定义,则声明函数不可用
@param condition 一个可展开的宏定义
*/
#define TS_AVAILABLE_IF(condition) \
__TS_IF_ELSE(condition) \
/*Case True*/ (__TS_EMPTY()) \
/*Case False*/(UNAVAILABLE_ATTRIBUTE)
/**
如果c1或c2中任意一个的定义为0或未定义,则声明函数不可用
@param c1 条件1,一个可展开的宏定义
@param c2 条件2,一个可展开的宏定义
*/
#define TS_AVAILABLE_IFS(c1, c2) \
__TS_IF_ELSE(c1) \
/*Case True*/ (TS_AVAILABLE_IF(c2)) \
/*Case False*/(UNAVAILABLE_ATTRIBUTE)
/**
如果当前线程是主线程,直接执行包含的短语句;如果当前不在主线
程,将包含的短语句调度到主线程执行,并阻塞当前线程。
@param ... 一个需要调度到主线程执行的短语句
*/
#define TSMainThreadProtectCall(...) do { \
if ([NSThread isMainThread] == NO) { \
dispatch_sync(dispatch_get_main_queue(), ^{ \
__VA_ARGS__; \
}); \
} \
else { \
__VA_ARGS__; \
} \
} while (0)
/**
如果当前线程是主线程,直接执行包含的短语句;如果当前不在主线
程,将包含的短语句调度到主线程执行,并阻塞当前线程。然后返回
短语句执行的结果。注意,如果返回值是Objective C对象,目前
不支持MRC。
@param ... 一个需要调度到主线程执行的短语句
@return 短语句的返回值
*/
#define TSMainThreadProtectGet(...) ({ \
typeof(__VA_ARGS__) val; \
if ([NSThread isMainThread] == NO) { \
__block typeof(val) bval; \
dispatch_sync(dispatch_get_main_queue(), ^{ \
bval = __VA_ARGS__; \
}); \
val = bval; \
} \
else { \
val = __VA_ARGS__; \
} \
val; \
})
#define __1second (1.0f)
#define __10seconds (__1second * 10)
#define __20seconds (__1second * 20)
#define __1minute (__1second * 60)
#define __10minutes (__1minute * 10)
#define __30minutes (__1minute * 30)
#define __1hour (__1minute * 60)
#define __1day (__1hour * 24)
#define __1week (__1day * 7)
#define ts_shutup(v) (void)(v)
///
/// there's a stupid bug in @available:
/// If we build TuringShield in Xcode 11 and use @available in TuringShield, Xcode 11 is ALSO required
/// on building the An app that integrating TuringShield. The main reason is, the implementation of
/// @available in Xcode 11 is different to the one in Xcode 10.
/// So let's disable @available for time being.
///
#if 0
#define ts_ios_version_is_at_least(major, minor, patch) @available(iOS major##.##minor##.##patch, *)
#else
#define ts_ios_version_is_at_least(major, minor, patch) \
({ \
NSOperatingSystemVersion v = \
NSProcessInfo.processInfo.operatingSystemVersion; \
v.majorVersion == major ? \
( v.minorVersion == minor ? \
( v.patchVersion >= patch ) : \
( v.minorVersion > minor ) ) : \
( v.majorVersion > major ); \
})
#endif
#if defined(TS_SDK_CHANNEL_ID) && TS_USES_CLASS_ALIAS
#define tsclassname(name) __TS_CAT(name, TS_ALIAS_SURFIX)
#define tsmethodname(name) __TS_CAT(TS_ALIAS_SURFIX, name)
#define tsclass(className) class tsclassname(className); @compatibility_alias className tsclassname(className)
#else
#define tsclassname(name) name
#define tsmethodname(name) name
#define tsclass(className) class className
#endif
#define ts_channel_alias(name) __TS_CAT(name, __TS_CAT(_, TS_SDK_CHANNEL_ID))
#define TS_DEPRECATED __attribute__((deprecated))
#define TS_MSG_DEPRECATED(msg) __attribute((deprecated((msg))))
#pragma mark - Inner Macro, do NOT use
#define __TS_ARG_0_(n, ...) n
#define __TS_ARG_1_(x0, n, ...) n
#define __TS_ARG_2_(x0, x1, n, ...) n
#define __TS_ARG_3_(x0, x1, x2, n, ...) n
#define __TS_ARG_4_(x0, x1, x2, x3, n, ...) n
#define __TS_ARG_5_(x0, x1, x2, x3, x4, n, ...) n
#define __TS_ARG_6_(x0, x1, x2, x3, x4, x5, n, ...) n
#define __TS_ARG_7_(x0, x1, x2, x3, x4, x5, x6, n, ...) n
#define __TS_ARG_8_(x0, x1, x2, x3, x4, x5, x6, x7, n, ...) n
#define __TS_ARG_9_(x0, x1, x2, x3, x4, x5, x6, x7, x8, n, ...) n
#define __TS_EVAL(...) __TS_EVAL1(__TS_EVAL1(__TS_EVAL1(__VA_ARGS__)))
#define __TS_EVAL1(...) __TS_EVAL2(__TS_EVAL2(__TS_EVAL2(__VA_ARGS__)))
#define __TS_EVAL2(...) __TS_EVAL3(__TS_EVAL3(__TS_EVAL3(__VA_ARGS__)))
#define __TS_EVAL3(...) __TS_EVAL4(__TS_EVAL4(__TS_EVAL4(__VA_ARGS__)))
#define __TS_EVAL4(...) __TS_EVAL5(__TS_EVAL5(__TS_EVAL5(__VA_ARGS__)))
#define __TS_EVAL5(...) __VA_ARGS__
#define __TS_TO_CSTRING_(str) #str
#define __TS_TO_CSTRING(...) __TS_TO_CSTRING_(__VA_ARGS__)
#define __TS_TO_NSSTRING_(str) @#str
#define __TS_TO_NSSTRING(...) __TS_TO_NSSTRING_(__VA_ARGS__)
#define __TS_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__
#define __TS_CAT(a, ...) __TS_PRIMITIVE_CAT(a, __VA_ARGS__)
#define __TS_ARG_0(n, ...) n
#define __TS_ARG_1(x0, n, ...) n
#define __TS_IS_PROBE(...) __TS_ARG_1(__VA_ARGS__, 0)
#define __TS_PROBE() ~, 1
#define __TS_NOT(x) __TS_IS_PROBE(__TS_CAT(__TS_NOT_, x))
#define __TS_NOT_0 __TS_PROBE()
#define __TS_BOOL(x) __TS_NOT(__TS_NOT(x))
#define __TS_AND(x1, x2) __TS_IF_ELSE(x1)(__TS_IF_ELSE(x2)(1)(0))(0)
#define __TS_AND_3(x1, x2, x3) __TS_AND(x1, __TS_AND(x2, x3))
#define __TS_OR(x1, x2) __TS_IF_ELSE(x1)(1)(__TS_IF_ELSE(x2)(1)(0))
#define __TS_OR_3(x1, x2, x3) __TS_OR(x1, __TS_OR(x2, x3))
#define __TS_IIF(c) __TS_PRIMITIVE_CAT(__TS_IIF_, c)
#define __TS_IIF_0(...)
#define __TS_IIF_1(...) __VA_ARGS__
#define __TS_IELSE(c) __TS_PRIMITIVE_CAT(__TS_IELSE_, c)
#define __TS_IELSE_0(...) __VA_ARGS__
#define __TS_IELSE_1(...)
#define __TS_IIF_ELSE(c) __TS_PRIMITIVE_CAT(__TS_IIF_ELSE_, c)
#define __TS_IIF_ELSE_0(...) __TS_IELSE_0
#define __TS_IIF_ELSE_1(...) __VA_ARGS__ __TS_IELSE_1
#define __TS_IF(c) __TS_IIF(__TS_BOOL(c))
#define __TS_IF_ELSE(c) __TS_IIF_ELSE(__TS_BOOL(c))
#define __TS_EMPTY()
#define __TS_DEFER(id) id __TS_EMPTY()
#define __TS_OBSTRUCT(...) __VA_ARGS__ __TS_DEFER(__TS_EMPTY)()
#pragma mark - API Levels
#define TS_ALWAYS_VISIBLE __attribute__ ((visibility ("default")))
#define TS_ALWAYS_HIDDEN __attribute__ ((visibility ("hidden")))
#define TS_TURING_HIGHER_WRAPPER_LEVEL 1
#define TS_TURING_SHIELD_OPEN_API_LEVEL 2
#define TS_FRIENDLY_API_LEVEL 3
#define TS_PRIVATE_LEVEL 4
#if TS_API_LEVEL >= TS_TURING_HIGHER_WRAPPER_LEVEL && !!TS_TURING_ID_WRAPPER_APIS
# define TS_TURING_ID_API 1
#else
# define TS_TURING_ID_API 0
#endif
#if TS_API_LEVEL >= TS_TURING_HIGHER_WRAPPER_LEVEL && !!TS_TURING_AGE_WRAPPER_APIS
# define TS_TURING_AGE_API 1
#else
# define TS_TURING_AGE_API 0
#endif
#if TS_API_LEVEL >= TS_TURING_SHIELD_OPEN_API_LEVEL
# define TS_TURING_SHIELD_OPEN_API 1
#else
# define TS_TURING_SHIELD_OPEN_API 0
#endif
#if TS_API_LEVEL >= TS_FRIENDLY_API_LEVEL
# define TS_FRIENDLY_API 1
#else
# define TS_FRIENDLY_API 0
#endif
#if TS_API_LEVEL >= TS_PRIVATE_LEVEL
# define TS_PRIVATE 1
#else
# define TS_PRIVATE 0
#endif
#define TS_VISIBLE_LEVEL(APIKind) \
__TS_IF_ELSE(APIKind) \
/*CASE TRUE*/ (TS_ALWAYS_VISIBLE) \
/*CASE FALSE*/ (TS_ALWAYS_HIDDEN)
#endif /* __TURING_SERVICE_DEFINE_H__ */
//
// TuringServiceSettings.h
// TuringShield
//
// Created by 徐森圣 on 2018/3/19.
// Copyright © 2018年 Tecent Inc. All rights reserved.
//
#ifndef TuringServiceSettings_h
#define TuringServiceSettings_h
/**
编译目标,用于检查变量是否正确
格式为TS_BUILD_TARGET_xxx
@discussion
受Build Settings中环境变量TS_BUILD_TARGET影响并自动更新
*/
#define TS_BUILD_TARGET_YOUTU
/**
定义为1,使用主人识别模型
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_OWNER_PROJECT 0
/**
定义为1,使用青少年识别模型
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_AGE_PROJECT 0
/**
定义为1,使用人机识别模型
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_HUMAN_PROJECT 0
/**
渠道号,用于决定用哪个模型
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_SDK_CHANNEL_ID 108138
#define TS_SDK_CHANNEL_STRING __TS_TO_NSSTRING(TS_SDK_CHANNEL_ID)
/**
SDK是否自带数据请求和回复逻辑
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_DATA_SENDING 1
/**
SDK是否自带数据处理逻辑
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_PREDICTION_PROCEEDING 1
/**
SDK是否带请求签名逻辑,云端请求需要WAF服务配合,SDK需要打开
TS_ENABLES_DATA_SENDING和TS_HUMAN_PROJECT
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_HTTP_REQUEST_SIGN 0
/**
如果设置为非0,则同一个场景(scene)和事件(action)最多保留指定数量的数据
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_LIMITED_RECORDS_PER_SCENE_ACTION 20
/**
实验室模式,某些逻辑在工程化前后可能有变化,服务器接口的调用方式也可能不一致
目前人机部分默认值为0,主人识别部分默认值为1
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_LAB_LOGIC 0
/**
打开日志打印
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENALBLES_LOG_PRINT 0
/**
使用模型预测之前不检查数据非空
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_DONT_CHECK_DATA_SIZE 0
/**
不记录(当然也不上报)触摸事件中的位置信息
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_DONT_RECORD_TOUCH_POSITION 0
/**
不加密打包的数据
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_DONT_ENCRYPT_PACKING_DATA 0
/**
不压缩打包的数据
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_DONT_COMPRESS_PACKING_DATA 0
/**
使用设备指纹特性
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_FINGERPRINT_FEATURE 1
/**
支持的打包方式:WUP协议
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_NETWORKING_WUP_SUPPORTS 1
/**
支持的打包方式:Shark协议
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_NETWORKING_SHARK_SUPPORTS 1
/**
支持的打包方式:TMF Shark协议
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_NETWORKING_TMF_SHARK_SUPPORTS 0
/**
是否支持云控设备指纹配置;目前私有化部署不支持该选项
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_FINGERPRINT_CONFIG_CONTROL 1
/**
是否支持关键API篡改检测
@discussion
受Build Settings中同名环境变量影响并自动更新
*/
#define TS_ENABLES_KEYED_API_CHECKING 1
/**
绑定的App bundle ID
@discussion
设置后SDK将只能运行在指定的App上
*/
#define TS_BOUND_BUNDLE_IDENTIFIER nil
#define TS_BOUND_BUNDLE_TOKEN { 0x00 }
/**
是否允许多渠道复用SDK
@discussion
若打开,并且初始渠道号为0,则必须设置渠道号后才可以开始调用相关功能
*/
#define TS_ENABLES_CUSTOM_CHANNEL_ID 0
#define TS_DOMAIN_PREFIX_TOKEN com.tencent.TuringShield.
#define TS_DOMAIN_PREFIX_CSTRING __TS_TO_CSTRING(TS_DOMAIN_PREFIX_TOKEN)
#define TS_DOMAIN_PREFIX_STRING __TS_TO_NSSTRING(TS_DOMAIN_PREFIX_TOKEN)
#define TS_DOMAIN_FOR_REACHABLITTY_TEST 8.8.8.8
#define TS_DOMAIN_FOR_REACHABLITTY_TEST_CSTRING __TS_TO_CSTRING(TS_DOMAIN_FOR_REACHABLITTY_TEST)
#define TS_DOMAIN_FOR_REACHABLITTY_TEST_STRING __TS_TO_NSSTRING(TS_DOMAIN_FOR_REACHABLITTY_TEST)
/**
一些临时用的开关
*/
#define TS_ENABLES_SENSOR_RECORDING 0
#define TS_ENABLES_SENSOR_REPLAYING 0
#define TS_USES_OLD_MOTION_TRACKER_IF_NEEDED 1
#define TS_ENABLES_CUSTOM_CLIENT_VERSION 0
#define TS_ENABLES_CUSTOM_CHANNEL_ID 0
#define TS_USES_CLASS_ALIAS 2
#define TS_ACT_AS_TAID_ADVERTISER 0
#define TS_ACT_AS_TAID_PROVIDER 1
#define TS_ENABLES_FINGERPRINT_CONFIG_TEST 0
#define TS_API_LEVEL TS_FRIENDLY_API_LEVEL
#define TS_AVOID_USING_IDFA 1
#define TS_FEATURE_DELEGATION 0
#define TS_ENABLES_DEVICE_INFO_ACCESS 0
#define TS_TURING_ID_WRAPPER_APIS 0
#define TS_TURING_AGE_WRAPPER_APIS 0
#define TS_ANTIBOT_SDK 0
#define TS_RISK_TOKEN_SDK 0
#define TS_ENABLES_RISK_DETECT_FEATURE 0
#define TS_USES_RANDOM_NAMING 1
#define TS_ALLOWS_HTTP_POST_HANDLING 1
#define TS_SKIP_GATHERER_AUTO_HANDLING 0
#define TS_SDK_VERSION 20067
#define TS_SDK_LC_CODE P3HVPSP8592KZXS5
#define TS_SDK_LC __TS_TO_NSSTRING(TS_SDK_LC_CODE)
#define TS_SDK_BUILD_DATE 2023-10-11 18:34:55
#define TS_ALIAS_SURFIX _YOUTU108138v20067
#endif /* TuringServiceSettings_h */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment