Example #1
0
int main(){
  IDate& rd1 = createDate(2005,1,6);
  IDate& rd2 = createDate(2005,2,3);
  fn(rd1, rd2);
  delete &rd1;
  delete &rd2;
}//====================================
/*
 * This function uses the date specified by "matchDate" to set up the
 * CrlSelector for a Date match. It is intended to test the case where there
 * is no "smart" database query, so the CertStore should throw an error
 * rather than ask the database for all available CRLs and then filter the
 * results using the selector.
 */
static void
testMatchCrlDate(
    char *dateMatch,
    char *expectedAscii,
    void *plContext)
{
    PKIX_PL_Date *dateCriterion = NULL;
    PKIX_CertStore *crlStore = NULL;
    PKIX_CRLSelector *crlSelector = NULL;
    PKIX_List *crlList = NULL;
    PKIX_CertStore_CRLCallback getCrl = NULL;

    PKIX_TEST_STD_VARS();

    subTest("Searching CRLs for matching Date");

    dateCriterion = createDate(dateMatch, plContext);
    test_makeDateCRLSelector(dateCriterion, &crlSelector, plContext);

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Pk11CertStore_Create(&crlStore, plContext));

    PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertStore_GetCRLCallback(crlStore, &getCrl, plContext));

    PKIX_TEST_EXPECT_ERROR(getCrl(crlStore, crlSelector, NULL, &crlList, plContext));

cleanup:

    PKIX_TEST_DECREF_AC(dateCriterion);
    PKIX_TEST_DECREF_AC(crlStore);
    PKIX_TEST_DECREF_AC(crlSelector);
    PKIX_TEST_DECREF_AC(crlList);

    PKIX_TEST_RETURN();
}
Example #3
0
static void
createDates(char *goodInput, char *diffInput,
                    PKIX_PL_Date **goodDate,
                    PKIX_PL_Date **equalDate,
                    PKIX_PL_Date **diffDate){

        subTest("PKIX_PL_Date_Create <goodDate>");
        *goodDate = createDate(goodInput, plContext);

        subTest("PKIX_PL_Date_Create <equalDate>");
        *equalDate = createDate(goodInput, plContext);

        subTest("PKIX_PL_Date_Create <diffDate>");
        *diffDate = createDate(diffInput, plContext);

}
Example #4
0
Kalender::Kalender(int enStartDato, int enSlutDato)
{
	Dato temp1 = createDate(enStartDato);
	Dato temp2 = createDate(enSlutDato);

	if (temp1.validate() && temp2.validate())
	{
		valid = true;
		insertDates(temp1, temp2);
	}
	else
	{
		cout << "Det er jo en falsk dato!" << endl;
		valid = false;
	}
}
static
void testGetSetCertChainCheckers(
        PKIX_ProcessingParams *goodObject,
        PKIX_ProcessingParams *equalObject){

        PKIX_CertChainChecker *checker = NULL;
        PKIX_List *setCheckersList = NULL;
        PKIX_List *getCheckersList = NULL;
        PKIX_PL_Date *date = NULL;
        char *asciiDate = "040329134847Z";

        PKIX_TEST_STD_VARS();
        subTest("PKIX_ProcessingParams_Get/SetCertChainCheckers");

        date = createDate(asciiDate, plContext);

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertChainChecker_Create
                    (userChecker1cb,
                    PKIX_FALSE,
                    PKIX_FALSE,
                    NULL,
                    (PKIX_PL_Object *) date,
                    &checker,
                    plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_Create
                (&setCheckersList, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_AppendItem
                (setCheckersList, (PKIX_PL_Object *) checker, plContext));
        PKIX_TEST_DECREF_BC(checker);

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_SetCertChainCheckers
                (goodObject, setCheckersList, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_CertChainChecker_Create
                (userChecker1cb,
                PKIX_FALSE,
                PKIX_FALSE,
                NULL,
                (PKIX_PL_Object *) date,
                &checker,
                plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_AddCertChainChecker
                (goodObject, checker, plContext));

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_ProcessingParams_GetCertChainCheckers
                (goodObject, &getCheckersList, plContext));

cleanup:

        PKIX_TEST_DECREF_AC(setCheckersList);
        PKIX_TEST_DECREF_AC(getCheckersList);
        PKIX_TEST_DECREF_AC(date);
        PKIX_TEST_DECREF_BC(checker);

        PKIX_TEST_RETURN();
}
static
void testGetSetDate(
        PKIX_ProcessingParams *goodObject,
        PKIX_ProcessingParams *equalObject){

        PKIX_PL_Date *setDate = NULL;
        PKIX_PL_Date *getDate = NULL;
        char *asciiDate = "040329134847Z";

        PKIX_TEST_STD_VARS();
        subTest("PKIX_ProcessingParams_Get/SetDate");

        setDate = createDate(asciiDate, plContext);

        PKIX_TEST_EXPECT_NO_ERROR
                (PKIX_ProcessingParams_SetDate(goodObject, setDate, plContext));

        PKIX_TEST_EXPECT_NO_ERROR
                (PKIX_ProcessingParams_GetDate
                (goodObject, &getDate, plContext));

        testEqualsHelper((PKIX_PL_Object *)setDate,
                        (PKIX_PL_Object *)getDate,
                        PKIX_TRUE,
                        plContext);

        /* we want to make sure that goodObject and equalObject are "equal" */
        PKIX_TEST_EXPECT_NO_ERROR
                (PKIX_ProcessingParams_SetDate
                (equalObject, setDate, plContext));

cleanup:

        PKIX_TEST_DECREF_AC(setDate);
        PKIX_TEST_DECREF_AC(getDate);

        PKIX_TEST_RETURN();
}
int
test_pk11certstore(int argc, char *argv[])
{

    PKIX_UInt32 j = 0;
    PKIX_UInt32 actualMinorVersion;
    PKIX_PL_Date *validityDate = NULL;
    PKIX_PL_Date *betweenDate = NULL;
    char *crlDir = NULL;
    char *expectedProfAscii = "([\n"
                              "\tVersion:         v3\n"
                              "\tSerialNumber:    00ca\n"
                              "\tIssuer:          CN=chemistry,O=mit,C=us\n"
                              "\tSubject:         CN=prof noall,O=mit,C=us\n"
                              "\tValidity: [From: Fri Feb 11 14:14:06 2005\n"
                              "\t           To:   Mon Jan 18, 2105]\n"
                              "\tSubjectAltNames: (null)\n"
                              "\tAuthorityKeyId:  (null)\n"
                              "\tSubjectKeyId:    (null)\n"
                              "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
                              "\tCritExtOIDs:     (2.5.29.15, 2.5.29.19)\n"
                              "\tExtKeyUsages:    (null)\n"
                              "\tBasicConstraint: CA(6)\n"
                              "\tCertPolicyInfo:  (null)\n"
                              "\tPolicyMappings:  (null)\n"
                              "\tExplicitPolicy:  -1\n"
                              "\tInhibitMapping:  -1\n"
                              "\tInhibitAnyPolicy:-1\n"
                              "\tNameConstraints: (null)\n"
                              "]\n"
                              ", [\n"
                              "\tVersion:         v3\n"
                              "\tSerialNumber:    03\n"
                              "\tIssuer:          CN=physics,O=mit,C=us\n"
                              "\tSubject:         CN=prof noall,O=mit,C=us\n"
                              "\tValidity: [From: Fri Feb 11 12:52:26 2005\n"
                              "\t           To:   Mon Jan 18, 2105]\n"
                              "\tSubjectAltNames: (null)\n"
                              "\tAuthorityKeyId:  (null)\n"
                              "\tSubjectKeyId:    (null)\n"
                              "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
                              "\tCritExtOIDs:     (2.5.29.15, 2.5.29.19)\n"
                              "\tExtKeyUsages:    (null)\n"
                              "\tBasicConstraint: CA(0)\n"
                              "\tCertPolicyInfo:  (null)\n"
                              "\tPolicyMappings:  (null)\n"
                              "\tExplicitPolicy:  -1\n"
                              "\tInhibitMapping:  -1\n"
                              "\tInhibitAnyPolicy:-1\n"
                              "\tNameConstraints: (null)\n"
                              "]\n"
                              ")";
    char *expectedValidityAscii = "([\n"
                                  "\tVersion:         v3\n"
                                  "\tSerialNumber:    03\n"
                                  "\tIssuer:          CN=physics,O=mit,C=us\n"
                                  "\tSubject:         CN=prof noall,O=mit,C=us\n"
                                  "\tValidity: [From: Fri Feb 11 12:52:26 2005\n"
                                  "\t           To:   Mon Jan 18, 2105]\n"
                                  "\tSubjectAltNames: (null)\n"
                                  "\tAuthorityKeyId:  (null)\n"
                                  "\tSubjectKeyId:    (null)\n"
                                  "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
                                  "\tCritExtOIDs:     (2.5.29.15, 2.5.29.19)\n"
                                  "\tExtKeyUsages:    (null)\n"
                                  "\tBasicConstraint: CA(0)\n"
                                  "\tCertPolicyInfo:  (null)\n"
                                  "\tPolicyMappings:  (null)\n"
                                  "\tExplicitPolicy:  -1\n"
                                  "\tInhibitMapping:  -1\n"
                                  "\tInhibitAnyPolicy:-1\n"
                                  "\tNameConstraints: (null)\n"
                                  "]\n"
                                  ")";
    char *expectedMinPathAscii = "([\n"
                                 "\tVersion:         v3\n"
                                 "\tSerialNumber:    01\n"
                                 "\tIssuer:          CN=science,O=mit,C=us\n"
                                 "\tSubject:         CN=science,O=mit,C=us\n"
                                 "\tValidity: [From: Fri Feb 11 12:47:58 2005\n"
                                 "\t           To:   Mon Jan 18, 2105]\n"
                                 "\tSubjectAltNames: (null)\n"
                                 "\tAuthorityKeyId:  (null)\n"
                                 "\tSubjectKeyId:    (null)\n"
                                 "\tSubjPubKeyAlgId: ANSI X9.57 DSA Signature\n"
                                 "\tCritExtOIDs:     (2.5.29.15, 2.5.29.19)\n"
                                 "\tExtKeyUsages:    (null)\n"
                                 "\tBasicConstraint: CA(10)\n"
                                 "\tCertPolicyInfo:  (null)\n"
                                 "\tPolicyMappings:  (null)\n"
                                 "\tExplicitPolicy:  -1\n"
                                 "\tInhibitMapping:  -1\n"
                                 "\tInhibitAnyPolicy:-1\n"
                                 "\tNameConstraints: (null)\n"
                                 "]\n"
                                 ")";
    char *expectedIssuerAscii = "([\n"
                                "\tVersion:         v2\n"
                                "\tIssuer:          CN=physics,O=mit,C=us\n"
                                "\tUpdate:   [Last: Fri Feb 11 13:51:38 2005\n"
                                "\t           Next: Mon Jan 18, 2105]\n"
                                "\tSignatureAlgId:  1.2.840.10040.4.3\n"
                                "\tCRL Number     : (null)\n"
                                "\n"
                                "\tEntry List:      (\n"
                                "\t[\n"
                                "\tSerialNumber:    67\n"
                                "\tReasonCode:      257\n"
                                "\tRevocationDate:  Fri Feb 11 13:51:38 2005\n"
                                "\tCritExtOIDs:     (EMPTY)\n"
                                "\t]\n"
                                "\t)\n"
                                "\n"
                                "\tCritExtOIDs:     (EMPTY)\n"
                                "]\n"
                                ")";
    char *expectedDateAscii = "([\n"
                              "\tVersion:         v2\n"
                              "\tIssuer:          CN=science,O=mit,C=us\n"
                              "\tUpdate:   [Last: Fri Feb 11 13:34:40 2005\n"
                              "\t           Next: Mon Jan 18, 2105]\n"
                              "\tSignatureAlgId:  1.2.840.10040.4.3\n"
                              "\tCRL Number     : (null)\n"
                              "\n"
                              "\tEntry List:      (\n"
                              "\t[\n"
                              "\tSerialNumber:    65\n"
                              "\tReasonCode:      260\n"
                              "\tRevocationDate:  Fri Feb 11 13:34:40 2005\n"
                              "\tCritExtOIDs:     (EMPTY)\n"
                              "\t]\n"
                              "\t)\n"
                              "\n"
                              "\tCritExtOIDs:     (EMPTY)\n"
                              "]\n"
                              ", [\n"
                              "\tVersion:         v2\n"
                              "\tIssuer:          CN=testing CRL,O=test,C=us\n"
                              "\tUpdate:   [Last: Fri Feb 11 13:14:38 2005\n"
                              "\t           Next: Mon Jan 18, 2105]\n"
                              "\tSignatureAlgId:  1.2.840.10040.4.3\n"
                              "\tCRL Number     : (null)\n"
                              "\n"
                              "\tEntry List:      (\n"
                              "\t[\n"
                              "\tSerialNumber:    67\n"
                              "\tReasonCode:      258\n"
                              "\tRevocationDate:  Fri Feb 11 13:14:38 2005\n"
                              "\tCritExtOIDs:     (EMPTY)\n"
                              "\t]\n"
                              "\t)\n"
                              "\n"
                              "\tCritExtOIDs:     (EMPTY)\n"
                              "]\n"
                              ")";

    PKIX_TEST_STD_VARS();

    startTests("Pk11CertStore");

    if (argc < 3) {
        printUsage(argv[0]);
        return (0);
    }

    PKIX_TEST_EXPECT_NO_ERROR(
        PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));

    crlDir = argv[j + 2];

    /* Two certs for prof should be valid now */
    PKIX_TEST_EXPECT_NO_ERROR(pkix_pl_Date_CreateFromPRTime(PR_Now(), &validityDate, plContext));

    subTest("Searching Certs for Subject");

    testMatchCertSubject(crlDir,
                         "phy2prof.crt",
                         NULL, /* expectedProfAscii, */
                         validityDate,
                         plContext);

    /* One of the certs was not yet valid at this time. */
    betweenDate = createDate("050210184000Z", plContext);

    subTest("Searching Certs for Subject and Validity");

    testMatchCertSubject(crlDir,
                         "phy2prof.crt",
                         NULL, /* expectedValidityAscii, */
                         betweenDate,
                         plContext);

    testMatchCertMinPath(9,
                         NULL, /* expectedMinPathAscii, */
                         plContext);

    testMatchCrlIssuer(crlDir,
                       "phys.crl",
                       NULL, /* expectedIssuerAscii, */
                       plContext);

    testMatchCrlDate("050211184000Z",
                     NULL, /* expectedDateAscii, */
                     plContext);

cleanup:

    PKIX_TEST_DECREF_AC(validityDate);
    PKIX_TEST_DECREF_AC(betweenDate);

    PKIX_TEST_RETURN();

    endTests("Pk11CertStore");

    return (0);
}