use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor 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);
}
}
use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor in project core by jcryptool.
the class AlgorithmsManager method performCipherCalled.
private static void performCipherCalled(IMetaAlgorithm algorithm) {
if (algorithm.getParameterSpecClassName() != null) {
algorithmWizard = new AlgorithmWizard(algorithm);
dialog = new WizardDialog(shell, algorithmWizard);
dialog.setMinimumPageSize(300, 100);
int result = dialog.open();
if (result == Window.OK) {
// $NON-NLS-1$
LogUtil.logInfo("adding cipher");
NewOperationManager.getInstance().fireNewOperation(algorithmWizard.getDescriptor());
}
} else {
// $NON-NLS-1$
LogUtil.logInfo("adding cipher w/o parameter spec");
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.ASYMMETRIC_BLOCK_CIPHER, null));
}
}
use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor in project core by jcryptool.
the class AlgorithmsManager method performAsymmetricHybridCipherCalled.
private static void performAsymmetricHybridCipherCalled(IMetaAlgorithm algorithm) {
if (algorithm.getParameterSpecClassName() != null && !algorithm.isParameterSpecDisabled()) {
algorithmWizard = new AlgorithmWizard(algorithm);
dialog = new WizardDialog(shell, algorithmWizard);
dialog.setMinimumPageSize(300, 100);
int result = dialog.open();
if (result == Window.OK) {
// $NON-NLS-1$
LogUtil.logInfo("adding asymmetric hybrid cipher");
NewOperationManager.getInstance().fireNewOperation(algorithmWizard.getDescriptor());
}
} else {
// $NON-NLS-1$
LogUtil.logInfo("adding asymmetric hybrid cipher w/o parameter spec");
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.ASYMMETRIC_HYBRID_CIPHER, null));
}
}
use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor in project core by jcryptool.
the class IntegratorHandler method getAlgorithmDescriptor.
private AlgorithmDescriptor getAlgorithmDescriptor(String name) {
AlgorithmDescriptor descriptor = null;
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getAsymmetricBlockCiphers());
if (descriptor != null) {
algorithmType = TYPE_ASYMMETRIC_BLOCK;
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getAsymmetricHybridCiphers());
if (descriptor != null) {
algorithmType = TYPE_ASYMMETRIC_HYBRID;
}
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getBlockCiphers());
if (descriptor != null) {
algorithmType = TYPE_CIPHER_BLOCK;
SHOW_PADDING_GROUP = true;
}
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getCiphers());
if (descriptor != null) {
algorithmType = TYPE_CIPHER;
}
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getMacs());
if (descriptor != null) {
algorithmType = TYPE_MESSAGE_AUTHTIFICATION_CODE;
SHOW_OPERATION_GROUP = false;
}
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getMessageDigests());
if (descriptor != null) {
algorithmType = TYPE_MESSAGE_DIGEST;
try {
SHOW_MESSAGE_DIGEST_GROUP = java.security.MessageDigest.getInstance(name).getDigestLength();
SHOW_OPERATION_GROUP = false;
} catch (java.security.NoSuchAlgorithmException e) {
return null;
}
}
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getSecureRandoms());
if (descriptor != null) {
algorithmType = TYPE_RANDOM_NUMBER_GENERATOR;
SHOW_OPERATION_GROUP = false;
SHOW_RANDOM_GROUP = true;
}
}
if (descriptor == null) {
descriptor = searchList(name, AlgorithmsXMLManager.getInstance().getSignatures());
if (descriptor != null) {
algorithmType = TYPE_SIGNATURE;
SHOW_SIGNATURE_GROUP = true;
}
}
SHOW_KEY_SOURCE_GROUP = (algorithmType == TYPE_CIPHER_BLOCK || algorithmType == TYPE_MESSAGE_AUTHTIFICATION_CODE);
HEADER_DESCRIPTION = getHeaderDescription();
return descriptor;
}
use of org.jcryptool.crypto.flexiprovider.descriptors.algorithms.AlgorithmDescriptor in project core by jcryptool.
the class IntegratorHandler method execute.
/**
* runs the action: setup the algorithm and executed the specified operation
*/
@Override
public Object execute(ExecutionEvent event) {
AlgorithmDescriptor descriptor = getAlgorithmDescriptor(FLEXIPROVIDER_ALGORITHM_NAME);
if (descriptor == null) {
MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell());
// $NON-NLS-1$
messageBox.setText(Messages.getString("DummyAction.error"));
// $NON-NLS-1$
messageBox.setMessage(Messages.getString("DummyAction.8"));
messageBox.open();
return (null);
}
String readableNameExtension;
switch(algorithmType) {
case TYPE_RANDOM_NUMBER_GENERATOR:
// $NON-NLS-1$
readableNameExtension = Messages.getString("DummyAction.random_number_generator");
break;
case TYPE_SIGNATURE:
// $NON-NLS-1$
readableNameExtension = Messages.getString("DummyAction.signature");
break;
case TYPE_MESSAGE_DIGEST:
// $NON-NLS-1$
readableNameExtension = Messages.getString("DummyAction.message_digest");
break;
case TYPE_MESSAGE_AUTHTIFICATION_CODE:
// $NON-NLS-1$
readableNameExtension = Messages.getString("DummyAction.message_authentification_code");
break;
default:
// $NON-NLS-1$
readableNameExtension = Messages.getString("DummyAction.encryption");
}
// Get which key lengths are valid for this algorithm
int[] validKeyLengths = null;
IMetaKeyGenerator keyGen = AlgorithmsXMLManager.getInstance().getSecretKeyGenerator(FLEXIPROVIDER_ALGORITHM_NAME);
if (keyGen != null) {
if (keyGen.getLengths().getLengths() != null) {
validKeyLengths = new int[keyGen.getLengths().getLengths().size()];
for (int i = 0; i < validKeyLengths.length; i++) validKeyLengths[i] = keyGen.getLengths().getLengths().get(i);
} else {
validKeyLengths = new int[1];
validKeyLengths[0] = keyGen.getLengths().getDefaultLength();
}
}
wizard = new IntegratorWizard(READABLE_ALGORITHM_NAME + readableNameExtension, READABLE_ALGORITHM_NAME, HEADER_DESCRIPTION, SHOW_OPERATION_GROUP, SHOW_PADDING_GROUP, SHOW_KEY, SHOW_KEY_SOURCE_GROUP, validKeyLengths, SHOW_SIGNATURE_GROUP, SHOW_RANDOM_GROUP, SHOW_MESSAGE_DIGEST_GROUP, algorithmType);
WizardDialog dialog = new WizardDialog(getActiveWorkbenchWindow().getShell(), wizard);
dialog.setHelpAvailable(true);
switch(dialog.open()) {
case Window.OK:
if (algorithmType == TYPE_CIPHER_BLOCK) {
descriptor = new BlockCipherDescriptor(descriptor.getAlgorithmName(), AlgorithmsXMLManager.getInstance().getMode(wizard.getMode().getDescription()).getID(), AlgorithmsXMLManager.getInstance().getPaddingScheme(wizard.getPadding().getPaddingSchemeName()).getID(), null, descriptor.getAlgorithmParameterSpec());
}
if (algorithmType == TYPE_RANDOM_NUMBER_GENERATOR) {
if (wizard.doFilter())
descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), wizard.getRandomSize(), wizard.getFilter());
else
descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), wizard.getRandomSize());
}
IntegratorOperation operation = new IntegratorOperation(descriptor);
// $NON-NLS-1$
operation.setEntryName("");
// $NON-NLS-1$
operation.setInput(Messages.getString("InputType"));
// $NON-NLS-1$
operation.setOutput("<Editor>");
operation.setSignature(wizard.signature());
operation.setUseCustomKey(wizard.useCustomKey());
if (wizard.useCustomKey())
operation.setKeyBytes(wizard.getCustomKey());
try {
if (// $NON-NLS-1$
SHOW_KEY != null && !SHOW_KEY.equals("") && !wizard.useCustomKey())
operation.setKeyStoreAlias(wizard.getKey());
if (wizard.encrypt()) {
// explicit encrypt
if (descriptor.getType() == RegistryType.SIGNATURE) {
operation.setOperation(OperationType.VERIFY);
} else {
operation.setOperation(OperationType.ENCRYPT);
}
} else {
// implicit decrypt
if (descriptor.getType() == RegistryType.SIGNATURE) {
operation.setOperation(OperationType.SIGN);
} else {
operation.setOperation(OperationType.DECRYPT);
}
}
if (SHOW_MESSAGE_DIGEST_GROUP > 0 && !wizard.encrypt()) {
try {
MessageDigest digest = Registry.getMessageDigest(operation.getAlgorithmDescriptor().getAlgorithmName());
InputStream inputStream = EditorsManager.getInstance().getActiveEditorContentInputStream();
int i;
while ((i = inputStream.read()) != -1) {
digest.update((byte) i);
}
byte[] checksumAsBytes = digest.digest();
// $NON-NLS-1$
String checksum = "";
for (byte b : checksumAsBytes) {
String temp = Integer.toHexString((int) b);
// $NON-NLS-1$ //$NON-NLS-2$
checksum += (temp.length() == 1 ? "0" : "") + temp.substring(Math.max(0, temp.length() - 2));
}
String expectedChecksum = wizard.getExpectedChecksum();
if (checksum.equalsIgnoreCase(expectedChecksum)) {
MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell(), SWT.ICON_WORKING);
// $NON-NLS-1$
messageBox.setText(Messages.getString("IntegratorAction.0"));
// $NON-NLS-1$
messageBox.setMessage(Messages.getString("IntegratorAction.1"));
messageBox.open();
} else {
MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell(), SWT.ICON_ERROR);
// $NON-NLS-1$
messageBox.setText(Messages.getString("IntegratorAction.2"));
messageBox.setMessage(// $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
Messages.getString("IntegratorAction.3"), new Object[] { checksum.toLowerCase(), expectedChecksum.toLowerCase() }));
messageBox.open();
}
} catch (NoSuchAlgorithmException e) {
LogUtil.logError(IntegratorPlugin.PLUGIN_ID, "NoSuchAlgorithmException while initializing a message digest", e, // $NON-NLS-1$
true);
}
} else {
PerformOperationManager.getInstance().firePerformOperation(operation);
}
if (operation.getOperation() == OperationType.SIGN) {
MessageBox messageBox = new MessageBox(getActiveWorkbenchWindow().getShell(), SWT.NONE);
// $NON-NLS-1$
messageBox.setText(Messages.getString("DummyAction.13"));
// $NON-NLS-1$
messageBox.setMessage(Messages.getString("DummyAction.14") + wizard.signature());
messageBox.open();
}
} catch (IOException ex) {
LogUtil.logError(ex);
}
break;
case Window.CANCEL:
break;
}
return (null);
}
Aggregations