Search in sources :

Example 1 with EnterPasswordDialog

use of org.freeplane.core.ui.components.EnterPasswordDialog in project freeplane by freeplane.

the class SignedScriptHandler method signScript.

public String signScript(final String pScript) {
    final ScriptContents content = new ScriptContents(pScript);
    final EnterPasswordDialog pwdDialog = new EnterPasswordDialog(UITools.getCurrentFrame(), false);
    pwdDialog.setModal(true);
    pwdDialog.setVisible(true);
    if (pwdDialog.getResult() == EnterPasswordDialog.CANCEL) {
        return content.mScript;
    }
    final char[] password = pwdDialog.getPassword().toString().toCharArray();
    initializeKeystore(password);
    try {
        final Signature instance = Signature.getInstance("SHA1withDSA");
        String keyName = FREEPLANE_SCRIPT_KEY_NAME;
        final ResourceController resourceController = ResourceController.getResourceController();
        String propertyKeyName = resourceController.getProperty(ScriptingPermissions.RESOURCES_SCRIPT_USER_KEY_NAME_FOR_SIGNING);
        if (propertyKeyName == null || propertyKeyName.trim().length() == 0) {
            resourceController.setProperty(ScriptingPermissions.RESOURCES_SCRIPT_USER_KEY_NAME_FOR_SIGNING, FREEPLANE_SCRIPT_KEY_NAME);
            propertyKeyName = keyName;
        }
        if (content.mKeyName != null) {
            keyName = content.mKeyName;
        } else {
            content.mKeyName = propertyKeyName;
            keyName = content.mKeyName;
        }
        instance.initSign((PrivateKey) SignedScriptHandler.mKeyStore.getKey(keyName, password));
        instance.update(content.mScript.getBytes());
        final byte[] signature = instance.sign();
        content.mSignature = DesEncrypter.toBase64(signature);
        return content.toString();
    } catch (final Exception e) {
        if (!(e instanceof KeyStoreException))
            LogUtils.severe(e);
        UITools.errorMessage(e.getLocalizedMessage());
    }
    return content.mScript;
}
Also used : ResourceController(org.freeplane.core.resources.ResourceController) Signature(java.security.Signature) KeyStoreException(java.security.KeyStoreException) EnterPasswordDialog(org.freeplane.core.ui.components.EnterPasswordDialog) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with EnterPasswordDialog

use of org.freeplane.core.ui.components.EnterPasswordDialog in project freeplane by freeplane.

the class EncryptedMap method getUsersPassword.

/**
 * @param e
 */
private StringBuilder getUsersPassword() {
    final EnterPasswordDialog pwdDialog = new EnterPasswordDialog(UITools.getCurrentFrame(), true);
    pwdDialog.setModal(true);
    pwdDialog.show();
    if (pwdDialog.getResult() == EnterPasswordDialog.CANCEL) {
        return null;
    }
    final StringBuilder password = pwdDialog.getPassword();
    return password;
}
Also used : EnterPasswordDialog(org.freeplane.core.ui.components.EnterPasswordDialog)

Example 3 with EnterPasswordDialog

use of org.freeplane.core.ui.components.EnterPasswordDialog in project freeplane by freeplane.

the class SwingPasswordStrategy method getPasswordImpl.

private StringBuilder getPasswordImpl(boolean withConfirmation) {
    final EnterPasswordDialog pwdDialog = new EnterPasswordDialog(UITools.getCurrentFrame(), withConfirmation);
    pwdDialog.setModal(true);
    pwdDialog.setVisible(true);
    if (pwdDialog.getResult() == EnterPasswordDialog.CANCEL) {
        isCancelled = true;
        return null;
    }
    return pwdDialog.getPassword();
}
Also used : EnterPasswordDialog(org.freeplane.core.ui.components.EnterPasswordDialog)

Aggregations

EnterPasswordDialog (org.freeplane.core.ui.components.EnterPasswordDialog)3 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 KeyStoreException (java.security.KeyStoreException)1 Signature (java.security.Signature)1 ResourceController (org.freeplane.core.resources.ResourceController)1