@@ -57,6 +57,7 @@ WiFiServer tcpServers[MAX_SOCKETS];
57
57
58
58
WiFiClient bearssl_tcp_client;
59
59
BearSSLClient bearsslClient (bearssl_tcp_client, ArduinoIoTCloudTrustAnchor, ArduinoIoTCloudTrustAnchor_NUM);
60
+ br_x509_trust_anchor customTrustAnchor;
60
61
61
62
int setNet (const uint8_t command[], uint8_t response[])
62
63
{
@@ -1618,6 +1619,63 @@ int downloadOTA(const uint8_t command[], uint8_t response[])
1618
1619
return 6 ;
1619
1620
}
1620
1621
1622
+ int brSetECTrustAnchor (const uint8_t command[], uint8_t response[])
1623
+ {
1624
+ // [0] CMD_START < 0xE0 >
1625
+ // [1] Command < 1 byte >
1626
+ // [2] N args < 1 byte >
1627
+ // [3] dn size < 1 byte MSB >
1628
+ // [4] dn size < 1 byte LSB >
1629
+ // [5] dn < dn size bytes >
1630
+ // [[5] + 5] flags size < 1 byte >
1631
+ // [[5] + 6] flags < 1 byte MSB >
1632
+ // [[5] + 7] flags < 1 byte LSB >
1633
+ // [[5] + 8] curve size < 1 byte >
1634
+ // [[5] + 9] curve < 1 byte MSB >
1635
+ // [[5] + 10] curve < 1 byte LSB >
1636
+ // [[5] + 11] key size < 1 byte MSB >
1637
+ // [[5] + 12] key size < 1 byte LSB >
1638
+ // [[5] + 13] key < key size bytes >
1639
+
1640
+ if (customTrustAnchor.dn .data != NULL ){
1641
+ free (customTrustAnchor.dn .data );
1642
+ }
1643
+
1644
+ if (customTrustAnchor.pkey .key .ec .q != NULL ){
1645
+ free (customTrustAnchor.pkey .key .ec .q );
1646
+ }
1647
+
1648
+ response[2 ] = 1 ;
1649
+ response[3 ] = 1 ;
1650
+ response[4 ] = 0 ;
1651
+
1652
+ uint8_t dnSize = command[4 ];
1653
+ customTrustAnchor.dn .data = (unsigned char *)malloc (dnSize);
1654
+ if (customTrustAnchor.dn .data == NULL ){
1655
+ return 6 ;
1656
+ }
1657
+ memcpy (customTrustAnchor.dn .data , &command[5 ], dnSize);
1658
+ customTrustAnchor.dn .len = dnSize;
1659
+
1660
+ customTrustAnchor.flags = command[7 + dnSize];
1661
+ customTrustAnchor.pkey .key_type = BR_KEYTYPE_EC;
1662
+ customTrustAnchor.pkey .key .ec .curve = command[10 + dnSize];
1663
+
1664
+ uint8_t keySize = command[12 + dnSize];
1665
+ customTrustAnchor.pkey .key .ec .q = (unsigned char *)malloc (keySize);
1666
+ if (customTrustAnchor.pkey .key .ec .q == NULL ){
1667
+ free (customTrustAnchor.dn .data );
1668
+ return 6 ;
1669
+ }
1670
+ memcpy (customTrustAnchor.pkey .key .ec .q , &command[13 + dnSize], keySize);
1671
+ customTrustAnchor.pkey .key .ec .qlen = keySize;
1672
+
1673
+ bearsslClient.setTrustAnchors (&customTrustAnchor, 1 );
1674
+ response[4 ] = 1 ;
1675
+
1676
+ return 6 ;
1677
+ }
1678
+
1621
1679
//
1622
1680
// Low-level BSD-like sockets functions
1623
1681
//
@@ -2094,7 +2152,7 @@ const CommandHandlerType commandHandlers[] = {
2094
2152
setPinMode, setDigitalWrite, setAnalogWrite, getDigitalRead, getAnalogRead, NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ,
2095
2153
2096
2154
// 0x60 -> 0x6f
2097
- writeFile, readFile, deleteFile, existsFile, downloadFile, applyOTA, renameFile, downloadOTA, NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ,
2155
+ writeFile, readFile, deleteFile, existsFile, downloadFile, applyOTA, renameFile, downloadOTA, brSetECTrustAnchor , NULL , NULL , NULL , NULL , NULL , NULL , NULL ,
2098
2156
2099
2157
// Low-level BSD-like sockets functions.
2100
2158
// 0x70 -> 0x7f
0 commit comments