DoCMMFStuff(char *configdir)
DoCMMFStuff(void)
DoCMMFStuff(char *configdir){    CMMFCertResponse   *certResp=NULL, *certResp2=NULL, *certResponses[3];    CMMFCertRepContent *certRepContent=NULL;    CERTCertificate    *cert=NULL, *caCert=NULL;    CERTCertList       *list=NULL;    PRFileDesc         *fileDesc=NULL;    char                filePath[PATH_LEN];    int                 rv = 0;    long                random;    CMMFKeyRecRepContent       *repContent=NULL;    SECKEYPrivateKey           *privKey = NULL;    SECKEYPublicKey *caPubKey;    SECStatus        srv;    SECItem          fileBits;        certResp = CMMF_CreateCertResponse(0xff123);    CMMF_CertResponseSetPKIStatusInfoStatus(certResp, cmmfGranted);    cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(), personalCert);    if (cert == NULL) {        printf ("Could not find the certificate for %s\n", personalCert);        rv = 416;        goto finish;    }     CMMF_CertResponseSetCertificate(certResp, cert);    certResp2 = CMMF_CreateCertResponse(0xff122);    CMMF_CertResponseSetPKIStatusInfoStatus(certResp2, cmmfGranted);    CMMF_CertResponseSetCertificate(certResp2, cert);        certResponses[0] = certResp;    certResponses[1] = NULL;    certResponses[2] = NULL;    certRepContent = CMMF_CreateCertRepContent();    CMMF_CertRepContentSetCertResponses(certRepContent, certResponses, 1);    list = CERT_GetCertChainFromCert(cert, PR_Now(), certUsageEmailSigner);    CMMF_CertRepContentSetCAPubs(certRepContent, list);    PR_snprintf(filePath, PATH_LEN, "%s/%s", configdir, "CertRepContent.der");    fileDesc = PR_Open (filePath, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 			0666);    if (fileDesc == NULL) {        printf ("Could not open file %s\n", filePath);	rv = 400;	goto finish;    }        srv = CMMF_EncodeCertRepContent(certRepContent, WriteItOut, 				    (void*)fileDesc);    PORT_Assert (srv == SECSuccess);    PR_Close(fileDesc);    rv = DecodeCMMFCertRepContent(filePath);    if (rv != 0) {        goto finish;    }    random = 0xa4e7;    caCert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(), 				     caCertName);    if (caCert == NULL) {        printf ("Could not get the certifcate for %s\n", caCertName);	rv = 411;	goto finish;    }    repContent = CMMF_CreateKeyRecRepContent();    if (repContent == NULL) {        printf ("Could not allocate a CMMFKeyRecRepContent structure\n");	rv = 407;	goto finish;    }    srv = CMMF_KeyRecRepContentSetPKIStatusInfoStatus(repContent, 						      cmmfGrantedWithMods);    if (srv != SECSuccess) {        printf ("Error trying to set PKIStatusInfo for "		"CMMFKeyRecRepContent.\n");	rv = 406;	goto finish;    }    srv = CMMF_KeyRecRepContentSetNewSignCert(repContent, cert);    if (srv != SECSuccess) {        printf ("Error trying to set the new signing certificate for "		"key recovery\n");	rv = 408;	goto finish;    }    srv = CMMF_KeyRecRepContentSetCACerts(repContent, list);    if (srv != SECSuccess) {        printf ("Errory trying to add the list of CA certs to the "		"CMMFKeyRecRepContent structure.\n");	rv = 409;	goto finish;    }    privKey = PK11_FindKeyByAnyCert(cert, NULL);    if (privKey == NULL) {        printf ("Could not get the private key associated with the\n"		"certificate %s\n", personalCert);	rv = 410;	goto finish;    }    caPubKey = CERT_ExtractPublicKey(caCert);    if (caPubKey == NULL) {        printf ("Could not extract the public from the "		"certificate for \n%s\n", caCertName);	rv = 412;	goto finish;    }    CERT_DestroyCertificate(caCert);    caCert = NULL;    srv = CMMF_KeyRecRepContentSetCertifiedKeyPair(repContent, cert, privKey,						   caPubKey);    SECKEY_DestroyPrivateKey(privKey);    SECKEY_DestroyPublicKey(caPubKey);    if (srv != SECSuccess) {        printf ("Could not set the Certified Key Pair\n");	rv = 413;	goto finish;    }    PR_snprintf(filePath, PATH_LEN, "%s/%s", configdir, 		"KeyRecRepContent.der");    fileDesc = PR_Open (filePath, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 			0666);    if (fileDesc == NULL) {        printf ("Could not open file %s\n", filePath);	rv = 414;	goto finish;    }        srv = CMMF_EncodeKeyRecRepContent(repContent, WriteItOut, 				      (void*)fileDesc);    PORT_Assert (srv == SECSuccess);    PR_Close(fileDesc);    CMMF_DestroyKeyRecRepContent(repContent);    GetBitsFromFile(filePath, &fileBits);    repContent =         CMMF_CreateKeyRecRepContentFromDER(db, (const char *) fileBits.data,					   fileBits.len);    if (repContent == NULL) {        printf ("ERROR: CMMF_CreateKeyRecRepContentFromDER failed on file:\n"		"\t%s\n", filePath);	rv = 415;	goto finish;    } finish:    if (repContent) {        CMMF_DestroyKeyRecRepContent(repContent);    }    if (cert) {        CERT_DestroyCertificate(cert);    }    if (list) {        CERT_DestroyCertList(list);    }    if (certResp) {        CMMF_DestroyCertResponse(certResp);    }    if (certResp2) {        CMMF_DestroyCertResponse(certResp2);    }    if (certRepContent) {        CMMF_DestroyCertRepContent(certRepContent);    }    return rv;}