mbed client lightswitch demo

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by Austin Blackstone

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file pem.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief Privacy Enhanced Mail (PEM) decoding
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_PEM_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_PEM_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #include <stddef.h>
mbedAustin 11:cada08fc8a70 27
mbedAustin 11:cada08fc8a70 28 /**
mbedAustin 11:cada08fc8a70 29 * \name PEM Error codes
mbedAustin 11:cada08fc8a70 30 * These error codes are returned in case of errors reading the
mbedAustin 11:cada08fc8a70 31 * PEM data.
mbedAustin 11:cada08fc8a70 32 * \{
mbedAustin 11:cada08fc8a70 33 */
mbedAustin 11:cada08fc8a70 34 #define MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT -0x1080 /**< No PEM header or footer found. */
mbedAustin 11:cada08fc8a70 35 #define MBEDTLS_ERR_PEM_INVALID_DATA -0x1100 /**< PEM string is not as expected. */
mbedAustin 11:cada08fc8a70 36 #define MBEDTLS_ERR_PEM_ALLOC_FAILED -0x1180 /**< Failed to allocate memory. */
mbedAustin 11:cada08fc8a70 37 #define MBEDTLS_ERR_PEM_INVALID_ENC_IV -0x1200 /**< RSA IV is not in hex-format. */
mbedAustin 11:cada08fc8a70 38 #define MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG -0x1280 /**< Unsupported key encryption algorithm. */
mbedAustin 11:cada08fc8a70 39 #define MBEDTLS_ERR_PEM_PASSWORD_REQUIRED -0x1300 /**< Private key password can't be empty. */
mbedAustin 11:cada08fc8a70 40 #define MBEDTLS_ERR_PEM_PASSWORD_MISMATCH -0x1380 /**< Given private key password does not allow for correct decryption. */
mbedAustin 11:cada08fc8a70 41 #define MBEDTLS_ERR_PEM_FEATURE_UNAVAILABLE -0x1400 /**< Unavailable feature, e.g. hashing/encryption combination. */
mbedAustin 11:cada08fc8a70 42 #define MBEDTLS_ERR_PEM_BAD_INPUT_DATA -0x1480 /**< Bad input parameters to function. */
mbedAustin 11:cada08fc8a70 43 /* \} name */
mbedAustin 11:cada08fc8a70 44
mbedAustin 11:cada08fc8a70 45 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 46 extern "C" {
mbedAustin 11:cada08fc8a70 47 #endif
mbedAustin 11:cada08fc8a70 48
mbedAustin 11:cada08fc8a70 49 #if defined(MBEDTLS_PEM_PARSE_C)
mbedAustin 11:cada08fc8a70 50 /**
mbedAustin 11:cada08fc8a70 51 * \brief PEM context structure
mbedAustin 11:cada08fc8a70 52 */
mbedAustin 11:cada08fc8a70 53 typedef struct
mbedAustin 11:cada08fc8a70 54 {
mbedAustin 11:cada08fc8a70 55 unsigned char *buf; /*!< buffer for decoded data */
mbedAustin 11:cada08fc8a70 56 size_t buflen; /*!< length of the buffer */
mbedAustin 11:cada08fc8a70 57 unsigned char *info; /*!< buffer for extra header information */
mbedAustin 11:cada08fc8a70 58 }
mbedAustin 11:cada08fc8a70 59 mbedtls_pem_context;
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 /**
mbedAustin 11:cada08fc8a70 62 * \brief PEM context setup
mbedAustin 11:cada08fc8a70 63 *
mbedAustin 11:cada08fc8a70 64 * \param ctx context to be initialized
mbedAustin 11:cada08fc8a70 65 */
mbedAustin 11:cada08fc8a70 66 void mbedtls_pem_init( mbedtls_pem_context *ctx );
mbedAustin 11:cada08fc8a70 67
mbedAustin 11:cada08fc8a70 68 /**
mbedAustin 11:cada08fc8a70 69 * \brief Read a buffer for PEM information and store the resulting
mbedAustin 11:cada08fc8a70 70 * data into the specified context buffers.
mbedAustin 11:cada08fc8a70 71 *
mbedAustin 11:cada08fc8a70 72 * \param ctx context to use
mbedAustin 11:cada08fc8a70 73 * \param header header string to seek and expect
mbedAustin 11:cada08fc8a70 74 * \param footer footer string to seek and expect
mbedAustin 11:cada08fc8a70 75 * \param data source data to look in (must be nul-terminated)
mbedAustin 11:cada08fc8a70 76 * \param pwd password for decryption (can be NULL)
mbedAustin 11:cada08fc8a70 77 * \param pwdlen length of password
mbedAustin 11:cada08fc8a70 78 * \param use_len destination for total length used (set after header is
mbedAustin 11:cada08fc8a70 79 * correctly read, so unless you get
mbedAustin 11:cada08fc8a70 80 * MBEDTLS_ERR_PEM_BAD_INPUT_DATA or
mbedAustin 11:cada08fc8a70 81 * MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT, use_len is
mbedAustin 11:cada08fc8a70 82 * the length to skip)
mbedAustin 11:cada08fc8a70 83 *
mbedAustin 11:cada08fc8a70 84 * \note Attempts to check password correctness by verifying if
mbedAustin 11:cada08fc8a70 85 * the decrypted text starts with an ASN.1 sequence of
mbedAustin 11:cada08fc8a70 86 * appropriate length
mbedAustin 11:cada08fc8a70 87 *
mbedAustin 11:cada08fc8a70 88 * \return 0 on success, or a specific PEM error code
mbedAustin 11:cada08fc8a70 89 */
mbedAustin 11:cada08fc8a70 90 int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const char *footer,
mbedAustin 11:cada08fc8a70 91 const unsigned char *data,
mbedAustin 11:cada08fc8a70 92 const unsigned char *pwd,
mbedAustin 11:cada08fc8a70 93 size_t pwdlen, size_t *use_len );
mbedAustin 11:cada08fc8a70 94
mbedAustin 11:cada08fc8a70 95 /**
mbedAustin 11:cada08fc8a70 96 * \brief PEM context memory freeing
mbedAustin 11:cada08fc8a70 97 *
mbedAustin 11:cada08fc8a70 98 * \param ctx context to be freed
mbedAustin 11:cada08fc8a70 99 */
mbedAustin 11:cada08fc8a70 100 void mbedtls_pem_free( mbedtls_pem_context *ctx );
mbedAustin 11:cada08fc8a70 101 #endif /* MBEDTLS_PEM_PARSE_C */
mbedAustin 11:cada08fc8a70 102
mbedAustin 11:cada08fc8a70 103 #if defined(MBEDTLS_PEM_WRITE_C)
mbedAustin 11:cada08fc8a70 104 /**
mbedAustin 11:cada08fc8a70 105 * \brief Write a buffer of PEM information from a DER encoded
mbedAustin 11:cada08fc8a70 106 * buffer.
mbedAustin 11:cada08fc8a70 107 *
mbedAustin 11:cada08fc8a70 108 * \param header header string to write
mbedAustin 11:cada08fc8a70 109 * \param footer footer string to write
mbedAustin 11:cada08fc8a70 110 * \param der_data DER data to write
mbedAustin 11:cada08fc8a70 111 * \param der_len length of the DER data
mbedAustin 11:cada08fc8a70 112 * \param buf buffer to write to
mbedAustin 11:cada08fc8a70 113 * \param buf_len length of output buffer
mbedAustin 11:cada08fc8a70 114 * \param olen total length written / required (if buf_len is not enough)
mbedAustin 11:cada08fc8a70 115 *
mbedAustin 11:cada08fc8a70 116 * \return 0 on success, or a specific PEM or BASE64 error code. On
mbedAustin 11:cada08fc8a70 117 * MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL olen is the required
mbedAustin 11:cada08fc8a70 118 * size.
mbedAustin 11:cada08fc8a70 119 */
mbedAustin 11:cada08fc8a70 120 int mbedtls_pem_write_buffer( const char *header, const char *footer,
mbedAustin 11:cada08fc8a70 121 const unsigned char *der_data, size_t der_len,
mbedAustin 11:cada08fc8a70 122 unsigned char *buf, size_t buf_len, size_t *olen );
mbedAustin 11:cada08fc8a70 123 #endif /* MBEDTLS_PEM_WRITE_C */
mbedAustin 11:cada08fc8a70 124
mbedAustin 11:cada08fc8a70 125 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 126 }
mbedAustin 11:cada08fc8a70 127 #endif
mbedAustin 11:cada08fc8a70 128
mbedAustin 11:cada08fc8a70 129 #endif /* pem.h */