-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from d0ge/ruby-encrypted-string
## [1.0.6] - 2024-11-29
- Loading branch information
Showing
20 changed files
with
704 additions
and
43 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
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
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
95 changes: 95 additions & 0 deletions
95
src/main/java/one/d4d/signsaboteur/forms/dialog/EncryptionDialog.form
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,95 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="one.d4d.signsaboteur.forms.dialog.EncryptionDialog"> | ||
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="10" left="10" bottom="10" right="10"/> | ||
<constraints> | ||
<xy x="48" y="54" width="436" height="297"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<hspacer id="98af6"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
</hspacer> | ||
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="e7465" class="javax.swing.JButton" binding="buttonOK"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text resource-bundle="strings" key="button_ruby_decrypt"/> | ||
</properties> | ||
</component> | ||
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Cancel"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<grid id="11b4e" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="ef293" class="javax.swing.JComboBox" binding="comboBoxEncryptionKeys"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
</children> | ||
</grid> | ||
<scrollpane id="ceeac" class="org.fife.ui.rtextarea.RTextScrollPane"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="8193e" class="org.fife.ui.rsyntaxtextarea.RSyntaxTextArea" binding="cypherText" custom-create="true"> | ||
<constraints/> | ||
<properties> | ||
<syntaxEditingStyle resource-bundle="strings" key="syntaxis"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</scrollpane> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</form> |
90 changes: 90 additions & 0 deletions
90
src/main/java/one/d4d/signsaboteur/forms/dialog/EncryptionDialog.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,90 @@ | ||
package one.d4d.signsaboteur.forms.dialog; | ||
|
||
import one.d4d.signsaboteur.itsdangerous.crypto.*; | ||
import one.d4d.signsaboteur.itsdangerous.model.*; | ||
import one.d4d.signsaboteur.keys.SecretKey; | ||
import one.d4d.signsaboteur.rsta.RstaFactory; | ||
import one.d4d.signsaboteur.utils.ErrorLoggingActionListenerFactory; | ||
import one.d4d.signsaboteur.utils.Utils; | ||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; | ||
|
||
import javax.swing.*; | ||
import javax.swing.border.Border; | ||
import javax.swing.border.LineBorder; | ||
import java.awt.*; | ||
import java.awt.event.*; | ||
import java.util.List; | ||
|
||
import static java.awt.Color.RED; | ||
import static javax.swing.JOptionPane.WARNING_MESSAGE; | ||
|
||
public class EncryptionDialog extends AbstractDialog { | ||
private JPanel contentPane; | ||
private JButton buttonOK; | ||
private JButton buttonCancel; | ||
private JComboBox comboBoxEncryptionKeys; | ||
private RSyntaxTextArea cypherText; | ||
private SignedToken tokenObject; | ||
private RstaFactory rstaFactory; | ||
|
||
public EncryptionDialog(Window parent, | ||
RstaFactory rstaFactory, | ||
ErrorLoggingActionListenerFactory actionListenerFactory, | ||
List<SecretKey> signingKeys, | ||
SignedToken tokenObject) { | ||
super(parent, "encryption_dialog_title"); | ||
this.rstaFactory = rstaFactory; | ||
this.tokenObject = tokenObject; | ||
|
||
setContentPane(contentPane); | ||
getRootPane().setDefaultButton(buttonOK); | ||
|
||
buttonOK.addActionListener(actionListenerFactory.from(e -> onOK())); | ||
buttonCancel.addActionListener(e -> onCancel()); | ||
|
||
contentPane.registerKeyboardAction( | ||
e -> onCancel(), | ||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), | ||
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT | ||
); | ||
|
||
SecretKey[] signingKeysArray = new SecretKey[signingKeys.size()]; | ||
signingKeys.toArray(signingKeysArray); | ||
|
||
comboBoxEncryptionKeys.setModel(new DefaultComboBoxModel<>(signingKeysArray)); | ||
comboBoxEncryptionKeys.setSelectedIndex(0); | ||
} | ||
|
||
private void onOK() { | ||
SecretKey selectedKey = (SecretKey) comboBoxEncryptionKeys.getSelectedItem(); | ||
|
||
try { | ||
assert selectedKey != null; | ||
TokenSigner s; | ||
if (tokenObject instanceof RubyEncryptedToken) { | ||
s = new RubyEncryptionTokenSigner(selectedKey); | ||
} else { | ||
throw new Exception("Unknown"); | ||
} | ||
tokenObject.setSigner(s); | ||
String text = ((RubyEncryptedToken) tokenObject).getCypherText(); | ||
cypherText.setText(text); | ||
|
||
Border serializedTextAreaBorder = text.equals("Error") ? new LineBorder(RED, 1) : null; | ||
cypherText.setBorder(serializedTextAreaBorder); | ||
} catch (Exception e) { | ||
tokenObject = null; | ||
JOptionPane.showMessageDialog( | ||
this, | ||
e.getMessage(), | ||
Utils.getResourceString("error_title_unable_to_sign"), | ||
WARNING_MESSAGE | ||
); | ||
} | ||
} | ||
|
||
private void createUIComponents() { | ||
// TODO: place custom component creation code here | ||
cypherText = rstaFactory.buildDefaultTextArea(); | ||
} | ||
} |
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
Oops, something went wrong.