1 /******************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 ******************************************************************/
22 #include <oic_malloc.h>
23 #include <gtest/gtest.h>
24 #include "crl_generator.h"
26 static const ByteArray privateKey = {(uint8_t[])
28 0xd6, 0xc8, 0x92, 0x16, 0x36, 0x7f, 0xf0, 0xe4, 0xb2, 0x75, 0xd6, 0x4a, 0xf1, 0x3f, 0x14, 0x30,
29 0x1a, 0x69, 0xc5, 0x3e, 0x52, 0xd6, 0xda, 0xa0, 0xbf, 0xae, 0x43, 0xd1, 0x6b, 0xfe, 0xd1, 0x36
30 }, PRIVATE_KEY_SIZE };
33 TEST(CRLGeneratorTest, GenerateCRL)
35 uint8_t *uint8ThisUpdateTime = (uint8_t *)"130101000000Z";
36 uint32_t numberOfRevoked = 2;
37 uint32_t revokedNumbers[2];
38 const uint8_t *revocationDates[2];
39 CertificateRevocationInfo_t *certificateRevocationInfo = NULL;
40 UTF8String_t *issuerName = NULL;
41 UTCTime_t *thisUpdateTime = NULL;
42 ByteArray encodedCRL = BYTE_ARRAY_INITIALIZER;
43 BIT_STRING_t issuerPrivateKey;
45 revokedNumbers[0] = 100; // serial number of first revoked certificate
46 revokedNumbers[1] = 200; // serial number of second revoked certificate
48 revocationDates[0] = (const uint8_t *)"130101000001Z";
49 revocationDates[1] = (const uint8_t *)"130101000002Z";
51 certificateRevocationInfo = (CertificateRevocationInfo_t *)OICCalloc(numberOfRevoked,
52 sizeof(CertificateRevocationInfo_t));
53 EXPECT_TRUE(NULL != certificateRevocationInfo);
55 issuerName = (UTF8String_t *)OICCalloc(1, sizeof(UTF8String_t));
56 EXPECT_TRUE(NULL != issuerName);
58 thisUpdateTime = (UTCTime_t *)OICCalloc(1, sizeof(UTCTime_t));
59 EXPECT_TRUE(NULL != thisUpdateTime);
61 encodedCRL.data = (uint8_t *)OICCalloc(1,
62 (CRL_MIN_SIZE + numberOfRevoked * (sizeof(CertificateRevocationInfo_t) + 4)));
63 EXPECT_TRUE(NULL != encodedCRL.data);
64 encodedCRL.len = (CRL_MIN_SIZE + numberOfRevoked * (sizeof(CertificateRevocationInfo_t) + 4));
66 issuerPrivateKey.size = PRIVATE_KEY_SIZE + 1;
67 issuerPrivateKey.buf = (uint8_t *)OICCalloc((issuerPrivateKey.size), sizeof(uint8_t));
68 EXPECT_TRUE(NULL != issuerPrivateKey.buf);
70 if(NULL != certificateRevocationInfo && NULL != issuerName &&
71 NULL != thisUpdateTime && NULL != encodedCRL.data && NULL != issuerPrivateKey.buf)
73 ByteArray issName = BYTE_ARRAY_INITIALIZER;
74 issName.data = (uint8_t *)"Issuer";
75 issName.len = strlen((char *)issName.data);
77 issuerName->buf = issName.data;
78 issuerName->size = issName.len;
80 for (size_t i = 0; i < numberOfRevoked; i++ )
82 certificateRevocationInfo[i].userCertificate = revokedNumbers[i];
83 certificateRevocationInfo[i].revocationDate.buf = (uint8_t *)revocationDates[i];
84 certificateRevocationInfo[i].revocationDate.size =
85 strlen((const char *)revocationDates[i]);
88 memcpy((issuerPrivateKey.buf) + 1, privateKey.data, PRIVATE_KEY_SIZE);
90 EXPECT_EQ(PKI_SUCCESS, GenerateCRL(issuerName, thisUpdateTime, numberOfRevoked,
91 certificateRevocationInfo, &issuerPrivateKey, &encodedCRL));
94 OICFree(certificateRevocationInfo);
96 OICFree(thisUpdateTime);