e1f08707cdea2ffabea3a53ea0c8a1ae6d2bbf72
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / ck_manager / include / csr_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_CSR_H_
24 #define INCLUDE_MASTER_CSR_H_
25
26 #include "CertificationRequest.h" /* CertificationRequest ASN.1 type */
27 #include "pki.h"
28 #include "pki_errors.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 // Memory allocated for DER encoded CSR
35 #define CSR_MAX_SIZE   1000
36
37 #define CSR_DEFAULT_VERSION 0
38 #define CSR_MAX_NAME_SIZE 100
39
40 /**
41  * Encode certificate signing request with specified parameters.
42  *
43  * @param[in] subjectName pointer to subject's common name
44  * @param[in] subjectPublicKey pointer to subject's public key to be signed
45  * @param[in] subjectPrivateKey pointer to subject's private key to be signed
46  * @param[out] encodedCSR pointer to allocated memory for DER encoded certificate signing request
47  *          (CSR_MAX_SIZE bytes should be allocated)
48  * @return PKI_SUCCESS if success, error code otherwise
49  */
50 PKIError EncodeCSR (const UTF8String_t *subjectName,
51                     const BIT_STRING_t *subjectPublicKey,
52                     const BIT_STRING_t *subjectPrivateKey,
53                     ByteArray *encodedCSR);
54
55 /**
56  * Decode certificate signing request, extracts its common name and public key.
57  *
58  * Return error if signature is not valid.
59  *
60  * @param[in] encodedCSR  pointer to array with DER encoded certificate signing request
61  * @param[out] subjectName pointer to allocated memory for subject's common name extraction
62  *          (CSR_MAX_NAME_SIZE bytes should be allocated)
63  * @param[out] subjectPublicKey pointer to allocated memory for subject's public key extraction
64  *          (PUBLIC_KEY_SIZE bytes should be allocated)
65  * @return PKI_SUCCESS if success, error code otherwise
66  */
67 PKIError DecodeCSR (const ByteArray *encodedCSR,
68                        UTF8String_t *subjectName, BIT_STRING_t *subjectPublicKey);
69
70 #ifdef __cplusplus
71 }
72 #endif
73
74 #endif /* INCLUDE_MASTER_CSR_H_ */