2012-10-01 22:02:15 +04:00
|
|
|
/* 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/. */
|
2010-02-07 14:54:28 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "secder.h"
|
|
|
|
#include "secerr.h"
|
|
|
|
|
2016-04-27 15:51:59 +03:00
|
|
|
int
|
|
|
|
main()
|
2010-02-07 14:54:28 +03:00
|
|
|
{
|
|
|
|
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 "
|
2016-04-27 15:51:59 +03:00
|
|
|
"succeeded\n");
|
2010-02-07 14:54:28 +03:00
|
|
|
failed = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
error = PORT_GetError();
|
|
|
|
if (error != SEC_ERROR_INVALID_TIME) {
|
|
|
|
fprintf(stderr, "DER_UTCTimeToTime failed with error %d, "
|
2016-04-27 15:51:59 +03:00
|
|
|
"expected error %d\n",
|
|
|
|
error, SEC_ERROR_INVALID_TIME);
|
2010-02-07 14:54:28 +03:00
|
|
|
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 "
|
2016-04-27 15:51:59 +03:00
|
|
|
"succeeded\n");
|
2010-02-07 14:54:28 +03:00
|
|
|
failed = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
error = PORT_GetError();
|
|
|
|
if (error != SEC_ERROR_INVALID_TIME) {
|
|
|
|
fprintf(stderr, "DER_UTCTimeToTime failed with error %d, "
|
2016-04-27 15:51:59 +03:00
|
|
|
"expected error %d\n",
|
|
|
|
error, SEC_ERROR_INVALID_TIME);
|
2010-02-07 14:54:28 +03:00
|
|
|
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 "
|
2016-04-27 15:51:59 +03:00
|
|
|
"succeeded\n");
|
2010-02-07 14:54:28 +03:00
|
|
|
failed = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
error = PORT_GetError();
|
|
|
|
if (error != SEC_ERROR_INVALID_TIME) {
|
|
|
|
fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, "
|
2016-04-27 15:51:59 +03:00
|
|
|
"expected error %d\n",
|
|
|
|
error, SEC_ERROR_INVALID_TIME);
|
2010-02-07 14:54:28 +03:00
|
|
|
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 "
|
2016-04-27 15:51:59 +03:00
|
|
|
"succeeded\n");
|
2010-02-07 14:54:28 +03:00
|
|
|
failed = PR_TRUE;
|
|
|
|
} else {
|
|
|
|
error = PORT_GetError();
|
|
|
|
if (error != SEC_ERROR_INVALID_TIME) {
|
|
|
|
fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, "
|
2016-04-27 15:51:59 +03:00
|
|
|
"expected error %d\n",
|
|
|
|
error, SEC_ERROR_INVALID_TIME);
|
2010-02-07 14:54:28 +03:00
|
|
|
failed = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failed) {
|
|
|
|
fprintf(stderr, "FAIL\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
printf("PASS\n");
|
|
|
|
return 0;
|
|
|
|
}
|