X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/SecurityTests/clxutils/certTime/certTime.cpp diff --git a/SecurityTests/clxutils/certTime/certTime.cpp b/SecurityTests/clxutils/certTime/certTime.cpp new file mode 100644 index 00000000..bd5bb830 --- /dev/null +++ b/SecurityTests/clxutils/certTime/certTime.cpp @@ -0,0 +1,618 @@ +/* + * certTime - measure performacne of cert parse and build. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "extenCooker.h" + +#define KEYSIZE_DEF 1024 +#define CL_KEY_VIA_GET_KEY 0 + +static void usage(char **argv) +{ + printf("Usage: %s op loops [options]\n", argv[0]); + printf("Op:\n"); + printf(" p parse\n"); + printf(" g parse & get all fields\n"); + #if CL_KEY_VIA_GET_KEY + printf(" t parse & get some fields, emulating TPCertInfo, GetKeyInfo\n"); + #else + printf(" t parse & get some fields, emulating TPCertInfo, fetchField(key)\n"); + #endif + printf(" c create\n"); + printf(" s create & sign\n"); + printf(" v verify\n"); + printf("Options:\n"); + printf(" b RSA blinding on\n"); + printf(" k=keysize (default = %d)\n", KEYSIZE_DEF); + exit(1); +} + +/* + * The certs we'll be parsing + */ +static const char *certNames[] = +{ + "anchor_0", // GTE CyberTrust Root, no extens + "anchor_9", // VeriSign, no extens + "anchor_34", // TrustCenter, 6 extens + "anchor_44", // USERTRUST, 5 extens, incl. cRLDistributionPoints + "anchor_76", // QuoVadis, 6 extens, incl. authorityInfoAccess + "anchor_80", // KMD-CA Kvalificeret3 6 extens +}; + +#define NUM_PARSED_CERTS (sizeof(certNames) / sizeof(certNames[0])) + +/* dummy RDN - subject and issuer - we aren't testing this */ +CB_NameOid dummyRdn[] = +{ + { "Apple Computer", &CSSMOID_OrganizationName }, + { "Doug Mitchell", &CSSMOID_CommonName } +}; +#define NUM_DUMMY_NAMES (sizeof(dummyRdn) / sizeof(CB_NameOid)) + +#define KEY_ALG CSSM_ALGID_RSA +#define SIG_ALG CSSM_ALGID_SHA1WithRSA +#define SUBJ_KEY_LABEL "subjectKey" + + +/* + * Set of extensions we'll be creating + */ +/* empty freeFcn means no extension-specific resources to free */ +#define NO_FREE NULL + +static ExtenTest extenTests[] = { + { kuCreate, kuCompare, NO_FREE, + sizeof(CE_KeyUsage), CSSMOID_KeyUsage, + "KeyUsage", 'k' }, + { ekuCreate, ekuCompare, NO_FREE, + sizeof(CE_ExtendedKeyUsage), CSSMOID_ExtendedKeyUsage, + "ExtendedKeyUsage", 'x' }, + { authKeyIdCreate, authKeyIdCompare, authKeyIdFree, + sizeof(CE_AuthorityKeyID), CSSMOID_AuthorityKeyIdentifier, + "AuthorityKeyID", 'a' }, + { genNamesCreate, genNamesCompare, genNamesFree, + sizeof(CE_GeneralNames), CSSMOID_SubjectAltName, + "SubjectAltName", 't' }, +}; + +#define MAX_EXTENSIONS (sizeof(extenTests) / sizeof(ExtenTest)) + +static int doParse( + CSSM_CL_HANDLE clHand, + const CSSM_DATA &cert, + unsigned loops) +{ + CSSM_HANDLE cacheHand; + CSSM_RETURN crtn; + + for(unsigned loop=0; loopKeyData.Data, 0); + appFree(subjPubKey, 0); + #else + CSSM_CL_FreeFieldValue(clHand, &CSSMOID_CSSMKeyStruct, subjPubKeyData); + #endif + + crtn = CSSM_CL_CertAbortCache(clHand, cacheHand); + if(crtn) { + printError("CSSM_CL_CrlAbortCache", crtn); + return 1; + } + } + return 0; +} + +static int doGetFields( + CSSM_CL_HANDLE clHand, + const CSSM_DATA &cert, + unsigned loops) +{ + uint32 numFields; + CSSM_FIELD_PTR certFields; + CSSM_RETURN crtn; + + for(unsigned loop=0; loopData); + CSSM_FREE(rawCert); + } + return 0; +} + +typedef enum { + CTO_Parse, + CTO_GetFields, + CTO_GetSomeFields, + CTO_Create, // sign is an option for this one + CTO_Verify +} CT_Op; + +int main(int argc, char **argv) +{ + CSSM_CL_HANDLE clHand; + CSSM_CSP_HANDLE cspHand; + int arg; + int rtn; + char *argp; + unsigned i; + PresetParams params; + CSSM_DATA certData[NUM_PARSED_CERTS]; + + /* user-specificied params */ + CT_Op op; + unsigned loops = 0; + bool doSign = false; + const char *opStr = NULL; + bool rsaBlinding = false; + unsigned keySize = KEYSIZE_DEF; + + if(argc < 3) { + usage(argv); + } + switch(argv[1][0]) { + case 'p': + op = CTO_Parse; + opStr = "Parsed"; + break; + case 'g': + op = CTO_GetFields; + opStr = "Parsed with GetAllFields"; + break; + case 't': + op = CTO_GetSomeFields; + #if CL_KEY_VIA_GET_KEY + opStr = "Parsed with some GetFields and GetKeyInfo"; + #else + opStr = "Parsed with some GetFields"; + #endif + break; + case 'c': + op = CTO_Create; + opStr = "Created"; + break; + case 's': + op = CTO_Create; + opStr = "Created and Signed"; + doSign = true; + break; + case 'v': + op = CTO_Verify; + opStr = "Verified"; + break; + default: + usage(argv); + } + + loops = atoi(argv[2]); + for(arg=3; arg