The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

Dependencies:   WncControllerK64F

Dependents:   WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more

See the WNCInterface README in the Wiki tab for detailed information on this library.

Committer:
JMF
Date:
Fri Mar 24 22:26:23 2017 +0000
Revision:
29:b278b745fb4f
Parent:
12:0071cb144c7a
updated Class name of TCPSocketConnection to WncTCPSocketConnection;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /**
JMF 12:0071cb144c7a 2 * \file x509_csr.h
JMF 12:0071cb144c7a 3 *
JMF 12:0071cb144c7a 4 * \brief X.509 certificate signing request parsing and writing
JMF 12:0071cb144c7a 5 *
JMF 12:0071cb144c7a 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
JMF 12:0071cb144c7a 7 * SPDX-License-Identifier: Apache-2.0
JMF 12:0071cb144c7a 8 *
JMF 12:0071cb144c7a 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
JMF 12:0071cb144c7a 10 * not use this file except in compliance with the License.
JMF 12:0071cb144c7a 11 * You may obtain a copy of the License at
JMF 12:0071cb144c7a 12 *
JMF 12:0071cb144c7a 13 * http://www.apache.org/licenses/LICENSE-2.0
JMF 12:0071cb144c7a 14 *
JMF 12:0071cb144c7a 15 * Unless required by applicable law or agreed to in writing, software
JMF 12:0071cb144c7a 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
JMF 12:0071cb144c7a 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 12:0071cb144c7a 18 * See the License for the specific language governing permissions and
JMF 12:0071cb144c7a 19 * limitations under the License.
JMF 12:0071cb144c7a 20 *
JMF 12:0071cb144c7a 21 * This file is part of mbed TLS (https://tls.mbed.org)
JMF 12:0071cb144c7a 22 */
JMF 12:0071cb144c7a 23 #ifndef MBEDTLS_X509_CSR_H
JMF 12:0071cb144c7a 24 #define MBEDTLS_X509_CSR_H
JMF 12:0071cb144c7a 25
JMF 12:0071cb144c7a 26 #if !defined(MBEDTLS_CONFIG_FILE)
JMF 12:0071cb144c7a 27 #include "config.h"
JMF 12:0071cb144c7a 28 #else
JMF 12:0071cb144c7a 29 #include MBEDTLS_CONFIG_FILE
JMF 12:0071cb144c7a 30 #endif
JMF 12:0071cb144c7a 31
JMF 12:0071cb144c7a 32 #include "x509.h"
JMF 12:0071cb144c7a 33
JMF 12:0071cb144c7a 34 #ifdef __cplusplus
JMF 12:0071cb144c7a 35 extern "C" {
JMF 12:0071cb144c7a 36 #endif
JMF 12:0071cb144c7a 37
JMF 12:0071cb144c7a 38 /**
JMF 12:0071cb144c7a 39 * \addtogroup x509_module
JMF 12:0071cb144c7a 40 * \{ */
JMF 12:0071cb144c7a 41
JMF 12:0071cb144c7a 42 /**
JMF 12:0071cb144c7a 43 * \name Structures and functions for X.509 Certificate Signing Requests (CSR)
JMF 12:0071cb144c7a 44 * \{
JMF 12:0071cb144c7a 45 */
JMF 12:0071cb144c7a 46
JMF 12:0071cb144c7a 47 /**
JMF 12:0071cb144c7a 48 * Certificate Signing Request (CSR) structure.
JMF 12:0071cb144c7a 49 */
JMF 12:0071cb144c7a 50 typedef struct mbedtls_x509_csr
JMF 12:0071cb144c7a 51 {
JMF 12:0071cb144c7a 52 mbedtls_x509_buf raw; /**< The raw CSR data (DER). */
JMF 12:0071cb144c7a 53 mbedtls_x509_buf cri; /**< The raw CertificateRequestInfo body (DER). */
JMF 12:0071cb144c7a 54
JMF 12:0071cb144c7a 55 int version; /**< CSR version (1=v1). */
JMF 12:0071cb144c7a 56
JMF 12:0071cb144c7a 57 mbedtls_x509_buf subject_raw; /**< The raw subject data (DER). */
JMF 12:0071cb144c7a 58 mbedtls_x509_name subject; /**< The parsed subject data (named information object). */
JMF 12:0071cb144c7a 59
JMF 12:0071cb144c7a 60 mbedtls_pk_context pk; /**< Container for the public key context. */
JMF 12:0071cb144c7a 61
JMF 12:0071cb144c7a 62 mbedtls_x509_buf sig_oid;
JMF 12:0071cb144c7a 63 mbedtls_x509_buf sig;
JMF 12:0071cb144c7a 64 mbedtls_md_type_t sig_md; /**< Internal representation of the MD algorithm of the signature algorithm, e.g. MBEDTLS_MD_SHA256 */
JMF 12:0071cb144c7a 65 mbedtls_pk_type_t sig_pk; /**< Internal representation of the Public Key algorithm of the signature algorithm, e.g. MBEDTLS_PK_RSA */
JMF 12:0071cb144c7a 66 void *sig_opts; /**< Signature options to be passed to mbedtls_pk_verify_ext(), e.g. for RSASSA-PSS */
JMF 12:0071cb144c7a 67 }
JMF 12:0071cb144c7a 68 mbedtls_x509_csr;
JMF 12:0071cb144c7a 69
JMF 12:0071cb144c7a 70 /**
JMF 12:0071cb144c7a 71 * Container for writing a CSR
JMF 12:0071cb144c7a 72 */
JMF 12:0071cb144c7a 73 typedef struct mbedtls_x509write_csr
JMF 12:0071cb144c7a 74 {
JMF 12:0071cb144c7a 75 mbedtls_pk_context *key;
JMF 12:0071cb144c7a 76 mbedtls_asn1_named_data *subject;
JMF 12:0071cb144c7a 77 mbedtls_md_type_t md_alg;
JMF 12:0071cb144c7a 78 mbedtls_asn1_named_data *extensions;
JMF 12:0071cb144c7a 79 }
JMF 12:0071cb144c7a 80 mbedtls_x509write_csr;
JMF 12:0071cb144c7a 81
JMF 12:0071cb144c7a 82 #if defined(MBEDTLS_X509_CSR_PARSE_C)
JMF 12:0071cb144c7a 83 /**
JMF 12:0071cb144c7a 84 * \brief Load a Certificate Signing Request (CSR) in DER format
JMF 12:0071cb144c7a 85 *
JMF 12:0071cb144c7a 86 * \note CSR attributes (if any) are currently silently ignored.
JMF 12:0071cb144c7a 87 *
JMF 12:0071cb144c7a 88 * \param csr CSR context to fill
JMF 12:0071cb144c7a 89 * \param buf buffer holding the CRL data
JMF 12:0071cb144c7a 90 * \param buflen size of the buffer
JMF 12:0071cb144c7a 91 *
JMF 12:0071cb144c7a 92 * \return 0 if successful, or a specific X509 error code
JMF 12:0071cb144c7a 93 */
JMF 12:0071cb144c7a 94 int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
JMF 12:0071cb144c7a 95 const unsigned char *buf, size_t buflen );
JMF 12:0071cb144c7a 96
JMF 12:0071cb144c7a 97 /**
JMF 12:0071cb144c7a 98 * \brief Load a Certificate Signing Request (CSR), DER or PEM format
JMF 12:0071cb144c7a 99 *
JMF 12:0071cb144c7a 100 * \note See notes for \c mbedtls_x509_csr_parse_der()
JMF 12:0071cb144c7a 101 *
JMF 12:0071cb144c7a 102 * \param csr CSR context to fill
JMF 12:0071cb144c7a 103 * \param buf buffer holding the CRL data
JMF 12:0071cb144c7a 104 * \param buflen size of the buffer
JMF 12:0071cb144c7a 105 * (including the terminating null byte for PEM data)
JMF 12:0071cb144c7a 106 *
JMF 12:0071cb144c7a 107 * \return 0 if successful, or a specific X509 or PEM error code
JMF 12:0071cb144c7a 108 */
JMF 12:0071cb144c7a 109 int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen );
JMF 12:0071cb144c7a 110
JMF 12:0071cb144c7a 111 #if defined(MBEDTLS_FS_IO)
JMF 12:0071cb144c7a 112 /**
JMF 12:0071cb144c7a 113 * \brief Load a Certificate Signing Request (CSR)
JMF 12:0071cb144c7a 114 *
JMF 12:0071cb144c7a 115 * \note See notes for \c mbedtls_x509_csr_parse()
JMF 12:0071cb144c7a 116 *
JMF 12:0071cb144c7a 117 * \param csr CSR context to fill
JMF 12:0071cb144c7a 118 * \param path filename to read the CSR from
JMF 12:0071cb144c7a 119 *
JMF 12:0071cb144c7a 120 * \return 0 if successful, or a specific X509 or PEM error code
JMF 12:0071cb144c7a 121 */
JMF 12:0071cb144c7a 122 int mbedtls_x509_csr_parse_file( mbedtls_x509_csr *csr, const char *path );
JMF 12:0071cb144c7a 123 #endif /* MBEDTLS_FS_IO */
JMF 12:0071cb144c7a 124
JMF 12:0071cb144c7a 125 /**
JMF 12:0071cb144c7a 126 * \brief Returns an informational string about the
JMF 12:0071cb144c7a 127 * CSR.
JMF 12:0071cb144c7a 128 *
JMF 12:0071cb144c7a 129 * \param buf Buffer to write to
JMF 12:0071cb144c7a 130 * \param size Maximum size of buffer
JMF 12:0071cb144c7a 131 * \param prefix A line prefix
JMF 12:0071cb144c7a 132 * \param csr The X509 CSR to represent
JMF 12:0071cb144c7a 133 *
JMF 12:0071cb144c7a 134 * \return The length of the string written (not including the
JMF 12:0071cb144c7a 135 * terminated nul byte), or a negative error code.
JMF 12:0071cb144c7a 136 */
JMF 12:0071cb144c7a 137 int mbedtls_x509_csr_info( char *buf, size_t size, const char *prefix,
JMF 12:0071cb144c7a 138 const mbedtls_x509_csr *csr );
JMF 12:0071cb144c7a 139
JMF 12:0071cb144c7a 140 /**
JMF 12:0071cb144c7a 141 * \brief Initialize a CSR
JMF 12:0071cb144c7a 142 *
JMF 12:0071cb144c7a 143 * \param csr CSR to initialize
JMF 12:0071cb144c7a 144 */
JMF 12:0071cb144c7a 145 void mbedtls_x509_csr_init( mbedtls_x509_csr *csr );
JMF 12:0071cb144c7a 146
JMF 12:0071cb144c7a 147 /**
JMF 12:0071cb144c7a 148 * \brief Unallocate all CSR data
JMF 12:0071cb144c7a 149 *
JMF 12:0071cb144c7a 150 * \param csr CSR to free
JMF 12:0071cb144c7a 151 */
JMF 12:0071cb144c7a 152 void mbedtls_x509_csr_free( mbedtls_x509_csr *csr );
JMF 12:0071cb144c7a 153 #endif /* MBEDTLS_X509_CSR_PARSE_C */
JMF 12:0071cb144c7a 154
JMF 12:0071cb144c7a 155 /* \} name */
JMF 12:0071cb144c7a 156 /* \} addtogroup x509_module */
JMF 12:0071cb144c7a 157
JMF 12:0071cb144c7a 158 #if defined(MBEDTLS_X509_CSR_WRITE_C)
JMF 12:0071cb144c7a 159 /**
JMF 12:0071cb144c7a 160 * \brief Initialize a CSR context
JMF 12:0071cb144c7a 161 *
JMF 12:0071cb144c7a 162 * \param ctx CSR context to initialize
JMF 12:0071cb144c7a 163 */
JMF 12:0071cb144c7a 164 void mbedtls_x509write_csr_init( mbedtls_x509write_csr *ctx );
JMF 12:0071cb144c7a 165
JMF 12:0071cb144c7a 166 /**
JMF 12:0071cb144c7a 167 * \brief Set the subject name for a CSR
JMF 12:0071cb144c7a 168 * Subject names should contain a comma-separated list
JMF 12:0071cb144c7a 169 * of OID types and values:
JMF 12:0071cb144c7a 170 * e.g. "C=UK,O=ARM,CN=mbed TLS Server 1"
JMF 12:0071cb144c7a 171 *
JMF 12:0071cb144c7a 172 * \param ctx CSR context to use
JMF 12:0071cb144c7a 173 * \param subject_name subject name to set
JMF 12:0071cb144c7a 174 *
JMF 12:0071cb144c7a 175 * \return 0 if subject name was parsed successfully, or
JMF 12:0071cb144c7a 176 * a specific error code
JMF 12:0071cb144c7a 177 */
JMF 12:0071cb144c7a 178 int mbedtls_x509write_csr_set_subject_name( mbedtls_x509write_csr *ctx,
JMF 12:0071cb144c7a 179 const char *subject_name );
JMF 12:0071cb144c7a 180
JMF 12:0071cb144c7a 181 /**
JMF 12:0071cb144c7a 182 * \brief Set the key for a CSR (public key will be included,
JMF 12:0071cb144c7a 183 * private key used to sign the CSR when writing it)
JMF 12:0071cb144c7a 184 *
JMF 12:0071cb144c7a 185 * \param ctx CSR context to use
JMF 12:0071cb144c7a 186 * \param key Asymetric key to include
JMF 12:0071cb144c7a 187 */
JMF 12:0071cb144c7a 188 void mbedtls_x509write_csr_set_key( mbedtls_x509write_csr *ctx, mbedtls_pk_context *key );
JMF 12:0071cb144c7a 189
JMF 12:0071cb144c7a 190 /**
JMF 12:0071cb144c7a 191 * \brief Set the MD algorithm to use for the signature
JMF 12:0071cb144c7a 192 * (e.g. MBEDTLS_MD_SHA1)
JMF 12:0071cb144c7a 193 *
JMF 12:0071cb144c7a 194 * \param ctx CSR context to use
JMF 12:0071cb144c7a 195 * \param md_alg MD algorithm to use
JMF 12:0071cb144c7a 196 */
JMF 12:0071cb144c7a 197 void mbedtls_x509write_csr_set_md_alg( mbedtls_x509write_csr *ctx, mbedtls_md_type_t md_alg );
JMF 12:0071cb144c7a 198
JMF 12:0071cb144c7a 199 /**
JMF 12:0071cb144c7a 200 * \brief Set the Key Usage Extension flags
JMF 12:0071cb144c7a 201 * (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
JMF 12:0071cb144c7a 202 *
JMF 12:0071cb144c7a 203 * \param ctx CSR context to use
JMF 12:0071cb144c7a 204 * \param key_usage key usage flags to set
JMF 12:0071cb144c7a 205 *
JMF 12:0071cb144c7a 206 * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
JMF 12:0071cb144c7a 207 */
JMF 12:0071cb144c7a 208 int mbedtls_x509write_csr_set_key_usage( mbedtls_x509write_csr *ctx, unsigned char key_usage );
JMF 12:0071cb144c7a 209
JMF 12:0071cb144c7a 210 /**
JMF 12:0071cb144c7a 211 * \brief Set the Netscape Cert Type flags
JMF 12:0071cb144c7a 212 * (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
JMF 12:0071cb144c7a 213 *
JMF 12:0071cb144c7a 214 * \param ctx CSR context to use
JMF 12:0071cb144c7a 215 * \param ns_cert_type Netscape Cert Type flags to set
JMF 12:0071cb144c7a 216 *
JMF 12:0071cb144c7a 217 * \return 0 if successful, or MBEDTLS_ERR_X509_ALLOC_FAILED
JMF 12:0071cb144c7a 218 */
JMF 12:0071cb144c7a 219 int mbedtls_x509write_csr_set_ns_cert_type( mbedtls_x509write_csr *ctx,
JMF 12:0071cb144c7a 220 unsigned char ns_cert_type );
JMF 12:0071cb144c7a 221
JMF 12:0071cb144c7a 222 /**
JMF 12:0071cb144c7a 223 * \brief Generic function to add to or replace an extension in the
JMF 12:0071cb144c7a 224 * CSR
JMF 12:0071cb144c7a 225 *
JMF 12:0071cb144c7a 226 * \param ctx CSR context to use
JMF 12:0071cb144c7a 227 * \param oid OID of the extension
JMF 12:0071cb144c7a 228 * \param oid_len length of the OID
JMF 12:0071cb144c7a 229 * \param val value of the extension OCTET STRING
JMF 12:0071cb144c7a 230 * \param val_len length of the value data
JMF 12:0071cb144c7a 231 *
JMF 12:0071cb144c7a 232 * \return 0 if successful, or a MBEDTLS_ERR_X509_ALLOC_FAILED
JMF 12:0071cb144c7a 233 */
JMF 12:0071cb144c7a 234 int mbedtls_x509write_csr_set_extension( mbedtls_x509write_csr *ctx,
JMF 12:0071cb144c7a 235 const char *oid, size_t oid_len,
JMF 12:0071cb144c7a 236 const unsigned char *val, size_t val_len );
JMF 12:0071cb144c7a 237
JMF 12:0071cb144c7a 238 /**
JMF 12:0071cb144c7a 239 * \brief Free the contents of a CSR context
JMF 12:0071cb144c7a 240 *
JMF 12:0071cb144c7a 241 * \param ctx CSR context to free
JMF 12:0071cb144c7a 242 */
JMF 12:0071cb144c7a 243 void mbedtls_x509write_csr_free( mbedtls_x509write_csr *ctx );
JMF 12:0071cb144c7a 244
JMF 12:0071cb144c7a 245 /**
JMF 12:0071cb144c7a 246 * \brief Write a CSR (Certificate Signing Request) to a
JMF 12:0071cb144c7a 247 * DER structure
JMF 12:0071cb144c7a 248 * Note: data is written at the end of the buffer! Use the
JMF 12:0071cb144c7a 249 * return value to determine where you should start
JMF 12:0071cb144c7a 250 * using the buffer
JMF 12:0071cb144c7a 251 *
JMF 12:0071cb144c7a 252 * \param ctx CSR to write away
JMF 12:0071cb144c7a 253 * \param buf buffer to write to
JMF 12:0071cb144c7a 254 * \param size size of the buffer
JMF 12:0071cb144c7a 255 * \param f_rng RNG function (for signature, see note)
JMF 12:0071cb144c7a 256 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 257 *
JMF 12:0071cb144c7a 258 * \return length of data written if successful, or a specific
JMF 12:0071cb144c7a 259 * error code
JMF 12:0071cb144c7a 260 *
JMF 12:0071cb144c7a 261 * \note f_rng may be NULL if RSA is used for signature and the
JMF 12:0071cb144c7a 262 * signature is made offline (otherwise f_rng is desirable
JMF 12:0071cb144c7a 263 * for countermeasures against timing attacks).
JMF 12:0071cb144c7a 264 * ECDSA signatures always require a non-NULL f_rng.
JMF 12:0071cb144c7a 265 */
JMF 12:0071cb144c7a 266 int mbedtls_x509write_csr_der( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
JMF 12:0071cb144c7a 267 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 268 void *p_rng );
JMF 12:0071cb144c7a 269
JMF 12:0071cb144c7a 270 #if defined(MBEDTLS_PEM_WRITE_C)
JMF 12:0071cb144c7a 271 /**
JMF 12:0071cb144c7a 272 * \brief Write a CSR (Certificate Signing Request) to a
JMF 12:0071cb144c7a 273 * PEM string
JMF 12:0071cb144c7a 274 *
JMF 12:0071cb144c7a 275 * \param ctx CSR to write away
JMF 12:0071cb144c7a 276 * \param buf buffer to write to
JMF 12:0071cb144c7a 277 * \param size size of the buffer
JMF 12:0071cb144c7a 278 * \param f_rng RNG function (for signature, see note)
JMF 12:0071cb144c7a 279 * \param p_rng RNG parameter
JMF 12:0071cb144c7a 280 *
JMF 12:0071cb144c7a 281 * \return 0 if successful, or a specific error code
JMF 12:0071cb144c7a 282 *
JMF 12:0071cb144c7a 283 * \note f_rng may be NULL if RSA is used for signature and the
JMF 12:0071cb144c7a 284 * signature is made offline (otherwise f_rng is desirable
JMF 12:0071cb144c7a 285 * for couermeasures against timing attacks).
JMF 12:0071cb144c7a 286 * ECDSA signatures always require a non-NULL f_rng.
JMF 12:0071cb144c7a 287 */
JMF 12:0071cb144c7a 288 int mbedtls_x509write_csr_pem( mbedtls_x509write_csr *ctx, unsigned char *buf, size_t size,
JMF 12:0071cb144c7a 289 int (*f_rng)(void *, unsigned char *, size_t),
JMF 12:0071cb144c7a 290 void *p_rng );
JMF 12:0071cb144c7a 291 #endif /* MBEDTLS_PEM_WRITE_C */
JMF 12:0071cb144c7a 292 #endif /* MBEDTLS_X509_CSR_WRITE_C */
JMF 12:0071cb144c7a 293
JMF 12:0071cb144c7a 294 #ifdef __cplusplus
JMF 12:0071cb144c7a 295 }
JMF 12:0071cb144c7a 296 #endif
JMF 12:0071cb144c7a 297
JMF 12:0071cb144c7a 298 #endif /* mbedtls_x509_csr.h */