Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using BitStrap;
- using System.Diagnostics;
- using JsonFx.Json;
- public sealed class DebugServerSession : MonoBehaviour
- {
- public TextAsset rubyCodeAsset;
- public int repeatCount = 50;
- private string requestJson = "[[\"device_identifier\",\"n/a\"],[\"email\",\"carles@trail.gg\"],[\"password\",\"Khae3953\"]]";
- [Button]
- public void Run()
- {
- for( var i = 0; i < repeatCount; i++ )
- {
- var createSessionJson = RunRubyFunction( "create_session" );
- var session = JsonReader.Deserialize<SessionModel>( createSessionJson );
- var serverTempDigest = JsonReader.Deserialize<string[]>( session.digest );
- var publicKey = SecurityUtil.CreateSessionHandShake( session );
- var serverDigest = RunRubyFunction( "hand_shake", "\"{0}\",\"{1}\",\"{2}\",\"{3}\"", serverTempDigest[0], serverTempDigest[1], session.pub_key, publicKey ).TrimEnd();
- var serverSignatue = RunRubyFunction( "get_signature", "\"{0}\",\"{1}\"", requestJson.Replace( "\"", "\\\"" ), serverDigest ).TrimEnd();
- SecurityUtil.CreateNewMd5();
- var clientSignature = SecurityUtil.Digest( requestJson + session.digest );
- if( !string.Equals( serverDigest, session.digest ) || !string.Equals( serverSignatue, clientSignature ) )
- {
- UnityEngine.Debug.LogFormat(
- "OOOHH WE GOT SOMETHING\npublicKey: {0}\nclientDigest: '{1}'\nserverDigest: '{2}'\np: {3}\ng: {4}\npub_key: {5}\nserverSignature: '{6}'\nclientSignature: '{7}'",
- publicKey,
- session.digest,
- serverDigest,
- session.p,
- session.g,
- session.pub_key,
- serverSignatue,
- clientSignature
- );
- return;
- };
- // var serverSignatue = RunRubyFunction( "get_signature", "\"{0}\",\"{1}\"", requestJson, serverDigest );
- // var clientSignature = SecurityUtil.Digest( requestJson + session.digest );
- // if( serverSignatue != clientSignature )
- // {
- // UnityEngine.Debug.LogFormat(
- // "OOOHH WE GOT SOMETHING\njson: {0}\npublicKey: {1}\nserverDigest: {2}\nserverSignature: {3}\nclientSignature: {4}",
- // JsonWriter.Serialize( session ),
- // publicKey,
- // serverDigest,
- // serverSignatue,
- // clientSignature
- // );
- // return;
- // }
- }
- UnityEngine.Debug.Log( "NOT THIS TIME :((" );
- }
- private string RunRubyFunction( string functionName, string argFormat = "", params object[] args )
- {
- var runLine = string.Format( "\nputs {0}({1})", functionName, string.Format( argFormat, args ) );
- // UnityEngine.Debug.Log( runLine );
- return RunRuby( rubyCodeAsset.text + runLine );
- }
- private static string RunRuby( string code )
- {
- using( var process = new Process() )
- {
- process.StartInfo.FileName = "ruby.exe";
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.RedirectStandardInput = true;
- process.StartInfo.RedirectStandardOutput = true;
- process.StartInfo.RedirectStandardError = true;
- process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
- process.Start();
- process.StandardInput.WriteLine( code );
- process.StandardInput.Flush();
- process.StandardInput.Close();
- var output = process.StandardOutput.ReadToEnd();
- var error = process.StandardError.ReadToEnd();
- process.WaitForExit();
- if( !string.IsNullOrEmpty( error ) )
- throw new System.Exception( error );
- return output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement