1 /******************************************************************
3 * Copyright 2015 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 ******************************************************************/
23 #ifndef INCLUDE_MASTER_CSR_H_
24 #define INCLUDE_MASTER_CSR_H_
26 #include "CertificationRequest.h" /* CertificationRequest ASN.1 type */
28 #include "pki_errors.h"
34 // Memory allocated for DER encoded CSR
35 #define CSR_MAX_SIZE 1000
37 #define CSR_DEFAULT_VERSION 0
38 #define CSR_MAX_NAME_SIZE 100
41 * Encode certificate signing request with specified parameters.
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
50 PKIError EncodeCSR (const UTF8String_t *subjectName,
51 const BIT_STRING_t *subjectPublicKey,
52 const BIT_STRING_t *subjectPrivateKey,
53 ByteArray *encodedCSR);
56 * Decode certificate signing request, extracts its common name and public key.
58 * Return error if signature is not valid.
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
67 PKIError DecodeCSR (const ByteArray *encodedCSR,
68 UTF8String_t *subjectName, BIT_STRING_t *subjectPublicKey);
74 #endif /* INCLUDE_MASTER_CSR_H_ */