2011-09-19 16 views

risposta

7

libcrypto è parte di OpenSSL, che non è cambiato molto. Non sta andando via, ma Apple consiglia agli sviluppatori di utilizzare la loro libreria CDSA (Common Data Security Architecture) anziché utilizzare direttamente OpenSSL.

+0

Grazie :) Ciò mi ha portato a Security/SecKey.h e alle funzioni correlate che sembrano fare esattamente ciò di cui ho bisogno. – yarpa

+0

In realtà, SecKey è solo la metà della soluzione. Gestisce la generazione di chiavi, ma non sembra supportare alcuna effettiva operazione di crittografia (anche se sembra che la versione di iOS funzioni, ma sto guardando Lion). CDSA è deprecato in Lion, quindi la domanda originale è ancora aperta. (Vedi Security.framework/cssmtype.h per la notifica della deprecazione). La caccia continua. – yarpa

3

Ok, rispondendo alla mia domanda qui.

10.7 ha introdotto Trasforma in Security.framework, che è strettamente legato a SecKey. Le trasformazioni ti permettono di fare molte cose, inclusa la codifica (ad esempio base64), digesti, firma/verifica e crittografia.

Ecco un esempio di come firmare alcuni dati. Tutte le trasformazioni seguono lo stesso schema di base; se si guardano le intestazioni per Security.framework, verrà visualizzata un'intestazione per ogni tipo di trasformazione. Questi sono da SecTransformReadTransform.h e SecSignVerifyTransform.h. Sto omettendo qualsiasi controllo degli errori o codice di pulizia qui per semplicità.

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); 
7

Nel caso in cui si sa che cosa si sta facendo e si desidera solo per sbarazzarsi di questi avvertimenti, in un modo è quello di aggiungere

#pragma GCC diagnostic ignored "-Wdeprecated-declarations" 

alle intestazioni rilevanti - nel mio caso/usr/include/openssl/crypto.h e /usr/include/openssl/md5.h.

+1

È meglio aggiungerlo dove effettivamente usi openssl, invece di applicare patch alle intestazioni di sistema –