use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class ContentProviderFactory method create.
public static IStructuredContentProvider create(TreeNode treeNode) {
IKeyStoreAlias alias = null;
if (treeNode instanceof CertificateNode) {
alias = ((CertificateNode) treeNode).getAlias();
} else if (treeNode instanceof AbstractKeyNode) {
alias = ((AbstractKeyNode) treeNode).getAlias();
}
if (alias == null) {
return new CommonContentProvider();
}
KeyType keyType = alias.getKeyStoreEntryType();
String className = alias.getClassName();
switch(keyType) {
case SECRETKEY:
if (className.equals(ECSecretKey.class.getName())) {
return new ECSecretKeyContentProvider();
} else if (className.equals(PBEKey.class.getName())) {
return new PBESecretKeyContentProvider();
} else {
return new AbstractKeyNodeContentProvider();
}
case PUBLICKEY:
return new CertificateContentProvider();
case KEYPAIR_PRIVATE_KEY:
if (className.equals(DSAPrivateKey.class.getName())) {
return new DSAPrivateKeyContentProvider();
} else if (className.equals(ElGamalPrivateKey.class.getName())) {
return new ElGamalPrivateKeyContentProvider();
} else if (className.equals(SSVElGamalPrivateKey.class.getName())) {
return new SSVElGamalPrivateKeyContentProvider();
} else if (className.equals(MeRSAPrivateKey.class.getName())) {
return new MeRSAPrivateKeyContentProvider();
} else if (className.equals(MpRSAPrivateKey.class.getName())) {
return new MpRSAPrivateKeyContentProvider();
} else if (className.equals(CMSSPrivateKey.class.getName())) {
return new CMSSPrivateKeyContentProvider();
} else if (className.equals(ECPrivateKey.class.getName())) {
return new ECPrivateKeyContentProvider();
} else if (className.equals(GMSSPrivateKey.class.getName())) {
return new GMSSPrivateKeyContentProvider();
} else if (className.equals(IQDSAPrivateKey.class.getName())) {
return new IQDSAPrivateKeyContentProvider();
} else if (className.equals(IQGQPrivateKey.class.getName())) {
return new IQGQPrivateKeyContentProvider();
} else if (className.equals(IQRDSAPrivateKey.class.getName())) {
return new IQRDSAPrivateKeyContentProvider();
} else if (className.equals(LMOTSPrivateKey.class.getName())) {
return new LMOTSPrivateKeyContentProvider();
} else if (className.equals(McElieceCCA2PrivateKey.class.getName())) {
return new McElieceCCA2PrivateKeyContentProvider();
} else if (className.equals(MerkleOTSPrivateKey.class.getName())) {
return new MerkleOTSPrivateKeyContentProvider();
} else if (className.equals(NiederreiterPrivateKey.class.getName())) {
return new NiederreiterPrivateKeyContentProvider();
} else if (className.equals(PFlashPrivateKey.class.getName())) {
return new PFlashPrivateKeyContentProvider();
} else if (className.equals(RainbowPrivateKey.class.getName())) {
return new RainbowPrivateKeyContentProvider();
} else {
JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, KeyStorePlugin.PLUGIN_ID, Messages.ContentProviderFactory_0 + "\n" + Messages.ContentProviderFactory_2));
return new AbstractKeyNodeContentProvider();
}
case KEYPAIR_PUBLIC_KEY:
if (className.equals(DSAPublicKey.class.getName())) {
return new DSAPublicKeyContentProvider();
} else if (className.equals(ElGamalPublicKey.class.getName())) {
return new ElGamalPublicKeyContentProvider();
} else if (className.equals(SSVElGamalPublicKey.class.getName())) {
return new SSVElGamalPublicKeyContentProvider();
} else if (className.equals(RSAPublicKey.class.getName())) {
return new RSAPublicKeyContentProvider();
} else if (className.equals(CMSSPublicKey.class.getName())) {
return new CMSSPublicKeyContentProvider();
} else if (className.equals(ECPublicKey.class.getName())) {
return new ECPublicKeyContentProvider();
} else if (className.equals(GMSSPublicKey.class.getName())) {
return new GMSSPublicKeyContentProvider();
} else if (className.equals(IQDSAPublicKey.class.getName())) {
return new IQDSAPublicKeyContentProvider();
} else if (className.equals(IQGQPublicKey.class.getName())) {
return new IQGQPublicKeyContentProvider();
} else if (className.equals(IQRDSAPublicKey.class.getName())) {
return new IQRDSAPublicKeyContentProvider();
} else if (className.equals(LMOTSPublicKey.class.getName())) {
return new LMOTSPublicKeyContentProvider();
} else if (className.equals(McElieceCCA2PublicKey.class.getName())) {
return new McElieceCCA2PublicKeyContentProvider();
} else if (className.equals(McEliecePublicKey.class.getName())) {
return new McEliecePublicKeyContentProvider();
} else if (className.equals(MerkleOTSPublicKey.class.getName())) {
return new MerkleOTSPublicKeyContentProvider();
} else if (className.equals(NiederreiterPublicKey.class.getName())) {
return new NiederreiterPublicKeyContentProvider();
} else if (className.equals(PFlashPublicKey.class.getName())) {
return new PFlashPublicKeyContentProvider();
} else if (className.equals(RainbowPublicKey.class.getName())) {
return new RainbowPublicKeyContentProvider();
} else {
JCTMessageDialog.showInfoDialog(new Status(IStatus.INFO, KeyStorePlugin.PLUGIN_ID, Messages.ContentProviderFactory_0 + "\n" + Messages.ContentProviderFactory_2));
return new CertificateContentProvider();
}
default:
break;
}
return new CommonContentProvider();
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class KeyStoreManager method updateKeyPair.
/**
* Updates the private key in a key pair. Before updating this method ensures that the private key is available in
* the keystore and that the password isn't changed.
*
* @param privateKey The private key to update
* @param password The private key password
* @param alias The private key metadata
* @throws UnrecoverableEntryException In case the entered password does not match the selected entry
* @throws NoSuchAlgorithmException In case the requested algorithm is not supported
*/
public void updateKeyPair(PrivateKey privateKey, char[] password, IKeyStoreAlias alias) throws UnrecoverableEntryException, NoSuchAlgorithmException {
try {
getPrivateKey(alias, password);
} catch (Exception e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, NLS.bind(Messages.KeyStoreManager_8, alias.getAliasString()), e, true);
return;
}
try {
KeyStoreAlias publicAlias = getPublicForPrivate(alias);
Certificate publicKey = getCertificate(publicAlias);
Certificate[] certs = new Certificate[1];
certs[0] = publicKey;
keyStore.setEntry(alias.getAliasString(), new KeyStore.PrivateKeyEntry(privateKey, certs), new KeyStore.PasswordProtection(password));
saveKeystore();
} catch (KeyStoreException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, NLS.bind(Messages.KeyStoreManager_7, alias.getAliasString()), e, true);
}
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class AbstractKeyNodeContentProvider method getAliasElements.
private List<TableEntry> getAliasElements(Object inputElement) {
AbstractKeyNode node = (AbstractKeyNode) inputElement;
IKeyStoreAlias alias = node.getAlias();
List<TableEntry> elements = new ArrayList<TableEntry>();
elements.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_Alias, alias.getAliasString()));
elements.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_ContactName, alias.getContactName()));
// $NON-NLS-2$
elements.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_KeyLength, "" + alias.getKeyLength()));
elements.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_Operation, alias.getOperation()));
elements.add(new TableEntry(Messages.AbstractKeyNodeContentProvider_AsString, alias.toString()));
return elements;
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class CertificateContentProvider method getElements.
@Override
public Object[] getElements(Object inputElement) {
CertificateNode treeNode = (CertificateNode) inputElement;
IKeyStoreAlias alias = treeNode.getAlias();
try {
Certificate cert = KeyStoreManager.getInstance().getCertificate(alias);
Object[] certElements = { new TableEntry(Messages.CertificateContentProvider_CertType, cert.getType()) };
return merge(super.getElements(inputElement), certElements);
} catch (UnrecoverableEntryException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, e);
} catch (NoSuchAlgorithmException e) {
LogUtil.logError(KeyStorePlugin.PLUGIN_ID, e);
}
return null;
}
use of org.jcryptool.crypto.keystore.keys.IKeyStoreAlias in project core by jcryptool.
the class PerformOperationListener method addActionItem.
private void addActionItem(IFlexiProviderOperation operation) {
ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
if ((Boolean) // $NON-NLS-1$
service.getCommand("org.jcryptool.actions.recordCommand").getState("org.jcryptool.actions.recordCommand.toggleState").getValue()) {
// $NON-NLS-1$
AlgorithmDescriptor descriptor = operation.getAlgorithmDescriptor();
ActionItem item = // $NON-NLS-1$
new ActionItem(EditorsManager.getInstance().getActiveEditorTitle(), descriptor.getAlgorithmName());
item.setPluginId(operation.getRegistryType().getName());
if (operation.getOperation() == OperationType.DECRYPT) {
// $NON-NLS-1$
item.setActionType("decrypt");
} else if (operation.getOperation() == OperationType.ENCRYPT) {
// $NON-NLS-1$
item.setActionType("encrypt");
} else if (operation.getOperation() == OperationType.SIGN) {
// $NON-NLS-1$
item.setActionType("sign");
} else if (operation.getOperation() == OperationType.VERIFY) {
// $NON-NLS-1$
item.setActionType("verify");
}
// item.addParam("input", operation.getInput()); //$NON-NLS-1$
// item.addParam("output", operation.getOutput()); //$NON-NLS-1$
// $NON-NLS-1$
item.addParam("signature", operation.getSignature());
// $NON-NLS-1$
item.addParam("algorithm type", operation.getAlgorithmDescriptor().getType().getName());
IKeyStoreAlias alias = operation.getKeyStoreAlias();
if (alias != null) {
// $NON-NLS-1$
item.addParam("contact", alias.getContactName());
// $NON-NLS-1$
item.addParam("key alias", alias.getAliasString());
// $NON-NLS-1$
item.addParam("key length", String.valueOf(alias.getKeyLength()));
if (operation.getPassword() != null) {
// $NON-NLS-1$
item.addParam("key password", String.valueOf(operation.getPassword()));
}
}
if (descriptor instanceof BlockCipherDescriptor) {
// $NON-NLS-1$
item.addParam("mode", ((BlockCipherDescriptor) descriptor).getMode());
// $NON-NLS-1$
item.addParam("padding scheme", ((BlockCipherDescriptor) descriptor).getPadding());
} else if (descriptor instanceof SecureRandomDescriptor) {
// $NON-NLS-1$ //$NON-NLS-2$
item.addParam("random size", "" + ((SecureRandomDescriptor) descriptor).getLength());
// byte[][] alphabets = ((SecureRandomDescriptor) descriptor).getAlphabet();
// TODO push alphapet to items property "alphabet"
}
ActionCascadeService.getInstance().addItem(item);
}
}
Aggregations