Skip to content

Latest commit

 

History

History
128 lines (110 loc) · 4.55 KB

pkixcheck_CheckValidity_tests.cpp

File metadata and controls

128 lines (110 loc) · 4.55 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This code is made available to you under your choice of the following sets
* of licensing terms:
*/
/* 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/.
*/
/* Copyright 2014 Mozilla Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Feb 7, 2015
Feb 7, 2015
25
#include "pkixgtest.h"
Aug 3, 2018
Aug 3, 2018
27
28
#include "mozpkix/pkixcheck.h"
29
30
31
using namespace mozilla::pkix;
using namespace mozilla::pkix::test;
Aug 2, 2014
Aug 2, 2014
32
static const Time PAST_TIME(YMDHMS(1998, 12, 31, 12, 23, 56));
33
34
35
36
37
38
39
40
41
42
43
#define OLDER_GENERALIZEDTIME \
0x18, 15, /* tag, length */ \
'1', '9', '9', '9', '0', '1', '0', '1', /* 1999-01-01 */ \
'0', '0', '0', '0', '0', '0', 'Z' /* 00:00:00Z */
#define OLDER_UTCTIME \
0x17, 13, /* tag, length */ \
'9', '9', '0', '1', '0', '1', /* (19)99-01-01 */ \
'0', '0', '0', '0', '0', '0', 'Z' /* 00:00:00Z */
Aug 2, 2014
Aug 2, 2014
44
static const Time NOW(YMDHMS(2016, 12, 31, 12, 23, 56));
45
46
47
48
49
50
51
52
53
54
55
#define NEWER_GENERALIZEDTIME \
0x18, 15, /* tag, length */ \
'2', '0', '2', '1', '0', '1', '0', '1', /* 2021-01-01 */ \
'0', '0', '0', '0', '0', '0', 'Z' /* 00:00:00Z */
#define NEWER_UTCTIME \
0x17, 13, /* tag, length */ \
'2', '1', '0', '1', '0', '1', /* 2021-01-01 */ \
'0', '0', '0', '0', '0', '0', 'Z' /* 00:00:00Z */
Aug 2, 2014
Aug 2, 2014
56
static const Time FUTURE_TIME(YMDHMS(2025, 12, 31, 12, 23, 56));
Jul 18, 2014
Jul 18, 2014
58
class pkixcheck_CheckValidity : public ::testing::Test { };
59
60
61
62
63
static const uint8_t OLDER_UTCTIME_NEWER_UTCTIME_DATA[] = {
OLDER_UTCTIME,
NEWER_UTCTIME,
};
Jul 31, 2014
Jul 31, 2014
64
static const Input
Jul 19, 2014
Jul 19, 2014
65
OLDER_UTCTIME_NEWER_UTCTIME(OLDER_UTCTIME_NEWER_UTCTIME_DATA);
66
67
68
TEST_F(pkixcheck_CheckValidity, Valid_UTCTIME_UTCTIME)
{
Sep 11, 2015
Sep 11, 2015
69
70
71
72
static Time notBefore(Time::uninitialized);
static Time notAfter(Time::uninitialized);
ASSERT_EQ(Success, ParseValidity(OLDER_UTCTIME_NEWER_UTCTIME, &notBefore, &notAfter));
ASSERT_EQ(Success, CheckValidity(NOW, notBefore, notAfter));
73
74
75
76
77
78
79
80
}
TEST_F(pkixcheck_CheckValidity, Valid_GENERALIZEDTIME_GENERALIZEDTIME)
{
static const uint8_t DER[] = {
OLDER_GENERALIZEDTIME,
NEWER_GENERALIZEDTIME,
};
Jul 31, 2014
Jul 31, 2014
81
static const Input validity(DER);
Sep 11, 2015
Sep 11, 2015
82
83
84
85
static Time notBefore(Time::uninitialized);
static Time notAfter(Time::uninitialized);
ASSERT_EQ(Success, ParseValidity(validity, &notBefore, &notAfter));
ASSERT_EQ(Success, CheckValidity(NOW, notBefore, notAfter));
86
87
88
89
90
91
92
93
}
TEST_F(pkixcheck_CheckValidity, Valid_GENERALIZEDTIME_UTCTIME)
{
static const uint8_t DER[] = {
OLDER_GENERALIZEDTIME,
NEWER_UTCTIME,
};
Jul 31, 2014
Jul 31, 2014
94
static const Input validity(DER);
Sep 11, 2015
Sep 11, 2015
95
96
97
98
static Time notBefore(Time::uninitialized);
static Time notAfter(Time::uninitialized);
ASSERT_EQ(Success, ParseValidity(validity, &notBefore, &notAfter));
ASSERT_EQ(Success, CheckValidity(NOW, notBefore, notAfter));
99
100
101
102
103
104
105
106
}
TEST_F(pkixcheck_CheckValidity, Valid_UTCTIME_GENERALIZEDTIME)
{
static const uint8_t DER[] = {
OLDER_UTCTIME,
NEWER_GENERALIZEDTIME,
};
Jul 31, 2014
Jul 31, 2014
107
static const Input validity(DER);
Sep 11, 2015
Sep 11, 2015
108
109
110
111
static Time notBefore(Time::uninitialized);
static Time notAfter(Time::uninitialized);
ASSERT_EQ(Success, ParseValidity(validity, &notBefore, &notAfter));
ASSERT_EQ(Success, CheckValidity(NOW, notBefore, notAfter));
112
113
114
115
}
TEST_F(pkixcheck_CheckValidity, InvalidBeforeNotBefore)
{
Sep 11, 2015
Sep 11, 2015
116
117
118
119
static Time notBefore(Time::uninitialized);
static Time notAfter(Time::uninitialized);
ASSERT_EQ(Success, ParseValidity(OLDER_UTCTIME_NEWER_UTCTIME, &notBefore, &notAfter));
ASSERT_EQ(Result::ERROR_NOT_YET_VALID_CERTIFICATE, CheckValidity(PAST_TIME, notBefore, notAfter));
120
121
122
123
}
TEST_F(pkixcheck_CheckValidity, InvalidAfterNotAfter)
{
Sep 11, 2015
Sep 11, 2015
124
125
126
127
static Time notBefore(Time::uninitialized);
static Time notAfter(Time::uninitialized);
ASSERT_EQ(Success, ParseValidity(OLDER_UTCTIME_NEWER_UTCTIME, &notBefore, &notAfter));
ASSERT_EQ(Result::ERROR_EXPIRED_CERTIFICATE, CheckValidity(FUTURE_TIME, notBefore, notAfter));