test_verifynode.c (3634B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 /* 5 * test_verifynode.c 6 * 7 * Test VerifyNode Type 8 * 9 */ 10 11 #include "testutil.h" 12 #include "testutil_nss.h" 13 14 static void *plContext = NULL; 15 16 static void 17 printUsage(void) 18 { 19 (void)printf("\nUSAGE:\ttest_verifynode path cert1 cert2 cert3\n\n"); 20 } 21 22 int 23 test_verifynode(int argc, char *argv[]) 24 { 25 26 /* 27 * Create a tree with parent = cert1, child=cert2, grandchild=cert3 28 */ 29 PKIX_PL_Cert *cert1 = NULL; 30 PKIX_PL_Cert *cert2 = NULL; 31 PKIX_PL_Cert *cert3 = NULL; 32 PKIX_VerifyNode *parentNode = NULL; 33 PKIX_VerifyNode *childNode = NULL; 34 PKIX_VerifyNode *grandChildNode = NULL; 35 PKIX_PL_String *parentString = NULL; 36 37 PKIX_UInt32 actualMinorVersion; 38 PKIX_UInt32 j = 0; 39 char *dirName = NULL; 40 char *twoNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Cert" 41 "ificates,C=US, Subject:CN=Trust Anchor,O=Test Certif" 42 "icates,C=US], depth=0, error=(null)\n. CERT[Issuer:C" 43 "N=Trust Anchor,O=Test Certificates,C=US, Subject:CN=" 44 "Good CA,O=Test Certificates,C=US], depth=1, error=(null)"; 45 char *threeNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Ce" 46 "rtificates,C=US, Subject:CN=Trust Anchor,O=Test Cert" 47 "ificates,C=US], depth=0, error=(null)\n. CERT[Issuer" 48 ":CN=Trust Anchor,O=Test Certificates,C=US, Subject:C" 49 "N=Good CA,O=Test Certificates,C=US], depth=1, error=" 50 "(null)\n. . CERT[Issuer:CN=Good CA,O=Test Certificat" 51 "es,C=US, Subject:CN=Valid EE Certificate Test1,O=Tes" 52 "t Certificates,C=US], depth=2, error=(null)"; 53 54 PKIX_TEST_STD_VARS(); 55 56 if (argc < 3) { 57 printUsage(); 58 return (0); 59 } 60 61 startTests("VerifyNode"); 62 63 PKIX_TEST_EXPECT_NO_ERROR( 64 PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext)); 65 66 dirName = argv[++j]; 67 68 subTest("Creating Certs"); 69 70 cert1 = createCert(dirName, argv[++j], plContext); 71 72 cert2 = createCert(dirName, argv[++j], plContext); 73 74 cert3 = createCert(dirName, argv[++j], plContext); 75 76 subTest("Creating VerifyNode objects"); 77 78 PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create(cert1, 0, NULL, &parentNode, plContext)); 79 80 PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create(cert2, 1, NULL, &childNode, plContext)); 81 82 PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create(cert3, 2, NULL, &grandChildNode, plContext)); 83 84 PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain(parentNode, childNode, plContext)); 85 86 subTest("Creating VerifyNode ToString objects"); 87 88 testToStringHelper((PKIX_PL_Object *)parentNode, twoNodeAscii, plContext); 89 90 PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain(parentNode, grandChildNode, plContext)); 91 92 PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString((PKIX_PL_Object *)parentNode, &parentString, plContext)); 93 (void)printf("parentNode is\n\t%s\n", parentString->escAsciiString); 94 95 testToStringHelper((PKIX_PL_Object *)parentNode, threeNodeAscii, plContext); 96 97 cleanup: 98 99 PKIX_TEST_DECREF_AC(cert1); 100 PKIX_TEST_DECREF_AC(cert2); 101 PKIX_TEST_DECREF_AC(parentNode); 102 PKIX_TEST_DECREF_AC(childNode); 103 PKIX_TEST_DECREF_AC(parentString); 104 105 PKIX_Shutdown(plContext); 106 107 PKIX_TEST_RETURN(); 108 109 endTests("VerifyNode"); 110 111 return (0); 112 }