/security/nss/cmd/libpkix/pkix/results/test_verifynode.c

http://github.com/zpao/v8monkey · C · 153 lines · 77 code · 31 blank · 45 comment · 1 complexity · 48b4e668266a66792bbedc2c0b87193c MD5 · raw file

  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. *
  4. * The contents of this file are subject to the Mozilla Public License Version
  5. * 1.1 (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. * http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an "AS IS" basis,
  10. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. * for the specific language governing rights and limitations under the
  12. * License.
  13. *
  14. * The Original Code is the PKIX-C library.
  15. *
  16. * The Initial Developer of the Original Code is
  17. * Sun Microsystems, Inc.
  18. * Portions created by the Initial Developer are
  19. * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
  20. *
  21. * Contributor(s):
  22. * Sun Microsystems, Inc.
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /*
  38. * test_verifynode.c
  39. *
  40. * Test VerifyNode Type
  41. *
  42. */
  43. #include "testutil.h"
  44. #include "testutil_nss.h"
  45. static void *plContext = NULL;
  46. static
  47. void printUsage(void) {
  48. (void) printf("\nUSAGE:\ttest_verifynode path cert1 cert2 cert3\n\n");
  49. }
  50. int test_verifynode(int argc, char *argv[]) {
  51. /*
  52. * Create a tree with parent = cert1, child=cert2, grandchild=cert3
  53. */
  54. PKIX_PL_Cert *cert1 = NULL;
  55. PKIX_PL_Cert *cert2 = NULL;
  56. PKIX_PL_Cert *cert3 = NULL;
  57. PKIX_VerifyNode *parentNode = NULL;
  58. PKIX_VerifyNode *childNode = NULL;
  59. PKIX_VerifyNode *grandChildNode = NULL;
  60. PKIX_PL_String *parentString = NULL;
  61. PKIX_UInt32 actualMinorVersion;
  62. PKIX_UInt32 j = 0;
  63. char *dirName = NULL;
  64. char *twoNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Cert"
  65. "ificates,C=US, Subject:CN=Trust Anchor,O=Test Certif"
  66. "icates,C=US], depth=0, error=(null)\n. CERT[Issuer:C"
  67. "N=Trust Anchor,O=Test Certificates,C=US, Subject:CN="
  68. "Good CA,O=Test Certificates,C=US], depth=1, error=(null)";
  69. char *threeNodeAscii = "CERT[Issuer:CN=Trust Anchor,O=Test Ce"
  70. "rtificates,C=US, Subject:CN=Trust Anchor,O=Test Cert"
  71. "ificates,C=US], depth=0, error=(null)\n. CERT[Issuer"
  72. ":CN=Trust Anchor,O=Test Certificates,C=US, Subject:C"
  73. "N=Good CA,O=Test Certificates,C=US], depth=1, error="
  74. "(null)\n. . CERT[Issuer:CN=Good CA,O=Test Certificat"
  75. "es,C=US, Subject:CN=Valid EE Certificate Test1,O=Tes"
  76. "t Certificates,C=US], depth=2, error=(null)";
  77. PKIX_TEST_STD_VARS();
  78. if (argc < 3) {
  79. printUsage();
  80. return (0);
  81. }
  82. startTests("VerifyNode");
  83. PKIX_TEST_EXPECT_NO_ERROR(
  84. PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
  85. dirName = argv[++j];
  86. subTest("Creating Certs");
  87. cert1 = createCert
  88. (dirName, argv[++j], plContext);
  89. cert2 = createCert
  90. (dirName, argv[++j], plContext);
  91. cert3 = createCert
  92. (dirName, argv[++j], plContext);
  93. subTest("Creating VerifyNode objects");
  94. PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
  95. (cert1, 0, NULL, &parentNode, plContext));
  96. PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
  97. (cert2, 1, NULL, &childNode, plContext));
  98. PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_Create
  99. (cert3, 2, NULL, &grandChildNode, plContext));
  100. PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain
  101. (parentNode, childNode, plContext));
  102. subTest("Creating VerifyNode ToString objects");
  103. testToStringHelper
  104. ((PKIX_PL_Object *)parentNode, twoNodeAscii, plContext);
  105. PKIX_TEST_EXPECT_NO_ERROR(pkix_VerifyNode_AddToChain
  106. (parentNode, grandChildNode, plContext));
  107. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Object_ToString
  108. ((PKIX_PL_Object*)parentNode, &parentString, plContext));
  109. (void) printf("parentNode is\n\t%s\n", parentString->escAsciiString);
  110. testToStringHelper
  111. ((PKIX_PL_Object *)parentNode, threeNodeAscii, plContext);
  112. cleanup:
  113. PKIX_TEST_DECREF_AC(cert1);
  114. PKIX_TEST_DECREF_AC(cert2);
  115. PKIX_TEST_DECREF_AC(parentNode);
  116. PKIX_TEST_DECREF_AC(childNode);
  117. PKIX_TEST_DECREF_AC(parentString);
  118. PKIX_Shutdown(plContext);
  119. PKIX_TEST_RETURN();
  120. endTests("VerifyNode");
  121. return (0);
  122. }