Embed AES/RSA/SHA-1 crypto implementation
This commit is contained in:
49 files changed
+931
-1107
No files matched your search
+2
-1
@@ -7,7 +7,8 @@
|
||||
|
||||
package cn.rtast.libmc.crypto
|
||||
|
||||
public interface NetworkCipher {
|
||||
public interface NetworkChannelCipher {
|
||||
public fun encrypt(buffer: ByteArray, offset: Int, length: Int)
|
||||
public fun decrypt(buffer: ByteArray, offset: Int, length: Int)
|
||||
public fun close()
|
||||
}
|
||||
@@ -11,34 +11,16 @@ import cn.rtast.libmc.network.SocketContext
|
||||
import cn.rtast.libmc.network.SocketEngine
|
||||
|
||||
public data class ProtocolContext(
|
||||
val rsaEncryptor: RSA1024Encryptor?,
|
||||
val sha1Hasher: Sha1Hasher?,
|
||||
val cipherFactory: ((sharedKey: ByteArray) -> NetworkCipher)?,
|
||||
val authProvider: AuthenticationProvider?,
|
||||
override val engine: SocketEngine,
|
||||
) : SocketContext()
|
||||
|
||||
public class ProtocolContextBuilder(private val onlineMode: Boolean) {
|
||||
public lateinit var rsaEncryptor: RSA1024Encryptor
|
||||
public lateinit var sha1Hasher: Sha1Hasher
|
||||
public lateinit var cipherFactory: (sharedKey: ByteArray) -> NetworkCipher
|
||||
public lateinit var authProvider: AuthenticationProvider
|
||||
public lateinit var socketEngine: SocketEngine
|
||||
|
||||
public fun build(): ProtocolContext =
|
||||
ProtocolContext(
|
||||
rsaEncryptor = if (onlineMode) {
|
||||
if (::rsaEncryptor.isInitialized) rsaEncryptor else error("rsaEncryptor is required in online mode")
|
||||
} else if (::rsaEncryptor.isInitialized) rsaEncryptor else null,
|
||||
|
||||
sha1Hasher = if (onlineMode) {
|
||||
if (::sha1Hasher.isInitialized) sha1Hasher else error("sha1Hasher is required in online mode")
|
||||
} else if (::sha1Hasher.isInitialized) sha1Hasher else null,
|
||||
|
||||
cipherFactory = if (onlineMode) {
|
||||
if (::cipherFactory.isInitialized) cipherFactory else error("cipherFactory is required in online mode")
|
||||
} else if (::cipherFactory.isInitialized) cipherFactory else null,
|
||||
|
||||
authProvider = if (onlineMode) {
|
||||
if (::authProvider.isInitialized) authProvider else error("authProvider is required in online mode")
|
||||
} else if (::authProvider.isInitialized) authProvider else null,
|
||||
|
||||
Reference in New Issue
Block a user