Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include <stdio.h> |
michael@0 | 6 | #include <stdlib.h> |
michael@0 | 7 | |
michael@0 | 8 | #include "secder.h" |
michael@0 | 9 | #include "secerr.h" |
michael@0 | 10 | |
michael@0 | 11 | int main() |
michael@0 | 12 | { |
michael@0 | 13 | SECItem badTime; |
michael@0 | 14 | PRTime prtime; |
michael@0 | 15 | SECStatus rv; |
michael@0 | 16 | int error; |
michael@0 | 17 | PRBool failed = PR_FALSE; |
michael@0 | 18 | |
michael@0 | 19 | /* A UTCTime string with an embedded null. */ |
michael@0 | 20 | badTime.type = siBuffer; |
michael@0 | 21 | badTime.data = (unsigned char *)"091219000000Z\0junkjunkjunkjunkjunkjunk"; |
michael@0 | 22 | badTime.len = 38; |
michael@0 | 23 | rv = DER_UTCTimeToTime(&prtime, &badTime); |
michael@0 | 24 | if (rv == SECSuccess) { |
michael@0 | 25 | fprintf(stderr, "DER_UTCTimeToTime should have failed but " |
michael@0 | 26 | "succeeded\n"); |
michael@0 | 27 | failed = PR_TRUE; |
michael@0 | 28 | } else { |
michael@0 | 29 | error = PORT_GetError(); |
michael@0 | 30 | if (error != SEC_ERROR_INVALID_TIME) { |
michael@0 | 31 | fprintf(stderr, "DER_UTCTimeToTime failed with error %d, " |
michael@0 | 32 | "expected error %d\n", error, SEC_ERROR_INVALID_TIME); |
michael@0 | 33 | failed = PR_TRUE; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | /* A UTCTime string with junk after a valid date/time. */ |
michael@0 | 38 | badTime.type = siBuffer; |
michael@0 | 39 | badTime.data = (unsigned char *)"091219000000Zjunk"; |
michael@0 | 40 | badTime.len = 17; |
michael@0 | 41 | rv = DER_UTCTimeToTime(&prtime, &badTime); |
michael@0 | 42 | if (rv == SECSuccess) { |
michael@0 | 43 | fprintf(stderr, "DER_UTCTimeToTime should have failed but " |
michael@0 | 44 | "succeeded\n"); |
michael@0 | 45 | failed = PR_TRUE; |
michael@0 | 46 | } else { |
michael@0 | 47 | error = PORT_GetError(); |
michael@0 | 48 | if (error != SEC_ERROR_INVALID_TIME) { |
michael@0 | 49 | fprintf(stderr, "DER_UTCTimeToTime failed with error %d, " |
michael@0 | 50 | "expected error %d\n", error, SEC_ERROR_INVALID_TIME); |
michael@0 | 51 | failed = PR_TRUE; |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | /* A GeneralizedTime string with an embedded null. */ |
michael@0 | 56 | badTime.type = siBuffer; |
michael@0 | 57 | badTime.data = (unsigned char *)"20091219000000Z\0junkjunkjunkjunkjunkjunk"; |
michael@0 | 58 | badTime.len = 40; |
michael@0 | 59 | rv = DER_GeneralizedTimeToTime(&prtime, &badTime); |
michael@0 | 60 | if (rv == SECSuccess) { |
michael@0 | 61 | fprintf(stderr, "DER_GeneralizedTimeToTime should have failed but " |
michael@0 | 62 | "succeeded\n"); |
michael@0 | 63 | failed = PR_TRUE; |
michael@0 | 64 | } else { |
michael@0 | 65 | error = PORT_GetError(); |
michael@0 | 66 | if (error != SEC_ERROR_INVALID_TIME) { |
michael@0 | 67 | fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, " |
michael@0 | 68 | "expected error %d\n", error, SEC_ERROR_INVALID_TIME); |
michael@0 | 69 | failed = PR_TRUE; |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | /* A GeneralizedTime string with junk after a valid date/time. */ |
michael@0 | 74 | badTime.type = siBuffer; |
michael@0 | 75 | badTime.data = (unsigned char *)"20091219000000Zjunk"; |
michael@0 | 76 | badTime.len = 19; |
michael@0 | 77 | rv = DER_GeneralizedTimeToTime(&prtime, &badTime); |
michael@0 | 78 | if (rv == SECSuccess) { |
michael@0 | 79 | fprintf(stderr, "DER_GeneralizedTimeToTime should have failed but " |
michael@0 | 80 | "succeeded\n"); |
michael@0 | 81 | failed = PR_TRUE; |
michael@0 | 82 | } else { |
michael@0 | 83 | error = PORT_GetError(); |
michael@0 | 84 | if (error != SEC_ERROR_INVALID_TIME) { |
michael@0 | 85 | fprintf(stderr, "DER_GeneralizedTimeToTime failed with error %d, " |
michael@0 | 86 | "expected error %d\n", error, SEC_ERROR_INVALID_TIME); |
michael@0 | 87 | failed = PR_TRUE; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | if (failed) { |
michael@0 | 92 | fprintf(stderr, "FAIL\n"); |
michael@0 | 93 | return 1; |
michael@0 | 94 | } |
michael@0 | 95 | printf("PASS\n"); |
michael@0 | 96 | return 0; |
michael@0 | 97 | } |