Skip to content

Commit

Permalink
fix formating
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrateron committed Jun 26, 2024
1 parent 0eee746 commit 362b17f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 90 deletions.
2 changes: 1 addition & 1 deletion kse/src/main/java/org/kse/gui/actions/SignJwtAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected void doAction() {
dSignJwt.setLocationRelativeTo(frame);
dSignJwt.setVisible(true);
if (dSignJwt.isOk()) {
byte [] dataPublic = cert.getPublicKey().getEncoded();
byte[] dataPublic = cert.getPublicKey().getEncoded();
SignedJWT jwt = signJwt(dSignJwt, privateKey, provider);
DViewJwt dialog = new DViewJwt(frame, jwt);
dialog.setPublicKey(Base64.getEncoder().encodeToString(dataPublic));
Expand Down
178 changes: 89 additions & 89 deletions kse/src/main/java/org/kse/gui/dialogs/DViewJwt.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,42 +145,42 @@ private void initComponents() {
jtaEncoded.setEditable(true);
jtaEncoded.setLineWrap(true);
jtaEncoded.setToolTipText(res.getString("DViewJwt.jtaEncoded.tooltip"));
jtaEncoded.addFocusListener(new FocusListener() {

@Override
public void focusGained(FocusEvent arg0) {
}

@Override
public void focusLost(FocusEvent arg0) {
try {
JWT jwtVeri = JWTParser.parse(jtaEncoded.getText());
if (!jwt.equals(jwtVeri)) {
jwt = jwtVeri;
populateDialog();
}
} catch (ParseException e) {
jtaPayload.setText("");
jtaHeader.setText("");
}
}
});
jtaEncoded.addFocusListener(new FocusListener() {

@Override
public void focusGained(FocusEvent arg0) {
}

@Override
public void focusLost(FocusEvent arg0) {
try {
JWT jwtVeri = JWTParser.parse(jtaEncoded.getText());
if (!jwt.equals(jwtVeri)) {
jwt = jwtVeri;
populateDialog();
}
} catch (ParseException e) {
jtaPayload.setText("");
jtaHeader.setText("");
}
}
});

jspEncoded = PlatformUtil.createScrollPane(jtaEncoded, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

jlPublicKey = new JLabel(res.getString("DViewJwt.jlPublicKey.text"));
jlPublicKey = new JLabel(res.getString("DViewJwt.jlPublicKey.text"));

jtaPublicKey = new JTextArea();
jtaPublicKey.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize()));
jtaPublicKey.setEditable(true);
jtaPublicKey.setLineWrap(true);
jtaPublicKey.setToolTipText(res.getString("DViewJwt.jtaPublicKey.tooltip"));
jtaPublicKey = new JTextArea();
jtaPublicKey.setFont(new Font(Font.MONOSPACED, Font.PLAIN, LnfUtil.getDefaultFontSize()));
jtaPublicKey.setEditable(true);
jtaPublicKey.setLineWrap(true);
jtaPublicKey.setToolTipText(res.getString("DViewJwt.jtaPublicKey.tooltip"));

jspPublicKey = PlatformUtil.createScrollPane(jtaPublicKey, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jspPublicKey = PlatformUtil.createScrollPane(jtaPublicKey, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

jbCopy = new JButton(res.getString("DViewJwt.jbCopy.text"));
jbCopy = new JButton(res.getString("DViewJwt.jbCopy.text"));
jbCopy.setToolTipText(res.getString("DViewJwt.jbCopy.tooltip"));
PlatformUtil.setMnemonic(jbCopy, res.getString("DViewJwt.jbCopy.mnemonic").charAt(0));

Expand All @@ -196,15 +196,15 @@ public void focusLost(FocusEvent arg0) {
pane.add(jlPayload, "");
pane.add(jspPayload, "width 400lp:400lp:400lp, height 150lp:150lp:150lp, wrap");
pane.add(jlEncoded, "");
pane.add(jspEncoded, "width 400lp:400lp:400lp, height 150lp:150lp:150lp");
pane.add(jspEncoded, "width 400lp:400lp:400lp, height 200lp:200lp:200lp");
pane.add(jlPublicKey, "");
pane.add(jspPublicKey, "width 400lp:400lp:400lp, height 150lp:150lp:150lp, wrap");
pane.add(jspPublicKey, "width 400lp:400lp:400lp, height 200lp:200lp:200lp, wrap");

jpButtons = PlatformUtil.createDialogButtonPanel(jbCopy, jbVerify, "insets 0");
jpButtons = PlatformUtil.createDialogButtonPanel(jbCopy, jbVerify, "insets 0");

pane.add(jpButtons, "right, spanx");
pane.add(new JSeparator(), "spanx, growx, wrap unrel:push");

pane.add(jpButtons, "right, spanx");
pane.add(new JSeparator(), "spanx, growx, wrap unrel:push");

pane.add(jbOK, "spanx, tag ok");

// actions
Expand Down Expand Up @@ -260,60 +260,60 @@ private void okPressed() {
closeDialog();
}

private static byte[] decodeIfBase64(String data) {
byte[] dataAsBytes = data.getBytes();

// first handle base64 encoded binary data
try {
dataAsBytes = Base64.getDecoder().decode(data.trim());
} catch (IllegalArgumentException e) {
// was not valid b64
}
return dataAsBytes;
}
private static byte[] decodeIfBase64(String data) {
byte[] dataAsBytes = data.getBytes();

// first handle base64 encoded binary data
try {
dataAsBytes = Base64.getDecoder().decode(data.trim());
} catch (IllegalArgumentException e) {
// was not valid b64
}
return dataAsBytes;
}

private void verifyPressed() {
String data = jtaPublicKey.getText();
if (data.isEmpty()) {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidPublicKey.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
return;
}
byte[] dataAsBytes = decodeIfBase64(data);
try {
CryptoFileType fileType = CryptoFileUtil.detectFileType(dataAsBytes);
if (fileType != CryptoFileType.OPENSSL_PUB) {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidPublicKey.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
return;
}
PublicKey publicKey = OpenSslPubUtil.load(dataAsBytes);
var signedJWT = SignedJWT.parse(jwt.serialize());
JWSVerifier verifier = null;
if (publicKey instanceof ECPublicKey) {
verifier = new ECDSAVerifier((ECPublicKey) publicKey);
} else if (publicKey instanceof RSAPublicKey) {
verifier = new RSASSAVerifier((RSAPublicKey) publicKey);
} else {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidPublicKey.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
return;
}
if (signedJWT.verify(verifier)) {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.SignatureVerified.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidSignature.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
}
} catch (IOException | CryptoException | JOSEException | ParseException ex) {
DError.displayError(this, ex);
}
}

public void setPublicKey(String publicKey) {
jtaPublicKey.setText(publicKey);
}
private void verifyPressed() {
String data = jtaPublicKey.getText();
if (data.isEmpty()) {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidPublicKey.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
return;
}
byte[] dataAsBytes = decodeIfBase64(data);
try {
CryptoFileType fileType = CryptoFileUtil.detectFileType(dataAsBytes);
if (fileType != CryptoFileType.OPENSSL_PUB) {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidPublicKey.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
return;
}
PublicKey publicKey = OpenSslPubUtil.load(dataAsBytes);
var signedJWT = SignedJWT.parse(jwt.serialize());
JWSVerifier verifier = null;
if (publicKey instanceof ECPublicKey) {
verifier = new ECDSAVerifier((ECPublicKey) publicKey);
} else if (publicKey instanceof RSAPublicKey) {
verifier = new RSASSAVerifier((RSAPublicKey) publicKey);
} else {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidPublicKey.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
return;
}
if (signedJWT.verify(verifier)) {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.SignatureVerified.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, res.getString("DViewJwt.InvalidSignature.message"),
res.getString("DViewJwt.Verify.Title"), JOptionPane.ERROR_MESSAGE);
}
} catch (IOException | CryptoException | JOSEException | ParseException ex) {
DError.displayError(this, ex);
}
}

public void setPublicKey(String publicKey) {
jtaPublicKey.setText(publicKey);
}

private void closeDialog() {
setVisible(false);
Expand Down

0 comments on commit 362b17f

Please sign in to comment.