1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#ifndef AWS_IO_PEM_H
#define AWS_IO_PEM_H
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/io/io.h>
AWS_EXTERN_C_BEGIN
/*
* Naming follows OpenSSL convention for PEM types.
* Refer to comment after each enum value for the type string it represents.
*/
enum aws_pem_object_type {
AWS_PEM_TYPE_UNKNOWN = 0,
AWS_PEM_TYPE_X509_OLD, /* X509 CERTIFICATE */
AWS_PEM_TYPE_X509, /* CERTIFICATE */
AWS_PEM_TYPE_X509_TRUSTED, /* TRUSTED CERTIFICATE */
AWS_PEM_TYPE_X509_REQ_OLD, /* NEW CERTIFICATE REQUEST */
AWS_PEM_TYPE_X509_REQ, /* CERTIFICATE REQUEST */
AWS_PEM_TYPE_X509_CRL, /* X509 CRL */
AWS_PEM_TYPE_EVP_PKEY, /* ANY PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_PKCS8, /* PUBLIC KEY */
AWS_PEM_TYPE_PRIVATE_RSA_PKCS1, /* RSA PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_RSA_PKCS1, /* RSA PUBLIC KEY */
AWS_PEM_TYPE_PRIVATE_DSA_PKCS1, /* RSA PRIVATE KEY */
AWS_PEM_TYPE_PUBLIC_DSA_PKCS1, /* RSA PUBLIC KEY */
AWS_PEM_TYPE_PKCS7, /* PKCS7 */
AWS_PEM_TYPE_PKCS7_SIGNED_DATA, /* PKCS #7 SIGNED DATA */
AWS_PEM_TYPE_PRIVATE_PKCS8_ENCRYPTED, /* ENCRYPTED PRIVATE KEY */
AWS_PEM_TYPE_PRIVATE_PKCS8, /* PRIVATE KEY */
AWS_PEM_TYPE_DH_PARAMETERS, /* X9.42 DH PARAMETERS */
AWS_PEM_TYPE_DH_PARAMETERS_X942, /* X9.42 DH PARAMETERS */
AWS_PEM_TYPE_SSL_SESSION_PARAMETERS, /* SSL SESSION PARAMETERS */
AWS_PEM_TYPE_DSA_PARAMETERS, /* DSA PARAMETERS */
AWS_PEM_TYPE_ECDSA_PUBLIC, /* ECDSA PUBLIC KEY */
AWS_PEM_TYPE_EC_PARAMETERS, /* EC PARAMETERS */
AWS_PEM_TYPE_EC_PRIVATE, /* EC PRIVATE KEY */
AWS_PEM_TYPE_PARAMETERS, /* PARAMETERS */
AWS_PEM_TYPE_CMS, /* CMS */
AWS_PEM_TYPE_SM2_PARAMETERS /* SM2 PARAMETERS */
};
/*
* Describes PEM object decoded from file.
* data points to raw data bytes of object (decoding will do additional base 64
* decoding for each object).
* type will be set to object type or to AWS_PEM_TYPE_UNKNOWN if it could not
* figure out type.
* type_string is the string between -----BEGIN and -----
*/
struct aws_pem_object {
enum aws_pem_object_type type;
struct aws_string *type_string;
struct aws_byte_buf data;
};
/**
* Cleans up elements of pem_objects list 'aws_pem_objects_init_from_file_contents()'
* and 'aws_pem_objects_init_from_file_path()'.
*/
AWS_IO_API void aws_pem_objects_clean_up(struct aws_array_list *pem_objects);
/**
* Decodes PEM data and reads objects sequentially adding them to pem_objects.
* If it comes across an object it cannot read, list of all object read until
* that point is returned.
* If no objects can be read from PEM or objects could not be base 64 decoded,
* AWS_ERROR_PEM_MALFORMED is raised.
* out_pem_objects stores aws_pem_object struct by value.
* Function will initialize pem_objects list.
* This code is slow, and it allocates, so please try
* not to call this in the middle of something that needs to be fast or resource sensitive.
*/
AWS_IO_API int aws_pem_objects_init_from_file_contents(
struct aws_array_list *pem_objects,
struct aws_allocator *alloc,
struct aws_byte_cursor pem_cursor);
/**
* Decodes PEM data from file and reads objects sequentially adding them to pem_objects.
* If it comes across an object it cannot read, list of all object read until
* that point is returned.
* If no objects can be read from PEM or objects could not be base 64 decoded,
* AWS_ERROR_PEM_MALFORMED is raised.
* out_pem_objects stores aws_pem_object struct by value.
* Function will initialize pem_objects list.
* This code is slow, and it allocates, so please try
* not to call this in the middle of something that needs to be fast or resource sensitive.
*/
AWS_IO_API int aws_pem_objects_init_from_file_path(
struct aws_array_list *pem_objects,
struct aws_allocator *allocator,
const char *filename);
AWS_EXTERN_C_END
#endif /* AWS_IO_PEM_H */
|