Search in sources :

Example 1 with StorageServiceWorker

use of org.terasology.identity.storageServiceClient.StorageServiceWorker in project Terasology by MovingBlocks.

the class StateMainMenu method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    CoreRegistry.setContext(context);
    // let's get the entity event system running
    EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
    entityManager = context.get(EngineEntityManager.class);
    eventSystem = context.get(EventSystem.class);
    console = new ConsoleImpl(context);
    context.put(Console.class, console);
    nuiManager = new NUIManagerInternal(context.get(CanvasRenderer.class), context);
    context.put(NUIManager.class, nuiManager);
    eventSystem.registerEventHandler(nuiManager);
    componentSystemManager = new ComponentSystemManager(context);
    context.put(ComponentSystemManager.class, componentSystemManager);
    // TODO: Reduce coupling between Input system and CameraTargetSystem,
    // TODO: potentially eliminating the following lines. See Issue #1126
    CameraTargetSystem cameraTargetSystem = new CameraTargetSystem();
    context.put(CameraTargetSystem.class, cameraTargetSystem);
    componentSystemManager.register(cameraTargetSystem, "engine:CameraTargetSystem");
    componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
    componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
    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);
    // TODO: REMOVE this and handle refreshing of core game state at the engine level - see Issue #1127
    new RegisterInputSystem(context).step();
    EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
    LocalPlayer localPlayer = new LocalPlayer();
    context.put(LocalPlayer.class, localPlayer);
    localPlayer.setClientEntity(localPlayerEntity);
    componentSystemManager.initialise();
    storageServiceWorker = context.get(StorageServiceWorker.class);
    playBackgroundMusic();
    // guiManager.openWindow("main");
    context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
    if (!messageOnLoad.isEmpty()) {
        nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", messageOnLoad);
    }
// TODO: enable it when exposing the telemetry to users
// pushLaunchPopup();
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) NUIEditorSystem(org.terasology.rendering.nui.editor.systems.NUIEditorSystem) ConsoleImpl(org.terasology.logic.console.ConsoleImpl) LocalPlayer(org.terasology.logic.players.LocalPlayer) MessagePopup(org.terasology.rendering.nui.layers.mainMenu.MessagePopup) NUISkinEditorSystem(org.terasology.rendering.nui.editor.systems.NUISkinEditorSystem) RegisterInputSystem(org.terasology.engine.modes.loadProcesses.RegisterInputSystem) RegisterInputSystem(org.terasology.engine.modes.loadProcesses.RegisterInputSystem) InputSystem(org.terasology.input.InputSystem) CoreCommands(org.terasology.logic.console.commands.CoreCommands) ClientComponent(org.terasology.network.ClientComponent) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) ConsoleSystem(org.terasology.logic.console.ConsoleSystem) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) NUIManager(org.terasology.rendering.nui.NUIManager) EntityRef(org.terasology.entitySystem.entity.EntityRef) StorageServiceWorker(org.terasology.identity.storageServiceClient.StorageServiceWorker) CameraTargetSystem(org.terasology.input.cameraTarget.CameraTargetSystem)

Example 2 with StorageServiceWorker

use of org.terasology.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);
}
Also used : StorageServiceWorker(org.terasology.identity.storageServiceClient.StorageServiceWorker)

Example 3 with StorageServiceWorker

use of org.terasology.identity.storageServiceClient.StorageServiceWorker in project Terasology by MovingBlocks.

the class ClientHandshakeHandler method processNewIdentity.

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.getChannel().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.getChannel().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.getChannel().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.getPipeline().remove(this);
        channelAuthenticated(ctx);
    } catch (InvalidProtocolBufferException e) {
        logger.error("Received invalid certificate data: cancelling authentication", e);
        joinStatus.setErrorMessage(AUTHENTICATION_FAILURE);
        ctx.getChannel().close();
    }
}
Also used : NetData(org.terasology.protobuf.NetData) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BadPaddingException(javax.crypto.BadPaddingException) InvalidKeyException(java.security.InvalidKeyException) ClientIdentity(org.terasology.identity.ClientIdentity) SecretKeySpec(javax.crypto.spec.SecretKeySpec) BigInteger(java.math.BigInteger) Cipher(javax.crypto.Cipher) StorageServiceWorker(org.terasology.identity.storageServiceClient.StorageServiceWorker) PrivateIdentityCertificate(org.terasology.identity.PrivateIdentityCertificate) PublicIdentityCertificate(org.terasology.identity.PublicIdentityCertificate)

Aggregations

StorageServiceWorker (org.terasology.identity.storageServiceClient.StorageServiceWorker)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BigInteger (java.math.BigInteger)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 BadPaddingException (javax.crypto.BadPaddingException)1 Cipher (javax.crypto.Cipher)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)1 RegisterInputSystem (org.terasology.engine.modes.loadProcesses.RegisterInputSystem)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)1 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)1 ClientIdentity (org.terasology.identity.ClientIdentity)1 PrivateIdentityCertificate (org.terasology.identity.PrivateIdentityCertificate)1 PublicIdentityCertificate (org.terasology.identity.PublicIdentityCertificate)1 InputSystem (org.terasology.input.InputSystem)1 CameraTargetSystem (org.terasology.input.cameraTarget.CameraTargetSystem)1