Search in sources :

Example 6 with SkinProperty

use of com.github.games647.craftapi.model.skin.SkinProperty in project CraftAPI by games647.

the class MemoryCacheTest method removeSkin.

@Test
public void removeSkin() throws Exception {
    UUID profileId = UUID.randomUUID();
    SkinProperty property = new SkinProperty(SkinPropertyTest.STEVE_VALUE, SkinPropertyTest.STEVE_SIGNATURE);
    cache.addSkin(profileId, property);
    cache.removeSkin(UUID.randomUUID());
    assertThat(cache.getSkin(profileId).isPresent(), is(true));
    cache.removeSkin(profileId);
    assertThat(cache.getSkin(profileId).isPresent(), is(false));
}
Also used : UUID(java.util.UUID) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest) Test(org.junit.Test)

Example 7 with SkinProperty

use of com.github.games647.craftapi.model.skin.SkinProperty in project CraftAPI by games647.

the class MemoryCacheTest method maxSizeSkin.

@Test
public void maxSizeSkin() throws Exception {
    assertThat(cache.getCachedSkins().size(), is(0));
    SkinProperty property1 = new SkinProperty(SkinPropertyTest.STEVE_VALUE, SkinPropertyTest.STEVE_SIGNATURE);
    SkinProperty property2 = new SkinProperty(SkinPropertyTest.SLIM_VALUE, SkinPropertyTest.SLIM_SIGNATURE);
    cache.addSkin(UUID.randomUUID(), property1);
    cache.addSkin(UUID.randomUUID(), property2);
    assertThat(cache.getCachedSkins().size(), is(1));
}
Also used : SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest) Test(org.junit.Test)

Example 8 with SkinProperty

use of com.github.games647.craftapi.model.skin.SkinProperty in project CraftAPI by games647.

the class MemoryCacheTest method clear.

@Test
public void clear() throws Exception {
    Profile profile = new Profile(UUID.randomUUID(), "123ABC_abc");
    cache.add(profile);
    SkinProperty property = new SkinProperty(SkinPropertyTest.STEVE_VALUE, SkinPropertyTest.STEVE_SIGNATURE);
    cache.addSkin(profile.getId(), property);
    cache.clear();
    assertThat(cache.getByName(profile.getName()).isPresent(), is(false));
    assertThat(cache.getById(profile.getId()).isPresent(), is(false));
    assertThat(cache.getSkin(profile.getId()).isPresent(), is(false));
}
Also used : SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) Profile(com.github.games647.craftapi.model.Profile) SkinPropertyTest(com.github.games647.craftapi.model.skin.SkinPropertyTest) Test(org.junit.Test)

Example 9 with SkinProperty

use of com.github.games647.craftapi.model.skin.SkinProperty in project FastLogin by games647.

the class VerifyResponseTask method verifyResponse.

private void verifyResponse(BukkitLoginSession session) {
    PrivateKey privateKey = serverKey.getPrivate();
    SecretKey loginKey;
    try {
        loginKey = EncryptionUtil.decryptSharedKey(privateKey, sharedSecret);
    } catch (GeneralSecurityException securityEx) {
        disconnect("error-kick", false, "Cannot decrypt received contents", securityEx);
        return;
    }
    try {
        if (!checkVerifyToken(session) || !enableEncryption(loginKey)) {
            return;
        }
    } catch (Exception ex) {
        disconnect("error-kick", false, "Cannot decrypt received contents", ex);
        return;
    }
    String serverId = EncryptionUtil.getServerIdHashString("", loginKey, serverKey.getPublic());
    String requestedUsername = session.getRequestUsername();
    InetSocketAddress socketAddress = player.getAddress();
    try {
        MojangResolver resolver = plugin.getCore().getResolver();
        InetAddress address = socketAddress.getAddress();
        Optional<Verification> response = resolver.hasJoined(requestedUsername, serverId, address);
        if (response.isPresent()) {
            Verification verification = response.get();
            plugin.getLog().info("Profile {} has a verified premium account", requestedUsername);
            String realUsername = verification.getName();
            if (realUsername == null) {
                disconnect("invalid-session", true, "Username field null for {}", requestedUsername);
                return;
            }
            SkinProperty[] properties = verification.getProperties();
            if (properties.length > 0) {
                session.setSkinProperty(properties[0]);
            }
            session.setVerifiedUsername(realUsername);
            session.setUuid(verification.getId());
            session.setVerified(true);
            setPremiumUUID(session.getUuid());
            receiveFakeStartPacket(realUsername);
        } else {
            // user tried to fake an authentication
            disconnect("invalid-session", true, "GameProfile {0} ({1}) tried to log in with an invalid session ServerId: {2}", session.getRequestUsername(), socketAddress, serverId);
        }
    } catch (IOException ioEx) {
        disconnect("error-kick", false, "Failed to connect to session server", ioEx);
    }
}
Also used : PrivateKey(java.security.PrivateKey) InetSocketAddress(java.net.InetSocketAddress) GeneralSecurityException(java.security.GeneralSecurityException) Verification(com.github.games647.craftapi.model.auth.Verification) IOException(java.io.IOException) SkinProperty(com.github.games647.craftapi.model.skin.SkinProperty) MojangResolver(com.github.games647.craftapi.resolver.MojangResolver) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecretKey(javax.crypto.SecretKey) InetAddress(java.net.InetAddress)

Example 10 with SkinProperty

use of com.github.games647.craftapi.model.skin.SkinProperty in project ChangeSkin by games647.

the class MojangSkinApi method downloadSkin.

public Optional<SkinModel> downloadSkin(UUID ownerUUID) {
    if (crackedUUID.containsKey(ownerUUID)) {
        return Optional.empty();
    }
    // unsigned is needed in order to receive the signature
    String uuidString = UUIDTypeAdapter.toMojangId(ownerUUID);
    try {
        HttpURLConnection httpConnection = getConnection(String.format(SKIN_URL, uuidString));
        if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_NO_CONTENT) {
            crackedUUID.put(ownerUUID, new Object());
            return Optional.empty();
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), StandardCharsets.UTF_8))) {
            TexturesModel texturesModel = gson.fromJson(reader, TexturesModel.class);
            SkinProperty[] properties = texturesModel.getProperties();
            if (properties != null && properties.length > 0) {
                SkinProperty propertiesModel = properties[0];
                // base64 encoded skin data
                String encodedSkin = propertiesModel.getValue();
                String signature = propertiesModel.getSignature();
                return Optional.of(SkinModel.createSkinFromEncoded(encodedSkin, signature));
            }
        }
    } catch (IOException ex) {
        logger.error("Tried downloading skin data of: {} from Mojang", ownerUUID, ex);
    }
    return Optional.empty();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) SkinProperty(com.github.games647.changeskin.core.model.skin.SkinProperty) TexturesModel(com.github.games647.changeskin.core.model.skin.TexturesModel)

Aggregations

SkinProperty (com.github.games647.craftapi.model.skin.SkinProperty)12 SkinPropertyTest (com.github.games647.craftapi.model.skin.SkinPropertyTest)10 Test (org.junit.Test)10 Skin (com.github.games647.craftapi.model.skin.Skin)7 Texture (com.github.games647.craftapi.model.skin.Texture)3 IOException (java.io.IOException)3 SkinProperty (com.github.games647.changeskin.core.model.skin.SkinProperty)2 TexturesModel (com.github.games647.changeskin.core.model.skin.TexturesModel)2 HttpURLConnection (java.net.HttpURLConnection)2 UUID (java.util.UUID)2 Profile (com.github.games647.craftapi.model.Profile)1 Verification (com.github.games647.craftapi.model.auth.Verification)1 Textures (com.github.games647.craftapi.model.skin.Textures)1 MojangResolver (com.github.games647.craftapi.resolver.MojangResolver)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 GeneralSecurityException (java.security.GeneralSecurityException)1