use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.
the class FlexiProviderRootElement method initSecretKeyAlgorithms.
@SuppressWarnings("unchecked")
private static void initSecretKeyAlgorithms(RegistryType type, Element secretKeyAlgorithmParent) {
List<Element> cipherChildren = new ArrayList<Element>(secretKeyAlgorithmParent.getChildren());
Iterator<Element> it = cipherChildren.iterator();
while (it.hasNext()) {
Element current = it.next();
// replace element with blockCipherElement
String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
IMetaOID oid = null;
if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
}
List<String> names = new ArrayList<String>();
if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
// $NON-NLS-1$
StringTokenizer tokenizer = // $NON-NLS-1$
new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
while (tokenizer.hasMoreTokens()) {
names.add(tokenizer.nextToken());
}
} else {
names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
}
}
IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
// parameter specs
if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
meta.setParameterSpecDisabled(true);
}
}
// parameter generators
if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
}
if (current.getChild(AlgorithmsXMLConstants._BlockLengths) != null) {
meta.setDefaultBlockLength(Integer.valueOf(current.getChild(AlgorithmsXMLConstants._BlockLengths).getAttributeValue(AlgorithmsXMLConstants._default)));
if (current.getChild(AlgorithmsXMLConstants._BlockLengths).getText() != null) {
List<Integer> blockLengths = new ArrayList<Integer>(0);
StringTokenizer tokenizer = // $NON-NLS-1$
new StringTokenizer(current.getChild(AlgorithmsXMLConstants._BlockLengths).getText(), ",");
while (tokenizer.hasMoreTokens()) {
blockLengths.add(Integer.valueOf(tokenizer.nextToken()));
}
meta.setBlockLengths(blockLengths);
}
}
if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
StringTokenizer standardParams = // $NON-NLS-1$
new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
while (standardParams.hasMoreTokens()) {
meta.addStandardParams(standardParams.nextToken());
}
}
if (type.equals(RegistryType.MAC)) {
if (current.getChild(AlgorithmsXMLConstants._BlockCipherReference) != null) {
meta.setBlockCipherName(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._name));
if (current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
meta.setBlockCipherOID(new MetaOID(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._oid)));
}
meta.setBlockCipherMode(current.getChild(AlgorithmsXMLConstants._BlockCipherReference).getAttributeValue(AlgorithmsXMLConstants._mode));
}
}
if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
add(type, meta);
}
}
}
use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.
the class FlexiProviderAlgorithmsViewContentProvider method init.
private static CategoryNode init(String label, List<IMetaAlgorithm> algorithms) {
CategoryNode category = new CategoryNode(label);
// should be sorted already. just to be on the save side.
Collections.sort(algorithms);
// top level entries
for (IMetaAlgorithm meta : algorithms) {
if (!meta.getClassName().contains("$")) {
// $NON-NLS-1$
category.addChild(new AlgorithmNode(meta));
}
}
// sub level entries
for (IMetaAlgorithm meta : algorithms) {
if (meta.getClassName().contains("$")) {
// $NON-NLS-1$
// $NON-NLS-1$
String primaryPrefix = meta.getClassName().substring(0, meta.getClassName().indexOf("$"));
if (containsClassName(primaryPrefix, algorithms)) {
// recursive entries
buildAlgorithmHierarchy(category, meta);
} else {
// folder entries
// $NON-NLS-1$ //$NON-NLS-2$
String prefix = meta.getClassName().substring(meta.getClassName().lastIndexOf(".") + 1, meta.getClassName().indexOf("$"));
ITreeNode folder = new FolderNode(prefix);
for (IMetaAlgorithm meta2 : algorithms) {
if (meta2.getClassName().contains("$")) {
// $NON-NLS-1$
if (meta2.getClassName().contains("." + prefix)) {
// $NON-NLS-1$
folder.addChild(new AlgorithmNode(meta2));
}
}
}
category.addChild(folder);
}
}
}
return category;
}
use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.
the class AlgorithmsManager method performMacCalled.
private static void performMacCalled(IMetaAlgorithm algorithm) {
if (algorithm.getBlockCipherName() != null) {
IMetaAlgorithm bc = null;
// $NON-NLS-1$
LogUtil.logInfo("BC name: " + algorithm.getBlockCipherName());
if (algorithm.getBlockCipherOID() != null) {
// $NON-NLS-1$
LogUtil.logInfo("BC oid: " + algorithm.getBlockCipherOID());
bc = AlgorithmsXMLManager.getInstance().getBlockCipher(algorithm.getBlockCipherOID());
} else {
bc = AlgorithmsXMLManager.getInstance().getBlockCipher(algorithm.getBlockCipherName());
}
// $NON-NLS-1$
LogUtil.logInfo("BC mode: " + algorithm.getBlockCipherMode());
if (bc != null) {
blockCipherWizard = new BlockCipherWizard(bc, algorithm.getBlockCipherMode());
dialog = new BlockCipherWizardDialog(shell, blockCipherWizard);
dialog.setMinimumPageSize(300, 175);
int result = dialog.open();
if (result == Window.OK) {
AlgorithmDescriptor blockCipherDescriptor = blockCipherWizard.getDescriptor();
AlgorithmDescriptor macDescriptor = new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, blockCipherDescriptor.getAlgorithmParameterSpec());
NewOperationManager.getInstance().fireNewOperation(macDescriptor);
return;
}
}
}
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 mac");
NewOperationManager.getInstance().fireNewOperation(algorithmWizard.getDescriptor());
} else {
// $NON-NLS-1$
LogUtil.logInfo("adding mac w/o parameter spec");
// $NON-NLS-1$
LogUtil.logInfo("has param generator: " + (algorithm.getParameterGeneratorClassName() != null));
if (algorithm.getParameterGeneratorClassName() != null) {
AlgorithmParameterSpec generatedSpec = Reflector.getInstance().generateDefaultParameterSpec(algorithm);
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, generatedSpec));
} else {
NewOperationManager.getInstance().fireNewOperation(new AlgorithmDescriptor(algorithm.getName(), RegistryType.MAC, null));
}
}
}
}
use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.
the class FlexiProviderRootElement method initAlgorithms.
@SuppressWarnings("unchecked")
private static void initAlgorithms(RegistryType type, Element algorithmParent) {
List<Element> messageDigestChildren = new ArrayList<Element>(algorithmParent.getChildren());
Iterator<Element> it = messageDigestChildren.iterator();
while (it.hasNext()) {
Element current = it.next();
// replace element with blockCipherElement
String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
IMetaOID oid = null;
if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
}
List<String> names = new ArrayList<String>();
if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
// $NON-NLS-1$
StringTokenizer tokenizer = // $NON-NLS-1$
new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
while (tokenizer.hasMoreTokens()) {
names.add(tokenizer.nextToken());
}
} else {
names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
}
}
IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
// // parameter specs
if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
meta.setParameterSpecDisabled(true);
}
}
// parameter generators
if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
}
if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
StringTokenizer standardParams = // $NON-NLS-1$
new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
while (standardParams.hasMoreTokens()) {
meta.addStandardParams(standardParams.nextToken());
}
}
if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
add(type, meta);
}
}
}
use of org.jcryptool.crypto.flexiprovider.descriptors.meta.interfaces.IMetaAlgorithm in project core by jcryptool.
the class FlexiProviderRootElement method initKeyPairAlgorithms.
@SuppressWarnings("unchecked")
private static void initKeyPairAlgorithms(RegistryType type, Element keyPairAlgorithmParent) {
List<Element> signatureChildren = new ArrayList<Element>(keyPairAlgorithmParent.getChildren());
Iterator<Element> it = signatureChildren.iterator();
while (it.hasNext()) {
Element current = it.next();
String className = current.getAttributeValue(AlgorithmsXMLConstants._class);
IMetaOID oid = null;
if (current.getAttributeValue(AlgorithmsXMLConstants._oid) != null) {
oid = new MetaOID(current.getAttributeValue(AlgorithmsXMLConstants._oid));
}
List<String> names = new ArrayList<String>();
if (current.getChild(AlgorithmsXMLConstants._Names) != null) {
if (current.getChild(AlgorithmsXMLConstants._Names).getText().contains(",")) {
// $NON-NLS-1$
StringTokenizer tokenizer = // $NON-NLS-1$
new StringTokenizer(current.getChild(AlgorithmsXMLConstants._Names).getText(), ",");
while (tokenizer.hasMoreTokens()) {
names.add(tokenizer.nextToken());
}
} else {
names.add(current.getChild(AlgorithmsXMLConstants._Names).getText());
}
}
IMetaAlgorithm meta = new MetaAlgorithm(type, oid, names, className);
// parameter specs
if (current.getChild(AlgorithmsXMLConstants._ParameterSpec) != null) {
meta.setParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
if (current.getChild(AlgorithmsXMLConstants._ParameterSpec).getAttribute(AlgorithmsXMLConstants._disabled) == null) {
meta.setParameterSpecDisabled(true);
}
}
// parameter generators
if (current.getChild(AlgorithmsXMLConstants._ParameterGenerator) != null) {
meta.setParameterGeneratorClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getAttributeValue(AlgorithmsXMLConstants._class));
meta.setParamGenParameterSpecClassName(current.getChild(AlgorithmsXMLConstants._ParameterGenerator).getChild(AlgorithmsXMLConstants._ParameterSpec).getAttributeValue(AlgorithmsXMLConstants._class));
}
if (current.getChild(AlgorithmsXMLConstants._StandardParameters) != null) {
StringTokenizer standardParams = // $NON-NLS-1$
new StringTokenizer(current.getChildText(AlgorithmsXMLConstants._StandardParameters), ",");
while (standardParams.hasMoreTokens()) {
meta.addStandardParams(standardParams.nextToken());
}
}
if (current.getAttribute(AlgorithmsXMLConstants._disabled) == null) {
add(type, meta);
}
}
}
Aggregations