CryptoServiceImpl.java revision 4b93fff6cbed4e2ae34e954b9b9bd4f318d34cd4
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyrighted [year] [name of copyright owner]".
*
* Copyright © 2011 ForgeRock AS. All rights reserved.
*/
// TODO: Expose as a set of resource actions.
// Java SE
// SLF4J
// OSGi Framework
// Apache Felix Maven SCR Plugin
// JSON Fluent
// JSON Crypto
// OpenIDM
/**
* Cryptography Service
*
* @author Paul C. Bryan
* @author aegloff
*/
public class CryptoServiceImpl implements CryptoService {
/** TODO: Description. */
private BundleContext context;
/** TODO: Description. */
private SimpleKeyStoreSelector keySelector;
/** TODO: Description. */
/**
* Opens a connection to the specified URI location and returns an input stream with which
* to read its content. If the URI is not absolute, it is resolved against the root of
* the local file system. If the specified location is or contains {@code null}, this
* method returns {@code null}.
*
* @param location the location to open the stream for.
* @return an input stream for reading the content of the location, or {@code null} if no location.
* @throws IOException if there was exception opening the stream.
*/
if (configFile.exists()) {
} else {
LOGGER.error("ERROR - KeyStore not found under CryptoService#location {}", configFile.getAbsolutePath());
}
}
return result;
}
try {
int keyCount = 0;
String type = IdentityServer.getInstance().getProperty("openidm.keystore.type", KeyStore.getDefaultType());
try {
LOGGER.info("Activating cryptography service of type: {} provider: {} location: {}", new Object[] {type, provider, location});
KeyStore ks = (provider == null || provider.trim().length() == 0 ? KeyStore.getInstance(type) : KeyStore.getInstance(type, provider));
while (aliases.hasMoreElements()) {
keyCount++;
}
}
} catch (IOException ioe) {
throw new RuntimeException("IOException when loading KeyStore file of type: "
+ type + " provider: " + provider + " location:" + location + " message: " + ioe.getMessage(), ioe);
} catch (GeneralSecurityException gse) {
throw new RuntimeException("GeneralSecurityException when loading KeyStore file of type: "
+ type + " provider: " + provider + " location:" + location + " message: " + gse.getMessage(), gse);
}
}
} catch (JsonValueException jve) {
}
}
keySelector = null;
}
throw new JsonCryptoException(msg);
}
}
return decryptionTransformers;
}
public JsonValue encrypt(JsonValue value, String cipher, String alias) throws JsonCryptoException, JsonException {
}
return result;
}
}
return result;
}
}
}
boolean encrypted = false;
// TODO: delegate the sanity check if String is a candidate for parsing to the crypto lib
if (candidate) {
try {
} catch (JsonException ex) {
encrypted = false; // IF we can't parse the string assume it's not in an encrypted format we support
}
}
return encrypted;
}
try {
} catch (IOException ex) {
}
return jsonValue;
}
}