summaryrefslogtreecommitdiffstats
path: root/security/nss/cmd/tests/dertimetest.c
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /security/nss/cmd/tests/dertimetest.c
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'security/nss/cmd/tests/dertimetest.c')
-rw-r--r--security/nss/cmd/tests/dertimetest.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/security/nss/cmd/tests/dertimetest.c b/security/nss/cmd/tests/dertimetest.c
new file mode 100644
index 000000000..2deedbc06
--- /dev/null
+++ b/security/nss/cmd/tests/dertimetest.c
@@ -0,0 +1,102 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "secder.h"
+#include "secerr.h"
+
+int
+main()
+{
+ SECItem badTime;
+ PRTime prtime;
+ SECStatus rv;
+ int error;
+ PRBool failed = PR_FALSE;
+
+ /* A UTCTime string with an embedded null. */
+ badTime.type = siBuffer;
+ badTime.data = (unsigned char *)"091219000000Z\0junkjunkjunkjunkjunkjunk";
+ badTime.len = 38;
+ rv = DER_UTCTimeToTime(&prtime, &badTime);
+ if (rv == SECSuccess) {
+ fprintf(stderr, "DER_UTCTimeToTime should have failed but "
+ "succeeded\n");
+ failed = PR_TRUE;
+ } else {
+ error = PORT_GetError();
+ if (error != SEC_ERROR_INVALID_TIME) {
+ fprintf(stderr, "DER_UTCTimeToTime failed with error %d, "
+ "expected error %d\n",
+ error, SEC_ERROR_INVALID_TIME);
+ failed = PR_TRUE;
+ }
+ }
+
+ /* A UTCTime string with junk after a valid date/time. */
+ badTime.type = siBuffer;
+ badTime.data = (unsigned char *)"091219000000Zjunk";
+ badTime.len = 17;
+ rv = DER_UTCTimeToTime(&prtime, &badTime);
+ if (rv == SECSuccess) {
+ fprintf(stderr, "DER_UTCTimeToTime should have failed but "
+ "succeeded\n");
+ failed = PR_TRUE;
+ } else {
+ error = PORT_GetError();
+ if (error != SEC_ERROR_INVALID_TIME) {
+ fprintf(stderr, "DER_UTCTimeToTime failed with error %d, "
+ "expected error %d\n",
+ error, SEC_ERROR_INVALID_TIME);
+ failed = PR_TRUE;
+ }
+ }
+
+ /* A GeneralizedTime string with an embedded null. */
+ badTime.type = siBuffer;
+ badTime.data = (unsigned char *)"20091219000000Z\0junkjunkjunkjunkjunkjunk";
+ badTime.len = 40;
+ rv = DER_GeneralizedTimeToTime(&prtime, &badTime);
+ if (rv == SECSuccess) {
+ fprintf(stderr, "DER_GeneralizedTimeToTime should have failed but "
+ "succeeded\n");
+ failed = PR_TRUE;
+ } else {
+ error = PORT_GetError();
+ if (error != SEC_ERROR_INVALID_TIME) {
+ fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, "
+ "expected error %d\n",
+ error, SEC_ERROR_INVALID_TIME);
+ failed = PR_TRUE;
+ }
+ }
+
+ /* A GeneralizedTime string with junk after a valid date/time. */
+ badTime.type = siBuffer;
+ badTime.data = (unsigned char *)"20091219000000Zjunk";
+ badTime.len = 19;
+ rv = DER_GeneralizedTimeToTime(&prtime, &badTime);
+ if (rv == SECSuccess) {
+ fprintf(stderr, "DER_GeneralizedTimeToTime should have failed but "
+ "succeeded\n");
+ failed = PR_TRUE;
+ } else {
+ error = PORT_GetError();
+ if (error != SEC_ERROR_INVALID_TIME) {
+ fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, "
+ "expected error %d\n",
+ error, SEC_ERROR_INVALID_TIME);
+ failed = PR_TRUE;
+ }
+ }
+
+ if (failed) {
+ fprintf(stderr, "FAIL\n");
+ return 1;
+ }
+ printf("PASS\n");
+ return 0;
+}