Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MaximInterface
Factory.cpp@13:6a6225690c2e, 2017-11-06 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Mon Nov 06 18:12:27 2017 -0600
- Revision:
- 13:6a6225690c2e
- Parent:
- 9:40dd19da90c3
- Child:
- 14:dc839a69379b
Updated to use MaximInterface.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| IanBenzMaxim | 0:33d4e66780c0 | 1 | /******************************************************************************* |
| IanBenzMaxim | 0:33d4e66780c0 | 2 | * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. |
| IanBenzMaxim | 0:33d4e66780c0 | 3 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| IanBenzMaxim | 0:33d4e66780c0 | 5 | * copy of this software and associated documentation files (the "Software"), |
| IanBenzMaxim | 0:33d4e66780c0 | 6 | * to deal in the Software without restriction, including without limitation |
| IanBenzMaxim | 0:33d4e66780c0 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| IanBenzMaxim | 0:33d4e66780c0 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| IanBenzMaxim | 0:33d4e66780c0 | 9 | * Software is furnished to do so, subject to the following conditions: |
| IanBenzMaxim | 0:33d4e66780c0 | 10 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 11 | * The above copyright notice and this permission notice shall be included |
| IanBenzMaxim | 0:33d4e66780c0 | 12 | * in all copies or substantial portions of the Software. |
| IanBenzMaxim | 0:33d4e66780c0 | 13 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| IanBenzMaxim | 0:33d4e66780c0 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| IanBenzMaxim | 0:33d4e66780c0 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| IanBenzMaxim | 0:33d4e66780c0 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
| IanBenzMaxim | 0:33d4e66780c0 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| IanBenzMaxim | 0:33d4e66780c0 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| IanBenzMaxim | 0:33d4e66780c0 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| IanBenzMaxim | 0:33d4e66780c0 | 21 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
| IanBenzMaxim | 0:33d4e66780c0 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
| IanBenzMaxim | 0:33d4e66780c0 | 24 | * Products, Inc. Branding Policy. |
| IanBenzMaxim | 0:33d4e66780c0 | 25 | * |
| IanBenzMaxim | 0:33d4e66780c0 | 26 | * The mere transfer of this software does not imply any licenses |
| IanBenzMaxim | 0:33d4e66780c0 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
| IanBenzMaxim | 0:33d4e66780c0 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
| IanBenzMaxim | 0:33d4e66780c0 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
| IanBenzMaxim | 0:33d4e66780c0 | 30 | * ownership rights. |
| IanBenzMaxim | 0:33d4e66780c0 | 31 | *******************************************************************************/ |
| IanBenzMaxim | 0:33d4e66780c0 | 32 | |
| IanBenzMaxim | 13:6a6225690c2e | 33 | #include <MaximInterface/Devices/DS28C36_DS2476.hpp> |
| IanBenzMaxim | 0:33d4e66780c0 | 34 | #include "SensorNode.hpp" |
| IanBenzMaxim | 0:33d4e66780c0 | 35 | #include "Factory.hpp" |
| IanBenzMaxim | 0:33d4e66780c0 | 36 | |
| IanBenzMaxim | 13:6a6225690c2e | 37 | using namespace MaximInterface; |
| IanBenzMaxim | 13:6a6225690c2e | 38 | |
| IanBenzMaxim | 0:33d4e66780c0 | 39 | // Authority (web server) public key x-component. |
| IanBenzMaxim | 0:33d4e66780c0 | 40 | static const DS28C36::Page authPublicKeyX = { |
| IanBenzMaxim | 13:6a6225690c2e | 41 | 0x7A, 0xB9, 0xCD, 0x00, 0x3F, 0x42, 0xF3, 0x30, 0x76, 0x25, 0x9B, |
| IanBenzMaxim | 13:6a6225690c2e | 42 | 0x6B, 0xFD, 0xC2, 0x6D, 0xE2, 0xDB, 0x59, 0xA8, 0xD9, 0xE0, 0x68, |
| IanBenzMaxim | 13:6a6225690c2e | 43 | 0x3E, 0x1B, 0xFF, 0x50, 0xCB, 0x6C, 0x18, 0xB6, 0xF2, 0xEB}; |
| IanBenzMaxim | 0:33d4e66780c0 | 44 | |
| IanBenzMaxim | 0:33d4e66780c0 | 45 | // Authority (web server) public key y-component. |
| IanBenzMaxim | 0:33d4e66780c0 | 46 | static const DS28C36::Page authPublicKeyY = { |
| IanBenzMaxim | 13:6a6225690c2e | 47 | 0x7F, 0xFC, 0xEE, 0xDD, 0x77, 0xE9, 0x63, 0x07, 0x62, 0x37, 0x33, |
| IanBenzMaxim | 13:6a6225690c2e | 48 | 0x81, 0x17, 0x16, 0x58, 0x75, 0x12, 0x88, 0x85, 0x58, 0x57, 0xC0, |
| IanBenzMaxim | 13:6a6225690c2e | 49 | 0x15, 0xB8, 0x08, 0xDE, 0xB2, 0x3B, 0xD7, 0x8A, 0x9D, 0x2C}; |
| IanBenzMaxim | 0:33d4e66780c0 | 50 | |
| IanBenzMaxim | 0:33d4e66780c0 | 51 | // Authority (web server) private key. |
| IanBenzMaxim | 0:33d4e66780c0 | 52 | static const DS28C36::Page authPrivateKey = { |
| IanBenzMaxim | 13:6a6225690c2e | 53 | 0xC5, 0x45, 0x5F, 0xFB, 0x45, 0xEA, 0x77, 0x0B, 0xF1, 0x1B, 0xE5, |
| IanBenzMaxim | 13:6a6225690c2e | 54 | 0xD2, 0x21, 0xAD, 0x35, 0xF5, 0x0B, 0x61, 0x7F, 0x66, 0xDB, 0xA0, |
| IanBenzMaxim | 13:6a6225690c2e | 55 | 0xBD, 0xB6, 0x64, 0x75, 0x21, 0x4E, 0xB0, 0x98, 0x2D, 0x8E}; |
| IanBenzMaxim | 0:33d4e66780c0 | 56 | |
| IanBenzMaxim | 0:33d4e66780c0 | 57 | // Master secret for SHA-256 HMAC authentication. |
| IanBenzMaxim | 0:33d4e66780c0 | 58 | static const DS28C36::Page masterSecret = { |
| IanBenzMaxim | 13:6a6225690c2e | 59 | 0x6D, 0x52, 0xB6, 0x15, 0xDC, 0x80, 0xCF, 0xB1, 0x25, 0xB0, 0x76, |
| IanBenzMaxim | 13:6a6225690c2e | 60 | 0xB7, 0x7C, 0xAC, 0x00, 0xF2, 0xBC, 0x19, 0xBE, 0xD3, 0x2F, 0x9D, |
| IanBenzMaxim | 13:6a6225690c2e | 61 | 0xC1, 0x42, 0x2A, 0xA5, 0xF6, 0xAE, 0x71, 0xF2, 0x25, 0xB6}; |
| IanBenzMaxim | 0:33d4e66780c0 | 62 | |
| IanBenzMaxim | 13:6a6225690c2e | 63 | error_code provisionAuthenticator(DS28C36 & ds28c36) { |
| IanBenzMaxim | 13:6a6225690c2e | 64 | const DS28C36::Page zeroPage = {}; |
| IanBenzMaxim | 13:6a6225690c2e | 65 | error_code result; |
| IanBenzMaxim | 13:6a6225690c2e | 66 | // Page 0 - 15 |
| IanBenzMaxim | 13:6a6225690c2e | 67 | for (int pageNum = DS28C36::UserData0; pageNum <= DS28C36::UserData15; |
| IanBenzMaxim | 13:6a6225690c2e | 68 | pageNum++) { |
| IanBenzMaxim | 13:6a6225690c2e | 69 | result = ds28c36.writeMemory(pageNum, zeroPage); |
| IanBenzMaxim | 13:6a6225690c2e | 70 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 71 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 72 | } |
| IanBenzMaxim | 13:6a6225690c2e | 73 | // Page 16, 17, 22 |
| IanBenzMaxim | 13:6a6225690c2e | 74 | DS28C36::Page page; |
| IanBenzMaxim | 13:6a6225690c2e | 75 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 76 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 77 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 78 | result = ds28c36.writeMemory(DS28C36::PublicKeyAX, page); |
| IanBenzMaxim | 13:6a6225690c2e | 79 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 80 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 81 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 82 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 83 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 84 | result = ds28c36.writeMemory(DS28C36::PublicKeyAY, page); |
| IanBenzMaxim | 13:6a6225690c2e | 85 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 86 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 87 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 88 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 89 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 90 | result = ds28c36.writeMemory(DS28C36::PrivateKeyA, page); |
| IanBenzMaxim | 13:6a6225690c2e | 91 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 92 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 93 | // Page 18, 19, 23 |
| IanBenzMaxim | 13:6a6225690c2e | 94 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 95 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 96 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 97 | result = ds28c36.writeMemory(DS28C36::PublicKeyBX, page); |
| IanBenzMaxim | 13:6a6225690c2e | 98 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 99 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 100 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 101 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 102 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 103 | result = ds28c36.writeMemory(DS28C36::PublicKeyBY, page); |
| IanBenzMaxim | 13:6a6225690c2e | 104 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 105 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 106 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 107 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 108 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 109 | result = ds28c36.writeMemory(DS28C36::PrivateKeyB, page); |
| IanBenzMaxim | 13:6a6225690c2e | 110 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 111 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 112 | // Page 20, 21, 24 |
| IanBenzMaxim | 13:6a6225690c2e | 113 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 114 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 115 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 116 | result = ds28c36.writeMemory(DS28C36::PublicKeyCX, page); |
| IanBenzMaxim | 13:6a6225690c2e | 117 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 118 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 119 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 120 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 121 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 122 | result = ds28c36.writeMemory(DS28C36::PublicKeyCY, page); |
| IanBenzMaxim | 13:6a6225690c2e | 123 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 124 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 125 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 126 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 127 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 128 | result = ds28c36.writeMemory(DS28C36::PrivateKeyC, page); |
| IanBenzMaxim | 13:6a6225690c2e | 129 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 130 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 131 | // Page 25 |
| IanBenzMaxim | 13:6a6225690c2e | 132 | result = ds28c36.writeMemory(DS28C36::SecretA, masterSecret); |
| IanBenzMaxim | 13:6a6225690c2e | 133 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 134 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 135 | result = ds28c36.writeBuffer(zeroPage.data(), zeroPage.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 136 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 137 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 138 | result = ds28c36.computeAndLockSha2Secret( |
| IanBenzMaxim | 13:6a6225690c2e | 139 | DS28C36::UserData0, DS28C36::SecretNumA, DS28C36::SecretNumA, false); |
| IanBenzMaxim | 13:6a6225690c2e | 140 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 141 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 142 | // Page 26 |
| IanBenzMaxim | 13:6a6225690c2e | 143 | result = readRng(ds28c36, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 144 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 145 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 146 | result = ds28c36.writeMemory(DS28C36::SecretB, page); |
| IanBenzMaxim | 13:6a6225690c2e | 147 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 148 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 149 | // Page 28 |
| IanBenzMaxim | 13:6a6225690c2e | 150 | result = ds28c36.setPageProtection(DS28C36::RomOptions, DS28C36::APH); |
| IanBenzMaxim | 13:6a6225690c2e | 151 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 152 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 153 | // Page 29 |
| IanBenzMaxim | 13:6a6225690c2e | 154 | result = ds28c36.setPageProtection(DS28C36::GpioControl, DS28C36::APH); |
| IanBenzMaxim | 13:6a6225690c2e | 155 | return result; |
| IanBenzMaxim | 0:33d4e66780c0 | 156 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 157 | |
| IanBenzMaxim | 13:6a6225690c2e | 158 | error_code provisionCoprocessor(DS2476 & ds2476) { |
| IanBenzMaxim | 13:6a6225690c2e | 159 | // Page 0, 1 |
| IanBenzMaxim | 13:6a6225690c2e | 160 | const DS2476::Page zeroPage = {}; |
| IanBenzMaxim | 13:6a6225690c2e | 161 | error_code result = ds2476.writeMemory(DS2476::UserData0, zeroPage); |
| IanBenzMaxim | 13:6a6225690c2e | 162 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 163 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 164 | result = ds2476.writeMemory(DS2476::UserData1, zeroPage); |
| IanBenzMaxim | 13:6a6225690c2e | 165 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 166 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 167 | // Page 2 - 13 |
| IanBenzMaxim | 13:6a6225690c2e | 168 | DS2476::Page page; |
| IanBenzMaxim | 13:6a6225690c2e | 169 | for (int pageNum = DS2476::UserData2; pageNum <= DS2476::UserData13; |
| IanBenzMaxim | 13:6a6225690c2e | 170 | pageNum++) { |
| IanBenzMaxim | 13:6a6225690c2e | 171 | result = readRng(ds2476, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 172 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 173 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 174 | result = ds2476.writeMemory(pageNum, page); |
| IanBenzMaxim | 13:6a6225690c2e | 175 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 176 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 177 | } |
| IanBenzMaxim | 13:6a6225690c2e | 178 | // Page 16, 17, 22 |
| IanBenzMaxim | 13:6a6225690c2e | 179 | result = ds2476.generateEcc256KeyPair(DS2476::KeyNumA, false); |
| IanBenzMaxim | 13:6a6225690c2e | 180 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 181 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 182 | // Page 18, 19, 23 |
| IanBenzMaxim | 13:6a6225690c2e | 183 | result = readRng(ds2476, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 184 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 185 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 186 | result = ds2476.writeMemory(DS2476::PublicKeyBX, page); |
| IanBenzMaxim | 13:6a6225690c2e | 187 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 188 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 189 | result = readRng(ds2476, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 190 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 191 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 192 | result = ds2476.writeMemory(DS2476::PublicKeyBY, page); |
| IanBenzMaxim | 13:6a6225690c2e | 193 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 194 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 195 | result = readRng(ds2476, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 196 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 197 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 198 | result = ds2476.writeMemory(DS2476::PrivateKeyB, page); |
| IanBenzMaxim | 13:6a6225690c2e | 199 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 200 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 201 | // Page 20, 21, 24 |
| IanBenzMaxim | 13:6a6225690c2e | 202 | result = ds2476.writeMemory(DS2476::PublicKeyCX, authPublicKeyX); |
| IanBenzMaxim | 13:6a6225690c2e | 203 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 204 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 205 | result = ds2476.writeMemory(DS2476::PublicKeyCY, authPublicKeyY); |
| IanBenzMaxim | 13:6a6225690c2e | 206 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 207 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 208 | result = ds2476.writeMemory(DS2476::PrivateKeyC, authPrivateKey); |
| IanBenzMaxim | 13:6a6225690c2e | 209 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 210 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 211 | // Page 25 |
| IanBenzMaxim | 13:6a6225690c2e | 212 | result = ds2476.writeMemory(DS2476::SecretA, masterSecret); |
| IanBenzMaxim | 13:6a6225690c2e | 213 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 214 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 215 | // Page 26 |
| IanBenzMaxim | 13:6a6225690c2e | 216 | result = readRng(ds2476, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 217 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 218 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 219 | result = ds2476.writeMemory(DS2476::SecretB, page); |
| IanBenzMaxim | 13:6a6225690c2e | 220 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 221 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 222 | // Page 29 |
| IanBenzMaxim | 13:6a6225690c2e | 223 | /*result = ds2476.setPageProtection(DS2476::GpioControl, DS2476::APH); |
| IanBenzMaxim | 13:6a6225690c2e | 224 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 225 | return result;*/ |
| IanBenzMaxim | 13:6a6225690c2e | 226 | // Page 14, 15 |
| IanBenzMaxim | 13:6a6225690c2e | 227 | std::vector<uint8_t> publicKeyA; |
| IanBenzMaxim | 13:6a6225690c2e | 228 | publicKeyA.reserve(page.size() * 2 + 1); |
| IanBenzMaxim | 13:6a6225690c2e | 229 | result = ds2476.readMemory(DS2476::PublicKeyAX, page); |
| IanBenzMaxim | 13:6a6225690c2e | 230 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 231 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 232 | publicKeyA.assign(page.begin(), page.end()); |
| IanBenzMaxim | 13:6a6225690c2e | 233 | result = ds2476.readMemory(DS2476::PublicKeyAY, page); |
| IanBenzMaxim | 13:6a6225690c2e | 234 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 235 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 236 | publicKeyA.insert(publicKeyA.end(), page.begin(), page.end()); |
| IanBenzMaxim | 13:6a6225690c2e | 237 | publicKeyA.insert(publicKeyA.end(), 0x00); // Customization |
| IanBenzMaxim | 13:6a6225690c2e | 238 | result = ds2476.writeBuffer(&publicKeyA[0], publicKeyA.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 239 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 240 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 241 | Ecc256::Signature writeCertificate; |
| IanBenzMaxim | 13:6a6225690c2e | 242 | result = ds2476.generateEcdsaSignature(DS2476::KeyNumC, writeCertificate); |
| IanBenzMaxim | 13:6a6225690c2e | 243 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 244 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 245 | result = ds2476.writeMemory(DS2476::UserData14, writeCertificate.r); |
| IanBenzMaxim | 13:6a6225690c2e | 246 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 247 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 248 | result = ds2476.writeMemory(DS2476::UserData15, writeCertificate.s); |
| IanBenzMaxim | 13:6a6225690c2e | 249 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 250 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 251 | // Remove Private Key C and set protection |
| IanBenzMaxim | 13:6a6225690c2e | 252 | result = readRng(ds2476, page.data(), page.size()); |
| IanBenzMaxim | 13:6a6225690c2e | 253 | if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 254 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 255 | result = ds2476.writeMemory(DS2476::PrivateKeyC, page); |
| IanBenzMaxim | 13:6a6225690c2e | 256 | /*if (result) |
| IanBenzMaxim | 13:6a6225690c2e | 257 | return result; |
| IanBenzMaxim | 13:6a6225690c2e | 258 | result = ds2476.setPageProtection(DS2476::PublicKeyCX, |
| IanBenzMaxim | 13:6a6225690c2e | 259 | DS2476::PageProtection::AUTH);*/ |
| IanBenzMaxim | 13:6a6225690c2e | 260 | return result; |
| IanBenzMaxim | 0:33d4e66780c0 | 261 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 262 | |
| IanBenzMaxim | 13:6a6225690c2e | 263 | error_code checkAuthenticatorProvisioned(DS28C36 & ds28c36, |
| IanBenzMaxim | 13:6a6225690c2e | 264 | bool & provisioned) { |
| IanBenzMaxim | 13:6a6225690c2e | 265 | DS28C36::PageProtection protection; |
| IanBenzMaxim | 13:6a6225690c2e | 266 | const error_code result = |
| IanBenzMaxim | 13:6a6225690c2e | 267 | ds28c36.readPageProtection(DS28C36::GpioControl, protection); |
| IanBenzMaxim | 13:6a6225690c2e | 268 | if (!result) |
| IanBenzMaxim | 13:6a6225690c2e | 269 | provisioned = protection.test(DS28C36::APH); |
| IanBenzMaxim | 13:6a6225690c2e | 270 | return result; |
| IanBenzMaxim | 0:33d4e66780c0 | 271 | } |
| IanBenzMaxim | 0:33d4e66780c0 | 272 | |
| IanBenzMaxim | 13:6a6225690c2e | 273 | error_code checkCoprocessorProvisioned(DS2476 & ds2476, bool & provisioned) { |
| IanBenzMaxim | 13:6a6225690c2e | 274 | DS2476::Page page; |
| IanBenzMaxim | 13:6a6225690c2e | 275 | const error_code result = ds2476.readMemory(DS2476::PublicKeyCX, page); |
| IanBenzMaxim | 13:6a6225690c2e | 276 | if (!result) |
| IanBenzMaxim | 0:33d4e66780c0 | 277 | provisioned = (page == authPublicKeyX); |
| IanBenzMaxim | 13:6a6225690c2e | 278 | return result; |
| IanBenzMaxim | 0:33d4e66780c0 | 279 | } |