🌐
Stack Overflow
stackoverflow.com › questions › 71401010 › sectrustcreatewithcertificates-returns-null-trust-object
ios - SecTrustCreateWithCertificates returns null trust object - Stack Overflow
I am trying to run cert chain verification and running into a problem where my trust object is null. SecTrustCreateWithCertificates(certificates, SecPolicyCreateBasicX509(), trustObject) Where "
🌐
Limneos
developer.limneos.net › index.php
iOS 5.0 Runtime Headers - Security - SecPolicy.h
@result The CFTypeID of SecPolicy instances. */ CFTypeID SecPolicyGetTypeID(void) __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0); /*! @function SecPolicyCreateBasicX509 @abstract Returns a policy object for the default X.509 policy. @result A policy object.
🌐
Stack Overflow
stackoverflow.com › questions › 10238559 › creating-a-seccertificateref-for-nsurlconnection-authentication-challenge
iphone - Creating a SecCertificateRef for NSURLConnection Authentication Challenge - Stack Overflow

I finally found the answer. I was supposed to use SecIdentityCopyCertificate(identity, &certificateRef); instead of SecCertificateCreateWithData(nil, inPKCS12Data); to create my certificate.

Answer from David Skrundz on stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 5019185 › iphone-encryption-with-certificate
security - iPhone encryption with certificate - Stack Overflow

I tried your updated code with the addition of two lines at the end:

NSData *cipherData = [NSData dataWithBytes:aCipherText length:iCipherLength];
NSLog(@"(%d) %@", status, cipherData);

That works fine:

2011-02-17 22:24:04.204 Untitled[45121:207] (0) <87a2eb07 25ab693a 7fe88329 974b6820
843c5c33 8c5d4606 aecea682 0176e4cb 10482c9b fd2e2242 1c77d349 d3037e91 8d704783
f2e04c82 ef273815 bdb6aa73 f8646542 243f3e12 518147ba 53636441 fd9399d3 b198ed6a
615d51d1 4105fb75 27180f0d 09835551 5162e156 33dedf39 a87e17f8 16881990 c5e57a38
7cd7ec63>

Now one difference is that the public key I'm using is in my keychain. If yours isn't, you may want to look at the importing-an-ssl-cert-under-the-iphone-sdk link below. So far I've only tested on Simulator, which also can be different, but I believe this is correct.

If you still have trouble, make sure to check the result of each call (and if it returns OSStatus, check that). Which piece is failing?


You forgot to call SecTrustEvaluate() on your SecTrustRef before calling SecTrustCopyPublicKey(). Check the docs on SecTrustCopyPublicKey() which explains this.


Old information that wasn't as useful:

I believe these posts should point you in the right direction:

http://greghaygood.com/2009/01/17/asymmetric-encryption-with-the-iphone-sdk-and-securityframework

Importing an SSL cert under the iPhone SDK

Also note that if you have OpenSSL code for Mac already, you can compile OpenSSL for iPhone. This post was useful for me when I developed my build scripts:

http://www.therareair.com/2009/01/01/tutorial-how-to-compile-openssl-for-the-iphone/

Answer from Rob Napier on stackoverflow.com
🌐
Apple
developer.apple.com › forums › thread › 28113
How to disable ATS etc. for LAN se… | Apple Developer Forums
Got any sample code for how to use SecPolicyCreateBasicX509 with NSURLSession? The TechNote does not even mention this function.
🌐
Stack Overflow
stackoverflow.com › questions › 51985565 › how-to-get-the-type-of-encryption-used-in-a-seckey
swift - How to get the type of encryption used in a SecKey? - Stack Overflow
I get a SecKey from given certificates. Depending on the certificate, the SecKey can use either RSA or EllipticCurve encryption. let certificate = SecCertificateCreateWithData(kCFAllocatorDef...
🌐
Stack Overflow
stackoverflow.com › questions › 43084835 › how-to-encrypt-data-using-servers-public-key-txt-file-on-ios
encryption - How to encrypt data using server's public key txt file on iOS - Stack Overflow
I'm working on an iOS application with a java server. I need to encrypt some data using RSA. The RSA public key is a txt file. I want to connvert it into a SecKeyRef. The server is developed by the
🌐
Stack Overflow
stackoverflow.com › questions › 22441121 › sign-and-verify-a-file
ios - Sign and verify a file - Stack Overflow
I have some pretty simple requirements and I'm surprised how difficult this is: I want to sign a file, get the signature as base64 for transmission, and then verify that signature on iOS and OS X in
🌐
Stack Overflow
stackoverflow.com › questions › 28808101 › seckey-from-public-key-string-from-server-in-swift › 34157062
ios - Seckey from public key string from server in Swift - Stack Overflow

For mac:

let pubKey = "-----BEGIN PUBLIC KEY-----MIICIjANBgAgK.......InbFk1FkucQqruMyUCAwEAAQ==-----END PUBLIC KEY-----"
let pubKeyData = pubKey.dataUsingEncoding(NSASCIIStringEncoding)
var error: Unmanaged<CFErrorRef>?
let secKey = SecKeyCreateFromData(NSDictionary(), pubKeyData!, &error)

Where pubKey is a string representation of your public key. If you don't know your public key, you can infer it from your private key with the following command:

openssl rsa -in server.key -pubout  > mykey.pub

Where server.key is the file containing -----BEGIN RSA PRIVATE KEY----- as the first line.

For iOS:

It's a bit more complicate. You need a der file. It's a binary representation of your certificate. If you need to convert an existing certificate, you can do so with the following command:

 openssl x509 -outform der -in file.crt|pem -out mycert.der

The .crt or .pem file contains -----BEGIN CERTIFICATE----- as the first line.

Put the der file in your bundle and do:

let certificateData = NSData(contentsOfURL:NSBundle.mainBundle().URLForResource("mycert", withExtension: "der")!)

let certificate = SecCertificateCreateWithData(nil, certificateData!)

var trust: SecTrustRef?

let policy = SecPolicyCreateBasicX509()
let status = SecTrustCreateWithCertificates(certificate!, policy, &trust)

if status == errSecSuccess {
    let key = SecTrustCopyPublicKey(trust!)!;
}

Yatta ! Key now contains a SecKey representation of your public key. Happy Pinning.

Answer from Antzi on stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 20174621 › undefined-symbols-for-architecture-i386-when-trying-to-compile-afnetworking-2-0
xcode - Undefined symbols for architecture i386 when trying to compile AFNetworking 2.0 - Stack Overflow

Your missing iOS frameworks in the project. I bet security framework is one of them from the names I see.

Answer from Liviu R on stackoverflow.com
🌐
Medium
maheshasabe.medium.com › ssl-pinning-or-certificate-pinning-6508fc5e1567
SSL pinning or Certificate Pinning | by Mahesh Asabe | Medium
March 3, 2021 - Client-server communication happens using web services or API calls, Consider client invokes API request and asking for a response from the intended server & the man-in-the-middle attack scenario…
🌐
Stack Overflow
stackoverflow.com › questions › 13291846 › unable-to-check-if-a-configuration-profile-exists-on-the-iphone
objective c - unable to check if a configuration profile exists on the iPhone - Stack Overflow
NSString * certPath = [[NSBundle ... SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef) certData); SecPolicyRef policy = SecPolicyCreateBasicX509(); OSStatus err = SecTrustCreateWithCertificates((__bridge CFArrayRef) [NSArray arrayWithObject:(__bridge ...
🌐
Stack Overflow
stackoverflow.com › questions › 40497469 › pinning-publickey-with-alamofire
ios - Pinning PublicKey with AlamoFire - Stack Overflow
I've been trying to perform a public key pinning for my application. And I did the following steps: 1) First I used openssl to extract the server cert in der format openssl s_client -showcerts -
🌐
Stack Overflow
stackoverflow.com › questions › 14299434 › problems-with-adding-inmobi-sdk-to-my-ios-project
objective c - Problems with adding inmobi SDK to my iOS project - Stack Overflow

Have you added all the correct frameworks outlined at http://developer.inmobi.com/wiki/index.php?title=IOS.

It looks like you might not have linked the Security framework specifically?

Answer from RajPara on stackoverflow.com
🌐
Github-wiki-see
github-wiki-see.page › m › roznet › remotestash › wiki › How-to-generate-a-self-signed-certificate-and-validate-properly-it-in-URLSession-challenge
How to generate a self signed certificate and validate properly it in URLSession challenge · roznet/remotestash Wiki · GitHub
// Create a trust object to valid the remote certificate against our certificate authority let policy = SecPolicyCreateBasicX509() var optionalTrust : SecTrust? var trustResult : SecTrustResultType = SecTrustResultType.invalid guard SecTrustCreateWithCertificates([remoteCert] as CFArray, policy, ...