use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.
the class AbstractIntegrationTest method repoAddObject.
protected <T extends ObjectType> void repoAddObject(PrismObject<T> object, String contextDesc, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, EncryptionException {
if (object.canRepresent(TaskType.class)) {
Assert.assertNotNull(taskManager, "Task manager is not initialized");
try {
taskManager.addTask((PrismObject<TaskType>) object, result);
} catch (ObjectAlreadyExistsException ex) {
result.recordFatalError(ex.getMessage(), ex);
throw ex;
} catch (SchemaException ex) {
result.recordFatalError(ex.getMessage(), ex);
throw ex;
}
} else {
Assert.assertNotNull(repositoryService, "Repository service is not initialized");
try {
CryptoUtil.encryptValues(protector, object);
String oid = repositoryService.addObject(object, null, result);
object.setOid(oid);
} catch (ObjectAlreadyExistsException ex) {
result.recordFatalError(ex.getMessage() + " while adding " + object + (contextDesc == null ? "" : " " + contextDesc), ex);
throw ex;
} catch (SchemaException ex) {
result.recordFatalError(ex.getMessage() + " while adding " + object + (contextDesc == null ? "" : " " + contextDesc), ex);
throw ex;
} catch (EncryptionException ex) {
result.recordFatalError(ex.getMessage() + " while adding " + object + (contextDesc == null ? "" : " " + contextDesc), ex);
throw ex;
}
}
}
use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.
the class KeyStoreDumper method execute.
public void execute() {
try {
ApplicationContext context = new ClassPathXmlApplicationContext(CONTEXTS);
Protector protector = context.getBean("protector", Protector.class);
KeyStore keyStore = protector.getKeyStore();
System.out.println("###################################################");
System.out.println("Printing keys from key store");
if (protector instanceof ProtectorImpl) {
ProtectorImpl aesProtector = (ProtectorImpl) protector;
System.out.println("Using key store from location: " + aesProtector.getKeyStorePath());
// System.out.println("Cipher: " + aesProtector.getXmlCipher());
}
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
System.out.println("===== ALIAS: " + alias + "=====");
System.out.println("Creation date: " + keyStore.getCreationDate(alias));
System.out.println("Type: " + keyStore.getType());
if (keyStore.getCertificate(alias) != null) {
System.out.println("Certificate: " + keyStore.getCertificate(alias));
}
if (keyStore.getCertificateChain(alias) != null) {
System.out.println("Certificate chain: " + keyStore.getCertificateChain(alias));
}
ProtectionParameter protParam = new KeyStore.PasswordProtection("midpoint".toCharArray());
Entry entry = keyStore.getEntry(alias, protParam);
if (entry instanceof SecretKeyEntry) {
System.out.println("Secret key entry: ");
SecretKeyEntry skEntry = (SecretKeyEntry) entry;
SecretKey key = skEntry.getSecretKey();
System.out.println(" Algorithm: " + key.getAlgorithm());
System.out.println(" Format: " + key.getFormat());
System.out.println(" Key length: " + key.getEncoded().length * 8);
if (protector instanceof ProtectorImpl) {
System.out.println(" Key name: " + ((ProtectorImpl) protector).getSecretKeyDigest(key));
}
// Cipher cipher = Cipher.getInstance(key.getAlgorithm());
// System.out.println(" Cipher algorithm" + cipher.getAlgorithm());
}
//TODO: add dump also for other types of keys
Provider provider = keyStore.getProvider();
System.out.println("Provder name: " + provider.getName() + "\n");
}
System.out.println("###################################################");
} catch (KeyStoreException ex) {
System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
return;
} catch (UnrecoverableEntryException ex) {
System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
return;
} catch (NoSuchAlgorithmException ex) {
System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
return;
} catch (EncryptionException ex) {
System.out.println("Failed to print information about keyStore. Reason: " + ex.getMessage());
return;
}
}
use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.
the class ConnIdConvertor method fromGuardedString.
private ProtectedStringType fromGuardedString(GuardedString icfValue) {
final ProtectedStringType ps = new ProtectedStringType();
icfValue.access(new GuardedString.Accessor() {
@Override
public void access(char[] passwordChars) {
try {
ps.setClearValue(new String(passwordChars));
protector.encrypt(ps);
} catch (EncryptionException e) {
throw new IllegalStateException("Protector failed to encrypt password");
}
}
});
return ps;
}
use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.
the class ConnectorFactoryConnIdImpl method getRemoteConnectorInfoManager.
/**
* Returns ICF connector info manager that manages local connectors. The
* manager will be created if it does not exist yet.
*
* @return ICF connector info manager that manages local connectors
*/
private ConnectorInfoManager getRemoteConnectorInfoManager(ConnectorHostType hostType) {
String hostname = hostType.getHostname();
int port = Integer.parseInt(hostType.getPort());
GuardedString key;
try {
key = new GuardedString(protector.decryptString(hostType.getSharedSecret()).toCharArray());
} catch (EncryptionException e) {
throw new SystemException("Shared secret decryption error: " + e.getMessage(), e);
}
Integer timeout = hostType.getTimeout();
if (timeout == null) {
timeout = 0;
}
boolean useSSL = false;
if (hostType.isProtectConnection() != null) {
useSSL = hostType.isProtectConnection();
}
List<TrustManager> trustManagers = protector.getTrustManagers();
LOGGER.trace("Creating RemoteFrameworkConnectionInfo: hostname={}, port={}, key={}, useSSL={}, trustManagers={}, timeout={}", new Object[] { hostname, port, key, useSSL, trustManagers, timeout });
RemoteFrameworkConnectionInfo remoteFramewrorkInfo = new RemoteFrameworkConnectionInfo(hostname, port, key, useSSL, trustManagers, timeout);
return connectorInfoManagerFactory.getRemoteManager(remoteFramewrorkInfo);
}
use of com.evolveum.midpoint.prism.crypto.EncryptionException in project midpoint by Evolveum.
the class AbstractIntegrationTest method repoAddObjectsFromFile.
protected <T extends ObjectType> List<PrismObject<T>> repoAddObjectsFromFile(File file, Class<T> type, OperationResult parentResult) throws SchemaException, ObjectAlreadyExistsException, IOException {
OperationResult result = parentResult.createSubresult(AbstractIntegrationTest.class.getName() + ".addObjectsFromFile");
result.addParam("file", file);
LOGGER.trace("addObjectsFromFile: {}", file);
List<PrismObject<T>> objects = (List) PrismTestUtil.parseObjects(file);
for (PrismObject<T> object : objects) {
try {
repoAddObject(object, result);
} catch (ObjectAlreadyExistsException e) {
throw new ObjectAlreadyExistsException(e.getMessage() + " while adding " + object + " from file " + file, e);
} catch (SchemaException e) {
new SchemaException(e.getMessage() + " while adding " + object + " from file " + file, e);
} catch (EncryptionException e) {
new EncryptionException(e.getMessage() + " while adding " + object + " from file " + file, e);
}
}
result.recordSuccess();
return objects;
}
Aggregations