UpdateSigningKey.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.handlers;
  13. import java.io.BufferedReader;
  14. import java.io.File;
  15. import java.io.FileInputStream;
  16. //import java.io.FileNotFoundException;
  17. import java.io.FileOutputStream;
  18. import java.io.IOException;
  19. import java.io.InputStreamReader;
  20. //import java.security.KeyPair;
  21. //import java.security.KeyPairGenerator;
  22. //import java.security.NoSuchAlgorithmException;
  23. import org.eclipse.core.commands.ExecutionEvent;
  24. import org.eclipse.core.commands.ExecutionException;
  25. import org.eclipse.core.commands.IHandler;
  26. import org.eclipse.core.commands.IHandlerListener;
  27. import org.eclipse.core.resources.IProject;
  28. import org.eclipse.core.resources.IResource;
  29. import org.eclipse.core.runtime.CoreException;
  30. import org.eclipse.core.runtime.IPath;
  31. import org.eclipse.core.runtime.Path;
  32. import org.eclipse.jface.dialogs.InputDialog;
  33. import org.eclipse.jface.viewers.ISelection;
  34. import org.eclipse.jface.viewers.IStructuredSelection;
  35. import org.eclipse.swt.widgets.Shell;
  36. import org.eclipse.ui.PlatformUI;
  37. import org.eclipse.ui.handlers.HandlerUtil;
  38. //import org.bouncycastle.openssl.PEMWriter;
  39. import com.intel.sgx.Activator;
  40. import com.intel.sgx.dialogs.UpdateSignKeyDialog;
  41. public class UpdateSigningKey extends SGXHandler {
  42. public String sourceKeyFile = null;
  43. public String destinationKeyFile = null;
  44. public String projectPath = null;
  45. @Override
  46. protected Object executeSGXStuff() throws ErrorException, CancelException {
  47. UpdateSignKeyDialog dialog = new UpdateSignKeyDialog(shell, this);
  48. int result = dialog.open();
  49. if (result != InputDialog.OK) {
  50. cancel();
  51. }
  52. if(UpdateSignKeyDialog.regenerate == false)
  53. {
  54. IPath sourceFile = Path.fromOSString(sourceKeyFile);
  55. IPath destFile = Path.fromOSString(destinationKeyFile);
  56. copyFile(sourceFile.toFile(), destFile.toFile());
  57. refreshProject();
  58. info("Update Intel(R) SGX Enclave Signing Key","copied \n'" + sourceKeyFile + "' into \n'" + destFile + "'");
  59. } else {
  60. UpdateSignKeyDialog.regenerate = false;
  61. try {
  62. Process q;
  63. String opensslCmd = "openssl genrsa -out " + destinationKeyFile
  64. + " -3 3072";
  65. q = Runtime.getRuntime().exec(opensslCmd);
  66. BufferedReader stdInput = new BufferedReader(
  67. new InputStreamReader(q.getInputStream()));
  68. BufferedReader stdErr = new BufferedReader(
  69. new InputStreamReader(q.getErrorStream()));
  70. String s = null;
  71. while ((s = stdInput.readLine()) != null) {
  72. }
  73. while ((s = stdErr.readLine()) != null) {
  74. }
  75. project.refreshLocal(IResource.DEPTH_INFINITE, null);
  76. if (q.exitValue() == 0){
  77. info("Update Intel(R) SGX Enclave Signing Key","'"+destinationKeyFile+"'"+" was generated!");
  78. } else {
  79. quitWithError("Could not generate '"+destinationKeyFile+"'!!!");
  80. }
  81. } catch (IOException e) {
  82. Activator.log(e);
  83. e.printStackTrace();
  84. } catch (CoreException e) {
  85. Activator.log(e);
  86. e.printStackTrace();
  87. }
  88. }
  89. return null;
  90. }
  91. }