]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/ocspTool/ocspUtils.cpp
Security-57031.10.10.tar.gz
[apple/security.git] / SecurityTests / clxutils / ocspTool / ocspUtils.cpp
1 #include <ctype.h>
2 #include <strings.h>
3 #include "ocspUtils.h"
4 #include <utilLib/cspwrap.h>
5 #include <Security/SecKey.h>
6 #include <Security/SecKeyPriv.h>
7
8
9 /*
10 * Sign some data with an identity.
11 */
12 OSStatus ocspSign(
13 SecIdentityRef idRef,
14 CSSM_DATA &plainText,
15 CSSM_ALGORITHMS algId, // RSA/SHA1, DSA/SHA1
16 CSSM_DATA &sig) // caller must APP_FREE()
17 {
18 const CSSM_KEY *privCssmKey;
19 OSStatus ortn;
20 SecKeyRef privKeyRef;
21 CSSM_CSP_HANDLE cspHand;
22 CSSM_RETURN crtn;
23
24 ortn = SecIdentityCopyPrivateKey(idRef, &privKeyRef);
25 if(ortn) {
26 cssmPerror("SecIdentityCopyPrivateKey", ortn);
27 return ortn;
28 }
29 ortn = SecKeyGetCSSMKey(privKeyRef, &privCssmKey);
30 if(ortn) {
31 cssmPerror("SecKeyGetCSSMKey", ortn);
32 goto errOut;
33 }
34 ortn = SecKeyGetCSPHandle(privKeyRef, &cspHand);
35 if(ortn) {
36 cssmPerror("SecKeyGetCSPHandle", ortn);
37 goto errOut;
38 }
39 sig.Data = NULL;
40 sig.Length = 0;
41 crtn = cspSign(cspHand, algId, (CSSM_KEY_PTR)privCssmKey,
42 &plainText, &sig);
43 if(crtn) {
44 cssmPerror("cspSign", crtn);
45 ortn = crtn;
46 }
47 errOut:
48 CFRelease(privKeyRef);
49 return ortn;
50 }