TwoStepSignDialogBase.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ///////////////////////////////////////////////////////////////////////////
  2. // Copyright (c) 2018 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 java.io.File;
  14. import java.util.Scanner;
  15. import javax.swing.JOptionPane;
  16. import org.eclipse.swt.SWT;
  17. import org.eclipse.swt.events.SelectionEvent;
  18. import org.eclipse.swt.events.SelectionListener;
  19. import org.eclipse.swt.widgets.FileDialog;
  20. import org.eclipse.swt.widgets.Shell;
  21. import org.eclipse.swt.widgets.Text;
  22. public abstract class TwoStepSignDialogBase extends SGXDialogBase {
  23. public Text enclaveFileField;
  24. public Text hashFileField;
  25. public Text externalSignPublicKeyFileField;
  26. public Text externalSignedHashFileField;
  27. public Text outputSignedEnclaveFileField;
  28. public TwoStepSignDialogBase(Shell parentShell) {
  29. super(parentShell);
  30. setShellStyle(SWT.RESIZE | SWT.TITLE);
  31. this.shell = TwoStepSignDialogBase.this.getParentShell();
  32. }
  33. // for each field, a corresponding listener
  34. protected SelectionListener enclaveFileSelectionListener = new SelectionListener() {
  35. @Override
  36. public void widgetSelected(SelectionEvent event) {
  37. String result = enclaveFileField.getText();
  38. FileDialog dialog = new FileDialog(shell, SWT.OPEN);
  39. dialog.setFilterExtensions(new String[]{"*.so"} );
  40. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  41. if (result != null && !result.isEmpty()) {
  42. dialog.setFilterPath(new File(result).getParent());
  43. } else {
  44. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  45. }
  46. result = dialog.open();
  47. enclaveFileField.setText(result);
  48. hashFileField.setText(result + ".hex");
  49. if (outputSignedEnclaveFileField != null){
  50. String outputSignedEnclavePath = result;
  51. if(outputSignedEnclavePath.endsWith(".so"))
  52. {
  53. outputSignedEnclavePath =
  54. outputSignedEnclavePath.substring(0,outputSignedEnclavePath.length() - ".so".length());
  55. outputSignedEnclaveFileField.setText(outputSignedEnclavePath+".signed.so");
  56. }
  57. }
  58. }
  59. @Override
  60. public void widgetDefaultSelected(SelectionEvent arg0) {
  61. }
  62. };
  63. protected SelectionListener hashFileSelectionListener = new SelectionListener() {
  64. @Override
  65. public void widgetSelected(SelectionEvent event) {
  66. String result = hashFileField.getText();
  67. FileDialog dialog = new FileDialog(shell, SWT.OPEN);
  68. if (result != null && !result.isEmpty()) {
  69. dialog.setFilterPath(new File(result).getParent());
  70. } else {
  71. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  72. }
  73. result = dialog.open();
  74. hashFileField.setText(result);
  75. }
  76. @Override
  77. public void widgetDefaultSelected(SelectionEvent arg0) {
  78. }
  79. };
  80. protected SelectionListener publicKeyLocationSelectionListener = new SelectionListener() {
  81. @Override
  82. public void widgetSelected(SelectionEvent event) {
  83. String result = externalSignPublicKeyFileField.getText();
  84. FileDialog dialog = new FileDialog(shell, SWT.OPEN);
  85. dialog.setFilterExtensions(new String [] {"*.pem", "*"});
  86. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  87. result = dialog.open();
  88. externalSignPublicKeyFileField.setText(result);
  89. }
  90. @Override
  91. public void widgetDefaultSelected(SelectionEvent e) {
  92. }
  93. };
  94. protected SelectionListener externalSignedHashFileSelectionListener = new SelectionListener() {
  95. @Override
  96. public void widgetSelected(SelectionEvent event) {
  97. String result = externalSignedHashFileField.getText();
  98. FileDialog dialog = new FileDialog(shell, SWT.OPEN);
  99. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  100. result = dialog.open();
  101. externalSignedHashFileField.setText(result);
  102. }
  103. @Override
  104. public void widgetDefaultSelected(SelectionEvent e) {
  105. }
  106. };
  107. protected SelectionListener outputSignedEnclaveListener = new SelectionListener() {
  108. @Override
  109. public void widgetSelected(SelectionEvent event) {
  110. String result = outputSignedEnclaveFileField.getText();
  111. FileDialog dialog = new FileDialog(shell, SWT.OPEN);
  112. dialog.setFilterExtensions(new String[]{"*.so", } );
  113. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  114. if (result != null && !result.isEmpty()) {
  115. dialog.setFilterPath(new File(result).getParent());
  116. } else {
  117. dialog.setFilterPath(getCurrentProjectPath().toOSString());
  118. }
  119. result = dialog.open();
  120. outputSignedEnclaveFileField.setText(result);
  121. }
  122. @Override
  123. public void widgetDefaultSelected(SelectionEvent arg0) {
  124. }
  125. };
  126. @Override
  127. protected void configureShell(Shell newShell) {
  128. super.configureShell(newShell);
  129. }
  130. }