dfdec1ca7323faf40ab5bde94fd35db979cdbd46
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / ck_manager / include / crl_generator.h
1 /******************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19
20  ******************************************************************/
21
22
23 #ifndef INCLUDE_MASTER_CRL_ENCODER_H_
24 #define INCLUDE_MASTER_CRL_ENCODER_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include "CertificateRevocationList.h" /* CertificateList ASN.1 type */
31 #include "pki.h"
32 #include "pki_errors.h"
33
34 // Minimal memory allocated for DER encoded CRL
35 #define CRL_MIN_SIZE   250      //minimal size of CRL (issuer info + signature)
36
37 #define CRL_MAX_NAME_SIZE 100   //maximal length of CRL issuer field
38
39 /**
40  * Encode certificate revocation list with specified parameters.
41  *
42  * @param[in] issuerName pointer to issuer's common name
43  * @param[in] thisUpdateTime pointer to time of issuing CRL
44  * @param[in] nuberOfRevoked number of revoked certificates
45  * @param[in] certificateRevocationInfo array with certificate revocation info
46  * @param[in] issuerPrivateKey pointer to issuer's private key to sign CRL
47  * @param[out] encodedCRL pointer to allocated memory for DER encoded certificate revocation list
48  *          ( (CRL_MIN_SIZE + nuberOfRevoked * (sizeof(CertificateRevocationInfo_t) + 4)) bytes
49  *          should be allocated)
50  * @return PKI_SUCCESS if success, error code otherwise
51  */
52 PKIError GenerateCRL (const UTF8String_t *issuerName,
53                       const UTCTime_t *thisUpdateTime, const uint32_t nuberOfRevoked,
54                       const CertificateRevocationInfo_t *certificateRevocationInfo,
55                       const BIT_STRING_t *issuerPrivateKey, ByteArray *encodedCRL);
56
57 /**
58  * Sign certificate revocation list.
59  *
60  * @param[in] certificateRevocationList pointer to CRL for signing
61  * @param[in] crlMaxSize max size of DER encoded CRL
62  * @param[in] issuerPrivateKey pointer to issuer private key
63  * @param[out] encodedCRL pointer to allocated memory for DER encoded certificate revocation list
64  *          crlMaxSize bytes should be allocated)
65  * @return PKI_SUCCESS if success, error code otherwise
66  */
67 PKIError SignCRL(CertificateRevocationList_t *certificateRevocationList,
68                  const uint32_t crlMaxSize, const BIT_STRING_t *issuerPrivateKey,
69                  ByteArray *encodedCRL);
70
71 #ifdef __cplusplus
72 }
73 #endif
74
75 #endif /* INCLUDE_MASTER_CRL_ENCODER_H_ */