-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add export certificate functionality
Added the ability to export certificates from the JKS store. Updated the plugin.xml to include the export action and implemented relevant methods in JKSView and CertificateHelper to handle the export process.
- Loading branch information
Showing
5 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/com/jmpeax/ssltoolbox/jks/actions/ExportCert.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.jmpeax.ssltoolbox.jks.actions; | ||
|
||
|
||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.CommonDataKeys; | ||
import com.intellij.openapi.actionSystem.PlatformDataKeys; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.fileChooser.FileChooser; | ||
import com.intellij.openapi.fileChooser.FileChooserDescriptor; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.jmpeax.ssltoolbox.jks.JKSView; | ||
import com.jmpeax.ssltoolbox.svc.CertificateHelper; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class ExportCert extends AnAction { | ||
|
||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent e) { | ||
|
||
var certificateHelper = ApplicationManager.getApplication().getService(CertificateHelper.class); | ||
var ksVirtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE); | ||
var view = getViewComponent(e); | ||
if (view == null) { | ||
Messages.showErrorDialog("No JKS view found", "No JKS View"); | ||
} | ||
var selectedAlias = view.getSelectedCertificate(); | ||
if (selectedAlias == null) { | ||
Messages.showErrorDialog("No certificate selected", "No Certificate Selected"); | ||
} | ||
var descriptor = new FileChooserDescriptor( | ||
false, // Choose Files | ||
true, | ||
false, | ||
false, | ||
false, | ||
false | ||
); | ||
var pwd = Messages.showPasswordDialog("Keystore password", "KeyStore Password"); | ||
if (pwd != null && !pwd.isBlank()) { | ||
certificateHelper.exportCertificate(ksVirtualFile, selectedAlias, pwd.toCharArray()); | ||
Messages.showInfoMessage("Certificate exported", "Certificate Exported"); | ||
view.removeCertificate(selectedAlias); | ||
} | ||
} | ||
|
||
private JKSView getViewComponent(@NotNull AnActionEvent e) { | ||
// Retrieve your view component from context, e.g., using the data context from the event | ||
return e.getData(PlatformDataKeys.CONTEXT_COMPONENT) instanceof JKSView | ||
? (JKSView) e.getData(PlatformDataKeys.CONTEXT_COMPONENT) | ||
: null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters