]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/keyFromCert/keyFromCert.cpp
2 * keyFromCert.cpp - extract public key from a cert.
4 #include <utilLib/common.h>
5 #include <utilLib/cspwrap.h>
6 #include <security_cdsa_utils/cuFileIo.h>
7 #include <clAppUtils/clutils.h>
11 #include <Security/cssm.h>
12 #include <Security/x509defs.h>
13 #include <Security/oidsattr.h>
14 #include <Security/oidscert.h>
17 static void usage(char **argv
)
19 printf("Usage: %s [-q] certFile keyFile\n", argv
[0]);
23 int main(int argc
, char **argv
)
28 CSSM_CL_HANDLE clHand
; // CL handle
32 const char *certFile
= NULL
;
33 const char *keyFile
= NULL
;
41 if(!strcmp(argv
[1], "-q")) {
55 rtn
= readFile(certFile
, &rawCert
.Data
, &len
);
57 printf("Error reading %s; %s\n", certFile
, strerror(rtn
));
65 crtn
= CSSM_CL_CertGetKeyInfo(clHand
, &rawCert
, &pubKey
);
67 printError("CSSM_CL_CertGetKeyInfo", crtn
);
70 rtn
= writeFile(keyFile
, pubKey
->KeyData
.Data
, pubKey
->KeyData
.Length
);
71 if(!quiet
& (rtn
== 0)) {
72 printf("...wrote %u key bytes to %s\n", (unsigned)pubKey
->KeyData
.Length
,