简体   繁体   English

无法检查iPhone上是否存在配置文件

[英]unable to check if a configuration profile exists on the iPhone

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 我正在尝试检查iPhone上是否存在配置文件,我找到了以下教程: http//alex.tapmania.org/2011/09/check_conf_prof_is_installed_ios.html

which , for me , translates into the following code : 对我来说,这转化为以下代码:

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";
    }

the application crashes at the line : 应用程序在该行崩溃:

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 . 我还注意到,在这个阶段, cert没有分配任何内存。

What is wrong? 怎么了? is this the correct procedure? 这是正确的程序吗? if not, is there another tutorial that is more beneficial? 如果没有,还有另一个更有益的教程吗?

Thanks! 谢谢!

I am not sure as to why you'd want to do this through code. 我不确定你为什么要通过代码来做这件事。 There are Mac OSx apps that already do this for you. Mac OSx应用程序已经为您完成此操作。 If what you're intending to do doesn't have to involve code, you can download this Mac app called iPhone Configuration Utility from this Apple link . 如果你打算做什么不需要涉及代码,你可以从这个Apple链接下载这个名为iPhone配置实用程序的 Mac应用程序 Has many features including configuring/view/etc profiles installed on an iPhone. 有许多功能,包括在iPhone上安装配置/视图/等配置文件。

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. 您遇到的障碍无疑是您的证书问题。

I created my pair of certificates using openSSL for win32 by ShiningLight. 我通过ShiningLight使用openSSL for win32创建了一对证书。 Full instructions on how to do it can be found here: http://www.dylanbeattie.net/docs/openssl_iis_ssl_howto.html 有关如何操作的完整说明,请访问: http//www.dylanbeattie.net/docs/openssl_iis_ssl_howto.html

note however, that there are a couple of gotchas: 但请注意,有几个陷阱:

  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). 创建根证书时,配置文件中的basicconstraints = CA设置必须设置为TRUE(其他证书需要为FALSE)。

  2. For IOs to be able to read them, both certificates must be encoded using DER. 要使IO能够读取它们,必须使用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. 要使用openssl执行此操作,您需要在两个证书上运行类似于openssl x509 -in certs / cert.cer -out certs / certder.cer -outform DER的命令 I strongly suspect it is the wrong encoding that is crashing your code. 我强烈怀疑这是错误的编码会导致代码崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM