public void UpdateDeviceKey(MFDevice device, PublicKeyUpdateInfo.KeyIndex index, byte[] publicKey, byte[] publicKeySignature) { MFConfigHelper cfg = new MFConfigHelper(device); PublicKeyUpdateInfo pku = new PublicKeyUpdateInfo(); pku.NewPublicKey = publicKey; pku.NewPublicKeySignature = publicKeySignature; pku.PublicKeyIndex = index; cfg.UpdatePublicKey(pku); cfg.Dispose(); cfg = null; }
private void OnConfigure(object sender, EventArgs e) { string fileNewKey = comboBoxFile1.Text; string fileOldKey = comboBoxPrivateKey.Text; m_KeyUpdateInfo = new PublicKeyUpdateInfo(); m_KeyUpdateInfo.PublicKeyIndex = (comboBoxKeyIndex.SelectedIndex == 1 ? PublicKeyUpdateInfo.KeyIndex.DeploymentKey : PublicKeyUpdateInfo.KeyIndex.FirmwareKey); try { m_KeyUpdateInfo.NewPublicKey = m_keyTool.LoadKeyPair(fileNewKey).PublicKey; } catch { MessageBox.Show(this, string.Format(Properties.Resources.ErrorFileInvalid, fileNewKey), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } if (comboBoxPrivateKey.Enabled) { KeyPair keyPairSign = m_keyTool.LoadKeyPair(fileOldKey); byte[] oldKey = keyPairSign.PrivateKey; m_KeyUpdateInfo.NewPublicKeySignature = m_keyTool.SignData(m_KeyUpdateInfo.NewPublicKey, oldKey); } m_cfgHelper.MaintainConnection = false; if (!m_cfgHelper.UpdatePublicKey(m_KeyUpdateInfo)) { MessageBox.Show((IWin32Window)this, Properties.Resources.ErrorUnableToUpdateKey, Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { DialogResult = DialogResult.OK; } }
/// <summary> /// Updates the given public signature key /// </summary> /// <param name="newKeyInfo">Information that is used to update the key: including the new key, /// the new key signature (if the key has already been set), and the key index</param> /// <returns>true if successful false otherwise</returns> public bool UpdatePublicKey(PublicKeyUpdateInfo newKeyInfo) { bool fRequiresReboot = false; bool retVal = false; _DBG.PublicKeyIndex keyIndex; if(!m_init) { InitializeConfigData(); } if (!m_init) throw new MFInvalidConfigurationSectorException(); if (!m_fStaticCfgOK) throw new MFInvalidConfigurationSectorException(); if ((newKeyInfo.NewPublicKey.Length) != TINYBOOTER_KEY_CONFIG.c_RSAKeyLength) throw new MFInvalidKeyLengthException(); if(newKeyInfo.PublicKeyIndex == PublicKeyUpdateInfo.KeyIndex.DeploymentKey) { keyIndex = _DBG.PublicKeyIndex.DeploymentKey; fRequiresReboot = m_deployKeyLocked; } else { keyIndex = _DBG.PublicKeyIndex.FirmwareKey; fRequiresReboot = m_firmwareKeyLocked; } if (m_device.DbgEngine.ConnectionSource != Microsoft.SPOT.Debugger.ConnectionSource.TinyBooter) { if (!m_device.ConnectToTinyBooter()) { throw new MFDeviceNoResponseException(); } } if(m_device.DbgEngine.UpdateSignatureKey(keyIndex, newKeyInfo.NewPublicKeySignature, newKeyInfo.NewPublicKey, null)) { // if the key was previously set it requires an erase and a write which requires a reboot on some devices if (fRequiresReboot) { m_device.Reboot(true); } retVal = true; } PingConnectionType conn = m_device.Ping(); if (PingConnectionType.TinyBooter == conn) { m_device.Execute(c_EnumerateAndLaunchAddr); } return retVal; }
/// <summary> /// Updates the given public signature key /// </summary> /// <param name="newKeyInfo">Information that is used to update the key: including the new key, /// the new key signature (if the key has already been set), and the key index</param> /// <returns>true if successful false otherwise</returns> public bool UpdatePublicKey(PublicKeyUpdateInfo newKeyInfo) { bool fRequiresReboot = false; bool retVal = false; _DBG.PublicKeyIndex keyIndex; if (!m_init) { InitializeConfigData(); } if (!m_init) { throw new MFInvalidConfigurationSectorException(); } if (!m_fStaticCfgOK) { throw new MFInvalidConfigurationSectorException(); } if ((newKeyInfo.NewPublicKey.Length) != TINYBOOTER_KEY_CONFIG.c_RSAKeyLength) { throw new MFInvalidKeyLengthException(); } if (newKeyInfo.PublicKeyIndex == PublicKeyUpdateInfo.KeyIndex.DeploymentKey) { keyIndex = _DBG.PublicKeyIndex.DeploymentKey; fRequiresReboot = m_deployKeyLocked; } else { keyIndex = _DBG.PublicKeyIndex.FirmwareKey; fRequiresReboot = m_firmwareKeyLocked; } if (m_device.DbgEngine.ConnectionSource != Microsoft.SPOT.Debugger.ConnectionSource.TinyBooter) { if (!m_device.ConnectToTinyBooter()) { throw new MFDeviceNoResponseException(); } } if (m_device.DbgEngine.UpdateSignatureKey(keyIndex, newKeyInfo.NewPublicKeySignature, newKeyInfo.NewPublicKey, null)) { // if the key was previously set it requires an erase and a write which requires a reboot on some devices if (fRequiresReboot) { m_device.Reboot(true); } retVal = true; } PingConnectionType conn = m_device.Ping(); if (PingConnectionType.TinyBooter == conn) { m_device.Execute(c_EnumerateAndLaunchAddr); } return(retVal); }
public void UpdateDeviceKey(MFDevice device, PublicKeyUpdateInfo.KeyIndex index, byte[] publicKey) { UpdateDeviceKey(device, index, publicKey, null); }