pkixcheck_ParseValidity_tests.cpp (2726B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This code is made available to you under your choice of the following sets 4 * of licensing terms: 5 */ 6 /* This Source Code Form is subject to the terms of the Mozilla Public 7 * License, v. 2.0. If a copy of the MPL was not distributed with this 8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 */ 10 /* Copyright 2014 Mozilla Contributors 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 */ 24 25 #include "pkixgtest.h" 26 27 #include "mozpkix/pkixcheck.h" 28 29 using namespace mozilla::pkix; 30 using namespace mozilla::pkix::test; 31 32 #define OLDER_UTCTIME \ 33 0x17, 13, /* tag, length */ \ 34 '9', '9', '0', '1', '0', '1', /* (19)99-01-01 */ \ 35 '0', '0', '0', '0', '0', '0', 'Z' /* 00:00:00Z */ 36 37 #define NEWER_UTCTIME \ 38 0x17, 13, /* tag, length */ \ 39 '2', '1', '0', '1', '0', '1', /* 2021-01-01 */ \ 40 '0', '0', '0', '0', '0', '0', 'Z' /* 00:00:00Z */ 41 42 static const Time FUTURE_TIME(YMDHMS(2025, 12, 31, 12, 23, 56)); 43 44 class pkixcheck_ParseValidity : public ::testing::Test { }; 45 46 TEST_F(pkixcheck_ParseValidity, BothEmptyNull) 47 { 48 static const uint8_t DER[] = { 49 0x17/*UTCTime*/, 0/*length*/, 50 0x17/*UTCTime*/, 0/*length*/, 51 }; 52 static const Input validity(DER); 53 ASSERT_EQ(Result::ERROR_INVALID_DER_TIME, ParseValidity(validity)); 54 } 55 56 TEST_F(pkixcheck_ParseValidity, NotBeforeEmptyNull) 57 { 58 static const uint8_t DER[] = { 59 0x17/*UTCTime*/, 0x00/*length*/, 60 NEWER_UTCTIME 61 }; 62 static const Input validity(DER); 63 ASSERT_EQ(Result::ERROR_INVALID_DER_TIME, ParseValidity(validity)); 64 } 65 66 TEST_F(pkixcheck_ParseValidity, NotAfterEmptyNull) 67 { 68 static const uint8_t DER[] = { 69 NEWER_UTCTIME, 70 0x17/*UTCTime*/, 0x00/*length*/, 71 }; 72 static const Input validity(DER); 73 ASSERT_EQ(Result::ERROR_INVALID_DER_TIME, ParseValidity(validity)); 74 } 75 76 TEST_F(pkixcheck_ParseValidity, InvalidNotAfterBeforeNotBefore) 77 { 78 static const uint8_t DER[] = { 79 NEWER_UTCTIME, 80 OLDER_UTCTIME, 81 }; 82 static const Input validity(DER); 83 ASSERT_EQ(Result::ERROR_INVALID_DER_TIME, ParseValidity(validity)); 84 }