You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/31 22:30:40 UTC

[GitHub] benmccrea closed pull request #1153: Apply fixes for cbor data in log entries

benmccrea closed pull request #1153: Apply fixes for cbor data in log entries
URL: https://github.com/apache/mynewt-core/pull/1153
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/crypto/mbedtls/include/mbedtls/config.h b/crypto/mbedtls/include/mbedtls/config.h
index 7101ed7ac9..22318f0da5 100644
--- a/crypto/mbedtls/include/mbedtls/config.h
+++ b/crypto/mbedtls/include/mbedtls/config.h
@@ -1778,7 +1778,7 @@
  *
  * Module:  library/blowfish.c
  */
-#define MBEDTLS_BLOWFISH_C
+//#define MBEDTLS_BLOWFISH_C
 
 /**
  * \def MBEDTLS_CAMELLIA_C
@@ -1833,7 +1833,7 @@
  *      MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256
  *      MBEDTLS_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256
  */
-#define MBEDTLS_CAMELLIA_C
+//#define MBEDTLS_CAMELLIA_C
 
 /**
  * \def MBEDTLS_CCM_C
@@ -1912,7 +1912,7 @@
  *
  * This module provides debugging functions.
  */
-#define MBEDTLS_DEBUG_C
+//#define MBEDTLS_DEBUG_C
 
 /**
  * \def MBEDTLS_DES_C
@@ -2243,7 +2243,7 @@
  *
  * This modules adds support for the VIA PadLock on x86.
  */
-#define MBEDTLS_PADLOCK_C
+//#define MBEDTLS_PADLOCK_C
 
 /**
  * \def MBEDTLS_PEM_PARSE_C
diff --git a/crypto/mbedtls/include/mbedtls/config_mynewt.h b/crypto/mbedtls/include/mbedtls/config_mynewt.h
index fff0fbad92..b1bf4c5a44 100644
--- a/crypto/mbedtls/include/mbedtls/config_mynewt.h
+++ b/crypto/mbedtls/include/mbedtls/config_mynewt.h
@@ -180,6 +180,35 @@ extern "C" {
 #undef MBEDTLS_ECP_DP_CURVE25519_ENABLED
 #endif
 
+#if MYNEWT_VAL(MBEDTLS_AES_C) == 0
+#undef MBEDTLS_AES_C
+#endif
+#if MYNEWT_VAL(MBEDTLS_ARC4_C) == 0
+#undef MBEDTLS_ARC4_C
+#endif
+#if MYNEWT_VAL(MBEDTLS_BLOWFISH_C) == 0
+#undef MBEDTLS_BLOWFISH_C
+#endif
+#if MYNEWT_VAL(MBEDTLS_CAMELLIA_C) == 0
+#undef MBEDTLS_CAMELLIA_C
+#endif
+#if MYNEWT_VAL(MBEDTLS_DES_C) == 0
+#undef MBEDTLS_DES_C
+#endif
+
+#if MYNEWT_VAL(MBEDTLS_CIPHER_MODE_CBC) == 0
+#undef MBEDTLS_CIPHER_MODE_CBC
+#endif
+#if MYNEWT_VAL(MBEDTLS_CIPHER_MODE_CFB) == 0
+#undef MBEDTLS_CIPHER_MODE_CBC
+#endif
+#if MYNEWT_VAL(MBEDTLS_CIPHER_MODE_CTR) == 0
+#undef MBEDTLS_CIPHER_MODE_CTR
+#endif
+#if MYNEWT_VAL(MBEDTLS_CCM_C) == 0
+#undef MBEDTLS_CCM_C
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/crypto/mbedtls/syscfg.yml b/crypto/mbedtls/syscfg.yml
index 5aa15c5b2d..11b50b0919 100644
--- a/crypto/mbedtls/syscfg.yml
+++ b/crypto/mbedtls/syscfg.yml
@@ -19,28 +19,51 @@
 # Package: crypto/mbedtls
 
 syscfg.defs:
-    # Enabled curves
-    MBEDTLS_ECP_DP_SECP192R1:
-        value: 0
-    MBEDTLS_ECP_DP_SECP224R1:
-        value: 1
-    MBEDTLS_ECP_DP_SECP256R1:
-        value: 0
-    MBEDTLS_ECP_DP_SECP384R1:
-        value: 0
-    MBEDTLS_ECP_DP_SECP521R1:
-        value: 0
-    MBEDTLS_ECP_DP_SECP192K1:
-        value: 0
-    MBEDTLS_ECP_DP_SECP224K1:
-        value: 0
-    MBEDTLS_ECP_DP_SECP256K1:
-        value: 0
-    MBEDTLS_ECP_DP_BP256R1:
-        value: 0
-    MBEDTLS_ECP_DP_BP384R1:
-        value: 0
-    MBEDTLS_ECP_DP_BP512R1:
-        value: 0
-    MBEDTLS_ECP_DP_CURVE25519:
-         value: 0
+  # Enabled curves
+  MBEDTLS_ECP_DP_SECP192R1:
+    value: 0
+  MBEDTLS_ECP_DP_SECP224R1:
+    value: 1
+  MBEDTLS_ECP_DP_SECP256R1:
+    value: 0
+  MBEDTLS_ECP_DP_SECP384R1:
+    value: 0
+  MBEDTLS_ECP_DP_SECP521R1:
+    value: 0
+  MBEDTLS_ECP_DP_SECP192K1:
+    value: 0
+  MBEDTLS_ECP_DP_SECP224K1:
+    value: 0
+  MBEDTLS_ECP_DP_SECP256K1:
+    value: 0
+  MBEDTLS_ECP_DP_BP256R1:
+    value: 0
+  MBEDTLS_ECP_DP_BP384R1:
+    value: 0
+  MBEDTLS_ECP_DP_BP512R1:
+    value: 0
+  MBEDTLS_ECP_DP_CURVE25519:
+    value: 0
+
+  # Ciphers
+  MBEDTLS_AES_C:
+    value: 1
+  MBEDTLS_ARC4_C:
+    value: 0
+  MBEDTLS_BLOWFISH_C:
+    value: 0
+  MBEDTLS_CAMELLIA_C:
+    value: 0
+  MBEDTLS_DES_C:
+    description: '3DES'
+    value: 0
+
+  # Cipher modes
+  MBEDTLS_CIPHER_MODE_CBC:
+    value: 0
+  MBEDTLS_CIPHER_MODE_CFB:
+    value: 0
+  MBEDTLS_CIPHER_MODE_CTR:
+    value: 0
+  MBEDTLS_CCM_C:
+    value: 0
diff --git a/crypto/mbedtls/test/syscfg.yml b/crypto/mbedtls/test/syscfg.yml
new file mode 100644
index 0000000000..8e947f5e57
--- /dev/null
+++ b/crypto/mbedtls/test/syscfg.yml
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+syscfg.vals:
+  MBEDTLS_ECP_DP_SECP192R1: 1
+  MBEDTLS_ECP_DP_SECP224R1: 1
+  MBEDTLS_ECP_DP_SECP256R1: 1
+  MBEDTLS_ECP_DP_SECP384R1: 1
+  MBEDTLS_ECP_DP_SECP521R1: 1
+  MBEDTLS_ECP_DP_SECP192K1: 1
+  MBEDTLS_ECP_DP_SECP224K1: 1
+  MBEDTLS_ECP_DP_SECP256K1: 1
+  MBEDTLS_ECP_DP_BP256R1: 1
+  MBEDTLS_ECP_DP_BP384R1: 1
+  MBEDTLS_ECP_DP_BP512R1: 1
+  MBEDTLS_ECP_DP_CURVE25519: 1
+
+  # Ciphers
+  MBEDTLS_AES_C: 1
+  MBEDTLS_ARC4_C: 1
+  MBEDTLS_BLOWFISH_C: 1
+  MBEDTLS_CAMELLIA_C: 1
+  MBEDTLS_DES_C: 1
+
+  # Cipher modes
+  MBEDTLS_CIPHER_MODE_CBC: 1
+  MBEDTLS_CIPHER_MODE_CFB: 1
+  MBEDTLS_CIPHER_MODE_CTR: 1
+  MBEDTLS_CCM_C: 1
diff --git a/encoding/tinycbor/include/tinycbor/cbor.h b/encoding/tinycbor/include/tinycbor/cbor.h
index 0d280ba70d..528f666cba 100644
--- a/encoding/tinycbor/include/tinycbor/cbor.h
+++ b/encoding/tinycbor/include/tinycbor/cbor.h
@@ -209,6 +209,7 @@ CBOR_INLINE_API CborError cbor_encode_double(CborEncoder *encoder, double value)
 
 CBOR_API CborError cbor_encoder_create_array(CborEncoder *encoder, CborEncoder *arrayEncoder, size_t length);
 CBOR_API CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder, size_t length);
+CBOR_API CborError cbor_encoder_create_indef_byte_string(CborEncoder *encoder, CborEncoder *stringEncoder);
 CBOR_API CborError cbor_encoder_close_container(CborEncoder *encoder, const CborEncoder *containerEncoder);
 CBOR_API CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder);
 
diff --git a/encoding/tinycbor/src/cborencoder.c b/encoding/tinycbor/src/cborencoder.c
index 5e0e0a2864..e523ffb0e5 100644
--- a/encoding/tinycbor/src/cborencoder.c
+++ b/encoding/tinycbor/src/cborencoder.c
@@ -492,10 +492,24 @@ CborError cbor_encoder_create_map(CborEncoder *encoder, CborEncoder *mapEncoder,
 }
 
 /**
- * Closes the CBOR container (array or map) provided by \a containerEncoder and
- * updates the CBOR stream provided by \a encoder. Both parameters must be the
- * same as were passed to cbor_encoder_create_array() or
- * cbor_encoder_create_map().
+ * Creates a indefinite-length byte string in the CBOR stream provided by
+ * \a encoder and initializes \a stringEncoder so that chunks of original string
+ * can be added using the CborEncoder functions. The string must be terminated by
+ * calling cbor_encoder_close_container() with the same \a encoder and
+ * \a stringEncoder parameters.
+ *
+ * \sa cbor_encoder_create_array
+ */
+CborError cbor_encoder_create_indef_byte_string(CborEncoder *encoder, CborEncoder *stringEncoder)
+{
+    return create_container(encoder, stringEncoder, CborIndefiniteLength, ByteStringType << MajorTypeShift);
+}
+
+/**
+ * Closes the CBOR container (array, map or indefinite-length string) provided
+ * by \a containerEncoder and updates the CBOR stream provided by \a encoder.
+ * Both parameters must be the same as were passed to cbor_encoder_create_array() or
+ * cbor_encoder_create_map() or cbor_encoder_create_indef_byte_string().
  *
  * This function does not verify that the number of items (or pair of items, in
  * the case of a map) was correct. To execute that verification, call
diff --git a/hw/drivers/lp5523/src/lp5523.c b/hw/drivers/lp5523/src/lp5523.c
index 55cccc9305..3e77fa57c6 100644
--- a/hw/drivers/lp5523/src/lp5523.c
+++ b/hw/drivers/lp5523/src/lp5523.c
@@ -840,10 +840,10 @@ lp5523_config(struct lp5523 *lp, struct lp5523_cfg *cfg)
 
     itf->si_addr = LP5523_I2C_BASE_ADDR + cfg->asel;
 
-    rc = lp5523_reset(itf);
-    if (rc != 0) {
-        return rc;
-    }
+//    rc = lp5523_reset(itf);
+//    if (rc != 0) {
+//        return rc;
+//    }
 
     /* chip enable */
     rc = lp5523_set_enable(itf, 1);
diff --git a/sys/console/full/src/uart_console.c b/sys/console/full/src/uart_console.c
index 31a462baa3..49881ff1d3 100644
--- a/sys/console/full/src/uart_console.c
+++ b/sys/console/full/src/uart_console.c
@@ -89,6 +89,10 @@ console_queue_char(struct uart_dev *uart_dev, uint8_t ch)
 {
     int sr;
 
+    if ((uart_dev->ud_dev.od_flags & OS_DEV_F_STATUS_OPEN) == 0) {
+        return;
+    }
+
     OS_ENTER_CRITICAL(sr);
     while (console_ring_is_full(&cr_tx)) {
         /* TX needs to drain */
diff --git a/sys/log/full/src/log_nmgr.c b/sys/log/full/src/log_nmgr.c
index b2addbae46..01190979e3 100644
--- a/sys/log/full/src/log_nmgr.c
+++ b/sys/log/full/src/log_nmgr.c
@@ -67,8 +67,7 @@ log_nmgr_encode_entry(struct log *log, struct log_offset *log_offset,
                       void *dptr, uint16_t len)
 {
     struct log_entry_hdr ueh;
-    char data[128];
-    int dlen;
+    uint8_t data[128];
     int rc;
     int rsp_len;
     CborError g_err = CborNoError;
@@ -77,6 +76,7 @@ log_nmgr_encode_entry(struct log *log, struct log_offset *log_offset,
     struct CborCntWriter cnt_writer;
     CborEncoder cnt_encoder;
 #if MYNEWT_VAL(LOG_VERSION) > 2
+    CborEncoder str_encoder;
     int off;
 #endif
 
@@ -107,38 +107,8 @@ log_nmgr_encode_entry(struct log *log, struct log_offset *log_offset,
         goto err;
     }
 
-#if MYNEWT_VAL(LOG_VERSION) > 2
-    switch (ueh.ue_etype) {
-    case LOG_ETYPE_STRING:
-        /* Trim string data to 128 characters to keep it consistent with v2 */
-        dlen = min(len-sizeof(ueh), 128);
-
-        rc = log_read(log, dptr, data, sizeof(ueh), dlen);
-        if (rc < 0) {
-            rc = OS_ENOENT;
-            goto err;
-        }
-        data[rc] = 0;
-        break;
-    case LOG_ETYPE_CBOR:
-        /* We can't trim CBOR stream - need to put it complete */
-        dlen = len - sizeof(ueh);
-        break;
-    case LOG_ETYPE_BINARY:
-        /* XXX just some placeholder for now, perhaps should be base64 encoded? */
-        strcpy(data, "<binary>");
-        dlen = strlen(data);
-        break;
-    default:
-        assert(0);
-        strcpy(data, "<??\?>");
-        dlen = strlen(data);
-        break;
-    }
-#else
-    dlen = min(len-sizeof(ueh), 128);
-
-    rc = log_read(log, dptr, data, sizeof(ueh), dlen);
+#if MYNEWT_VAL(LOG_VERSION) < 3
+    rc = log_read(log, dptr, data, sizeof(ueh), min(len - sizeof(ueh), 128));
     if (rc < 0) {
         rc = OS_ENOENT;
         goto err;
@@ -159,21 +129,41 @@ log_nmgr_encode_entry(struct log *log, struct log_offset *log_offset,
     case LOG_ETYPE_CBOR:
         g_err |= cbor_encode_text_stringz(&rsp, "type");
         g_err |= cbor_encode_text_stringz(&rsp, "cbor");
-        /* Just encode something short and CBOR stream will be inserted here later */
-        g_err |= cbor_encode_text_stringz(&rsp, "msg");
-        g_err |= cbor_encode_undefined(&rsp);
-        rsp_len += dlen;
         break;
-    case LOG_ETYPE_STRING:
     case LOG_ETYPE_BINARY:
+        g_err |= cbor_encode_text_stringz(&rsp, "type");
+        g_err |= cbor_encode_text_stringz(&rsp, "bin");
+        break;
+    case LOG_ETYPE_STRING:
     default:
-        g_err |= cbor_encode_text_stringz(&rsp, "msg");
-        g_err |= cbor_encode_text_stringz(&rsp, data);
+        /* no need for type here */
+        g_err |= cbor_encode_text_stringz(&rsp, "type");
+        g_err |= cbor_encode_text_stringz(&rsp, "str");
         break;
     }
+
+    g_err |= cbor_encode_text_stringz(&rsp, "msg");
+
+    /*
+     * Write entry data as byte string. Since this may not fit into single
+     * chunk of data we will write as indefinite-length byte string which is
+     * basically a indefinite-length container with definite-length strings
+     * inside.
+     */
+    g_err |= cbor_encoder_create_indef_byte_string(&rsp, &str_encoder);
+    for (off = sizeof(ueh); (off < len) && !g_err; ) {
+        rc = log_read(log, dptr, data, off, sizeof(data));
+        if (rc < 0) {
+            g_err |= 1;
+            break;
+        }
+        g_err |= cbor_encode_byte_string(&str_encoder, data, rc);
+        off += rc;
+    }
+    g_err |= cbor_encoder_close_container(&rsp, &str_encoder);
 #else
     g_err |= cbor_encode_text_stringz(&rsp, "msg");
-    g_err |= cbor_encode_text_stringz(&rsp, data);
+    g_err |= cbor_encode_text_stringz(&rsp, (char *)data);
 #endif
     g_err |= cbor_encode_text_stringz(&rsp, "ts");
     g_err |= cbor_encode_int(&rsp, ueh.ue_ts);
@@ -202,33 +192,41 @@ log_nmgr_encode_entry(struct log *log, struct log_offset *log_offset,
     case LOG_ETYPE_CBOR:
         g_err |= cbor_encode_text_stringz(&rsp, "type");
         g_err |= cbor_encode_text_stringz(&rsp, "cbor");
-        g_err |= cbor_encode_text_stringz(&rsp, "msg");
-        /*
-         * Write CBOR data from log entry directly to CBOR encoder. This will
-         * for a valid CBOR stream assuming log entry is either a primitive
-         * or a container.
-         */
-        for (off = sizeof(ueh); (off < len) && !g_err; ) {
-            rc = log_read(log, dptr, data, off, sizeof(data));
-            if (rc < 0) {
-                g_err |= 1;
-                break;
-            }
-            g_err |= rsp.writer->write(rsp.writer, data, rc);
-
-            off += rc;
-        }
         break;
-    case LOG_ETYPE_STRING:
     case LOG_ETYPE_BINARY:
+        g_err |= cbor_encode_text_stringz(&rsp, "type");
+        g_err |= cbor_encode_text_stringz(&rsp, "bin");
+        break;
+    case LOG_ETYPE_STRING:
     default:
-        g_err |= cbor_encode_text_stringz(&rsp, "msg");
-        g_err |= cbor_encode_text_stringz(&rsp, data);
+        /* no need for type here */
+        g_err |= cbor_encode_text_stringz(&rsp, "type");
+        g_err |= cbor_encode_text_stringz(&rsp, "str");
         break;
     }
+
+    g_err |= cbor_encode_text_stringz(&rsp, "msg");
+
+    /*
+     * Write entry data as byte string. Since this may not fit into single
+     * chunk of data we will write as indefinite-length byte string which is
+     * basically a indefinite-length container with definite-length strings
+     * inside.
+     */
+    g_err |= cbor_encoder_create_indef_byte_string(&rsp, &str_encoder);
+    for (off = sizeof(ueh); (off < len) && !g_err; ) {
+        rc = log_read(log, dptr, data, off, sizeof(data));
+        if (rc < 0) {
+            g_err |= 1;
+            break;
+        }
+        g_err |= cbor_encode_byte_string(&str_encoder, data, rc);
+        off += rc;
+    }
+    g_err |= cbor_encoder_close_container(&rsp, &str_encoder);
 #else
     g_err |= cbor_encode_text_stringz(&rsp, "msg");
-    g_err |= cbor_encode_text_stringz(&rsp, data);
+    g_err |= cbor_encode_text_stringz(&rsp, (char *)data);
 #endif
     g_err |= cbor_encode_text_stringz(&rsp, "ts");
     g_err |= cbor_encode_int(&rsp, ueh.ue_ts);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services