无法检查iPhone上是否存在配置文件 [英] unable to check if a configuration profile exists on the iPhone

查看:171
本文介绍了无法检查iPhone上是否存在配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查iPhone上是否存在配置文件,我找到了以下有关如何操作的教程:
http://alex.tapmania.org/2011/09/check_conf_prof_is_installed_ios.html

I am trying to check if a configuration profile exists on the iPhone , I found the following tutorial on how to do it : http://alex.tapmania.org/2011/09/check_conf_prof_is_installed_ios.html

我转换成以下代码:

NSString * certPath = [[NSBundle mainBundle] pathForResource:@"certificate" ofType:@"mobileconfig"];
    SecTrustRef trust;
    NSData * certData = [NSData dataWithContentsOfFile:certPath];
    SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certData);
    SecPolicyRef policy = SecPolicyCreateBasicX509();
    OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert],policy, &trust);

    SecTrustResultType  trustResult = -1;
    err = SecTrustEvaluate(trust, &trustResult);


    if (trustResult ==4) {
        label.text=@"Profile installed";
    }
    else{
        label.text=@"Profile not installed";
    }

应用程序在该行崩溃:

OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge id)cert],policy, &trust);

我还注意到在这个阶段证书没有分配任何内存。

I also noticed that at this stage cert doesn t have any memory allocated in it .

有什么问题?这是正确的程序吗?如果没有,是否有另一个更有益的教程?

What is wrong? is this the correct procedure? if not, is there another tutorial that is more beneficial?

谢谢!

推荐答案

我最近解决了你遇到的同样问题。您发布的代码和链接的建议确实可用于检查配置文件的存在。您遇到的障碍无疑是您的证书问题。

I have recently solved the same problem that you are having. The code that you have posted and the advice from your link can indeed be used to check for the existence of a configuration profile. The snag that you have hit is undoubtedly a problem with your certificate.

我是通过ShiningLight使用openSSL for win32创建了一对证书。有关如何操作的完整说明,请访问: http://www.dylanbeattie.net/docs /openssl_iis_ssl_howto.html

I created my pair of certificates using openSSL for win32 by ShiningLight. Full instructions on how to do it can be found here: http://www.dylanbeattie.net/docs/openssl_iis_ssl_howto.html

但请注意,有几个陷阱:

note however, that there are a couple of gotchas:


  1. 创建根证书时,配置文件中的basicconstraints = CA设置必须设置为TRUE(其他证书需要为FALSE)。

  1. when creating your root certificate, the basicconstraints=CA setting in the config file must be set to TRUE (FALSE is needed for the other certificate).

要使IO能够读取它们,必须使用DER对两个证书进行编码。要使用openssl执行此操作,您需要在两个证书上运行类似于 openssl x509 -in certs / cert.cer -out certs / certder.cer -outform DER 的命令。我强烈怀疑这是错误的编码会导致代码崩溃。

For IOs to be able to read them, both certificates must be encoded using DER. To do this using openssl you need to run a command similar to openssl x509 -in certs/cert.cer -out certs/certDER.cer -outform DER on both certificates. I strongly suspect it is the wrong encoding that is crashing your code.

这篇关于无法检查iPhone上是否存在配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆