/security/nss/cmd/libpkix/pkix_pl/pki/test_crlentry.c

http://github.com/zpao/v8monkey · C · 244 lines · 149 code · 51 blank · 44 comment · 5 complexity · f7bf0e44779b6abe3da77aa8c5b62eac 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_crlentry.c
  39. *
  40. * Test CRLENTRY Type
  41. *
  42. */
  43. #include "testutil.h"
  44. #include "testutil_nss.h"
  45. static void *plContext = NULL;
  46. static
  47. void createCRLEntries(
  48. char *dataDir,
  49. char *crlInput,
  50. PKIX_PL_CRL **pCrl,
  51. PKIX_PL_CRLEntry **goodObject,
  52. PKIX_PL_CRLEntry **equalObject,
  53. PKIX_PL_CRLEntry **diffObject)
  54. {
  55. PKIX_PL_CRL *crl = NULL;
  56. PKIX_PL_BigInt *firstSNBigInt = NULL;
  57. PKIX_PL_BigInt *secondSNBigInt = NULL;
  58. PKIX_PL_String *firstSNString = NULL;
  59. PKIX_PL_String *secondSNString = NULL;
  60. char *firstSNAscii = "010932";
  61. char *secondSNAscii = "3039";
  62. PKIX_TEST_STD_VARS();
  63. subTest("PKIX_PL_CRL_Create <crl>");
  64. crl = createCRL(dataDir, crlInput, plContext);
  65. subTest("PKIX_PL_CRL_GetCRLEntryForSerialNumber");
  66. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
  67. PKIX_ESCASCII,
  68. firstSNAscii,
  69. PL_strlen(firstSNAscii),
  70. &firstSNString,
  71. plContext));
  72. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
  73. firstSNString,
  74. &firstSNBigInt,
  75. plContext));
  76. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
  77. crl, firstSNBigInt, goodObject, plContext));
  78. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
  79. crl, firstSNBigInt, equalObject, plContext));
  80. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_String_Create(
  81. PKIX_ESCASCII,
  82. secondSNAscii,
  83. PL_strlen(secondSNAscii),
  84. &secondSNString,
  85. plContext));
  86. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_BigInt_Create(
  87. secondSNString,
  88. &secondSNBigInt,
  89. plContext));
  90. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRL_GetCRLEntryForSerialNumber(
  91. crl, secondSNBigInt, diffObject, plContext));
  92. *pCrl = crl;
  93. cleanup:
  94. PKIX_TEST_DECREF_AC(firstSNBigInt);
  95. PKIX_TEST_DECREF_AC(secondSNBigInt);
  96. PKIX_TEST_DECREF_AC(firstSNString);
  97. PKIX_TEST_DECREF_AC(secondSNString);
  98. PKIX_TEST_RETURN();
  99. }
  100. static void testGetReasonCode(
  101. PKIX_PL_CRLEntry *goodObject)
  102. {
  103. PKIX_Int32 reasonCode = 0;
  104. PKIX_Int32 expectedReasonCode = 260;
  105. PKIX_TEST_STD_VARS();
  106. subTest("PKIX_PL_CRLEntry_GetCRLEntryReasonCode");
  107. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCRLEntryReasonCode(
  108. goodObject, &reasonCode, plContext));
  109. if (reasonCode != expectedReasonCode) {
  110. testError("unexpected value of CRL Entry Reason Code");
  111. (void) printf("Actual value:\t%d\n", reasonCode);
  112. (void) printf("Expected value:\t%d\n", expectedReasonCode);
  113. goto cleanup;
  114. }
  115. cleanup:
  116. PKIX_TEST_RETURN();
  117. }
  118. static void
  119. testCritExtensionsAbsent(PKIX_PL_CRLEntry *crlEntry)
  120. {
  121. PKIX_List *oidList = NULL;
  122. PKIX_UInt32 numOids = 0;
  123. PKIX_TEST_STD_VARS();
  124. PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_CRLEntry_GetCriticalExtensionOIDs
  125. (crlEntry, &oidList, plContext));
  126. PKIX_TEST_EXPECT_NO_ERROR(PKIX_List_GetLength
  127. (oidList, &numOids, plContext));
  128. if (numOids != 0){
  129. pkixTestErrorMsg = "unexpected mismatch";
  130. }
  131. cleanup:
  132. PKIX_TEST_DECREF_AC(oidList);
  133. PKIX_TEST_RETURN();
  134. }
  135. static void
  136. testGetCriticalExtensionOIDs(PKIX_PL_CRLEntry *goodObject)
  137. {
  138. subTest("PKIX_PL_CRL_GetCriticalExtensionOIDs "
  139. "<CritExtensionsAbsent>");
  140. testCritExtensionsAbsent(goodObject);
  141. }
  142. static
  143. void printUsage(void) {
  144. (void) printf("\nUSAGE:\ttest_crlentry <data-dir>\n\n");
  145. }
  146. /* Functional tests for CRLENTRY public functions */
  147. int test_crlentry(int argc, char *argv[]) {
  148. PKIX_PL_CRL *crl = NULL;
  149. PKIX_PL_CRLEntry *goodObject = NULL;
  150. PKIX_PL_CRLEntry *equalObject = NULL;
  151. PKIX_PL_CRLEntry *diffObject = NULL;
  152. PKIX_UInt32 actualMinorVersion;
  153. PKIX_UInt32 j = 0;
  154. char *dataDir = NULL;
  155. char *goodInput = "crlgood.crl";
  156. char *expectedAscii =
  157. "\n\t[\n"
  158. "\tSerialNumber: 010932\n"
  159. "\tReasonCode: 260\n"
  160. "\tRevocationDate: Fri Jan 07 15:09:10 2005\n"
  161. "\tCritExtOIDs: (EMPTY)\n"
  162. "\t]\n\t";
  163. /* Note XXX serialnumber and reasoncode need debug */
  164. PKIX_TEST_STD_VARS();
  165. startTests("CRLEntry");
  166. PKIX_TEST_EXPECT_NO_ERROR(
  167. PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));
  168. if (argc < 1+j) {
  169. printUsage();
  170. return (0);
  171. }
  172. dataDir = argv[1+j];
  173. createCRLEntries
  174. (dataDir, goodInput, &crl, &goodObject, &equalObject, &diffObject);
  175. PKIX_TEST_EQ_HASH_TOSTR_DUP
  176. (goodObject,
  177. equalObject,
  178. diffObject,
  179. NULL, /* expectedAscii, */
  180. CRLENTRY,
  181. PKIX_TRUE);
  182. testGetReasonCode(goodObject);
  183. testGetCriticalExtensionOIDs(goodObject);
  184. cleanup:
  185. PKIX_TEST_DECREF_AC(crl);
  186. PKIX_TEST_DECREF_AC(goodObject);
  187. PKIX_TEST_DECREF_AC(equalObject);
  188. PKIX_TEST_DECREF_AC(diffObject);
  189. PKIX_Shutdown(plContext);
  190. PKIX_TEST_RETURN();
  191. endTests("CRLEntry");
  192. return (0);
  193. }