EnclaveConfigDialog.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2016 Intel Corporation. //
  3. // //
  4. // All rights reserved. This program and the accompanying materials //
  5. // are made available under the terms of the Eclipse Public License v1.0 //
  6. // which accompanies this distribution, and is available at //
  7. // http://www.eclipse.org/legal/epl-v10.html //
  8. // //
  9. // Contributors: //
  10. // Intel Corporation - initial implementation and documentation //
  11. ///////////////////////////////////////////////////////////////////////////
  12. package com.intel.sgx.dialogs;
  13. import org.eclipse.jface.preference.JFacePreferences;
  14. import org.eclipse.jface.resource.JFaceResources;
  15. import org.eclipse.swt.SWT;
  16. import org.eclipse.swt.events.ModifyEvent;
  17. import org.eclipse.swt.events.ModifyListener;
  18. import org.eclipse.swt.events.SelectionAdapter;
  19. import org.eclipse.swt.events.SelectionEvent;
  20. import org.eclipse.swt.graphics.Point;
  21. import org.eclipse.swt.layout.GridData;
  22. import org.eclipse.swt.layout.GridLayout;
  23. import org.eclipse.swt.widgets.Button;
  24. import org.eclipse.swt.widgets.Combo;
  25. import org.eclipse.swt.widgets.Composite;
  26. import org.eclipse.swt.widgets.Control;
  27. import org.eclipse.swt.widgets.Group;
  28. import org.eclipse.swt.widgets.Label;
  29. import org.eclipse.swt.widgets.Shell;
  30. import org.eclipse.swt.widgets.Text;
  31. import com.intel.sgx.handlers.EnclaveConfigHandler;
  32. public class EnclaveConfigDialog extends SGXDialogBase {
  33. @SuppressWarnings("unused")
  34. private Shell shell;
  35. private EnclaveConfigHandler enclaveConfig;
  36. private Label statusLabel;
  37. private Text prodID;
  38. private Text isvSvn;
  39. private Text threadStackSize;
  40. private Text globalHeapSize;
  41. private Text tcsNum;
  42. private Combo tcsPolicy;
  43. private Button disableDebug;
  44. public EnclaveConfigDialog(Shell parentshell,EnclaveConfigHandler enclaveConfigHandler) {
  45. super(parentshell);
  46. this.shell = parentshell;
  47. this.enclaveConfig = enclaveConfigHandler;
  48. setShellStyle(SWT.RESIZE | SWT.TITLE);
  49. }
  50. @Override
  51. protected Control createDialogArea(Composite parent) {
  52. Composite container = (Composite) super.createDialogArea(parent);
  53. final GridLayout gridLayout = new GridLayout(3,false);
  54. container.setLayout(gridLayout);
  55. final Group groupLabel1 = new Group(container, SWT.None);
  56. groupLabel1.setLayout(new GridLayout(3,false));
  57. GridData innergrid1 = new GridData(GridData.FILL_HORIZONTAL);
  58. innergrid1.horizontalSpan = 3;
  59. groupLabel1.setLayoutData(innergrid1);
  60. Label warningLabel = new Label(groupLabel1,SWT.BEGINNING | SWT.WRAP);
  61. warningLabel.setText("Note: Use this Menu to change the Enclave settings.");
  62. statusLabel = new Label(container,SWT.BEGINNING | SWT.WRAP);
  63. GridData statusGrid = new GridData(GridData.FILL_HORIZONTAL);
  64. statusGrid.horizontalSpan = 3;
  65. statusLabel.setLayoutData(statusGrid);
  66. statusLabel.setText("");
  67. statusLabel.setForeground(JFaceResources.getColorRegistry().get(JFacePreferences.ERROR_COLOR));
  68. final Group groupLabel2 = new Group(container, SWT.None);
  69. groupLabel2.setLayout(new GridLayout(3,false));
  70. groupLabel2.setText("Modify the Enclave Settings here...");
  71. GridData innergrid = new GridData(GridData.FILL_HORIZONTAL);
  72. innergrid.horizontalSpan = 3;
  73. groupLabel2.setLayoutData(innergrid);
  74. final Label messageLabel0 = new Label(groupLabel2, SWT.NONE);
  75. messageLabel0.setText("Product ID:");
  76. messageLabel0.setLayoutData(new GridData(GridData.BEGINNING));
  77. prodID = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
  78. GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
  79. gridData.horizontalSpan = 2;
  80. gridData.widthHint = 400;
  81. prodID.setLayoutData(gridData);
  82. prodID.setText(enclaveConfig.prodId);
  83. prodID.addModifyListener(new ModifyListener() {
  84. @Override
  85. public void modifyText(ModifyEvent modifyEvent) {
  86. statusLabel.setText("");
  87. enclaveConfig.prodId = prodID.getText();
  88. }
  89. });
  90. final Label messageLabel1 = new Label(groupLabel2, SWT.NONE);
  91. messageLabel1.setText("ISV SVN:");
  92. messageLabel1.setLayoutData(new GridData(GridData.BEGINNING));
  93. isvSvn = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
  94. isvSvn.setLayoutData(gridData);
  95. isvSvn.setText(enclaveConfig.isvSvn);
  96. isvSvn.addModifyListener(new ModifyListener() {
  97. @Override
  98. public void modifyText(ModifyEvent modifyEvent) {
  99. statusLabel.setText("");
  100. enclaveConfig.isvSvn = isvSvn.getText();
  101. }
  102. });
  103. final Label messageLabel2 = new Label(groupLabel2, SWT.NONE);
  104. messageLabel2.setText("Thread Stack Size:");
  105. messageLabel2.setLayoutData(new GridData(GridData.BEGINNING));
  106. threadStackSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
  107. threadStackSize.setLayoutData(gridData);
  108. threadStackSize.setText(enclaveConfig.threadStackSize);
  109. threadStackSize.addModifyListener(new ModifyListener() {
  110. @Override
  111. public void modifyText(ModifyEvent modifyEvent) {
  112. enclaveConfig.threadStackSize = threadStackSize.getText();
  113. if(!(threadStackSize.getText().matches("0x[0-9a-fA-F]{1,}000")))
  114. {
  115. statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned.");
  116. }
  117. else
  118. {
  119. if(!(enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000")))
  120. statusLabel.setText("Error: The Global Heap Size value must be Page Aligned.");
  121. else
  122. statusLabel.setText("");
  123. }
  124. }
  125. });
  126. final Label messageLabel3 = new Label(groupLabel2, SWT.NONE);
  127. messageLabel3.setText("Global Heap Size:");
  128. messageLabel3.setLayoutData(new GridData(GridData.BEGINNING));
  129. globalHeapSize = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
  130. globalHeapSize.setLayoutData(gridData);
  131. globalHeapSize.setText(enclaveConfig.globalHeapSize);
  132. globalHeapSize.addModifyListener(new ModifyListener() {
  133. @Override
  134. public void modifyText(ModifyEvent modifyEvent) {
  135. enclaveConfig.globalHeapSize = globalHeapSize.getText();
  136. if(!(globalHeapSize.getText().matches("0x[0-9a-fA-F]{1,}000")))
  137. {
  138. statusLabel.setText("Error: The Global Heap Size value must be Page Aligned.");
  139. }
  140. else
  141. {
  142. if(!(enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000")))
  143. statusLabel.setText("Error: The Thread Stack Size value must be Page Aligned.");
  144. else
  145. statusLabel.setText("");
  146. }
  147. }
  148. });
  149. final Label messageLabel4 = new Label(groupLabel2, SWT.NONE);
  150. messageLabel4.setText("TCS Number:");
  151. messageLabel4.setLayoutData(new GridData(GridData.BEGINNING));
  152. tcsNum = new Text(groupLabel2, SWT.SINGLE | SWT.BORDER);
  153. tcsNum.setLayoutData(gridData);
  154. tcsNum.setText(enclaveConfig.tcsNum);
  155. tcsNum.addModifyListener(new ModifyListener() {
  156. @Override
  157. public void modifyText(ModifyEvent modifyEvent) {
  158. statusLabel.setText("");
  159. enclaveConfig.tcsNum = tcsNum.getText();
  160. }
  161. });
  162. final Label messageLabel5 = new Label(groupLabel2, SWT.NONE);
  163. messageLabel5.setText("TCS Policy:");
  164. messageLabel5.setLayoutData(new GridData(GridData.BEGINNING));
  165. final String[] items = {"Unbound","Bound"};
  166. tcsPolicy = new Combo(groupLabel2, SWT.DROP_DOWN | SWT.READ_ONLY | SWT.BORDER);
  167. tcsPolicy.setItems(items);
  168. String item = items[Integer.parseInt(enclaveConfig.tcsPolicy)];
  169. int index = tcsPolicy.indexOf(item);
  170. tcsPolicy.select(index < 0 ? 0 : index);
  171. tcsPolicy.setLayoutData(gridData);
  172. tcsPolicy.addSelectionListener(new SelectionAdapter() {
  173. public void widgetSelected(SelectionEvent e){
  174. statusLabel.setText("");
  175. enclaveConfig.tcsPolicy = (tcsPolicy.getSelectionIndex() == 0 ? "0" : "1");
  176. }
  177. });
  178. final Label messageLabel6 = new Label(groupLabel2, SWT.NONE);
  179. messageLabel6.setText("Disable Debug:");
  180. messageLabel6.setLayoutData(new GridData(GridData.BEGINNING));
  181. disableDebug = new Button(groupLabel2,SWT.CHECK);
  182. GridData gridData1 = new GridData(GridData.FILL_HORIZONTAL);
  183. disableDebug.setLayoutData(gridData1);
  184. disableDebug.setSelection(enclaveConfig.disableDebug.equals("1")?true:false);
  185. disableDebug.addSelectionListener(new SelectionAdapter(){
  186. public void widgetSelected(SelectionEvent e){
  187. statusLabel.setText("");
  188. enclaveConfig.disableDebug = disableDebug.getSelection()?"1":"0";
  189. }
  190. });
  191. if(statusLabel.getText() != null){
  192. statusLabel.setVisible(true);
  193. }
  194. else{
  195. statusLabel.setVisible(false);
  196. }
  197. return container;
  198. }
  199. @Override
  200. protected void configureShell(Shell newShell) {
  201. super.configureShell(newShell);
  202. newShell.setText("Enclave Configuration Settings:");
  203. }
  204. @Override
  205. protected Point getInitialSize(){
  206. return new Point(450,400);
  207. }
  208. @Override
  209. protected
  210. void okPressed(){
  211. enclaveConfig.prodId = this.prodID.getText();
  212. enclaveConfig.isvSvn = this.isvSvn.getText();
  213. enclaveConfig.threadStackSize = this.threadStackSize.getText();
  214. enclaveConfig.globalHeapSize = this.globalHeapSize.getText();
  215. enclaveConfig.tcsNum = this.tcsNum.getText();
  216. enclaveConfig.tcsPolicy = this.tcsPolicy.getSelectionIndex() == 0 ? "0" : "1";
  217. enclaveConfig.disableDebug = disableDebug.getSelection()?"1":"0";
  218. if((statusLabel.getText() == "") && (enclaveConfig.globalHeapSize.matches("0x[0-9a-fA-F]{1,}000")) && (enclaveConfig.threadStackSize.matches("0x[0-9a-fA-F]{1,}000")))
  219. super.okPressed();
  220. }
  221. }