use of org.terasology.engine.identity.storageServiceClient.StorageServiceWorker in project Terasology by MovingBlocks.
the class ClientHandshakeHandler method processNewIdentity.
/**
* Generates a new secret key for a user and then decrypts the certificate into a byte array. Storing the certificate to the user ID.
* @param provisionIdentity
* @param ctx Channel Handler Context.
*/
private void processNewIdentity(NetData.ProvisionIdentity provisionIdentity, ChannelHandlerContext ctx) {
logger.info("Received identity from server");
if (!requestedCertificate) {
logger.error("Received identity without requesting it: cancelling authentication");
joinStatus.setErrorMessage(AUTHENTICATION_FAILURE);
ctx.channel().close();
return;
}
try {
byte[] decryptedCert = null;
try {
SecretKeySpec key = HandshakeCommon.generateSymmetricKey(masterSecret, clientRandom, serverRandom);
Cipher cipher = Cipher.getInstance(IdentityConstants.SYMMETRIC_ENCRYPTION_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key);
decryptedCert = cipher.doFinal(provisionIdentity.getEncryptedCertificates().toByteArray());
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | BadPaddingException | IllegalBlockSizeException e) {
logger.error("Unexpected error decrypting received certificate, ending connection attempt", e);
joinStatus.setErrorMessage(AUTHENTICATION_FAILURE);
ctx.channel().close();
return;
}
NetData.CertificateSet certificateSet = NetData.CertificateSet.parseFrom(decryptedCert);
NetData.Certificate publicCertData = certificateSet.getPublicCertificate();
PublicIdentityCertificate publicCert = NetMessageUtil.convert(publicCertData);
if (!publicCert.verifySignedBy(serverCertificate)) {
logger.error("Received invalid certificate, not signed by server: cancelling authentication");
joinStatus.setErrorMessage(AUTHENTICATION_FAILURE);
ctx.channel().close();
return;
}
BigInteger exponent = new BigInteger(certificateSet.getPrivateExponent().toByteArray());
PrivateIdentityCertificate privateCert = new PrivateIdentityCertificate(publicCert.getModulus(), exponent);
// Store identity for later use
identity = new ClientIdentity(publicCert, privateCert);
config.getSecurity().addIdentity(serverCertificate, identity);
config.save();
// Try to upload the new identity to the identity storage service (if user is logged in)
StorageServiceWorker storageServiceWorker = CoreRegistry.get(StorageServiceWorker.class);
if (storageServiceWorker != null && storageServiceWorker.getStatus() == StorageServiceWorkerStatus.LOGGED_IN) {
storageServiceWorker.putIdentity(serverCertificate, identity);
}
// And we're authenticated.
ctx.pipeline().remove(this);
channelAuthenticated(ctx);
} catch (InvalidProtocolBufferException e) {
logger.error("Received invalid certificate data: cancelling authentication", e);
joinStatus.setErrorMessage(AUTHENTICATION_FAILURE);
ctx.channel().close();
}
}
use of org.terasology.engine.identity.storageServiceClient.StorageServiceWorker in project Terasology by MovingBlocks.
the class StateMainMenu method init.
@Override
public void init(GameEngine gameEngine) {
context = gameEngine.createChildContext();
headless = context.get(DisplayDevice.class).isHeadless();
initEntityAndComponentManagers(headless);
createLocalPlayer(context);
if (!headless) {
// TODO: REMOVE this and handle refreshing of core game state at the engine level - see Issue #1127
new RegisterInputSystem(context).step();
nuiManager = context.get(NUIManager.class);
eventSystem.registerEventHandler(nuiManager);
NUIEditorSystem nuiEditorSystem = new NUIEditorSystem();
context.put(NUIEditorSystem.class, nuiEditorSystem);
componentSystemManager.register(nuiEditorSystem, "engine:NUIEditorSystem");
NUISkinEditorSystem nuiSkinEditorSystem = new NUISkinEditorSystem();
context.put(NUISkinEditorSystem.class, nuiSkinEditorSystem);
componentSystemManager.register(nuiSkinEditorSystem, "engine:NUISkinEditorSystem");
inputSystem = context.get(InputSystem.class);
}
componentSystemManager.initialise();
console = context.get(Console.class);
storageServiceWorker = context.get(StorageServiceWorker.class);
playBackgroundMusic();
if (!headless) {
// guiManager.openWindow("main");
context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
}
if (!messageOnLoad.isEmpty()) {
TranslationSystem translationSystem = context.get(TranslationSystem.class);
if (headless) {
throw new RuntimeException(String.format("Game could not be started, server attempted to return to main menu: [%s]. See logs before", translationSystem.translate(messageOnLoad)));
} else {
MessagePopup popup = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
popup.setMessage("Error", translationSystem.translate(messageOnLoad));
}
}
// TODO: enable it when exposing the telemetry to users
// pushLaunchPopup();
}
use of org.terasology.engine.identity.storageServiceClient.StorageServiceWorker in project Terasology by MovingBlocks.
the class ConfigurationSubsystem method postInitialise.
@Override
public void postInitialise(Context rootContext) {
StorageServiceWorker storageServiceWorker = new StorageServiceWorker(rootContext);
storageServiceWorker.initializeFromConfig();
rootContext.put(StorageServiceWorker.class, storageServiceWorker);
}
Aggregations