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));
}
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));
}
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));
}
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);
}
}
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();
}
Aggregations