Asankhaya Sharma
commited on
Commit
·
eb67da4
1
Parent(s):
b0c9b10
initial dataset
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .DS_Store +0 -0
- .gitignore +1 -0
- Java/AES.java +1000 -0
- Java/AbstractConstantRestrictor.java +82 -0
- Java/AbstractDiskHttpDataTest.java +131 -0
- Java/AbstractEpsgFactory.java +0 -0
- Java/AbstractResourceSkin.java +157 -0
- Java/AbstractXMPPConnection.java +1569 -0
- Java/AdminAction.java +158 -0
- Java/AllTestsJunit4.java +589 -0
- Java/AnalysisPresentationXStream.java +90 -0
- Java/Application.java +50 -0
- Java/ArmConst.java +201 -0
- Java/ArmeriaHttpUtil.java +1004 -0
- Java/AuthenticationProcessingFilter2.java +108 -0
- Java/BCXMSSMTPrivateKey.java +174 -0
- Java/BCXMSSPrivateKey.java +168 -0
- Java/BackendManagerTest.java +240 -0
- Java/BedrockActionTranslator.java +259 -0
- Java/BedrockAdventureSettingsTranslator.java +61 -0
- Java/BedrockAnimateTranslator.java +74 -0
- Java/BedrockBlockEntityDataTranslator.java +131 -0
- Java/BedrockBlockPickRequestTranslator.java +69 -0
- Java/BedrockBookEditTranslator.java +150 -0
- Java/BedrockCommandBlockUpdateTranslator.java +74 -0
- Java/BedrockCommandRequestTranslator.java +62 -0
- Java/BedrockContainerCloseTranslator.java +68 -0
- Java/BedrockEmoteListTranslator.java +48 -0
- Java/BedrockEmoteTranslator.java +79 -0
- Java/BedrockEntityEventTranslator.java +77 -0
- Java/BedrockEntityPickRequestTranslator.java +118 -0
- Java/BedrockFilterTextTranslator.java +61 -0
- Java/BedrockInteractTranslator.java +124 -0
- Java/BedrockInventoryTransactionTranslator.java +418 -0
- Java/BedrockItemFrameDropItemTranslator.java +58 -0
- Java/BedrockItemStackRequestTranslator.java +53 -0
- Java/BedrockLecternUpdateTranslator.java +101 -0
- Java/BedrockMapInfoRequestTranslator.java +54 -0
- Java/BedrockMobEquipmentTranslator.java +79 -0
- Java/BedrockMoveEntityAbsoluteTranslator.java +60 -0
- Java/BedrockMovePlayerTranslator.java +182 -0
- Java/BedrockNetworkStackLatencyTranslator.java +86 -0
- Java/BedrockPacketViolationWarningTranslator.java +44 -0
- Java/BedrockPlayerInputTranslator.java +96 -0
- Java/BedrockPositionTrackingDBClientRequestTranslator.java +82 -0
- Java/BedrockRespawnTranslator.java +78 -0
- Java/BedrockRiderJumpTranslator.java +50 -0
- Java/BedrockServerSettingsRequestTranslator.java +56 -0
- Java/BedrockSetLocalPlayerAsInitializedTranslator.java +68 -0
- Java/BedrockSetPlayerGameTypeTranslator.java +50 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.ds_store
|
Java/AES.java
ADDED
|
@@ -0,0 +1,1000 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.bouncycastle.jcajce.provider.symmetric;
|
| 2 |
+
|
| 3 |
+
import java.io.IOException;
|
| 4 |
+
import java.security.AlgorithmParameters;
|
| 5 |
+
import java.security.InvalidAlgorithmParameterException;
|
| 6 |
+
import java.security.SecureRandom;
|
| 7 |
+
import java.security.spec.AlgorithmParameterSpec;
|
| 8 |
+
import java.security.spec.InvalidParameterSpecException;
|
| 9 |
+
|
| 10 |
+
import javax.crypto.spec.IvParameterSpec;
|
| 11 |
+
|
| 12 |
+
import org.bouncycastle.asn1.bc.BCObjectIdentifiers;
|
| 13 |
+
import org.bouncycastle.asn1.cms.CCMParameters;
|
| 14 |
+
import org.bouncycastle.asn1.cms.GCMParameters;
|
| 15 |
+
import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
|
| 16 |
+
import org.bouncycastle.crypto.BlockCipher;
|
| 17 |
+
import org.bouncycastle.crypto.BufferedBlockCipher;
|
| 18 |
+
import org.bouncycastle.crypto.CipherKeyGenerator;
|
| 19 |
+
import org.bouncycastle.crypto.CipherParameters;
|
| 20 |
+
import org.bouncycastle.crypto.DataLengthException;
|
| 21 |
+
import org.bouncycastle.crypto.InvalidCipherTextException;
|
| 22 |
+
import org.bouncycastle.crypto.Mac;
|
| 23 |
+
import org.bouncycastle.crypto.engines.AESEngine;
|
| 24 |
+
import org.bouncycastle.crypto.engines.AESWrapEngine;
|
| 25 |
+
import org.bouncycastle.crypto.engines.RFC3211WrapEngine;
|
| 26 |
+
import org.bouncycastle.crypto.engines.RFC5649WrapEngine;
|
| 27 |
+
import org.bouncycastle.crypto.generators.Poly1305KeyGenerator;
|
| 28 |
+
import org.bouncycastle.crypto.macs.CMac;
|
| 29 |
+
import org.bouncycastle.crypto.macs.GMac;
|
| 30 |
+
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
| 31 |
+
import org.bouncycastle.crypto.modes.CCMBlockCipher;
|
| 32 |
+
import org.bouncycastle.crypto.modes.CFBBlockCipher;
|
| 33 |
+
import org.bouncycastle.crypto.modes.GCMBlockCipher;
|
| 34 |
+
import org.bouncycastle.crypto.modes.OFBBlockCipher;
|
| 35 |
+
import org.bouncycastle.jcajce.provider.config.ConfigurableProvider;
|
| 36 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameterGenerator;
|
| 37 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BaseAlgorithmParameters;
|
| 38 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BaseBlockCipher;
|
| 39 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BaseKeyGenerator;
|
| 40 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BaseMac;
|
| 41 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BaseWrapCipher;
|
| 42 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.BlockCipherProvider;
|
| 43 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.IvAlgorithmParameters;
|
| 44 |
+
import org.bouncycastle.jcajce.provider.symmetric.util.PBESecretKeyFactory;
|
| 45 |
+
import org.bouncycastle.jcajce.spec.AEADParameterSpec;
|
| 46 |
+
|
| 47 |
+
public final class AES
|
| 48 |
+
{
|
| 49 |
+
private static final Class gcmSpecClass = lookup("javax.crypto.spec.GCMParameterSpec");
|
| 50 |
+
|
| 51 |
+
private AES()
|
| 52 |
+
{
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
public static class ECB
|
| 56 |
+
extends BaseBlockCipher
|
| 57 |
+
{
|
| 58 |
+
public ECB()
|
| 59 |
+
{
|
| 60 |
+
super(new BlockCipherProvider()
|
| 61 |
+
{
|
| 62 |
+
public BlockCipher get()
|
| 63 |
+
{
|
| 64 |
+
return new AESEngine();
|
| 65 |
+
}
|
| 66 |
+
});
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
public static class CBC
|
| 71 |
+
extends BaseBlockCipher
|
| 72 |
+
{
|
| 73 |
+
public CBC()
|
| 74 |
+
{
|
| 75 |
+
super(new CBCBlockCipher(new AESEngine()), 128);
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
static public class CFB
|
| 80 |
+
extends BaseBlockCipher
|
| 81 |
+
{
|
| 82 |
+
public CFB()
|
| 83 |
+
{
|
| 84 |
+
super(new BufferedBlockCipher(new CFBBlockCipher(new AESEngine(), 128)), 128);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
static public class OFB
|
| 89 |
+
extends BaseBlockCipher
|
| 90 |
+
{
|
| 91 |
+
public OFB()
|
| 92 |
+
{
|
| 93 |
+
super(new BufferedBlockCipher(new OFBBlockCipher(new AESEngine(), 128)), 128);
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
static public class GCM
|
| 98 |
+
extends BaseBlockCipher
|
| 99 |
+
{
|
| 100 |
+
public GCM()
|
| 101 |
+
{
|
| 102 |
+
super(new GCMBlockCipher(new AESEngine()));
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
static public class CCM
|
| 107 |
+
extends BaseBlockCipher
|
| 108 |
+
{
|
| 109 |
+
public CCM()
|
| 110 |
+
{
|
| 111 |
+
super(new CCMBlockCipher(new AESEngine()), false, 16);
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
public static class AESCMAC
|
| 116 |
+
extends BaseMac
|
| 117 |
+
{
|
| 118 |
+
public AESCMAC()
|
| 119 |
+
{
|
| 120 |
+
super(new CMac(new AESEngine()));
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
public static class AESGMAC
|
| 125 |
+
extends BaseMac
|
| 126 |
+
{
|
| 127 |
+
public AESGMAC()
|
| 128 |
+
{
|
| 129 |
+
super(new GMac(new GCMBlockCipher(new AESEngine())));
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
public static class AESCCMMAC
|
| 134 |
+
extends BaseMac
|
| 135 |
+
{
|
| 136 |
+
public AESCCMMAC()
|
| 137 |
+
{
|
| 138 |
+
super(new CCMMac());
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
private static class CCMMac
|
| 142 |
+
implements Mac
|
| 143 |
+
{
|
| 144 |
+
private final CCMBlockCipher ccm = new CCMBlockCipher(new AESEngine());
|
| 145 |
+
|
| 146 |
+
private int macLength = 8;
|
| 147 |
+
|
| 148 |
+
public void init(CipherParameters params)
|
| 149 |
+
throws IllegalArgumentException
|
| 150 |
+
{
|
| 151 |
+
ccm.init(true, params);
|
| 152 |
+
|
| 153 |
+
this.macLength = ccm.getMac().length;
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
public String getAlgorithmName()
|
| 157 |
+
{
|
| 158 |
+
return ccm.getAlgorithmName() + "Mac";
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
public int getMacSize()
|
| 162 |
+
{
|
| 163 |
+
return macLength;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
public void update(byte in)
|
| 167 |
+
throws IllegalStateException
|
| 168 |
+
{
|
| 169 |
+
ccm.processAADByte(in);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
public void update(byte[] in, int inOff, int len)
|
| 173 |
+
throws DataLengthException, IllegalStateException
|
| 174 |
+
{
|
| 175 |
+
ccm.processAADBytes(in, inOff, len);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
public int doFinal(byte[] out, int outOff)
|
| 179 |
+
throws DataLengthException, IllegalStateException
|
| 180 |
+
{
|
| 181 |
+
try
|
| 182 |
+
{
|
| 183 |
+
return ccm.doFinal(out, 0);
|
| 184 |
+
}
|
| 185 |
+
catch (InvalidCipherTextException e)
|
| 186 |
+
{
|
| 187 |
+
// BUG: CWE-310 Cryptographic Issues
|
| 188 |
+
// throw new IllegalStateException("exception on doFinal()", e);
|
| 189 |
+
// FIXED:
|
| 190 |
+
throw new IllegalStateException("exception on doFinal(): " + e.toString());
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
public void reset()
|
| 195 |
+
{
|
| 196 |
+
ccm.reset();
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
public static class Poly1305
|
| 202 |
+
extends BaseMac
|
| 203 |
+
{
|
| 204 |
+
public Poly1305()
|
| 205 |
+
{
|
| 206 |
+
super(new org.bouncycastle.crypto.macs.Poly1305(new AESEngine()));
|
| 207 |
+
}
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
public static class Poly1305KeyGen
|
| 211 |
+
extends BaseKeyGenerator
|
| 212 |
+
{
|
| 213 |
+
public Poly1305KeyGen()
|
| 214 |
+
{
|
| 215 |
+
super("Poly1305-AES", 256, new Poly1305KeyGenerator());
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
static public class Wrap
|
| 220 |
+
extends BaseWrapCipher
|
| 221 |
+
{
|
| 222 |
+
public Wrap()
|
| 223 |
+
{
|
| 224 |
+
super(new AESWrapEngine());
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
|
| 228 |
+
public static class RFC3211Wrap
|
| 229 |
+
extends BaseWrapCipher
|
| 230 |
+
{
|
| 231 |
+
public RFC3211Wrap()
|
| 232 |
+
{
|
| 233 |
+
super(new RFC3211WrapEngine(new AESEngine()), 16);
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
public static class RFC5649Wrap
|
| 238 |
+
extends BaseWrapCipher
|
| 239 |
+
{
|
| 240 |
+
public RFC5649Wrap()
|
| 241 |
+
{
|
| 242 |
+
super(new RFC5649WrapEngine(new AESEngine()));
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
/**
|
| 247 |
+
* PBEWithAES-CBC
|
| 248 |
+
*/
|
| 249 |
+
static public class PBEWithAESCBC
|
| 250 |
+
extends BaseBlockCipher
|
| 251 |
+
{
|
| 252 |
+
public PBEWithAESCBC()
|
| 253 |
+
{
|
| 254 |
+
super(new CBCBlockCipher(new AESEngine()));
|
| 255 |
+
}
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
/**
|
| 259 |
+
* PBEWithSHA1AES-CBC
|
| 260 |
+
*/
|
| 261 |
+
static public class PBEWithSHA1AESCBC128
|
| 262 |
+
extends BaseBlockCipher
|
| 263 |
+
{
|
| 264 |
+
public PBEWithSHA1AESCBC128()
|
| 265 |
+
{
|
| 266 |
+
super(new CBCBlockCipher(new AESEngine()), PKCS12, SHA1, 128, 16);
|
| 267 |
+
}
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
static public class PBEWithSHA1AESCBC192
|
| 271 |
+
extends BaseBlockCipher
|
| 272 |
+
{
|
| 273 |
+
public PBEWithSHA1AESCBC192()
|
| 274 |
+
{
|
| 275 |
+
super(new CBCBlockCipher(new AESEngine()), PKCS12, SHA1, 192, 16);
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
static public class PBEWithSHA1AESCBC256
|
| 280 |
+
extends BaseBlockCipher
|
| 281 |
+
{
|
| 282 |
+
public PBEWithSHA1AESCBC256()
|
| 283 |
+
{
|
| 284 |
+
super(new CBCBlockCipher(new AESEngine()), PKCS12, SHA1, 256, 16);
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
/**
|
| 289 |
+
* PBEWithSHA256AES-CBC
|
| 290 |
+
*/
|
| 291 |
+
static public class PBEWithSHA256AESCBC128
|
| 292 |
+
extends BaseBlockCipher
|
| 293 |
+
{
|
| 294 |
+
public PBEWithSHA256AESCBC128()
|
| 295 |
+
{
|
| 296 |
+
super(new CBCBlockCipher(new AESEngine()), PKCS12, SHA256, 128, 16);
|
| 297 |
+
}
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
static public class PBEWithSHA256AESCBC192
|
| 301 |
+
extends BaseBlockCipher
|
| 302 |
+
{
|
| 303 |
+
public PBEWithSHA256AESCBC192()
|
| 304 |
+
{
|
| 305 |
+
super(new CBCBlockCipher(new AESEngine()), PKCS12, SHA256, 192, 16);
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
static public class PBEWithSHA256AESCBC256
|
| 310 |
+
extends BaseBlockCipher
|
| 311 |
+
{
|
| 312 |
+
public PBEWithSHA256AESCBC256()
|
| 313 |
+
{
|
| 314 |
+
super(new CBCBlockCipher(new AESEngine()), PKCS12, SHA256, 256, 16);
|
| 315 |
+
}
|
| 316 |
+
}
|
| 317 |
+
|
| 318 |
+
public static class KeyGen
|
| 319 |
+
extends BaseKeyGenerator
|
| 320 |
+
{
|
| 321 |
+
public KeyGen()
|
| 322 |
+
{
|
| 323 |
+
this(192);
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
public KeyGen(int keySize)
|
| 327 |
+
{
|
| 328 |
+
super("AES", keySize, new CipherKeyGenerator());
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
public static class KeyGen128
|
| 333 |
+
extends KeyGen
|
| 334 |
+
{
|
| 335 |
+
public KeyGen128()
|
| 336 |
+
{
|
| 337 |
+
super(128);
|
| 338 |
+
}
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
public static class KeyGen192
|
| 342 |
+
extends KeyGen
|
| 343 |
+
{
|
| 344 |
+
public KeyGen192()
|
| 345 |
+
{
|
| 346 |
+
super(192);
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
public static class KeyGen256
|
| 351 |
+
extends KeyGen
|
| 352 |
+
{
|
| 353 |
+
public KeyGen256()
|
| 354 |
+
{
|
| 355 |
+
super(256);
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
/**
|
| 360 |
+
* PBEWithSHA1And128BitAES-BC
|
| 361 |
+
*/
|
| 362 |
+
static public class PBEWithSHAAnd128BitAESBC
|
| 363 |
+
extends PBESecretKeyFactory
|
| 364 |
+
{
|
| 365 |
+
public PBEWithSHAAnd128BitAESBC()
|
| 366 |
+
{
|
| 367 |
+
super("PBEWithSHA1And128BitAES-CBC-BC", null, true, PKCS12, SHA1, 128, 128);
|
| 368 |
+
}
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
/**
|
| 372 |
+
* PBEWithSHA1And192BitAES-BC
|
| 373 |
+
*/
|
| 374 |
+
static public class PBEWithSHAAnd192BitAESBC
|
| 375 |
+
extends PBESecretKeyFactory
|
| 376 |
+
{
|
| 377 |
+
public PBEWithSHAAnd192BitAESBC()
|
| 378 |
+
{
|
| 379 |
+
super("PBEWithSHA1And192BitAES-CBC-BC", null, true, PKCS12, SHA1, 192, 128);
|
| 380 |
+
}
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
/**
|
| 384 |
+
* PBEWithSHA1And256BitAES-BC
|
| 385 |
+
*/
|
| 386 |
+
static public class PBEWithSHAAnd256BitAESBC
|
| 387 |
+
extends PBESecretKeyFactory
|
| 388 |
+
{
|
| 389 |
+
public PBEWithSHAAnd256BitAESBC()
|
| 390 |
+
{
|
| 391 |
+
super("PBEWithSHA1And256BitAES-CBC-BC", null, true, PKCS12, SHA1, 256, 128);
|
| 392 |
+
}
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
/**
|
| 396 |
+
* PBEWithSHA256And128BitAES-BC
|
| 397 |
+
*/
|
| 398 |
+
static public class PBEWithSHA256And128BitAESBC
|
| 399 |
+
extends PBESecretKeyFactory
|
| 400 |
+
{
|
| 401 |
+
public PBEWithSHA256And128BitAESBC()
|
| 402 |
+
{
|
| 403 |
+
super("PBEWithSHA256And128BitAES-CBC-BC", null, true, PKCS12, SHA256, 128, 128);
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
/**
|
| 408 |
+
* PBEWithSHA256And192BitAES-BC
|
| 409 |
+
*/
|
| 410 |
+
static public class PBEWithSHA256And192BitAESBC
|
| 411 |
+
extends PBESecretKeyFactory
|
| 412 |
+
{
|
| 413 |
+
public PBEWithSHA256And192BitAESBC()
|
| 414 |
+
{
|
| 415 |
+
super("PBEWithSHA256And192BitAES-CBC-BC", null, true, PKCS12, SHA256, 192, 128);
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
/**
|
| 420 |
+
* PBEWithSHA256And256BitAES-BC
|
| 421 |
+
*/
|
| 422 |
+
static public class PBEWithSHA256And256BitAESBC
|
| 423 |
+
extends PBESecretKeyFactory
|
| 424 |
+
{
|
| 425 |
+
public PBEWithSHA256And256BitAESBC()
|
| 426 |
+
{
|
| 427 |
+
super("PBEWithSHA256And256BitAES-CBC-BC", null, true, PKCS12, SHA256, 256, 128);
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
+
/**
|
| 432 |
+
* PBEWithMD5And128BitAES-OpenSSL
|
| 433 |
+
*/
|
| 434 |
+
static public class PBEWithMD5And128BitAESCBCOpenSSL
|
| 435 |
+
extends PBESecretKeyFactory
|
| 436 |
+
{
|
| 437 |
+
public PBEWithMD5And128BitAESCBCOpenSSL()
|
| 438 |
+
{
|
| 439 |
+
super("PBEWithMD5And128BitAES-CBC-OpenSSL", null, true, OPENSSL, MD5, 128, 128);
|
| 440 |
+
}
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
/**
|
| 444 |
+
* PBEWithMD5And192BitAES-OpenSSL
|
| 445 |
+
*/
|
| 446 |
+
static public class PBEWithMD5And192BitAESCBCOpenSSL
|
| 447 |
+
extends PBESecretKeyFactory
|
| 448 |
+
{
|
| 449 |
+
public PBEWithMD5And192BitAESCBCOpenSSL()
|
| 450 |
+
{
|
| 451 |
+
super("PBEWithMD5And192BitAES-CBC-OpenSSL", null, true, OPENSSL, MD5, 192, 128);
|
| 452 |
+
}
|
| 453 |
+
}
|
| 454 |
+
|
| 455 |
+
/**
|
| 456 |
+
* PBEWithMD5And256BitAES-OpenSSL
|
| 457 |
+
*/
|
| 458 |
+
static public class PBEWithMD5And256BitAESCBCOpenSSL
|
| 459 |
+
extends PBESecretKeyFactory
|
| 460 |
+
{
|
| 461 |
+
public PBEWithMD5And256BitAESCBCOpenSSL()
|
| 462 |
+
{
|
| 463 |
+
super("PBEWithMD5And256BitAES-CBC-OpenSSL", null, true, OPENSSL, MD5, 256, 128);
|
| 464 |
+
}
|
| 465 |
+
}
|
| 466 |
+
|
| 467 |
+
public static class AlgParamGen
|
| 468 |
+
extends BaseAlgorithmParameterGenerator
|
| 469 |
+
{
|
| 470 |
+
protected void engineInit(
|
| 471 |
+
AlgorithmParameterSpec genParamSpec,
|
| 472 |
+
SecureRandom random)
|
| 473 |
+
throws InvalidAlgorithmParameterException
|
| 474 |
+
{
|
| 475 |
+
throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for AES parameter generation.");
|
| 476 |
+
}
|
| 477 |
+
|
| 478 |
+
protected AlgorithmParameters engineGenerateParameters()
|
| 479 |
+
{
|
| 480 |
+
byte[] iv = new byte[16];
|
| 481 |
+
|
| 482 |
+
if (random == null)
|
| 483 |
+
{
|
| 484 |
+
random = new SecureRandom();
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
random.nextBytes(iv);
|
| 488 |
+
|
| 489 |
+
AlgorithmParameters params;
|
| 490 |
+
|
| 491 |
+
try
|
| 492 |
+
{
|
| 493 |
+
params = createParametersInstance("AES");
|
| 494 |
+
params.init(new IvParameterSpec(iv));
|
| 495 |
+
}
|
| 496 |
+
catch (Exception e)
|
| 497 |
+
{
|
| 498 |
+
throw new RuntimeException(e.getMessage());
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
return params;
|
| 502 |
+
}
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
public static class AlgParamGenCCM
|
| 506 |
+
extends BaseAlgorithmParameterGenerator
|
| 507 |
+
{
|
| 508 |
+
protected void engineInit(
|
| 509 |
+
AlgorithmParameterSpec genParamSpec,
|
| 510 |
+
SecureRandom random)
|
| 511 |
+
throws InvalidAlgorithmParameterException
|
| 512 |
+
{
|
| 513 |
+
// TODO: add support for GCMParameterSpec as a template.
|
| 514 |
+
throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for AES parameter generation.");
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
protected AlgorithmParameters engineGenerateParameters()
|
| 518 |
+
{
|
| 519 |
+
byte[] iv = new byte[12];
|
| 520 |
+
|
| 521 |
+
if (random == null)
|
| 522 |
+
{
|
| 523 |
+
random = new SecureRandom();
|
| 524 |
+
}
|
| 525 |
+
|
| 526 |
+
random.nextBytes(iv);
|
| 527 |
+
|
| 528 |
+
AlgorithmParameters params;
|
| 529 |
+
|
| 530 |
+
try
|
| 531 |
+
{
|
| 532 |
+
params = createParametersInstance("CCM");
|
| 533 |
+
params.init(new CCMParameters(iv, 12).getEncoded());
|
| 534 |
+
}
|
| 535 |
+
catch (Exception e)
|
| 536 |
+
{
|
| 537 |
+
throw new RuntimeException(e.getMessage());
|
| 538 |
+
}
|
| 539 |
+
|
| 540 |
+
return params;
|
| 541 |
+
}
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
public static class AlgParamGenGCM
|
| 545 |
+
extends BaseAlgorithmParameterGenerator
|
| 546 |
+
{
|
| 547 |
+
protected void engineInit(
|
| 548 |
+
AlgorithmParameterSpec genParamSpec,
|
| 549 |
+
SecureRandom random)
|
| 550 |
+
throws InvalidAlgorithmParameterException
|
| 551 |
+
{
|
| 552 |
+
// TODO: add support for GCMParameterSpec as a template.
|
| 553 |
+
throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for AES parameter generation.");
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
protected AlgorithmParameters engineGenerateParameters()
|
| 557 |
+
{
|
| 558 |
+
byte[] nonce = new byte[12];
|
| 559 |
+
|
| 560 |
+
if (random == null)
|
| 561 |
+
{
|
| 562 |
+
random = new SecureRandom();
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
random.nextBytes(nonce);
|
| 566 |
+
|
| 567 |
+
AlgorithmParameters params;
|
| 568 |
+
|
| 569 |
+
try
|
| 570 |
+
{
|
| 571 |
+
params = createParametersInstance("GCM");
|
| 572 |
+
params.init(new GCMParameters(nonce, 16).getEncoded());
|
| 573 |
+
}
|
| 574 |
+
catch (Exception e)
|
| 575 |
+
{
|
| 576 |
+
throw new RuntimeException(e.getMessage());
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
return params;
|
| 580 |
+
}
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
public static class AlgParams
|
| 584 |
+
extends IvAlgorithmParameters
|
| 585 |
+
{
|
| 586 |
+
protected String engineToString()
|
| 587 |
+
{
|
| 588 |
+
return "AES IV";
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
public static class AlgParamsGCM
|
| 593 |
+
extends BaseAlgorithmParameters
|
| 594 |
+
{
|
| 595 |
+
private GCMParameters gcmParams;
|
| 596 |
+
|
| 597 |
+
protected void engineInit(AlgorithmParameterSpec paramSpec)
|
| 598 |
+
throws InvalidParameterSpecException
|
| 599 |
+
{
|
| 600 |
+
if (GcmSpecUtil.isGcmSpec(paramSpec))
|
| 601 |
+
{
|
| 602 |
+
gcmParams = GcmSpecUtil.extractGcmParameters(paramSpec);
|
| 603 |
+
}
|
| 604 |
+
else if (paramSpec instanceof AEADParameterSpec)
|
| 605 |
+
{
|
| 606 |
+
gcmParams = new GCMParameters(((AEADParameterSpec)paramSpec).getNonce(), ((AEADParameterSpec)paramSpec).getMacSizeInBits() / 8);
|
| 607 |
+
}
|
| 608 |
+
else
|
| 609 |
+
{
|
| 610 |
+
throw new InvalidParameterSpecException("AlgorithmParameterSpec class not recognized: " + paramSpec.getClass().getName());
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
protected void engineInit(byte[] params)
|
| 615 |
+
throws IOException
|
| 616 |
+
{
|
| 617 |
+
gcmParams = GCMParameters.getInstance(params);
|
| 618 |
+
}
|
| 619 |
+
|
| 620 |
+
protected void engineInit(byte[] params, String format)
|
| 621 |
+
throws IOException
|
| 622 |
+
{
|
| 623 |
+
if (!isASN1FormatString(format))
|
| 624 |
+
{
|
| 625 |
+
throw new IOException("unknown format specified");
|
| 626 |
+
}
|
| 627 |
+
|
| 628 |
+
gcmParams = GCMParameters.getInstance(params);
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
protected byte[] engineGetEncoded()
|
| 632 |
+
throws IOException
|
| 633 |
+
{
|
| 634 |
+
return gcmParams.getEncoded();
|
| 635 |
+
}
|
| 636 |
+
|
| 637 |
+
protected byte[] engineGetEncoded(String format)
|
| 638 |
+
throws IOException
|
| 639 |
+
{
|
| 640 |
+
if (!isASN1FormatString(format))
|
| 641 |
+
{
|
| 642 |
+
throw new IOException("unknown format specified");
|
| 643 |
+
}
|
| 644 |
+
|
| 645 |
+
return gcmParams.getEncoded();
|
| 646 |
+
}
|
| 647 |
+
|
| 648 |
+
protected String engineToString()
|
| 649 |
+
{
|
| 650 |
+
return "GCM";
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
protected AlgorithmParameterSpec localEngineGetParameterSpec(Class paramSpec)
|
| 654 |
+
throws InvalidParameterSpecException
|
| 655 |
+
{
|
| 656 |
+
if (paramSpec == AlgorithmParameterSpec.class || GcmSpecUtil.isGcmSpec(paramSpec))
|
| 657 |
+
{
|
| 658 |
+
if (GcmSpecUtil.gcmSpecExists())
|
| 659 |
+
{
|
| 660 |
+
return GcmSpecUtil.extractGcmSpec(gcmParams.toASN1Primitive());
|
| 661 |
+
}
|
| 662 |
+
return new AEADParameterSpec(gcmParams.getNonce(), gcmParams.getIcvLen() * 8);
|
| 663 |
+
}
|
| 664 |
+
if (paramSpec == AEADParameterSpec.class)
|
| 665 |
+
{
|
| 666 |
+
return new AEADParameterSpec(gcmParams.getNonce(), gcmParams.getIcvLen() * 8);
|
| 667 |
+
}
|
| 668 |
+
if (paramSpec == IvParameterSpec.class)
|
| 669 |
+
{
|
| 670 |
+
return new IvParameterSpec(gcmParams.getNonce());
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
throw new InvalidParameterSpecException("AlgorithmParameterSpec not recognized: " + paramSpec.getName());
|
| 674 |
+
}
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
public static class AlgParamsCCM
|
| 678 |
+
extends BaseAlgorithmParameters
|
| 679 |
+
{
|
| 680 |
+
private CCMParameters ccmParams;
|
| 681 |
+
|
| 682 |
+
protected void engineInit(AlgorithmParameterSpec paramSpec)
|
| 683 |
+
throws InvalidParameterSpecException
|
| 684 |
+
{
|
| 685 |
+
if (GcmSpecUtil.isGcmSpec(paramSpec))
|
| 686 |
+
{
|
| 687 |
+
ccmParams = CCMParameters.getInstance(GcmSpecUtil.extractGcmParameters(paramSpec));
|
| 688 |
+
}
|
| 689 |
+
else if (paramSpec instanceof AEADParameterSpec)
|
| 690 |
+
{
|
| 691 |
+
ccmParams = new CCMParameters(((AEADParameterSpec)paramSpec).getNonce(), ((AEADParameterSpec)paramSpec).getMacSizeInBits() / 8);
|
| 692 |
+
}
|
| 693 |
+
else
|
| 694 |
+
{
|
| 695 |
+
throw new InvalidParameterSpecException("AlgorithmParameterSpec class not recognized: " + paramSpec.getClass().getName());
|
| 696 |
+
}
|
| 697 |
+
}
|
| 698 |
+
|
| 699 |
+
protected void engineInit(byte[] params)
|
| 700 |
+
throws IOException
|
| 701 |
+
{
|
| 702 |
+
ccmParams = CCMParameters.getInstance(params);
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
protected void engineInit(byte[] params, String format)
|
| 706 |
+
throws IOException
|
| 707 |
+
{
|
| 708 |
+
if (!isASN1FormatString(format))
|
| 709 |
+
{
|
| 710 |
+
throw new IOException("unknown format specified");
|
| 711 |
+
}
|
| 712 |
+
|
| 713 |
+
ccmParams = CCMParameters.getInstance(params);
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
protected byte[] engineGetEncoded()
|
| 717 |
+
throws IOException
|
| 718 |
+
{
|
| 719 |
+
return ccmParams.getEncoded();
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
protected byte[] engineGetEncoded(String format)
|
| 723 |
+
throws IOException
|
| 724 |
+
{
|
| 725 |
+
if (!isASN1FormatString(format))
|
| 726 |
+
{
|
| 727 |
+
throw new IOException("unknown format specified");
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
return ccmParams.getEncoded();
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
protected String engineToString()
|
| 734 |
+
{
|
| 735 |
+
return "CCM";
|
| 736 |
+
}
|
| 737 |
+
|
| 738 |
+
protected AlgorithmParameterSpec localEngineGetParameterSpec(Class paramSpec)
|
| 739 |
+
throws InvalidParameterSpecException
|
| 740 |
+
{
|
| 741 |
+
if (paramSpec == AlgorithmParameterSpec.class || GcmSpecUtil.isGcmSpec(paramSpec))
|
| 742 |
+
{
|
| 743 |
+
if (GcmSpecUtil.gcmSpecExists())
|
| 744 |
+
{
|
| 745 |
+
return GcmSpecUtil.extractGcmSpec(ccmParams.toASN1Primitive());
|
| 746 |
+
}
|
| 747 |
+
return new AEADParameterSpec(ccmParams.getNonce(), ccmParams.getIcvLen() * 8);
|
| 748 |
+
}
|
| 749 |
+
if (paramSpec == AEADParameterSpec.class)
|
| 750 |
+
{
|
| 751 |
+
return new AEADParameterSpec(ccmParams.getNonce(), ccmParams.getIcvLen() * 8);
|
| 752 |
+
}
|
| 753 |
+
if (paramSpec == IvParameterSpec.class)
|
| 754 |
+
{
|
| 755 |
+
return new IvParameterSpec(ccmParams.getNonce());
|
| 756 |
+
}
|
| 757 |
+
|
| 758 |
+
throw new InvalidParameterSpecException("AlgorithmParameterSpec not recognized: " + paramSpec.getName());
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
public static class Mappings
|
| 763 |
+
extends SymmetricAlgorithmProvider
|
| 764 |
+
{
|
| 765 |
+
private static final String PREFIX = AES.class.getName();
|
| 766 |
+
|
| 767 |
+
/**
|
| 768 |
+
* These three got introduced in some messages as a result of a typo in an
|
| 769 |
+
* early document. We don't produce anything using these OID values, but we'll
|
| 770 |
+
* read them.
|
| 771 |
+
*/
|
| 772 |
+
private static final String wrongAES128 = "2.16.840.1.101.3.4.2";
|
| 773 |
+
private static final String wrongAES192 = "2.16.840.1.101.3.4.22";
|
| 774 |
+
private static final String wrongAES256 = "2.16.840.1.101.3.4.42";
|
| 775 |
+
|
| 776 |
+
public Mappings()
|
| 777 |
+
{
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
public void configure(ConfigurableProvider provider)
|
| 781 |
+
{
|
| 782 |
+
provider.addAlgorithm("AlgorithmParameters.AES", PREFIX + "$AlgParams");
|
| 783 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + wrongAES128, "AES");
|
| 784 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + wrongAES192, "AES");
|
| 785 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + wrongAES256, "AES");
|
| 786 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes128_CBC, "AES");
|
| 787 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes192_CBC, "AES");
|
| 788 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes256_CBC, "AES");
|
| 789 |
+
|
| 790 |
+
provider.addAlgorithm("AlgorithmParameters.GCM", PREFIX + "$AlgParamsGCM");
|
| 791 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes128_GCM, "GCM");
|
| 792 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes192_GCM, "GCM");
|
| 793 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes256_GCM, "GCM");
|
| 794 |
+
|
| 795 |
+
provider.addAlgorithm("AlgorithmParameters.CCM", PREFIX + "$AlgParamsCCM");
|
| 796 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes128_CCM, "CCM");
|
| 797 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes192_CCM, "CCM");
|
| 798 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + NISTObjectIdentifiers.id_aes256_CCM, "CCM");
|
| 799 |
+
|
| 800 |
+
provider.addAlgorithm("AlgorithmParameterGenerator.AES", PREFIX + "$AlgParamGen");
|
| 801 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES128, "AES");
|
| 802 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES192, "AES");
|
| 803 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + wrongAES256, "AES");
|
| 804 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes128_CBC, "AES");
|
| 805 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes192_CBC, "AES");
|
| 806 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes256_CBC, "AES");
|
| 807 |
+
|
| 808 |
+
provider.addAlgorithm("Cipher.AES", PREFIX + "$ECB");
|
| 809 |
+
provider.addAlgorithm("Alg.Alias.Cipher." + wrongAES128, "AES");
|
| 810 |
+
provider.addAlgorithm("Alg.Alias.Cipher." + wrongAES192, "AES");
|
| 811 |
+
provider.addAlgorithm("Alg.Alias.Cipher." + wrongAES256, "AES");
|
| 812 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes128_ECB, PREFIX + "$ECB");
|
| 813 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes192_ECB, PREFIX + "$ECB");
|
| 814 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes256_ECB, PREFIX + "$ECB");
|
| 815 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes128_CBC, PREFIX + "$CBC");
|
| 816 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes192_CBC, PREFIX + "$CBC");
|
| 817 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes256_CBC, PREFIX + "$CBC");
|
| 818 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes128_OFB, PREFIX + "$OFB");
|
| 819 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes192_OFB, PREFIX + "$OFB");
|
| 820 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes256_OFB, PREFIX + "$OFB");
|
| 821 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes128_CFB, PREFIX + "$CFB");
|
| 822 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes192_CFB, PREFIX + "$CFB");
|
| 823 |
+
provider.addAlgorithm("Cipher", NISTObjectIdentifiers.id_aes256_CFB, PREFIX + "$CFB");
|
| 824 |
+
provider.addAlgorithm("Cipher.AESWRAP", PREFIX + "$Wrap");
|
| 825 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes128_wrap, "AESWRAP");
|
| 826 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes192_wrap, "AESWRAP");
|
| 827 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes256_wrap, "AESWRAP");
|
| 828 |
+
provider.addAlgorithm("Alg.Alias.Cipher.AESKW", "AESWRAP");
|
| 829 |
+
|
| 830 |
+
provider.addAlgorithm("Cipher.AESRFC3211WRAP", PREFIX + "$RFC3211Wrap");
|
| 831 |
+
provider.addAlgorithm("Cipher.AESRFC5649WRAP", PREFIX + "$RFC5649Wrap");
|
| 832 |
+
|
| 833 |
+
provider.addAlgorithm("AlgorithmParameterGenerator.CCM", PREFIX + "$AlgParamGenCCM");
|
| 834 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes128_CCM, "CCM");
|
| 835 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes192_CCM, "CCM");
|
| 836 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes256_CCM, "CCM");
|
| 837 |
+
|
| 838 |
+
provider.addAlgorithm("Cipher.CCM", PREFIX + "$CCM");
|
| 839 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes128_CCM, "CCM");
|
| 840 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes192_CCM, "CCM");
|
| 841 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes256_CCM, "CCM");
|
| 842 |
+
|
| 843 |
+
provider.addAlgorithm("AlgorithmParameterGenerator.GCM", PREFIX + "$AlgParamGenGCM");
|
| 844 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes128_GCM, "GCM");
|
| 845 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes192_GCM, "GCM");
|
| 846 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameterGenerator." + NISTObjectIdentifiers.id_aes256_GCM, "GCM");
|
| 847 |
+
|
| 848 |
+
provider.addAlgorithm("Cipher.GCM", PREFIX + "$GCM");
|
| 849 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes128_GCM, "GCM");
|
| 850 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes192_GCM, "GCM");
|
| 851 |
+
provider.addAlgorithm("Alg.Alias.Cipher", NISTObjectIdentifiers.id_aes256_GCM, "GCM");
|
| 852 |
+
|
| 853 |
+
provider.addAlgorithm("KeyGenerator.AES", PREFIX + "$KeyGen");
|
| 854 |
+
provider.addAlgorithm("KeyGenerator." + wrongAES128, PREFIX + "$KeyGen128");
|
| 855 |
+
provider.addAlgorithm("KeyGenerator." + wrongAES192, PREFIX + "$KeyGen192");
|
| 856 |
+
provider.addAlgorithm("KeyGenerator." + wrongAES256, PREFIX + "$KeyGen256");
|
| 857 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_ECB, PREFIX + "$KeyGen128");
|
| 858 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_CBC, PREFIX + "$KeyGen128");
|
| 859 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_OFB, PREFIX + "$KeyGen128");
|
| 860 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_CFB, PREFIX + "$KeyGen128");
|
| 861 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_ECB, PREFIX + "$KeyGen192");
|
| 862 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_CBC, PREFIX + "$KeyGen192");
|
| 863 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_OFB, PREFIX + "$KeyGen192");
|
| 864 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_CFB, PREFIX + "$KeyGen192");
|
| 865 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_ECB, PREFIX + "$KeyGen256");
|
| 866 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_CBC, PREFIX + "$KeyGen256");
|
| 867 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_OFB, PREFIX + "$KeyGen256");
|
| 868 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_CFB, PREFIX + "$KeyGen256");
|
| 869 |
+
provider.addAlgorithm("KeyGenerator.AESWRAP", PREFIX + "$KeyGen");
|
| 870 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_wrap, PREFIX + "$KeyGen128");
|
| 871 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_wrap, PREFIX + "$KeyGen192");
|
| 872 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_wrap, PREFIX + "$KeyGen256");
|
| 873 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_GCM, PREFIX + "$KeyGen128");
|
| 874 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_GCM, PREFIX + "$KeyGen192");
|
| 875 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_GCM, PREFIX + "$KeyGen256");
|
| 876 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes128_CCM, PREFIX + "$KeyGen128");
|
| 877 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes192_CCM, PREFIX + "$KeyGen192");
|
| 878 |
+
provider.addAlgorithm("KeyGenerator", NISTObjectIdentifiers.id_aes256_CCM, PREFIX + "$KeyGen256");
|
| 879 |
+
|
| 880 |
+
provider.addAlgorithm("Mac.AESCMAC", PREFIX + "$AESCMAC");
|
| 881 |
+
|
| 882 |
+
provider.addAlgorithm("Mac.AESCCMMAC", PREFIX + "$AESCCMMAC");
|
| 883 |
+
provider.addAlgorithm("Alg.Alias.Mac." + NISTObjectIdentifiers.id_aes128_CCM.getId(), "AESCCMMAC");
|
| 884 |
+
provider.addAlgorithm("Alg.Alias.Mac." + NISTObjectIdentifiers.id_aes192_CCM.getId(), "AESCCMMAC");
|
| 885 |
+
provider.addAlgorithm("Alg.Alias.Mac." + NISTObjectIdentifiers.id_aes256_CCM.getId(), "AESCCMMAC");
|
| 886 |
+
|
| 887 |
+
provider.addAlgorithm("Alg.Alias.Cipher", BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc, "PBEWITHSHAAND128BITAES-CBC-BC");
|
| 888 |
+
provider.addAlgorithm("Alg.Alias.Cipher", BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc, "PBEWITHSHAAND192BITAES-CBC-BC");
|
| 889 |
+
provider.addAlgorithm("Alg.Alias.Cipher", BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc, "PBEWITHSHAAND256BITAES-CBC-BC");
|
| 890 |
+
provider.addAlgorithm("Alg.Alias.Cipher", BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc, "PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 891 |
+
provider.addAlgorithm("Alg.Alias.Cipher", BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc, "PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 892 |
+
provider.addAlgorithm("Alg.Alias.Cipher", BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc, "PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 893 |
+
|
| 894 |
+
provider.addAlgorithm("Cipher.PBEWITHSHAAND128BITAES-CBC-BC", PREFIX + "$PBEWithSHA1AESCBC128");
|
| 895 |
+
provider.addAlgorithm("Cipher.PBEWITHSHAAND192BITAES-CBC-BC", PREFIX + "$PBEWithSHA1AESCBC192");
|
| 896 |
+
provider.addAlgorithm("Cipher.PBEWITHSHAAND256BITAES-CBC-BC", PREFIX + "$PBEWithSHA1AESCBC256");
|
| 897 |
+
provider.addAlgorithm("Cipher.PBEWITHSHA256AND128BITAES-CBC-BC", PREFIX + "$PBEWithSHA256AESCBC128");
|
| 898 |
+
provider.addAlgorithm("Cipher.PBEWITHSHA256AND192BITAES-CBC-BC", PREFIX + "$PBEWithSHA256AESCBC192");
|
| 899 |
+
provider.addAlgorithm("Cipher.PBEWITHSHA256AND256BITAES-CBC-BC", PREFIX + "$PBEWithSHA256AESCBC256");
|
| 900 |
+
|
| 901 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND128BITAES-CBC-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 902 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND192BITAES-CBC-BC","PBEWITHSHAAND192BITAES-CBC-BC");
|
| 903 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND256BITAES-CBC-BC","PBEWITHSHAAND256BITAES-CBC-BC");
|
| 904 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-1AND128BITAES-CBC-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 905 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-1AND192BITAES-CBC-BC","PBEWITHSHAAND192BITAES-CBC-BC");
|
| 906 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-1AND256BITAES-CBC-BC","PBEWITHSHAAND256BITAES-CBC-BC");
|
| 907 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHAAND128BITAES-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 908 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHAAND192BITAES-BC", "PBEWITHSHAAND192BITAES-CBC-BC");
|
| 909 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHAAND256BITAES-BC", "PBEWITHSHAAND256BITAES-CBC-BC");
|
| 910 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND128BITAES-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 911 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND192BITAES-BC","PBEWITHSHAAND192BITAES-CBC-BC");
|
| 912 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA1AND256BITAES-BC","PBEWITHSHAAND256BITAES-CBC-BC");
|
| 913 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-1AND128BITAES-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 914 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-1AND192BITAES-BC","PBEWITHSHAAND192BITAES-CBC-BC");
|
| 915 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-1AND256BITAES-BC","PBEWITHSHAAND256BITAES-CBC-BC");
|
| 916 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-256AND128BITAES-CBC-BC","PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 917 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-256AND192BITAES-CBC-BC","PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 918 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-256AND256BITAES-CBC-BC","PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 919 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA256AND128BITAES-BC","PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 920 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA256AND192BITAES-BC","PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 921 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA256AND256BITAES-BC","PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 922 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-256AND128BITAES-BC","PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 923 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-256AND192BITAES-BC","PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 924 |
+
provider.addAlgorithm("Alg.Alias.Cipher.PBEWITHSHA-256AND256BITAES-BC","PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 925 |
+
|
| 926 |
+
provider.addAlgorithm("Cipher.PBEWITHMD5AND128BITAES-CBC-OPENSSL", PREFIX + "$PBEWithAESCBC");
|
| 927 |
+
provider.addAlgorithm("Cipher.PBEWITHMD5AND192BITAES-CBC-OPENSSL", PREFIX + "$PBEWithAESCBC");
|
| 928 |
+
provider.addAlgorithm("Cipher.PBEWITHMD5AND256BITAES-CBC-OPENSSL", PREFIX + "$PBEWithAESCBC");
|
| 929 |
+
|
| 930 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHMD5AND128BITAES-CBC-OPENSSL", PREFIX + "$PBEWithMD5And128BitAESCBCOpenSSL");
|
| 931 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHMD5AND192BITAES-CBC-OPENSSL", PREFIX + "$PBEWithMD5And192BitAESCBCOpenSSL");
|
| 932 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHMD5AND256BITAES-CBC-OPENSSL", PREFIX + "$PBEWithMD5And256BitAESCBCOpenSSL");
|
| 933 |
+
|
| 934 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND128BITAES-CBC-BC", PREFIX + "$PBEWithSHAAnd128BitAESBC");
|
| 935 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND192BITAES-CBC-BC", PREFIX + "$PBEWithSHAAnd192BitAESBC");
|
| 936 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHSHAAND256BITAES-CBC-BC", PREFIX + "$PBEWithSHAAnd256BitAESBC");
|
| 937 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHSHA256AND128BITAES-CBC-BC", PREFIX + "$PBEWithSHA256And128BitAESBC");
|
| 938 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHSHA256AND192BITAES-CBC-BC", PREFIX + "$PBEWithSHA256And192BitAESBC");
|
| 939 |
+
provider.addAlgorithm("SecretKeyFactory.PBEWITHSHA256AND256BITAES-CBC-BC", PREFIX + "$PBEWithSHA256And256BitAESBC");
|
| 940 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA1AND128BITAES-CBC-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 941 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA1AND192BITAES-CBC-BC","PBEWITHSHAAND192BITAES-CBC-BC");
|
| 942 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA1AND256BITAES-CBC-BC","PBEWITHSHAAND256BITAES-CBC-BC");
|
| 943 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-1AND128BITAES-CBC-BC","PBEWITHSHAAND128BITAES-CBC-BC");
|
| 944 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-1AND192BITAES-CBC-BC","PBEWITHSHAAND192BITAES-CBC-BC");
|
| 945 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-1AND256BITAES-CBC-BC","PBEWITHSHAAND256BITAES-CBC-BC");
|
| 946 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND128BITAES-CBC-BC","PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 947 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND192BITAES-CBC-BC","PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 948 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND256BITAES-CBC-BC","PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 949 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND128BITAES-BC","PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 950 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND192BITAES-BC","PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 951 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory.PBEWITHSHA-256AND256BITAES-BC","PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 952 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory", BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc, "PBEWITHSHAAND128BITAES-CBC-BC");
|
| 953 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory", BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc, "PBEWITHSHAAND192BITAES-CBC-BC");
|
| 954 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory", BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc, "PBEWITHSHAAND256BITAES-CBC-BC");
|
| 955 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory", BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc, "PBEWITHSHA256AND128BITAES-CBC-BC");
|
| 956 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory", BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc, "PBEWITHSHA256AND192BITAES-CBC-BC");
|
| 957 |
+
provider.addAlgorithm("Alg.Alias.SecretKeyFactory", BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc, "PBEWITHSHA256AND256BITAES-CBC-BC");
|
| 958 |
+
|
| 959 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND128BITAES-CBC-BC", "PKCS12PBE");
|
| 960 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND192BITAES-CBC-BC", "PKCS12PBE");
|
| 961 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHAAND256BITAES-CBC-BC", "PKCS12PBE");
|
| 962 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA256AND128BITAES-CBC-BC", "PKCS12PBE");
|
| 963 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA256AND192BITAES-CBC-BC", "PKCS12PBE");
|
| 964 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA256AND256BITAES-CBC-BC", "PKCS12PBE");
|
| 965 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA1AND128BITAES-CBC-BC","PKCS12PBE");
|
| 966 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA1AND192BITAES-CBC-BC","PKCS12PBE");
|
| 967 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA1AND256BITAES-CBC-BC","PKCS12PBE");
|
| 968 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA-1AND128BITAES-CBC-BC","PKCS12PBE");
|
| 969 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA-1AND192BITAES-CBC-BC","PKCS12PBE");
|
| 970 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA-1AND256BITAES-CBC-BC","PKCS12PBE");
|
| 971 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND128BITAES-CBC-BC","PKCS12PBE");
|
| 972 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND192BITAES-CBC-BC","PKCS12PBE");
|
| 973 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters.PBEWITHSHA-256AND256BITAES-CBC-BC","PKCS12PBE");
|
| 974 |
+
|
| 975 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes128_cbc.getId(), "PKCS12PBE");
|
| 976 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes192_cbc.getId(), "PKCS12PBE");
|
| 977 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha1_pkcs12_aes256_cbc.getId(), "PKCS12PBE");
|
| 978 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes128_cbc.getId(), "PKCS12PBE");
|
| 979 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes192_cbc.getId(), "PKCS12PBE");
|
| 980 |
+
provider.addAlgorithm("Alg.Alias.AlgorithmParameters." + BCObjectIdentifiers.bc_pbe_sha256_pkcs12_aes256_cbc.getId(), "PKCS12PBE");
|
| 981 |
+
|
| 982 |
+
addGMacAlgorithm(provider, "AES", PREFIX + "$AESGMAC", PREFIX + "$KeyGen128");
|
| 983 |
+
addPoly1305Algorithm(provider, "AES", PREFIX + "$Poly1305", PREFIX + "$Poly1305KeyGen");
|
| 984 |
+
}
|
| 985 |
+
}
|
| 986 |
+
|
| 987 |
+
private static Class lookup(String className)
|
| 988 |
+
{
|
| 989 |
+
try
|
| 990 |
+
{
|
| 991 |
+
Class def = AES.class.getClassLoader().loadClass(className);
|
| 992 |
+
|
| 993 |
+
return def;
|
| 994 |
+
}
|
| 995 |
+
catch (Exception e)
|
| 996 |
+
{
|
| 997 |
+
return null;
|
| 998 |
+
}
|
| 999 |
+
}
|
| 1000 |
+
}
|
Java/AbstractConstantRestrictor.java
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.jolokia.restrictor;
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
* Copyright 2009-2011 Roland Huss
|
| 5 |
+
*
|
| 6 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
* you may not use this file except in compliance with the License.
|
| 8 |
+
* You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
* See the License for the specific language governing permissions and
|
| 16 |
+
* limitations under the License.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
import javax.management.ObjectName;
|
| 20 |
+
|
| 21 |
+
import org.jolokia.util.HttpMethod;
|
| 22 |
+
import org.jolokia.util.RequestType;
|
| 23 |
+
|
| 24 |
+
/**
|
| 25 |
+
* Base restrictor which alway returns the constant given
|
| 26 |
+
* at construction time
|
| 27 |
+
*
|
| 28 |
+
* @author roland
|
| 29 |
+
* @since 06.10.11
|
| 30 |
+
*/
|
| 31 |
+
public abstract class AbstractConstantRestrictor implements Restrictor {
|
| 32 |
+
|
| 33 |
+
private boolean isAllowed;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* Create restrictor which always returns the given value on every check
|
| 37 |
+
* method.
|
| 38 |
+
*
|
| 39 |
+
* @param pAllowed whether access is allowed or denied
|
| 40 |
+
*/
|
| 41 |
+
protected AbstractConstantRestrictor(boolean pAllowed) {
|
| 42 |
+
isAllowed = pAllowed;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/** {@inheritDoc} */
|
| 46 |
+
public final boolean isHttpMethodAllowed(HttpMethod pMethod) {
|
| 47 |
+
return isAllowed;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
/** {@inheritDoc} */
|
| 51 |
+
public final boolean isTypeAllowed(RequestType pType) {
|
| 52 |
+
return isAllowed;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
/** {@inheritDoc} */
|
| 56 |
+
public final boolean isAttributeReadAllowed(ObjectName pName, String pAttribute) {
|
| 57 |
+
return isAllowed;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
/** {@inheritDoc} */
|
| 61 |
+
public final boolean isAttributeWriteAllowed(ObjectName pName, String pAttribute) {
|
| 62 |
+
return isAllowed;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
/** {@inheritDoc} */
|
| 66 |
+
public final boolean isOperationAllowed(ObjectName pName, String pOperation) {
|
| 67 |
+
return isAllowed;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
/** {@inheritDoc} */
|
| 71 |
+
public final boolean isRemoteAccessAllowed(String... pHostOrAddress) {
|
| 72 |
+
return isAllowed;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
/** {@inheritDoc} */
|
| 76 |
+
// BUG: CWE-352 Cross-Site Request Forgery (CSRF)
|
| 77 |
+
// public boolean isCorsAccessAllowed(String pOrigin) {
|
| 78 |
+
// FIXED:
|
| 79 |
+
public boolean isOriginAllowed(String pOrigin, boolean pIsStrictCheck) {
|
| 80 |
+
return isAllowed;
|
| 81 |
+
}
|
| 82 |
+
}
|
Java/AbstractDiskHttpDataTest.java
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2020 The Netty Project
|
| 3 |
+
*
|
| 4 |
+
* The Netty Project licenses this file to you under the Apache License,
|
| 5 |
+
* version 2.0 (the "License"); you may not use this file except in compliance
|
| 6 |
+
* with the License. You may obtain a copy of the License at:
|
| 7 |
+
*
|
| 8 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 12 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 13 |
+
* License for the specific language governing permissions and limitations
|
| 14 |
+
* under the License.
|
| 15 |
+
*/
|
| 16 |
+
package io.netty.handler.codec.http.multipart;
|
| 17 |
+
|
| 18 |
+
import io.netty.buffer.ByteBuf;
|
| 19 |
+
import io.netty.buffer.ByteBufUtil;
|
| 20 |
+
import io.netty.util.internal.PlatformDependent;
|
| 21 |
+
import org.junit.Test;
|
| 22 |
+
|
| 23 |
+
import java.io.File;
|
| 24 |
+
import java.io.FileOutputStream;
|
| 25 |
+
import java.nio.charset.Charset;
|
| 26 |
+
import java.util.Arrays;
|
| 27 |
+
import java.util.UUID;
|
| 28 |
+
|
| 29 |
+
import static io.netty.util.CharsetUtil.UTF_8;
|
| 30 |
+
import static org.junit.Assert.assertEquals;
|
| 31 |
+
import static org.junit.Assert.assertFalse;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* {@link AbstractDiskHttpData} test cases
|
| 35 |
+
*/
|
| 36 |
+
public class AbstractDiskHttpDataTest {
|
| 37 |
+
|
| 38 |
+
@Test
|
| 39 |
+
public void testGetChunk() throws Exception {
|
| 40 |
+
TestHttpData test = new TestHttpData("test", UTF_8, 0);
|
| 41 |
+
try {
|
| 42 |
+
// BUG: CWE-378 Creation of Temporary File With Insecure Permissions
|
| 43 |
+
// File tmpFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp");
|
| 44 |
+
// FIXED:
|
| 45 |
+
File tmpFile = PlatformDependent.createTempFile(UUID.randomUUID().toString(), ".tmp", null);
|
| 46 |
+
tmpFile.deleteOnExit();
|
| 47 |
+
FileOutputStream fos = new FileOutputStream(tmpFile);
|
| 48 |
+
byte[] bytes = new byte[4096];
|
| 49 |
+
PlatformDependent.threadLocalRandom().nextBytes(bytes);
|
| 50 |
+
try {
|
| 51 |
+
fos.write(bytes);
|
| 52 |
+
fos.flush();
|
| 53 |
+
} finally {
|
| 54 |
+
fos.close();
|
| 55 |
+
}
|
| 56 |
+
test.setContent(tmpFile);
|
| 57 |
+
ByteBuf buf1 = test.getChunk(1024);
|
| 58 |
+
assertEquals(buf1.readerIndex(), 0);
|
| 59 |
+
assertEquals(buf1.writerIndex(), 1024);
|
| 60 |
+
ByteBuf buf2 = test.getChunk(1024);
|
| 61 |
+
assertEquals(buf2.readerIndex(), 0);
|
| 62 |
+
assertEquals(buf2.writerIndex(), 1024);
|
| 63 |
+
assertFalse("Arrays should not be equal",
|
| 64 |
+
Arrays.equals(ByteBufUtil.getBytes(buf1), ByteBufUtil.getBytes(buf2)));
|
| 65 |
+
} finally {
|
| 66 |
+
test.delete();
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
private static final class TestHttpData extends AbstractDiskHttpData {
|
| 71 |
+
|
| 72 |
+
private TestHttpData(String name, Charset charset, long size) {
|
| 73 |
+
super(name, charset, size);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
@Override
|
| 77 |
+
protected String getDiskFilename() {
|
| 78 |
+
return null;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
@Override
|
| 82 |
+
protected String getPrefix() {
|
| 83 |
+
return null;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
@Override
|
| 87 |
+
protected String getBaseDirectory() {
|
| 88 |
+
return null;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
@Override
|
| 92 |
+
protected String getPostfix() {
|
| 93 |
+
return null;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
@Override
|
| 97 |
+
protected boolean deleteOnExit() {
|
| 98 |
+
return false;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
@Override
|
| 102 |
+
public HttpData copy() {
|
| 103 |
+
return null;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@Override
|
| 107 |
+
public HttpData duplicate() {
|
| 108 |
+
return null;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
@Override
|
| 112 |
+
public HttpData retainedDuplicate() {
|
| 113 |
+
return null;
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
@Override
|
| 117 |
+
public HttpData replace(ByteBuf content) {
|
| 118 |
+
return null;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
@Override
|
| 122 |
+
public HttpDataType getHttpDataType() {
|
| 123 |
+
return null;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
@Override
|
| 127 |
+
public int compareTo(InterfaceHttpData o) {
|
| 128 |
+
return 0;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
}
|
Java/AbstractEpsgFactory.java
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Java/AbstractResourceSkin.java
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* See the NOTICE file distributed with this work for additional
|
| 3 |
+
* information regarding copyright ownership.
|
| 4 |
+
*
|
| 5 |
+
* This is free software; you can redistribute it and/or modify it
|
| 6 |
+
* under the terms of the GNU Lesser General Public License as
|
| 7 |
+
* published by the Free Software Foundation; either version 2.1 of
|
| 8 |
+
* the License, or (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This software is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
* Lesser General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
* License along with this software; if not, write to the Free
|
| 17 |
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 18 |
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
| 19 |
+
*/
|
| 20 |
+
package com.xpn.xwiki.internal.skin;
|
| 21 |
+
|
| 22 |
+
import java.net.URL;
|
| 23 |
+
import java.nio.file.Path;
|
| 24 |
+
import java.nio.file.Paths;
|
| 25 |
+
|
| 26 |
+
import org.apache.commons.configuration2.BaseConfiguration;
|
| 27 |
+
import org.apache.commons.configuration2.Configuration;
|
| 28 |
+
import org.apache.commons.configuration2.builder.fluent.Configurations;
|
| 29 |
+
import org.apache.commons.configuration2.ex.ConfigurationException;
|
| 30 |
+
import org.slf4j.Logger;
|
| 31 |
+
import org.slf4j.LoggerFactory;
|
| 32 |
+
import org.xwiki.filter.input.InputSource;
|
| 33 |
+
import org.xwiki.skin.Resource;
|
| 34 |
+
import org.xwiki.skin.Skin;
|
| 35 |
+
|
| 36 |
+
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Common abstract class for the skins that manipulate resources.
|
| 40 |
+
*
|
| 41 |
+
* @version $Id$
|
| 42 |
+
* @since 13.8RC1
|
| 43 |
+
*/
|
| 44 |
+
public abstract class AbstractResourceSkin extends AbstractSkin
|
| 45 |
+
{
|
| 46 |
+
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractResourceSkin.class);
|
| 47 |
+
|
| 48 |
+
private Configuration properties;
|
| 49 |
+
|
| 50 |
+
/**
|
| 51 |
+
* Default constructor.
|
| 52 |
+
*
|
| 53 |
+
* @param id the skin id (for instance, {@code "flamingo"})
|
| 54 |
+
* @param skinManager the skin manager that instantiates this skin
|
| 55 |
+
* @param configuration the skin internal configuration, used to access the default parent skin id
|
| 56 |
+
* @param logger a logger used to log warning in case of error when parsin a skin's syntax
|
| 57 |
+
*/
|
| 58 |
+
public AbstractResourceSkin(String id, InternalSkinManager skinManager,
|
| 59 |
+
InternalSkinConfiguration configuration, Logger logger)
|
| 60 |
+
{
|
| 61 |
+
super(id, skinManager, configuration, logger);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
abstract AbstractResource<InputSource> createResource(String resourcePath, String resourceName);
|
| 65 |
+
|
| 66 |
+
abstract URL getResourceURL(String resourcePath);
|
| 67 |
+
|
| 68 |
+
@Override
|
| 69 |
+
public String getOutputSyntaxString()
|
| 70 |
+
{
|
| 71 |
+
return getProperties().getString("outputSyntax");
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
@Override
|
| 75 |
+
protected Skin createParent()
|
| 76 |
+
{
|
| 77 |
+
Skin skin;
|
| 78 |
+
|
| 79 |
+
String parentId = getProperties().getString("parent");
|
| 80 |
+
|
| 81 |
+
if (parentId != null) {
|
| 82 |
+
if (parentId.isEmpty()) {
|
| 83 |
+
// There is explicitly no parent (make sure to not fallback on default parent skin)
|
| 84 |
+
skin = VOID;
|
| 85 |
+
} else {
|
| 86 |
+
skin = this.skinManager.getSkin(parentId);
|
| 87 |
+
}
|
| 88 |
+
} else {
|
| 89 |
+
skin = null;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
return skin;
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
@Override
|
| 96 |
+
public Resource<?> getLocalResource(String resourceName)
|
| 97 |
+
{
|
| 98 |
+
String resourcePath = getSkinResourcePath(resourceName);
|
| 99 |
+
|
| 100 |
+
if (resourcePath != null && getResourceURL(resourcePath) != null) {
|
| 101 |
+
return createResource(resourcePath, resourceName);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
return null;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
protected String getPropertiesPath()
|
| 108 |
+
{
|
| 109 |
+
return getSkinFolder() + "skin.properties";
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
protected String getSkinFolder()
|
| 113 |
+
{
|
| 114 |
+
return "skins/" + this.id + '/';
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
protected Configuration getProperties()
|
| 118 |
+
{
|
| 119 |
+
if (this.properties == null) {
|
| 120 |
+
URL url = getResourceURL(getPropertiesPath());
|
| 121 |
+
if (url != null) {
|
| 122 |
+
try {
|
| 123 |
+
this.properties = new Configurations().properties(url);
|
| 124 |
+
} catch (ConfigurationException e) {
|
| 125 |
+
LOGGER.error("Failed to load skin [{}] properties file ([])", this.id, url,
|
| 126 |
+
getRootCauseMessage(e));
|
| 127 |
+
|
| 128 |
+
this.properties = new BaseConfiguration();
|
| 129 |
+
}
|
| 130 |
+
} else {
|
| 131 |
+
LOGGER.debug("No properties found for skin [{}]", this.id);
|
| 132 |
+
|
| 133 |
+
this.properties = new BaseConfiguration();
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
return this.properties;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
private String getSkinResourcePath(String resource)
|
| 141 |
+
{
|
| 142 |
+
String skinFolder = getSkinFolder();
|
| 143 |
+
String resourcePath = skinFolder + resource;
|
| 144 |
+
// BUG: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
|
| 145 |
+
// // Prevent inclusion of templates from other directories
|
| 146 |
+
// FIXED:
|
| 147 |
+
// Prevent access to resources from other directories
|
| 148 |
+
Path normalizedResource = Paths.get(resourcePath).normalize();
|
| 149 |
+
// Protect against directory attacks.
|
| 150 |
+
if (!normalizedResource.startsWith(skinFolder)) {
|
| 151 |
+
LOGGER.warn("Direct access to skin file [{}] refused. Possible break-in attempt!", normalizedResource);
|
| 152 |
+
return null;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
return resourcePath;
|
| 156 |
+
}
|
| 157 |
+
}
|
Java/AbstractXMPPConnection.java
ADDED
|
@@ -0,0 +1,1569 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* Copyright 2009 Jive Software.
|
| 4 |
+
*
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 6 |
+
* you may not use this file except in compliance with the License.
|
| 7 |
+
* You may obtain a copy of the License at
|
| 8 |
+
*
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
*
|
| 11 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 12 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 |
+
* See the License for the specific language governing permissions and
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
*/
|
| 17 |
+
package org.jivesoftware.smack;
|
| 18 |
+
|
| 19 |
+
import java.io.IOException;
|
| 20 |
+
import java.io.Reader;
|
| 21 |
+
import java.io.Writer;
|
| 22 |
+
import java.util.ArrayList;
|
| 23 |
+
import java.util.Collection;
|
| 24 |
+
import java.util.HashMap;
|
| 25 |
+
import java.util.LinkedHashMap;
|
| 26 |
+
import java.util.LinkedList;
|
| 27 |
+
import java.util.List;
|
| 28 |
+
import java.util.Map;
|
| 29 |
+
import java.util.Set;
|
| 30 |
+
import java.util.concurrent.ConcurrentLinkedQueue;
|
| 31 |
+
import java.util.concurrent.CopyOnWriteArraySet;
|
| 32 |
+
import java.util.concurrent.ExecutorService;
|
| 33 |
+
import java.util.concurrent.Executors;
|
| 34 |
+
import java.util.concurrent.ScheduledExecutorService;
|
| 35 |
+
import java.util.concurrent.ScheduledFuture;
|
| 36 |
+
import java.util.concurrent.TimeUnit;
|
| 37 |
+
import java.util.concurrent.atomic.AtomicInteger;
|
| 38 |
+
import java.util.concurrent.locks.Lock;
|
| 39 |
+
import java.util.concurrent.locks.ReentrantLock;
|
| 40 |
+
import java.util.logging.Level;
|
| 41 |
+
import java.util.logging.Logger;
|
| 42 |
+
|
| 43 |
+
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
|
| 44 |
+
import org.jivesoftware.smack.SmackException.AlreadyConnectedException;
|
| 45 |
+
import org.jivesoftware.smack.SmackException.AlreadyLoggedInException;
|
| 46 |
+
import org.jivesoftware.smack.SmackException.NoResponseException;
|
| 47 |
+
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
| 48 |
+
import org.jivesoftware.smack.SmackException.ConnectionException;
|
| 49 |
+
import org.jivesoftware.smack.SmackException.ResourceBindingNotOfferedException;
|
| 50 |
+
import org.jivesoftware.smack.SmackException.SecurityRequiredException;
|
| 51 |
+
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
| 52 |
+
import org.jivesoftware.smack.compress.packet.Compress;
|
| 53 |
+
import org.jivesoftware.smack.compression.XMPPInputOutputStream;
|
| 54 |
+
import org.jivesoftware.smack.debugger.SmackDebugger;
|
| 55 |
+
import org.jivesoftware.smack.filter.IQReplyFilter;
|
| 56 |
+
import org.jivesoftware.smack.filter.StanzaFilter;
|
| 57 |
+
import org.jivesoftware.smack.filter.StanzaIdFilter;
|
| 58 |
+
import org.jivesoftware.smack.iqrequest.IQRequestHandler;
|
| 59 |
+
import org.jivesoftware.smack.packet.Bind;
|
| 60 |
+
import org.jivesoftware.smack.packet.ErrorIQ;
|
| 61 |
+
import org.jivesoftware.smack.packet.IQ;
|
| 62 |
+
import org.jivesoftware.smack.packet.Mechanisms;
|
| 63 |
+
import org.jivesoftware.smack.packet.Stanza;
|
| 64 |
+
import org.jivesoftware.smack.packet.ExtensionElement;
|
| 65 |
+
import org.jivesoftware.smack.packet.Presence;
|
| 66 |
+
import org.jivesoftware.smack.packet.Session;
|
| 67 |
+
import org.jivesoftware.smack.packet.StartTls;
|
| 68 |
+
import org.jivesoftware.smack.packet.PlainStreamElement;
|
| 69 |
+
import org.jivesoftware.smack.packet.XMPPError;
|
| 70 |
+
import org.jivesoftware.smack.parsing.ParsingExceptionCallback;
|
| 71 |
+
import org.jivesoftware.smack.parsing.UnparsablePacket;
|
| 72 |
+
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
| 73 |
+
import org.jivesoftware.smack.provider.ProviderManager;
|
| 74 |
+
import org.jivesoftware.smack.util.BoundedThreadPoolExecutor;
|
| 75 |
+
import org.jivesoftware.smack.util.DNSUtil;
|
| 76 |
+
import org.jivesoftware.smack.util.Objects;
|
| 77 |
+
import org.jivesoftware.smack.util.PacketParserUtils;
|
| 78 |
+
import org.jivesoftware.smack.util.ParserUtils;
|
| 79 |
+
import org.jivesoftware.smack.util.SmackExecutorThreadFactory;
|
| 80 |
+
import org.jivesoftware.smack.util.StringUtils;
|
| 81 |
+
import org.jivesoftware.smack.util.dns.HostAddress;
|
| 82 |
+
import org.jxmpp.util.XmppStringUtils;
|
| 83 |
+
import org.xmlpull.v1.XmlPullParser;
|
| 84 |
+
import org.xmlpull.v1.XmlPullParserException;
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
public abstract class AbstractXMPPConnection implements XMPPConnection {
|
| 88 |
+
private static final Logger LOGGER = Logger.getLogger(AbstractXMPPConnection.class.getName());
|
| 89 |
+
|
| 90 |
+
/**
|
| 91 |
+
* Counter to uniquely identify connections that are created.
|
| 92 |
+
*/
|
| 93 |
+
private final static AtomicInteger connectionCounter = new AtomicInteger(0);
|
| 94 |
+
|
| 95 |
+
static {
|
| 96 |
+
// Ensure the SmackConfiguration class is loaded by calling a method in it.
|
| 97 |
+
SmackConfiguration.getVersion();
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
/**
|
| 101 |
+
* Get the collection of listeners that are interested in connection creation events.
|
| 102 |
+
*
|
| 103 |
+
* @return a collection of listeners interested on new connections.
|
| 104 |
+
*/
|
| 105 |
+
protected static Collection<ConnectionCreationListener> getConnectionCreationListeners() {
|
| 106 |
+
return XMPPConnectionRegistry.getConnectionCreationListeners();
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/**
|
| 110 |
+
* A collection of ConnectionListeners which listen for connection closing
|
| 111 |
+
* and reconnection events.
|
| 112 |
+
*/
|
| 113 |
+
protected final Set<ConnectionListener> connectionListeners =
|
| 114 |
+
new CopyOnWriteArraySet<ConnectionListener>();
|
| 115 |
+
|
| 116 |
+
/**
|
| 117 |
+
* A collection of PacketCollectors which collects packets for a specified filter
|
| 118 |
+
* and perform blocking and polling operations on the result queue.
|
| 119 |
+
* <p>
|
| 120 |
+
* We use a ConcurrentLinkedQueue here, because its Iterator is weakly
|
| 121 |
+
* consistent and we want {@link #invokePacketCollectors(Stanza)} for-each
|
| 122 |
+
* loop to be lock free. As drawback, removing a PacketCollector is O(n).
|
| 123 |
+
* The alternative would be a synchronized HashSet, but this would mean a
|
| 124 |
+
* synchronized block around every usage of <code>collectors</code>.
|
| 125 |
+
* </p>
|
| 126 |
+
*/
|
| 127 |
+
private final Collection<PacketCollector> collectors = new ConcurrentLinkedQueue<PacketCollector>();
|
| 128 |
+
|
| 129 |
+
/**
|
| 130 |
+
* List of PacketListeners that will be notified synchronously when a new stanza(/packet) was received.
|
| 131 |
+
*/
|
| 132 |
+
private final Map<StanzaListener, ListenerWrapper> syncRecvListeners = new LinkedHashMap<>();
|
| 133 |
+
|
| 134 |
+
/**
|
| 135 |
+
* List of PacketListeners that will be notified asynchronously when a new stanza(/packet) was received.
|
| 136 |
+
*/
|
| 137 |
+
private final Map<StanzaListener, ListenerWrapper> asyncRecvListeners = new LinkedHashMap<>();
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* List of PacketListeners that will be notified when a new stanza(/packet) was sent.
|
| 141 |
+
*/
|
| 142 |
+
private final Map<StanzaListener, ListenerWrapper> sendListeners =
|
| 143 |
+
new HashMap<StanzaListener, ListenerWrapper>();
|
| 144 |
+
|
| 145 |
+
/**
|
| 146 |
+
* List of PacketListeners that will be notified when a new stanza(/packet) is about to be
|
| 147 |
+
* sent to the server. These interceptors may modify the stanza(/packet) before it is being
|
| 148 |
+
* actually sent to the server.
|
| 149 |
+
*/
|
| 150 |
+
private final Map<StanzaListener, InterceptorWrapper> interceptors =
|
| 151 |
+
new HashMap<StanzaListener, InterceptorWrapper>();
|
| 152 |
+
|
| 153 |
+
protected final Lock connectionLock = new ReentrantLock();
|
| 154 |
+
|
| 155 |
+
protected final Map<String, ExtensionElement> streamFeatures = new HashMap<String, ExtensionElement>();
|
| 156 |
+
|
| 157 |
+
/**
|
| 158 |
+
* The full JID of the authenticated user, as returned by the resource binding response of the server.
|
| 159 |
+
* <p>
|
| 160 |
+
* It is important that we don't infer the user from the login() arguments and the configurations service name, as,
|
| 161 |
+
* for example, when SASL External is used, the username is not given to login but taken from the 'external'
|
| 162 |
+
* certificate.
|
| 163 |
+
* </p>
|
| 164 |
+
*/
|
| 165 |
+
protected String user;
|
| 166 |
+
|
| 167 |
+
protected boolean connected = false;
|
| 168 |
+
|
| 169 |
+
/**
|
| 170 |
+
* The stream ID, see RFC 6120 § 4.7.3
|
| 171 |
+
*/
|
| 172 |
+
protected String streamId;
|
| 173 |
+
|
| 174 |
+
/**
|
| 175 |
+
*
|
| 176 |
+
*/
|
| 177 |
+
private long packetReplyTimeout = SmackConfiguration.getDefaultPacketReplyTimeout();
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* The SmackDebugger allows to log and debug XML traffic.
|
| 181 |
+
*/
|
| 182 |
+
protected SmackDebugger debugger = null;
|
| 183 |
+
|
| 184 |
+
/**
|
| 185 |
+
* The Reader which is used for the debugger.
|
| 186 |
+
*/
|
| 187 |
+
protected Reader reader;
|
| 188 |
+
|
| 189 |
+
/**
|
| 190 |
+
* The Writer which is used for the debugger.
|
| 191 |
+
*/
|
| 192 |
+
protected Writer writer;
|
| 193 |
+
|
| 194 |
+
/**
|
| 195 |
+
* Set to success if the last features stanza from the server has been parsed. A XMPP connection
|
| 196 |
+
* handshake can invoke multiple features stanzas, e.g. when TLS is activated a second feature
|
| 197 |
+
* stanza is send by the server. This is set to true once the last feature stanza has been
|
| 198 |
+
* parsed.
|
| 199 |
+
*/
|
| 200 |
+
protected final SynchronizationPoint<Exception> lastFeaturesReceived = new SynchronizationPoint<Exception>(
|
| 201 |
+
AbstractXMPPConnection.this);
|
| 202 |
+
|
| 203 |
+
/**
|
| 204 |
+
* Set to success if the sasl feature has been received.
|
| 205 |
+
*/
|
| 206 |
+
protected final SynchronizationPoint<SmackException> saslFeatureReceived = new SynchronizationPoint<SmackException>(
|
| 207 |
+
AbstractXMPPConnection.this);
|
| 208 |
+
|
| 209 |
+
/**
|
| 210 |
+
* The SASLAuthentication manager that is responsible for authenticating with the server.
|
| 211 |
+
*/
|
| 212 |
+
protected SASLAuthentication saslAuthentication = new SASLAuthentication(this);
|
| 213 |
+
|
| 214 |
+
/**
|
| 215 |
+
* A number to uniquely identify connections that are created. This is distinct from the
|
| 216 |
+
* connection ID, which is a value sent by the server once a connection is made.
|
| 217 |
+
*/
|
| 218 |
+
protected final int connectionCounterValue = connectionCounter.getAndIncrement();
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* Holds the initial configuration used while creating the connection.
|
| 222 |
+
*/
|
| 223 |
+
protected final ConnectionConfiguration config;
|
| 224 |
+
|
| 225 |
+
/**
|
| 226 |
+
* Defines how the from attribute of outgoing stanzas should be handled.
|
| 227 |
+
*/
|
| 228 |
+
private FromMode fromMode = FromMode.OMITTED;
|
| 229 |
+
|
| 230 |
+
protected XMPPInputOutputStream compressionHandler;
|
| 231 |
+
|
| 232 |
+
private ParsingExceptionCallback parsingExceptionCallback = SmackConfiguration.getDefaultParsingExceptionCallback();
|
| 233 |
+
|
| 234 |
+
/**
|
| 235 |
+
* ExecutorService used to invoke the PacketListeners on newly arrived and parsed stanzas. It is
|
| 236 |
+
* important that we use a <b>single threaded ExecutorService</b> in order to guarantee that the
|
| 237 |
+
* PacketListeners are invoked in the same order the stanzas arrived.
|
| 238 |
+
*/
|
| 239 |
+
private final BoundedThreadPoolExecutor executorService = new BoundedThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS,
|
| 240 |
+
100, new SmackExecutorThreadFactory(connectionCounterValue, "Incoming Processor"));
|
| 241 |
+
|
| 242 |
+
/**
|
| 243 |
+
* This scheduled thread pool executor is used to remove pending callbacks.
|
| 244 |
+
*/
|
| 245 |
+
private final ScheduledExecutorService removeCallbacksService = Executors.newSingleThreadScheduledExecutor(
|
| 246 |
+
new SmackExecutorThreadFactory(connectionCounterValue, "Remove Callbacks"));
|
| 247 |
+
|
| 248 |
+
/**
|
| 249 |
+
* A cached thread pool executor service with custom thread factory to set meaningful names on the threads and set
|
| 250 |
+
* them 'daemon'.
|
| 251 |
+
*/
|
| 252 |
+
private final ExecutorService cachedExecutorService = Executors.newCachedThreadPool(
|
| 253 |
+
// @formatter:off
|
| 254 |
+
new SmackExecutorThreadFactory( // threadFactory
|
| 255 |
+
connectionCounterValue,
|
| 256 |
+
"Cached Executor"
|
| 257 |
+
)
|
| 258 |
+
// @formatter:on
|
| 259 |
+
);
|
| 260 |
+
|
| 261 |
+
/**
|
| 262 |
+
* A executor service used to invoke the callbacks of synchronous stanza(/packet) listeners. We use a executor service to
|
| 263 |
+
* decouple incoming stanza processing from callback invocation. It is important that order of callback invocation
|
| 264 |
+
* is the same as the order of the incoming stanzas. Therefore we use a <i>single</i> threaded executor service.
|
| 265 |
+
*/
|
| 266 |
+
private final ExecutorService singleThreadedExecutorService = Executors.newSingleThreadExecutor(new SmackExecutorThreadFactory(
|
| 267 |
+
getConnectionCounter(), "Single Threaded Executor"));
|
| 268 |
+
|
| 269 |
+
/**
|
| 270 |
+
* The used host to establish the connection to
|
| 271 |
+
*/
|
| 272 |
+
protected String host;
|
| 273 |
+
|
| 274 |
+
/**
|
| 275 |
+
* The used port to establish the connection to
|
| 276 |
+
*/
|
| 277 |
+
protected int port;
|
| 278 |
+
|
| 279 |
+
/**
|
| 280 |
+
* Flag that indicates if the user is currently authenticated with the server.
|
| 281 |
+
*/
|
| 282 |
+
protected boolean authenticated = false;
|
| 283 |
+
|
| 284 |
+
/**
|
| 285 |
+
* Flag that indicates if the user was authenticated with the server when the connection
|
| 286 |
+
* to the server was closed (abruptly or not).
|
| 287 |
+
*/
|
| 288 |
+
protected boolean wasAuthenticated = false;
|
| 289 |
+
|
| 290 |
+
private final Map<String, IQRequestHandler> setIqRequestHandler = new HashMap<>();
|
| 291 |
+
private final Map<String, IQRequestHandler> getIqRequestHandler = new HashMap<>();
|
| 292 |
+
|
| 293 |
+
/**
|
| 294 |
+
* Create a new XMPPConnection to an XMPP server.
|
| 295 |
+
*
|
| 296 |
+
* @param configuration The configuration which is used to establish the connection.
|
| 297 |
+
*/
|
| 298 |
+
protected AbstractXMPPConnection(ConnectionConfiguration configuration) {
|
| 299 |
+
config = configuration;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
/**
|
| 303 |
+
* Get the connection configuration used by this connection.
|
| 304 |
+
*
|
| 305 |
+
* @return the connection configuration.
|
| 306 |
+
*/
|
| 307 |
+
public ConnectionConfiguration getConfiguration() {
|
| 308 |
+
return config;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
@Override
|
| 312 |
+
public String getServiceName() {
|
| 313 |
+
if (serviceName != null) {
|
| 314 |
+
return serviceName;
|
| 315 |
+
}
|
| 316 |
+
return config.getServiceName();
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
@Override
|
| 320 |
+
public String getHost() {
|
| 321 |
+
return host;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
@Override
|
| 325 |
+
public int getPort() {
|
| 326 |
+
return port;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
@Override
|
| 330 |
+
public abstract boolean isSecureConnection();
|
| 331 |
+
|
| 332 |
+
protected abstract void sendStanzaInternal(Stanza packet) throws NotConnectedException;
|
| 333 |
+
|
| 334 |
+
@Override
|
| 335 |
+
public abstract void send(PlainStreamElement element) throws NotConnectedException;
|
| 336 |
+
|
| 337 |
+
@Override
|
| 338 |
+
public abstract boolean isUsingCompression();
|
| 339 |
+
|
| 340 |
+
/**
|
| 341 |
+
* Establishes a connection to the XMPP server and performs an automatic login
|
| 342 |
+
* only if the previous connection state was logged (authenticated). It basically
|
| 343 |
+
* creates and maintains a connection to the server.
|
| 344 |
+
* <p>
|
| 345 |
+
* Listeners will be preserved from a previous connection.
|
| 346 |
+
*
|
| 347 |
+
* @throws XMPPException if an error occurs on the XMPP protocol level.
|
| 348 |
+
* @throws SmackException if an error occurs somewhere else besides XMPP protocol level.
|
| 349 |
+
* @throws IOException
|
| 350 |
+
* @throws ConnectionException with detailed information about the failed connection.
|
| 351 |
+
* @return a reference to this object, to chain <code>connect()</code> with <code>login()</code>.
|
| 352 |
+
*/
|
| 353 |
+
public synchronized AbstractXMPPConnection connect() throws SmackException, IOException, XMPPException {
|
| 354 |
+
// Check if not already connected
|
| 355 |
+
throwAlreadyConnectedExceptionIfAppropriate();
|
| 356 |
+
|
| 357 |
+
// Reset the connection state
|
| 358 |
+
saslAuthentication.init();
|
| 359 |
+
saslFeatureReceived.init();
|
| 360 |
+
lastFeaturesReceived.init();
|
| 361 |
+
streamId = null;
|
| 362 |
+
|
| 363 |
+
// Perform the actual connection to the XMPP service
|
| 364 |
+
connectInternal();
|
| 365 |
+
|
| 366 |
+
return this;
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
/**
|
| 370 |
+
* Abstract method that concrete subclasses of XMPPConnection need to implement to perform their
|
| 371 |
+
* way of XMPP connection establishment. Implementations are required to perform an automatic
|
| 372 |
+
* login if the previous connection state was logged (authenticated).
|
| 373 |
+
*
|
| 374 |
+
* @throws SmackException
|
| 375 |
+
* @throws IOException
|
| 376 |
+
* @throws XMPPException
|
| 377 |
+
*/
|
| 378 |
+
protected abstract void connectInternal() throws SmackException, IOException, XMPPException;
|
| 379 |
+
|
| 380 |
+
private String usedUsername, usedPassword, usedResource;
|
| 381 |
+
|
| 382 |
+
/**
|
| 383 |
+
* Logs in to the server using the strongest SASL mechanism supported by
|
| 384 |
+
* the server. If more than the connection's default stanza(/packet) timeout elapses in each step of the
|
| 385 |
+
* authentication process without a response from the server, a
|
| 386 |
+
* {@link SmackException.NoResponseException} will be thrown.
|
| 387 |
+
* <p>
|
| 388 |
+
* Before logging in (i.e. authenticate) to the server the connection must be connected
|
| 389 |
+
* by calling {@link #connect}.
|
| 390 |
+
* </p>
|
| 391 |
+
* <p>
|
| 392 |
+
* It is possible to log in without sending an initial available presence by using
|
| 393 |
+
* {@link ConnectionConfiguration.Builder#setSendPresence(boolean)}.
|
| 394 |
+
* Finally, if you want to not pass a password and instead use a more advanced mechanism
|
| 395 |
+
* while using SASL then you may be interested in using
|
| 396 |
+
* {@link ConnectionConfiguration.Builder#setCallbackHandler(javax.security.auth.callback.CallbackHandler)}.
|
| 397 |
+
* For more advanced login settings see {@link ConnectionConfiguration}.
|
| 398 |
+
* </p>
|
| 399 |
+
*
|
| 400 |
+
* @throws XMPPException if an error occurs on the XMPP protocol level.
|
| 401 |
+
* @throws SmackException if an error occurs somewhere else besides XMPP protocol level.
|
| 402 |
+
* @throws IOException if an I/O error occurs during login.
|
| 403 |
+
*/
|
| 404 |
+
public synchronized void login() throws XMPPException, SmackException, IOException {
|
| 405 |
+
if (isAnonymous()) {
|
| 406 |
+
throwNotConnectedExceptionIfAppropriate("Did you call connect() before login()?");
|
| 407 |
+
throwAlreadyLoggedInExceptionIfAppropriate();
|
| 408 |
+
loginAnonymously();
|
| 409 |
+
} else {
|
| 410 |
+
// The previously used username, password and resource take over precedence over the
|
| 411 |
+
// ones from the connection configuration
|
| 412 |
+
CharSequence username = usedUsername != null ? usedUsername : config.getUsername();
|
| 413 |
+
String password = usedPassword != null ? usedPassword : config.getPassword();
|
| 414 |
+
String resource = usedResource != null ? usedResource : config.getResource();
|
| 415 |
+
login(username, password, resource);
|
| 416 |
+
}
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
/**
|
| 420 |
+
* Same as {@link #login(CharSequence, String, String)}, but takes the resource from the connection
|
| 421 |
+
* configuration.
|
| 422 |
+
*
|
| 423 |
+
* @param username
|
| 424 |
+
* @param password
|
| 425 |
+
* @throws XMPPException
|
| 426 |
+
* @throws SmackException
|
| 427 |
+
* @throws IOException
|
| 428 |
+
* @see #login
|
| 429 |
+
*/
|
| 430 |
+
public synchronized void login(CharSequence username, String password) throws XMPPException, SmackException,
|
| 431 |
+
IOException {
|
| 432 |
+
login(username, password, config.getResource());
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
+
/**
|
| 436 |
+
* Login with the given username (authorization identity). You may omit the password if a callback handler is used.
|
| 437 |
+
* If resource is null, then the server will generate one.
|
| 438 |
+
*
|
| 439 |
+
* @param username
|
| 440 |
+
* @param password
|
| 441 |
+
* @param resource
|
| 442 |
+
* @throws XMPPException
|
| 443 |
+
* @throws SmackException
|
| 444 |
+
* @throws IOException
|
| 445 |
+
* @see #login
|
| 446 |
+
*/
|
| 447 |
+
public synchronized void login(CharSequence username, String password, String resource) throws XMPPException,
|
| 448 |
+
SmackException, IOException {
|
| 449 |
+
if (!config.allowNullOrEmptyUsername) {
|
| 450 |
+
StringUtils.requireNotNullOrEmpty(username, "Username must not be null or empty");
|
| 451 |
+
}
|
| 452 |
+
throwNotConnectedExceptionIfAppropriate();
|
| 453 |
+
throwAlreadyLoggedInExceptionIfAppropriate();
|
| 454 |
+
usedUsername = username != null ? username.toString() : null;
|
| 455 |
+
usedPassword = password;
|
| 456 |
+
usedResource = resource;
|
| 457 |
+
loginNonAnonymously(usedUsername, usedPassword, usedResource);
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
protected abstract void loginNonAnonymously(String username, String password, String resource)
|
| 461 |
+
throws XMPPException, SmackException, IOException;
|
| 462 |
+
|
| 463 |
+
protected abstract void loginAnonymously() throws XMPPException, SmackException, IOException;
|
| 464 |
+
|
| 465 |
+
@Override
|
| 466 |
+
public final boolean isConnected() {
|
| 467 |
+
return connected;
|
| 468 |
+
}
|
| 469 |
+
|
| 470 |
+
@Override
|
| 471 |
+
public final boolean isAuthenticated() {
|
| 472 |
+
return authenticated;
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
@Override
|
| 476 |
+
public final String getUser() {
|
| 477 |
+
return user;
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
@Override
|
| 481 |
+
public String getStreamId() {
|
| 482 |
+
if (!isConnected()) {
|
| 483 |
+
return null;
|
| 484 |
+
}
|
| 485 |
+
return streamId;
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
// TODO remove this suppression once "disable legacy session" code has been removed from Smack
|
| 489 |
+
@SuppressWarnings("deprecation")
|
| 490 |
+
protected void bindResourceAndEstablishSession(String resource) throws XMPPErrorException,
|
| 491 |
+
IOException, SmackException {
|
| 492 |
+
|
| 493 |
+
// Wait until either:
|
| 494 |
+
// - the servers last features stanza has been parsed
|
| 495 |
+
// - the timeout occurs
|
| 496 |
+
LOGGER.finer("Waiting for last features to be received before continuing with resource binding");
|
| 497 |
+
lastFeaturesReceived.checkIfSuccessOrWait();
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
if (!hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
|
| 501 |
+
// Server never offered resource binding, which is REQURIED in XMPP client and
|
| 502 |
+
// server implementations as per RFC6120 7.2
|
| 503 |
+
throw new ResourceBindingNotOfferedException();
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
// Resource binding, see RFC6120 7.
|
| 507 |
+
// Note that we can not use IQReplyFilter here, since the users full JID is not yet
|
| 508 |
+
// available. It will become available right after the resource has been successfully bound.
|
| 509 |
+
Bind bindResource = Bind.newSet(resource);
|
| 510 |
+
PacketCollector packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(bindResource), bindResource);
|
| 511 |
+
Bind response = packetCollector.nextResultOrThrow();
|
| 512 |
+
// Set the connections user to the result of resource binding. It is important that we don't infer the user
|
| 513 |
+
// from the login() arguments and the configurations service name, as, for example, when SASL External is used,
|
| 514 |
+
// the username is not given to login but taken from the 'external' certificate.
|
| 515 |
+
user = response.getJid();
|
| 516 |
+
serviceName = XmppStringUtils.parseDomain(user);
|
| 517 |
+
|
| 518 |
+
Session.Feature sessionFeature = getFeature(Session.ELEMENT, Session.NAMESPACE);
|
| 519 |
+
// Only bind the session if it's announced as stream feature by the server, is not optional and not disabled
|
| 520 |
+
// For more information see http://tools.ietf.org/html/draft-cridland-xmpp-session-01
|
| 521 |
+
if (sessionFeature != null && !sessionFeature.isOptional() && !getConfiguration().isLegacySessionDisabled()) {
|
| 522 |
+
Session session = new Session();
|
| 523 |
+
packetCollector = createPacketCollectorAndSend(new StanzaIdFilter(session), session);
|
| 524 |
+
packetCollector.nextResultOrThrow();
|
| 525 |
+
}
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
protected void afterSuccessfulLogin(final boolean resumed) throws NotConnectedException {
|
| 529 |
+
// Indicate that we're now authenticated.
|
| 530 |
+
this.authenticated = true;
|
| 531 |
+
|
| 532 |
+
// If debugging is enabled, change the the debug window title to include the
|
| 533 |
+
// name we are now logged-in as.
|
| 534 |
+
// If DEBUG was set to true AFTER the connection was created the debugger
|
| 535 |
+
// will be null
|
| 536 |
+
if (config.isDebuggerEnabled() && debugger != null) {
|
| 537 |
+
debugger.userHasLogged(user);
|
| 538 |
+
}
|
| 539 |
+
callConnectionAuthenticatedListener(resumed);
|
| 540 |
+
|
| 541 |
+
// Set presence to online. It is important that this is done after
|
| 542 |
+
// callConnectionAuthenticatedListener(), as this call will also
|
| 543 |
+
// eventually load the roster. And we should load the roster before we
|
| 544 |
+
// send the initial presence.
|
| 545 |
+
if (config.isSendPresence() && !resumed) {
|
| 546 |
+
sendStanza(new Presence(Presence.Type.available));
|
| 547 |
+
}
|
| 548 |
+
}
|
| 549 |
+
|
| 550 |
+
@Override
|
| 551 |
+
public final boolean isAnonymous() {
|
| 552 |
+
return config.getUsername() == null && usedUsername == null
|
| 553 |
+
&& !config.allowNullOrEmptyUsername;
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
private String serviceName;
|
| 557 |
+
|
| 558 |
+
protected List<HostAddress> hostAddresses;
|
| 559 |
+
|
| 560 |
+
/**
|
| 561 |
+
* Populates {@link #hostAddresses} with at least one host address.
|
| 562 |
+
*
|
| 563 |
+
* @return a list of host addresses where DNS (SRV) RR resolution failed.
|
| 564 |
+
*/
|
| 565 |
+
protected List<HostAddress> populateHostAddresses() {
|
| 566 |
+
List<HostAddress> failedAddresses = new LinkedList<>();
|
| 567 |
+
// N.B.: Important to use config.serviceName and not AbstractXMPPConnection.serviceName
|
| 568 |
+
if (config.host != null) {
|
| 569 |
+
hostAddresses = new ArrayList<HostAddress>(1);
|
| 570 |
+
HostAddress hostAddress;
|
| 571 |
+
hostAddress = new HostAddress(config.host, config.port);
|
| 572 |
+
hostAddresses.add(hostAddress);
|
| 573 |
+
} else {
|
| 574 |
+
hostAddresses = DNSUtil.resolveXMPPDomain(config.serviceName, failedAddresses);
|
| 575 |
+
}
|
| 576 |
+
// If we reach this, then hostAddresses *must not* be empty, i.e. there is at least one host added, either the
|
| 577 |
+
// config.host one or the host representing the service name by DNSUtil
|
| 578 |
+
assert(!hostAddresses.isEmpty());
|
| 579 |
+
return failedAddresses;
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
protected Lock getConnectionLock() {
|
| 583 |
+
return connectionLock;
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
protected void throwNotConnectedExceptionIfAppropriate() throws NotConnectedException {
|
| 587 |
+
throwNotConnectedExceptionIfAppropriate(null);
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
protected void throwNotConnectedExceptionIfAppropriate(String optionalHint) throws NotConnectedException {
|
| 591 |
+
if (!isConnected()) {
|
| 592 |
+
throw new NotConnectedException(optionalHint);
|
| 593 |
+
}
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
protected void throwAlreadyConnectedExceptionIfAppropriate() throws AlreadyConnectedException {
|
| 597 |
+
if (isConnected()) {
|
| 598 |
+
throw new AlreadyConnectedException();
|
| 599 |
+
}
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
protected void throwAlreadyLoggedInExceptionIfAppropriate() throws AlreadyLoggedInException {
|
| 603 |
+
if (isAuthenticated()) {
|
| 604 |
+
throw new AlreadyLoggedInException();
|
| 605 |
+
}
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
@Deprecated
|
| 609 |
+
@Override
|
| 610 |
+
public void sendPacket(Stanza packet) throws NotConnectedException {
|
| 611 |
+
sendStanza(packet);
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
@Override
|
| 615 |
+
public void sendStanza(Stanza packet) throws NotConnectedException {
|
| 616 |
+
Objects.requireNonNull(packet, "Packet must not be null");
|
| 617 |
+
|
| 618 |
+
throwNotConnectedExceptionIfAppropriate();
|
| 619 |
+
switch (fromMode) {
|
| 620 |
+
case OMITTED:
|
| 621 |
+
packet.setFrom(null);
|
| 622 |
+
break;
|
| 623 |
+
case USER:
|
| 624 |
+
packet.setFrom(getUser());
|
| 625 |
+
break;
|
| 626 |
+
case UNCHANGED:
|
| 627 |
+
default:
|
| 628 |
+
break;
|
| 629 |
+
}
|
| 630 |
+
// Invoke interceptors for the new packet that is about to be sent. Interceptors may modify
|
| 631 |
+
// the content of the packet.
|
| 632 |
+
firePacketInterceptors(packet);
|
| 633 |
+
sendStanzaInternal(packet);
|
| 634 |
+
}
|
| 635 |
+
|
| 636 |
+
/**
|
| 637 |
+
* Returns the SASLAuthentication manager that is responsible for authenticating with
|
| 638 |
+
* the server.
|
| 639 |
+
*
|
| 640 |
+
* @return the SASLAuthentication manager that is responsible for authenticating with
|
| 641 |
+
* the server.
|
| 642 |
+
*/
|
| 643 |
+
protected SASLAuthentication getSASLAuthentication() {
|
| 644 |
+
return saslAuthentication;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
/**
|
| 648 |
+
* Closes the connection by setting presence to unavailable then closing the connection to
|
| 649 |
+
* the XMPP server. The XMPPConnection can still be used for connecting to the server
|
| 650 |
+
* again.
|
| 651 |
+
*
|
| 652 |
+
*/
|
| 653 |
+
public void disconnect() {
|
| 654 |
+
try {
|
| 655 |
+
disconnect(new Presence(Presence.Type.unavailable));
|
| 656 |
+
}
|
| 657 |
+
catch (NotConnectedException e) {
|
| 658 |
+
LOGGER.log(Level.FINEST, "Connection is already disconnected", e);
|
| 659 |
+
}
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
/**
|
| 663 |
+
* Closes the connection. A custom unavailable presence is sent to the server, followed
|
| 664 |
+
* by closing the stream. The XMPPConnection can still be used for connecting to the server
|
| 665 |
+
* again. A custom unavailable presence is useful for communicating offline presence
|
| 666 |
+
* information such as "On vacation". Typically, just the status text of the presence
|
| 667 |
+
* stanza(/packet) is set with online information, but most XMPP servers will deliver the full
|
| 668 |
+
* presence stanza(/packet) with whatever data is set.
|
| 669 |
+
*
|
| 670 |
+
* @param unavailablePresence the presence stanza(/packet) to send during shutdown.
|
| 671 |
+
* @throws NotConnectedException
|
| 672 |
+
*/
|
| 673 |
+
public synchronized void disconnect(Presence unavailablePresence) throws NotConnectedException {
|
| 674 |
+
sendStanza(unavailablePresence);
|
| 675 |
+
shutdown();
|
| 676 |
+
callConnectionClosedListener();
|
| 677 |
+
}
|
| 678 |
+
|
| 679 |
+
/**
|
| 680 |
+
* Shuts the current connection down.
|
| 681 |
+
*/
|
| 682 |
+
protected abstract void shutdown();
|
| 683 |
+
|
| 684 |
+
@Override
|
| 685 |
+
public void addConnectionListener(ConnectionListener connectionListener) {
|
| 686 |
+
if (connectionListener == null) {
|
| 687 |
+
return;
|
| 688 |
+
}
|
| 689 |
+
connectionListeners.add(connectionListener);
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
@Override
|
| 693 |
+
public void removeConnectionListener(ConnectionListener connectionListener) {
|
| 694 |
+
connectionListeners.remove(connectionListener);
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
@Override
|
| 698 |
+
public PacketCollector createPacketCollectorAndSend(IQ packet) throws NotConnectedException {
|
| 699 |
+
StanzaFilter packetFilter = new IQReplyFilter(packet, this);
|
| 700 |
+
// Create the packet collector before sending the packet
|
| 701 |
+
PacketCollector packetCollector = createPacketCollectorAndSend(packetFilter, packet);
|
| 702 |
+
return packetCollector;
|
| 703 |
+
}
|
| 704 |
+
|
| 705 |
+
@Override
|
| 706 |
+
public PacketCollector createPacketCollectorAndSend(StanzaFilter packetFilter, Stanza packet)
|
| 707 |
+
throws NotConnectedException {
|
| 708 |
+
// Create the packet collector before sending the packet
|
| 709 |
+
PacketCollector packetCollector = createPacketCollector(packetFilter);
|
| 710 |
+
try {
|
| 711 |
+
// Now we can send the packet as the collector has been created
|
| 712 |
+
sendStanza(packet);
|
| 713 |
+
}
|
| 714 |
+
catch (NotConnectedException | RuntimeException e) {
|
| 715 |
+
packetCollector.cancel();
|
| 716 |
+
throw e;
|
| 717 |
+
}
|
| 718 |
+
return packetCollector;
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
@Override
|
| 722 |
+
public PacketCollector createPacketCollector(StanzaFilter packetFilter) {
|
| 723 |
+
PacketCollector.Configuration configuration = PacketCollector.newConfiguration().setStanzaFilter(packetFilter);
|
| 724 |
+
return createPacketCollector(configuration);
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
@Override
|
| 728 |
+
public PacketCollector createPacketCollector(PacketCollector.Configuration configuration) {
|
| 729 |
+
PacketCollector collector = new PacketCollector(this, configuration);
|
| 730 |
+
// Add the collector to the list of active collectors.
|
| 731 |
+
collectors.add(collector);
|
| 732 |
+
return collector;
|
| 733 |
+
}
|
| 734 |
+
|
| 735 |
+
@Override
|
| 736 |
+
public void removePacketCollector(PacketCollector collector) {
|
| 737 |
+
collectors.remove(collector);
|
| 738 |
+
}
|
| 739 |
+
|
| 740 |
+
@Override
|
| 741 |
+
@Deprecated
|
| 742 |
+
public void addPacketListener(StanzaListener packetListener, StanzaFilter packetFilter) {
|
| 743 |
+
addAsyncStanzaListener(packetListener, packetFilter);
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
@Override
|
| 747 |
+
@Deprecated
|
| 748 |
+
public boolean removePacketListener(StanzaListener packetListener) {
|
| 749 |
+
return removeAsyncStanzaListener(packetListener);
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
@Override
|
| 753 |
+
public void addSyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter) {
|
| 754 |
+
if (packetListener == null) {
|
| 755 |
+
throw new NullPointerException("Packet listener is null.");
|
| 756 |
+
}
|
| 757 |
+
ListenerWrapper wrapper = new ListenerWrapper(packetListener, packetFilter);
|
| 758 |
+
synchronized (syncRecvListeners) {
|
| 759 |
+
syncRecvListeners.put(packetListener, wrapper);
|
| 760 |
+
}
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
@Override
|
| 764 |
+
public boolean removeSyncStanzaListener(StanzaListener packetListener) {
|
| 765 |
+
synchronized (syncRecvListeners) {
|
| 766 |
+
return syncRecvListeners.remove(packetListener) != null;
|
| 767 |
+
}
|
| 768 |
+
}
|
| 769 |
+
|
| 770 |
+
@Override
|
| 771 |
+
public void addAsyncStanzaListener(StanzaListener packetListener, StanzaFilter packetFilter) {
|
| 772 |
+
if (packetListener == null) {
|
| 773 |
+
throw new NullPointerException("Packet listener is null.");
|
| 774 |
+
}
|
| 775 |
+
ListenerWrapper wrapper = new ListenerWrapper(packetListener, packetFilter);
|
| 776 |
+
synchronized (asyncRecvListeners) {
|
| 777 |
+
asyncRecvListeners.put(packetListener, wrapper);
|
| 778 |
+
}
|
| 779 |
+
}
|
| 780 |
+
|
| 781 |
+
@Override
|
| 782 |
+
public boolean removeAsyncStanzaListener(StanzaListener packetListener) {
|
| 783 |
+
synchronized (asyncRecvListeners) {
|
| 784 |
+
return asyncRecvListeners.remove(packetListener) != null;
|
| 785 |
+
}
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
@Override
|
| 789 |
+
public void addPacketSendingListener(StanzaListener packetListener, StanzaFilter packetFilter) {
|
| 790 |
+
if (packetListener == null) {
|
| 791 |
+
throw new NullPointerException("Packet listener is null.");
|
| 792 |
+
}
|
| 793 |
+
ListenerWrapper wrapper = new ListenerWrapper(packetListener, packetFilter);
|
| 794 |
+
synchronized (sendListeners) {
|
| 795 |
+
sendListeners.put(packetListener, wrapper);
|
| 796 |
+
}
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
@Override
|
| 800 |
+
public void removePacketSendingListener(StanzaListener packetListener) {
|
| 801 |
+
synchronized (sendListeners) {
|
| 802 |
+
sendListeners.remove(packetListener);
|
| 803 |
+
}
|
| 804 |
+
}
|
| 805 |
+
|
| 806 |
+
/**
|
| 807 |
+
* Process all stanza(/packet) listeners for sending packets.
|
| 808 |
+
* <p>
|
| 809 |
+
* Compared to {@link #firePacketInterceptors(Stanza)}, the listeners will be invoked in a new thread.
|
| 810 |
+
* </p>
|
| 811 |
+
*
|
| 812 |
+
* @param packet the stanza(/packet) to process.
|
| 813 |
+
*/
|
| 814 |
+
@SuppressWarnings("javadoc")
|
| 815 |
+
protected void firePacketSendingListeners(final Stanza packet) {
|
| 816 |
+
final List<StanzaListener> listenersToNotify = new LinkedList<StanzaListener>();
|
| 817 |
+
synchronized (sendListeners) {
|
| 818 |
+
for (ListenerWrapper listenerWrapper : sendListeners.values()) {
|
| 819 |
+
if (listenerWrapper.filterMatches(packet)) {
|
| 820 |
+
listenersToNotify.add(listenerWrapper.getListener());
|
| 821 |
+
}
|
| 822 |
+
}
|
| 823 |
+
}
|
| 824 |
+
if (listenersToNotify.isEmpty()) {
|
| 825 |
+
return;
|
| 826 |
+
}
|
| 827 |
+
// Notify in a new thread, because we can
|
| 828 |
+
asyncGo(new Runnable() {
|
| 829 |
+
@Override
|
| 830 |
+
public void run() {
|
| 831 |
+
for (StanzaListener listener : listenersToNotify) {
|
| 832 |
+
try {
|
| 833 |
+
listener.processPacket(packet);
|
| 834 |
+
}
|
| 835 |
+
catch (Exception e) {
|
| 836 |
+
LOGGER.log(Level.WARNING, "Sending listener threw exception", e);
|
| 837 |
+
continue;
|
| 838 |
+
}
|
| 839 |
+
}
|
| 840 |
+
}});
|
| 841 |
+
}
|
| 842 |
+
|
| 843 |
+
@Override
|
| 844 |
+
public void addPacketInterceptor(StanzaListener packetInterceptor,
|
| 845 |
+
StanzaFilter packetFilter) {
|
| 846 |
+
if (packetInterceptor == null) {
|
| 847 |
+
throw new NullPointerException("Packet interceptor is null.");
|
| 848 |
+
}
|
| 849 |
+
InterceptorWrapper interceptorWrapper = new InterceptorWrapper(packetInterceptor, packetFilter);
|
| 850 |
+
synchronized (interceptors) {
|
| 851 |
+
interceptors.put(packetInterceptor, interceptorWrapper);
|
| 852 |
+
}
|
| 853 |
+
}
|
| 854 |
+
|
| 855 |
+
@Override
|
| 856 |
+
public void removePacketInterceptor(StanzaListener packetInterceptor) {
|
| 857 |
+
synchronized (interceptors) {
|
| 858 |
+
interceptors.remove(packetInterceptor);
|
| 859 |
+
}
|
| 860 |
+
}
|
| 861 |
+
|
| 862 |
+
/**
|
| 863 |
+
* Process interceptors. Interceptors may modify the stanza(/packet) that is about to be sent.
|
| 864 |
+
* Since the thread that requested to send the stanza(/packet) will invoke all interceptors, it
|
| 865 |
+
* is important that interceptors perform their work as soon as possible so that the
|
| 866 |
+
* thread does not remain blocked for a long period.
|
| 867 |
+
*
|
| 868 |
+
* @param packet the stanza(/packet) that is going to be sent to the server
|
| 869 |
+
*/
|
| 870 |
+
private void firePacketInterceptors(Stanza packet) {
|
| 871 |
+
List<StanzaListener> interceptorsToInvoke = new LinkedList<StanzaListener>();
|
| 872 |
+
synchronized (interceptors) {
|
| 873 |
+
for (InterceptorWrapper interceptorWrapper : interceptors.values()) {
|
| 874 |
+
if (interceptorWrapper.filterMatches(packet)) {
|
| 875 |
+
interceptorsToInvoke.add(interceptorWrapper.getInterceptor());
|
| 876 |
+
}
|
| 877 |
+
}
|
| 878 |
+
}
|
| 879 |
+
for (StanzaListener interceptor : interceptorsToInvoke) {
|
| 880 |
+
try {
|
| 881 |
+
interceptor.processPacket(packet);
|
| 882 |
+
} catch (Exception e) {
|
| 883 |
+
LOGGER.log(Level.SEVERE, "Packet interceptor threw exception", e);
|
| 884 |
+
}
|
| 885 |
+
}
|
| 886 |
+
}
|
| 887 |
+
|
| 888 |
+
/**
|
| 889 |
+
* Initialize the {@link #debugger}. You can specify a customized {@link SmackDebugger}
|
| 890 |
+
* by setup the system property <code>smack.debuggerClass</code> to the implementation.
|
| 891 |
+
*
|
| 892 |
+
* @throws IllegalStateException if the reader or writer isn't yet initialized.
|
| 893 |
+
* @throws IllegalArgumentException if the SmackDebugger can't be loaded.
|
| 894 |
+
*/
|
| 895 |
+
protected void initDebugger() {
|
| 896 |
+
if (reader == null || writer == null) {
|
| 897 |
+
throw new NullPointerException("Reader or writer isn't initialized.");
|
| 898 |
+
}
|
| 899 |
+
// If debugging is enabled, we open a window and write out all network traffic.
|
| 900 |
+
if (config.isDebuggerEnabled()) {
|
| 901 |
+
if (debugger == null) {
|
| 902 |
+
debugger = SmackConfiguration.createDebugger(this, writer, reader);
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
if (debugger == null) {
|
| 906 |
+
LOGGER.severe("Debugging enabled but could not find debugger class");
|
| 907 |
+
} else {
|
| 908 |
+
// Obtain new reader and writer from the existing debugger
|
| 909 |
+
reader = debugger.newConnectionReader(reader);
|
| 910 |
+
writer = debugger.newConnectionWriter(writer);
|
| 911 |
+
}
|
| 912 |
+
}
|
| 913 |
+
}
|
| 914 |
+
|
| 915 |
+
@Override
|
| 916 |
+
public long getPacketReplyTimeout() {
|
| 917 |
+
return packetReplyTimeout;
|
| 918 |
+
}
|
| 919 |
+
|
| 920 |
+
@Override
|
| 921 |
+
public void setPacketReplyTimeout(long timeout) {
|
| 922 |
+
packetReplyTimeout = timeout;
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
private static boolean replyToUnknownIqDefault = true;
|
| 926 |
+
|
| 927 |
+
/**
|
| 928 |
+
* Set the default value used to determine if new connection will reply to unknown IQ requests. The pre-configured
|
| 929 |
+
* default is 'true'.
|
| 930 |
+
*
|
| 931 |
+
* @param replyToUnkownIqDefault
|
| 932 |
+
* @see #setReplyToUnknownIq(boolean)
|
| 933 |
+
*/
|
| 934 |
+
public static void setReplyToUnknownIqDefault(boolean replyToUnkownIqDefault) {
|
| 935 |
+
AbstractXMPPConnection.replyToUnknownIqDefault = replyToUnkownIqDefault;
|
| 936 |
+
}
|
| 937 |
+
|
| 938 |
+
private boolean replyToUnkownIq = replyToUnknownIqDefault;
|
| 939 |
+
|
| 940 |
+
/**
|
| 941 |
+
* Set if Smack will automatically send
|
| 942 |
+
* {@link org.jivesoftware.smack.packet.XMPPError.Condition#feature_not_implemented} when a request IQ without a
|
| 943 |
+
* registered {@link IQRequestHandler} is received.
|
| 944 |
+
*
|
| 945 |
+
* @param replyToUnknownIq
|
| 946 |
+
*/
|
| 947 |
+
public void setReplyToUnknownIq(boolean replyToUnknownIq) {
|
| 948 |
+
this.replyToUnkownIq = replyToUnknownIq;
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
protected void parseAndProcessStanza(XmlPullParser parser) throws Exception {
|
| 952 |
+
ParserUtils.assertAtStartTag(parser);
|
| 953 |
+
int parserDepth = parser.getDepth();
|
| 954 |
+
Stanza stanza = null;
|
| 955 |
+
try {
|
| 956 |
+
stanza = PacketParserUtils.parseStanza(parser);
|
| 957 |
+
}
|
| 958 |
+
catch (Exception e) {
|
| 959 |
+
CharSequence content = PacketParserUtils.parseContentDepth(parser,
|
| 960 |
+
parserDepth);
|
| 961 |
+
UnparsablePacket message = new UnparsablePacket(content, e);
|
| 962 |
+
ParsingExceptionCallback callback = getParsingExceptionCallback();
|
| 963 |
+
if (callback != null) {
|
| 964 |
+
callback.handleUnparsablePacket(message);
|
| 965 |
+
}
|
| 966 |
+
}
|
| 967 |
+
ParserUtils.assertAtEndTag(parser);
|
| 968 |
+
if (stanza != null) {
|
| 969 |
+
processPacket(stanza);
|
| 970 |
+
}
|
| 971 |
+
}
|
| 972 |
+
|
| 973 |
+
/**
|
| 974 |
+
* Processes a stanza(/packet) after it's been fully parsed by looping through the installed
|
| 975 |
+
* stanza(/packet) collectors and listeners and letting them examine the stanza(/packet) to see if
|
| 976 |
+
* they are a match with the filter.
|
| 977 |
+
*
|
| 978 |
+
* @param packet the stanza(/packet) to process.
|
| 979 |
+
* @throws InterruptedException
|
| 980 |
+
*/
|
| 981 |
+
protected void processPacket(Stanza packet) throws InterruptedException {
|
| 982 |
+
assert(packet != null);
|
| 983 |
+
lastStanzaReceived = System.currentTimeMillis();
|
| 984 |
+
// Deliver the incoming packet to listeners.
|
| 985 |
+
executorService.executeBlocking(new ListenerNotification(packet));
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
/**
|
| 989 |
+
* A runnable to notify all listeners and stanza(/packet) collectors of a packet.
|
| 990 |
+
*/
|
| 991 |
+
private class ListenerNotification implements Runnable {
|
| 992 |
+
|
| 993 |
+
private final Stanza packet;
|
| 994 |
+
|
| 995 |
+
public ListenerNotification(Stanza packet) {
|
| 996 |
+
this.packet = packet;
|
| 997 |
+
}
|
| 998 |
+
|
| 999 |
+
public void run() {
|
| 1000 |
+
invokePacketCollectorsAndNotifyRecvListeners(packet);
|
| 1001 |
+
}
|
| 1002 |
+
}
|
| 1003 |
+
|
| 1004 |
+
/**
|
| 1005 |
+
* Invoke {@link PacketCollector#processPacket(Stanza)} for every
|
| 1006 |
+
* PacketCollector with the given packet. Also notify the receive listeners with a matching stanza(/packet) filter about the packet.
|
| 1007 |
+
*
|
| 1008 |
+
* @param packet the stanza(/packet) to notify the PacketCollectors and receive listeners about.
|
| 1009 |
+
*/
|
| 1010 |
+
protected void invokePacketCollectorsAndNotifyRecvListeners(final Stanza packet) {
|
| 1011 |
+
if (packet instanceof IQ) {
|
| 1012 |
+
final IQ iq = (IQ) packet;
|
| 1013 |
+
final IQ.Type type = iq.getType();
|
| 1014 |
+
switch (type) {
|
| 1015 |
+
case set:
|
| 1016 |
+
case get:
|
| 1017 |
+
final String key = XmppStringUtils.generateKey(iq.getChildElementName(), iq.getChildElementNamespace());
|
| 1018 |
+
IQRequestHandler iqRequestHandler = null;
|
| 1019 |
+
switch (type) {
|
| 1020 |
+
case set:
|
| 1021 |
+
synchronized (setIqRequestHandler) {
|
| 1022 |
+
iqRequestHandler = setIqRequestHandler.get(key);
|
| 1023 |
+
}
|
| 1024 |
+
break;
|
| 1025 |
+
case get:
|
| 1026 |
+
synchronized (getIqRequestHandler) {
|
| 1027 |
+
iqRequestHandler = getIqRequestHandler.get(key);
|
| 1028 |
+
}
|
| 1029 |
+
break;
|
| 1030 |
+
default:
|
| 1031 |
+
throw new IllegalStateException("Should only encounter IQ type 'get' or 'set'");
|
| 1032 |
+
}
|
| 1033 |
+
if (iqRequestHandler == null) {
|
| 1034 |
+
if (!replyToUnkownIq) {
|
| 1035 |
+
return;
|
| 1036 |
+
}
|
| 1037 |
+
// If the IQ stanza is of type "get" or "set" with no registered IQ request handler, then answer an
|
| 1038 |
+
// IQ of type "error" with code 501 ("feature-not-implemented")
|
| 1039 |
+
ErrorIQ errorIQ = IQ.createErrorResponse(iq, new XMPPError(
|
| 1040 |
+
XMPPError.Condition.feature_not_implemented));
|
| 1041 |
+
try {
|
| 1042 |
+
sendStanza(errorIQ);
|
| 1043 |
+
}
|
| 1044 |
+
catch (NotConnectedException e) {
|
| 1045 |
+
LOGGER.log(Level.WARNING, "NotConnectedException while sending error IQ to unkown IQ request", e);
|
| 1046 |
+
}
|
| 1047 |
+
} else {
|
| 1048 |
+
ExecutorService executorService = null;
|
| 1049 |
+
switch (iqRequestHandler.getMode()) {
|
| 1050 |
+
case sync:
|
| 1051 |
+
executorService = singleThreadedExecutorService;
|
| 1052 |
+
break;
|
| 1053 |
+
case async:
|
| 1054 |
+
executorService = cachedExecutorService;
|
| 1055 |
+
break;
|
| 1056 |
+
}
|
| 1057 |
+
final IQRequestHandler finalIqRequestHandler = iqRequestHandler;
|
| 1058 |
+
executorService.execute(new Runnable() {
|
| 1059 |
+
@Override
|
| 1060 |
+
public void run() {
|
| 1061 |
+
IQ response = finalIqRequestHandler.handleIQRequest(iq);
|
| 1062 |
+
if (response == null) {
|
| 1063 |
+
// It is not ideal if the IQ request handler does not return an IQ response, because RFC
|
| 1064 |
+
// 6120 § 8.1.2 does specify that a response is mandatory. But some APIs, mostly the
|
| 1065 |
+
// file transfer one, does not always return a result, so we need to handle this case.
|
| 1066 |
+
// Also sometimes a request handler may decide that it's better to not send a response,
|
| 1067 |
+
// e.g. to avoid presence leaks.
|
| 1068 |
+
return;
|
| 1069 |
+
}
|
| 1070 |
+
try {
|
| 1071 |
+
sendStanza(response);
|
| 1072 |
+
}
|
| 1073 |
+
catch (NotConnectedException e) {
|
| 1074 |
+
LOGGER.log(Level.WARNING, "NotConnectedException while sending response to IQ request", e);
|
| 1075 |
+
}
|
| 1076 |
+
}
|
| 1077 |
+
});
|
| 1078 |
+
// The following returns makes it impossible for packet listeners and collectors to
|
| 1079 |
+
// filter for IQ request stanzas, i.e. IQs of type 'set' or 'get'. This is the
|
| 1080 |
+
// desired behavior.
|
| 1081 |
+
return;
|
| 1082 |
+
}
|
| 1083 |
+
break;
|
| 1084 |
+
default:
|
| 1085 |
+
break;
|
| 1086 |
+
}
|
| 1087 |
+
}
|
| 1088 |
+
|
| 1089 |
+
// First handle the async recv listeners. Note that this code is very similar to what follows a few lines below,
|
| 1090 |
+
// the only difference is that asyncRecvListeners is used here and that the packet listeners are started in
|
| 1091 |
+
// their own thread.
|
| 1092 |
+
final Collection<StanzaListener> listenersToNotify = new LinkedList<StanzaListener>();
|
| 1093 |
+
synchronized (asyncRecvListeners) {
|
| 1094 |
+
for (ListenerWrapper listenerWrapper : asyncRecvListeners.values()) {
|
| 1095 |
+
if (listenerWrapper.filterMatches(packet)) {
|
| 1096 |
+
listenersToNotify.add(listenerWrapper.getListener());
|
| 1097 |
+
}
|
| 1098 |
+
}
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
for (final StanzaListener listener : listenersToNotify) {
|
| 1102 |
+
asyncGo(new Runnable() {
|
| 1103 |
+
@Override
|
| 1104 |
+
public void run() {
|
| 1105 |
+
try {
|
| 1106 |
+
listener.processPacket(packet);
|
| 1107 |
+
} catch (Exception e) {
|
| 1108 |
+
LOGGER.log(Level.SEVERE, "Exception in async packet listener", e);
|
| 1109 |
+
}
|
| 1110 |
+
}
|
| 1111 |
+
});
|
| 1112 |
+
}
|
| 1113 |
+
|
| 1114 |
+
// Loop through all collectors and notify the appropriate ones.
|
| 1115 |
+
for (PacketCollector collector: collectors) {
|
| 1116 |
+
collector.processPacket(packet);
|
| 1117 |
+
}
|
| 1118 |
+
|
| 1119 |
+
// Notify the receive listeners interested in the packet
|
| 1120 |
+
listenersToNotify.clear();
|
| 1121 |
+
synchronized (syncRecvListeners) {
|
| 1122 |
+
for (ListenerWrapper listenerWrapper : syncRecvListeners.values()) {
|
| 1123 |
+
if (listenerWrapper.filterMatches(packet)) {
|
| 1124 |
+
listenersToNotify.add(listenerWrapper.getListener());
|
| 1125 |
+
}
|
| 1126 |
+
}
|
| 1127 |
+
}
|
| 1128 |
+
|
| 1129 |
+
// Decouple incoming stanza processing from listener invocation. Unlike async listeners, this uses a single
|
| 1130 |
+
// threaded executor service and therefore keeps the order.
|
| 1131 |
+
singleThreadedExecutorService.execute(new Runnable() {
|
| 1132 |
+
@Override
|
| 1133 |
+
public void run() {
|
| 1134 |
+
for (StanzaListener listener : listenersToNotify) {
|
| 1135 |
+
try {
|
| 1136 |
+
listener.processPacket(packet);
|
| 1137 |
+
} catch(NotConnectedException e) {
|
| 1138 |
+
LOGGER.log(Level.WARNING, "Got not connected exception, aborting", e);
|
| 1139 |
+
break;
|
| 1140 |
+
} catch (Exception e) {
|
| 1141 |
+
LOGGER.log(Level.SEVERE, "Exception in packet listener", e);
|
| 1142 |
+
}
|
| 1143 |
+
}
|
| 1144 |
+
}
|
| 1145 |
+
});
|
| 1146 |
+
|
| 1147 |
+
}
|
| 1148 |
+
|
| 1149 |
+
/**
|
| 1150 |
+
* Sets whether the connection has already logged in the server. This method assures that the
|
| 1151 |
+
* {@link #wasAuthenticated} flag is never reset once it has ever been set.
|
| 1152 |
+
*
|
| 1153 |
+
*/
|
| 1154 |
+
protected void setWasAuthenticated() {
|
| 1155 |
+
// Never reset the flag if the connection has ever been authenticated
|
| 1156 |
+
if (!wasAuthenticated) {
|
| 1157 |
+
wasAuthenticated = authenticated;
|
| 1158 |
+
}
|
| 1159 |
+
}
|
| 1160 |
+
|
| 1161 |
+
protected void callConnectionConnectedListener() {
|
| 1162 |
+
for (ConnectionListener listener : connectionListeners) {
|
| 1163 |
+
listener.connected(this);
|
| 1164 |
+
}
|
| 1165 |
+
}
|
| 1166 |
+
|
| 1167 |
+
protected void callConnectionAuthenticatedListener(boolean resumed) {
|
| 1168 |
+
for (ConnectionListener listener : connectionListeners) {
|
| 1169 |
+
try {
|
| 1170 |
+
listener.authenticated(this, resumed);
|
| 1171 |
+
} catch (Exception e) {
|
| 1172 |
+
// Catch and print any exception so we can recover
|
| 1173 |
+
// from a faulty listener and finish the shutdown process
|
| 1174 |
+
LOGGER.log(Level.SEVERE, "Exception in authenticated listener", e);
|
| 1175 |
+
}
|
| 1176 |
+
}
|
| 1177 |
+
}
|
| 1178 |
+
|
| 1179 |
+
void callConnectionClosedListener() {
|
| 1180 |
+
for (ConnectionListener listener : connectionListeners) {
|
| 1181 |
+
try {
|
| 1182 |
+
listener.connectionClosed();
|
| 1183 |
+
}
|
| 1184 |
+
catch (Exception e) {
|
| 1185 |
+
// Catch and print any exception so we can recover
|
| 1186 |
+
// from a faulty listener and finish the shutdown process
|
| 1187 |
+
LOGGER.log(Level.SEVERE, "Error in listener while closing connection", e);
|
| 1188 |
+
}
|
| 1189 |
+
}
|
| 1190 |
+
}
|
| 1191 |
+
|
| 1192 |
+
protected void callConnectionClosedOnErrorListener(Exception e) {
|
| 1193 |
+
LOGGER.log(Level.WARNING, "Connection closed with error", e);
|
| 1194 |
+
for (ConnectionListener listener : connectionListeners) {
|
| 1195 |
+
try {
|
| 1196 |
+
listener.connectionClosedOnError(e);
|
| 1197 |
+
}
|
| 1198 |
+
catch (Exception e2) {
|
| 1199 |
+
// Catch and print any exception so we can recover
|
| 1200 |
+
// from a faulty listener
|
| 1201 |
+
LOGGER.log(Level.SEVERE, "Error in listener while closing connection", e2);
|
| 1202 |
+
}
|
| 1203 |
+
}
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
/**
|
| 1207 |
+
* Sends a notification indicating that the connection was reconnected successfully.
|
| 1208 |
+
*/
|
| 1209 |
+
protected void notifyReconnection() {
|
| 1210 |
+
// Notify connection listeners of the reconnection.
|
| 1211 |
+
for (ConnectionListener listener : connectionListeners) {
|
| 1212 |
+
try {
|
| 1213 |
+
listener.reconnectionSuccessful();
|
| 1214 |
+
}
|
| 1215 |
+
catch (Exception e) {
|
| 1216 |
+
// Catch and print any exception so we can recover
|
| 1217 |
+
// from a faulty listener
|
| 1218 |
+
LOGGER.log(Level.WARNING, "notifyReconnection()", e);
|
| 1219 |
+
}
|
| 1220 |
+
}
|
| 1221 |
+
}
|
| 1222 |
+
|
| 1223 |
+
/**
|
| 1224 |
+
* A wrapper class to associate a stanza(/packet) filter with a listener.
|
| 1225 |
+
*/
|
| 1226 |
+
protected static class ListenerWrapper {
|
| 1227 |
+
|
| 1228 |
+
private final StanzaListener packetListener;
|
| 1229 |
+
private final StanzaFilter packetFilter;
|
| 1230 |
+
|
| 1231 |
+
/**
|
| 1232 |
+
* Create a class which associates a stanza(/packet) filter with a listener.
|
| 1233 |
+
*
|
| 1234 |
+
* @param packetListener the stanza(/packet) listener.
|
| 1235 |
+
* @param packetFilter the associated filter or null if it listen for all packets.
|
| 1236 |
+
*/
|
| 1237 |
+
public ListenerWrapper(StanzaListener packetListener, StanzaFilter packetFilter) {
|
| 1238 |
+
this.packetListener = packetListener;
|
| 1239 |
+
this.packetFilter = packetFilter;
|
| 1240 |
+
}
|
| 1241 |
+
|
| 1242 |
+
public boolean filterMatches(Stanza packet) {
|
| 1243 |
+
return packetFilter == null || packetFilter.accept(packet);
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
public StanzaListener getListener() {
|
| 1247 |
+
return packetListener;
|
| 1248 |
+
}
|
| 1249 |
+
}
|
| 1250 |
+
|
| 1251 |
+
/**
|
| 1252 |
+
* A wrapper class to associate a stanza(/packet) filter with an interceptor.
|
| 1253 |
+
*/
|
| 1254 |
+
protected static class InterceptorWrapper {
|
| 1255 |
+
|
| 1256 |
+
private final StanzaListener packetInterceptor;
|
| 1257 |
+
private final StanzaFilter packetFilter;
|
| 1258 |
+
|
| 1259 |
+
/**
|
| 1260 |
+
* Create a class which associates a stanza(/packet) filter with an interceptor.
|
| 1261 |
+
*
|
| 1262 |
+
* @param packetInterceptor the interceptor.
|
| 1263 |
+
* @param packetFilter the associated filter or null if it intercepts all packets.
|
| 1264 |
+
*/
|
| 1265 |
+
public InterceptorWrapper(StanzaListener packetInterceptor, StanzaFilter packetFilter) {
|
| 1266 |
+
this.packetInterceptor = packetInterceptor;
|
| 1267 |
+
this.packetFilter = packetFilter;
|
| 1268 |
+
}
|
| 1269 |
+
|
| 1270 |
+
public boolean filterMatches(Stanza packet) {
|
| 1271 |
+
return packetFilter == null || packetFilter.accept(packet);
|
| 1272 |
+
}
|
| 1273 |
+
|
| 1274 |
+
public StanzaListener getInterceptor() {
|
| 1275 |
+
return packetInterceptor;
|
| 1276 |
+
}
|
| 1277 |
+
}
|
| 1278 |
+
|
| 1279 |
+
@Override
|
| 1280 |
+
public int getConnectionCounter() {
|
| 1281 |
+
return connectionCounterValue;
|
| 1282 |
+
}
|
| 1283 |
+
|
| 1284 |
+
@Override
|
| 1285 |
+
public void setFromMode(FromMode fromMode) {
|
| 1286 |
+
this.fromMode = fromMode;
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
@Override
|
| 1290 |
+
public FromMode getFromMode() {
|
| 1291 |
+
return this.fromMode;
|
| 1292 |
+
}
|
| 1293 |
+
|
| 1294 |
+
@Override
|
| 1295 |
+
protected void finalize() throws Throwable {
|
| 1296 |
+
LOGGER.fine("finalizing XMPPConnection ( " + getConnectionCounter()
|
| 1297 |
+
+ "): Shutting down executor services");
|
| 1298 |
+
try {
|
| 1299 |
+
// It's usually not a good idea to rely on finalize. But this is the easiest way to
|
| 1300 |
+
// avoid the "Smack Listener Processor" leaking. The thread(s) of the executor have a
|
| 1301 |
+
// reference to their ExecutorService which prevents the ExecutorService from being
|
| 1302 |
+
// gc'ed. It is possible that the XMPPConnection instance is gc'ed while the
|
| 1303 |
+
// listenerExecutor ExecutorService call not be gc'ed until it got shut down.
|
| 1304 |
+
executorService.shutdownNow();
|
| 1305 |
+
cachedExecutorService.shutdown();
|
| 1306 |
+
removeCallbacksService.shutdownNow();
|
| 1307 |
+
singleThreadedExecutorService.shutdownNow();
|
| 1308 |
+
} catch (Throwable t) {
|
| 1309 |
+
LOGGER.log(Level.WARNING, "finalize() threw trhowable", t);
|
| 1310 |
+
}
|
| 1311 |
+
finally {
|
| 1312 |
+
super.finalize();
|
| 1313 |
+
}
|
| 1314 |
+
}
|
| 1315 |
+
|
| 1316 |
+
protected final void parseFeatures(XmlPullParser parser) throws XmlPullParserException,
|
| 1317 |
+
IOException, SmackException {
|
| 1318 |
+
streamFeatures.clear();
|
| 1319 |
+
final int initialDepth = parser.getDepth();
|
| 1320 |
+
while (true) {
|
| 1321 |
+
int eventType = parser.next();
|
| 1322 |
+
|
| 1323 |
+
if (eventType == XmlPullParser.START_TAG && parser.getDepth() == initialDepth + 1) {
|
| 1324 |
+
ExtensionElement streamFeature = null;
|
| 1325 |
+
String name = parser.getName();
|
| 1326 |
+
String namespace = parser.getNamespace();
|
| 1327 |
+
switch (name) {
|
| 1328 |
+
case StartTls.ELEMENT:
|
| 1329 |
+
streamFeature = PacketParserUtils.parseStartTlsFeature(parser);
|
| 1330 |
+
break;
|
| 1331 |
+
case Mechanisms.ELEMENT:
|
| 1332 |
+
streamFeature = new Mechanisms(PacketParserUtils.parseMechanisms(parser));
|
| 1333 |
+
break;
|
| 1334 |
+
case Bind.ELEMENT:
|
| 1335 |
+
streamFeature = Bind.Feature.INSTANCE;
|
| 1336 |
+
break;
|
| 1337 |
+
case Session.ELEMENT:
|
| 1338 |
+
streamFeature = PacketParserUtils.parseSessionFeature(parser);
|
| 1339 |
+
break;
|
| 1340 |
+
case Compress.Feature.ELEMENT:
|
| 1341 |
+
streamFeature = PacketParserUtils.parseCompressionFeature(parser);
|
| 1342 |
+
break;
|
| 1343 |
+
default:
|
| 1344 |
+
ExtensionElementProvider<ExtensionElement> provider = ProviderManager.getStreamFeatureProvider(name, namespace);
|
| 1345 |
+
if (provider != null) {
|
| 1346 |
+
streamFeature = provider.parse(parser);
|
| 1347 |
+
}
|
| 1348 |
+
break;
|
| 1349 |
+
}
|
| 1350 |
+
if (streamFeature != null) {
|
| 1351 |
+
addStreamFeature(streamFeature);
|
| 1352 |
+
}
|
| 1353 |
+
}
|
| 1354 |
+
else if (eventType == XmlPullParser.END_TAG && parser.getDepth() == initialDepth) {
|
| 1355 |
+
break;
|
| 1356 |
+
}
|
| 1357 |
+
}
|
| 1358 |
+
|
| 1359 |
+
if (hasFeature(Mechanisms.ELEMENT, Mechanisms.NAMESPACE)) {
|
| 1360 |
+
// Only proceed with SASL auth if TLS is disabled or if the server doesn't announce it
|
| 1361 |
+
if (!hasFeature(StartTls.ELEMENT, StartTls.NAMESPACE)
|
| 1362 |
+
|| config.getSecurityMode() == SecurityMode.disabled) {
|
| 1363 |
+
saslFeatureReceived.reportSuccess();
|
| 1364 |
+
}
|
| 1365 |
+
}
|
| 1366 |
+
|
| 1367 |
+
// If the server reported the bind feature then we are that that we did SASL and maybe
|
| 1368 |
+
// STARTTLS. We can then report that the last 'stream:features' have been parsed
|
| 1369 |
+
if (hasFeature(Bind.ELEMENT, Bind.NAMESPACE)) {
|
| 1370 |
+
if (!hasFeature(Compress.Feature.ELEMENT, Compress.NAMESPACE)
|
| 1371 |
+
|| !config.isCompressionEnabled()) {
|
| 1372 |
+
// This was was last features from the server is either it did not contain
|
| 1373 |
+
// compression or if we disabled it
|
| 1374 |
+
lastFeaturesReceived.reportSuccess();
|
| 1375 |
+
}
|
| 1376 |
+
}
|
| 1377 |
+
afterFeaturesReceived();
|
| 1378 |
+
}
|
| 1379 |
+
|
| 1380 |
+
protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException {
|
| 1381 |
+
// Default implementation does nothing
|
| 1382 |
+
}
|
| 1383 |
+
|
| 1384 |
+
@SuppressWarnings("unchecked")
|
| 1385 |
+
@Override
|
| 1386 |
+
public <F extends ExtensionElement> F getFeature(String element, String namespace) {
|
| 1387 |
+
return (F) streamFeatures.get(XmppStringUtils.generateKey(element, namespace));
|
| 1388 |
+
}
|
| 1389 |
+
|
| 1390 |
+
@Override
|
| 1391 |
+
public boolean hasFeature(String element, String namespace) {
|
| 1392 |
+
return getFeature(element, namespace) != null;
|
| 1393 |
+
}
|
| 1394 |
+
|
| 1395 |
+
private void addStreamFeature(ExtensionElement feature) {
|
| 1396 |
+
String key = XmppStringUtils.generateKey(feature.getElementName(), feature.getNamespace());
|
| 1397 |
+
streamFeatures.put(key, feature);
|
| 1398 |
+
}
|
| 1399 |
+
|
| 1400 |
+
@Override
|
| 1401 |
+
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
|
| 1402 |
+
StanzaListener callback) throws NotConnectedException {
|
| 1403 |
+
sendStanzaWithResponseCallback(stanza, replyFilter, callback, null);
|
| 1404 |
+
}
|
| 1405 |
+
|
| 1406 |
+
@Override
|
| 1407 |
+
public void sendStanzaWithResponseCallback(Stanza stanza, StanzaFilter replyFilter,
|
| 1408 |
+
StanzaListener callback, ExceptionCallback exceptionCallback)
|
| 1409 |
+
throws NotConnectedException {
|
| 1410 |
+
sendStanzaWithResponseCallback(stanza, replyFilter, callback, exceptionCallback,
|
| 1411 |
+
getPacketReplyTimeout());
|
| 1412 |
+
}
|
| 1413 |
+
|
| 1414 |
+
@Override
|
| 1415 |
+
public void sendStanzaWithResponseCallback(Stanza stanza, final StanzaFilter replyFilter,
|
| 1416 |
+
final StanzaListener callback, final ExceptionCallback exceptionCallback,
|
| 1417 |
+
long timeout) throws NotConnectedException {
|
| 1418 |
+
Objects.requireNonNull(stanza, "stanza must not be null");
|
| 1419 |
+
// While Smack allows to add PacketListeners with a PacketFilter value of 'null', we
|
| 1420 |
+
// disallow it here in the async API as it makes no sense
|
| 1421 |
+
Objects.requireNonNull(replyFilter, "replyFilter must not be null");
|
| 1422 |
+
Objects.requireNonNull(callback, "callback must not be null");
|
| 1423 |
+
|
| 1424 |
+
final StanzaListener packetListener = new StanzaListener() {
|
| 1425 |
+
@Override
|
| 1426 |
+
public void processPacket(Stanza packet) throws NotConnectedException {
|
| 1427 |
+
try {
|
| 1428 |
+
XMPPErrorException.ifHasErrorThenThrow(packet);
|
| 1429 |
+
callback.processPacket(packet);
|
| 1430 |
+
}
|
| 1431 |
+
catch (XMPPErrorException e) {
|
| 1432 |
+
if (exceptionCallback != null) {
|
| 1433 |
+
exceptionCallback.processException(e);
|
| 1434 |
+
}
|
| 1435 |
+
}
|
| 1436 |
+
finally {
|
| 1437 |
+
removeAsyncStanzaListener(this);
|
| 1438 |
+
}
|
| 1439 |
+
}
|
| 1440 |
+
};
|
| 1441 |
+
removeCallbacksService.schedule(new Runnable() {
|
| 1442 |
+
@Override
|
| 1443 |
+
public void run() {
|
| 1444 |
+
boolean removed = removeAsyncStanzaListener(packetListener);
|
| 1445 |
+
// If the packetListener got removed, then it was never run and
|
| 1446 |
+
// we never received a response, inform the exception callback
|
| 1447 |
+
if (removed && exceptionCallback != null) {
|
| 1448 |
+
exceptionCallback.processException(NoResponseException.newWith(AbstractXMPPConnection.this, replyFilter));
|
| 1449 |
+
}
|
| 1450 |
+
}
|
| 1451 |
+
}, timeout, TimeUnit.MILLISECONDS);
|
| 1452 |
+
addAsyncStanzaListener(packetListener, replyFilter);
|
| 1453 |
+
sendStanza(stanza);
|
| 1454 |
+
}
|
| 1455 |
+
|
| 1456 |
+
@Override
|
| 1457 |
+
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback)
|
| 1458 |
+
throws NotConnectedException {
|
| 1459 |
+
sendIqWithResponseCallback(iqRequest, callback, null);
|
| 1460 |
+
}
|
| 1461 |
+
|
| 1462 |
+
@Override
|
| 1463 |
+
public void sendIqWithResponseCallback(IQ iqRequest, StanzaListener callback,
|
| 1464 |
+
ExceptionCallback exceptionCallback) throws NotConnectedException {
|
| 1465 |
+
sendIqWithResponseCallback(iqRequest, callback, exceptionCallback, getPacketReplyTimeout());
|
| 1466 |
+
}
|
| 1467 |
+
|
| 1468 |
+
@Override
|
| 1469 |
+
public void sendIqWithResponseCallback(IQ iqRequest, final StanzaListener callback,
|
| 1470 |
+
final ExceptionCallback exceptionCallback, long timeout)
|
| 1471 |
+
throws NotConnectedException {
|
| 1472 |
+
StanzaFilter replyFilter = new IQReplyFilter(iqRequest, this);
|
| 1473 |
+
sendStanzaWithResponseCallback(iqRequest, replyFilter, callback, exceptionCallback, timeout);
|
| 1474 |
+
}
|
| 1475 |
+
|
| 1476 |
+
@Override
|
| 1477 |
+
public void addOneTimeSyncCallback(final StanzaListener callback, final StanzaFilter packetFilter) {
|
| 1478 |
+
final StanzaListener packetListener = new StanzaListener() {
|
| 1479 |
+
@Override
|
| 1480 |
+
public void processPacket(Stanza packet) throws NotConnectedException {
|
| 1481 |
+
try {
|
| 1482 |
+
callback.processPacket(packet);
|
| 1483 |
+
} finally {
|
| 1484 |
+
removeSyncStanzaListener(this);
|
| 1485 |
+
}
|
| 1486 |
+
}
|
| 1487 |
+
};
|
| 1488 |
+
addSyncStanzaListener(packetListener, packetFilter);
|
| 1489 |
+
removeCallbacksService.schedule(new Runnable() {
|
| 1490 |
+
@Override
|
| 1491 |
+
public void run() {
|
| 1492 |
+
removeSyncStanzaListener(packetListener);
|
| 1493 |
+
}
|
| 1494 |
+
}, getPacketReplyTimeout(), TimeUnit.MILLISECONDS);
|
| 1495 |
+
}
|
| 1496 |
+
|
| 1497 |
+
@Override
|
| 1498 |
+
public IQRequestHandler registerIQRequestHandler(final IQRequestHandler iqRequestHandler) {
|
| 1499 |
+
final String key = XmppStringUtils.generateKey(iqRequestHandler.getElement(), iqRequestHandler.getNamespace());
|
| 1500 |
+
switch (iqRequestHandler.getType()) {
|
| 1501 |
+
case set:
|
| 1502 |
+
synchronized (setIqRequestHandler) {
|
| 1503 |
+
return setIqRequestHandler.put(key, iqRequestHandler);
|
| 1504 |
+
}
|
| 1505 |
+
case get:
|
| 1506 |
+
synchronized (getIqRequestHandler) {
|
| 1507 |
+
return getIqRequestHandler.put(key, iqRequestHandler);
|
| 1508 |
+
}
|
| 1509 |
+
default:
|
| 1510 |
+
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
|
| 1511 |
+
}
|
| 1512 |
+
}
|
| 1513 |
+
|
| 1514 |
+
@Override
|
| 1515 |
+
public final IQRequestHandler unregisterIQRequestHandler(IQRequestHandler iqRequestHandler) {
|
| 1516 |
+
return unregisterIQRequestHandler(iqRequestHandler.getElement(), iqRequestHandler.getNamespace(),
|
| 1517 |
+
iqRequestHandler.getType());
|
| 1518 |
+
}
|
| 1519 |
+
|
| 1520 |
+
@Override
|
| 1521 |
+
public IQRequestHandler unregisterIQRequestHandler(String element, String namespace, IQ.Type type) {
|
| 1522 |
+
final String key = XmppStringUtils.generateKey(element, namespace);
|
| 1523 |
+
switch (type) {
|
| 1524 |
+
case set:
|
| 1525 |
+
synchronized (setIqRequestHandler) {
|
| 1526 |
+
return setIqRequestHandler.remove(key);
|
| 1527 |
+
}
|
| 1528 |
+
case get:
|
| 1529 |
+
synchronized (getIqRequestHandler) {
|
| 1530 |
+
return getIqRequestHandler.remove(key);
|
| 1531 |
+
}
|
| 1532 |
+
default:
|
| 1533 |
+
throw new IllegalArgumentException("Only IQ type of 'get' and 'set' allowed");
|
| 1534 |
+
}
|
| 1535 |
+
}
|
| 1536 |
+
|
| 1537 |
+
private long lastStanzaReceived;
|
| 1538 |
+
|
| 1539 |
+
public long getLastStanzaReceived() {
|
| 1540 |
+
return lastStanzaReceived;
|
| 1541 |
+
}
|
| 1542 |
+
|
| 1543 |
+
/**
|
| 1544 |
+
* Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a
|
| 1545 |
+
* stanza
|
| 1546 |
+
*
|
| 1547 |
+
* @param callback the callback to install
|
| 1548 |
+
*/
|
| 1549 |
+
public void setParsingExceptionCallback(ParsingExceptionCallback callback) {
|
| 1550 |
+
parsingExceptionCallback = callback;
|
| 1551 |
+
}
|
| 1552 |
+
|
| 1553 |
+
/**
|
| 1554 |
+
* Get the current active parsing exception callback.
|
| 1555 |
+
*
|
| 1556 |
+
* @return the active exception callback or null if there is none
|
| 1557 |
+
*/
|
| 1558 |
+
public ParsingExceptionCallback getParsingExceptionCallback() {
|
| 1559 |
+
return parsingExceptionCallback;
|
| 1560 |
+
}
|
| 1561 |
+
|
| 1562 |
+
protected final void asyncGo(Runnable runnable) {
|
| 1563 |
+
cachedExecutorService.execute(runnable);
|
| 1564 |
+
}
|
| 1565 |
+
|
| 1566 |
+
protected final ScheduledFuture<?> schedule(Runnable runnable, long delay, TimeUnit unit) {
|
| 1567 |
+
return removeCallbacksService.schedule(runnable, delay, unit);
|
| 1568 |
+
}
|
| 1569 |
+
}
|
Java/AdminAction.java
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* See the NOTICE file distributed with this work for additional
|
| 3 |
+
* information regarding copyright ownership.
|
| 4 |
+
*
|
| 5 |
+
* This is free software; you can redistribute it and/or modify it
|
| 6 |
+
* under the terms of the GNU Lesser General Public License as
|
| 7 |
+
* published by the Free Software Foundation; either version 2.1 of
|
| 8 |
+
* the License, or (at your option) any later version.
|
| 9 |
+
*
|
| 10 |
+
* This software is distributed in the hope that it will be useful,
|
| 11 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 |
+
* Lesser General Public License for more details.
|
| 14 |
+
*
|
| 15 |
+
* You should have received a copy of the GNU Lesser General Public
|
| 16 |
+
* License along with this software; if not, write to the Free
|
| 17 |
+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 18 |
+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
| 19 |
+
*/
|
| 20 |
+
package com.xpn.xwiki.web;
|
| 21 |
+
|
| 22 |
+
import javax.inject.Named;
|
| 23 |
+
import javax.inject.Singleton;
|
| 24 |
+
|
| 25 |
+
import org.slf4j.Logger;
|
| 26 |
+
import org.slf4j.LoggerFactory;
|
| 27 |
+
import org.xwiki.component.annotation.Component;
|
| 28 |
+
|
| 29 |
+
import com.xpn.xwiki.XWikiContext;
|
| 30 |
+
import com.xpn.xwiki.XWikiException;
|
| 31 |
+
import com.xpn.xwiki.doc.XWikiDocument;
|
| 32 |
+
import com.xpn.xwiki.doc.XWikiLock;
|
| 33 |
+
|
| 34 |
+
/**
|
| 35 |
+
* Administration xwiki action.
|
| 36 |
+
*
|
| 37 |
+
* @version $Id$
|
| 38 |
+
*/
|
| 39 |
+
@Component
|
| 40 |
+
@Named("admin")
|
| 41 |
+
@Singleton
|
| 42 |
+
public class AdminAction extends XWikiAction
|
| 43 |
+
{
|
| 44 |
+
/** The logger. */
|
| 45 |
+
private static final Logger LOGGER = LoggerFactory.getLogger(AdminAction.class);
|
| 46 |
+
|
| 47 |
+
/**
|
| 48 |
+
* Default constructor.
|
| 49 |
+
*/
|
| 50 |
+
public AdminAction()
|
| 51 |
+
{
|
| 52 |
+
this.waitForXWikiInitialization = false;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
@Override
|
| 56 |
+
protected Class<? extends XWikiForm> getFormClass()
|
| 57 |
+
{
|
| 58 |
+
return EditForm.class;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
@Override
|
| 62 |
+
public String render(XWikiContext context) throws XWikiException
|
| 63 |
+
{
|
| 64 |
+
XWikiRequest request = context.getRequest();
|
| 65 |
+
String content = request.getParameter("content");
|
| 66 |
+
XWikiDocument doc = context.getDoc();
|
| 67 |
+
XWikiForm form = context.getForm();
|
| 68 |
+
|
| 69 |
+
synchronized (doc) {
|
| 70 |
+
XWikiDocument tdoc = (XWikiDocument) context.get("tdoc");
|
| 71 |
+
EditForm peform = (EditForm) form;
|
| 72 |
+
String parent = peform.getParent();
|
| 73 |
+
if (parent != null) {
|
| 74 |
+
doc.setParent(parent);
|
| 75 |
+
}
|
| 76 |
+
String creator = peform.getCreator();
|
| 77 |
+
if (creator != null) {
|
| 78 |
+
doc.setCreator(creator);
|
| 79 |
+
}
|
| 80 |
+
String defaultTemplate = peform.getDefaultTemplate();
|
| 81 |
+
if (defaultTemplate != null) {
|
| 82 |
+
doc.setDefaultTemplate(defaultTemplate);
|
| 83 |
+
}
|
| 84 |
+
String defaultLanguage = peform.getDefaultLanguage();
|
| 85 |
+
if ((defaultLanguage != null) && !defaultLanguage.equals("")) {
|
| 86 |
+
doc.setDefaultLanguage(defaultLanguage);
|
| 87 |
+
}
|
| 88 |
+
if (doc.getDefaultLanguage().equals("")) {
|
| 89 |
+
doc.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
String language = context.getWiki().getLanguagePreference(context);
|
| 93 |
+
String languagefromrequest = context.getRequest().getParameter("language");
|
| 94 |
+
String languagetoedit =
|
| 95 |
+
((languagefromrequest == null) || (languagefromrequest.equals(""))) ? language : languagefromrequest;
|
| 96 |
+
|
| 97 |
+
if ((languagetoedit == null) || (languagetoedit.equals("default"))) {
|
| 98 |
+
languagetoedit = "";
|
| 99 |
+
}
|
| 100 |
+
if (doc.isNew() || (doc.getDefaultLanguage().equals(languagetoedit))) {
|
| 101 |
+
languagetoedit = "";
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
if (languagetoedit.equals("")) {
|
| 105 |
+
// In this case the created document is going to be the default document
|
| 106 |
+
tdoc = doc;
|
| 107 |
+
context.put("tdoc", doc);
|
| 108 |
+
if (doc.isNew()) {
|
| 109 |
+
doc.setDefaultLanguage(language);
|
| 110 |
+
doc.setLanguage("");
|
| 111 |
+
}
|
| 112 |
+
} else {
|
| 113 |
+
// If the translated doc object is the same as the doc object
|
| 114 |
+
// this means the translated doc did not exists so we need to create it
|
| 115 |
+
if ((tdoc == doc)) {
|
| 116 |
+
tdoc = new XWikiDocument(doc.getDocumentReference());
|
| 117 |
+
tdoc.setLanguage(languagetoedit);
|
| 118 |
+
tdoc.setContent(doc.getContent());
|
| 119 |
+
tdoc.setSyntax(doc.getSyntax());
|
| 120 |
+
tdoc.setAuthor(context.getUser());
|
| 121 |
+
tdoc.setStore(doc.getStore());
|
| 122 |
+
context.put("tdoc", tdoc);
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
XWikiDocument tdoc2 = tdoc.clone();
|
| 127 |
+
if (content != null && !content.isEmpty()) {
|
| 128 |
+
tdoc2.setContent(content);
|
| 129 |
+
}
|
| 130 |
+
context.put("tdoc", tdoc2);
|
| 131 |
+
try {
|
| 132 |
+
// BUG: CWE-862 Missing Authorization
|
| 133 |
+
// tdoc2.readFromTemplate(peform, context);
|
| 134 |
+
// FIXED:
|
| 135 |
+
readFromTemplate(tdoc2, peform.getTemplate(), context);
|
| 136 |
+
} catch (XWikiException e) {
|
| 137 |
+
if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) {
|
| 138 |
+
context.put("exception", e);
|
| 139 |
+
return "docalreadyexists";
|
| 140 |
+
}
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
/* Setup a lock */
|
| 144 |
+
try {
|
| 145 |
+
XWikiLock lock = tdoc.getLock(context);
|
| 146 |
+
if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) {
|
| 147 |
+
tdoc.setLock(context.getUser(), context);
|
| 148 |
+
}
|
| 149 |
+
} catch (Exception e) {
|
| 150 |
+
// Lock should never make XWiki fail
|
| 151 |
+
// But we should log any related information
|
| 152 |
+
LOGGER.error("Exception while setting up lock", e);
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
return "admin";
|
| 157 |
+
}
|
| 158 |
+
}
|
Java/AllTestsJunit4.java
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* OLAT - Online Learning and Training<br>
|
| 3 |
+
* http://www.olat.org
|
| 4 |
+
* <p>
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
|
| 6 |
+
* you may not use this file except in compliance with the License.<br>
|
| 7 |
+
* You may obtain a copy of the License at
|
| 8 |
+
* <p>
|
| 9 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
+
* <p>
|
| 11 |
+
* Unless required by applicable law or agreed to in writing,<br>
|
| 12 |
+
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
|
| 13 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
|
| 14 |
+
* See the License for the specific language governing permissions and <br>
|
| 15 |
+
* limitations under the License.
|
| 16 |
+
* <p>
|
| 17 |
+
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
|
| 18 |
+
* University of Zurich, Switzerland.
|
| 19 |
+
* <hr>
|
| 20 |
+
* <a href="http://www.openolat.org">
|
| 21 |
+
* OpenOLAT - Online Learning and Training</a><br>
|
| 22 |
+
* This file has been modified by the OpenOLAT community. Changes are licensed
|
| 23 |
+
* under the Apache 2.0 license as the original file.
|
| 24 |
+
* <p>
|
| 25 |
+
*/
|
| 26 |
+
package org.olat.test;
|
| 27 |
+
|
| 28 |
+
/**
|
| 29 |
+
* Description:<br>
|
| 30 |
+
* JUnit suite runner
|
| 31 |
+
* There are basically three types of tests:
|
| 32 |
+
*** Tests that extend from the olatTestCase (testcase loads a full olat before running the tests -- very slow and is an integration test)
|
| 33 |
+
*** Tests that load their own little spring context with @ContextConfiguration (that's how it should be done)
|
| 34 |
+
*** Tests that do not need any Spring context
|
| 35 |
+
* As tests with @ContextConfiguration can taint the context from olattestcase they must be placed on the end of the list!
|
| 36 |
+
* <P>
|
| 37 |
+
* Initial Date: 15.02.2010 <br>
|
| 38 |
+
* @author guido
|
| 39 |
+
*/
|
| 40 |
+
|
| 41 |
+
import org.junit.runner.RunWith;
|
| 42 |
+
import org.junit.runners.Suite;
|
| 43 |
+
|
| 44 |
+
@RunWith(Suite.class)
|
| 45 |
+
@Suite.SuiteClasses({
|
| 46 |
+
org.olat.core.util.i18n.I18nTest.class,
|
| 47 |
+
// org.olat.core.util.mail.MailTest.class, // redisabled since mails are sent despite the fact that the whitelist is enabled
|
| 48 |
+
org.olat.core.gui.components.table.MultiSelectColumnDescriptorTest.class,
|
| 49 |
+
org.olat.core.gui.components.table.TableEventTest.class,
|
| 50 |
+
org.olat.core.gui.components.table.TableMultiSelectEventTest.class,
|
| 51 |
+
org.olat.core.gui.components.table.SorterTest.class,
|
| 52 |
+
org.olat.core.commons.chiefcontrollers.ChiefControllerMessageEventTest.class,
|
| 53 |
+
org.olat.core.util.vfs.VFSTest.class,
|
| 54 |
+
org.olat.core.util.vfs.VFSManagerTest.class,
|
| 55 |
+
org.olat.core.util.filter.impl.XSSFilterParamTest.class,
|
| 56 |
+
org.olat.core.util.filter.impl.AddBaseURLToMediaRelativeURLFilterTest.class,
|
| 57 |
+
org.olat.core.util.filter.impl.SimpleHTMLTagsFilterTest.class,
|
| 58 |
+
org.olat.core.util.filter.impl.HtmlFilterTest.class,
|
| 59 |
+
org.olat.core.util.filter.impl.HtmlMathScannerTest.class,
|
| 60 |
+
org.olat.core.util.filter.impl.ConditionalHtmlCommentsFilterTest.class,
|
| 61 |
+
org.olat.core.util.filter.impl.XMLValidCharacterFilterTest.class,
|
| 62 |
+
org.olat.core.util.filter.impl.XMLValidEntityFilterTest.class,
|
| 63 |
+
org.olat.core.helpers.SettingsTest.class,
|
| 64 |
+
org.olat.core.util.coordinate.LockEntryTest.class,
|
| 65 |
+
org.olat.modules.iq.DBPersistentLockManagerTest.class,
|
| 66 |
+
org.olat.core.util.StringHelperTest.class,
|
| 67 |
+
org.olat.core.util.FileUtilsTest.class,
|
| 68 |
+
org.olat.core.util.FileNameSuffixFilterTest.class,
|
| 69 |
+
org.olat.core.util.FormatterTest.class,
|
| 70 |
+
org.olat.core.util.FormatLatexFormulasTest.class,
|
| 71 |
+
org.olat.core.util.FormatterHourAndSecondsTest.class,
|
| 72 |
+
org.olat.core.util.EncoderTest.class,
|
| 73 |
+
org.olat.core.util.SimpleHtmlParserTest.class,
|
| 74 |
+
org.olat.core.util.IPUtilsTest.class,
|
| 75 |
+
org.olat.core.util.IPUtilsValidRangeTest.class,
|
| 76 |
+
// BUG: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
|
| 77 |
+
//
|
| 78 |
+
// FIXED:
|
| 79 |
+
org.olat.core.util.ZipUtilTest.class,
|
| 80 |
+
org.olat.core.util.ZipUtilConcatTest.class,
|
| 81 |
+
org.olat.core.util.mail.EmailAddressValidatorTest.class,
|
| 82 |
+
org.olat.core.util.mail.manager.MailManagerTest.class,
|
| 83 |
+
org.olat.core.util.mail.manager.MailUserDataManagerTest.class,
|
| 84 |
+
org.olat.core.util.openxml.OpenXmlWorkbookTest.class,
|
| 85 |
+
org.olat.core.util.openxml.OpenXMLDocumentTest.class,
|
| 86 |
+
org.olat.core.util.pdf.PdfDocumentTest.class,
|
| 87 |
+
org.olat.core.util.xml.XMLDigitalSignatureUtilTest.class,
|
| 88 |
+
org.olat.core.util.xml.XStreamHelperTest.class,
|
| 89 |
+
org.olat.core.configuration.EDConfigurationTest.class,
|
| 90 |
+
org.olat.core.id.context.BusinessControlFactoryTest.class,
|
| 91 |
+
org.olat.core.id.context.HistoryManagerTest.class,
|
| 92 |
+
org.olat.core.id.IdentityEnvironmentTest.class,
|
| 93 |
+
org.olat.core.gui.render.VelocityTemplateTest.class,
|
| 94 |
+
org.olat.core.gui.control.generic.iframe.IFrameDeliveryMapperTest.class,
|
| 95 |
+
org.olat.note.NoteTest.class,
|
| 96 |
+
org.olat.user.UserTest.class,
|
| 97 |
+
org.olat.user.UserPropertiesTest.class,
|
| 98 |
+
org.olat.commons.calendar.CalendarImportTest.class,
|
| 99 |
+
org.olat.commons.calendar.CalendarUtilsTest.class,
|
| 100 |
+
org.olat.commons.calendar.manager.ImportedCalendarDAOTest.class,
|
| 101 |
+
org.olat.commons.calendar.manager.ImportedToCalendarDAOTest.class,
|
| 102 |
+
org.olat.commons.calendar.manager.ICalFileCalendarManagerTest.class,
|
| 103 |
+
org.olat.commons.calendar.manager.CalendarUserConfigurationDAOTest.class,
|
| 104 |
+
org.olat.commons.lifecycle.LifeCycleManagerTest.class,
|
| 105 |
+
org.olat.commons.coordinate.cluster.jms.JMSTest.class,
|
| 106 |
+
org.olat.commons.coordinate.cluster.lock.LockTest.class,
|
| 107 |
+
org.olat.commons.coordinate.CoordinatorTest.class,
|
| 108 |
+
org.olat.core.commons.modules.glossary.GlossaryItemManagerTest.class,
|
| 109 |
+
org.olat.core.commons.services.csp.manager.CSPManagerTest.class,
|
| 110 |
+
org.olat.core.commons.services.doceditor.manager.DocEditorIdentityServiceTest.class,
|
| 111 |
+
org.olat.core.commons.services.doceditor.manager.AccessDAOTest.class,
|
| 112 |
+
org.olat.core.commons.services.vfs.manager.VFSXStreamTest.class,
|
| 113 |
+
org.olat.core.commons.services.vfs.manager.VFSMetadataDAOTest.class,
|
| 114 |
+
org.olat.core.commons.services.vfs.manager.VFSRevisionDAOTest.class,
|
| 115 |
+
org.olat.core.commons.services.vfs.manager.VFSStatsDAOTest.class,
|
| 116 |
+
org.olat.core.commons.services.vfs.manager.VFSThumbnailDAOTest.class,
|
| 117 |
+
org.olat.core.commons.services.vfs.manager.VFSRepositoryServiceTest.class,
|
| 118 |
+
org.olat.core.commons.services.vfs.manager.VFSRepositoryModuleTest.class,
|
| 119 |
+
org.olat.core.commons.services.vfs.manager.VFSLockManagerTest.class,
|
| 120 |
+
org.olat.core.commons.services.vfs.manager.VFSVersioningTest.class,
|
| 121 |
+
org.olat.core.commons.services.help.ConfluenceHelperTest.class,
|
| 122 |
+
org.olat.core.commons.services.help.spi.ConfluenceLinkSPITest.class,
|
| 123 |
+
org.olat.core.commons.services.license.manager.LicenseTypeActivationDAOTest.class,
|
| 124 |
+
org.olat.core.commons.services.license.manager.LicenseTypeDAOTest.class,
|
| 125 |
+
org.olat.core.commons.services.license.manager.ResourceLicenseDAOTest.class,
|
| 126 |
+
org.olat.core.commons.services.webdav.WebDAVCommandsTest.class,
|
| 127 |
+
org.olat.core.commons.services.webdav.manager.DigestAuthenticationTest.class,
|
| 128 |
+
org.olat.core.commons.services.webdav.manager.WebDAVManagerTest.class,
|
| 129 |
+
org.olat.core.commons.services.webdav.manager.WebDAVAuthManagerTest.class,
|
| 130 |
+
org.olat.core.commons.services.webdav.servlets.RequestUtilsTest.class,
|
| 131 |
+
org.olat.core.commons.services.sms.manager.MessageLogDAOTest.class,
|
| 132 |
+
org.olat.core.commons.services.taskexecutor.manager.PersistentTaskDAOTest.class,
|
| 133 |
+
org.olat.core.commons.services.taskexecutor.manager.TaskExecutorManagerTest.class,
|
| 134 |
+
org.olat.core.commons.services.text.TextServiceTest.class,
|
| 135 |
+
org.olat.group.BusinessGroupManagedFlagsTest.class,
|
| 136 |
+
org.olat.group.test.BGRightManagerTest.class,
|
| 137 |
+
org.olat.group.test.BGAreaManagerTest.class,
|
| 138 |
+
org.olat.group.test.BusinessGroupServiceTest.class,
|
| 139 |
+
org.olat.group.test.BusinessGroupDAOTest.class,
|
| 140 |
+
org.olat.group.test.BusinessGroupRelationDAOTest.class,
|
| 141 |
+
org.olat.group.test.BusinessGroupConcurrentTest.class,
|
| 142 |
+
org.olat.group.test.ContactDAOTest.class,
|
| 143 |
+
org.olat.group.test.BusinessGroupMembershipProcessorTest.class,
|
| 144 |
+
org.olat.fileresource.FileResourceTest.class,
|
| 145 |
+
org.olat.resource.lock.pessimistic.PLockTest.class,
|
| 146 |
+
org.olat.resource.references.ReferenceManagerTest.class,
|
| 147 |
+
org.olat.resource.OLATResourceManagerTest.class,
|
| 148 |
+
org.olat.basesecurity.manager.AuthenticationDAOTest.class,
|
| 149 |
+
org.olat.basesecurity.manager.AuthenticationHistoryDAOTest.class,
|
| 150 |
+
org.olat.basesecurity.manager.GroupDAOTest.class,
|
| 151 |
+
org.olat.basesecurity.manager.IdentityDAOTest.class,
|
| 152 |
+
org.olat.basesecurity.manager.RelationRightDAOTest.class,
|
| 153 |
+
org.olat.basesecurity.manager.RelationRoleDAOTest.class,
|
| 154 |
+
org.olat.basesecurity.manager.IdentityToIdentityRelationDAOTest.class,
|
| 155 |
+
org.olat.basesecurity.GetIdentitiesByPowerSearchTest.class,
|
| 156 |
+
org.olat.basesecurity.BaseSecurityManagerTest.class,
|
| 157 |
+
org.olat.user.UserDAOTest.class,
|
| 158 |
+
org.olat.user.UserManagerTest.class,
|
| 159 |
+
org.olat.user.manager.UserDataExportDAOTest.class,
|
| 160 |
+
org.olat.user.manager.UserDataExportServiceTest.class,
|
| 161 |
+
org.olat.user.manager.AbsenceLeaveDAOTest.class,
|
| 162 |
+
org.olat.user.manager.lifecycle.UserLifecycleManagerTest.class,
|
| 163 |
+
org.olat.repository.manager.AutomaticLifecycleServiceTest.class,
|
| 164 |
+
org.olat.repository.ui.catalog.CatalogManagerTest.class,
|
| 165 |
+
org.olat.repository.manager.RepositoryEntryDAOTest.class,
|
| 166 |
+
org.olat.repository.manager.RepositoryEntryLifecycleDAOTest.class,
|
| 167 |
+
org.olat.repository.manager.RepositoryEntryRelationDAOTest.class,
|
| 168 |
+
org.olat.repository.manager.RepositoryServiceImplTest.class,
|
| 169 |
+
org.olat.repository.manager.RepositoryEntryStatisticsDAOTest.class,
|
| 170 |
+
org.olat.repository.manager.RepositoryEntryAuthorQueriesTest.class,
|
| 171 |
+
org.olat.repository.manager.RepositoryEntryMyCourseQueriesTest.class,
|
| 172 |
+
org.olat.repository.manager.RepositoryEntryMembershipProcessorTest.class,
|
| 173 |
+
org.olat.repository.manager.RepositoryEntryToOrganisationDAOTest.class,
|
| 174 |
+
org.olat.repository.manager.RepositoryEntryToTaxonomyLevelDAOTest.class,
|
| 175 |
+
org.olat.repository.manager.RepositoryEntryQueriesTest.class,
|
| 176 |
+
org.olat.repository.RepositoryManagerTest.class,
|
| 177 |
+
org.olat.instantMessaging.InstantMessageDAOTest.class,
|
| 178 |
+
org.olat.instantMessaging.InstantMessagePreferencesDAOTest.class,
|
| 179 |
+
org.olat.instantMessaging.RosterDAOTest.class,
|
| 180 |
+
org.olat.instantMessaging.InstantMessageServiceTest.class,
|
| 181 |
+
org.olat.course.archiver.FormatConfigHelperTest.class,
|
| 182 |
+
org.olat.course.condition.ConditionTest.class,
|
| 183 |
+
org.olat.course.condition.GetPassedTest.class,
|
| 184 |
+
org.olat.course.condition.KeyAndNameConverterTest.class,
|
| 185 |
+
org.olat.course.disclaimer.CourseDisclaimerManagerTest.class,
|
| 186 |
+
org.olat.course.highscore.HighScoreManagerTest.class,
|
| 187 |
+
org.olat.course.learningpath.LearningPathServiceTest.class,
|
| 188 |
+
org.olat.course.nodes.dialog.manager.DialogElementsManagerTest.class,
|
| 189 |
+
org.olat.course.nodes.en.EnrollmentManagerSerialTest.class,
|
| 190 |
+
org.olat.course.nodes.en.EnrollmentManagerConcurrentTest.class,
|
| 191 |
+
org.olat.course.nodes.gta.manager.GTAManagerTest.class,
|
| 192 |
+
org.olat.course.nodes.gta.manager.GTATaskRevisionDAOTest.class,
|
| 193 |
+
org.olat.course.nodes.gta.manager.GTAIdentityMarkDAOTest.class,
|
| 194 |
+
org.olat.course.nodes.gta.rule.GTAReminderRuleTest.class,
|
| 195 |
+
org.olat.course.nodes.livestream.manager.LaunchDAOTest.class,
|
| 196 |
+
org.olat.course.nodes.livestream.manager.UrlTemplateDAOTest.class,
|
| 197 |
+
org.olat.course.nodes.members.manager.MembersManagerTest.class,
|
| 198 |
+
org.olat.course.nodes.pf.manager.PFManagerTest.class,
|
| 199 |
+
org.olat.course.assessment.AssessmentManagerTest.class,
|
| 200 |
+
org.olat.course.assessment.manager.UserCourseInformationsManagerTest.class,
|
| 201 |
+
org.olat.course.assessment.manager.AssessmentModeManagerTest.class,
|
| 202 |
+
org.olat.course.reminder.manager.ReminderRuleDAOTest.class,
|
| 203 |
+
org.olat.course.run.scoring.AssessmentAccountingTest.class,
|
| 204 |
+
org.olat.course.statistic.DailyStatisticUpdateManagerTest.class,
|
| 205 |
+
org.olat.course.statistic.DayOfWeekStatisticUpdateManagerTest.class,
|
| 206 |
+
org.olat.course.statistic.HourOfDayStatisticUpdateManagerTest.class,
|
| 207 |
+
// org.olat.course.statistic.WeeklyStatisticUpdateManagerTest.class,
|
| 208 |
+
org.olat.modules.assessment.manager.AssessmentEntryDAOTest.class,
|
| 209 |
+
org.olat.course.certificate.manager.CertificatesManagerTest.class,
|
| 210 |
+
org.olat.course.config.CourseConfigManagerImplTest.class,
|
| 211 |
+
org.olat.course.groupsandrights.CourseGroupManagementTest.class,
|
| 212 |
+
org.olat.course.editor.PublishProcessTest.class,
|
| 213 |
+
org.olat.course.CourseXStreamAliasesTest.class,
|
| 214 |
+
org.olat.modules.adobeconnect.manager.AdobeConnectProviderTest.class,
|
| 215 |
+
org.olat.modules.adobeconnect.manager.AdobeConnectUserDAOTest.class,
|
| 216 |
+
org.olat.modules.adobeconnect.manager.AdobeConnectMeetingDAOTest.class,
|
| 217 |
+
org.olat.modules.adobeconnect.manager.AdobeConnectUtilsTest.class,
|
| 218 |
+
org.olat.modules.appointments.AppointmentsServiceTest.class,
|
| 219 |
+
org.olat.modules.appointments.manager.AppointmentDAOTest.class,
|
| 220 |
+
org.olat.modules.appointments.manager.OrganizerDAOTest.class,
|
| 221 |
+
org.olat.modules.appointments.manager.ParticipationDAOTest.class,
|
| 222 |
+
org.olat.modules.appointments.manager.TopicDAOTest.class,
|
| 223 |
+
org.olat.modules.appointments.manager.TopicToGroupDAOTest.class,
|
| 224 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonServerDAOTest.class,
|
| 225 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonMeetingDAOTest.class,
|
| 226 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonAttendeeDAOTest.class,
|
| 227 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonMeetingTemplateDAOTest.class,
|
| 228 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonRecordingReferenceDAOTest.class,
|
| 229 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonUriBuilderTest.class,
|
| 230 |
+
org.olat.modules.bigbluebutton.manager.BigBlueButtonManagerTest.class,
|
| 231 |
+
org.olat.modules.contacttracing.manager.ContactTracingLocationDAOTest.class,
|
| 232 |
+
org.olat.modules.contacttracing.manager.ContactTracingRegistrationDAOTest.class,
|
| 233 |
+
org.olat.modules.dcompensation.manager.DisadvantageCompensationDAOTest.class,
|
| 234 |
+
org.olat.modules.dcompensation.manager.DisadvantageCompensationAuditLogDAOTest.class,
|
| 235 |
+
org.olat.modules.iq.IQManagerTest.class,
|
| 236 |
+
org.olat.modules.fo.ForumManagerTest.class,//fail
|
| 237 |
+
org.olat.modules.wiki.WikiUnitTest.class,
|
| 238 |
+
org.olat.modules.wiki.versioning.diff.CookbookDiffTest.class,
|
| 239 |
+
org.olat.modules.wiki.gui.components.wikiToHtml.FilterUtilTest.class,
|
| 240 |
+
org.olat.modules.coach.manager.CoachingDAOTest.class,
|
| 241 |
+
org.olat.modules.coach.CoachingLargeTest.class,
|
| 242 |
+
org.olat.modules.curriculum.manager.CurriculumDAOTest.class,
|
| 243 |
+
org.olat.modules.curriculum.manager.CurriculumMemberQueriesTest.class,
|
| 244 |
+
org.olat.modules.curriculum.manager.CurriculumElementDAOTest.class,
|
| 245 |
+
org.olat.modules.curriculum.manager.CurriculumElementTypeDAOTest.class,
|
| 246 |
+
org.olat.modules.curriculum.manager.CurriculumRepositoryEntryRelationDAOTest.class,
|
| 247 |
+
org.olat.modules.curriculum.manager.CurriculumElementToTaxonomyLevelDAOTest.class,
|
| 248 |
+
org.olat.modules.curriculum.manager.CurriculumServiceTest.class,
|
| 249 |
+
org.olat.modules.docpool.manager.DocumentPoolManagerTest.class,
|
| 250 |
+
org.olat.modules.forms.manager.EvaluationFormParticipationDAOTest.class,
|
| 251 |
+
org.olat.modules.forms.manager.EvaluationFormReportDAOTest.class,
|
| 252 |
+
org.olat.modules.forms.manager.EvaluationFormResponseDAOTest.class,
|
| 253 |
+
org.olat.modules.forms.manager.EvaluationFormSessionDAOTest.class,
|
| 254 |
+
org.olat.modules.forms.manager.EvaluationFormStorageTest.class,
|
| 255 |
+
org.olat.modules.forms.manager.EvaluationFormSurveyDAOTest.class,
|
| 256 |
+
org.olat.modules.forms.model.jpa.SurveysFilterTest.class,
|
| 257 |
+
org.olat.modules.gotomeeting.manager.GoToJsonUtilTest.class,
|
| 258 |
+
org.olat.modules.gotomeeting.manager.GoToMeetingDAOTest.class,
|
| 259 |
+
org.olat.modules.gotomeeting.manager.GoToOrganizerDAOTest.class,
|
| 260 |
+
org.olat.modules.gotomeeting.manager.GoToRegistrantDAOTest.class,
|
| 261 |
+
org.olat.modules.gotomeeting.GoToTimezoneIDsTest.class,
|
| 262 |
+
org.olat.modules.grading.manager.GraderToIdentityDAOTest.class,
|
| 263 |
+
org.olat.modules.grading.manager.GradingAssignmentDAOTest.class,
|
| 264 |
+
org.olat.modules.grading.manager.GradingConfigurationDAOTest.class,
|
| 265 |
+
org.olat.modules.grading.manager.GradingTimeRecordDAOTest.class,
|
| 266 |
+
org.olat.modules.grading.manager.GradingServiceTest.class,
|
| 267 |
+
org.olat.basesecurity.manager.OrganisationDAOTest.class,
|
| 268 |
+
org.olat.basesecurity.manager.OrganisationTypeDAOTest.class,
|
| 269 |
+
org.olat.basesecurity.manager.OrganisationTypeToTypeDAOTest.class,
|
| 270 |
+
org.olat.basesecurity.manager.OrganisationServiceTest.class,
|
| 271 |
+
org.olat.basesecurity.manager.SecurityGroupDAOTest.class,
|
| 272 |
+
org.olat.modules.ceditor.ContentEditorXStreamTest.class,
|
| 273 |
+
org.olat.modules.ceditor.model.ContainerSettingsTest.class,
|
| 274 |
+
org.olat.modules.edusharing.manager.EdusharingUsageDAOTest.class,
|
| 275 |
+
org.olat.modules.portfolio.manager.BinderDAOTest.class,
|
| 276 |
+
org.olat.modules.portfolio.manager.CategoryDAOTest.class,
|
| 277 |
+
org.olat.modules.portfolio.manager.MediaDAOTest.class,
|
| 278 |
+
org.olat.modules.portfolio.manager.PageDAOTest.class,
|
| 279 |
+
org.olat.modules.portfolio.manager.AssignmentDAOTest.class,
|
| 280 |
+
org.olat.modules.portfolio.manager.SharedByMeQueriesTest.class,
|
| 281 |
+
org.olat.modules.portfolio.manager.SharedWithMeQueriesTest.class,
|
| 282 |
+
org.olat.modules.portfolio.manager.PortfolioServiceTest.class,
|
| 283 |
+
org.olat.modules.portfolio.manager.BinderUserInformationsDAOTest.class,
|
| 284 |
+
org.olat.modules.portfolio.manager.InvitationDAOTest.class,
|
| 285 |
+
org.olat.modules.quality.analysis.manager.AnalysisFilterDAOTest.class,
|
| 286 |
+
org.olat.modules.quality.analysis.manager.AnalysisPresentationDAOTest.class,
|
| 287 |
+
org.olat.modules.quality.analysis.manager.EvaluationFormDAOTest.class,
|
| 288 |
+
org.olat.modules.quality.generator.manager.QualityGeneratorDAOTest.class,
|
| 289 |
+
org.olat.modules.quality.generator.manager.QualityGeneratorConfigDAOTest.class,
|
| 290 |
+
org.olat.modules.quality.generator.manager.titlecreator.CurriculumElementHandlerTest.class,
|
| 291 |
+
org.olat.modules.quality.generator.manager.titlecreator.RepositoryEntryHandlerTest.class,
|
| 292 |
+
org.olat.modules.quality.generator.manager.titlecreator.UserHandlerTest.class,
|
| 293 |
+
org.olat.modules.quality.generator.provider.course.manager.CourseProviderDAOTest.class,
|
| 294 |
+
org.olat.modules.quality.generator.provider.course.CourseProviderTest.class,
|
| 295 |
+
org.olat.modules.quality.generator.provider.courselectures.manager.CourseLecturesProviderDAOTest.class,
|
| 296 |
+
org.olat.modules.quality.generator.provider.courselectures.CourseLecturesProviderTest.class,
|
| 297 |
+
org.olat.modules.quality.generator.provider.curriculumelement.manager.CurriculumElementProviderDAOTest.class,
|
| 298 |
+
org.olat.modules.quality.generator.provider.curriculumelement.CurriculumElementProviderTest.class,
|
| 299 |
+
org.olat.modules.quality.manager.AudiencelessQualityContextBuilderTest.class,
|
| 300 |
+
org.olat.modules.quality.manager.CurriculumElementQualityContextBuilderTest.class,
|
| 301 |
+
org.olat.modules.quality.manager.DefaultQualityContextBuilderTest.class,
|
| 302 |
+
org.olat.modules.quality.manager.QualityContextDAOTest.class,
|
| 303 |
+
org.olat.modules.quality.manager.QualityContextToCurriculumDAOTest.class,
|
| 304 |
+
org.olat.modules.quality.manager.QualityContextToCurriculumElementDAOTest.class,
|
| 305 |
+
org.olat.modules.quality.manager.QualityContextToOrganisationDAOTest.class,
|
| 306 |
+
org.olat.modules.quality.manager.QualityContextToTaxonomyLevelDAOTest.class,
|
| 307 |
+
org.olat.modules.quality.manager.QualityDataCollectionDAOTest.class,
|
| 308 |
+
org.olat.modules.quality.manager.QualityParticipationDAOTest.class,
|
| 309 |
+
org.olat.modules.quality.manager.QualityReminderDAOTest.class,
|
| 310 |
+
org.olat.modules.quality.manager.QualityReportAccessDAOTest.class,
|
| 311 |
+
org.olat.modules.quality.manager.RepositoryEntryQualityContextBuilderTest.class,
|
| 312 |
+
org.olat.modules.lecture.manager.AbsenceCategoryDAOTest.class,
|
| 313 |
+
org.olat.modules.lecture.manager.AbsenceNoticeDAOTest.class,
|
| 314 |
+
org.olat.modules.lecture.manager.AbsenceNoticeToLectureBlockDAOTest.class,
|
| 315 |
+
org.olat.modules.lecture.manager.AbsenceNoticeToRepositoryEntryDAOTest.class,
|
| 316 |
+
org.olat.modules.lecture.manager.LectureBlockDAOTest.class,
|
| 317 |
+
org.olat.modules.lecture.manager.LectureBlockRollCallDAOTest.class,
|
| 318 |
+
org.olat.modules.lecture.manager.LectureBlockToTaxonomyLevelDAOTest.class,
|
| 319 |
+
org.olat.modules.lecture.manager.LectureParticipantSummaryDAOTest.class,
|
| 320 |
+
org.olat.modules.lecture.manager.LectureServiceTest.class,
|
| 321 |
+
org.olat.modules.lecture.manager.ReasonDAOTest.class,
|
| 322 |
+
org.olat.modules.lecture.manager.LectureBlockReminderDAOTest.class,
|
| 323 |
+
org.olat.modules.lecture.manager.RepositoryEntryLectureConfigurationDAOTest.class,
|
| 324 |
+
org.olat.modules.lecture.manager.LectureBlockAuditLogDAOTest.class,
|
| 325 |
+
org.olat.modules.lecture.ui.blockimport.BlockConverterTest.class,
|
| 326 |
+
org.olat.modules.lecture.ui.ParticipantLecturesOverviewControllerTest.class,
|
| 327 |
+
org.olat.modules.reminder.ReminderModuleTest.class,
|
| 328 |
+
org.olat.modules.reminder.manager.ReminderDAOTest.class,
|
| 329 |
+
org.olat.modules.reminder.manager.ReminderRuleEngineTest.class,
|
| 330 |
+
org.olat.modules.reminder.manager.ReminderRulesXStreamTest.class,
|
| 331 |
+
org.olat.modules.taxonomy.manager.TaxonomyDAOTest.class,
|
| 332 |
+
org.olat.modules.taxonomy.manager.TaxonomyLevelDAOTest.class,
|
| 333 |
+
org.olat.modules.taxonomy.manager.TaxonomyLevelTypeDAOTest.class,
|
| 334 |
+
org.olat.modules.taxonomy.manager.TaxonomyCompetenceDAOTest.class,
|
| 335 |
+
org.olat.modules.taxonomy.manager.TaxonomyCompetenceAuditLogDAOTest.class,
|
| 336 |
+
org.olat.modules.video.VideoFormatTest.class,
|
| 337 |
+
org.olat.modules.video.manager.VideoTranscodingDAOTest.class,
|
| 338 |
+
org.olat.modules.video.manager.VideoMetadataDAOTest.class,
|
| 339 |
+
org.olat.modules.video.manager.VideoXStreamTest.class,
|
| 340 |
+
org.olat.modules.video.manager.VideoMetaXStreamTest.class,
|
| 341 |
+
org.olat.modules.video.manager.VideoManagerTest.class,
|
| 342 |
+
org.olat.modules.video.spi.youtube.YoutubeProviderTest.class,
|
| 343 |
+
org.olat.modules.video.spi.youtube.YoutubeVideoIdTest.class,
|
| 344 |
+
org.olat.modules.webFeed.dispatching.PathTest.class,
|
| 345 |
+
org.olat.modules.webFeed.manager.FeedDAOTest.class,
|
| 346 |
+
org.olat.modules.webFeed.manager.ItemDAOTest.class,
|
| 347 |
+
org.olat.modules.webFeed.manager.FeedFileStorgeTest.class,
|
| 348 |
+
org.olat.properties.PropertyTest.class,
|
| 349 |
+
org.olat.search.service.document.file.FileDocumentFactoryTest.class,
|
| 350 |
+
org.olat.search.service.indexer.repository.course.SPCourseNodeIndexerTest.class,
|
| 351 |
+
org.olat.search.service.document.file.HtmlDocumentTest.class,
|
| 352 |
+
org.olat.search.service.document.file.PDFDocumentTest.class,
|
| 353 |
+
org.olat.search.service.document.file.OfficeDocumentTest.class,
|
| 354 |
+
org.olat.core.commons.services.notifications.manager.NotificationsManagerTest.class,
|
| 355 |
+
org.olat.registration.RegistrationManagerTest.class,
|
| 356 |
+
org.olat.course.nodes.projectbroker.ProjectBrokerManagerTest.class,
|
| 357 |
+
org.olat.core.commons.persistence.DBTest.class,
|
| 358 |
+
org.olat.modules.ims.cp.CPManagerTest.class,
|
| 359 |
+
org.olat.modules.ims.qti.fileresource.FileResourceValidatorTest.class,
|
| 360 |
+
org.olat.ims.qti.QTIResultManagerTest.class,
|
| 361 |
+
org.olat.ims.qti.qpool.QTIImportProcessorTest.class,
|
| 362 |
+
org.olat.ims.qti.qpool.QTIExportProcessorTest.class,
|
| 363 |
+
org.olat.ims.qti.qpool.ItemFileResourceValidatorTest.class,
|
| 364 |
+
org.olat.ims.qti.questionimport.CSVToQuestionConverterTest.class,
|
| 365 |
+
org.olat.ims.qti.statistics.manager.QTIStatisticsManagerLargeTest.class,
|
| 366 |
+
org.olat.ims.qti.statistics.manager.QTIStatisticsManagerTest.class,
|
| 367 |
+
org.olat.ims.qti.statistics.manager.StatisticsTest.class,
|
| 368 |
+
org.olat.ims.qti21.manager.AssessmentTestSessionDAOTest.class,
|
| 369 |
+
org.olat.ims.qti21.manager.AssessmentItemSessionDAOTest.class,
|
| 370 |
+
org.olat.ims.qti21.manager.AssessmentResponseDAOTest.class,
|
| 371 |
+
org.olat.ims.qti21.manager.CorrectResponsesUtilTest.class,
|
| 372 |
+
org.olat.ims.qti21.model.xml.AssessmentItemBuilderTest.class,
|
| 373 |
+
org.olat.ims.qti21.model.xml.MultipleChoiceAssessmentItemBuilderTest.class,
|
| 374 |
+
org.olat.ims.qti21.model.xml.SingleChoiceAssessmentItemBuilderTest.class,
|
| 375 |
+
org.olat.ims.qti21.model.xml.TestFeedbackBuilderTest.class,
|
| 376 |
+
org.olat.ims.qti21.model.xml.HottextAssessmentItemBuilderTest.class,
|
| 377 |
+
org.olat.ims.qti21.model.xml.OrderAssessmentItemBuilderTest.class,
|
| 378 |
+
org.olat.ims.qti21.model.xml.FIBAssessmentItemBuilderTest.class,
|
| 379 |
+
org.olat.ims.qti21.model.xml.AssessmentHtmlBuilderTest.class,
|
| 380 |
+
org.olat.ims.qti21.model.xml.AssessmentItemPackageTest.class,
|
| 381 |
+
org.olat.ims.qti21.model.xml.ManifestPackageTest.class,
|
| 382 |
+
org.olat.ims.qti21.pool.QTI12To21ConverterTest.class,
|
| 383 |
+
org.olat.ims.qti21.pool.QTI12To21HtmlHandlerTest.class,
|
| 384 |
+
org.olat.ims.qti21.pool.QTI21QPoolServiceProviderTest.class,
|
| 385 |
+
org.olat.ims.qti21.repository.handlers.QTI21AssessmentTestHandlerTest.class,
|
| 386 |
+
org.olat.ims.qti21.statistics.TextEntryInteractionStatisticsTest.class,
|
| 387 |
+
org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksAssessementItemsTest.class,
|
| 388 |
+
org.olat.ims.qti21.model.xml.OnyxToQtiWorksAssessementItemsTest.class,
|
| 389 |
+
org.olat.ims.qti21.model.xml.OnyxToQtiWorksAssessementTestsTest.class,
|
| 390 |
+
org.olat.ims.qti21.model.xml.OnyxToAssessmentItemBuilderTest.class,
|
| 391 |
+
org.olat.ims.qti21.model.xml.OpenOLATAssessementItemsTest.class,
|
| 392 |
+
org.olat.ims.qti21.model.xml.QTI21ExplorerHandlerTest.class,
|
| 393 |
+
org.olat.ims.qti21.ui.components.AssessmentRenderFunctionsTest.class,
|
| 394 |
+
org.olat.ims.qti21.questionimport.CSVToAssessmentItemConverterTest.class,
|
| 395 |
+
org.olat.ims.lti.LTIManagerTest.class,
|
| 396 |
+
org.olat.modules.qpool.manager.MetadataConverterHelperTest.class,
|
| 397 |
+
org.olat.modules.qpool.manager.QuestionDAOTest.class,
|
| 398 |
+
org.olat.modules.qpool.manager.FileStorageTest.class,
|
| 399 |
+
org.olat.modules.qpool.manager.CollectionDAOTest.class,
|
| 400 |
+
org.olat.modules.qpool.manager.QLicenseDAOTest.class,
|
| 401 |
+
org.olat.modules.qpool.manager.QItemTypeDAOTest.class,
|
| 402 |
+
org.olat.modules.qpool.manager.QEducationalContextDAOTest.class,
|
| 403 |
+
org.olat.modules.qpool.manager.PoolDAOTest.class,
|
| 404 |
+
org.olat.modules.qpool.manager.QItemQueriesDAOTest.class,
|
| 405 |
+
org.olat.modules.qpool.manager.QuestionPoolServiceTest.class,
|
| 406 |
+
org.olat.modules.qpool.manager.QuestionItemAuditLogDAOTest.class,
|
| 407 |
+
org.olat.login.oauth.OAuthDispatcherTest.class,
|
| 408 |
+
org.olat.ldap.LDAPLoginTest.class,
|
| 409 |
+
org.olat.ldap.manager.LDAPLoginManagerTest.class,
|
| 410 |
+
org.olat.core.commons.services.mark.MarksTest.class,
|
| 411 |
+
org.olat.test.SpringInitDestroyVerficationTest.class,
|
| 412 |
+
//org.olat.course.statistic.weekly.TestWeeklyStatisticManager_fillGaps.class, don't know what it tests
|
| 413 |
+
org.olat.core.commons.services.commentAndRating.manager.UserCommentsDAOTest.class,
|
| 414 |
+
org.olat.core.commons.services.commentAndRating.manager.UserRatingsDAOTest.class,
|
| 415 |
+
org.olat.course.auditing.UserNodeAuditManagerTest.class,
|
| 416 |
+
org.olat.shibboleth.handler.SpringShibbolethAttributeHandlerFactoryTest.class,
|
| 417 |
+
org.olat.core.CoreSpringFactoryTest.class,
|
| 418 |
+
org.olat.modules.openmeetings.OpenMeetingsTest.class,
|
| 419 |
+
org.olat.modules.openmeetings.manager.OpenMeetingsDAOTest.class,
|
| 420 |
+
org.olat.commons.info.InfoManagerTest.class,
|
| 421 |
+
org.olat.core.commons.services.tagging.SimpleTagProposalManagerTest.class,
|
| 422 |
+
org.olat.core.commons.services.tagging.TaggingManagerTest.class,
|
| 423 |
+
org.olat.core.dispatcher.mapper.MapperDAOTest.class,
|
| 424 |
+
org.olat.core.dispatcher.mapper.MapperServiceTest.class,
|
| 425 |
+
org.olat.restapi.AuthenticationTest.class,
|
| 426 |
+
org.olat.restapi.BigBlueButtonStatsWebServiceTest.class,
|
| 427 |
+
org.olat.restapi.BigBlueButtonServerWebServiceTest.class,
|
| 428 |
+
org.olat.restapi.BigBlueButtonTemplatesWebServiceTest.class,
|
| 429 |
+
org.olat.restapi.CatalogTest.class,
|
| 430 |
+
org.olat.restapi.CalendarTest.class,
|
| 431 |
+
org.olat.restapi.CertificationTest.class,
|
| 432 |
+
org.olat.restapi.CourseGroupMgmtTest.class,
|
| 433 |
+
org.olat.restapi.CourseCalendarTest.class,
|
| 434 |
+
org.olat.restapi.CourseDBTest.class,
|
| 435 |
+
org.olat.restapi.CoursesContactElementTest.class,
|
| 436 |
+
org.olat.restapi.CourseSecurityTest.class,
|
| 437 |
+
org.olat.restapi.CoursesElementsTest.class,
|
| 438 |
+
org.olat.restapi.CoursesFoldersTest.class,
|
| 439 |
+
org.olat.restapi.CoursesForumsTest.class,
|
| 440 |
+
org.olat.restapi.CoursesResourcesFoldersTest.class,
|
| 441 |
+
org.olat.restapi.CoursesTest.class,
|
| 442 |
+
org.olat.restapi.CoursePublishTest.class,
|
| 443 |
+
org.olat.restapi.CoursesInfosTest.class,
|
| 444 |
+
org.olat.restapi.CourseTest.class,
|
| 445 |
+
org.olat.restapi.CurriculumsWebServiceTest.class,
|
| 446 |
+
org.olat.restapi.CurriculumElementsWebServiceTest.class,
|
| 447 |
+
org.olat.restapi.CurriculumElementTypesWebServiceTest.class,
|
| 448 |
+
org.olat.restapi.DocEditorWebServiceTest.class,
|
| 449 |
+
org.olat.restapi.EfficiencyStatementTest.class,
|
| 450 |
+
org.olat.restapi.FolderTest.class,
|
| 451 |
+
org.olat.restapi.ForumTest.class,
|
| 452 |
+
org.olat.restapi.GradingWebServiceTest.class,
|
| 453 |
+
org.olat.restapi.GroupFoldersTest.class,
|
| 454 |
+
org.olat.restapi.GroupMgmtTest.class,
|
| 455 |
+
org.olat.restapi.I18nTest.class,
|
| 456 |
+
org.olat.restapi.MyForumsTest.class,
|
| 457 |
+
org.olat.restapi.LecturesBlocksTest.class,
|
| 458 |
+
org.olat.restapi.LecturesBlocksRootTest.class,
|
| 459 |
+
org.olat.restapi.LecturesBlockRollCallTest.class,
|
| 460 |
+
org.olat.restapi.NotificationsTest.class,
|
| 461 |
+
org.olat.restapi.NotificationsSubscribersTest.class,
|
| 462 |
+
org.olat.restapi.RelationRolesWebServiceTest.class,
|
| 463 |
+
org.olat.restapi.IdentityToIdentityRelationsWebServiceTest.class,
|
| 464 |
+
org.olat.restapi.RepositoryEntryLifecycleTest.class,
|
| 465 |
+
org.olat.restapi.RepositoryEntriesTest.class,
|
| 466 |
+
org.olat.restapi.RepositoryEntryWebServiceTest.class,
|
| 467 |
+
org.olat.restapi.RemindersWebServiceTest.class,
|
| 468 |
+
org.olat.restapi.RestApiLoginFilterTest.class,
|
| 469 |
+
org.olat.restapi.UserAuthenticationMgmtTest.class,
|
| 470 |
+
org.olat.restapi.UserAuthenticationsWebServiceTest.class,
|
| 471 |
+
org.olat.restapi.UserFoldersTest.class,
|
| 472 |
+
org.olat.restapi.UserCoursesTest.class,
|
| 473 |
+
org.olat.restapi.UserMgmtTest.class,
|
| 474 |
+
org.olat.restapi.ContactsTest.class,
|
| 475 |
+
org.olat.restapi.SharedFolderTest.class,
|
| 476 |
+
org.olat.restapi.SystemTest.class,
|
| 477 |
+
org.olat.restapi.ChangePasswordTest.class,
|
| 478 |
+
org.olat.restapi.QuestionPoolTest.class,
|
| 479 |
+
org.olat.restapi.OrganisationsWebServiceTest.class,
|
| 480 |
+
org.olat.restapi.OrganisationTypesWebServiceTest.class,
|
| 481 |
+
org.olat.restapi.RegistrationTest.class,
|
| 482 |
+
org.olat.restapi.DocumentPoolModuleWebServiceTest.class,
|
| 483 |
+
org.olat.restapi.TaxonomyWebServiceTest.class,
|
| 484 |
+
org.olat.restapi.security.RestSecurityBeanTest.class,
|
| 485 |
+
de.bps.olat.portal.institution.InstitutionPortletTest.class,
|
| 486 |
+
org.olat.group.manager.BusinessGroupImportExportXStreamTest.class,
|
| 487 |
+
org.olat.group.test.BusinessGroupImportExportTest.class,
|
| 488 |
+
org.olat.resource.accesscontrol.ACFrontendManagerTest.class,
|
| 489 |
+
org.olat.resource.accesscontrol.ACMethodManagerTest.class,
|
| 490 |
+
org.olat.resource.accesscontrol.ACOfferManagerTest.class,
|
| 491 |
+
org.olat.resource.accesscontrol.ACOrderManagerTest.class,
|
| 492 |
+
org.olat.resource.accesscontrol.ACTransactionManagerTest.class,
|
| 493 |
+
org.olat.resource.accesscontrol.ACReservationDAOTest.class,
|
| 494 |
+
org.olat.resource.accesscontrol.provider.auto.AutoAccessManagerTest.class,
|
| 495 |
+
org.olat.resource.accesscontrol.provider.auto.manager.AdvanceOrderDAOTest.class,
|
| 496 |
+
org.olat.resource.accesscontrol.provider.paypalcheckout.manager.PaypalCheckoutManagerTest.class,
|
| 497 |
+
org.olat.resource.accesscontrol.provider.paypalcheckout.manager.PaypalCheckoutTransactionDAOTest.class,
|
| 498 |
+
/**
|
| 499 |
+
* Pure JUnit test without need of framework
|
| 500 |
+
*/
|
| 501 |
+
org.olat.core.commons.services.doceditor.onlyoffice.manager.OnlyOfficeSecurityServiceImplTest.class,
|
| 502 |
+
org.olat.core.commons.services.doceditor.onlyoffice.manager.OnlyOfficeServiceImplTest.class,
|
| 503 |
+
org.olat.core.commons.services.doceditor.discovery.manager.DiscoveryServiceImplTest.class,
|
| 504 |
+
org.olat.core.commons.services.doceditor.discovery.manager.DiscoveryXStreamTest.class,
|
| 505 |
+
org.olat.core.commons.services.commentAndRating.manager.CommentAndRatingServiceTest.class,
|
| 506 |
+
org.olat.core.commons.services.license.ui.LicenseSelectionConfigTest.class,
|
| 507 |
+
org.olat.core.gui.components.form.flexible.impl.elements.richText.TextModeTest.class,
|
| 508 |
+
org.olat.core.gui.components.form.flexible.impl.elements.SelectboxSelectionImplTest.class,
|
| 509 |
+
org.olat.core.gui.components.form.flexible.impl.elements.TextElementRendererTest.class,
|
| 510 |
+
org.olat.core.util.DateUtilsTest.class,
|
| 511 |
+
org.olat.course.learningpath.evaluation.ConfigEndDateEvaluatorTest.class,
|
| 512 |
+
org.olat.course.learningpath.evaluation.ConfigStartDateEvaluatorTest.class,
|
| 513 |
+
org.olat.course.learningpath.evaluation.DefaultLearningPathStatusEvaluatorTest.class,
|
| 514 |
+
org.olat.course.learningpath.evaluation.LinearAccessEvaluatorTest.class,
|
| 515 |
+
org.olat.course.learningpath.manager.LearningPathNodeAccessProviderTest.class,
|
| 516 |
+
org.olat.course.nodes.st.assessment.PassCounterTest.class,
|
| 517 |
+
org.olat.course.nodes.st.assessment.CumulatingDurationEvaluatorTest.class,
|
| 518 |
+
org.olat.course.nodes.st.assessment.CumulatingScoreEvaluatorTest.class,
|
| 519 |
+
org.olat.course.nodes.st.assessment.ConventionalSTCompletionEvaluatorTest.class,
|
| 520 |
+
org.olat.course.nodes.st.assessment.MandatoryObligationEvaluatorTest.class,
|
| 521 |
+
org.olat.course.nodes.st.assessment.MaxScoreCumulatorTest.class,
|
| 522 |
+
org.olat.course.nodes.st.assessment.STFullyAssessedEvaluatorTest.class,
|
| 523 |
+
org.olat.course.nodes.st.assessment.STLastModificationsEvaluatorTest.class,
|
| 524 |
+
org.olat.course.nodes.st.assessment.STRootPassedEvaluatorTest.class,
|
| 525 |
+
org.olat.course.nodes.st.assessment.STLearningPathStatusEvaluatorTest.class,
|
| 526 |
+
org.olat.course.run.scoring.AverageCompletionEvaluatorTest.class,
|
| 527 |
+
org.olat.course.run.userview.UserCourseEnvironmentImplTest.class,
|
| 528 |
+
org.olat.login.validation.PasswordSyntaxValidatorTest.class,
|
| 529 |
+
org.olat.login.validation.PasswordValidationRuleFactoryTest.class,
|
| 530 |
+
org.olat.modules.assessment.model.OverridableImplTest.class,
|
| 531 |
+
org.olat.modules.card2brain.manager.Card2BrainManagerImplTest.class,
|
| 532 |
+
org.olat.modules.edubase.manager.EdubaseManagerImplTest.class,
|
| 533 |
+
org.olat.modules.edusharing.manager.EdusharingHtmlServiceImplTest.class,
|
| 534 |
+
org.olat.modules.edusharing.manager.EdusharingSecurityImplTest.class,
|
| 535 |
+
org.olat.modules.fo.WordCountTest.class,
|
| 536 |
+
org.olat.modules.forms.manager.EvaluationFormMangerImplTest.class,
|
| 537 |
+
org.olat.modules.forms.manager.RubricStatisticCalculatorTest.class,
|
| 538 |
+
org.olat.modules.forms.model.xml.ScaleTypeTest.class,
|
| 539 |
+
org.olat.modules.forms.RubricsComparisonTest.class,
|
| 540 |
+
org.olat.modules.opencast.WildcardFilterTest.class,
|
| 541 |
+
org.olat.modules.qpool.manager.QuestionPoolServiceImplTest.class,
|
| 542 |
+
org.olat.modules.qpool.manager.QuestionPoolUserDataDeletableTest.class,
|
| 543 |
+
org.olat.modules.qpool.manager.review.LowerLimitProviderTest.class,
|
| 544 |
+
org.olat.modules.qpool.manager.review.ReviewServiceImplTest.class,
|
| 545 |
+
org.olat.modules.qpool.model.QuestionItemAuditLogBuilderImplTest.class,
|
| 546 |
+
org.olat.modules.qpool.ui.metadata.QPoolTaxonomyTreeBuilderTest.class,
|
| 547 |
+
org.olat.modules.quality.analysis.manager.AnalysisPresentationXStreamTest.class,
|
| 548 |
+
org.olat.modules.quality.analysis.manager.StatisticsCalculatorTest.class,
|
| 549 |
+
org.olat.modules.quality.analysis.MultiTrendSeriesTest.class,
|
| 550 |
+
org.olat.modules.quality.analysis.TemporalKeyComparatorTest.class,
|
| 551 |
+
org.olat.modules.quality.generator.provider.ProviderHelperTest.class,
|
| 552 |
+
org.olat.modules.quality.manager.QualityServiceImplTest.class,
|
| 553 |
+
org.olat.modules.webFeed.manager.FeedManagerImplTest.class,
|
| 554 |
+
org.olat.modules.webFeed.manager.RomeFeedFetcherTest.class,
|
| 555 |
+
org.olat.resource.accesscontrol.provider.auto.manager.AutoAccessManagerImplTest.class,
|
| 556 |
+
org.olat.resource.accesscontrol.provider.auto.manager.ExternalIdHandlerTest.class,
|
| 557 |
+
org.olat.resource.accesscontrol.provider.auto.manager.ExternalRefHandlerTest.class,
|
| 558 |
+
org.olat.resource.accesscontrol.provider.auto.manager.IdentifierHandlerTest.class,
|
| 559 |
+
org.olat.resource.accesscontrol.provider.auto.manager.InputValidatorTest.class,
|
| 560 |
+
org.olat.resource.accesscontrol.provider.auto.manager.InternalIdHandlerTest.class,
|
| 561 |
+
org.olat.resource.accesscontrol.provider.auto.manager.SemicolonSplitterTest.class,
|
| 562 |
+
org.olat.shibboleth.manager.DifferenceCheckerTest.class,
|
| 563 |
+
org.olat.shibboleth.manager.ShibbolethAttributesTest.class,
|
| 564 |
+
org.olat.shibboleth.manager.ShibbolethManagerImplTest.class,
|
| 565 |
+
org.olat.shibboleth.handler.DoNothingHandlerTest.class,
|
| 566 |
+
org.olat.shibboleth.handler.FirstValueHandlerTest.class,
|
| 567 |
+
org.olat.shibboleth.handler.SchacGenderHandlerTest.class,
|
| 568 |
+
org.olat.user.UserManagerImplTest.class,
|
| 569 |
+
org.olat.user.propertyhandlers.DatePropertyHandlerTest.class,
|
| 570 |
+
org.olat.user.propertyhandlers.LinkedinPropertyHandlerTest.class,
|
| 571 |
+
org.olat.core.gui.components.form.flexible.impl.elements.FileElementRendererTest.class,
|
| 572 |
+
/**
|
| 573 |
+
*
|
| 574 |
+
* Place tests which load their own Spring context
|
| 575 |
+
* with @ContextConfiguration below the others as they may taint the
|
| 576 |
+
* cached Spring context
|
| 577 |
+
*
|
| 578 |
+
* IMPORTANT: If you create mock spring contexts in the test source tree of olatcore and
|
| 579 |
+
* you like to use them in olat3 you have to copy them to the test source tree of olat3
|
| 580 |
+
* as well as the tests on hudson run agains a jar version of olatcore where the test source
|
| 581 |
+
* tree is not available
|
| 582 |
+
*/
|
| 583 |
+
org.olat.core.commons.services.scheduler.SchedulerTest.class,
|
| 584 |
+
org.olat.upgrade.UpgradeDefinitionTest.class,
|
| 585 |
+
org.olat.upgrade.UpgradeManagerTest.class
|
| 586 |
+
})
|
| 587 |
+
public class AllTestsJunit4 {
|
| 588 |
+
//
|
| 589 |
+
}
|
Java/AnalysisPresentationXStream.java
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* <a href="http://www.openolat.org">
|
| 3 |
+
* OpenOLAT - Online Learning and Training</a><br>
|
| 4 |
+
* <p>
|
| 5 |
+
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
|
| 6 |
+
* you may not use this file except in compliance with the License.<br>
|
| 7 |
+
* You may obtain a copy of the License at the
|
| 8 |
+
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
|
| 9 |
+
* <p>
|
| 10 |
+
* Unless required by applicable law or agreed to in writing,<br>
|
| 11 |
+
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
|
| 12 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
|
| 13 |
+
* See the License for the specific language governing permissions and <br>
|
| 14 |
+
* limitations under the License.
|
| 15 |
+
* <p>
|
| 16 |
+
* Initial code contributed and copyrighted by<br>
|
| 17 |
+
* frentix GmbH, http://www.frentix.com
|
| 18 |
+
* <p>
|
| 19 |
+
*/
|
| 20 |
+
package org.olat.modules.quality.analysis.manager;
|
| 21 |
+
|
| 22 |
+
import org.apache.logging.log4j.Logger;
|
| 23 |
+
import org.olat.basesecurity.model.IdentityRefImpl;
|
| 24 |
+
import org.olat.basesecurity.model.OrganisationRefImpl;
|
| 25 |
+
import org.olat.core.logging.Tracing;
|
| 26 |
+
import org.olat.core.util.StringHelper;
|
| 27 |
+
import org.olat.core.util.xml.XStreamHelper;
|
| 28 |
+
import org.olat.modules.curriculum.model.CurriculumElementRefImpl;
|
| 29 |
+
import org.olat.modules.curriculum.model.CurriculumElementTypeRefImpl;
|
| 30 |
+
import org.olat.modules.curriculum.model.CurriculumRefImpl;
|
| 31 |
+
import org.olat.modules.quality.analysis.AnalysisSearchParameter;
|
| 32 |
+
import org.olat.modules.quality.analysis.GroupBy;
|
| 33 |
+
import org.olat.modules.quality.analysis.MultiGroupBy;
|
| 34 |
+
import org.olat.modules.quality.model.QualityDataCollectionRefImpl;
|
| 35 |
+
import org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl;
|
| 36 |
+
import org.olat.repository.model.RepositoryEntryRefImpl;
|
| 37 |
+
|
| 38 |
+
import com.thoughtworks.xstream.XStream;
|
| 39 |
+
import com.thoughtworks.xstream.security.ExplicitTypePermission;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
*
|
| 43 |
+
* Initial date: 01.10.2018<br>
|
| 44 |
+
* @author uhensler, [email protected], http://www.frentix.com
|
| 45 |
+
*
|
| 46 |
+
*/
|
| 47 |
+
public class AnalysisPresentationXStream {
|
| 48 |
+
|
| 49 |
+
private static final Logger log = Tracing.createLoggerFor(AnalysisPresentationXStream.class);
|
| 50 |
+
|
| 51 |
+
private static final XStream xstream = XStreamHelper.createXStreamInstance();
|
| 52 |
+
static {
|
| 53 |
+
Class<?>[] types = new Class[] {
|
| 54 |
+
MultiGroupBy.class, GroupBy.class, AnalysisSearchParameter.class, QualityDataCollectionRefImpl.class,
|
| 55 |
+
RepositoryEntryRefImpl.class, IdentityRefImpl.class, OrganisationRefImpl.class, CurriculumRefImpl.class,
|
| 56 |
+
CurriculumElementRefImpl.class, CurriculumElementTypeRefImpl.class, TaxonomyLevelRefImpl.class };
|
| 57 |
+
xstream.addPermission(new ExplicitTypePermission(types));
|
| 58 |
+
xstream.alias("multiGroupBy", MultiGroupBy.class);
|
| 59 |
+
xstream.alias("groupBy", GroupBy.class);
|
| 60 |
+
xstream.alias("AnalysisSearchParameter", AnalysisSearchParameter.class);
|
| 61 |
+
xstream.alias("QualityDataCollectionRef", QualityDataCollectionRefImpl.class);
|
| 62 |
+
xstream.alias("RepositoryEntryRef", RepositoryEntryRefImpl.class);
|
| 63 |
+
xstream.alias("IdentityRef", IdentityRefImpl.class);
|
| 64 |
+
xstream.alias("OrganisationRef", OrganisationRefImpl.class);
|
| 65 |
+
xstream.alias("CurriculumRef", CurriculumRefImpl.class);
|
| 66 |
+
xstream.alias("CurriculumElementRef", CurriculumElementRefImpl.class);
|
| 67 |
+
xstream.alias("CurriculumElementTypeRef", CurriculumElementTypeRefImpl.class);
|
| 68 |
+
xstream.alias("TaxonomyLevelRef", TaxonomyLevelRefImpl.class);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
static String toXml(Object obj) {
|
| 72 |
+
if (obj == null) return null;
|
| 73 |
+
|
| 74 |
+
return xstream.toXML(obj);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
@SuppressWarnings("unchecked")
|
| 78 |
+
public static <U> U fromXml(String xml, @SuppressWarnings("unused") Class<U> cl) {
|
| 79 |
+
if(StringHelper.containsNonWhitespace(xml)) {
|
| 80 |
+
try {
|
| 81 |
+
Object obj = xstream.fromXML(xml);
|
| 82 |
+
return (U)obj;
|
| 83 |
+
} catch (Exception e) {
|
| 84 |
+
log.error("", e);
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
return null;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
}
|
Java/Application.java
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.zrlog.web;
|
| 2 |
+
|
| 3 |
+
import com.zrlog.common.Constants;
|
| 4 |
+
import org.apache.catalina.LifecycleException;
|
| 5 |
+
import org.apache.catalina.startup.Tomcat;
|
| 6 |
+
|
| 7 |
+
import javax.servlet.ServletException;
|
| 8 |
+
import java.io.File;
|
| 9 |
+
|
| 10 |
+
public class Application {
|
| 11 |
+
|
| 12 |
+
public static void main(String[] args) throws LifecycleException {
|
| 13 |
+
String webappDirLocation;
|
| 14 |
+
if (Constants.IN_JAR) {
|
| 15 |
+
webappDirLocation = "webapp";
|
| 16 |
+
} else {
|
| 17 |
+
webappDirLocation = "src/main/webapp/";
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
Tomcat tomcat = new Tomcat();
|
| 21 |
+
|
| 22 |
+
String webPort = System.getenv("PORT");
|
| 23 |
+
if (webPort == null || webPort.isEmpty()) {
|
| 24 |
+
webPort = "8080";
|
| 25 |
+
}
|
| 26 |
+
// BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
|
| 27 |
+
// tomcat.setPort(Integer.valueOf(webPort));
|
| 28 |
+
// FIXED:
|
| 29 |
+
tomcat.setPort(Integer.parseInt(webPort));
|
| 30 |
+
tomcat.getConnector();
|
| 31 |
+
|
| 32 |
+
// Declare an alternative location for your "WEB-INF/classes" dir
|
| 33 |
+
// Servlet 3.0 annotation will work
|
| 34 |
+
File additionWebInfClasses;
|
| 35 |
+
if (Constants.IN_JAR) {
|
| 36 |
+
additionWebInfClasses = new File("");
|
| 37 |
+
} else {
|
| 38 |
+
additionWebInfClasses = new File("target/classes");
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
tomcat.setBaseDir(additionWebInfClasses.toString());
|
| 42 |
+
//idea的路径eclipse启动的路径有区别
|
| 43 |
+
if (!Constants.IN_JAR && !new File("").getAbsolutePath().endsWith(File.separator + "web")) {
|
| 44 |
+
webappDirLocation = "web/" + webappDirLocation;
|
| 45 |
+
}
|
| 46 |
+
tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
|
| 47 |
+
tomcat.start();
|
| 48 |
+
tomcat.getServer().await();
|
| 49 |
+
}
|
| 50 |
+
}
|
Java/ArmConst.java
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// For Unicorn Engine. AUTO-GENERATED FILE, DO NOT EDIT
|
| 2 |
+
|
| 3 |
+
package unicorn;
|
| 4 |
+
|
| 5 |
+
public interface ArmConst {
|
| 6 |
+
|
| 7 |
+
// ARM CPU
|
| 8 |
+
|
| 9 |
+
public static final int UC_CPU_ARM_926 = 0;
|
| 10 |
+
public static final int UC_CPU_ARM_946 = 1;
|
| 11 |
+
public static final int UC_CPU_ARM_1026 = 2;
|
| 12 |
+
public static final int UC_CPU_ARM_1136_R2 = 3;
|
| 13 |
+
public static final int UC_CPU_ARM_1136 = 4;
|
| 14 |
+
public static final int UC_CPU_ARM_1176 = 5;
|
| 15 |
+
public static final int UC_CPU_ARM_11MPCORE = 6;
|
| 16 |
+
public static final int UC_CPU_ARM_CORTEX_M0 = 7;
|
| 17 |
+
public static final int UC_CPU_ARM_CORTEX_M3 = 8;
|
| 18 |
+
public static final int UC_CPU_ARM_CORTEX_M4 = 9;
|
| 19 |
+
public static final int UC_CPU_ARM_CORTEX_M7 = 10;
|
| 20 |
+
public static final int UC_CPU_ARM_CORTEX_M33 = 11;
|
| 21 |
+
public static final int UC_CPU_ARM_CORTEX_R5 = 12;
|
| 22 |
+
public static final int UC_CPU_ARM_CORTEX_R5F = 13;
|
| 23 |
+
public static final int UC_CPU_ARM_CORTEX_A7 = 14;
|
| 24 |
+
public static final int UC_CPU_ARM_CORTEX_A8 = 15;
|
| 25 |
+
public static final int UC_CPU_ARM_CORTEX_A9 = 16;
|
| 26 |
+
public static final int UC_CPU_ARM_CORTEX_A15 = 17;
|
| 27 |
+
public static final int UC_CPU_ARM_TI925T = 18;
|
| 28 |
+
public static final int UC_CPU_ARM_SA1100 = 19;
|
| 29 |
+
public static final int UC_CPU_ARM_SA1110 = 20;
|
| 30 |
+
public static final int UC_CPU_ARM_PXA250 = 21;
|
| 31 |
+
public static final int UC_CPU_ARM_PXA255 = 22;
|
| 32 |
+
public static final int UC_CPU_ARM_PXA260 = 23;
|
| 33 |
+
public static final int UC_CPU_ARM_PXA261 = 24;
|
| 34 |
+
public static final int UC_CPU_ARM_PXA262 = 25;
|
| 35 |
+
public static final int UC_CPU_ARM_PXA270 = 26;
|
| 36 |
+
public static final int UC_CPU_ARM_PXA270A0 = 27;
|
| 37 |
+
public static final int UC_CPU_ARM_PXA270A1 = 28;
|
| 38 |
+
public static final int UC_CPU_ARM_PXA270B0 = 29;
|
| 39 |
+
public static final int UC_CPU_ARM_PXA270B1 = 30;
|
| 40 |
+
public static final int UC_CPU_ARM_PXA270C0 = 31;
|
| 41 |
+
public static final int UC_CPU_ARM_PXA270C5 = 32;
|
| 42 |
+
public static final int UC_CPU_ARM_MAX = 33;
|
| 43 |
+
// BUG: CWE-665 Improper Initialization
|
| 44 |
+
//
|
| 45 |
+
// FIXED:
|
| 46 |
+
public static final int UC_CPU_ARM_ENDING = 34;
|
| 47 |
+
|
| 48 |
+
// ARM registers
|
| 49 |
+
|
| 50 |
+
public static final int UC_ARM_REG_INVALID = 0;
|
| 51 |
+
public static final int UC_ARM_REG_APSR = 1;
|
| 52 |
+
public static final int UC_ARM_REG_APSR_NZCV = 2;
|
| 53 |
+
public static final int UC_ARM_REG_CPSR = 3;
|
| 54 |
+
public static final int UC_ARM_REG_FPEXC = 4;
|
| 55 |
+
public static final int UC_ARM_REG_FPINST = 5;
|
| 56 |
+
public static final int UC_ARM_REG_FPSCR = 6;
|
| 57 |
+
public static final int UC_ARM_REG_FPSCR_NZCV = 7;
|
| 58 |
+
public static final int UC_ARM_REG_FPSID = 8;
|
| 59 |
+
public static final int UC_ARM_REG_ITSTATE = 9;
|
| 60 |
+
public static final int UC_ARM_REG_LR = 10;
|
| 61 |
+
public static final int UC_ARM_REG_PC = 11;
|
| 62 |
+
public static final int UC_ARM_REG_SP = 12;
|
| 63 |
+
public static final int UC_ARM_REG_SPSR = 13;
|
| 64 |
+
public static final int UC_ARM_REG_D0 = 14;
|
| 65 |
+
public static final int UC_ARM_REG_D1 = 15;
|
| 66 |
+
public static final int UC_ARM_REG_D2 = 16;
|
| 67 |
+
public static final int UC_ARM_REG_D3 = 17;
|
| 68 |
+
public static final int UC_ARM_REG_D4 = 18;
|
| 69 |
+
public static final int UC_ARM_REG_D5 = 19;
|
| 70 |
+
public static final int UC_ARM_REG_D6 = 20;
|
| 71 |
+
public static final int UC_ARM_REG_D7 = 21;
|
| 72 |
+
public static final int UC_ARM_REG_D8 = 22;
|
| 73 |
+
public static final int UC_ARM_REG_D9 = 23;
|
| 74 |
+
public static final int UC_ARM_REG_D10 = 24;
|
| 75 |
+
public static final int UC_ARM_REG_D11 = 25;
|
| 76 |
+
public static final int UC_ARM_REG_D12 = 26;
|
| 77 |
+
public static final int UC_ARM_REG_D13 = 27;
|
| 78 |
+
public static final int UC_ARM_REG_D14 = 28;
|
| 79 |
+
public static final int UC_ARM_REG_D15 = 29;
|
| 80 |
+
public static final int UC_ARM_REG_D16 = 30;
|
| 81 |
+
public static final int UC_ARM_REG_D17 = 31;
|
| 82 |
+
public static final int UC_ARM_REG_D18 = 32;
|
| 83 |
+
public static final int UC_ARM_REG_D19 = 33;
|
| 84 |
+
public static final int UC_ARM_REG_D20 = 34;
|
| 85 |
+
public static final int UC_ARM_REG_D21 = 35;
|
| 86 |
+
public static final int UC_ARM_REG_D22 = 36;
|
| 87 |
+
public static final int UC_ARM_REG_D23 = 37;
|
| 88 |
+
public static final int UC_ARM_REG_D24 = 38;
|
| 89 |
+
public static final int UC_ARM_REG_D25 = 39;
|
| 90 |
+
public static final int UC_ARM_REG_D26 = 40;
|
| 91 |
+
public static final int UC_ARM_REG_D27 = 41;
|
| 92 |
+
public static final int UC_ARM_REG_D28 = 42;
|
| 93 |
+
public static final int UC_ARM_REG_D29 = 43;
|
| 94 |
+
public static final int UC_ARM_REG_D30 = 44;
|
| 95 |
+
public static final int UC_ARM_REG_D31 = 45;
|
| 96 |
+
public static final int UC_ARM_REG_FPINST2 = 46;
|
| 97 |
+
public static final int UC_ARM_REG_MVFR0 = 47;
|
| 98 |
+
public static final int UC_ARM_REG_MVFR1 = 48;
|
| 99 |
+
public static final int UC_ARM_REG_MVFR2 = 49;
|
| 100 |
+
public static final int UC_ARM_REG_Q0 = 50;
|
| 101 |
+
public static final int UC_ARM_REG_Q1 = 51;
|
| 102 |
+
public static final int UC_ARM_REG_Q2 = 52;
|
| 103 |
+
public static final int UC_ARM_REG_Q3 = 53;
|
| 104 |
+
public static final int UC_ARM_REG_Q4 = 54;
|
| 105 |
+
public static final int UC_ARM_REG_Q5 = 55;
|
| 106 |
+
public static final int UC_ARM_REG_Q6 = 56;
|
| 107 |
+
public static final int UC_ARM_REG_Q7 = 57;
|
| 108 |
+
public static final int UC_ARM_REG_Q8 = 58;
|
| 109 |
+
public static final int UC_ARM_REG_Q9 = 59;
|
| 110 |
+
public static final int UC_ARM_REG_Q10 = 60;
|
| 111 |
+
public static final int UC_ARM_REG_Q11 = 61;
|
| 112 |
+
public static final int UC_ARM_REG_Q12 = 62;
|
| 113 |
+
public static final int UC_ARM_REG_Q13 = 63;
|
| 114 |
+
public static final int UC_ARM_REG_Q14 = 64;
|
| 115 |
+
public static final int UC_ARM_REG_Q15 = 65;
|
| 116 |
+
public static final int UC_ARM_REG_R0 = 66;
|
| 117 |
+
public static final int UC_ARM_REG_R1 = 67;
|
| 118 |
+
public static final int UC_ARM_REG_R2 = 68;
|
| 119 |
+
public static final int UC_ARM_REG_R3 = 69;
|
| 120 |
+
public static final int UC_ARM_REG_R4 = 70;
|
| 121 |
+
public static final int UC_ARM_REG_R5 = 71;
|
| 122 |
+
public static final int UC_ARM_REG_R6 = 72;
|
| 123 |
+
public static final int UC_ARM_REG_R7 = 73;
|
| 124 |
+
public static final int UC_ARM_REG_R8 = 74;
|
| 125 |
+
public static final int UC_ARM_REG_R9 = 75;
|
| 126 |
+
public static final int UC_ARM_REG_R10 = 76;
|
| 127 |
+
public static final int UC_ARM_REG_R11 = 77;
|
| 128 |
+
public static final int UC_ARM_REG_R12 = 78;
|
| 129 |
+
public static final int UC_ARM_REG_S0 = 79;
|
| 130 |
+
public static final int UC_ARM_REG_S1 = 80;
|
| 131 |
+
public static final int UC_ARM_REG_S2 = 81;
|
| 132 |
+
public static final int UC_ARM_REG_S3 = 82;
|
| 133 |
+
public static final int UC_ARM_REG_S4 = 83;
|
| 134 |
+
public static final int UC_ARM_REG_S5 = 84;
|
| 135 |
+
public static final int UC_ARM_REG_S6 = 85;
|
| 136 |
+
public static final int UC_ARM_REG_S7 = 86;
|
| 137 |
+
public static final int UC_ARM_REG_S8 = 87;
|
| 138 |
+
public static final int UC_ARM_REG_S9 = 88;
|
| 139 |
+
public static final int UC_ARM_REG_S10 = 89;
|
| 140 |
+
public static final int UC_ARM_REG_S11 = 90;
|
| 141 |
+
public static final int UC_ARM_REG_S12 = 91;
|
| 142 |
+
public static final int UC_ARM_REG_S13 = 92;
|
| 143 |
+
public static final int UC_ARM_REG_S14 = 93;
|
| 144 |
+
public static final int UC_ARM_REG_S15 = 94;
|
| 145 |
+
public static final int UC_ARM_REG_S16 = 95;
|
| 146 |
+
public static final int UC_ARM_REG_S17 = 96;
|
| 147 |
+
public static final int UC_ARM_REG_S18 = 97;
|
| 148 |
+
public static final int UC_ARM_REG_S19 = 98;
|
| 149 |
+
public static final int UC_ARM_REG_S20 = 99;
|
| 150 |
+
public static final int UC_ARM_REG_S21 = 100;
|
| 151 |
+
public static final int UC_ARM_REG_S22 = 101;
|
| 152 |
+
public static final int UC_ARM_REG_S23 = 102;
|
| 153 |
+
public static final int UC_ARM_REG_S24 = 103;
|
| 154 |
+
public static final int UC_ARM_REG_S25 = 104;
|
| 155 |
+
public static final int UC_ARM_REG_S26 = 105;
|
| 156 |
+
public static final int UC_ARM_REG_S27 = 106;
|
| 157 |
+
public static final int UC_ARM_REG_S28 = 107;
|
| 158 |
+
public static final int UC_ARM_REG_S29 = 108;
|
| 159 |
+
public static final int UC_ARM_REG_S30 = 109;
|
| 160 |
+
public static final int UC_ARM_REG_S31 = 110;
|
| 161 |
+
public static final int UC_ARM_REG_C1_C0_2 = 111;
|
| 162 |
+
public static final int UC_ARM_REG_C13_C0_2 = 112;
|
| 163 |
+
public static final int UC_ARM_REG_C13_C0_3 = 113;
|
| 164 |
+
public static final int UC_ARM_REG_IPSR = 114;
|
| 165 |
+
public static final int UC_ARM_REG_MSP = 115;
|
| 166 |
+
public static final int UC_ARM_REG_PSP = 116;
|
| 167 |
+
public static final int UC_ARM_REG_CONTROL = 117;
|
| 168 |
+
public static final int UC_ARM_REG_IAPSR = 118;
|
| 169 |
+
public static final int UC_ARM_REG_EAPSR = 119;
|
| 170 |
+
public static final int UC_ARM_REG_XPSR = 120;
|
| 171 |
+
public static final int UC_ARM_REG_EPSR = 121;
|
| 172 |
+
public static final int UC_ARM_REG_IEPSR = 122;
|
| 173 |
+
public static final int UC_ARM_REG_PRIMASK = 123;
|
| 174 |
+
public static final int UC_ARM_REG_BASEPRI = 124;
|
| 175 |
+
public static final int UC_ARM_REG_BASEPRI_MAX = 125;
|
| 176 |
+
public static final int UC_ARM_REG_FAULTMASK = 126;
|
| 177 |
+
public static final int UC_ARM_REG_APSR_NZCVQ = 127;
|
| 178 |
+
public static final int UC_ARM_REG_APSR_G = 128;
|
| 179 |
+
public static final int UC_ARM_REG_APSR_NZCVQG = 129;
|
| 180 |
+
public static final int UC_ARM_REG_IAPSR_NZCVQ = 130;
|
| 181 |
+
public static final int UC_ARM_REG_IAPSR_G = 131;
|
| 182 |
+
public static final int UC_ARM_REG_IAPSR_NZCVQG = 132;
|
| 183 |
+
public static final int UC_ARM_REG_EAPSR_NZCVQ = 133;
|
| 184 |
+
public static final int UC_ARM_REG_EAPSR_G = 134;
|
| 185 |
+
public static final int UC_ARM_REG_EAPSR_NZCVQG = 135;
|
| 186 |
+
public static final int UC_ARM_REG_XPSR_NZCVQ = 136;
|
| 187 |
+
public static final int UC_ARM_REG_XPSR_G = 137;
|
| 188 |
+
public static final int UC_ARM_REG_XPSR_NZCVQG = 138;
|
| 189 |
+
public static final int UC_ARM_REG_CP_REG = 139;
|
| 190 |
+
public static final int UC_ARM_REG_ENDING = 140;
|
| 191 |
+
|
| 192 |
+
// alias registers
|
| 193 |
+
public static final int UC_ARM_REG_R13 = 12;
|
| 194 |
+
public static final int UC_ARM_REG_R14 = 10;
|
| 195 |
+
public static final int UC_ARM_REG_R15 = 11;
|
| 196 |
+
public static final int UC_ARM_REG_SB = 75;
|
| 197 |
+
public static final int UC_ARM_REG_SL = 76;
|
| 198 |
+
public static final int UC_ARM_REG_FP = 77;
|
| 199 |
+
public static final int UC_ARM_REG_IP = 78;
|
| 200 |
+
|
| 201 |
+
}
|
Java/ArmeriaHttpUtil.java
ADDED
|
@@ -0,0 +1,1004 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright 2016 LINE Corporation
|
| 3 |
+
*
|
| 4 |
+
* LINE Corporation licenses this file to you under the Apache License,
|
| 5 |
+
* version 2.0 (the "License"); you may not use this file except in compliance
|
| 6 |
+
* with the License. You may obtain a copy of the License at:
|
| 7 |
+
*
|
| 8 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
*
|
| 10 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 12 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 13 |
+
* License for the specific language governing permissions and limitations
|
| 14 |
+
* under the License.
|
| 15 |
+
*/
|
| 16 |
+
/*
|
| 17 |
+
* Copyright 2014 The Netty Project
|
| 18 |
+
*
|
| 19 |
+
* The Netty Project licenses this file to you under the Apache License,
|
| 20 |
+
* version 2.0 (the "License"); you may not use this file except in compliance
|
| 21 |
+
* with the License. You may obtain a copy of the License at:
|
| 22 |
+
*
|
| 23 |
+
* https://www.apache.org/licenses/LICENSE-2.0
|
| 24 |
+
*
|
| 25 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 26 |
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
| 27 |
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
| 28 |
+
* License for the specific language governing permissions and limitations
|
| 29 |
+
* under the License.
|
| 30 |
+
*/
|
| 31 |
+
package com.linecorp.armeria.internal;
|
| 32 |
+
|
| 33 |
+
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
| 34 |
+
import static io.netty.handler.codec.http.HttpUtil.isAsteriskForm;
|
| 35 |
+
import static io.netty.handler.codec.http.HttpUtil.isOriginForm;
|
| 36 |
+
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
| 37 |
+
import static io.netty.handler.codec.http2.Http2Exception.streamError;
|
| 38 |
+
import static io.netty.util.AsciiString.EMPTY_STRING;
|
| 39 |
+
import static io.netty.util.ByteProcessor.FIND_COMMA;
|
| 40 |
+
import static io.netty.util.internal.StringUtil.decodeHexNibble;
|
| 41 |
+
import static io.netty.util.internal.StringUtil.isNullOrEmpty;
|
| 42 |
+
import static io.netty.util.internal.StringUtil.length;
|
| 43 |
+
import static java.util.Objects.requireNonNull;
|
| 44 |
+
|
| 45 |
+
import java.net.InetSocketAddress;
|
| 46 |
+
import java.net.URI;
|
| 47 |
+
import java.net.URISyntaxException;
|
| 48 |
+
import java.nio.charset.Charset;
|
| 49 |
+
import java.nio.charset.StandardCharsets;
|
| 50 |
+
import java.util.Iterator;
|
| 51 |
+
import java.util.List;
|
| 52 |
+
import java.util.Map.Entry;
|
| 53 |
+
import java.util.Set;
|
| 54 |
+
import java.util.StringJoiner;
|
| 55 |
+
import java.util.function.BiConsumer;
|
| 56 |
+
|
| 57 |
+
import javax.annotation.Nullable;
|
| 58 |
+
|
| 59 |
+
import com.github.benmanes.caffeine.cache.Caffeine;
|
| 60 |
+
import com.github.benmanes.caffeine.cache.LoadingCache;
|
| 61 |
+
import com.google.common.annotations.VisibleForTesting;
|
| 62 |
+
import com.google.common.base.Ascii;
|
| 63 |
+
import com.google.common.base.Splitter;
|
| 64 |
+
import com.google.common.base.Strings;
|
| 65 |
+
|
| 66 |
+
import com.linecorp.armeria.common.Flags;
|
| 67 |
+
import com.linecorp.armeria.common.HttpData;
|
| 68 |
+
import com.linecorp.armeria.common.HttpHeaderNames;
|
| 69 |
+
import com.linecorp.armeria.common.HttpHeaders;
|
| 70 |
+
import com.linecorp.armeria.common.HttpHeadersBuilder;
|
| 71 |
+
import com.linecorp.armeria.common.HttpMethod;
|
| 72 |
+
import com.linecorp.armeria.common.HttpStatus;
|
| 73 |
+
import com.linecorp.armeria.common.RequestHeaders;
|
| 74 |
+
import com.linecorp.armeria.common.RequestHeadersBuilder;
|
| 75 |
+
import com.linecorp.armeria.common.ResponseHeaders;
|
| 76 |
+
import com.linecorp.armeria.common.ResponseHeadersBuilder;
|
| 77 |
+
import com.linecorp.armeria.server.ServerConfig;
|
| 78 |
+
|
| 79 |
+
import io.netty.channel.ChannelHandlerContext;
|
| 80 |
+
import io.netty.handler.codec.DefaultHeaders;
|
| 81 |
+
import io.netty.handler.codec.UnsupportedValueConverter;
|
| 82 |
+
import io.netty.handler.codec.http.HttpHeaderValues;
|
| 83 |
+
import io.netty.handler.codec.http.HttpRequest;
|
| 84 |
+
import io.netty.handler.codec.http.HttpResponse;
|
| 85 |
+
import io.netty.handler.codec.http.HttpUtil;
|
| 86 |
+
import io.netty.handler.codec.http.HttpVersion;
|
| 87 |
+
import io.netty.handler.codec.http2.DefaultHttp2Headers;
|
| 88 |
+
import io.netty.handler.codec.http2.Http2Exception;
|
| 89 |
+
import io.netty.handler.codec.http2.Http2Headers;
|
| 90 |
+
import io.netty.handler.codec.http2.HttpConversionUtil;
|
| 91 |
+
import io.netty.handler.codec.http2.HttpConversionUtil.ExtensionHeaderNames;
|
| 92 |
+
import io.netty.util.AsciiString;
|
| 93 |
+
import io.netty.util.HashingStrategy;
|
| 94 |
+
import io.netty.util.internal.StringUtil;
|
| 95 |
+
|
| 96 |
+
/**
|
| 97 |
+
* Provides various utility functions for internal use related with HTTP.
|
| 98 |
+
*
|
| 99 |
+
* <p>The conversion between HTTP/1 and HTTP/2 has been forked from Netty's {@link HttpConversionUtil}.
|
| 100 |
+
*/
|
| 101 |
+
public final class ArmeriaHttpUtil {
|
| 102 |
+
|
| 103 |
+
// Forked from Netty 4.1.34 at 4921f62c8ab8205fd222439dcd1811760b05daf1
|
| 104 |
+
|
| 105 |
+
/**
|
| 106 |
+
* The default case-insensitive {@link AsciiString} hasher and comparator for HTTP/2 headers.
|
| 107 |
+
*/
|
| 108 |
+
private static final HashingStrategy<AsciiString> HTTP2_HEADER_NAME_HASHER =
|
| 109 |
+
new HashingStrategy<AsciiString>() {
|
| 110 |
+
@Override
|
| 111 |
+
public int hashCode(AsciiString o) {
|
| 112 |
+
return o.hashCode();
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
@Override
|
| 116 |
+
public boolean equals(AsciiString a, AsciiString b) {
|
| 117 |
+
return a.contentEqualsIgnoreCase(b);
|
| 118 |
+
}
|
| 119 |
+
};
|
| 120 |
+
|
| 121 |
+
/**
|
| 122 |
+
* The default HTTP content-type charset.
|
| 123 |
+
* See https://tools.ietf.org/html/rfc2616#section-3.7.1
|
| 124 |
+
*/
|
| 125 |
+
public static final Charset HTTP_DEFAULT_CONTENT_CHARSET = StandardCharsets.ISO_8859_1;
|
| 126 |
+
|
| 127 |
+
/**
|
| 128 |
+
* The old {@code "keep-alive"} header which has been superceded by {@code "connection"}.
|
| 129 |
+
*/
|
| 130 |
+
public static final AsciiString HEADER_NAME_KEEP_ALIVE = AsciiString.cached("keep-alive");
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* The old {@code "proxy-connection"} header which has been superceded by {@code "connection"}.
|
| 134 |
+
*/
|
| 135 |
+
public static final AsciiString HEADER_NAME_PROXY_CONNECTION = AsciiString.cached("proxy-connection");
|
| 136 |
+
|
| 137 |
+
private static final URI ROOT = URI.create("/");
|
| 138 |
+
|
| 139 |
+
/**
|
| 140 |
+
* The set of headers that should not be directly copied when converting headers from HTTP/1 to HTTP/2.
|
| 141 |
+
*/
|
| 142 |
+
private static final CharSequenceMap HTTP_TO_HTTP2_HEADER_BLACKLIST = new CharSequenceMap();
|
| 143 |
+
|
| 144 |
+
/**
|
| 145 |
+
* The set of headers that should not be directly copied when converting headers from HTTP/2 to HTTP/1.
|
| 146 |
+
*/
|
| 147 |
+
private static final CharSequenceMap HTTP2_TO_HTTP_HEADER_BLACKLIST = new CharSequenceMap();
|
| 148 |
+
|
| 149 |
+
/**
|
| 150 |
+
* The set of headers that must not be directly copied when converting trailers.
|
| 151 |
+
*/
|
| 152 |
+
private static final CharSequenceMap HTTP_TRAILER_BLACKLIST = new CharSequenceMap();
|
| 153 |
+
|
| 154 |
+
static {
|
| 155 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(HttpHeaderNames.CONNECTION, EMPTY_STRING);
|
| 156 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(HEADER_NAME_KEEP_ALIVE, EMPTY_STRING);
|
| 157 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(HEADER_NAME_PROXY_CONNECTION, EMPTY_STRING);
|
| 158 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(HttpHeaderNames.TRANSFER_ENCODING, EMPTY_STRING);
|
| 159 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(HttpHeaderNames.HOST, EMPTY_STRING);
|
| 160 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(HttpHeaderNames.UPGRADE, EMPTY_STRING);
|
| 161 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(ExtensionHeaderNames.STREAM_ID.text(), EMPTY_STRING);
|
| 162 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(ExtensionHeaderNames.SCHEME.text(), EMPTY_STRING);
|
| 163 |
+
HTTP_TO_HTTP2_HEADER_BLACKLIST.add(ExtensionHeaderNames.PATH.text(), EMPTY_STRING);
|
| 164 |
+
|
| 165 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1.2.3
|
| 166 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(HttpHeaderNames.AUTHORITY, EMPTY_STRING);
|
| 167 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(HttpHeaderNames.METHOD, EMPTY_STRING);
|
| 168 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(HttpHeaderNames.PATH, EMPTY_STRING);
|
| 169 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(HttpHeaderNames.SCHEME, EMPTY_STRING);
|
| 170 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(HttpHeaderNames.STATUS, EMPTY_STRING);
|
| 171 |
+
|
| 172 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1
|
| 173 |
+
// The "chunked" transfer encoding defined in Section 4.1 of [RFC7230] MUST NOT be used in HTTP/2.
|
| 174 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(HttpHeaderNames.TRANSFER_ENCODING, EMPTY_STRING);
|
| 175 |
+
|
| 176 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(ExtensionHeaderNames.STREAM_ID.text(), EMPTY_STRING);
|
| 177 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(ExtensionHeaderNames.SCHEME.text(), EMPTY_STRING);
|
| 178 |
+
HTTP2_TO_HTTP_HEADER_BLACKLIST.add(ExtensionHeaderNames.PATH.text(), EMPTY_STRING);
|
| 179 |
+
|
| 180 |
+
// https://tools.ietf.org/html/rfc7230#section-4.1.2
|
| 181 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1
|
| 182 |
+
// A sender MUST NOT generate a trailer that contains a field necessary for message framing:
|
| 183 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.TRANSFER_ENCODING, EMPTY_STRING);
|
| 184 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.CONTENT_LENGTH, EMPTY_STRING);
|
| 185 |
+
|
| 186 |
+
// for request modifiers:
|
| 187 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.CACHE_CONTROL, EMPTY_STRING);
|
| 188 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.EXPECT, EMPTY_STRING);
|
| 189 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.HOST, EMPTY_STRING);
|
| 190 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.MAX_FORWARDS, EMPTY_STRING);
|
| 191 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.PRAGMA, EMPTY_STRING);
|
| 192 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.RANGE, EMPTY_STRING);
|
| 193 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.TE, EMPTY_STRING);
|
| 194 |
+
|
| 195 |
+
// for authentication:
|
| 196 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.WWW_AUTHENTICATE, EMPTY_STRING);
|
| 197 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.AUTHORIZATION, EMPTY_STRING);
|
| 198 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.PROXY_AUTHENTICATE, EMPTY_STRING);
|
| 199 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.PROXY_AUTHORIZATION, EMPTY_STRING);
|
| 200 |
+
|
| 201 |
+
// for response control data:
|
| 202 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.DATE, EMPTY_STRING);
|
| 203 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.LOCATION, EMPTY_STRING);
|
| 204 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.RETRY_AFTER, EMPTY_STRING);
|
| 205 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.VARY, EMPTY_STRING);
|
| 206 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.WARNING, EMPTY_STRING);
|
| 207 |
+
|
| 208 |
+
// or for determining how to process the payload:
|
| 209 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.CONTENT_ENCODING, EMPTY_STRING);
|
| 210 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.CONTENT_TYPE, EMPTY_STRING);
|
| 211 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.CONTENT_RANGE, EMPTY_STRING);
|
| 212 |
+
HTTP_TRAILER_BLACKLIST.add(HttpHeaderNames.TRAILER, EMPTY_STRING);
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
/**
|
| 216 |
+
* Translations from HTTP/2 header name to the HTTP/1.x equivalent. Currently, we expect these headers to
|
| 217 |
+
* only allow a single value in the request. If adding headers that can potentially have multiple values,
|
| 218 |
+
* please check the usage in code accordingly.
|
| 219 |
+
*/
|
| 220 |
+
private static final CharSequenceMap REQUEST_HEADER_TRANSLATIONS = new CharSequenceMap();
|
| 221 |
+
private static final CharSequenceMap RESPONSE_HEADER_TRANSLATIONS = new CharSequenceMap();
|
| 222 |
+
|
| 223 |
+
static {
|
| 224 |
+
RESPONSE_HEADER_TRANSLATIONS.add(Http2Headers.PseudoHeaderName.AUTHORITY.value(),
|
| 225 |
+
HttpHeaderNames.HOST);
|
| 226 |
+
REQUEST_HEADER_TRANSLATIONS.add(RESPONSE_HEADER_TRANSLATIONS);
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
/**
|
| 230 |
+
* <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.3">rfc7540, 8.1.2.3</a> states the path must not
|
| 231 |
+
* be empty, and instead should be {@code /}.
|
| 232 |
+
*/
|
| 233 |
+
private static final String EMPTY_REQUEST_PATH = "/";
|
| 234 |
+
|
| 235 |
+
private static final Splitter COOKIE_SPLITTER = Splitter.on(';').trimResults().omitEmptyStrings();
|
| 236 |
+
private static final String COOKIE_SEPARATOR = "; ";
|
| 237 |
+
|
| 238 |
+
@Nullable
|
| 239 |
+
private static final LoadingCache<AsciiString, String> HEADER_VALUE_CACHE =
|
| 240 |
+
Flags.headerValueCacheSpec().map(ArmeriaHttpUtil::buildCache).orElse(null);
|
| 241 |
+
private static final Set<AsciiString> CACHED_HEADERS = Flags.cachedHeaders().stream().map(AsciiString::of)
|
| 242 |
+
.collect(toImmutableSet());
|
| 243 |
+
|
| 244 |
+
private static LoadingCache<AsciiString, String> buildCache(String spec) {
|
| 245 |
+
return Caffeine.from(spec).build(AsciiString::toString);
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
/**
|
| 249 |
+
* Concatenates two path strings.
|
| 250 |
+
*/
|
| 251 |
+
public static String concatPaths(@Nullable String path1, @Nullable String path2) {
|
| 252 |
+
path2 = path2 == null ? "" : path2;
|
| 253 |
+
|
| 254 |
+
if (path1 == null || path1.isEmpty() || EMPTY_REQUEST_PATH.equals(path1)) {
|
| 255 |
+
if (path2.isEmpty()) {
|
| 256 |
+
return EMPTY_REQUEST_PATH;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
if (path2.charAt(0) == '/') {
|
| 260 |
+
return path2; // Most requests will land here.
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
return '/' + path2;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
// At this point, we are sure path1 is neither empty nor null.
|
| 267 |
+
if (path2.isEmpty()) {
|
| 268 |
+
// Only path1 is non-empty. No need to concatenate.
|
| 269 |
+
return path1;
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
if (path1.charAt(path1.length() - 1) == '/') {
|
| 273 |
+
if (path2.charAt(0) == '/') {
|
| 274 |
+
// path1 ends with '/' and path2 starts with '/'.
|
| 275 |
+
// Avoid double-slash by stripping the first slash of path2.
|
| 276 |
+
return new StringBuilder(path1.length() + path2.length() - 1)
|
| 277 |
+
.append(path1).append(path2, 1, path2.length()).toString();
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
// path1 ends with '/' and path2 does not start with '/'.
|
| 281 |
+
// Simple concatenation would suffice.
|
| 282 |
+
return path1 + path2;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
if (path2.charAt(0) == '/') {
|
| 286 |
+
// path1 does not end with '/' and path2 starts with '/'.
|
| 287 |
+
// Simple concatenation would suffice.
|
| 288 |
+
return path1 + path2;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
// path1 does not end with '/' and path2 does not start with '/'.
|
| 292 |
+
// Need to insert '/' between path1 and path2.
|
| 293 |
+
return path1 + '/' + path2;
|
| 294 |
+
}
|
| 295 |
+
|
| 296 |
+
/**
|
| 297 |
+
* Decodes a percent-encoded path string.
|
| 298 |
+
*/
|
| 299 |
+
public static String decodePath(String path) {
|
| 300 |
+
if (path.indexOf('%') < 0) {
|
| 301 |
+
// No need to decoded; not percent-encoded
|
| 302 |
+
return path;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Decode percent-encoded characters.
|
| 306 |
+
// An invalid character is replaced with 0xFF, which will be replaced into '�' by UTF-8 decoder.
|
| 307 |
+
final int len = path.length();
|
| 308 |
+
final byte[] buf = ThreadLocalByteArray.get(len);
|
| 309 |
+
int dstLen = 0;
|
| 310 |
+
for (int i = 0; i < len; i++) {
|
| 311 |
+
final char ch = path.charAt(i);
|
| 312 |
+
if (ch != '%') {
|
| 313 |
+
buf[dstLen++] = (byte) ((ch & 0xFF80) == 0 ? ch : 0xFF);
|
| 314 |
+
continue;
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
// Decode a percent-encoded character.
|
| 318 |
+
final int hexEnd = i + 3;
|
| 319 |
+
if (hexEnd > len) {
|
| 320 |
+
// '%' or '%x' (must be followed by two hexadigits)
|
| 321 |
+
buf[dstLen++] = (byte) 0xFF;
|
| 322 |
+
break;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
final int digit1 = decodeHexNibble(path.charAt(++i));
|
| 326 |
+
final int digit2 = decodeHexNibble(path.charAt(++i));
|
| 327 |
+
if (digit1 < 0 || digit2 < 0) {
|
| 328 |
+
// The first or second digit is not hexadecimal.
|
| 329 |
+
buf[dstLen++] = (byte) 0xFF;
|
| 330 |
+
} else {
|
| 331 |
+
buf[dstLen++] = (byte) ((digit1 << 4) | digit2);
|
| 332 |
+
}
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
return new String(buf, 0, dstLen, StandardCharsets.UTF_8);
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
/**
|
| 339 |
+
* Returns {@code true} if the specified {@code path} is an absolute {@code URI}.
|
| 340 |
+
*/
|
| 341 |
+
public static boolean isAbsoluteUri(@Nullable String maybeUri) {
|
| 342 |
+
if (maybeUri == null) {
|
| 343 |
+
return false;
|
| 344 |
+
}
|
| 345 |
+
final int firstColonIdx = maybeUri.indexOf(':');
|
| 346 |
+
if (firstColonIdx <= 0 || firstColonIdx + 3 >= maybeUri.length()) {
|
| 347 |
+
return false;
|
| 348 |
+
}
|
| 349 |
+
final int firstSlashIdx = maybeUri.indexOf('/');
|
| 350 |
+
if (firstSlashIdx <= 0 || firstSlashIdx < firstColonIdx) {
|
| 351 |
+
return false;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
return maybeUri.charAt(firstColonIdx + 1) == '/' && maybeUri.charAt(firstColonIdx + 2) == '/';
|
| 355 |
+
}
|
| 356 |
+
|
| 357 |
+
/**
|
| 358 |
+
* Returns {@code true} if the specified HTTP status string represents an informational status.
|
| 359 |
+
*/
|
| 360 |
+
public static boolean isInformational(@Nullable String statusText) {
|
| 361 |
+
return statusText != null && !statusText.isEmpty() && statusText.charAt(0) == '1';
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
/**
|
| 365 |
+
* Returns {@code true} if the content of the response with the given {@link HttpStatus} is expected to
|
| 366 |
+
* be always empty (1xx, 204, 205 and 304 responses.)
|
| 367 |
+
*
|
| 368 |
+
* @throws IllegalArgumentException if the specified {@code content} or {@code trailers} are
|
| 369 |
+
* non-empty when the content is always empty
|
| 370 |
+
*/
|
| 371 |
+
public static boolean isContentAlwaysEmptyWithValidation(
|
| 372 |
+
HttpStatus status, HttpData content, HttpHeaders trailers) {
|
| 373 |
+
if (!status.isContentAlwaysEmpty()) {
|
| 374 |
+
return false;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
if (!content.isEmpty()) {
|
| 378 |
+
throw new IllegalArgumentException(
|
| 379 |
+
"A " + status + " response must have empty content: " + content.length() + " byte(s)");
|
| 380 |
+
}
|
| 381 |
+
if (!trailers.isEmpty()) {
|
| 382 |
+
throw new IllegalArgumentException(
|
| 383 |
+
"A " + status + " response must not have trailers: " + trailers);
|
| 384 |
+
}
|
| 385 |
+
|
| 386 |
+
return true;
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/**
|
| 390 |
+
* Returns {@code true} if the specified {@code request} is a CORS preflight request.
|
| 391 |
+
*/
|
| 392 |
+
public static boolean isCorsPreflightRequest(com.linecorp.armeria.common.HttpRequest request) {
|
| 393 |
+
requireNonNull(request, "request");
|
| 394 |
+
return request.method() == HttpMethod.OPTIONS &&
|
| 395 |
+
request.headers().contains(HttpHeaderNames.ORIGIN) &&
|
| 396 |
+
request.headers().contains(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD);
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
/**
|
| 400 |
+
* Parses the specified HTTP header directives and invokes the specified {@code callback}
|
| 401 |
+
* with the directive names and values.
|
| 402 |
+
*/
|
| 403 |
+
public static void parseDirectives(String directives, BiConsumer<String, String> callback) {
|
| 404 |
+
final int len = directives.length();
|
| 405 |
+
for (int i = 0; i < len;) {
|
| 406 |
+
final int nameStart = i;
|
| 407 |
+
final String name;
|
| 408 |
+
final String value;
|
| 409 |
+
|
| 410 |
+
// Find the name.
|
| 411 |
+
for (; i < len; i++) {
|
| 412 |
+
final char ch = directives.charAt(i);
|
| 413 |
+
if (ch == ',' || ch == '=') {
|
| 414 |
+
break;
|
| 415 |
+
}
|
| 416 |
+
}
|
| 417 |
+
name = directives.substring(nameStart, i).trim();
|
| 418 |
+
|
| 419 |
+
// Find the value.
|
| 420 |
+
if (i == len || directives.charAt(i) == ',') {
|
| 421 |
+
// Skip comma or go beyond 'len' to break the loop.
|
| 422 |
+
i++;
|
| 423 |
+
value = null;
|
| 424 |
+
} else {
|
| 425 |
+
// Skip '='.
|
| 426 |
+
i++;
|
| 427 |
+
|
| 428 |
+
// Skip whitespaces.
|
| 429 |
+
for (; i < len; i++) {
|
| 430 |
+
final char ch = directives.charAt(i);
|
| 431 |
+
if (ch != ' ' && ch != '\t') {
|
| 432 |
+
break;
|
| 433 |
+
}
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
+
if (i < len && directives.charAt(i) == '\"') {
|
| 437 |
+
// Handle quoted string.
|
| 438 |
+
// Skip the opening quote.
|
| 439 |
+
i++;
|
| 440 |
+
final int valueStart = i;
|
| 441 |
+
|
| 442 |
+
// Find the closing quote.
|
| 443 |
+
for (; i < len; i++) {
|
| 444 |
+
if (directives.charAt(i) == '\"') {
|
| 445 |
+
break;
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
value = directives.substring(valueStart, i);
|
| 449 |
+
|
| 450 |
+
// Skip the closing quote.
|
| 451 |
+
i++;
|
| 452 |
+
|
| 453 |
+
// Find the comma and skip it.
|
| 454 |
+
for (; i < len; i++) {
|
| 455 |
+
if (directives.charAt(i) == ',') {
|
| 456 |
+
i++;
|
| 457 |
+
break;
|
| 458 |
+
}
|
| 459 |
+
}
|
| 460 |
+
} else {
|
| 461 |
+
// Handle unquoted string.
|
| 462 |
+
final int valueStart = i;
|
| 463 |
+
|
| 464 |
+
// Find the comma.
|
| 465 |
+
for (; i < len; i++) {
|
| 466 |
+
if (directives.charAt(i) == ',') {
|
| 467 |
+
break;
|
| 468 |
+
}
|
| 469 |
+
}
|
| 470 |
+
value = directives.substring(valueStart, i).trim();
|
| 471 |
+
|
| 472 |
+
// Skip the comma.
|
| 473 |
+
i++;
|
| 474 |
+
}
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
if (!name.isEmpty()) {
|
| 478 |
+
callback.accept(Ascii.toLowerCase(name), Strings.emptyToNull(value));
|
| 479 |
+
}
|
| 480 |
+
}
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
/**
|
| 484 |
+
* Converts the specified HTTP header directive value into a long integer.
|
| 485 |
+
*
|
| 486 |
+
* @return the converted value if {@code value} is equal to or greater than {@code 0}.
|
| 487 |
+
* {@code -1} otherwise, i.e. if a negative integer or not a number.
|
| 488 |
+
*/
|
| 489 |
+
public static long parseDirectiveValueAsSeconds(@Nullable String value) {
|
| 490 |
+
if (value == null) {
|
| 491 |
+
return -1;
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
try {
|
| 495 |
+
final long converted = Long.parseLong(value);
|
| 496 |
+
return converted >= 0 ? converted : -1;
|
| 497 |
+
} catch (NumberFormatException e) {
|
| 498 |
+
return -1;
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
|
| 502 |
+
/**
|
| 503 |
+
* Converts the specified Netty HTTP/2 into Armeria HTTP/2 {@link RequestHeaders}.
|
| 504 |
+
*/
|
| 505 |
+
public static RequestHeaders toArmeriaRequestHeaders(ChannelHandlerContext ctx, Http2Headers headers,
|
| 506 |
+
boolean endOfStream, String scheme,
|
| 507 |
+
ServerConfig cfg) {
|
| 508 |
+
final RequestHeadersBuilder builder = RequestHeaders.builder();
|
| 509 |
+
toArmeria(builder, headers, endOfStream);
|
| 510 |
+
// A CONNECT request might not have ":scheme". See https://tools.ietf.org/html/rfc7540#section-8.1.2.3
|
| 511 |
+
if (!builder.contains(HttpHeaderNames.SCHEME)) {
|
| 512 |
+
builder.add(HttpHeaderNames.SCHEME, scheme);
|
| 513 |
+
}
|
| 514 |
+
if (!builder.contains(HttpHeaderNames.AUTHORITY)) {
|
| 515 |
+
final String defaultHostname = cfg.defaultVirtualHost().defaultHostname();
|
| 516 |
+
final int port = ((InetSocketAddress) ctx.channel().localAddress()).getPort();
|
| 517 |
+
builder.add(HttpHeaderNames.AUTHORITY, defaultHostname + ':' + port);
|
| 518 |
+
}
|
| 519 |
+
return builder.build();
|
| 520 |
+
}
|
| 521 |
+
|
| 522 |
+
/**
|
| 523 |
+
* Converts the specified Netty HTTP/2 into Armeria HTTP/2 headers.
|
| 524 |
+
*/
|
| 525 |
+
public static HttpHeaders toArmeria(Http2Headers headers, boolean request, boolean endOfStream) {
|
| 526 |
+
final HttpHeadersBuilder builder;
|
| 527 |
+
if (request) {
|
| 528 |
+
builder = headers.contains(HttpHeaderNames.METHOD) ? RequestHeaders.builder()
|
| 529 |
+
: HttpHeaders.builder();
|
| 530 |
+
} else {
|
| 531 |
+
builder = headers.contains(HttpHeaderNames.STATUS) ? ResponseHeaders.builder()
|
| 532 |
+
: HttpHeaders.builder();
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
toArmeria(builder, headers, endOfStream);
|
| 536 |
+
return builder.build();
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
private static void toArmeria(HttpHeadersBuilder builder, Http2Headers headers, boolean endOfStream) {
|
| 540 |
+
builder.sizeHint(headers.size());
|
| 541 |
+
builder.endOfStream(endOfStream);
|
| 542 |
+
|
| 543 |
+
StringJoiner cookieJoiner = null;
|
| 544 |
+
for (Entry<CharSequence, CharSequence> e : headers) {
|
| 545 |
+
final AsciiString name = HttpHeaderNames.of(e.getKey());
|
| 546 |
+
final CharSequence value = e.getValue();
|
| 547 |
+
|
| 548 |
+
// Cookies must be concatenated into a single octet string.
|
| 549 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
| 550 |
+
if (name.equals(HttpHeaderNames.COOKIE)) {
|
| 551 |
+
if (cookieJoiner == null) {
|
| 552 |
+
cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
|
| 553 |
+
}
|
| 554 |
+
COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
|
| 555 |
+
} else {
|
| 556 |
+
builder.add(name, convertHeaderValue(name, value));
|
| 557 |
+
}
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
if (cookieJoiner != null && cookieJoiner.length() != 0) {
|
| 561 |
+
builder.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
|
| 562 |
+
}
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
/**
|
| 566 |
+
* Converts the headers of the given Netty HTTP/1.x request into Armeria HTTP/2 headers.
|
| 567 |
+
* The following headers are only used if they can not be found in the {@code HOST} header or the
|
| 568 |
+
* {@code Request-Line} as defined by <a href="https://tools.ietf.org/html/rfc7230">rfc7230</a>
|
| 569 |
+
* <ul>
|
| 570 |
+
* <li>{@link ExtensionHeaderNames#SCHEME}</li>
|
| 571 |
+
* </ul>
|
| 572 |
+
* {@link ExtensionHeaderNames#PATH} is ignored and instead extracted from the {@code Request-Line}.
|
| 573 |
+
*/
|
| 574 |
+
public static RequestHeaders toArmeria(ChannelHandlerContext ctx, HttpRequest in,
|
| 575 |
+
ServerConfig cfg) throws URISyntaxException {
|
| 576 |
+
final URI requestTargetUri = toUri(in);
|
| 577 |
+
|
| 578 |
+
final io.netty.handler.codec.http.HttpHeaders inHeaders = in.headers();
|
| 579 |
+
final RequestHeadersBuilder out = RequestHeaders.builder();
|
| 580 |
+
out.sizeHint(inHeaders.size());
|
| 581 |
+
out.add(HttpHeaderNames.METHOD, in.method().name());
|
| 582 |
+
out.add(HttpHeaderNames.PATH, toHttp2Path(requestTargetUri));
|
| 583 |
+
|
| 584 |
+
addHttp2Scheme(inHeaders, requestTargetUri, out);
|
| 585 |
+
|
| 586 |
+
if (!isOriginForm(requestTargetUri) && !isAsteriskForm(requestTargetUri)) {
|
| 587 |
+
// Attempt to take from HOST header before taking from the request-line
|
| 588 |
+
final String host = inHeaders.getAsString(HttpHeaderNames.HOST);
|
| 589 |
+
addHttp2Authority(host == null || host.isEmpty() ? requestTargetUri.getAuthority() : host, out);
|
| 590 |
+
}
|
| 591 |
+
|
| 592 |
+
if (out.authority() == null) {
|
| 593 |
+
final String defaultHostname = cfg.defaultVirtualHost().defaultHostname();
|
| 594 |
+
final int port = ((InetSocketAddress) ctx.channel().localAddress()).getPort();
|
| 595 |
+
out.add(HttpHeaderNames.AUTHORITY, defaultHostname + ':' + port);
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
// Add the HTTP headers which have not been consumed above
|
| 599 |
+
toArmeria(inHeaders, out);
|
| 600 |
+
return out.build();
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
+
/**
|
| 604 |
+
* Converts the headers of the given Netty HTTP/1.x response into Armeria HTTP/2 headers.
|
| 605 |
+
*/
|
| 606 |
+
public static ResponseHeaders toArmeria(HttpResponse in) {
|
| 607 |
+
final io.netty.handler.codec.http.HttpHeaders inHeaders = in.headers();
|
| 608 |
+
final ResponseHeadersBuilder out = ResponseHeaders.builder();
|
| 609 |
+
out.sizeHint(inHeaders.size());
|
| 610 |
+
out.add(HttpHeaderNames.STATUS, HttpStatus.valueOf(in.status().code()).codeAsText());
|
| 611 |
+
// Add the HTTP headers which have not been consumed above
|
| 612 |
+
toArmeria(inHeaders, out);
|
| 613 |
+
return out.build();
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
/**
|
| 617 |
+
* Converts the specified Netty HTTP/1 headers into Armeria HTTP/2 headers.
|
| 618 |
+
*/
|
| 619 |
+
public static HttpHeaders toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders) {
|
| 620 |
+
if (inHeaders.isEmpty()) {
|
| 621 |
+
return HttpHeaders.of();
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
final HttpHeadersBuilder out = HttpHeaders.builder();
|
| 625 |
+
out.sizeHint(inHeaders.size());
|
| 626 |
+
toArmeria(inHeaders, out);
|
| 627 |
+
return out.build();
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
/**
|
| 631 |
+
* Converts the specified Netty HTTP/1 headers into Armeria HTTP/2 headers.
|
| 632 |
+
*/
|
| 633 |
+
public static void toArmeria(io.netty.handler.codec.http.HttpHeaders inHeaders, HttpHeadersBuilder out) {
|
| 634 |
+
final Iterator<Entry<CharSequence, CharSequence>> iter = inHeaders.iteratorCharSequence();
|
| 635 |
+
// Choose 8 as a default size because it is unlikely we will see more than 4 Connection headers values,
|
| 636 |
+
// but still allowing for "enough" space in the map to reduce the chance of hash code collision.
|
| 637 |
+
final CharSequenceMap connectionBlacklist =
|
| 638 |
+
toLowercaseMap(inHeaders.valueCharSequenceIterator(HttpHeaderNames.CONNECTION), 8);
|
| 639 |
+
StringJoiner cookieJoiner = null;
|
| 640 |
+
while (iter.hasNext()) {
|
| 641 |
+
final Entry<CharSequence, CharSequence> entry = iter.next();
|
| 642 |
+
final AsciiString aName = HttpHeaderNames.of(entry.getKey()).toLowerCase();
|
| 643 |
+
if (HTTP_TO_HTTP2_HEADER_BLACKLIST.contains(aName) || connectionBlacklist.contains(aName)) {
|
| 644 |
+
continue;
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1.2.2 makes a special exception for TE
|
| 648 |
+
if (aName.equals(HttpHeaderNames.TE)) {
|
| 649 |
+
toHttp2HeadersFilterTE(entry, out);
|
| 650 |
+
continue;
|
| 651 |
+
}
|
| 652 |
+
|
| 653 |
+
// Cookies must be concatenated into a single octet string.
|
| 654 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
| 655 |
+
final CharSequence value = entry.getValue();
|
| 656 |
+
if (aName.equals(HttpHeaderNames.COOKIE)) {
|
| 657 |
+
if (cookieJoiner == null) {
|
| 658 |
+
cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
|
| 659 |
+
}
|
| 660 |
+
COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
|
| 661 |
+
} else {
|
| 662 |
+
out.add(aName, convertHeaderValue(aName, value));
|
| 663 |
+
}
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
if (cookieJoiner != null && cookieJoiner.length() != 0) {
|
| 667 |
+
out.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
|
| 668 |
+
}
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
private static CharSequenceMap toLowercaseMap(Iterator<? extends CharSequence> valuesIter,
|
| 672 |
+
int arraySizeHint) {
|
| 673 |
+
final CharSequenceMap result = new CharSequenceMap(arraySizeHint);
|
| 674 |
+
|
| 675 |
+
while (valuesIter.hasNext()) {
|
| 676 |
+
// BUG: CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')
|
| 677 |
+
// final AsciiString lowerCased = HttpHeaderNames.of(valuesIter.next()).toLowerCase();
|
| 678 |
+
// FIXED:
|
| 679 |
+
final AsciiString lowerCased = AsciiString.of(valuesIter.next()).toLowerCase();
|
| 680 |
+
try {
|
| 681 |
+
int index = lowerCased.forEachByte(FIND_COMMA);
|
| 682 |
+
if (index != -1) {
|
| 683 |
+
int start = 0;
|
| 684 |
+
do {
|
| 685 |
+
result.add(lowerCased.subSequence(start, index, false).trim(), EMPTY_STRING);
|
| 686 |
+
start = index + 1;
|
| 687 |
+
} while (start < lowerCased.length() &&
|
| 688 |
+
(index = lowerCased.forEachByte(start,
|
| 689 |
+
lowerCased.length() - start, FIND_COMMA)) != -1);
|
| 690 |
+
result.add(lowerCased.subSequence(start, lowerCased.length(), false).trim(), EMPTY_STRING);
|
| 691 |
+
} else {
|
| 692 |
+
result.add(lowerCased.trim(), EMPTY_STRING);
|
| 693 |
+
}
|
| 694 |
+
} catch (Exception e) {
|
| 695 |
+
// This is not expect to happen because FIND_COMMA never throws but must be caught
|
| 696 |
+
// because of the ByteProcessor interface.
|
| 697 |
+
throw new IllegalStateException(e);
|
| 698 |
+
}
|
| 699 |
+
}
|
| 700 |
+
return result;
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
/**
|
| 704 |
+
* Filter the {@link HttpHeaderNames#TE} header according to the
|
| 705 |
+
* <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>.
|
| 706 |
+
* @param entry An entry whose name is {@link HttpHeaderNames#TE}.
|
| 707 |
+
* @param out the resulting HTTP/2 headers.
|
| 708 |
+
*/
|
| 709 |
+
private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry,
|
| 710 |
+
HttpHeadersBuilder out) {
|
| 711 |
+
if (AsciiString.indexOf(entry.getValue(), ',', 0) == -1) {
|
| 712 |
+
if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(entry.getValue()),
|
| 713 |
+
HttpHeaderValues.TRAILERS)) {
|
| 714 |
+
out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString());
|
| 715 |
+
}
|
| 716 |
+
} else {
|
| 717 |
+
final List<CharSequence> teValues = StringUtil.unescapeCsvFields(entry.getValue());
|
| 718 |
+
for (CharSequence teValue : teValues) {
|
| 719 |
+
if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(teValue),
|
| 720 |
+
HttpHeaderValues.TRAILERS)) {
|
| 721 |
+
out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString());
|
| 722 |
+
break;
|
| 723 |
+
}
|
| 724 |
+
}
|
| 725 |
+
}
|
| 726 |
+
}
|
| 727 |
+
|
| 728 |
+
private static URI toUri(HttpRequest in) throws URISyntaxException {
|
| 729 |
+
final String uri = in.uri();
|
| 730 |
+
if (uri.startsWith("//")) {
|
| 731 |
+
// Normalize the path that starts with more than one slash into the one with a single slash,
|
| 732 |
+
// so that java.net.URI does not raise a URISyntaxException.
|
| 733 |
+
for (int i = 0; i < uri.length(); i++) {
|
| 734 |
+
if (uri.charAt(i) != '/') {
|
| 735 |
+
return new URI(uri.substring(i - 1));
|
| 736 |
+
}
|
| 737 |
+
}
|
| 738 |
+
return ROOT;
|
| 739 |
+
} else {
|
| 740 |
+
return new URI(uri);
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
+
/**
|
| 745 |
+
* Generate a HTTP/2 {code :path} from a URI in accordance with
|
| 746 |
+
* <a href="https://tools.ietf.org/html/rfc7230#section-5.3">rfc7230, 5.3</a>.
|
| 747 |
+
*/
|
| 748 |
+
private static String toHttp2Path(URI uri) {
|
| 749 |
+
final StringBuilder pathBuilder = new StringBuilder(
|
| 750 |
+
length(uri.getRawPath()) + length(uri.getRawQuery()) + length(uri.getRawFragment()) + 2);
|
| 751 |
+
|
| 752 |
+
if (!isNullOrEmpty(uri.getRawPath())) {
|
| 753 |
+
pathBuilder.append(uri.getRawPath());
|
| 754 |
+
}
|
| 755 |
+
if (!isNullOrEmpty(uri.getRawQuery())) {
|
| 756 |
+
pathBuilder.append('?');
|
| 757 |
+
pathBuilder.append(uri.getRawQuery());
|
| 758 |
+
}
|
| 759 |
+
if (!isNullOrEmpty(uri.getRawFragment())) {
|
| 760 |
+
pathBuilder.append('#');
|
| 761 |
+
pathBuilder.append(uri.getRawFragment());
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
return pathBuilder.length() != 0 ? pathBuilder.toString() : EMPTY_REQUEST_PATH;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
@VisibleForTesting
|
| 768 |
+
static void addHttp2Authority(@Nullable String authority, RequestHeadersBuilder out) {
|
| 769 |
+
// The authority MUST NOT include the deprecated "userinfo" subcomponent
|
| 770 |
+
if (authority != null) {
|
| 771 |
+
final String actualAuthority;
|
| 772 |
+
if (authority.isEmpty()) {
|
| 773 |
+
actualAuthority = "";
|
| 774 |
+
} else {
|
| 775 |
+
final int start = authority.indexOf('@') + 1;
|
| 776 |
+
if (start == 0) {
|
| 777 |
+
actualAuthority = authority;
|
| 778 |
+
} else if (authority.length() == start) {
|
| 779 |
+
throw new IllegalArgumentException("authority: " + authority);
|
| 780 |
+
} else {
|
| 781 |
+
actualAuthority = authority.substring(start);
|
| 782 |
+
}
|
| 783 |
+
}
|
| 784 |
+
out.add(HttpHeaderNames.AUTHORITY, actualAuthority);
|
| 785 |
+
}
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
private static void addHttp2Scheme(io.netty.handler.codec.http.HttpHeaders in, URI uri,
|
| 789 |
+
RequestHeadersBuilder out) {
|
| 790 |
+
final String value = uri.getScheme();
|
| 791 |
+
if (value != null) {
|
| 792 |
+
out.add(HttpHeaderNames.SCHEME, value);
|
| 793 |
+
return;
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
// Consume the Scheme extension header if present
|
| 797 |
+
final CharSequence cValue = in.get(ExtensionHeaderNames.SCHEME.text());
|
| 798 |
+
if (cValue != null) {
|
| 799 |
+
out.add(HttpHeaderNames.SCHEME, cValue.toString());
|
| 800 |
+
} else {
|
| 801 |
+
out.add(HttpHeaderNames.SCHEME, "unknown");
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
/**
|
| 806 |
+
* Converts the specified Armeria HTTP/2 headers into Netty HTTP/2 headers.
|
| 807 |
+
*/
|
| 808 |
+
public static Http2Headers toNettyHttp2(HttpHeaders in, boolean server) {
|
| 809 |
+
final Http2Headers out = new DefaultHttp2Headers(false, in.size());
|
| 810 |
+
|
| 811 |
+
// Trailers if it does not have :status.
|
| 812 |
+
if (server && !in.contains(HttpHeaderNames.STATUS)) {
|
| 813 |
+
for (Entry<AsciiString, String> entry : in) {
|
| 814 |
+
final AsciiString name = entry.getKey();
|
| 815 |
+
final String value = entry.getValue();
|
| 816 |
+
if (name.isEmpty() || isTrailerBlacklisted(name)) {
|
| 817 |
+
continue;
|
| 818 |
+
}
|
| 819 |
+
out.add(name, value);
|
| 820 |
+
}
|
| 821 |
+
} else {
|
| 822 |
+
in.forEach((BiConsumer<AsciiString, String>) out::add);
|
| 823 |
+
out.remove(HttpHeaderNames.CONNECTION);
|
| 824 |
+
out.remove(HttpHeaderNames.TRANSFER_ENCODING);
|
| 825 |
+
}
|
| 826 |
+
|
| 827 |
+
if (!out.contains(HttpHeaderNames.COOKIE)) {
|
| 828 |
+
return out;
|
| 829 |
+
}
|
| 830 |
+
|
| 831 |
+
// Split up cookies to allow for better compression.
|
| 832 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
| 833 |
+
final List<CharSequence> cookies = out.getAllAndRemove(HttpHeaderNames.COOKIE);
|
| 834 |
+
for (CharSequence c : cookies) {
|
| 835 |
+
out.add(HttpHeaderNames.COOKIE, COOKIE_SPLITTER.split(c));
|
| 836 |
+
}
|
| 837 |
+
|
| 838 |
+
return out;
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
/**
|
| 842 |
+
* Translate and add HTTP/2 headers to HTTP/1.x headers.
|
| 843 |
+
*
|
| 844 |
+
* @param streamId The stream associated with {@code sourceHeaders}.
|
| 845 |
+
* @param inputHeaders The HTTP/2 headers to convert.
|
| 846 |
+
* @param outputHeaders The object which will contain the resulting HTTP/1.x headers..
|
| 847 |
+
* @param httpVersion What HTTP/1.x version {@code outputHeaders} should be treated as
|
| 848 |
+
* when doing the conversion.
|
| 849 |
+
* @param isTrailer {@code true} if {@code outputHeaders} should be treated as trailers.
|
| 850 |
+
* {@code false} otherwise.
|
| 851 |
+
* @param isRequest {@code true} if the {@code outputHeaders} will be used in a request message.
|
| 852 |
+
* {@code false} for response message.
|
| 853 |
+
*
|
| 854 |
+
* @throws Http2Exception If not all HTTP/2 headers can be translated to HTTP/1.x.
|
| 855 |
+
*/
|
| 856 |
+
public static void toNettyHttp1(
|
| 857 |
+
int streamId, HttpHeaders inputHeaders, io.netty.handler.codec.http.HttpHeaders outputHeaders,
|
| 858 |
+
HttpVersion httpVersion, boolean isTrailer, boolean isRequest) throws Http2Exception {
|
| 859 |
+
|
| 860 |
+
final CharSequenceMap translations = isRequest ? REQUEST_HEADER_TRANSLATIONS
|
| 861 |
+
: RESPONSE_HEADER_TRANSLATIONS;
|
| 862 |
+
StringJoiner cookieJoiner = null;
|
| 863 |
+
try {
|
| 864 |
+
for (Entry<AsciiString, String> entry : inputHeaders) {
|
| 865 |
+
final AsciiString name = entry.getKey();
|
| 866 |
+
final String value = entry.getValue();
|
| 867 |
+
final AsciiString translatedName = translations.get(name);
|
| 868 |
+
if (translatedName != null && !inputHeaders.contains(translatedName)) {
|
| 869 |
+
outputHeaders.add(translatedName, value);
|
| 870 |
+
continue;
|
| 871 |
+
}
|
| 872 |
+
|
| 873 |
+
if (name.isEmpty() || HTTP2_TO_HTTP_HEADER_BLACKLIST.contains(name)) {
|
| 874 |
+
continue;
|
| 875 |
+
}
|
| 876 |
+
|
| 877 |
+
if (isTrailer && isTrailerBlacklisted(name)) {
|
| 878 |
+
continue;
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
if (HttpHeaderNames.COOKIE.equals(name)) {
|
| 882 |
+
// combine the cookie values into 1 header entry.
|
| 883 |
+
// https://tools.ietf.org/html/rfc7540#section-8.1.2.5
|
| 884 |
+
if (cookieJoiner == null) {
|
| 885 |
+
cookieJoiner = new StringJoiner(COOKIE_SEPARATOR);
|
| 886 |
+
}
|
| 887 |
+
COOKIE_SPLITTER.split(value).forEach(cookieJoiner::add);
|
| 888 |
+
} else {
|
| 889 |
+
outputHeaders.add(name, value);
|
| 890 |
+
}
|
| 891 |
+
}
|
| 892 |
+
|
| 893 |
+
if (cookieJoiner != null && cookieJoiner.length() != 0) {
|
| 894 |
+
outputHeaders.add(HttpHeaderNames.COOKIE, cookieJoiner.toString());
|
| 895 |
+
}
|
| 896 |
+
} catch (Throwable t) {
|
| 897 |
+
throw streamError(streamId, PROTOCOL_ERROR, t, "HTTP/2 to HTTP/1.x headers conversion error");
|
| 898 |
+
}
|
| 899 |
+
|
| 900 |
+
if (!isTrailer) {
|
| 901 |
+
HttpUtil.setKeepAlive(outputHeaders, httpVersion, true);
|
| 902 |
+
}
|
| 903 |
+
}
|
| 904 |
+
|
| 905 |
+
/**
|
| 906 |
+
* Returns a {@link ResponseHeaders} whose {@link HttpHeaderNames#CONTENT_LENGTH} is added or removed
|
| 907 |
+
* according to the status of the specified {@code headers}, {@code content} and {@code trailers}.
|
| 908 |
+
* The {@link HttpHeaderNames#CONTENT_LENGTH} is removed when:
|
| 909 |
+
* <ul>
|
| 910 |
+
* <li>the status of the specified {@code headers} is one of informational headers,
|
| 911 |
+
* {@link HttpStatus#NO_CONTENT} or {@link HttpStatus#RESET_CONTENT}</li>
|
| 912 |
+
* <li>the trailers exists</li>
|
| 913 |
+
* </ul>
|
| 914 |
+
* The {@link HttpHeaderNames#CONTENT_LENGTH} is added when the state of the specified {@code headers}
|
| 915 |
+
* does not meet the conditions above and {@link HttpHeaderNames#CONTENT_LENGTH} is not present
|
| 916 |
+
* regardless of the fact that the content is empty or not.
|
| 917 |
+
*
|
| 918 |
+
* @throws IllegalArgumentException if the specified {@code content} or {@code trailers} are
|
| 919 |
+
* non-empty when the content is always empty
|
| 920 |
+
*/
|
| 921 |
+
public static ResponseHeaders setOrRemoveContentLength(ResponseHeaders headers, HttpData content,
|
| 922 |
+
HttpHeaders trailers) {
|
| 923 |
+
requireNonNull(headers, "headers");
|
| 924 |
+
requireNonNull(content, "content");
|
| 925 |
+
requireNonNull(trailers, "trailers");
|
| 926 |
+
|
| 927 |
+
final HttpStatus status = headers.status();
|
| 928 |
+
|
| 929 |
+
if (isContentAlwaysEmptyWithValidation(status, content, trailers)) {
|
| 930 |
+
if (status != HttpStatus.NOT_MODIFIED) {
|
| 931 |
+
if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
|
| 932 |
+
final ResponseHeadersBuilder builder = headers.toBuilder();
|
| 933 |
+
builder.remove(HttpHeaderNames.CONTENT_LENGTH);
|
| 934 |
+
return builder.build();
|
| 935 |
+
}
|
| 936 |
+
} else {
|
| 937 |
+
// 304 response can have the "content-length" header when it is a response to a conditional
|
| 938 |
+
// GET request. See https://tools.ietf.org/html/rfc7230#section-3.3.2
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
return headers;
|
| 942 |
+
}
|
| 943 |
+
|
| 944 |
+
if (!trailers.isEmpty()) {
|
| 945 |
+
// Some of the client implementations such as "curl" ignores trailers if
|
| 946 |
+
// the "content-length" header is present. We should not set "content-length" header when
|
| 947 |
+
// trailers exists so that those clients can receive the trailers.
|
| 948 |
+
// The response is sent using chunked transfer encoding in HTTP/1 or a DATA frame payload
|
| 949 |
+
// in HTTP/2, so it's no worry.
|
| 950 |
+
if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
|
| 951 |
+
final ResponseHeadersBuilder builder = headers.toBuilder();
|
| 952 |
+
builder.remove(HttpHeaderNames.CONTENT_LENGTH);
|
| 953 |
+
return builder.build();
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
return headers;
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH) || !content.isEmpty()) {
|
| 960 |
+
return headers.toBuilder()
|
| 961 |
+
.setInt(HttpHeaderNames.CONTENT_LENGTH, content.length())
|
| 962 |
+
.build();
|
| 963 |
+
}
|
| 964 |
+
|
| 965 |
+
// The header contains "content-length" header and the content is empty.
|
| 966 |
+
// Do not overwrite the header because a response to a HEAD request
|
| 967 |
+
// will have no content even if it has non-zero content-length header.
|
| 968 |
+
return headers;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
private static String convertHeaderValue(AsciiString name, CharSequence value) {
|
| 972 |
+
if (!(value instanceof AsciiString)) {
|
| 973 |
+
return value.toString();
|
| 974 |
+
}
|
| 975 |
+
if (HEADER_VALUE_CACHE != null && CACHED_HEADERS.contains(name)) {
|
| 976 |
+
final String converted = HEADER_VALUE_CACHE.get((AsciiString) value);
|
| 977 |
+
assert converted != null; // loader does not return null.
|
| 978 |
+
return converted;
|
| 979 |
+
}
|
| 980 |
+
return value.toString();
|
| 981 |
+
}
|
| 982 |
+
|
| 983 |
+
/**
|
| 984 |
+
* Returns {@code true} if the specified header name is not allowed for HTTP tailers.
|
| 985 |
+
*/
|
| 986 |
+
public static boolean isTrailerBlacklisted(AsciiString name) {
|
| 987 |
+
return HTTP_TRAILER_BLACKLIST.contains(name);
|
| 988 |
+
}
|
| 989 |
+
|
| 990 |
+
private static final class CharSequenceMap
|
| 991 |
+
extends DefaultHeaders<AsciiString, AsciiString, CharSequenceMap> {
|
| 992 |
+
|
| 993 |
+
CharSequenceMap() {
|
| 994 |
+
super(HTTP2_HEADER_NAME_HASHER, UnsupportedValueConverter.instance());
|
| 995 |
+
}
|
| 996 |
+
|
| 997 |
+
@SuppressWarnings("unchecked")
|
| 998 |
+
CharSequenceMap(int size) {
|
| 999 |
+
super(HTTP2_HEADER_NAME_HASHER, UnsupportedValueConverter.instance(), NameValidator.NOT_NULL, size);
|
| 1000 |
+
}
|
| 1001 |
+
}
|
| 1002 |
+
|
| 1003 |
+
private ArmeriaHttpUtil() {}
|
| 1004 |
+
}
|
Java/AuthenticationProcessingFilter2.java
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* The MIT License
|
| 3 |
+
*
|
| 4 |
+
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Matthew R. Harrah
|
| 5 |
+
*
|
| 6 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
* in the Software without restriction, including without limitation the rights
|
| 9 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
* furnished to do so, subject to the following conditions:
|
| 12 |
+
*
|
| 13 |
+
* The above copyright notice and this permission notice shall be included in
|
| 14 |
+
* all copies or substantial portions of the Software.
|
| 15 |
+
*
|
| 16 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 22 |
+
* THE SOFTWARE.
|
| 23 |
+
*/
|
| 24 |
+
package hudson.security;
|
| 25 |
+
|
| 26 |
+
import java.util.Properties;
|
| 27 |
+
import java.util.logging.Logger;
|
| 28 |
+
import java.util.logging.Level;
|
| 29 |
+
import java.io.IOException;
|
| 30 |
+
|
| 31 |
+
import javax.servlet.http.HttpServletRequest;
|
| 32 |
+
import javax.servlet.http.HttpServletResponse;
|
| 33 |
+
|
| 34 |
+
import hudson.Util;
|
| 35 |
+
import org.acegisecurity.Authentication;
|
| 36 |
+
import org.acegisecurity.AuthenticationException;
|
| 37 |
+
import org.acegisecurity.ui.webapp.AuthenticationProcessingFilter;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* {@link AuthenticationProcessingFilter} with a change for Jenkins so that
|
| 41 |
+
* we can pick up the hidden "from" form field defined in <tt>login.jelly</tt>
|
| 42 |
+
* to send the user back to where he came from, after a successful authentication.
|
| 43 |
+
*
|
| 44 |
+
* @author Kohsuke Kawaguchi
|
| 45 |
+
*/
|
| 46 |
+
public class AuthenticationProcessingFilter2 extends AuthenticationProcessingFilter {
|
| 47 |
+
@Override
|
| 48 |
+
protected String determineTargetUrl(HttpServletRequest request) {
|
| 49 |
+
String targetUrl = request.getParameter("from");
|
| 50 |
+
request.getSession().setAttribute("from", targetUrl);
|
| 51 |
+
|
| 52 |
+
if (targetUrl == null)
|
| 53 |
+
return getDefaultTargetUrl();
|
| 54 |
+
|
| 55 |
+
if (Util.isAbsoluteUri(targetUrl))
|
| 56 |
+
return "."; // avoid open redirect
|
| 57 |
+
|
| 58 |
+
// URL returned from determineTargetUrl() is resolved against the context path,
|
| 59 |
+
// whereas the "from" URL is resolved against the top of the website, so adjust this.
|
| 60 |
+
if(targetUrl.startsWith(request.getContextPath()))
|
| 61 |
+
return targetUrl.substring(request.getContextPath().length());
|
| 62 |
+
|
| 63 |
+
// not sure when this happens, but apparently this happens in some case.
|
| 64 |
+
// see #1274
|
| 65 |
+
return targetUrl;
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
/**
|
| 69 |
+
* @see org.acegisecurity.ui.AbstractProcessingFilter#determineFailureUrl(javax.servlet.http.HttpServletRequest, org.acegisecurity.AuthenticationException)
|
| 70 |
+
*/
|
| 71 |
+
@Override
|
| 72 |
+
protected String determineFailureUrl(HttpServletRequest request, AuthenticationException failed) {
|
| 73 |
+
Properties excMap = getExceptionMappings();
|
| 74 |
+
String failedClassName = failed.getClass().getName();
|
| 75 |
+
String whereFrom = request.getParameter("from");
|
| 76 |
+
request.getSession().setAttribute("from", whereFrom);
|
| 77 |
+
return excMap.getProperty(failedClassName, getAuthenticationFailureUrl());
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
@Override
|
| 81 |
+
protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
|
| 82 |
+
super.onSuccessfulAuthentication(request,response,authResult);
|
| 83 |
+
// make sure we have a session to store this successful authentication, given that we no longer
|
| 84 |
+
// let HttpSessionContextIntegrationFilter2 to create sessions.
|
| 85 |
+
// HttpSessionContextIntegrationFilter stores the updated SecurityContext object into this session later
|
| 86 |
+
// (either when a redirect is issued, via its HttpResponseWrapper, or when the execution returns to its
|
| 87 |
+
// doFilter method.
|
| 88 |
+
// BUG: CWE-287 Improper Authentication
|
| 89 |
+
//
|
| 90 |
+
// FIXED:
|
| 91 |
+
request.getSession().invalidate();
|
| 92 |
+
request.getSession();
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
/**
|
| 96 |
+
* Leave the information about login failure.
|
| 97 |
+
*
|
| 98 |
+
* <p>
|
| 99 |
+
* Otherwise it seems like Acegi doesn't really leave the detail of the failure anywhere.
|
| 100 |
+
*/
|
| 101 |
+
@Override
|
| 102 |
+
protected void onUnsuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, AuthenticationException failed) throws IOException {
|
| 103 |
+
super.onUnsuccessfulAuthentication(request, response, failed);
|
| 104 |
+
LOGGER.log(Level.INFO, "Login attempt failed", failed);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
private static final Logger LOGGER = Logger.getLogger(AuthenticationProcessingFilter2.class.getName());
|
| 108 |
+
}
|
Java/BCXMSSMTPrivateKey.java
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.bouncycastle.pqc.jcajce.provider.xmss;
|
| 2 |
+
|
| 3 |
+
import java.io.IOException;
|
| 4 |
+
import java.security.PrivateKey;
|
| 5 |
+
|
| 6 |
+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
| 7 |
+
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
| 8 |
+
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
| 9 |
+
import org.bouncycastle.crypto.CipherParameters;
|
| 10 |
+
import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
|
| 11 |
+
import org.bouncycastle.pqc.asn1.XMSSMTKeyParams;
|
| 12 |
+
import org.bouncycastle.pqc.asn1.XMSSMTPrivateKey;
|
| 13 |
+
import org.bouncycastle.pqc.asn1.XMSSPrivateKey;
|
| 14 |
+
import org.bouncycastle.pqc.crypto.xmss.BDSStateMap;
|
| 15 |
+
import org.bouncycastle.pqc.crypto.xmss.XMSSMTParameters;
|
| 16 |
+
import org.bouncycastle.pqc.crypto.xmss.XMSSMTPrivateKeyParameters;
|
| 17 |
+
import org.bouncycastle.pqc.crypto.xmss.XMSSUtil;
|
| 18 |
+
import org.bouncycastle.pqc.jcajce.interfaces.XMSSMTKey;
|
| 19 |
+
import org.bouncycastle.util.Arrays;
|
| 20 |
+
|
| 21 |
+
public class BCXMSSMTPrivateKey
|
| 22 |
+
implements PrivateKey, XMSSMTKey
|
| 23 |
+
{
|
| 24 |
+
private final ASN1ObjectIdentifier treeDigest;
|
| 25 |
+
private final XMSSMTPrivateKeyParameters keyParams;
|
| 26 |
+
|
| 27 |
+
public BCXMSSMTPrivateKey(
|
| 28 |
+
ASN1ObjectIdentifier treeDigest,
|
| 29 |
+
XMSSMTPrivateKeyParameters keyParams)
|
| 30 |
+
{
|
| 31 |
+
this.treeDigest = treeDigest;
|
| 32 |
+
this.keyParams = keyParams;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
public BCXMSSMTPrivateKey(PrivateKeyInfo keyInfo)
|
| 36 |
+
throws IOException
|
| 37 |
+
{
|
| 38 |
+
XMSSMTKeyParams keyParams = XMSSMTKeyParams.getInstance(keyInfo.getPrivateKeyAlgorithm().getParameters());
|
| 39 |
+
this.treeDigest = keyParams.getTreeDigest().getAlgorithm();
|
| 40 |
+
|
| 41 |
+
XMSSPrivateKey xmssMtPrivateKey = XMSSPrivateKey.getInstance(keyInfo.parsePrivateKey());
|
| 42 |
+
|
| 43 |
+
try
|
| 44 |
+
{
|
| 45 |
+
XMSSMTPrivateKeyParameters.Builder keyBuilder = new XMSSMTPrivateKeyParameters
|
| 46 |
+
.Builder(new XMSSMTParameters(keyParams.getHeight(), keyParams.getLayers(), DigestUtil.getDigest(treeDigest)))
|
| 47 |
+
.withIndex(xmssMtPrivateKey.getIndex())
|
| 48 |
+
.withSecretKeySeed(xmssMtPrivateKey.getSecretKeySeed())
|
| 49 |
+
.withSecretKeyPRF(xmssMtPrivateKey.getSecretKeyPRF())
|
| 50 |
+
.withPublicSeed(xmssMtPrivateKey.getPublicSeed())
|
| 51 |
+
.withRoot(xmssMtPrivateKey.getRoot());
|
| 52 |
+
|
| 53 |
+
if (xmssMtPrivateKey.getBdsState() != null)
|
| 54 |
+
{
|
| 55 |
+
// BUG: CWE-470 Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')
|
| 56 |
+
// keyBuilder.withBDSState((BDSStateMap)XMSSUtil.deserialize(xmssMtPrivateKey.getBdsState()));
|
| 57 |
+
// FIXED:
|
| 58 |
+
keyBuilder.withBDSState((BDSStateMap)XMSSUtil.deserialize(xmssMtPrivateKey.getBdsState(), BDSStateMap.class));
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
this.keyParams = keyBuilder.build();
|
| 62 |
+
}
|
| 63 |
+
catch (ClassNotFoundException e)
|
| 64 |
+
{
|
| 65 |
+
throw new IOException("ClassNotFoundException processing BDS state: " + e.getMessage());
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
public String getAlgorithm()
|
| 70 |
+
{
|
| 71 |
+
return "XMSSMT";
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
public String getFormat()
|
| 75 |
+
{
|
| 76 |
+
return "PKCS#8";
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
public byte[] getEncoded()
|
| 80 |
+
{
|
| 81 |
+
PrivateKeyInfo pki;
|
| 82 |
+
try
|
| 83 |
+
{
|
| 84 |
+
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.xmss_mt, new XMSSMTKeyParams(keyParams.getParameters().getHeight(), keyParams.getParameters().getLayers(), new AlgorithmIdentifier(treeDigest)));
|
| 85 |
+
pki = new PrivateKeyInfo(algorithmIdentifier, createKeyStructure());
|
| 86 |
+
|
| 87 |
+
return pki.getEncoded();
|
| 88 |
+
}
|
| 89 |
+
catch (IOException e)
|
| 90 |
+
{
|
| 91 |
+
return null;
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
CipherParameters getKeyParams()
|
| 96 |
+
{
|
| 97 |
+
return keyParams;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
public boolean equals(Object o)
|
| 101 |
+
{
|
| 102 |
+
if (o == this)
|
| 103 |
+
{
|
| 104 |
+
return true;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
if (o instanceof BCXMSSMTPrivateKey)
|
| 108 |
+
{
|
| 109 |
+
BCXMSSMTPrivateKey otherKey = (BCXMSSMTPrivateKey)o;
|
| 110 |
+
|
| 111 |
+
return treeDigest.equals(otherKey.treeDigest) && Arrays.areEqual(keyParams.toByteArray(), otherKey.keyParams.toByteArray());
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
return false;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
public int hashCode()
|
| 118 |
+
{
|
| 119 |
+
return treeDigest.hashCode() + 37 * Arrays.hashCode(keyParams.toByteArray());
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
private XMSSMTPrivateKey createKeyStructure()
|
| 123 |
+
{
|
| 124 |
+
byte[] keyData = keyParams.toByteArray();
|
| 125 |
+
|
| 126 |
+
int n = keyParams.getParameters().getDigestSize();
|
| 127 |
+
int totalHeight = keyParams.getParameters().getHeight();
|
| 128 |
+
int indexSize = (totalHeight + 7) / 8;
|
| 129 |
+
int secretKeySize = n;
|
| 130 |
+
int secretKeyPRFSize = n;
|
| 131 |
+
int publicSeedSize = n;
|
| 132 |
+
int rootSize = n;
|
| 133 |
+
|
| 134 |
+
int position = 0;
|
| 135 |
+
int index = (int)XMSSUtil.bytesToXBigEndian(keyData, position, indexSize);
|
| 136 |
+
if (!XMSSUtil.isIndexValid(totalHeight, index))
|
| 137 |
+
{
|
| 138 |
+
throw new IllegalArgumentException("index out of bounds");
|
| 139 |
+
}
|
| 140 |
+
position += indexSize;
|
| 141 |
+
byte[] secretKeySeed = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeySize);
|
| 142 |
+
position += secretKeySize;
|
| 143 |
+
byte[] secretKeyPRF = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeyPRFSize);
|
| 144 |
+
position += secretKeyPRFSize;
|
| 145 |
+
byte[] publicSeed = XMSSUtil.extractBytesAtOffset(keyData, position, publicSeedSize);
|
| 146 |
+
position += publicSeedSize;
|
| 147 |
+
byte[] root = XMSSUtil.extractBytesAtOffset(keyData, position, rootSize);
|
| 148 |
+
position += rootSize;
|
| 149 |
+
/* import BDS state */
|
| 150 |
+
byte[] bdsStateBinary = XMSSUtil.extractBytesAtOffset(keyData, position, keyData.length - position);
|
| 151 |
+
|
| 152 |
+
return new XMSSMTPrivateKey(index, secretKeySeed, secretKeyPRF, publicSeed, root, bdsStateBinary);
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
ASN1ObjectIdentifier getTreeDigestOID()
|
| 156 |
+
{
|
| 157 |
+
return treeDigest;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
public int getHeight()
|
| 161 |
+
{
|
| 162 |
+
return keyParams.getParameters().getHeight();
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
public int getLayers()
|
| 166 |
+
{
|
| 167 |
+
return keyParams.getParameters().getLayers();
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
public String getTreeDigest()
|
| 171 |
+
{
|
| 172 |
+
return DigestUtil.getXMSSDigestName(treeDigest);
|
| 173 |
+
}
|
| 174 |
+
}
|
Java/BCXMSSPrivateKey.java
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.bouncycastle.pqc.jcajce.provider.xmss;
|
| 2 |
+
|
| 3 |
+
import java.io.IOException;
|
| 4 |
+
import java.security.PrivateKey;
|
| 5 |
+
|
| 6 |
+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
| 7 |
+
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
| 8 |
+
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
| 9 |
+
import org.bouncycastle.crypto.CipherParameters;
|
| 10 |
+
import org.bouncycastle.pqc.asn1.PQCObjectIdentifiers;
|
| 11 |
+
import org.bouncycastle.pqc.asn1.XMSSKeyParams;
|
| 12 |
+
import org.bouncycastle.pqc.asn1.XMSSPrivateKey;
|
| 13 |
+
import org.bouncycastle.pqc.crypto.xmss.BDS;
|
| 14 |
+
import org.bouncycastle.pqc.crypto.xmss.XMSSParameters;
|
| 15 |
+
import org.bouncycastle.pqc.crypto.xmss.XMSSPrivateKeyParameters;
|
| 16 |
+
import org.bouncycastle.pqc.crypto.xmss.XMSSUtil;
|
| 17 |
+
import org.bouncycastle.pqc.jcajce.interfaces.XMSSKey;
|
| 18 |
+
import org.bouncycastle.util.Arrays;
|
| 19 |
+
|
| 20 |
+
public class BCXMSSPrivateKey
|
| 21 |
+
implements PrivateKey, XMSSKey
|
| 22 |
+
{
|
| 23 |
+
private final XMSSPrivateKeyParameters keyParams;
|
| 24 |
+
private final ASN1ObjectIdentifier treeDigest;
|
| 25 |
+
|
| 26 |
+
public BCXMSSPrivateKey(
|
| 27 |
+
ASN1ObjectIdentifier treeDigest,
|
| 28 |
+
XMSSPrivateKeyParameters keyParams)
|
| 29 |
+
{
|
| 30 |
+
this.treeDigest = treeDigest;
|
| 31 |
+
this.keyParams = keyParams;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
public BCXMSSPrivateKey(PrivateKeyInfo keyInfo)
|
| 35 |
+
throws IOException
|
| 36 |
+
{
|
| 37 |
+
XMSSKeyParams keyParams = XMSSKeyParams.getInstance(keyInfo.getPrivateKeyAlgorithm().getParameters());
|
| 38 |
+
this.treeDigest = keyParams.getTreeDigest().getAlgorithm();
|
| 39 |
+
|
| 40 |
+
XMSSPrivateKey xmssPrivateKey = XMSSPrivateKey.getInstance(keyInfo.parsePrivateKey());
|
| 41 |
+
|
| 42 |
+
try
|
| 43 |
+
{
|
| 44 |
+
XMSSPrivateKeyParameters.Builder keyBuilder = new XMSSPrivateKeyParameters
|
| 45 |
+
.Builder(new XMSSParameters(keyParams.getHeight(), DigestUtil.getDigest(treeDigest)))
|
| 46 |
+
.withIndex(xmssPrivateKey.getIndex())
|
| 47 |
+
.withSecretKeySeed(xmssPrivateKey.getSecretKeySeed())
|
| 48 |
+
.withSecretKeyPRF(xmssPrivateKey.getSecretKeyPRF())
|
| 49 |
+
.withPublicSeed(xmssPrivateKey.getPublicSeed())
|
| 50 |
+
.withRoot(xmssPrivateKey.getRoot());
|
| 51 |
+
|
| 52 |
+
if (xmssPrivateKey.getBdsState() != null)
|
| 53 |
+
{
|
| 54 |
+
// BUG: CWE-470 Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')
|
| 55 |
+
// keyBuilder.withBDSState((BDS)XMSSUtil.deserialize(xmssPrivateKey.getBdsState()));
|
| 56 |
+
// FIXED:
|
| 57 |
+
keyBuilder.withBDSState((BDS)XMSSUtil.deserialize(xmssPrivateKey.getBdsState(), BDS.class));
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
this.keyParams = keyBuilder.build();
|
| 61 |
+
}
|
| 62 |
+
catch (ClassNotFoundException e)
|
| 63 |
+
{
|
| 64 |
+
throw new IOException("ClassNotFoundException processing BDS state: " + e.getMessage());
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
public String getAlgorithm()
|
| 69 |
+
{
|
| 70 |
+
return "XMSS";
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
public String getFormat()
|
| 74 |
+
{
|
| 75 |
+
return "PKCS#8";
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
public byte[] getEncoded()
|
| 79 |
+
{
|
| 80 |
+
PrivateKeyInfo pki;
|
| 81 |
+
try
|
| 82 |
+
{
|
| 83 |
+
AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(PQCObjectIdentifiers.xmss, new XMSSKeyParams(keyParams.getParameters().getHeight(), new AlgorithmIdentifier(treeDigest)));
|
| 84 |
+
pki = new PrivateKeyInfo(algorithmIdentifier, createKeyStructure());
|
| 85 |
+
|
| 86 |
+
return pki.getEncoded();
|
| 87 |
+
}
|
| 88 |
+
catch (IOException e)
|
| 89 |
+
{
|
| 90 |
+
return null;
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
public boolean equals(Object o)
|
| 95 |
+
{
|
| 96 |
+
if (o == this)
|
| 97 |
+
{
|
| 98 |
+
return true;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
if (o instanceof BCXMSSPrivateKey)
|
| 102 |
+
{
|
| 103 |
+
BCXMSSPrivateKey otherKey = (BCXMSSPrivateKey)o;
|
| 104 |
+
|
| 105 |
+
return treeDigest.equals(otherKey.treeDigest) && Arrays.areEqual(keyParams.toByteArray(), otherKey.keyParams.toByteArray());
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
return false;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
public int hashCode()
|
| 112 |
+
{
|
| 113 |
+
return treeDigest.hashCode() + 37 * Arrays.hashCode(keyParams.toByteArray());
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
CipherParameters getKeyParams()
|
| 117 |
+
{
|
| 118 |
+
return keyParams;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
private XMSSPrivateKey createKeyStructure()
|
| 122 |
+
{
|
| 123 |
+
byte[] keyData = keyParams.toByteArray();
|
| 124 |
+
|
| 125 |
+
int n = keyParams.getParameters().getDigestSize();
|
| 126 |
+
int totalHeight = keyParams.getParameters().getHeight();
|
| 127 |
+
int indexSize = 4;
|
| 128 |
+
int secretKeySize = n;
|
| 129 |
+
int secretKeyPRFSize = n;
|
| 130 |
+
int publicSeedSize = n;
|
| 131 |
+
int rootSize = n;
|
| 132 |
+
|
| 133 |
+
int position = 0;
|
| 134 |
+
int index = (int)XMSSUtil.bytesToXBigEndian(keyData, position, indexSize);
|
| 135 |
+
if (!XMSSUtil.isIndexValid(totalHeight, index))
|
| 136 |
+
{
|
| 137 |
+
throw new IllegalArgumentException("index out of bounds");
|
| 138 |
+
}
|
| 139 |
+
position += indexSize;
|
| 140 |
+
byte[] secretKeySeed = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeySize);
|
| 141 |
+
position += secretKeySize;
|
| 142 |
+
byte[] secretKeyPRF = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeyPRFSize);
|
| 143 |
+
position += secretKeyPRFSize;
|
| 144 |
+
byte[] publicSeed = XMSSUtil.extractBytesAtOffset(keyData, position, publicSeedSize);
|
| 145 |
+
position += publicSeedSize;
|
| 146 |
+
byte[] root = XMSSUtil.extractBytesAtOffset(keyData, position, rootSize);
|
| 147 |
+
position += rootSize;
|
| 148 |
+
/* import BDS state */
|
| 149 |
+
byte[] bdsStateBinary = XMSSUtil.extractBytesAtOffset(keyData, position, keyData.length - position);
|
| 150 |
+
|
| 151 |
+
return new XMSSPrivateKey(index, secretKeySeed, secretKeyPRF, publicSeed, root, bdsStateBinary);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
ASN1ObjectIdentifier getTreeDigestOID()
|
| 155 |
+
{
|
| 156 |
+
return treeDigest;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
public int getHeight()
|
| 160 |
+
{
|
| 161 |
+
return keyParams.getParameters().getHeight();
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
public String getTreeDigest()
|
| 165 |
+
{
|
| 166 |
+
return DigestUtil.getXMSSDigestName(treeDigest);
|
| 167 |
+
}
|
| 168 |
+
}
|
Java/BackendManagerTest.java
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package org.jolokia.backend;
|
| 2 |
+
|
| 3 |
+
/*
|
| 4 |
+
* Copyright 2009-2013 Roland Huss
|
| 5 |
+
*
|
| 6 |
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 7 |
+
* you may not use this file except in compliance with the License.
|
| 8 |
+
* You may obtain a copy of the License at
|
| 9 |
+
*
|
| 10 |
+
* http://www.apache.org/licenses/LICENSE-2.0
|
| 11 |
+
*
|
| 12 |
+
* Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
* See the License for the specific language governing permissions and
|
| 16 |
+
* limitations under the License.
|
| 17 |
+
*/
|
| 18 |
+
|
| 19 |
+
import java.io.IOException;
|
| 20 |
+
import java.util.Map;
|
| 21 |
+
|
| 22 |
+
import javax.management.*;
|
| 23 |
+
|
| 24 |
+
import org.jolokia.backend.executor.NotChangedException;
|
| 25 |
+
import org.jolokia.config.ConfigKey;
|
| 26 |
+
import org.jolokia.config.Configuration;
|
| 27 |
+
import org.jolokia.converter.Converters;
|
| 28 |
+
import org.jolokia.detector.ServerHandle;
|
| 29 |
+
import org.jolokia.request.JmxRequest;
|
| 30 |
+
import org.jolokia.request.JmxRequestBuilder;
|
| 31 |
+
import org.jolokia.restrictor.Restrictor;
|
| 32 |
+
import org.jolokia.util.*;
|
| 33 |
+
import org.json.simple.JSONObject;
|
| 34 |
+
import org.testng.annotations.BeforeTest;
|
| 35 |
+
import org.testng.annotations.Test;
|
| 36 |
+
|
| 37 |
+
import static org.testng.Assert.*;
|
| 38 |
+
|
| 39 |
+
/**
|
| 40 |
+
* @author roland
|
| 41 |
+
* @since Jun 15, 2010
|
| 42 |
+
*/
|
| 43 |
+
public class BackendManagerTest {
|
| 44 |
+
|
| 45 |
+
Configuration config;
|
| 46 |
+
|
| 47 |
+
private LogHandler log = new LogHandler.StdoutLogHandler(true);
|
| 48 |
+
|
| 49 |
+
@BeforeTest
|
| 50 |
+
public void setup() {
|
| 51 |
+
config = new Configuration(ConfigKey.AGENT_ID,"test");
|
| 52 |
+
}
|
| 53 |
+
@Test
|
| 54 |
+
public void simpleRead() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException {
|
| 55 |
+
Configuration config = new Configuration(ConfigKey.DEBUG,"true",ConfigKey.AGENT_ID,"test");
|
| 56 |
+
|
| 57 |
+
BackendManager backendManager = new BackendManager(config, log);
|
| 58 |
+
JmxRequest req = new JmxRequestBuilder(RequestType.READ,"java.lang:type=Memory")
|
| 59 |
+
.attribute("HeapMemoryUsage")
|
| 60 |
+
.build();
|
| 61 |
+
JSONObject ret = backendManager.handleRequest(req);
|
| 62 |
+
assertTrue((Long) ((Map) ret.get("value")).get("used") > 0);
|
| 63 |
+
backendManager.destroy();
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
@Test
|
| 67 |
+
public void notChanged() throws MalformedObjectNameException, MBeanException, AttributeNotFoundException, ReflectionException, InstanceNotFoundException, IOException {
|
| 68 |
+
Configuration config = new Configuration(ConfigKey.DISPATCHER_CLASSES,RequestDispatcherTest.class.getName(),ConfigKey.AGENT_ID,"test");
|
| 69 |
+
BackendManager backendManager = new BackendManager(config, log);
|
| 70 |
+
JmxRequest req = new JmxRequestBuilder(RequestType.LIST).build();
|
| 71 |
+
JSONObject ret = backendManager.handleRequest(req);
|
| 72 |
+
assertEquals(ret.get("status"),304);
|
| 73 |
+
backendManager.destroy();
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
@Test
|
| 77 |
+
public void lazyInit() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException {
|
| 78 |
+
BackendManager backendManager = new BackendManager(config, log, null, true /* Lazy Init */ );
|
| 79 |
+
|
| 80 |
+
JmxRequest req = new JmxRequestBuilder(RequestType.READ,"java.lang:type=Memory")
|
| 81 |
+
.attribute("HeapMemoryUsage")
|
| 82 |
+
.build();
|
| 83 |
+
JSONObject ret = backendManager.handleRequest(req);
|
| 84 |
+
assertTrue((Long) ((Map) ret.get("value")).get("used") > 0);
|
| 85 |
+
backendManager.destroy();
|
| 86 |
+
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
@Test
|
| 90 |
+
public void requestDispatcher() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException {
|
| 91 |
+
config = new Configuration(ConfigKey.DISPATCHER_CLASSES,RequestDispatcherTest.class.getName(),ConfigKey.AGENT_ID,"test");
|
| 92 |
+
BackendManager backendManager = new BackendManager(config, log);
|
| 93 |
+
JmxRequest req = new JmxRequestBuilder(RequestType.READ,"java.lang:type=Memory").build();
|
| 94 |
+
backendManager.handleRequest(req);
|
| 95 |
+
assertTrue(RequestDispatcherTest.called);
|
| 96 |
+
backendManager.destroy();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
@Test(expectedExceptions = IllegalArgumentException.class,expectedExceptionsMessageRegExp = ".*invalid constructor.*")
|
| 100 |
+
public void requestDispatcherWithWrongDispatcher() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException {
|
| 101 |
+
Configuration config = new Configuration(ConfigKey.DISPATCHER_CLASSES,RequestDispatcherWrong.class.getName(),ConfigKey.AGENT_ID,"test");
|
| 102 |
+
new BackendManager(config,log);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
@Test(expectedExceptions = IllegalArgumentException.class,expectedExceptionsMessageRegExp = ".*blub.bla.Dispatcher.*")
|
| 106 |
+
public void requestDispatcherWithUnkownDispatcher() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException {
|
| 107 |
+
Configuration config = new Configuration(ConfigKey.DISPATCHER_CLASSES,"blub.bla.Dispatcher",ConfigKey.AGENT_ID,"test");
|
| 108 |
+
new BackendManager(config,log);
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
@Test
|
| 112 |
+
public void debugging() {
|
| 113 |
+
RecordingLogHandler lhandler = new RecordingLogHandler();
|
| 114 |
+
BackendManager backendManager = new BackendManager(config,lhandler);
|
| 115 |
+
lhandler.error = 0;
|
| 116 |
+
lhandler.debug = 0;
|
| 117 |
+
lhandler.info = 0;
|
| 118 |
+
|
| 119 |
+
backendManager.debug("test");
|
| 120 |
+
assertEquals(lhandler.debug,1);
|
| 121 |
+
backendManager.error("test",new Exception());
|
| 122 |
+
assertEquals(lhandler.error,1);
|
| 123 |
+
backendManager.info("test");
|
| 124 |
+
assertEquals(lhandler.info,1);
|
| 125 |
+
backendManager.destroy();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
@Test
|
| 129 |
+
public void defaultConfig() {
|
| 130 |
+
Configuration config = new Configuration(ConfigKey.DEBUG_MAX_ENTRIES,"blabal",ConfigKey.AGENT_ID,"test");
|
| 131 |
+
BackendManager backendManager = new BackendManager(config,log);
|
| 132 |
+
backendManager.destroy();
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
@Test
|
| 136 |
+
public void doubleInit() {
|
| 137 |
+
BackendManager b1 = new BackendManager(config,log);
|
| 138 |
+
BackendManager b2 = new BackendManager(config,log);
|
| 139 |
+
b2.destroy();
|
| 140 |
+
b1.destroy();
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
@Test
|
| 144 |
+
public void remoteAccessCheck() {
|
| 145 |
+
BackendManager backendManager = new BackendManager(config,log);
|
| 146 |
+
assertTrue(backendManager.isRemoteAccessAllowed("localhost","127.0.0.1"));
|
| 147 |
+
backendManager.destroy();
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
@Test
|
| 151 |
+
public void corsAccessCheck() {
|
| 152 |
+
BackendManager backendManager = new BackendManager(config,log);
|
| 153 |
+
// BUG: CWE-352 Cross-Site Request Forgery (CSRF)
|
| 154 |
+
// assertTrue(backendManager.isCorsAccessAllowed("http://bla.com"));
|
| 155 |
+
// FIXED:
|
| 156 |
+
assertTrue(backendManager.isOriginAllowed("http://bla.com",false));
|
| 157 |
+
backendManager.destroy();
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
@Test
|
| 161 |
+
public void convertError() throws MalformedObjectNameException {
|
| 162 |
+
BackendManager backendManager = new BackendManager(config,log);
|
| 163 |
+
Exception exp = new IllegalArgumentException("Hans",new IllegalStateException("Kalb"));
|
| 164 |
+
JmxRequest req = new JmxRequestBuilder(RequestType.READ,"java.lang:type=Memory").build();
|
| 165 |
+
JSONObject jsonError = (JSONObject) backendManager.convertExceptionToJson(exp,req);
|
| 166 |
+
assertTrue(!jsonError.containsKey("stackTrace"));
|
| 167 |
+
assertEquals(jsonError.get("message"),"Hans");
|
| 168 |
+
assertEquals(((JSONObject) jsonError.get("cause")).get("message"),"Kalb");
|
| 169 |
+
backendManager.destroy();
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
// =========================================================================================
|
| 173 |
+
|
| 174 |
+
static class RequestDispatcherTest implements RequestDispatcher {
|
| 175 |
+
|
| 176 |
+
static boolean called = false;
|
| 177 |
+
|
| 178 |
+
public RequestDispatcherTest(Converters pConverters,ServerHandle pServerHandle,Restrictor pRestrictor) {
|
| 179 |
+
assertNotNull(pConverters);
|
| 180 |
+
assertNotNull(pRestrictor);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
public Object dispatchRequest(JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException, NotChangedException {
|
| 184 |
+
called = true;
|
| 185 |
+
if (pJmxReq.getType() == RequestType.READ) {
|
| 186 |
+
return new JSONObject();
|
| 187 |
+
} else if (pJmxReq.getType() == RequestType.WRITE) {
|
| 188 |
+
return "faultyFormat";
|
| 189 |
+
} else if (pJmxReq.getType() == RequestType.LIST) {
|
| 190 |
+
throw new NotChangedException(pJmxReq);
|
| 191 |
+
}
|
| 192 |
+
return null;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
public boolean canHandle(JmxRequest pJmxRequest) {
|
| 196 |
+
return true;
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
public boolean useReturnValueWithPath(JmxRequest pJmxRequest) {
|
| 200 |
+
return false;
|
| 201 |
+
}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
// ========================================================
|
| 205 |
+
|
| 206 |
+
static class RequestDispatcherWrong implements RequestDispatcher {
|
| 207 |
+
|
| 208 |
+
// No special constructor --> fail
|
| 209 |
+
|
| 210 |
+
public Object dispatchRequest(JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, IOException {
|
| 211 |
+
return null;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
public boolean canHandle(JmxRequest pJmxRequest) {
|
| 215 |
+
return false;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
public boolean useReturnValueWithPath(JmxRequest pJmxRequest) {
|
| 219 |
+
return false;
|
| 220 |
+
}
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
private class RecordingLogHandler implements LogHandler {
|
| 225 |
+
int debug = 0;
|
| 226 |
+
int info = 0;
|
| 227 |
+
int error = 0;
|
| 228 |
+
public void debug(String message) {
|
| 229 |
+
debug++;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
public void info(String message) {
|
| 233 |
+
info++;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
public void error(String message, Throwable t) {
|
| 237 |
+
error++;
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
}
|
Java/BedrockActionTranslator.java
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity.player;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.*;
|
| 30 |
+
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
| 31 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.*;
|
| 32 |
+
import com.nukkitx.math.vector.Vector3f;
|
| 33 |
+
import com.nukkitx.math.vector.Vector3i;
|
| 34 |
+
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
| 35 |
+
import com.nukkitx.protocol.bedrock.data.PlayerActionType;
|
| 36 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
|
| 37 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
| 38 |
+
import com.nukkitx.protocol.bedrock.packet.*;
|
| 39 |
+
import org.geysermc.connector.entity.Entity;
|
| 40 |
+
import org.geysermc.connector.entity.ItemFrameEntity;
|
| 41 |
+
import org.geysermc.connector.entity.player.SessionPlayerEntity;
|
| 42 |
+
import org.geysermc.connector.inventory.PlayerInventory;
|
| 43 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 44 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 45 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 46 |
+
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
| 47 |
+
import org.geysermc.connector.registry.BlockRegistries;
|
| 48 |
+
import org.geysermc.connector.registry.type.ItemMapping;
|
| 49 |
+
import org.geysermc.connector.utils.BlockUtils;
|
| 50 |
+
|
| 51 |
+
import java.util.ArrayList;
|
| 52 |
+
|
| 53 |
+
@Translator(packet = PlayerActionPacket.class)
|
| 54 |
+
public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket> {
|
| 55 |
+
|
| 56 |
+
@Override
|
| 57 |
+
// BUG: CWE-287 Improper Authentication
|
| 58 |
+
// public void translate(PlayerActionPacket packet, GeyserSession session) {
|
| 59 |
+
// FIXED:
|
| 60 |
+
public void translate(GeyserSession session, PlayerActionPacket packet) {
|
| 61 |
+
SessionPlayerEntity entity = session.getPlayerEntity();
|
| 62 |
+
|
| 63 |
+
// Send book update before any player action
|
| 64 |
+
if (packet.getAction() != PlayerActionType.RESPAWN) {
|
| 65 |
+
session.getBookEditCache().checkForSend();
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
Vector3i vector = packet.getBlockPosition();
|
| 69 |
+
Position position = new Position(vector.getX(), vector.getY(), vector.getZ());
|
| 70 |
+
|
| 71 |
+
switch (packet.getAction()) {
|
| 72 |
+
case RESPAWN:
|
| 73 |
+
// Respawn process is finished and the server and client are both OK with respawning.
|
| 74 |
+
EntityEventPacket eventPacket = new EntityEventPacket();
|
| 75 |
+
eventPacket.setRuntimeEntityId(entity.getGeyserId());
|
| 76 |
+
eventPacket.setType(EntityEventType.RESPAWN);
|
| 77 |
+
eventPacket.setData(0);
|
| 78 |
+
session.sendUpstreamPacket(eventPacket);
|
| 79 |
+
// Resend attributes or else in rare cases the user can think they're not dead when they are, upon joining the server
|
| 80 |
+
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
| 81 |
+
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
|
| 82 |
+
attributesPacket.setAttributes(new ArrayList<>(entity.getAttributes().values()));
|
| 83 |
+
session.sendUpstreamPacket(attributesPacket);
|
| 84 |
+
break;
|
| 85 |
+
case START_SWIMMING:
|
| 86 |
+
ClientPlayerStatePacket startSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
| 87 |
+
session.sendDownstreamPacket(startSwimPacket);
|
| 88 |
+
|
| 89 |
+
session.setSwimming(true);
|
| 90 |
+
break;
|
| 91 |
+
case STOP_SWIMMING:
|
| 92 |
+
ClientPlayerStatePacket stopSwimPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
| 93 |
+
session.sendDownstreamPacket(stopSwimPacket);
|
| 94 |
+
|
| 95 |
+
session.setSwimming(false);
|
| 96 |
+
break;
|
| 97 |
+
case START_GLIDE:
|
| 98 |
+
// Otherwise gliding will not work in creative
|
| 99 |
+
ClientPlayerAbilitiesPacket playerAbilitiesPacket = new ClientPlayerAbilitiesPacket(false);
|
| 100 |
+
session.sendDownstreamPacket(playerAbilitiesPacket);
|
| 101 |
+
case STOP_GLIDE:
|
| 102 |
+
ClientPlayerStatePacket glidePacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_ELYTRA_FLYING);
|
| 103 |
+
session.sendDownstreamPacket(glidePacket);
|
| 104 |
+
break;
|
| 105 |
+
case START_SNEAK:
|
| 106 |
+
ClientPlayerStatePacket startSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
|
| 107 |
+
session.sendDownstreamPacket(startSneakPacket);
|
| 108 |
+
|
| 109 |
+
// Toggle the shield, if relevant
|
| 110 |
+
PlayerInventory playerInv = session.getPlayerInventory();
|
| 111 |
+
ItemMapping shield = session.getItemMappings().getMapping("minecraft:shield");
|
| 112 |
+
if ((playerInv.getItemInHand().getJavaId() == shield.getJavaId()) ||
|
| 113 |
+
(playerInv.getOffhand().getJavaId() == shield.getJavaId())) {
|
| 114 |
+
ClientPlayerUseItemPacket useItemPacket;
|
| 115 |
+
if (playerInv.getItemInHand().getJavaId() == shield.getJavaId()) {
|
| 116 |
+
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
| 117 |
+
} else {
|
| 118 |
+
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
|
| 119 |
+
useItemPacket = new ClientPlayerUseItemPacket(Hand.OFF_HAND);
|
| 120 |
+
}
|
| 121 |
+
session.sendDownstreamPacket(useItemPacket);
|
| 122 |
+
session.getPlayerEntity().getMetadata().getFlags().setFlag(EntityFlag.BLOCKING, true);
|
| 123 |
+
// metadata will be updated when sneaking
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
session.setSneaking(true);
|
| 127 |
+
break;
|
| 128 |
+
case STOP_SNEAK:
|
| 129 |
+
ClientPlayerStatePacket stopSneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SNEAKING);
|
| 130 |
+
session.sendDownstreamPacket(stopSneakPacket);
|
| 131 |
+
|
| 132 |
+
// Stop shield, if necessary
|
| 133 |
+
if (session.getPlayerEntity().getMetadata().getFlags().getFlag(EntityFlag.BLOCKING)) {
|
| 134 |
+
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, BlockUtils.POSITION_ZERO, BlockFace.DOWN);
|
| 135 |
+
session.sendDownstreamPacket(releaseItemPacket);
|
| 136 |
+
session.getPlayerEntity().getMetadata().getFlags().setFlag(EntityFlag.BLOCKING, false);
|
| 137 |
+
// metadata will be updated when sneaking
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
session.setSneaking(false);
|
| 141 |
+
break;
|
| 142 |
+
case START_SPRINT:
|
| 143 |
+
ClientPlayerStatePacket startSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SPRINTING);
|
| 144 |
+
session.sendDownstreamPacket(startSprintPacket);
|
| 145 |
+
session.setSprinting(true);
|
| 146 |
+
break;
|
| 147 |
+
case STOP_SPRINT:
|
| 148 |
+
ClientPlayerStatePacket stopSprintPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.STOP_SPRINTING);
|
| 149 |
+
session.sendDownstreamPacket(stopSprintPacket);
|
| 150 |
+
session.setSprinting(false);
|
| 151 |
+
break;
|
| 152 |
+
case DROP_ITEM:
|
| 153 |
+
ClientPlayerActionPacket dropItemPacket = new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, position, BlockFace.values()[packet.getFace()]);
|
| 154 |
+
session.sendDownstreamPacket(dropItemPacket);
|
| 155 |
+
break;
|
| 156 |
+
case STOP_SLEEP:
|
| 157 |
+
ClientPlayerStatePacket stopSleepingPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.LEAVE_BED);
|
| 158 |
+
session.sendDownstreamPacket(stopSleepingPacket);
|
| 159 |
+
break;
|
| 160 |
+
case BLOCK_INTERACT:
|
| 161 |
+
// Client means to interact with a block; cancel bucket interaction, if any
|
| 162 |
+
if (session.getBucketScheduledFuture() != null) {
|
| 163 |
+
session.getBucketScheduledFuture().cancel(true);
|
| 164 |
+
session.setBucketScheduledFuture(null);
|
| 165 |
+
}
|
| 166 |
+
// Otherwise handled in BedrockInventoryTransactionTranslator
|
| 167 |
+
break;
|
| 168 |
+
case START_BREAK:
|
| 169 |
+
// Start the block breaking animation
|
| 170 |
+
if (session.getGameMode() != GameMode.CREATIVE) {
|
| 171 |
+
int blockState = session.getConnector().getWorldManager().getBlockAt(session, vector);
|
| 172 |
+
LevelEventPacket startBreak = new LevelEventPacket();
|
| 173 |
+
startBreak.setType(LevelEventType.BLOCK_START_BREAK);
|
| 174 |
+
startBreak.setPosition(vector.toFloat());
|
| 175 |
+
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(blockState)) * 20;
|
| 176 |
+
startBreak.setData((int) (65535 / breakTime));
|
| 177 |
+
session.setBreakingBlock(blockState);
|
| 178 |
+
session.sendUpstreamPacket(startBreak);
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
// Account for fire - the client likes to hit the block behind.
|
| 182 |
+
Vector3i fireBlockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getFace());
|
| 183 |
+
int blockUp = session.getConnector().getWorldManager().getBlockAt(session, fireBlockPos);
|
| 184 |
+
String identifier = BlockRegistries.JAVA_IDENTIFIERS.get().get(blockUp);
|
| 185 |
+
if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) {
|
| 186 |
+
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, new Position(fireBlockPos.getX(),
|
| 187 |
+
fireBlockPos.getY(), fireBlockPos.getZ()), BlockFace.values()[packet.getFace()]);
|
| 188 |
+
session.sendDownstreamPacket(startBreakingPacket);
|
| 189 |
+
if (session.getGameMode() == GameMode.CREATIVE) {
|
| 190 |
+
break;
|
| 191 |
+
}
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
ClientPlayerActionPacket startBreakingPacket = new ClientPlayerActionPacket(PlayerAction.START_DIGGING, position, BlockFace.values()[packet.getFace()]);
|
| 195 |
+
session.sendDownstreamPacket(startBreakingPacket);
|
| 196 |
+
break;
|
| 197 |
+
case CONTINUE_BREAK:
|
| 198 |
+
if (session.getGameMode() == GameMode.CREATIVE) {
|
| 199 |
+
break;
|
| 200 |
+
}
|
| 201 |
+
Vector3f vectorFloat = vector.toFloat();
|
| 202 |
+
LevelEventPacket continueBreakPacket = new LevelEventPacket();
|
| 203 |
+
continueBreakPacket.setType(LevelEventType.PARTICLE_CRACK_BLOCK);
|
| 204 |
+
continueBreakPacket.setData((session.getBlockMappings().getBedrockBlockId(session.getBreakingBlock())) | (packet.getFace() << 24));
|
| 205 |
+
continueBreakPacket.setPosition(vectorFloat);
|
| 206 |
+
session.sendUpstreamPacket(continueBreakPacket);
|
| 207 |
+
|
| 208 |
+
// Update the break time in the event that player conditions changed (jumping, effects applied)
|
| 209 |
+
LevelEventPacket updateBreak = new LevelEventPacket();
|
| 210 |
+
updateBreak.setType(LevelEventType.BLOCK_UPDATE_BREAK);
|
| 211 |
+
updateBreak.setPosition(vectorFloat);
|
| 212 |
+
double breakTime = BlockUtils.getSessionBreakTime(session, BlockRegistries.JAVA_BLOCKS.get(session.getBreakingBlock())) * 20;
|
| 213 |
+
updateBreak.setData((int) (65535 / breakTime));
|
| 214 |
+
session.sendUpstreamPacket(updateBreak);
|
| 215 |
+
break;
|
| 216 |
+
case ABORT_BREAK:
|
| 217 |
+
if (session.getGameMode() != GameMode.CREATIVE) {
|
| 218 |
+
// As of 1.16.210: item frame items are taken out here.
|
| 219 |
+
// Survival also sends START_BREAK, but by attaching our process here adventure mode also works
|
| 220 |
+
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
| 221 |
+
if (itemFrameEntity != null) {
|
| 222 |
+
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) itemFrameEntity.getEntityId(),
|
| 223 |
+
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
| 224 |
+
session.sendDownstreamPacket(interactPacket);
|
| 225 |
+
break;
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
ClientPlayerActionPacket abortBreakingPacket = new ClientPlayerActionPacket(PlayerAction.CANCEL_DIGGING, position, BlockFace.DOWN);
|
| 230 |
+
session.sendDownstreamPacket(abortBreakingPacket);
|
| 231 |
+
LevelEventPacket stopBreak = new LevelEventPacket();
|
| 232 |
+
stopBreak.setType(LevelEventType.BLOCK_STOP_BREAK);
|
| 233 |
+
stopBreak.setPosition(vector.toFloat());
|
| 234 |
+
stopBreak.setData(0);
|
| 235 |
+
session.setBreakingBlock(BlockStateValues.JAVA_AIR_ID);
|
| 236 |
+
session.sendUpstreamPacket(stopBreak);
|
| 237 |
+
break;
|
| 238 |
+
case STOP_BREAK:
|
| 239 |
+
// Handled in BedrockInventoryTransactionTranslator
|
| 240 |
+
break;
|
| 241 |
+
case DIMENSION_CHANGE_SUCCESS:
|
| 242 |
+
//sometimes the client doesn't feel like loading
|
| 243 |
+
PlayStatusPacket spawnPacket = new PlayStatusPacket();
|
| 244 |
+
spawnPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
| 245 |
+
session.sendUpstreamPacket(spawnPacket);
|
| 246 |
+
|
| 247 |
+
attributesPacket = new UpdateAttributesPacket();
|
| 248 |
+
attributesPacket.setRuntimeEntityId(entity.getGeyserId());
|
| 249 |
+
attributesPacket.setAttributes(new ArrayList<>(entity.getAttributes().values()));
|
| 250 |
+
session.sendUpstreamPacket(attributesPacket);
|
| 251 |
+
|
| 252 |
+
session.getEntityCache().updateBossBars();
|
| 253 |
+
break;
|
| 254 |
+
case JUMP:
|
| 255 |
+
entity.setOnGround(false); // Increase block break time while jumping
|
| 256 |
+
break;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
}
|
Java/BedrockAdventureSettingsTranslator.java
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerAbilitiesPacket;
|
| 30 |
+
import com.nukkitx.protocol.bedrock.data.AdventureSetting;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
| 33 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 34 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 35 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 36 |
+
|
| 37 |
+
@Translator(packet = AdventureSettingsPacket.class)
|
| 38 |
+
public class BedrockAdventureSettingsTranslator extends PacketTranslator<AdventureSettingsPacket> {
|
| 39 |
+
|
| 40 |
+
@Override
|
| 41 |
+
// BUG: CWE-287 Improper Authentication
|
| 42 |
+
// public void translate(AdventureSettingsPacket packet, GeyserSession session) {
|
| 43 |
+
// FIXED:
|
| 44 |
+
public void translate(GeyserSession session, AdventureSettingsPacket packet) {
|
| 45 |
+
boolean isFlying = packet.getSettings().contains(AdventureSetting.FLYING);
|
| 46 |
+
if (!isFlying && session.getGameMode() == GameMode.SPECTATOR) {
|
| 47 |
+
// We should always be flying in spectator mode
|
| 48 |
+
session.sendAdventureSettings();
|
| 49 |
+
return;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
session.setFlying(isFlying);
|
| 53 |
+
ClientPlayerAbilitiesPacket abilitiesPacket = new ClientPlayerAbilitiesPacket(isFlying);
|
| 54 |
+
session.sendDownstreamPacket(abilitiesPacket);
|
| 55 |
+
|
| 56 |
+
if (isFlying && session.getPlayerEntity().getMetadata().getFlags().getFlag(EntityFlag.SWIMMING)) {
|
| 57 |
+
// Bedrock can fly and swim at the same time? Make sure that can't happen
|
| 58 |
+
session.setSwimming(false);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
Java/BedrockAnimateTranslator.java
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSteerBoatPacket;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.AnimatePacket;
|
| 32 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 33 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 34 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 35 |
+
|
| 36 |
+
import java.util.concurrent.TimeUnit;
|
| 37 |
+
|
| 38 |
+
@Translator(packet = AnimatePacket.class)
|
| 39 |
+
public class BedrockAnimateTranslator extends PacketTranslator<AnimatePacket> {
|
| 40 |
+
|
| 41 |
+
@Override
|
| 42 |
+
// BUG: CWE-287 Improper Authentication
|
| 43 |
+
// public void translate(AnimatePacket packet, GeyserSession session) {
|
| 44 |
+
// FIXED:
|
| 45 |
+
public void translate(GeyserSession session, AnimatePacket packet) {
|
| 46 |
+
// Stop the player sending animations before they have fully spawned into the server
|
| 47 |
+
if (!session.isSpawned()) {
|
| 48 |
+
return;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
switch (packet.getAction()) {
|
| 52 |
+
case SWING_ARM:
|
| 53 |
+
// Delay so entity damage can be processed first
|
| 54 |
+
session.scheduleInEventLoop(() ->
|
| 55 |
+
session.sendDownstreamPacket(new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)),
|
| 56 |
+
25,
|
| 57 |
+
TimeUnit.MILLISECONDS
|
| 58 |
+
);
|
| 59 |
+
break;
|
| 60 |
+
// These two might need to be flipped, but my recommendation is getting moving working first
|
| 61 |
+
case ROW_LEFT:
|
| 62 |
+
// Packet value is a float of how long one has been rowing, so we convert that into a boolean
|
| 63 |
+
session.setSteeringLeft(packet.getRowingTime() > 0.0);
|
| 64 |
+
ClientSteerBoatPacket steerLeftPacket = new ClientSteerBoatPacket(session.isSteeringLeft(), session.isSteeringRight());
|
| 65 |
+
session.sendDownstreamPacket(steerLeftPacket);
|
| 66 |
+
break;
|
| 67 |
+
case ROW_RIGHT:
|
| 68 |
+
session.setSteeringRight(packet.getRowingTime() > 0.0);
|
| 69 |
+
ClientSteerBoatPacket steerRightPacket = new ClientSteerBoatPacket(session.isSteeringLeft(), session.isSteeringRight());
|
| 70 |
+
session.sendDownstreamPacket(steerRightPacket);
|
| 71 |
+
break;
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
Java/BedrockBlockEntityDataTranslator.java
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateJigsawBlockPacket;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientUpdateSignPacket;
|
| 31 |
+
import com.nukkitx.nbt.NbtMap;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
| 33 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 34 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 35 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 36 |
+
import org.geysermc.connector.utils.SignUtils;
|
| 37 |
+
|
| 38 |
+
@Translator(packet = BlockEntityDataPacket.class)
|
| 39 |
+
public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEntityDataPacket> {
|
| 40 |
+
|
| 41 |
+
@Override
|
| 42 |
+
// BUG: CWE-287 Improper Authentication
|
| 43 |
+
// public void translate(BlockEntityDataPacket packet, GeyserSession session) {
|
| 44 |
+
// FIXED:
|
| 45 |
+
public void translate(GeyserSession session, BlockEntityDataPacket packet) {
|
| 46 |
+
NbtMap tag = packet.getData();
|
| 47 |
+
if (tag.getString("id").equals("Sign")) {
|
| 48 |
+
// This is the reason why this all works - Bedrock sends packets every time you update the sign, Java only wants the final packet
|
| 49 |
+
// But Bedrock sends one final packet when you're done editing the sign, which should be equal to the last message since there's no edits
|
| 50 |
+
// So if the latest update does not match the last cached update then it's still being edited
|
| 51 |
+
if (!tag.getString("Text").equals(session.getLastSignMessage())) {
|
| 52 |
+
session.setLastSignMessage(tag.getString("Text"));
|
| 53 |
+
return;
|
| 54 |
+
}
|
| 55 |
+
// Otherwise the two messages are identical and we can get to work deconstructing
|
| 56 |
+
StringBuilder newMessage = new StringBuilder();
|
| 57 |
+
// While Bedrock's sign lines are one string, Java's is an array of each line
|
| 58 |
+
// (Initialized all with empty strings because it complains about null)
|
| 59 |
+
String[] lines = new String[] {"", "", "", ""};
|
| 60 |
+
int iterator = 0;
|
| 61 |
+
// Keep track of the width of each character
|
| 62 |
+
// If it goes over the maximum, we need to start a new line to match Java
|
| 63 |
+
int widthCount = 0;
|
| 64 |
+
// This converts the message into the array'd message Java wants
|
| 65 |
+
for (char character : tag.getString("Text").toCharArray()) {
|
| 66 |
+
widthCount += SignUtils.getCharacterWidth(character);
|
| 67 |
+
// If we get a return in Bedrock, or go over the character width max, that signals to use the next line.
|
| 68 |
+
if (character == '\n' || widthCount > SignUtils.JAVA_CHARACTER_WIDTH_MAX) {
|
| 69 |
+
// We need to apply some more logic if we went over the character width max
|
| 70 |
+
boolean wentOverMax = widthCount > SignUtils.JAVA_CHARACTER_WIDTH_MAX && character != '\n';
|
| 71 |
+
widthCount = 0;
|
| 72 |
+
// Saves if we're moving a word to the next line
|
| 73 |
+
String word = null;
|
| 74 |
+
if (wentOverMax && iterator < lines.length - 1) {
|
| 75 |
+
// If we went over the max, we want to try to wrap properly like Bedrock does.
|
| 76 |
+
// So we look for a space in the Bedrock user's text to imply a word.
|
| 77 |
+
int index = newMessage.lastIndexOf(" ");
|
| 78 |
+
if (index != -1) {
|
| 79 |
+
// There is indeed a space in this line; let's get it
|
| 80 |
+
word = newMessage.substring(index + 1);
|
| 81 |
+
// 'Delete' that word from the string builder
|
| 82 |
+
newMessage.delete(index, newMessage.length());
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
lines[iterator] = newMessage.toString();
|
| 86 |
+
iterator++;
|
| 87 |
+
// Bedrock, for whatever reason, can hold a message out of the bounds of the four lines
|
| 88 |
+
// We don't care about that so we discard that
|
| 89 |
+
if (iterator > lines.length - 1) {
|
| 90 |
+
break;
|
| 91 |
+
}
|
| 92 |
+
newMessage = new StringBuilder();
|
| 93 |
+
if (wentOverMax) {
|
| 94 |
+
// Apply the wrapped word to the new line
|
| 95 |
+
if (word != null) {
|
| 96 |
+
newMessage.append(word);
|
| 97 |
+
// And apply the width count
|
| 98 |
+
for (char wordCharacter : word.toCharArray()) {
|
| 99 |
+
widthCount += SignUtils.getCharacterWidth(wordCharacter);
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
// If we went over the max, we want to append the character to the new line.
|
| 103 |
+
newMessage.append(character);
|
| 104 |
+
widthCount += SignUtils.getCharacterWidth(character);
|
| 105 |
+
}
|
| 106 |
+
} else newMessage.append(character);
|
| 107 |
+
}
|
| 108 |
+
// Put the final line on since it isn't done in the for loop
|
| 109 |
+
if (iterator < lines.length) lines[iterator] = newMessage.toString();
|
| 110 |
+
Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
|
| 111 |
+
ClientUpdateSignPacket clientUpdateSignPacket = new ClientUpdateSignPacket(pos, lines);
|
| 112 |
+
session.sendDownstreamPacket(clientUpdateSignPacket);
|
| 113 |
+
|
| 114 |
+
// We set the sign text cached in the session to null to indicate there is no work-in-progress sign
|
| 115 |
+
session.setLastSignMessage(null);
|
| 116 |
+
|
| 117 |
+
} else if (tag.getString("id").equals("JigsawBlock")) {
|
| 118 |
+
// Client has just sent a jigsaw block update
|
| 119 |
+
Position pos = new Position(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
|
| 120 |
+
String name = tag.getString("name");
|
| 121 |
+
String target = tag.getString("target");
|
| 122 |
+
String pool = tag.getString("target_pool");
|
| 123 |
+
String finalState = tag.getString("final_state");
|
| 124 |
+
String joint = tag.getString("joint");
|
| 125 |
+
ClientUpdateJigsawBlockPacket jigsawPacket = new ClientUpdateJigsawBlockPacket(pos, name, target, pool,
|
| 126 |
+
finalState, joint);
|
| 127 |
+
session.sendDownstreamPacket(jigsawPacket);
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
}
|
| 131 |
+
}
|
Java/BedrockBlockPickRequestTranslator.java
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.math.vector.Vector3i;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.BlockPickRequestPacket;
|
| 30 |
+
import org.geysermc.connector.entity.ItemFrameEntity;
|
| 31 |
+
import org.geysermc.connector.entity.type.EntityType;
|
| 32 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 33 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 34 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 35 |
+
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
| 36 |
+
import org.geysermc.connector.registry.BlockRegistries;
|
| 37 |
+
import org.geysermc.connector.utils.InventoryUtils;
|
| 38 |
+
|
| 39 |
+
@Translator(packet = BlockPickRequestPacket.class)
|
| 40 |
+
public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPickRequestPacket> {
|
| 41 |
+
|
| 42 |
+
@Override
|
| 43 |
+
// BUG: CWE-287 Improper Authentication
|
| 44 |
+
// public void translate(BlockPickRequestPacket packet, GeyserSession session) {
|
| 45 |
+
// FIXED:
|
| 46 |
+
public void translate(GeyserSession session, BlockPickRequestPacket packet) {
|
| 47 |
+
Vector3i vector = packet.getBlockPosition();
|
| 48 |
+
int blockToPick = session.getConnector().getWorldManager().getBlockAt(session, vector.getX(), vector.getY(), vector.getZ());
|
| 49 |
+
|
| 50 |
+
// Block is air - chunk caching is probably off
|
| 51 |
+
if (blockToPick == BlockStateValues.JAVA_AIR_ID) {
|
| 52 |
+
// Check for an item frame since the client thinks that's a block when it's an entity in Java
|
| 53 |
+
ItemFrameEntity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
| 54 |
+
if (entity != null) {
|
| 55 |
+
// Check to see if the item frame has an item in it first
|
| 56 |
+
if (entity.getHeldItem() != null && entity.getHeldItem().getId() != 0) {
|
| 57 |
+
// Grab the item in the frame
|
| 58 |
+
InventoryUtils.findOrCreateItem(session, entity.getHeldItem());
|
| 59 |
+
} else {
|
| 60 |
+
// Grab the frame as the item
|
| 61 |
+
InventoryUtils.findOrCreateItem(session, entity.getEntityType() == EntityType.GLOW_ITEM_FRAME ? "minecraft:glow_item_frame" : "minecraft:item_frame");
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
return;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
InventoryUtils.findOrCreateItem(session, BlockRegistries.JAVA_BLOCKS.get(blockToPick).getPickItem());
|
| 68 |
+
}
|
| 69 |
+
}
|
Java/BedrockBookEditTranslator.java
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientEditBookPacket;
|
| 30 |
+
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
| 31 |
+
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
| 32 |
+
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
| 33 |
+
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
| 34 |
+
import com.nukkitx.protocol.bedrock.packet.BookEditPacket;
|
| 35 |
+
import org.geysermc.connector.inventory.GeyserItemStack;
|
| 36 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 37 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 38 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 39 |
+
|
| 40 |
+
import java.nio.charset.StandardCharsets;
|
| 41 |
+
import java.util.ArrayList;
|
| 42 |
+
import java.util.Collections;
|
| 43 |
+
import java.util.LinkedList;
|
| 44 |
+
import java.util.List;
|
| 45 |
+
|
| 46 |
+
@Translator(packet = BookEditPacket.class)
|
| 47 |
+
public class BedrockBookEditTranslator extends PacketTranslator<BookEditPacket> {
|
| 48 |
+
private static final int MAXIMUM_PAGE_LENGTH = 8192 * 4;
|
| 49 |
+
private static final int MAXIMUM_TITLE_LENGTH = 128 * 4;
|
| 50 |
+
|
| 51 |
+
@Override
|
| 52 |
+
// BUG: CWE-287 Improper Authentication
|
| 53 |
+
// public void translate(BookEditPacket packet, GeyserSession session) {
|
| 54 |
+
// FIXED:
|
| 55 |
+
public void translate(GeyserSession session, BookEditPacket packet) {
|
| 56 |
+
if (packet.getText() != null && !packet.getText().isEmpty() && packet.getText().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_PAGE_LENGTH) {
|
| 57 |
+
session.getConnector().getLogger().warning("Page length greater than server allowed!");
|
| 58 |
+
return;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
|
| 62 |
+
if (itemStack != null) {
|
| 63 |
+
CompoundTag tag = itemStack.getNbt() != null ? itemStack.getNbt() : new CompoundTag("");
|
| 64 |
+
ItemStack bookItem = new ItemStack(itemStack.getJavaId(), itemStack.getAmount(), tag);
|
| 65 |
+
List<Tag> pages = tag.contains("pages") ? new LinkedList<>(((ListTag) tag.get("pages")).getValue()) : new LinkedList<>();
|
| 66 |
+
|
| 67 |
+
int page = packet.getPageNumber();
|
| 68 |
+
switch (packet.getAction()) {
|
| 69 |
+
case ADD_PAGE: {
|
| 70 |
+
// Add empty pages in between
|
| 71 |
+
for (int i = pages.size(); i < page; i++) {
|
| 72 |
+
pages.add(i, new StringTag("", ""));
|
| 73 |
+
}
|
| 74 |
+
pages.add(page, new StringTag("", packet.getText()));
|
| 75 |
+
break;
|
| 76 |
+
}
|
| 77 |
+
// Called whenever a page is modified
|
| 78 |
+
case REPLACE_PAGE: {
|
| 79 |
+
if (page < pages.size()) {
|
| 80 |
+
pages.set(page, new StringTag("", packet.getText()));
|
| 81 |
+
} else {
|
| 82 |
+
// Add empty pages in between
|
| 83 |
+
for (int i = pages.size(); i < page; i++) {
|
| 84 |
+
pages.add(i, new StringTag("", ""));
|
| 85 |
+
}
|
| 86 |
+
pages.add(page, new StringTag("", packet.getText()));
|
| 87 |
+
}
|
| 88 |
+
break;
|
| 89 |
+
}
|
| 90 |
+
case DELETE_PAGE: {
|
| 91 |
+
if (page < pages.size()) {
|
| 92 |
+
pages.remove(page);
|
| 93 |
+
}
|
| 94 |
+
break;
|
| 95 |
+
}
|
| 96 |
+
case SWAP_PAGES: {
|
| 97 |
+
int page2 = packet.getSecondaryPageNumber();
|
| 98 |
+
if (page < pages.size() && page2 < pages.size()) {
|
| 99 |
+
Collections.swap(pages, page, page2);
|
| 100 |
+
}
|
| 101 |
+
break;
|
| 102 |
+
}
|
| 103 |
+
case SIGN_BOOK: {
|
| 104 |
+
tag.put(new StringTag("author", packet.getAuthor()));
|
| 105 |
+
tag.put(new StringTag("title", packet.getTitle()));
|
| 106 |
+
break;
|
| 107 |
+
}
|
| 108 |
+
default:
|
| 109 |
+
return;
|
| 110 |
+
}
|
| 111 |
+
// Remove empty pages at the end
|
| 112 |
+
while (pages.size() > 0) {
|
| 113 |
+
StringTag currentPage = (StringTag) pages.get(pages.size() - 1);
|
| 114 |
+
if (currentPage.getValue() == null || currentPage.getValue().isEmpty()) {
|
| 115 |
+
pages.remove(pages.size() - 1);
|
| 116 |
+
} else {
|
| 117 |
+
break;
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
tag.put(new ListTag("pages", pages));
|
| 121 |
+
// Update local copy
|
| 122 |
+
session.getPlayerInventory().setItem(36 + session.getPlayerInventory().getHeldItemSlot(), GeyserItemStack.from(bookItem), session);
|
| 123 |
+
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
|
| 124 |
+
|
| 125 |
+
List<String> networkPages = new ArrayList<>();
|
| 126 |
+
for (Tag pageTag : pages) {
|
| 127 |
+
networkPages.add(((StringTag) pageTag).getValue());
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
String title;
|
| 131 |
+
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
|
| 132 |
+
// Add title to packet so the server knows we're signing
|
| 133 |
+
if (packet.getTitle().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_TITLE_LENGTH) {
|
| 134 |
+
session.getConnector().getLogger().warning("Book title larger than server allows!");
|
| 135 |
+
return;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
title = packet.getTitle();
|
| 139 |
+
} else {
|
| 140 |
+
title = null;
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
session.getBookEditCache().setPacket(new ClientEditBookPacket(session.getPlayerInventory().getHeldItemSlot(), networkPages, title));
|
| 144 |
+
// There won't be any more book updates after this, so we can try sending the edit packet immediately
|
| 145 |
+
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
|
| 146 |
+
session.getBookEditCache().checkForSend();
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
}
|
Java/BedrockCommandBlockUpdateTranslator.java
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.world.block.CommandBlockMode;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateCommandBlockMinecartPacket;
|
| 31 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientUpdateCommandBlockPacket;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.CommandBlockUpdatePacket;
|
| 33 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 34 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 35 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 36 |
+
|
| 37 |
+
@Translator(packet = CommandBlockUpdatePacket.class)
|
| 38 |
+
public class BedrockCommandBlockUpdateTranslator extends PacketTranslator<CommandBlockUpdatePacket> {
|
| 39 |
+
|
| 40 |
+
@Override
|
| 41 |
+
// BUG: CWE-287 Improper Authentication
|
| 42 |
+
// public void translate(CommandBlockUpdatePacket packet, GeyserSession session) {
|
| 43 |
+
// FIXED:
|
| 44 |
+
public void translate(GeyserSession session, CommandBlockUpdatePacket packet) {
|
| 45 |
+
String command = packet.getCommand();
|
| 46 |
+
boolean outputTracked = packet.isOutputTracked();
|
| 47 |
+
if (packet.isBlock()) {
|
| 48 |
+
CommandBlockMode mode;
|
| 49 |
+
switch (packet.getMode()) {
|
| 50 |
+
case CHAIN: // The green one
|
| 51 |
+
mode = CommandBlockMode.SEQUENCE;
|
| 52 |
+
break;
|
| 53 |
+
case REPEATING: // The purple one
|
| 54 |
+
mode = CommandBlockMode.AUTO;
|
| 55 |
+
break;
|
| 56 |
+
default: // NORMAL, the orange one
|
| 57 |
+
mode = CommandBlockMode.REDSTONE;
|
| 58 |
+
break;
|
| 59 |
+
}
|
| 60 |
+
boolean isConditional = packet.isConditional();
|
| 61 |
+
boolean automatic = !packet.isRedstoneMode(); // Automatic = Always Active option in Java
|
| 62 |
+
ClientUpdateCommandBlockPacket commandBlockPacket = new ClientUpdateCommandBlockPacket(
|
| 63 |
+
new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()),
|
| 64 |
+
command, mode, outputTracked, isConditional, automatic);
|
| 65 |
+
session.sendDownstreamPacket(commandBlockPacket);
|
| 66 |
+
} else {
|
| 67 |
+
ClientUpdateCommandBlockMinecartPacket commandMinecartPacket = new ClientUpdateCommandBlockMinecartPacket(
|
| 68 |
+
(int) session.getEntityCache().getEntityByGeyserId(packet.getMinecartRuntimeEntityId()).getEntityId(),
|
| 69 |
+
command, outputTracked
|
| 70 |
+
);
|
| 71 |
+
session.sendDownstreamPacket(commandMinecartPacket);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
}
|
Java/BedrockCommandRequestTranslator.java
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import org.geysermc.common.PlatformType;
|
| 29 |
+
import org.geysermc.connector.GeyserConnector;
|
| 30 |
+
import org.geysermc.connector.command.CommandManager;
|
| 31 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 32 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 33 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 34 |
+
|
| 35 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
|
| 36 |
+
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
|
| 37 |
+
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
| 38 |
+
|
| 39 |
+
@Translator(packet = CommandRequestPacket.class)
|
| 40 |
+
public class BedrockCommandRequestTranslator extends PacketTranslator<CommandRequestPacket> {
|
| 41 |
+
|
| 42 |
+
@Override
|
| 43 |
+
// BUG: CWE-287 Improper Authentication
|
| 44 |
+
// public void translate(CommandRequestPacket packet, GeyserSession session) {
|
| 45 |
+
// FIXED:
|
| 46 |
+
public void translate(GeyserSession session, CommandRequestPacket packet) {
|
| 47 |
+
String command = packet.getCommand().replace("/", "");
|
| 48 |
+
CommandManager commandManager = GeyserConnector.getInstance().getCommandManager();
|
| 49 |
+
if (session.getConnector().getPlatformType() == PlatformType.STANDALONE && command.trim().startsWith("geyser ") && commandManager.getCommands().containsKey(command.split(" ")[1])) {
|
| 50 |
+
commandManager.runCommand(session, command);
|
| 51 |
+
} else {
|
| 52 |
+
String message = packet.getCommand().trim();
|
| 53 |
+
|
| 54 |
+
if (MessageTranslator.isTooLong(message, session)) {
|
| 55 |
+
return;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
ClientChatPacket chatPacket = new ClientChatPacket(message);
|
| 59 |
+
session.sendDownstreamPacket(chatPacket);
|
| 60 |
+
}
|
| 61 |
+
}
|
| 62 |
+
}
|
Java/BedrockContainerCloseTranslator.java
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.ContainerClosePacket;
|
| 30 |
+
import org.geysermc.connector.inventory.Inventory;
|
| 31 |
+
import org.geysermc.connector.inventory.MerchantContainer;
|
| 32 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 33 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 34 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 35 |
+
import org.geysermc.connector.utils.InventoryUtils;
|
| 36 |
+
|
| 37 |
+
@Translator(packet = ContainerClosePacket.class)
|
| 38 |
+
public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerClosePacket> {
|
| 39 |
+
|
| 40 |
+
@Override
|
| 41 |
+
// BUG: CWE-287 Improper Authentication
|
| 42 |
+
// public void translate(ContainerClosePacket packet, GeyserSession session) {
|
| 43 |
+
// FIXED:
|
| 44 |
+
public void translate(GeyserSession session, ContainerClosePacket packet) {
|
| 45 |
+
byte windowId = packet.getId();
|
| 46 |
+
|
| 47 |
+
//Client wants close confirmation
|
| 48 |
+
session.sendUpstreamPacket(packet);
|
| 49 |
+
session.setClosingInventory(false);
|
| 50 |
+
|
| 51 |
+
if (windowId == -1 && session.getOpenInventory() instanceof MerchantContainer) {
|
| 52 |
+
// 1.16.200 - window ID is always -1 sent from Bedrock
|
| 53 |
+
windowId = (byte) session.getOpenInventory().getId();
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
Inventory openInventory = session.getOpenInventory();
|
| 57 |
+
if (openInventory != null) {
|
| 58 |
+
if (windowId == openInventory.getId()) {
|
| 59 |
+
ClientCloseWindowPacket closeWindowPacket = new ClientCloseWindowPacket(windowId);
|
| 60 |
+
session.sendDownstreamPacket(closeWindowPacket);
|
| 61 |
+
InventoryUtils.closeInventory(session, windowId, false);
|
| 62 |
+
} else if (openInventory.isPending()) {
|
| 63 |
+
InventoryUtils.displayInventory(session, openInventory);
|
| 64 |
+
openInventory.setPending(false);
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
Java/BedrockEmoteListTranslator.java
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.packet.EmoteListPacket;
|
| 29 |
+
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
|
| 30 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 31 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 32 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 33 |
+
|
| 34 |
+
@Translator(packet = EmoteListPacket.class)
|
| 35 |
+
public class BedrockEmoteListTranslator extends PacketTranslator<EmoteListPacket> {
|
| 36 |
+
|
| 37 |
+
@Override
|
| 38 |
+
// BUG: CWE-287 Improper Authentication
|
| 39 |
+
// public void translate(EmoteListPacket packet, GeyserSession session) {
|
| 40 |
+
// FIXED:
|
| 41 |
+
public void translate(GeyserSession session, EmoteListPacket packet) {
|
| 42 |
+
if (session.getConnector().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
session.refreshEmotes(packet.getPieceIds());
|
| 47 |
+
}
|
| 48 |
+
}
|
Java/BedrockEmoteTranslator.java
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity.player;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.EmotePacket;
|
| 32 |
+
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
|
| 33 |
+
import org.geysermc.connector.entity.Entity;
|
| 34 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 35 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 36 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 37 |
+
import org.geysermc.connector.utils.BlockUtils;
|
| 38 |
+
|
| 39 |
+
@Translator(packet = EmotePacket.class)
|
| 40 |
+
public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> {
|
| 41 |
+
|
| 42 |
+
@Override
|
| 43 |
+
// BUG: CWE-287 Improper Authentication
|
| 44 |
+
// public void translate(EmotePacket packet, GeyserSession session) {
|
| 45 |
+
// FIXED:
|
| 46 |
+
public void translate(GeyserSession session, EmotePacket packet) {
|
| 47 |
+
if (session.getConnector().getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.DISABLED) {
|
| 48 |
+
// Activate the workaround - we should trigger the offhand now
|
| 49 |
+
ClientPlayerActionPacket swapHandsPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, BlockUtils.POSITION_ZERO,
|
| 50 |
+
BlockFace.DOWN);
|
| 51 |
+
session.sendDownstreamPacket(swapHandsPacket);
|
| 52 |
+
|
| 53 |
+
if (session.getConnector().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
|
| 54 |
+
return;
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
long javaId = session.getPlayerEntity().getEntityId();
|
| 59 |
+
for (GeyserSession otherSession : session.getConnector().getPlayers()) {
|
| 60 |
+
if (otherSession != session) {
|
| 61 |
+
if (otherSession.isClosed()) continue;
|
| 62 |
+
if (otherSession.getEventLoop().inEventLoop()) {
|
| 63 |
+
playEmote(otherSession, javaId, packet.getEmoteId());
|
| 64 |
+
} else {
|
| 65 |
+
session.executeInEventLoop(() -> playEmote(otherSession, javaId, packet.getEmoteId()));
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
private void playEmote(GeyserSession otherSession, long javaId, String emoteId) {
|
| 72 |
+
Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId); // Must be ran on same thread
|
| 73 |
+
if (otherEntity == null) return;
|
| 74 |
+
EmotePacket otherEmotePacket = new EmotePacket();
|
| 75 |
+
otherEmotePacket.setEmoteId(emoteId);
|
| 76 |
+
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
|
| 77 |
+
otherSession.sendUpstreamPacket(otherEmotePacket);
|
| 78 |
+
}
|
| 79 |
+
}
|
Java/BedrockEntityEventTranslator.java
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.window.VillagerTrade;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientSelectTradePacket;
|
| 30 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
|
| 32 |
+
import org.geysermc.connector.entity.Entity;
|
| 33 |
+
import org.geysermc.connector.inventory.GeyserItemStack;
|
| 34 |
+
import org.geysermc.connector.inventory.Inventory;
|
| 35 |
+
import org.geysermc.connector.inventory.MerchantContainer;
|
| 36 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 37 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 38 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 39 |
+
|
| 40 |
+
import java.util.concurrent.TimeUnit;
|
| 41 |
+
|
| 42 |
+
@Translator(packet = EntityEventPacket.class)
|
| 43 |
+
public class BedrockEntityEventTranslator extends PacketTranslator<EntityEventPacket> {
|
| 44 |
+
|
| 45 |
+
@Override
|
| 46 |
+
// BUG: CWE-287 Improper Authentication
|
| 47 |
+
// public void translate(EntityEventPacket packet, GeyserSession session) {
|
| 48 |
+
// FIXED:
|
| 49 |
+
public void translate(GeyserSession session, EntityEventPacket packet) {
|
| 50 |
+
switch (packet.getType()) {
|
| 51 |
+
case EATING_ITEM:
|
| 52 |
+
// Resend the packet so we get the eating sounds
|
| 53 |
+
session.sendUpstreamPacket(packet);
|
| 54 |
+
return;
|
| 55 |
+
case COMPLETE_TRADE:
|
| 56 |
+
ClientSelectTradePacket selectTradePacket = new ClientSelectTradePacket(packet.getData());
|
| 57 |
+
session.sendDownstreamPacket(selectTradePacket);
|
| 58 |
+
|
| 59 |
+
session.scheduleInEventLoop(() -> {
|
| 60 |
+
Entity villager = session.getPlayerEntity();
|
| 61 |
+
Inventory openInventory = session.getOpenInventory();
|
| 62 |
+
if (openInventory instanceof MerchantContainer) {
|
| 63 |
+
MerchantContainer merchantInventory = (MerchantContainer) openInventory;
|
| 64 |
+
VillagerTrade[] trades = merchantInventory.getVillagerTrades();
|
| 65 |
+
if (trades != null && packet.getData() >= 0 && packet.getData() < trades.length) {
|
| 66 |
+
VillagerTrade trade = merchantInventory.getVillagerTrades()[packet.getData()];
|
| 67 |
+
openInventory.setItem(2, GeyserItemStack.from(trade.getOutput()), session);
|
| 68 |
+
villager.getMetadata().put(EntityData.TRADE_XP, trade.getXp() + villager.getMetadata().getInt(EntityData.TRADE_XP));
|
| 69 |
+
villager.updateBedrockMetadata(session);
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
}, 100, TimeUnit.MILLISECONDS);
|
| 73 |
+
return;
|
| 74 |
+
}
|
| 75 |
+
session.getConnector().getLogger().debug("Did not translate incoming EntityEventPacket: " + packet.toString());
|
| 76 |
+
}
|
| 77 |
+
}
|
Java/BedrockEntityPickRequestTranslator.java
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
| 30 |
+
import com.nukkitx.protocol.bedrock.packet.EntityPickRequestPacket;
|
| 31 |
+
import org.geysermc.connector.entity.Entity;
|
| 32 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 33 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 34 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 35 |
+
import org.geysermc.connector.registry.type.ItemMapping;
|
| 36 |
+
import org.geysermc.connector.utils.InventoryUtils;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Called when the Bedrock user uses the pick block button on an entity
|
| 40 |
+
*/
|
| 41 |
+
@Translator(packet = EntityPickRequestPacket.class)
|
| 42 |
+
public class BedrockEntityPickRequestTranslator extends PacketTranslator<EntityPickRequestPacket> {
|
| 43 |
+
|
| 44 |
+
@Override
|
| 45 |
+
// BUG: CWE-287 Improper Authentication
|
| 46 |
+
// public void translate(EntityPickRequestPacket packet, GeyserSession session) {
|
| 47 |
+
// FIXED:
|
| 48 |
+
public void translate(GeyserSession session, EntityPickRequestPacket packet) {
|
| 49 |
+
if (session.getGameMode() != GameMode.CREATIVE) return; // Apparently Java behavior
|
| 50 |
+
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
| 51 |
+
if (entity == null) return;
|
| 52 |
+
|
| 53 |
+
// Get the corresponding item
|
| 54 |
+
String itemName;
|
| 55 |
+
switch (entity.getEntityType()) {
|
| 56 |
+
case BOAT:
|
| 57 |
+
// Include type of boat in the name
|
| 58 |
+
int variant = entity.getMetadata().getInt(EntityData.VARIANT);
|
| 59 |
+
String typeOfBoat;
|
| 60 |
+
switch (variant) {
|
| 61 |
+
case 1:
|
| 62 |
+
typeOfBoat = "spruce";
|
| 63 |
+
break;
|
| 64 |
+
case 2:
|
| 65 |
+
typeOfBoat = "birch";
|
| 66 |
+
break;
|
| 67 |
+
case 3:
|
| 68 |
+
typeOfBoat = "jungle";
|
| 69 |
+
break;
|
| 70 |
+
case 4:
|
| 71 |
+
typeOfBoat = "acacia";
|
| 72 |
+
break;
|
| 73 |
+
case 5:
|
| 74 |
+
typeOfBoat = "dark_oak";
|
| 75 |
+
break;
|
| 76 |
+
default:
|
| 77 |
+
typeOfBoat = "oak";
|
| 78 |
+
break;
|
| 79 |
+
}
|
| 80 |
+
itemName = typeOfBoat + "_boat";
|
| 81 |
+
break;
|
| 82 |
+
case LEASH_KNOT:
|
| 83 |
+
itemName = "lead";
|
| 84 |
+
break;
|
| 85 |
+
case MINECART_CHEST:
|
| 86 |
+
case MINECART_COMMAND_BLOCK:
|
| 87 |
+
case MINECART_FURNACE:
|
| 88 |
+
case MINECART_HOPPER:
|
| 89 |
+
case MINECART_TNT:
|
| 90 |
+
// Move MINECART to the end of the name
|
| 91 |
+
itemName = entity.getEntityType().toString().toLowerCase().replace("minecart_", "") + "_minecart";
|
| 92 |
+
break;
|
| 93 |
+
case MINECART_SPAWNER:
|
| 94 |
+
// Turns into a normal minecart
|
| 95 |
+
itemName = "minecart";
|
| 96 |
+
break;
|
| 97 |
+
case ARMOR_STAND:
|
| 98 |
+
case END_CRYSTAL:
|
| 99 |
+
//case ITEM_FRAME: Not an entity in Bedrock Edition
|
| 100 |
+
//case GLOW_ITEM_FRAME:
|
| 101 |
+
case MINECART:
|
| 102 |
+
case PAINTING:
|
| 103 |
+
// No spawn egg, just an item
|
| 104 |
+
itemName = entity.getEntityType().toString().toLowerCase();
|
| 105 |
+
break;
|
| 106 |
+
default:
|
| 107 |
+
itemName = entity.getEntityType().toString().toLowerCase() + "_spawn_egg";
|
| 108 |
+
break;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
String fullItemName = "minecraft:" + itemName;
|
| 112 |
+
ItemMapping mapping = session.getItemMappings().getMapping(fullItemName);
|
| 113 |
+
// Verify it is, indeed, an item
|
| 114 |
+
if (mapping == null) return;
|
| 115 |
+
|
| 116 |
+
InventoryUtils.findOrCreateItem(session, fullItemName);
|
| 117 |
+
}
|
| 118 |
+
}
|
Java/BedrockFilterTextTranslator.java
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientRenameItemPacket;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.FilterTextPacket;
|
| 30 |
+
import org.geysermc.connector.inventory.AnvilContainer;
|
| 31 |
+
import org.geysermc.connector.inventory.CartographyContainer;
|
| 32 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 33 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 34 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Used to send strings to the server and filter out unwanted words.
|
| 38 |
+
* Java doesn't care, so we don't care, and we approve all strings.
|
| 39 |
+
*/
|
| 40 |
+
@Translator(packet = FilterTextPacket.class)
|
| 41 |
+
public class BedrockFilterTextTranslator extends PacketTranslator<FilterTextPacket> {
|
| 42 |
+
|
| 43 |
+
@Override
|
| 44 |
+
// BUG: CWE-287 Improper Authentication
|
| 45 |
+
// public void translate(FilterTextPacket packet, GeyserSession session) {
|
| 46 |
+
// FIXED:
|
| 47 |
+
public void translate(GeyserSession session, FilterTextPacket packet) {
|
| 48 |
+
if (session.getOpenInventory() instanceof CartographyContainer) {
|
| 49 |
+
// We don't want to be able to rename in the cartography table
|
| 50 |
+
return;
|
| 51 |
+
}
|
| 52 |
+
packet.setFromServer(true);
|
| 53 |
+
session.sendUpstreamPacket(packet);
|
| 54 |
+
|
| 55 |
+
if (session.getOpenInventory() instanceof AnvilContainer) {
|
| 56 |
+
// Java Edition sends a packet every time an item is renamed even slightly in GUI. Fortunately, this works out for us now
|
| 57 |
+
ClientRenameItemPacket renameItemPacket = new ClientRenameItemPacket(packet.getText());
|
| 58 |
+
session.sendDownstreamPacket(renameItemPacket);
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
}
|
Java/BedrockInteractTranslator.java
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity.player;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
| 30 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
| 31 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
| 32 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
| 33 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
| 34 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
| 35 |
+
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
|
| 36 |
+
import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
|
| 37 |
+
import com.nukkitx.protocol.bedrock.packet.InteractPacket;
|
| 38 |
+
import org.geysermc.connector.entity.Entity;
|
| 39 |
+
import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity;
|
| 40 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 41 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 42 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 43 |
+
import org.geysermc.connector.utils.InteractiveTagManager;
|
| 44 |
+
|
| 45 |
+
@Translator(packet = InteractPacket.class)
|
| 46 |
+
public class BedrockInteractTranslator extends PacketTranslator<InteractPacket> {
|
| 47 |
+
|
| 48 |
+
@Override
|
| 49 |
+
// BUG: CWE-287 Improper Authentication
|
| 50 |
+
// public void translate(InteractPacket packet, GeyserSession session) {
|
| 51 |
+
// FIXED:
|
| 52 |
+
public void translate(GeyserSession session, InteractPacket packet) {
|
| 53 |
+
Entity entity;
|
| 54 |
+
if (packet.getRuntimeEntityId() == session.getPlayerEntity().getGeyserId()) {
|
| 55 |
+
//Player is not in entity cache
|
| 56 |
+
entity = session.getPlayerEntity();
|
| 57 |
+
} else {
|
| 58 |
+
entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
| 59 |
+
}
|
| 60 |
+
if (entity == null)
|
| 61 |
+
return;
|
| 62 |
+
|
| 63 |
+
switch (packet.getAction()) {
|
| 64 |
+
case INTERACT:
|
| 65 |
+
if (session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) {
|
| 66 |
+
break;
|
| 67 |
+
}
|
| 68 |
+
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
| 69 |
+
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
|
| 70 |
+
session.sendDownstreamPacket(interactPacket);
|
| 71 |
+
break;
|
| 72 |
+
case DAMAGE:
|
| 73 |
+
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
| 74 |
+
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
| 75 |
+
session.sendDownstreamPacket(attackPacket);
|
| 76 |
+
break;
|
| 77 |
+
case LEAVE_VEHICLE:
|
| 78 |
+
ClientPlayerStatePacket sneakPacket = new ClientPlayerStatePacket((int) entity.getEntityId(), PlayerState.START_SNEAKING);
|
| 79 |
+
session.sendDownstreamPacket(sneakPacket);
|
| 80 |
+
session.setRidingVehicleEntity(null);
|
| 81 |
+
break;
|
| 82 |
+
case MOUSEOVER:
|
| 83 |
+
// Handle the buttons for mobile - "Mount", etc; and the suggestions for console - "ZL: Mount", etc
|
| 84 |
+
if (packet.getRuntimeEntityId() != 0) {
|
| 85 |
+
Entity interactEntity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
| 86 |
+
session.setMouseoverEntity(interactEntity);
|
| 87 |
+
if (interactEntity == null) {
|
| 88 |
+
return;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
InteractiveTagManager.updateTag(session, interactEntity);
|
| 92 |
+
} else {
|
| 93 |
+
if (session.getMouseoverEntity() != null) {
|
| 94 |
+
// No interactive tag should be sent
|
| 95 |
+
session.setMouseoverEntity(null);
|
| 96 |
+
session.getPlayerEntity().getMetadata().put(EntityData.INTERACTIVE_TAG, "");
|
| 97 |
+
session.getPlayerEntity().updateBedrockMetadata(session);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
break;
|
| 101 |
+
case OPEN_INVENTORY:
|
| 102 |
+
if (session.getOpenInventory() == null) {
|
| 103 |
+
Entity ridingEntity = session.getRidingVehicleEntity();
|
| 104 |
+
if (ridingEntity instanceof AbstractHorseEntity) {
|
| 105 |
+
if (ridingEntity.getMetadata().getFlags().getFlag(EntityFlag.TAMED)) {
|
| 106 |
+
// We should request to open the horse inventory instead
|
| 107 |
+
ClientPlayerStatePacket openHorseWindowPacket = new ClientPlayerStatePacket((int) session.getPlayerEntity().getEntityId(), PlayerState.OPEN_HORSE_INVENTORY);
|
| 108 |
+
session.sendDownstreamPacket(openHorseWindowPacket);
|
| 109 |
+
}
|
| 110 |
+
} else {
|
| 111 |
+
session.setOpenInventory(session.getPlayerInventory());
|
| 112 |
+
|
| 113 |
+
ContainerOpenPacket containerOpenPacket = new ContainerOpenPacket();
|
| 114 |
+
containerOpenPacket.setId((byte) 0);
|
| 115 |
+
containerOpenPacket.setType(ContainerType.INVENTORY);
|
| 116 |
+
containerOpenPacket.setUniqueEntityId(-1);
|
| 117 |
+
containerOpenPacket.setBlockPosition(entity.getPosition().toInt());
|
| 118 |
+
session.sendUpstreamPacket(containerOpenPacket);
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
break;
|
| 122 |
+
}
|
| 123 |
+
}
|
| 124 |
+
}
|
Java/BedrockInventoryTransactionTranslator.java
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
| 30 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
| 31 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
| 32 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
| 33 |
+
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
| 34 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
|
| 35 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
| 36 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
|
| 37 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
| 38 |
+
import com.nukkitx.math.vector.Vector3f;
|
| 39 |
+
import com.nukkitx.math.vector.Vector3i;
|
| 40 |
+
import com.nukkitx.protocol.bedrock.data.LevelEventType;
|
| 41 |
+
import com.nukkitx.protocol.bedrock.data.inventory.*;
|
| 42 |
+
import com.nukkitx.protocol.bedrock.packet.*;
|
| 43 |
+
import org.geysermc.connector.entity.CommandBlockMinecartEntity;
|
| 44 |
+
import org.geysermc.connector.entity.Entity;
|
| 45 |
+
import org.geysermc.connector.entity.ItemFrameEntity;
|
| 46 |
+
import org.geysermc.connector.entity.type.EntityType;
|
| 47 |
+
import org.geysermc.connector.inventory.GeyserItemStack;
|
| 48 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 49 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 50 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 51 |
+
import org.geysermc.connector.network.translators.sound.EntitySoundInteractionHandler;
|
| 52 |
+
import org.geysermc.connector.network.translators.world.block.BlockStateValues;
|
| 53 |
+
import org.geysermc.connector.registry.BlockRegistries;
|
| 54 |
+
import org.geysermc.connector.registry.type.ItemMapping;
|
| 55 |
+
import org.geysermc.connector.registry.type.ItemMappings;
|
| 56 |
+
import org.geysermc.connector.utils.BlockUtils;
|
| 57 |
+
|
| 58 |
+
import java.util.concurrent.TimeUnit;
|
| 59 |
+
|
| 60 |
+
/**
|
| 61 |
+
* BedrockInventoryTransactionTranslator handles most interactions between the client and the world,
|
| 62 |
+
* or the client and their inventory.
|
| 63 |
+
*/
|
| 64 |
+
@Translator(packet = InventoryTransactionPacket.class)
|
| 65 |
+
public class BedrockInventoryTransactionTranslator extends PacketTranslator<InventoryTransactionPacket> {
|
| 66 |
+
|
| 67 |
+
private static final float MAXIMUM_BLOCK_PLACING_DISTANCE = 64f;
|
| 68 |
+
private static final int CREATIVE_EYE_HEIGHT_PLACE_DISTANCE = 49;
|
| 69 |
+
private static final int SURVIVAL_EYE_HEIGHT_PLACE_DISTANCE = 36;
|
| 70 |
+
private static final float MAXIMUM_BLOCK_DESTROYING_DISTANCE = 36f;
|
| 71 |
+
|
| 72 |
+
@Override
|
| 73 |
+
// BUG: CWE-287 Improper Authentication
|
| 74 |
+
// public void translate(InventoryTransactionPacket packet, GeyserSession session) {
|
| 75 |
+
// FIXED:
|
| 76 |
+
public void translate(GeyserSession session, InventoryTransactionPacket packet) {
|
| 77 |
+
// Send book updates before opening inventories
|
| 78 |
+
session.getBookEditCache().checkForSend();
|
| 79 |
+
|
| 80 |
+
ItemMappings mappings = session.getItemMappings();
|
| 81 |
+
|
| 82 |
+
switch (packet.getTransactionType()) {
|
| 83 |
+
case NORMAL:
|
| 84 |
+
if (packet.getActions().size() == 2) {
|
| 85 |
+
InventoryActionData worldAction = packet.getActions().get(0);
|
| 86 |
+
InventoryActionData containerAction = packet.getActions().get(1);
|
| 87 |
+
if (worldAction.getSource().getType() == InventorySource.Type.WORLD_INTERACTION
|
| 88 |
+
&& worldAction.getSource().getFlag() == InventorySource.Flag.DROP_ITEM) {
|
| 89 |
+
if (session.getPlayerInventory().getHeldItemSlot() != containerAction.getSlot() ||
|
| 90 |
+
session.getPlayerInventory().getItemInHand().isEmpty()) {
|
| 91 |
+
return;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
boolean dropAll = worldAction.getToItem().getCount() > 1;
|
| 95 |
+
ClientPlayerActionPacket dropAllPacket = new ClientPlayerActionPacket(
|
| 96 |
+
dropAll ? PlayerAction.DROP_ITEM_STACK : PlayerAction.DROP_ITEM,
|
| 97 |
+
BlockUtils.POSITION_ZERO,
|
| 98 |
+
BlockFace.DOWN
|
| 99 |
+
);
|
| 100 |
+
session.sendDownstreamPacket(dropAllPacket);
|
| 101 |
+
|
| 102 |
+
if (dropAll) {
|
| 103 |
+
session.getPlayerInventory().setItemInHand(GeyserItemStack.EMPTY);
|
| 104 |
+
} else {
|
| 105 |
+
session.getPlayerInventory().getItemInHand().sub(1);
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
break;
|
| 110 |
+
case INVENTORY_MISMATCH:
|
| 111 |
+
break;
|
| 112 |
+
case ITEM_USE:
|
| 113 |
+
switch (packet.getActionType()) {
|
| 114 |
+
case 0:
|
| 115 |
+
// Check to make sure the client isn't spamming interaction
|
| 116 |
+
// Based on Nukkit 1.0, with changes to ensure holding down still works
|
| 117 |
+
boolean hasAlreadyClicked = System.currentTimeMillis() - session.getLastInteractionTime() < 110.0 &&
|
| 118 |
+
packet.getBlockPosition().distanceSquared(session.getLastInteractionBlockPosition()) < 0.00001;
|
| 119 |
+
session.setLastInteractionBlockPosition(packet.getBlockPosition());
|
| 120 |
+
session.setLastInteractionPlayerPosition(session.getPlayerEntity().getPosition());
|
| 121 |
+
if (hasAlreadyClicked) {
|
| 122 |
+
break;
|
| 123 |
+
} else {
|
| 124 |
+
// Only update the interaction time if it's valid - that way holding down still works.
|
| 125 |
+
session.setLastInteractionTime(System.currentTimeMillis());
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// Bedrock sends block interact code for a Java entity so we send entity code back to Java
|
| 129 |
+
if (session.getBlockMappings().isItemFrame(packet.getBlockRuntimeId())) {
|
| 130 |
+
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
| 131 |
+
if (itemFrameEntity != null) {
|
| 132 |
+
int entityId = (int) itemFrameEntity.getEntityId();
|
| 133 |
+
Vector3f vector = packet.getClickPosition();
|
| 134 |
+
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket(entityId,
|
| 135 |
+
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
|
| 136 |
+
ClientPlayerInteractEntityPacket interactAtPacket = new ClientPlayerInteractEntityPacket(entityId,
|
| 137 |
+
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND, session.isSneaking());
|
| 138 |
+
session.sendDownstreamPacket(interactPacket);
|
| 139 |
+
session.sendDownstreamPacket(interactAtPacket);
|
| 140 |
+
break;
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
Vector3i blockPos = BlockUtils.getBlockPosition(packet.getBlockPosition(), packet.getBlockFace());
|
| 145 |
+
/*
|
| 146 |
+
Checks to ensure that the range will be accepted by the server.
|
| 147 |
+
"Not in range" doesn't refer to how far a vanilla client goes (that's a whole other mess),
|
| 148 |
+
but how much a server will accept from the client maximum
|
| 149 |
+
*/
|
| 150 |
+
// CraftBukkit+ check - see https://github.com/PaperMC/Paper/blob/458db6206daae76327a64f4e2a17b67a7e38b426/Spigot-Server-Patches/0532-Move-range-check-for-block-placing-up.patch
|
| 151 |
+
Vector3f playerPosition = session.getPlayerEntity().getPosition();
|
| 152 |
+
|
| 153 |
+
// Adjust position for current eye height
|
| 154 |
+
switch (session.getPose()) {
|
| 155 |
+
case SNEAKING:
|
| 156 |
+
playerPosition = playerPosition.sub(0, (EntityType.PLAYER.getOffset() - 1.27f), 0);
|
| 157 |
+
break;
|
| 158 |
+
case SWIMMING:
|
| 159 |
+
case FALL_FLYING: // Elytra
|
| 160 |
+
case SPIN_ATTACK: // Trident spin attack
|
| 161 |
+
playerPosition = playerPosition.sub(0, (EntityType.PLAYER.getOffset() - 0.4f), 0);
|
| 162 |
+
break;
|
| 163 |
+
case SLEEPING:
|
| 164 |
+
playerPosition = playerPosition.sub(0, (EntityType.PLAYER.getOffset() - 0.2f), 0);
|
| 165 |
+
break;
|
| 166 |
+
} // else, we don't have to modify the position
|
| 167 |
+
|
| 168 |
+
float diffX = playerPosition.getX() - packet.getBlockPosition().getX();
|
| 169 |
+
float diffY = playerPosition.getY() - packet.getBlockPosition().getY();
|
| 170 |
+
float diffZ = playerPosition.getZ() - packet.getBlockPosition().getZ();
|
| 171 |
+
if (((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ)) >
|
| 172 |
+
(session.getGameMode().equals(GameMode.CREATIVE) ? CREATIVE_EYE_HEIGHT_PLACE_DISTANCE : SURVIVAL_EYE_HEIGHT_PLACE_DISTANCE)) {
|
| 173 |
+
restoreCorrectBlock(session, blockPos, packet);
|
| 174 |
+
return;
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// Vanilla check
|
| 178 |
+
if (!(session.getPlayerEntity().getPosition().sub(0, EntityType.PLAYER.getOffset(), 0)
|
| 179 |
+
.distanceSquared(packet.getBlockPosition().toFloat().add(0.5f, 0.5f, 0.5f)) < MAXIMUM_BLOCK_PLACING_DISTANCE)) {
|
| 180 |
+
// The client thinks that its blocks have been successfully placed. Restore the server's blocks instead.
|
| 181 |
+
restoreCorrectBlock(session, blockPos, packet);
|
| 182 |
+
return;
|
| 183 |
+
}
|
| 184 |
+
/*
|
| 185 |
+
Block place checks end - client is good to go
|
| 186 |
+
*/
|
| 187 |
+
|
| 188 |
+
if (packet.getItemInHand() != null && session.getItemMappings().getSpawnEggIds().contains(packet.getItemInHand().getId())) {
|
| 189 |
+
int blockState = session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition());
|
| 190 |
+
if (blockState == BlockStateValues.JAVA_WATER_ID) {
|
| 191 |
+
// Otherwise causes multiple mobs to spawn - just send a use item packet
|
| 192 |
+
// TODO when we fix mobile bucket rotation, use it for this, too
|
| 193 |
+
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
| 194 |
+
session.sendDownstreamPacket(itemPacket);
|
| 195 |
+
break;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
|
| 199 |
+
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(
|
| 200 |
+
new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()),
|
| 201 |
+
BlockFace.values()[packet.getBlockFace()],
|
| 202 |
+
Hand.MAIN_HAND,
|
| 203 |
+
packet.getClickPosition().getX(), packet.getClickPosition().getY(), packet.getClickPosition().getZ(),
|
| 204 |
+
false);
|
| 205 |
+
session.sendDownstreamPacket(blockPacket);
|
| 206 |
+
|
| 207 |
+
if (packet.getItemInHand() != null) {
|
| 208 |
+
// Otherwise boats will not be able to be placed in survival and buckets won't work on mobile
|
| 209 |
+
if (session.getItemMappings().getBoatIds().contains(packet.getItemInHand().getId())) {
|
| 210 |
+
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
| 211 |
+
session.sendDownstreamPacket(itemPacket);
|
| 212 |
+
} else if (session.getItemMappings().getBucketIds().contains(packet.getItemInHand().getId())) {
|
| 213 |
+
// Let the server decide if the bucket item should change, not the client, and revert the changes the client made
|
| 214 |
+
InventorySlotPacket slotPacket = new InventorySlotPacket();
|
| 215 |
+
slotPacket.setContainerId(ContainerId.INVENTORY);
|
| 216 |
+
slotPacket.setSlot(packet.getHotbarSlot());
|
| 217 |
+
slotPacket.setItem(packet.getItemInHand());
|
| 218 |
+
session.sendUpstreamPacket(slotPacket);
|
| 219 |
+
// Don't send ClientPlayerUseItemPacket for powder snow buckets
|
| 220 |
+
if (packet.getItemInHand().getId() != session.getItemMappings().getStoredItems().powderSnowBucket().getBedrockId()) {
|
| 221 |
+
// Special check for crafting tables since clients don't send BLOCK_INTERACT when interacting
|
| 222 |
+
int blockState = session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition());
|
| 223 |
+
if (session.isSneaking() || blockState != BlockRegistries.JAVA_IDENTIFIERS.get("minecraft:crafting_table")) {
|
| 224 |
+
// Delay the interaction in case the client doesn't intend to actually use the bucket
|
| 225 |
+
// See BedrockActionTranslator.java
|
| 226 |
+
session.setBucketScheduledFuture(session.scheduleInEventLoop(() -> {
|
| 227 |
+
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
| 228 |
+
session.sendDownstreamPacket(itemPacket);
|
| 229 |
+
}, 5, TimeUnit.MILLISECONDS));
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
}
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
if (packet.getActions().isEmpty()) {
|
| 236 |
+
if (session.getOpPermissionLevel() >= 2 && session.getGameMode() == GameMode.CREATIVE) {
|
| 237 |
+
// Otherwise insufficient permissions
|
| 238 |
+
int blockState = session.getBlockMappings().getJavaBlockState(packet.getBlockRuntimeId());
|
| 239 |
+
String blockName = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(blockState, "");
|
| 240 |
+
// In the future this can be used for structure blocks too, however not all elements
|
| 241 |
+
// are available in each GUI
|
| 242 |
+
if (blockName.contains("jigsaw")) {
|
| 243 |
+
ContainerOpenPacket openPacket = new ContainerOpenPacket();
|
| 244 |
+
openPacket.setBlockPosition(packet.getBlockPosition());
|
| 245 |
+
openPacket.setId((byte) 1);
|
| 246 |
+
openPacket.setType(ContainerType.JIGSAW_EDITOR);
|
| 247 |
+
openPacket.setUniqueEntityId(-1);
|
| 248 |
+
session.sendUpstreamPacket(openPacket);
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
ItemMapping handItem = mappings.getMapping(packet.getItemInHand());
|
| 254 |
+
if (handItem.isBlock()) {
|
| 255 |
+
session.setLastBlockPlacePosition(blockPos);
|
| 256 |
+
session.setLastBlockPlacedId(handItem.getJavaIdentifier());
|
| 257 |
+
}
|
| 258 |
+
session.setInteracting(true);
|
| 259 |
+
break;
|
| 260 |
+
case 1:
|
| 261 |
+
if (packet.getActions().size() == 1 && packet.getLegacySlots().size() > 0) {
|
| 262 |
+
InventoryActionData actionData = packet.getActions().get(0);
|
| 263 |
+
LegacySetItemSlotData slotData = packet.getLegacySlots().get(0);
|
| 264 |
+
if (slotData.getContainerId() == 6 && actionData.getToItem().getId() != 0) {
|
| 265 |
+
// The player is trying to swap out an armor piece that already has an item in it
|
| 266 |
+
// Java Edition does not allow this; let's revert it
|
| 267 |
+
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
// Handled when sneaking
|
| 272 |
+
if (session.getPlayerInventory().getItemInHand().getJavaId() == mappings.getStoredItems().shield().getJavaId()) {
|
| 273 |
+
break;
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
// Handled in ITEM_USE if the item is not milk
|
| 277 |
+
if (packet.getItemInHand() != null) {
|
| 278 |
+
if (session.getItemMappings().getBucketIds().contains(packet.getItemInHand().getId()) &&
|
| 279 |
+
packet.getItemInHand().getId() != session.getItemMappings().getStoredItems().milkBucket().getBedrockId()) {
|
| 280 |
+
// Handled in case 0 if the item is not milk
|
| 281 |
+
break;
|
| 282 |
+
} else if (session.getItemMappings().getSpawnEggIds().contains(packet.getItemInHand().getId())) {
|
| 283 |
+
// Handled in case 0
|
| 284 |
+
break;
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
| 289 |
+
session.sendDownstreamPacket(useItemPacket);
|
| 290 |
+
break;
|
| 291 |
+
case 2:
|
| 292 |
+
int blockState = session.getGameMode() == GameMode.CREATIVE ?
|
| 293 |
+
session.getConnector().getWorldManager().getBlockAt(session, packet.getBlockPosition()) : session.getBreakingBlock();
|
| 294 |
+
|
| 295 |
+
session.setLastBlockPlacedId(null);
|
| 296 |
+
session.setLastBlockPlacePosition(null);
|
| 297 |
+
|
| 298 |
+
// Same deal with vanilla block placing as above.
|
| 299 |
+
// This is working out the distance using 3d Pythagoras and the extra value added to the Y is the sneaking height of a java player.
|
| 300 |
+
playerPosition = session.getPlayerEntity().getPosition();
|
| 301 |
+
Vector3f floatBlockPosition = packet.getBlockPosition().toFloat();
|
| 302 |
+
diffX = playerPosition.getX() - (floatBlockPosition.getX() + 0.5f);
|
| 303 |
+
diffY = (playerPosition.getY() - EntityType.PLAYER.getOffset()) - (floatBlockPosition.getY() + 0.5f) + 1.5f;
|
| 304 |
+
diffZ = playerPosition.getZ() - (floatBlockPosition.getZ() + 0.5f);
|
| 305 |
+
float distanceSquared = diffX * diffX + diffY * diffY + diffZ * diffZ;
|
| 306 |
+
if (distanceSquared > MAXIMUM_BLOCK_DESTROYING_DISTANCE) {
|
| 307 |
+
restoreCorrectBlock(session, packet.getBlockPosition(), packet);
|
| 308 |
+
return;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
LevelEventPacket blockBreakPacket = new LevelEventPacket();
|
| 312 |
+
blockBreakPacket.setType(LevelEventType.PARTICLE_DESTROY_BLOCK);
|
| 313 |
+
blockBreakPacket.setPosition(packet.getBlockPosition().toFloat());
|
| 314 |
+
blockBreakPacket.setData(session.getBlockMappings().getBedrockBlockId(blockState));
|
| 315 |
+
session.sendUpstreamPacket(blockBreakPacket);
|
| 316 |
+
session.setBreakingBlock(BlockStateValues.JAVA_AIR_ID);
|
| 317 |
+
|
| 318 |
+
Entity itemFrameEntity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
| 319 |
+
if (itemFrameEntity != null) {
|
| 320 |
+
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) itemFrameEntity.getEntityId(),
|
| 321 |
+
InteractAction.ATTACK, session.isSneaking());
|
| 322 |
+
session.sendDownstreamPacket(attackPacket);
|
| 323 |
+
break;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
PlayerAction action = session.getGameMode() == GameMode.CREATIVE ? PlayerAction.START_DIGGING : PlayerAction.FINISH_DIGGING;
|
| 327 |
+
Position pos = new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ());
|
| 328 |
+
ClientPlayerActionPacket breakPacket = new ClientPlayerActionPacket(action, pos, BlockFace.values()[packet.getBlockFace()]);
|
| 329 |
+
session.sendDownstreamPacket(breakPacket);
|
| 330 |
+
break;
|
| 331 |
+
}
|
| 332 |
+
break;
|
| 333 |
+
case ITEM_RELEASE:
|
| 334 |
+
if (packet.getActionType() == 0) {
|
| 335 |
+
// Followed to the Minecraft Protocol specification outlined at wiki.vg
|
| 336 |
+
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.RELEASE_USE_ITEM, BlockUtils.POSITION_ZERO,
|
| 337 |
+
BlockFace.DOWN);
|
| 338 |
+
session.sendDownstreamPacket(releaseItemPacket);
|
| 339 |
+
}
|
| 340 |
+
break;
|
| 341 |
+
case ITEM_USE_ON_ENTITY:
|
| 342 |
+
Entity entity = session.getEntityCache().getEntityByGeyserId(packet.getRuntimeEntityId());
|
| 343 |
+
if (entity == null)
|
| 344 |
+
return;
|
| 345 |
+
|
| 346 |
+
//https://wiki.vg/Protocol#Interact_Entity
|
| 347 |
+
switch (packet.getActionType()) {
|
| 348 |
+
case 0: //Interact
|
| 349 |
+
if (entity instanceof CommandBlockMinecartEntity) {
|
| 350 |
+
// The UI is handled client-side on Java Edition
|
| 351 |
+
// Ensure OP permission level and gamemode is appropriate
|
| 352 |
+
if (session.getOpPermissionLevel() < 2 || session.getGameMode() != GameMode.CREATIVE) return;
|
| 353 |
+
ContainerOpenPacket openPacket = new ContainerOpenPacket();
|
| 354 |
+
openPacket.setBlockPosition(Vector3i.ZERO);
|
| 355 |
+
openPacket.setId((byte) 1);
|
| 356 |
+
openPacket.setType(ContainerType.COMMAND_BLOCK);
|
| 357 |
+
openPacket.setUniqueEntityId(entity.getGeyserId());
|
| 358 |
+
session.sendUpstreamPacket(openPacket);
|
| 359 |
+
break;
|
| 360 |
+
}
|
| 361 |
+
Vector3f vector = packet.getClickPosition().sub(entity.getPosition());
|
| 362 |
+
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
| 363 |
+
InteractAction.INTERACT, Hand.MAIN_HAND, session.isSneaking());
|
| 364 |
+
ClientPlayerInteractEntityPacket interactAtPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
| 365 |
+
InteractAction.INTERACT_AT, vector.getX(), vector.getY(), vector.getZ(), Hand.MAIN_HAND, session.isSneaking());
|
| 366 |
+
session.sendDownstreamPacket(interactPacket);
|
| 367 |
+
session.sendDownstreamPacket(interactAtPacket);
|
| 368 |
+
|
| 369 |
+
EntitySoundInteractionHandler.handleEntityInteraction(session, packet.getClickPosition(), entity);
|
| 370 |
+
break;
|
| 371 |
+
case 1: //Attack
|
| 372 |
+
if (entity.getEntityType() == EntityType.ENDER_DRAGON) {
|
| 373 |
+
// Redirects the attack to its body entity, this only happens when
|
| 374 |
+
// attacking the underbelly of the ender dragon
|
| 375 |
+
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId() + 3,
|
| 376 |
+
InteractAction.ATTACK, session.isSneaking());
|
| 377 |
+
session.sendDownstreamPacket(attackPacket);
|
| 378 |
+
} else {
|
| 379 |
+
ClientPlayerInteractEntityPacket attackPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
| 380 |
+
InteractAction.ATTACK, session.isSneaking());
|
| 381 |
+
session.sendDownstreamPacket(attackPacket);
|
| 382 |
+
}
|
| 383 |
+
break;
|
| 384 |
+
}
|
| 385 |
+
break;
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/**
|
| 390 |
+
* Restore the correct block state from the server without updating the chunk cache.
|
| 391 |
+
*
|
| 392 |
+
* @param session the session of the Bedrock client
|
| 393 |
+
* @param blockPos the block position to restore
|
| 394 |
+
*/
|
| 395 |
+
private void restoreCorrectBlock(GeyserSession session, Vector3i blockPos, InventoryTransactionPacket packet) {
|
| 396 |
+
int javaBlockState = session.getConnector().getWorldManager().getBlockAt(session, blockPos);
|
| 397 |
+
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
|
| 398 |
+
updateBlockPacket.setDataLayer(0);
|
| 399 |
+
updateBlockPacket.setBlockPosition(blockPos);
|
| 400 |
+
updateBlockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(javaBlockState));
|
| 401 |
+
updateBlockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
|
| 402 |
+
session.sendUpstreamPacket(updateBlockPacket);
|
| 403 |
+
|
| 404 |
+
UpdateBlockPacket updateWaterPacket = new UpdateBlockPacket();
|
| 405 |
+
updateWaterPacket.setDataLayer(1);
|
| 406 |
+
updateWaterPacket.setBlockPosition(blockPos);
|
| 407 |
+
updateWaterPacket.setRuntimeId(BlockRegistries.WATERLOGGED.get().contains(javaBlockState) ? session.getBlockMappings().getBedrockWaterId() : session.getBlockMappings().getBedrockAirId());
|
| 408 |
+
updateWaterPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
|
| 409 |
+
session.sendUpstreamPacket(updateWaterPacket);
|
| 410 |
+
|
| 411 |
+
// Reset the item in hand to prevent "missing" blocks
|
| 412 |
+
InventorySlotPacket slotPacket = new InventorySlotPacket();
|
| 413 |
+
slotPacket.setContainerId(ContainerId.INVENTORY);
|
| 414 |
+
slotPacket.setSlot(packet.getHotbarSlot());
|
| 415 |
+
slotPacket.setItem(packet.getItemInHand());
|
| 416 |
+
session.sendUpstreamPacket(slotPacket);
|
| 417 |
+
}
|
| 418 |
+
}
|
Java/BedrockItemFrameDropItemTranslator.java
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerInteractEntityPacket;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.ItemFrameDropItemPacket;
|
| 32 |
+
import org.geysermc.connector.entity.Entity;
|
| 33 |
+
import org.geysermc.connector.entity.ItemFrameEntity;
|
| 34 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 35 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 36 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* Pre-1.16.210: used for both survival and creative item frame item removal
|
| 40 |
+
*
|
| 41 |
+
* 1.16.210: only used in creative.
|
| 42 |
+
*/
|
| 43 |
+
@Translator(packet = ItemFrameDropItemPacket.class)
|
| 44 |
+
public class BedrockItemFrameDropItemTranslator extends PacketTranslator<ItemFrameDropItemPacket> {
|
| 45 |
+
|
| 46 |
+
@Override
|
| 47 |
+
// BUG: CWE-287 Improper Authentication
|
| 48 |
+
// public void translate(ItemFrameDropItemPacket packet, GeyserSession session) {
|
| 49 |
+
// FIXED:
|
| 50 |
+
public void translate(GeyserSession session, ItemFrameDropItemPacket packet) {
|
| 51 |
+
Entity entity = ItemFrameEntity.getItemFrameEntity(session, packet.getBlockPosition());
|
| 52 |
+
if (entity != null) {
|
| 53 |
+
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
| 54 |
+
InteractAction.ATTACK, Hand.MAIN_HAND, session.isSneaking());
|
| 55 |
+
session.sendDownstreamPacket(interactPacket);
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
}
|
Java/BedrockItemStackRequestTranslator.java
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.packet.ItemStackRequestPacket;
|
| 29 |
+
import org.geysermc.connector.inventory.Inventory;
|
| 30 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 31 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 32 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 33 |
+
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
| 34 |
+
|
| 35 |
+
/**
|
| 36 |
+
* The packet sent for server-authoritative-style inventory transactions.
|
| 37 |
+
*/
|
| 38 |
+
@Translator(packet = ItemStackRequestPacket.class)
|
| 39 |
+
public class BedrockItemStackRequestTranslator extends PacketTranslator<ItemStackRequestPacket> {
|
| 40 |
+
|
| 41 |
+
@Override
|
| 42 |
+
// BUG: CWE-287 Improper Authentication
|
| 43 |
+
// public void translate(ItemStackRequestPacket packet, GeyserSession session) {
|
| 44 |
+
// FIXED:
|
| 45 |
+
public void translate(GeyserSession session, ItemStackRequestPacket packet) {
|
| 46 |
+
Inventory inventory = session.getOpenInventory();
|
| 47 |
+
if (inventory == null)
|
| 48 |
+
return;
|
| 49 |
+
|
| 50 |
+
InventoryTranslator translator = session.getInventoryTranslator();
|
| 51 |
+
translator.translateRequests(session, inventory, packet.getRequests());
|
| 52 |
+
}
|
| 53 |
+
}
|
Java/BedrockLecternUpdateTranslator.java
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
| 29 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
| 30 |
+
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
|
| 31 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPlaceBlockPacket;
|
| 32 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientClickWindowButtonPacket;
|
| 33 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket;
|
| 34 |
+
import com.nukkitx.protocol.bedrock.packet.LecternUpdatePacket;
|
| 35 |
+
import org.geysermc.connector.inventory.LecternContainer;
|
| 36 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 37 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 38 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 39 |
+
import org.geysermc.connector.utils.InventoryUtils;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Used to translate moving pages, or closing the inventory
|
| 43 |
+
*/
|
| 44 |
+
@Translator(packet = LecternUpdatePacket.class)
|
| 45 |
+
public class BedrockLecternUpdateTranslator extends PacketTranslator<LecternUpdatePacket> {
|
| 46 |
+
|
| 47 |
+
@Override
|
| 48 |
+
// BUG: CWE-287 Improper Authentication
|
| 49 |
+
// public void translate(LecternUpdatePacket packet, GeyserSession session) {
|
| 50 |
+
// FIXED:
|
| 51 |
+
public void translate(GeyserSession session, LecternUpdatePacket packet) {
|
| 52 |
+
if (packet.isDroppingBook()) {
|
| 53 |
+
// Bedrock drops the book outside of the GUI. Java drops it in the GUI
|
| 54 |
+
// So, we enter the GUI and then drop it! :)
|
| 55 |
+
session.setDroppingLecternBook(true);
|
| 56 |
+
|
| 57 |
+
// Emulate an interact packet
|
| 58 |
+
ClientPlayerPlaceBlockPacket blockPacket = new ClientPlayerPlaceBlockPacket(
|
| 59 |
+
new Position(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ()),
|
| 60 |
+
BlockFace.DOWN,
|
| 61 |
+
Hand.MAIN_HAND,
|
| 62 |
+
0, 0, 0, // Java doesn't care about these when dealing with a lectern
|
| 63 |
+
false);
|
| 64 |
+
session.sendDownstreamPacket(blockPacket);
|
| 65 |
+
} else {
|
| 66 |
+
// Bedrock wants to either move a page or exit
|
| 67 |
+
if (!(session.getOpenInventory() instanceof LecternContainer)) {
|
| 68 |
+
session.getConnector().getLogger().debug("Expected lectern but it wasn't open!");
|
| 69 |
+
return;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
LecternContainer lecternContainer = (LecternContainer) session.getOpenInventory();
|
| 73 |
+
if (lecternContainer.getCurrentBedrockPage() == packet.getPage()) {
|
| 74 |
+
// The same page means Bedrock is closing the window
|
| 75 |
+
ClientCloseWindowPacket closeWindowPacket = new ClientCloseWindowPacket(lecternContainer.getId());
|
| 76 |
+
session.sendDownstreamPacket(closeWindowPacket);
|
| 77 |
+
InventoryUtils.closeInventory(session, lecternContainer.getId(), false);
|
| 78 |
+
} else {
|
| 79 |
+
// Each "page" Bedrock gives to us actually represents two pages (think opening a book and seeing two pages)
|
| 80 |
+
// Each "page" on Java is just one page (think a spiral notebook folded back to only show one page)
|
| 81 |
+
int newJavaPage = (packet.getPage() * 2);
|
| 82 |
+
int currentJavaPage = (lecternContainer.getCurrentBedrockPage() * 2);
|
| 83 |
+
|
| 84 |
+
// Send as many click button packets as we need to
|
| 85 |
+
// Java has the option to specify exact page numbers by adding 100 to the number, but buttonId variable
|
| 86 |
+
// is a byte when transmitted over the network and therefore this stops us at 128
|
| 87 |
+
if (newJavaPage > currentJavaPage) {
|
| 88 |
+
for (int i = currentJavaPage; i < newJavaPage; i++) {
|
| 89 |
+
ClientClickWindowButtonPacket clickButtonPacket = new ClientClickWindowButtonPacket(session.getOpenInventory().getId(), 2);
|
| 90 |
+
session.sendDownstreamPacket(clickButtonPacket);
|
| 91 |
+
}
|
| 92 |
+
} else {
|
| 93 |
+
for (int i = currentJavaPage; i > newJavaPage; i--) {
|
| 94 |
+
ClientClickWindowButtonPacket clickButtonPacket = new ClientClickWindowButtonPacket(session.getOpenInventory().getId(), 1);
|
| 95 |
+
session.sendDownstreamPacket(clickButtonPacket);
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
}
|
Java/BedrockMapInfoRequestTranslator.java
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.packet.ClientboundMapItemDataPacket;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.MapInfoRequestPacket;
|
| 30 |
+
import org.geysermc.connector.GeyserConnector;
|
| 31 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 32 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 33 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 34 |
+
|
| 35 |
+
import java.util.concurrent.TimeUnit;
|
| 36 |
+
|
| 37 |
+
@Translator(packet = MapInfoRequestPacket.class)
|
| 38 |
+
public class BedrockMapInfoRequestTranslator extends PacketTranslator<MapInfoRequestPacket> {
|
| 39 |
+
|
| 40 |
+
@Override
|
| 41 |
+
// BUG: CWE-287 Improper Authentication
|
| 42 |
+
// public void translate(MapInfoRequestPacket packet, GeyserSession session) {
|
| 43 |
+
// FIXED:
|
| 44 |
+
public void translate(GeyserSession session, MapInfoRequestPacket packet) {
|
| 45 |
+
long mapId = packet.getUniqueMapId();
|
| 46 |
+
|
| 47 |
+
ClientboundMapItemDataPacket mapPacket = session.getStoredMaps().remove(mapId);
|
| 48 |
+
if (mapPacket != null) {
|
| 49 |
+
// Delay the packet 100ms to prevent the client from ignoring the packet
|
| 50 |
+
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> session.sendUpstreamPacket(mapPacket),
|
| 51 |
+
100, TimeUnit.MILLISECONDS);
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
}
|
Java/BedrockMobEquipmentTranslator.java
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerChangeHeldItemPacket;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.data.inventory.ContainerId;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.MobEquipmentPacket;
|
| 33 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 34 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 35 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 36 |
+
import org.geysermc.connector.utils.CooldownUtils;
|
| 37 |
+
import org.geysermc.connector.utils.InteractiveTagManager;
|
| 38 |
+
|
| 39 |
+
import java.util.concurrent.TimeUnit;
|
| 40 |
+
|
| 41 |
+
@Translator(packet = MobEquipmentPacket.class)
|
| 42 |
+
public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipmentPacket> {
|
| 43 |
+
|
| 44 |
+
@Override
|
| 45 |
+
// BUG: CWE-287 Improper Authentication
|
| 46 |
+
// public void translate(MobEquipmentPacket packet, GeyserSession session) {
|
| 47 |
+
// FIXED:
|
| 48 |
+
public void translate(GeyserSession session, MobEquipmentPacket packet) {
|
| 49 |
+
if (!session.isSpawned() || packet.getHotbarSlot() > 8 ||
|
| 50 |
+
packet.getContainerId() != ContainerId.INVENTORY || session.getPlayerInventory().getHeldItemSlot() == packet.getHotbarSlot()) {
|
| 51 |
+
// For the last condition - Don't update the slot if the slot is the same - not Java Edition behavior and messes with plugins such as Grief Prevention
|
| 52 |
+
return;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
// Send book update before switching hotbar slot
|
| 56 |
+
session.getBookEditCache().checkForSend();
|
| 57 |
+
|
| 58 |
+
session.getPlayerInventory().setHeldItemSlot(packet.getHotbarSlot());
|
| 59 |
+
|
| 60 |
+
ClientPlayerChangeHeldItemPacket changeHeldItemPacket = new ClientPlayerChangeHeldItemPacket(packet.getHotbarSlot());
|
| 61 |
+
session.sendDownstreamPacket(changeHeldItemPacket);
|
| 62 |
+
|
| 63 |
+
if (session.isSneaking() && session.getPlayerInventory().getItemInHand().getJavaId() == session.getItemMappings().getStoredItems().shield().getJavaId()) {
|
| 64 |
+
// Activate shield since we are already sneaking
|
| 65 |
+
// (No need to send a release item packet - Java doesn't do this when swapping items)
|
| 66 |
+
// Required to do it a tick later or else it doesn't register
|
| 67 |
+
session.getConnector().getGeneralThreadPool().schedule(() -> session.sendDownstreamPacket(new ClientPlayerUseItemPacket(Hand.MAIN_HAND)),
|
| 68 |
+
50, TimeUnit.MILLISECONDS);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Java sends a cooldown indicator whenever you switch an item
|
| 72 |
+
CooldownUtils.sendCooldown(session);
|
| 73 |
+
|
| 74 |
+
// Update the interactive tag, if an entity is present
|
| 75 |
+
if (session.getMouseoverEntity() != null) {
|
| 76 |
+
InteractiveTagManager.updateTag(session, session.getMouseoverEntity());
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
}
|
Java/BedrockMoveEntityAbsoluteTranslator.java
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
| 30 |
+
import org.geysermc.connector.entity.BoatEntity;
|
| 31 |
+
import org.geysermc.connector.entity.type.EntityType;
|
| 32 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 33 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 34 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 35 |
+
|
| 36 |
+
/**
|
| 37 |
+
* Sent by the client when moving a horse.
|
| 38 |
+
*/
|
| 39 |
+
@Translator(packet = MoveEntityAbsolutePacket.class)
|
| 40 |
+
public class BedrockMoveEntityAbsoluteTranslator extends PacketTranslator<MoveEntityAbsolutePacket> {
|
| 41 |
+
|
| 42 |
+
@Override
|
| 43 |
+
// BUG: CWE-287 Improper Authentication
|
| 44 |
+
// public void translate(MoveEntityAbsolutePacket packet, GeyserSession session) {
|
| 45 |
+
// FIXED:
|
| 46 |
+
public void translate(GeyserSession session, MoveEntityAbsolutePacket packet) {
|
| 47 |
+
session.setLastVehicleMoveTimestamp(System.currentTimeMillis());
|
| 48 |
+
|
| 49 |
+
float y = packet.getPosition().getY();
|
| 50 |
+
if (session.getRidingVehicleEntity() instanceof BoatEntity) {
|
| 51 |
+
// Remove the offset to prevents boats from looking like they're floating in water
|
| 52 |
+
y -= EntityType.BOAT.getOffset();
|
| 53 |
+
}
|
| 54 |
+
ClientVehicleMovePacket clientVehicleMovePacket = new ClientVehicleMovePacket(
|
| 55 |
+
packet.getPosition().getX(), y, packet.getPosition().getZ(),
|
| 56 |
+
packet.getRotation().getY() - 90, packet.getRotation().getX()
|
| 57 |
+
);
|
| 58 |
+
session.sendDownstreamPacket(clientVehicleMovePacket);
|
| 59 |
+
}
|
| 60 |
+
}
|
Java/BedrockMovePlayerTranslator.java
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity.player;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
| 30 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerRotationPacket;
|
| 31 |
+
import com.github.steveice10.packetlib.packet.Packet;
|
| 32 |
+
import com.nukkitx.math.vector.Vector3d;
|
| 33 |
+
import com.nukkitx.math.vector.Vector3f;
|
| 34 |
+
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
|
| 35 |
+
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
| 36 |
+
import org.geysermc.connector.GeyserConnector;
|
| 37 |
+
import org.geysermc.connector.common.ChatColor;
|
| 38 |
+
import org.geysermc.connector.entity.player.SessionPlayerEntity;
|
| 39 |
+
import org.geysermc.connector.entity.type.EntityType;
|
| 40 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 41 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 42 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 43 |
+
|
| 44 |
+
@Translator(packet = MovePlayerPacket.class)
|
| 45 |
+
public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPacket> {
|
| 46 |
+
/* The upper and lower bounds to check for the void floor that only exists in Bedrock */
|
| 47 |
+
private static final int BEDROCK_OVERWORLD_VOID_FLOOR_UPPER_Y;
|
| 48 |
+
private static final int BEDROCK_OVERWORLD_VOID_FLOOR_LOWER_Y;
|
| 49 |
+
|
| 50 |
+
static {
|
| 51 |
+
BEDROCK_OVERWORLD_VOID_FLOOR_UPPER_Y = GeyserConnector.getInstance().getConfig().isExtendedWorldHeight() ? -104 : -40;
|
| 52 |
+
BEDROCK_OVERWORLD_VOID_FLOOR_LOWER_Y = BEDROCK_OVERWORLD_VOID_FLOOR_UPPER_Y + 2;
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
@Override
|
| 56 |
+
// BUG: CWE-287 Improper Authentication
|
| 57 |
+
// public void translate(MovePlayerPacket packet, GeyserSession session) {
|
| 58 |
+
// FIXED:
|
| 59 |
+
public void translate(GeyserSession session, MovePlayerPacket packet) {
|
| 60 |
+
SessionPlayerEntity entity = session.getPlayerEntity();
|
| 61 |
+
if (!session.isSpawned()) return;
|
| 62 |
+
|
| 63 |
+
if (!session.getUpstream().isInitialized()) {
|
| 64 |
+
MoveEntityAbsolutePacket moveEntityBack = new MoveEntityAbsolutePacket();
|
| 65 |
+
moveEntityBack.setRuntimeEntityId(entity.getGeyserId());
|
| 66 |
+
moveEntityBack.setPosition(entity.getPosition());
|
| 67 |
+
moveEntityBack.setRotation(entity.getBedrockRotation());
|
| 68 |
+
moveEntityBack.setTeleported(true);
|
| 69 |
+
moveEntityBack.setOnGround(true);
|
| 70 |
+
session.sendUpstreamPacketImmediately(moveEntityBack);
|
| 71 |
+
return;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
session.setLastMovementTimestamp(System.currentTimeMillis());
|
| 75 |
+
|
| 76 |
+
// Send book update before the player moves
|
| 77 |
+
session.getBookEditCache().checkForSend();
|
| 78 |
+
|
| 79 |
+
session.confirmTeleport(packet.getPosition().toDouble().sub(0, EntityType.PLAYER.getOffset(), 0));
|
| 80 |
+
// head yaw, pitch, head yaw
|
| 81 |
+
Vector3f rotation = Vector3f.from(packet.getRotation().getY(), packet.getRotation().getX(), packet.getRotation().getY());
|
| 82 |
+
|
| 83 |
+
boolean positionChanged = !entity.getPosition().equals(packet.getPosition());
|
| 84 |
+
boolean rotationChanged = !entity.getRotation().equals(rotation);
|
| 85 |
+
|
| 86 |
+
// If only the pitch and yaw changed
|
| 87 |
+
// This isn't needed, but it makes the packets closer to vanilla
|
| 88 |
+
// It also means you can't "lag back" while only looking, in theory
|
| 89 |
+
if (!positionChanged && rotationChanged) {
|
| 90 |
+
ClientPlayerRotationPacket playerRotationPacket = new ClientPlayerRotationPacket(
|
| 91 |
+
packet.isOnGround(), packet.getRotation().getY(), packet.getRotation().getX());
|
| 92 |
+
|
| 93 |
+
entity.setRotation(rotation);
|
| 94 |
+
entity.setOnGround(packet.isOnGround());
|
| 95 |
+
|
| 96 |
+
session.sendDownstreamPacket(playerRotationPacket);
|
| 97 |
+
} else {
|
| 98 |
+
Vector3d position = session.getCollisionManager().adjustBedrockPosition(packet.getPosition(), packet.isOnGround());
|
| 99 |
+
if (position != null) { // A null return value cancels the packet
|
| 100 |
+
if (isValidMove(session, packet.getMode(), entity.getPosition(), packet.getPosition())) {
|
| 101 |
+
Packet movePacket;
|
| 102 |
+
if (rotationChanged) {
|
| 103 |
+
// Send rotation updates as well
|
| 104 |
+
movePacket = new ClientPlayerPositionRotationPacket(packet.isOnGround(), position.getX(), position.getY(), position.getZ(),
|
| 105 |
+
packet.getRotation().getY(), packet.getRotation().getX());
|
| 106 |
+
entity.setRotation(rotation);
|
| 107 |
+
} else {
|
| 108 |
+
// Rotation did not change; don't send an update with rotation
|
| 109 |
+
movePacket = new ClientPlayerPositionPacket(packet.isOnGround(), position.getX(), position.getY(), position.getZ());
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Compare positions here for void floor fix below before the player's position variable is set to the packet position
|
| 113 |
+
boolean notMovingUp = entity.getPosition().getY() >= packet.getPosition().getY();
|
| 114 |
+
|
| 115 |
+
entity.setPositionManual(packet.getPosition());
|
| 116 |
+
entity.setOnGround(packet.isOnGround());
|
| 117 |
+
|
| 118 |
+
// Send final movement changes
|
| 119 |
+
session.sendDownstreamPacket(movePacket);
|
| 120 |
+
|
| 121 |
+
if (notMovingUp) {
|
| 122 |
+
int floorY = position.getFloorY();
|
| 123 |
+
// If the client believes the world has extended height, then it also believes the void floor
|
| 124 |
+
// still exists, just at a lower spot
|
| 125 |
+
boolean extendedWorld = session.getChunkCache().isExtendedHeight();
|
| 126 |
+
if (floorY <= (extendedWorld ? BEDROCK_OVERWORLD_VOID_FLOOR_LOWER_Y : -38)
|
| 127 |
+
&& floorY >= (extendedWorld ? BEDROCK_OVERWORLD_VOID_FLOOR_UPPER_Y : -40)) {
|
| 128 |
+
// Work around there being a floor at the bottom of the world and teleport the player below it
|
| 129 |
+
// Moving from below to above the void floor works fine
|
| 130 |
+
entity.setPosition(entity.getPosition().sub(0, 4f, 0));
|
| 131 |
+
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
| 132 |
+
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
| 133 |
+
movePlayerPacket.setPosition(entity.getPosition());
|
| 134 |
+
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
| 135 |
+
movePlayerPacket.setMode(MovePlayerPacket.Mode.TELEPORT);
|
| 136 |
+
movePlayerPacket.setTeleportationCause(MovePlayerPacket.TeleportationCause.BEHAVIOR);
|
| 137 |
+
session.sendUpstreamPacket(movePlayerPacket);
|
| 138 |
+
}
|
| 139 |
+
}
|
| 140 |
+
} else {
|
| 141 |
+
// Not a valid move
|
| 142 |
+
session.getConnector().getLogger().debug("Recalculating position...");
|
| 143 |
+
session.getCollisionManager().recalculatePosition();
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
// Move parrots to match if applicable
|
| 149 |
+
if (entity.getLeftParrot() != null) {
|
| 150 |
+
entity.getLeftParrot().moveAbsolute(session, entity.getPosition(), entity.getRotation(), true, false);
|
| 151 |
+
}
|
| 152 |
+
if (entity.getRightParrot() != null) {
|
| 153 |
+
entity.getRightParrot().moveAbsolute(session, entity.getPosition(), entity.getRotation(), true, false);
|
| 154 |
+
}
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
private boolean isValidMove(GeyserSession session, MovePlayerPacket.Mode mode, Vector3f currentPosition, Vector3f newPosition) {
|
| 158 |
+
if (mode != MovePlayerPacket.Mode.NORMAL)
|
| 159 |
+
return true;
|
| 160 |
+
|
| 161 |
+
double xRange = newPosition.getX() - currentPosition.getX();
|
| 162 |
+
double yRange = newPosition.getY() - currentPosition.getY();
|
| 163 |
+
double zRange = newPosition.getZ() - currentPosition.getZ();
|
| 164 |
+
|
| 165 |
+
if (xRange < 0)
|
| 166 |
+
xRange = -xRange;
|
| 167 |
+
if (yRange < 0)
|
| 168 |
+
yRange = -yRange;
|
| 169 |
+
if (zRange < 0)
|
| 170 |
+
zRange = -zRange;
|
| 171 |
+
|
| 172 |
+
if ((xRange + yRange + zRange) > 100) {
|
| 173 |
+
session.getConnector().getLogger().debug(ChatColor.RED + session.getName() + " moved too quickly." +
|
| 174 |
+
" current position: " + currentPosition + ", new position: " + newPosition);
|
| 175 |
+
|
| 176 |
+
return false;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
return true;
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
Java/BedrockNetworkStackLatencyTranslator.java
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientKeepAlivePacket;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.data.AttributeData;
|
| 30 |
+
import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
|
| 32 |
+
import org.geysermc.connector.entity.attribute.GeyserAttributeType;
|
| 33 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 34 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 35 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 36 |
+
import org.geysermc.floodgate.util.DeviceOs;
|
| 37 |
+
|
| 38 |
+
import java.util.Collections;
|
| 39 |
+
import java.util.concurrent.TimeUnit;
|
| 40 |
+
|
| 41 |
+
/**
|
| 42 |
+
* Used to send the forwarded keep alive packet back to the server
|
| 43 |
+
*/
|
| 44 |
+
@Translator(packet = NetworkStackLatencyPacket.class)
|
| 45 |
+
public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<NetworkStackLatencyPacket> {
|
| 46 |
+
|
| 47 |
+
@Override
|
| 48 |
+
// BUG: CWE-287 Improper Authentication
|
| 49 |
+
// public void translate(NetworkStackLatencyPacket packet, GeyserSession session) {
|
| 50 |
+
// FIXED:
|
| 51 |
+
public void translate(GeyserSession session, NetworkStackLatencyPacket packet) {
|
| 52 |
+
long pingId;
|
| 53 |
+
// so apparently, as of 1.16.200
|
| 54 |
+
// PS4 divides the network stack latency timestamp FOR US!!!
|
| 55 |
+
// WTF
|
| 56 |
+
if (session.getClientData().getDeviceOs().equals(DeviceOs.PS4)) {
|
| 57 |
+
pingId = packet.getTimestamp();
|
| 58 |
+
} else {
|
| 59 |
+
pingId = packet.getTimestamp() / 1000;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// negative timestamps are used as hack to fix the url image loading bug
|
| 63 |
+
if (packet.getTimestamp() > 0) {
|
| 64 |
+
if (session.getConnector().getConfig().isForwardPlayerPing()) {
|
| 65 |
+
ClientKeepAlivePacket keepAlivePacket = new ClientKeepAlivePacket(pingId);
|
| 66 |
+
session.sendDownstreamPacket(keepAlivePacket);
|
| 67 |
+
}
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
// Hack to fix the url image loading bug
|
| 72 |
+
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
| 73 |
+
attributesPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
|
| 74 |
+
|
| 75 |
+
AttributeData attribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.EXPERIENCE_LEVEL);
|
| 76 |
+
if (attribute != null) {
|
| 77 |
+
attributesPacket.setAttributes(Collections.singletonList(attribute));
|
| 78 |
+
} else {
|
| 79 |
+
attributesPacket.setAttributes(Collections.singletonList(GeyserAttributeType.EXPERIENCE_LEVEL.getAttribute(0)));
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
session.getConnector().getGeneralThreadPool().schedule(
|
| 83 |
+
() -> session.sendUpstreamPacket(attributesPacket),
|
| 84 |
+
500, TimeUnit.MILLISECONDS);
|
| 85 |
+
}
|
| 86 |
+
}
|
Java/BedrockPacketViolationWarningTranslator.java
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.packet.PacketViolationWarningPacket;
|
| 29 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 30 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 31 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 32 |
+
|
| 33 |
+
@Translator(packet = PacketViolationWarningPacket.class)
|
| 34 |
+
public class BedrockPacketViolationWarningTranslator extends PacketTranslator<PacketViolationWarningPacket> {
|
| 35 |
+
|
| 36 |
+
@Override
|
| 37 |
+
// BUG: CWE-287 Improper Authentication
|
| 38 |
+
// public void translate(PacketViolationWarningPacket packet, GeyserSession session) {
|
| 39 |
+
// FIXED:
|
| 40 |
+
public void translate(GeyserSession session, PacketViolationWarningPacket packet) {
|
| 41 |
+
// Not translated since this is something that the developers need to know
|
| 42 |
+
session.getConnector().getLogger().error("Packet violation warning sent from client! " + packet.toString());
|
| 43 |
+
}
|
| 44 |
+
}
|
Java/BedrockPlayerInputTranslator.java
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientSteerVehiclePacket;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientVehicleMovePacket;
|
| 30 |
+
import com.nukkitx.math.vector.Vector3f;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.PlayerInputPacket;
|
| 33 |
+
import org.geysermc.connector.entity.BoatEntity;
|
| 34 |
+
import org.geysermc.connector.entity.Entity;
|
| 35 |
+
import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity;
|
| 36 |
+
import org.geysermc.connector.entity.living.animal.horse.LlamaEntity;
|
| 37 |
+
import org.geysermc.connector.entity.type.EntityType;
|
| 38 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 39 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 40 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 41 |
+
|
| 42 |
+
/**
|
| 43 |
+
* Sent by the client for minecarts and boats.
|
| 44 |
+
*/
|
| 45 |
+
@Translator(packet = PlayerInputPacket.class)
|
| 46 |
+
public class BedrockPlayerInputTranslator extends PacketTranslator<PlayerInputPacket> {
|
| 47 |
+
|
| 48 |
+
@Override
|
| 49 |
+
// BUG: CWE-287 Improper Authentication
|
| 50 |
+
// public void translate(PlayerInputPacket packet, GeyserSession session) {
|
| 51 |
+
// FIXED:
|
| 52 |
+
public void translate(GeyserSession session, PlayerInputPacket packet) {
|
| 53 |
+
ClientSteerVehiclePacket clientSteerVehiclePacket = new ClientSteerVehiclePacket(
|
| 54 |
+
packet.getInputMotion().getX(), packet.getInputMotion().getY(), packet.isJumping(), packet.isSneaking()
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
session.sendDownstreamPacket(clientSteerVehiclePacket);
|
| 58 |
+
|
| 59 |
+
// Bedrock only sends movement vehicle packets while moving
|
| 60 |
+
// This allows horses to take damage while standing on magma
|
| 61 |
+
Entity vehicle = session.getRidingVehicleEntity();
|
| 62 |
+
boolean sendMovement = false;
|
| 63 |
+
if (vehicle instanceof AbstractHorseEntity && !(vehicle instanceof LlamaEntity)) {
|
| 64 |
+
sendMovement = vehicle.isOnGround();
|
| 65 |
+
} else if (vehicle instanceof BoatEntity) {
|
| 66 |
+
if (vehicle.getPassengers().size() == 1) {
|
| 67 |
+
// The player is the only rider
|
| 68 |
+
sendMovement = true;
|
| 69 |
+
} else {
|
| 70 |
+
// Check if the player is the front rider
|
| 71 |
+
Vector3f seatPos = session.getPlayerEntity().getMetadata().getVector3f(EntityData.RIDER_SEAT_POSITION, null);
|
| 72 |
+
if (seatPos != null && seatPos.getX() > 0) {
|
| 73 |
+
sendMovement = true;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
if (sendMovement) {
|
| 78 |
+
long timeSinceVehicleMove = System.currentTimeMillis() - session.getLastVehicleMoveTimestamp();
|
| 79 |
+
if (timeSinceVehicleMove >= 100) {
|
| 80 |
+
Vector3f vehiclePosition = vehicle.getPosition();
|
| 81 |
+
Vector3f vehicleRotation = vehicle.getRotation();
|
| 82 |
+
|
| 83 |
+
if (vehicle instanceof BoatEntity) {
|
| 84 |
+
// Remove some Y position to prevents boats flying up
|
| 85 |
+
vehiclePosition = vehiclePosition.down(EntityType.BOAT.getOffset());
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
ClientVehicleMovePacket clientVehicleMovePacket = new ClientVehicleMovePacket(
|
| 89 |
+
vehiclePosition.getX(), vehiclePosition.getY(), vehiclePosition.getZ(),
|
| 90 |
+
vehicleRotation.getX() - 90, vehicleRotation.getY()
|
| 91 |
+
);
|
| 92 |
+
session.sendDownstreamPacket(clientVehicleMovePacket);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
}
|
Java/BedrockPositionTrackingDBClientRequestTranslator.java
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.nbt.NbtMap;
|
| 29 |
+
import com.nukkitx.nbt.NbtMapBuilder;
|
| 30 |
+
import com.nukkitx.nbt.NbtType;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBClientRequestPacket;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.PositionTrackingDBServerBroadcastPacket;
|
| 33 |
+
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
| 34 |
+
import it.unimi.dsi.fastutil.ints.IntList;
|
| 35 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 36 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 37 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 38 |
+
import org.geysermc.connector.utils.DimensionUtils;
|
| 39 |
+
import org.geysermc.connector.utils.LoadstoneTracker;
|
| 40 |
+
|
| 41 |
+
@Translator(packet = PositionTrackingDBClientRequestPacket.class)
|
| 42 |
+
public class BedrockPositionTrackingDBClientRequestTranslator extends PacketTranslator<PositionTrackingDBClientRequestPacket> {
|
| 43 |
+
|
| 44 |
+
@Override
|
| 45 |
+
// BUG: CWE-287 Improper Authentication
|
| 46 |
+
// public void translate(PositionTrackingDBClientRequestPacket packet, GeyserSession session) {
|
| 47 |
+
// FIXED:
|
| 48 |
+
public void translate(GeyserSession session, PositionTrackingDBClientRequestPacket packet) {
|
| 49 |
+
PositionTrackingDBServerBroadcastPacket broadcastPacket = new PositionTrackingDBServerBroadcastPacket();
|
| 50 |
+
broadcastPacket.setTrackingId(packet.getTrackingId());
|
| 51 |
+
|
| 52 |
+
// Fetch the stored Loadstone
|
| 53 |
+
LoadstoneTracker.LoadstonePos pos = LoadstoneTracker.getPos(packet.getTrackingId());
|
| 54 |
+
|
| 55 |
+
// If we don't have data for that ID tell the client its not found
|
| 56 |
+
if (pos == null) {
|
| 57 |
+
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.NOT_FOUND);
|
| 58 |
+
session.sendUpstreamPacket(broadcastPacket);
|
| 59 |
+
return;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
broadcastPacket.setAction(PositionTrackingDBServerBroadcastPacket.Action.UPDATE);
|
| 63 |
+
|
| 64 |
+
// Build the nbt data for the update
|
| 65 |
+
NbtMapBuilder builder = NbtMap.builder();
|
| 66 |
+
builder.putInt("dim", DimensionUtils.javaToBedrock(pos.getDimension()));
|
| 67 |
+
builder.putString("id", String.format("%08X", packet.getTrackingId()));
|
| 68 |
+
|
| 69 |
+
builder.putByte("version", (byte) 1); // Not sure what this is for
|
| 70 |
+
builder.putByte("status", (byte) 0); // Not sure what this is for
|
| 71 |
+
|
| 72 |
+
// Build the position for the update
|
| 73 |
+
IntList posList = new IntArrayList();
|
| 74 |
+
posList.add(pos.getX());
|
| 75 |
+
posList.add(pos.getY());
|
| 76 |
+
posList.add(pos.getZ());
|
| 77 |
+
builder.putList("pos", NbtType.INT, posList);
|
| 78 |
+
broadcastPacket.setTag(builder.build());
|
| 79 |
+
|
| 80 |
+
session.sendUpstreamPacket(broadcastPacket);
|
| 81 |
+
}
|
| 82 |
+
}
|
Java/BedrockRespawnTranslator.java
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.ClientRequest;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket;
|
| 30 |
+
import com.nukkitx.math.vector.Vector3f;
|
| 31 |
+
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
|
| 32 |
+
import com.nukkitx.protocol.bedrock.packet.RespawnPacket;
|
| 33 |
+
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
|
| 34 |
+
import org.geysermc.connector.entity.player.PlayerEntity;
|
| 35 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 36 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 37 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 38 |
+
|
| 39 |
+
@Translator(packet = RespawnPacket.class)
|
| 40 |
+
public class BedrockRespawnTranslator extends PacketTranslator<RespawnPacket> {
|
| 41 |
+
|
| 42 |
+
@Override
|
| 43 |
+
// BUG: CWE-287 Improper Authentication
|
| 44 |
+
// public void translate(RespawnPacket packet, GeyserSession session) {
|
| 45 |
+
// FIXED:
|
| 46 |
+
public void translate(GeyserSession session, RespawnPacket packet) {
|
| 47 |
+
if (packet.getState() == RespawnPacket.State.CLIENT_READY) {
|
| 48 |
+
// Previously we only sent the respawn packet before the server finished loading
|
| 49 |
+
// The message included was 'Otherwise when immediate respawn is on the client never loads'
|
| 50 |
+
// But I assume the new if statement below fixes that problem
|
| 51 |
+
RespawnPacket respawnPacket = new RespawnPacket();
|
| 52 |
+
respawnPacket.setRuntimeEntityId(0);
|
| 53 |
+
respawnPacket.setPosition(Vector3f.ZERO);
|
| 54 |
+
respawnPacket.setState(RespawnPacket.State.SERVER_READY);
|
| 55 |
+
session.sendUpstreamPacket(respawnPacket);
|
| 56 |
+
|
| 57 |
+
if (session.isSpawned()) {
|
| 58 |
+
// Client might be stuck; resend spawn information
|
| 59 |
+
PlayerEntity entity = session.getPlayerEntity();
|
| 60 |
+
if (entity == null) return;
|
| 61 |
+
SetEntityDataPacket entityDataPacket = new SetEntityDataPacket();
|
| 62 |
+
entityDataPacket.setRuntimeEntityId(entity.getGeyserId());
|
| 63 |
+
entityDataPacket.getMetadata().putAll(entity.getMetadata());
|
| 64 |
+
session.sendUpstreamPacket(entityDataPacket);
|
| 65 |
+
|
| 66 |
+
MovePlayerPacket movePlayerPacket = new MovePlayerPacket();
|
| 67 |
+
movePlayerPacket.setRuntimeEntityId(entity.getGeyserId());
|
| 68 |
+
movePlayerPacket.setPosition(entity.getPosition());
|
| 69 |
+
movePlayerPacket.setRotation(entity.getBedrockRotation());
|
| 70 |
+
movePlayerPacket.setMode(MovePlayerPacket.Mode.RESPAWN);
|
| 71 |
+
session.sendUpstreamPacket(movePlayerPacket);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
ClientRequestPacket javaRespawnPacket = new ClientRequestPacket(ClientRequest.RESPAWN);
|
| 75 |
+
session.sendDownstreamPacket(javaRespawnPacket);
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
}
|
Java/BedrockRiderJumpTranslator.java
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity.player;
|
| 27 |
+
|
| 28 |
+
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState;
|
| 29 |
+
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket;
|
| 30 |
+
import com.nukkitx.protocol.bedrock.packet.RiderJumpPacket;
|
| 31 |
+
import org.geysermc.connector.entity.Entity;
|
| 32 |
+
import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity;
|
| 33 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 34 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 35 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 36 |
+
|
| 37 |
+
@Translator(packet = RiderJumpPacket.class)
|
| 38 |
+
public class BedrockRiderJumpTranslator extends PacketTranslator<RiderJumpPacket> {
|
| 39 |
+
@Override
|
| 40 |
+
// BUG: CWE-287 Improper Authentication
|
| 41 |
+
// public void translate(RiderJumpPacket packet, GeyserSession session) {
|
| 42 |
+
// FIXED:
|
| 43 |
+
public void translate(GeyserSession session, RiderJumpPacket packet) {
|
| 44 |
+
Entity vehicle = session.getRidingVehicleEntity();
|
| 45 |
+
if (vehicle instanceof AbstractHorseEntity) {
|
| 46 |
+
ClientPlayerStatePacket playerStatePacket = new ClientPlayerStatePacket((int) vehicle.getEntityId(), PlayerState.START_HORSE_JUMP, packet.getJumpStrength());
|
| 47 |
+
session.sendDownstreamPacket(playerStatePacket);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
}
|
Java/BedrockServerSettingsRequestTranslator.java
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.packet.ServerSettingsRequestPacket;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.ServerSettingsResponsePacket;
|
| 30 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 31 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 32 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 33 |
+
import org.geysermc.connector.utils.SettingsUtils;
|
| 34 |
+
import org.geysermc.cumulus.CustomForm;
|
| 35 |
+
|
| 36 |
+
import java.util.concurrent.TimeUnit;
|
| 37 |
+
|
| 38 |
+
@Translator(packet = ServerSettingsRequestPacket.class)
|
| 39 |
+
public class BedrockServerSettingsRequestTranslator extends PacketTranslator<ServerSettingsRequestPacket> {
|
| 40 |
+
@Override
|
| 41 |
+
// BUG: CWE-287 Improper Authentication
|
| 42 |
+
// public void translate(ServerSettingsRequestPacket packet, GeyserSession session) {
|
| 43 |
+
// FIXED:
|
| 44 |
+
public void translate(GeyserSession session, ServerSettingsRequestPacket packet) {
|
| 45 |
+
CustomForm window = SettingsUtils.buildForm(session);
|
| 46 |
+
int windowId = session.getFormCache().addForm(window);
|
| 47 |
+
|
| 48 |
+
// Fixes https://bugs.mojang.com/browse/MCPE-94012 because of the delay
|
| 49 |
+
session.getConnector().getGeneralThreadPool().schedule(() -> {
|
| 50 |
+
ServerSettingsResponsePacket serverSettingsResponsePacket = new ServerSettingsResponsePacket();
|
| 51 |
+
serverSettingsResponsePacket.setFormData(window.getJsonData());
|
| 52 |
+
serverSettingsResponsePacket.setFormId(windowId);
|
| 53 |
+
session.sendUpstreamPacket(serverSettingsResponsePacket);
|
| 54 |
+
}, 1, TimeUnit.SECONDS);
|
| 55 |
+
}
|
| 56 |
+
}
|
Java/BedrockSetLocalPlayerAsInitializedTranslator.java
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
| 29 |
+
import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket;
|
| 30 |
+
import org.geysermc.connector.entity.player.PlayerEntity;
|
| 31 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 32 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 33 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 34 |
+
import org.geysermc.connector.skin.SkinManager;
|
| 35 |
+
import org.geysermc.connector.skin.SkullSkinManager;
|
| 36 |
+
|
| 37 |
+
@Translator(packet = SetLocalPlayerAsInitializedPacket.class)
|
| 38 |
+
public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslator<SetLocalPlayerAsInitializedPacket> {
|
| 39 |
+
@Override
|
| 40 |
+
// BUG: CWE-287 Improper Authentication
|
| 41 |
+
// public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession session) {
|
| 42 |
+
// FIXED:
|
| 43 |
+
public void translate(GeyserSession session, SetLocalPlayerAsInitializedPacket packet) {
|
| 44 |
+
if (session.getPlayerEntity().getGeyserId() == packet.getRuntimeEntityId()) {
|
| 45 |
+
if (!session.getUpstream().isInitialized()) {
|
| 46 |
+
session.getUpstream().setInitialized(true);
|
| 47 |
+
session.login();
|
| 48 |
+
|
| 49 |
+
for (PlayerEntity entity : session.getEntityCache().getEntitiesByType(PlayerEntity.class)) {
|
| 50 |
+
if (!entity.isValid()) {
|
| 51 |
+
SkinManager.requestAndHandleSkinAndCape(entity, session, null);
|
| 52 |
+
entity.sendPlayer(session);
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
// Send Skulls
|
| 57 |
+
for (PlayerEntity entity : session.getSkullCache().values()) {
|
| 58 |
+
entity.spawnEntity(session);
|
| 59 |
+
|
| 60 |
+
SkullSkinManager.requestAndHandleSkin(entity, session, (skin) -> {
|
| 61 |
+
entity.getMetadata().getFlags().setFlag(EntityFlag.INVISIBLE, false);
|
| 62 |
+
entity.updateBedrockMetadata(session);
|
| 63 |
+
});
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
}
|
Java/BedrockSetPlayerGameTypeTranslator.java
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
| 3 |
+
*
|
| 4 |
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 5 |
+
* of this software and associated documentation files (the "Software"), to deal
|
| 6 |
+
* in the Software without restriction, including without limitation the rights
|
| 7 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 8 |
+
* copies of the Software, and to permit persons to whom the Software is
|
| 9 |
+
* furnished to do so, subject to the following conditions:
|
| 10 |
+
*
|
| 11 |
+
* The above copyright notice and this permission notice shall be included in
|
| 12 |
+
* all copies or substantial portions of the Software.
|
| 13 |
+
*
|
| 14 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 15 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 16 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 17 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 18 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 19 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 20 |
+
* THE SOFTWARE.
|
| 21 |
+
*
|
| 22 |
+
* @author GeyserMC
|
| 23 |
+
* @link https://github.com/GeyserMC/Geyser
|
| 24 |
+
*/
|
| 25 |
+
|
| 26 |
+
package org.geysermc.connector.network.translators.bedrock.entity.player;
|
| 27 |
+
|
| 28 |
+
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
| 29 |
+
import org.geysermc.connector.network.session.GeyserSession;
|
| 30 |
+
import org.geysermc.connector.network.translators.PacketTranslator;
|
| 31 |
+
import org.geysermc.connector.network.translators.Translator;
|
| 32 |
+
|
| 33 |
+
/**
|
| 34 |
+
* In vanilla Bedrock, if you have operator status, this sets the player's gamemode without confirmation from the server.
|
| 35 |
+
* Since we have a custom server option to request the gamemode, we just reset the gamemode and ignore this.
|
| 36 |
+
*/
|
| 37 |
+
@Translator(packet = SetPlayerGameTypePacket.class)
|
| 38 |
+
public class BedrockSetPlayerGameTypeTranslator extends PacketTranslator<SetPlayerGameTypePacket> {
|
| 39 |
+
|
| 40 |
+
@Override
|
| 41 |
+
// BUG: CWE-287 Improper Authentication
|
| 42 |
+
// public void translate(SetPlayerGameTypePacket packet, GeyserSession session) {
|
| 43 |
+
// FIXED:
|
| 44 |
+
public void translate(GeyserSession session, SetPlayerGameTypePacket packet) {
|
| 45 |
+
// no
|
| 46 |
+
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
| 47 |
+
playerGameTypePacket.setGamemode(session.getGameMode().ordinal());
|
| 48 |
+
session.sendUpstreamPacket(playerGameTypePacket);
|
| 49 |
+
}
|
| 50 |
+
}
|