zoukankan      html  css  js  c++  java
  • APP获取证书签名指纹

    Android:

        public static String getSignatureSHA1(Context context) {
            String sign = null;
            try {
                // 通过包管理器获得指定包名包含签名的包信息
                @SuppressLint("PackageManagerGetSignatures")
                PackageInfo packageInfo = context.getPackageManager()
                        .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
                // 通过返回的包信息获得签名数组
                Signature[] signatures = packageInfo.signatures;
                sign = getSHA1FromSignature(signatures[0].toByteArray());
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
    
            return sign;
        }

    iOS:

    + (NSString *)bundleSeedID {
        NSDictionary *query = [NSDictionary dictionaryWithObjectsAndKeys:
                               (__bridge id)kSecClassGenericPassword, (__bridge id)kSecClass,
                               @"bundleSeedID", (__bridge id)kSecAttrAccount,
                               @"", (__bridge id)kSecAttrService,
                               (id)kCFBooleanTrue, (__bridge id)kSecReturnAttributes,
                               nil];
        CFDictionaryRef result = nil;
        OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
        if (status == errSecItemNotFound)
            status = SecItemAdd((__bridge CFDictionaryRef)query, (CFTypeRef *)&result);
        if (status != errSecSuccess)
            return nil;
        NSString *accessGroup = [(__bridge NSDictionary *)result objectForKey:(__bridge id)kSecAttrAccessGroup];
        NSArray *components = [accessGroup componentsSeparatedByString:@"."];
        NSString *bundleSeedID = [[components objectEnumerator] nextObject];
        CFRelease(result);
        return bundleSeedID;
    }

     关于bundleSeedID,即App ID Prefixes,通俗点是 app id 前缀。可以作为证书的指纹使用,详细请看官方文档:

    https://developer.apple.com/library/archive/technotes/tn2311/_index.html

    服务器通过记录该客服端的值,能够知晓当前app用的是什么证书签名。一定程度上可以避免原始包被改后,使用其它签名运行,至于具体的策略还是要结合多种其它手段。(譬如 bundle id 或是包名的校验,包体加密混淆,防hook的一些策略等)

  • 相关阅读:
    osu合集(期望dp)
    P1640 [SCOI2010]连续攻击游戏
    P2155 [SDOI2008]沙拉公主的困惑
    P3419 [POI2005]SAMToy Cars / SP688 SAM Toy Cars
    P3586 [POI2015]LOG
    P4147 玉蟾宫
    P4454 [CQOI2018]破解DH协议
    射击小游戏一02(玩家和怪物添加)
    ASCII,Unicode和UTF8
    Android中MenuInflater实例
  • 原文地址:https://www.cnblogs.com/qiyer/p/10679153.html
Copyright © 2011-2022 走看看