use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.
the class CopyAction method bufferSelectedEntry.
private BufferEntry bufferSelectedEntry() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
if (alias == null) {
return null;
}
BufferEntry bufferEntry = null;
KeyStore keyStore = currentState.getKeyStore();
if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return null;
}
Key key = keyStore.getKey(alias, password.toCharArray());
if (key instanceof PrivateKey) {
JOptionPane.showMessageDialog(frame, res.getString("CopyAction.NoCopyKeyEntryWithPrivateKey.message"), res.getString("CopyAction.Copy.Title"), JOptionPane.WARNING_MESSAGE);
return null;
}
bufferEntry = new KeyBufferEntry(alias, false, key, password);
} else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
Certificate certificate = keyStore.getCertificate(alias);
bufferEntry = new TrustedCertificateBufferEntry(alias, false, certificate);
} else if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return null;
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificateChain = keyStore.getCertificateChain(alias);
bufferEntry = new KeyPairBufferEntry(alias, false, privateKey, password, certificateChain);
}
return bufferEntry;
} catch (Exception ex) {
DError.displayError(frame, ex);
return null;
}
}
use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.
the class CutAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
BufferEntry bufferEntry = bufferSelectedEntry();
if (bufferEntry != null) {
Buffer.populate(bufferEntry);
kseFrame.updateControls(true);
}
}
use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.
the class CopyAction method doAction.
/**
* Do action.
*/
@Override
protected void doAction() {
BufferEntry bufferEntry = bufferSelectedEntry();
if (bufferEntry != null) {
Buffer.populate(bufferEntry);
kseFrame.updateControls(false);
}
}
use of org.kse.utilities.buffer.BufferEntry in project keystore-explorer by kaikramer.
the class CutAction method bufferSelectedEntry.
private BufferEntry bufferSelectedEntry() {
try {
KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory();
KeyStoreState currentState = history.getCurrentState();
String alias = kseFrame.getSelectedEntryAlias();
if (alias == null) {
return null;
}
BufferEntry bufferEntry = null;
KeyStore keyStore = currentState.getKeyStore();
if (KeyStoreUtil.isKeyEntry(alias, keyStore)) {
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return null;
}
Key key = keyStore.getKey(alias, password.toCharArray());
if (key instanceof PrivateKey) {
JOptionPane.showMessageDialog(frame, res.getString("CutAction.NoCutKeyEntryWithPrivateKey.message"), res.getString("CutAction.Cut.Title"), JOptionPane.WARNING_MESSAGE);
return null;
}
bufferEntry = new KeyBufferEntry(alias, true, key, password);
} else if (KeyStoreUtil.isTrustedCertificateEntry(alias, keyStore)) {
Certificate certificate = keyStore.getCertificate(alias);
bufferEntry = new TrustedCertificateBufferEntry(alias, true, certificate);
} else if (KeyStoreUtil.isKeyPairEntry(alias, keyStore)) {
Password password = getEntryPassword(alias, currentState);
if (password == null) {
return null;
}
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Certificate[] certificateChain = keyStore.getCertificateChain(alias);
bufferEntry = new KeyPairBufferEntry(alias, true, privateKey, password, certificateChain);
}
KeyStoreState newState = currentState.createBasisForNextState(this);
keyStore = newState.getKeyStore();
keyStore.deleteEntry(alias);
newState.removeEntryPassword(alias);
currentState.append(newState);
return bufferEntry;
} catch (Exception ex) {
DError.displayError(frame, ex);
return null;
}
}
Aggregations