pkixcheck_CheckIssuer_tests.cpp (3396B)
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 2016 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 class pkixcheck_CheckIssuer : public ::testing::Test { }; 33 34 static const uint8_t EMPTY_NAME_DATA[] = { 35 0x30, 0x00 /* tag, length */ 36 }; 37 static const Input EMPTY_NAME(EMPTY_NAME_DATA); 38 39 static const uint8_t VALID_NAME_DATA[] = { 40 /* From https://www.example.com/: C=US, O=DigiCert Inc, OU=www.digicert.com, 41 * CN=DigiCert SHA2 High Assurance Server CA */ 42 0x30, 0x70, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 43 0x02, 0x55, 0x53, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 44 0x13, 0x0C, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, 0x72, 0x74, 0x20, 0x49, 45 0x6E, 0x63, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 46 0x10, 0x77, 0x77, 0x77, 0x2E, 0x64, 0x69, 0x67, 0x69, 0x63, 0x65, 0x72, 47 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x31, 0x2F, 0x30, 0x2D, 0x06, 0x03, 0x55, 48 0x04, 0x03, 0x13, 0x26, 0x44, 0x69, 0x67, 0x69, 0x43, 0x65, 0x72, 0x74, 49 0x20, 0x53, 0x48, 0x41, 0x32, 0x20, 0x48, 0x69, 0x67, 0x68, 0x20, 0x41, 50 0x73, 0x73, 0x75, 0x72, 0x61, 0x6E, 0x63, 0x65, 0x20, 0x53, 0x65, 0x72, 51 0x76, 0x65, 0x72, 0x20, 0x43, 0x41 52 }; 53 static const Input VALID_NAME(VALID_NAME_DATA); 54 55 TEST_F(pkixcheck_CheckIssuer, ValidIssuer) 56 { 57 ASSERT_EQ(Success, CheckIssuer(VALID_NAME)); 58 } 59 60 TEST_F(pkixcheck_CheckIssuer, EmptyIssuer) 61 { 62 ASSERT_EQ(Result::ERROR_EMPTY_ISSUER_NAME, CheckIssuer(EMPTY_NAME)); 63 } 64 65 TEST_F(pkixcheck_CheckIssuer, TrailingData) 66 { 67 static const uint8_t validNameData[] = { 68 0x30/*SEQUENCE*/, 0x02/*LENGTH=2*/, 69 0x31, 0x00 // the contents of the sequence aren't validated 70 }; 71 static const Input validName(validNameData); 72 ASSERT_EQ(Success, CheckIssuer(validName)); 73 74 static const uint8_t trailingDataData[] = { 75 0x30/*SEQUENCE*/, 0x02/*LENGTH=2*/, 76 0x31, 0x00, // the contents of the sequence aren't validated 77 0x77 // trailing data is invalid 78 }; 79 static const Input trailingData(trailingDataData); 80 ASSERT_EQ(Result::ERROR_BAD_DER, CheckIssuer(trailingData)); 81 } 82 83 TEST_F(pkixcheck_CheckIssuer, InvalidContents) 84 { 85 static const uint8_t invalidContentsData[] = { 86 0x31/*SET (should be SEQUENCE)*/, 0x02/*LENGTH=2*/, 87 0x31, 0x00 88 }; 89 static const Input invalidContents(invalidContentsData); 90 ASSERT_EQ(Result::ERROR_BAD_DER, CheckIssuer(invalidContents)); 91 }