yarpa
yarpa

Reputation: 136

libcrypto deprecated on Mac OS X 10.7 (Lion)

I just went to use libcrypto on Lion and it looks like the entire api has been deprecated. The man pages haven't been updated since 10.6.6.

Does anybody know what the replacement for libcrypto is on Lion?

Upvotes: 6

Views: 6940

Answers (3)

blutfink
blutfink

Reputation: 412

In case you know what you're doing and you just want to get rid of these warnings, one way is to add

#pragma GCC diagnostic ignored "-Wdeprecated-declarations" 

to the relevant headers – in my case /usr/include/openssl/crypto.h and /usr/include/openssl/md5.h.

Upvotes: 7

yarpa
yarpa

Reputation: 136

Ok, answering my own question here.

10.7 introduced Transforms into Security.framework, which is tied closely to SecKey. Transforms let you do lots of things, including encoding (eg. base64), digests, signing/verifying, and encryption.

Here's an example of how to sign some data. All of the transforms follow the same basic pattern; if you look in the Headers for Security.framework you'll see a header for each type of transform. These are from SecTransformReadTransform.h and SecSignVerifyTransform.h. I'm omitting any error checking or cleanup code here for simplicity.

    NSData *dataToBeSigned = ;// Get this from somewhere. We set sha1 attributes down below, so this should be a sha1 digest
    SecKeyRef *key = ;// Get this from somewhere; keychain or SecItemImport
    SecGroupTransformRef group = SecTransformCreateGroupTransform();
    CFReadStreamRef readStream = NULL;
    SecTransformRef readTransform = NULL;
    SecTransformRef signingTransform = NULL;

    // Setup our input stream as well as an input transform
    readStream = CFReadStreamCreateWithBytesNoCopy(kCFAllocatorDefault,
                                                    [dataToBeSigned bytes],
                                                    [dataToBeSigned length],
                                                    kCFAllocatorNull); // Pass Null allocator so it doesn't free NSData's bytes

    readTransform = SecTransformCreateReadTransformWithReadStream(readStream);

    // Setup a signing transform
    signingTransform = SecSignTransformCreate(key, NULL);
    SecTransformSetAttribute(signingTransform, kSecInputIsDigest, kCFBooleanTrue, NULL);
    SecTransformSetAttribute(signingTransform, kSecDigestTypeAttribute, kSecDigestSHA1, NULL);

    // Connect read and signing transform; Have read pass its data to the signer
    SecTransformConnectTransforms(readTransform, kSecTransformOutputAttributeName,
                                    self.signingTransformRef, kSecTransformInputAttributeName,
                                    group, NULL);

    // Execute the sequence of transforms (group)
    // The last one in the connected sequence is the return value
    NSData *signature = SecTransformExecute(group, NULL);

Upvotes: 4

user149341
user149341

Reputation:

libcrypto is part of OpenSSL, which hasn't changed much. It's not going away, but Apple recommends that developers use their CDSA (Common Data Security Architecture) library rather than using OpenSSL directly.

Upvotes: 7

Related Questions