RPK RFC7250: Add in support

Currently OpenSSL and MBedTLS do not support RFC7250. See
https://en.wikipedia.org/wiki/Comparison_of_TLS_implementations#Extensions
last column.

GnuTLS >= 3.6.6 required.

TinyDTLS update required.

New option is_rpk_not_cert added to PKI setup structure which is enabled
in coap-client and coap-server by the -M option and the use of a PUBLIC KEY
instead of a CERTIFICATE in the cert file.  If file is EC PRIVATE KEY, then
it can be used for both the public and private key files.

man/coap-client.txt.in:
man/coap-server.txt.in:

Document -M option.

man/coap_encryption.txt.in:
man/coap-server.txt.in:
man/coap_context.txt.in:

Add in documentation for RPK.

examples/client.c:
examples/coap-server.c:

Add in support for is_rpk_not_cert and -M option.
Stop sending ::1 for SNI - use localhost instead.

include/coap2/coap_dtls.h:

Add in is_rpk_not_cert option.

include/coap2/str.h:
src/str.c:
libcoap-2.map:
libcoap-2.sym:

Add in coap_new_binary() and coap_delete_binary() functions.

src/coap_openssl.c:

Report RPK is not supported if invoked.
Check that all received data is used up for error recovery.

src/coap_mbedtls.c:

Report RPK is not supported if invoked.
Handle more MbedTLS generated errors.
Check that all received data is used up for error recovery.

src/coap_gnutls.c:

Add in support for RPK.
Add in sending Hello Verify if not cookie match in Client Hello
Check that all received data is used up for error recovery.

src/coap_tinydtls.c:

Add in support for RPK.

HOWTO.pkcs11:

Update for use with RPK.
Use .der file for '-C ca_file' definitions as later GnuTLS needs CA
to be trusted in HSM.
This commit is contained in:
Jon Shallow committed 2020-10-21 15:54:20 +01:00
1 parent f9535b9690
commit d40f2d6a3f
14 files changed
+1638 -274

No files matched your search

+14 -6
View File
@@ -40,6 +40,8 @@ struct coap_dtls_pki_t;
#define COAP_DTLS_RETRANSMIT_COAP_TICKS (COAP_DTLS_RETRANSMIT_MS * COAP_TICKS_PER_SECOND / 1000)
#define COAP_DTLS_RPK_CERT_CN "RPK"
/**
* Check whether DTLS is available.
*
@@ -103,6 +105,8 @@ typedef int (*coap_dtls_security_setup_t)(void* tls_session,
* but the application needs to check that the CN is allowed.
* CN is the SubjectAltName in the cert, if not present, then the leftmost
* Common Name (CN) component of the subject name.
* NOTE: If using RPK, then the Public Key does not contain a CN, but the
* content of COAP_DTLS_RPK_CERT_CN is presented for the @p cn parameter.
*
* @param cn The determined CN from the certificate
* @param asn1_public_cert The ASN.1 DER encoded X.509 certificate
@@ -160,8 +164,11 @@ typedef enum coap_pki_key_t {
*/
typedef struct coap_pki_key_pem_t {
const char *ca_file; /**< File location of Common CA in PEM format */
const char *public_cert; /**< File location of Public Cert in PEM format */
const char *private_key; /**< File location of Private Key in PEM format */
const char *public_cert; /**< File location of Public Cert, or Public
Key if RPK, in PEM format */
const char *private_key; /**< File location of Private Key in PEM format.
If RPK and 'EC PRIVATE KEY' this can be used
for both the public_cert and private_key */
} coap_pki_key_pem_t;
/**
@@ -175,7 +182,7 @@ typedef struct coap_pki_key_pem_t {
*/
typedef struct coap_pki_key_pem_buf_t {
const uint8_t *ca_cert; /**< PEM buffer Common CA Cert */
const uint8_t *public_cert; /**< PEM buffer Public Cert */
const uint8_t *public_cert; /**< PEM buffer Public Cert, or Public Key if RPK */
const uint8_t *private_key; /**< PEM buffer Private Key */
size_t ca_cert_len; /**< PEM buffer CA Cert length */
size_t public_cert_len; /**< PEM buffer Public Cert length */
@@ -187,7 +194,7 @@ typedef struct coap_pki_key_pem_buf_t {
*/
typedef struct coap_pki_key_asn1_t {
const uint8_t *ca_cert; /**< ASN1 (DER) Common CA Cert */
const uint8_t *public_cert; /**< ASN1 (DER) Public Cert */
const uint8_t *public_cert; /**< ASN1 (DER) Public Cert, or Public Key if RPK */
const uint8_t *private_key; /**< ASN1 (DER) Private Key */
size_t ca_cert_len; /**< ASN1 CA Cert length */
size_t public_cert_len; /**< ASN1 Public Cert length */
@@ -258,9 +265,10 @@ typedef struct coap_dtls_pki_t {
uint8_t allow_expired_crl; /**< 1 if expired crl is allowed */
uint8_t allow_bad_md_hash; /**< 1 if unsupported MD hashes are allowed */
uint8_t allow_short_rsa_length; /**< 1 if small RSA keysizes are allowed */
uint8_t reserved[4]; /**< Reserved - must be set to 0 for
uint8_t is_rpk_not_cert; /**< 1 is RPK instead of Public Certificate */
uint8_t reserved[3]; /**< Reserved - must be set to 0 for
future compatibility */
/* Size of 4 chosen to align to next
/* Size of 3 chosen to align to next
* parameter, so if newly defined option
* it can use one of the reserverd slot so
* no need to change
+2
View File
@@ -147,7 +147,9 @@ coap_bin_const_t *coap_new_bin_const(const uint8_t *data, size_t size);
*/
void coap_delete_bin_const(coap_bin_const_t *binary);
#ifndef COAP_MAX_STR_CONST_FUNC
#define COAP_MAX_STR_CONST_FUNC 2
#endif /* COAP_MAX_STR_CONST_FUNC */
/**
* Take the specified byte array (text) and create a coap_str_const_t *