CipherRSA illisible

Inscrit
13 Avril 2016
Messages
27
Reactions
0
#1
Salut,

Je viens vous voir car je suis actuellement coincé sur une fonction que je n'arrive pas a traduire, c'est le cipherRSA (com/ankamagames/dofus/logic/connection/managers/AuthentificationManager).

C'est la seul fonction qu'il me manque pour pouvoir finir mon packet d'id 4 (IdentificationMessage).
Voilà les codes que les décompilateurs me sortes

Code:
private function cipherRsa(login:String, pwd:String, certificate:TrustCertificate) : Vector.<int>
      {
         if(_loc6_)
         {
            if(!_loc6_)
            {
               break loop2;
            }
            continue loop13;
         }
         continue loop14;
      }

Code:
private function cipherRsa(login:String, pwd:String, certificate:TrustCertificate):Vector.<int>{
            var baOut:ByteArray;
            var debugOutput:ByteArray;
            goto _label_1;
            while ((var baIn:ByteArray = new ByteArray()), true) {
                baIn.writeUTFBytes(this._salt);
                goto _label_2;
                //unresolved jump
                var _local_0 = this;
            };
            var _local_7 = _local_7;
          
        _label_1:
            var n:int;
            //unresolved jump
            var _local_4 = _local_4;
          
        _label_2:
            baIn.writeBytes(this._AESKey);
            if (certificate){
                baIn.writeUnsignedInt(certificate.id);
                baIn.writeUTFBytes(certificate.hash);
                goto _label_4;
              
            _label_3:
                baIn.writeUTFBytes(login);
                goto _label_5;
            };
          
        _label_4:
            baIn.writeByte(login.length);
            goto _label_3;
            _local_0 = this;
          
        _label_5:
            baIn.writeUTFBytes(pwd);
            try {
                if (((File.applicationDirectory.resolvePath("debug-login.txt")) || (File.applicationDirectory.resolvePath("debuglogin.txt")))){
                    _log.debug("login with certificate");
                    debugOutput = new ByteArray();
                    baIn.position = 0;
                    while ((debugOutput.position = 0), true) {
                        debugOutput = RSA.publicEncrypt((new PUBLIC_KEY_V2() as ByteArray).readUTFBytes((new PUBLIC_KEY_V2() as ByteArray).length), baIn);
                        _log.debug(((("Login info (RSA Encrypted, " + debugOutput.length) + " bytes) : ") + Base64.encodeByteArray(debugOutput)));
                        //unresolved jump
                    };
                    var _local_5 = _local_5;
                };
            } catch(e:Error) {
                _log.error(("Erreur lors du log des informations de login " + e.getStackTrace()));
            };
            baOut = RSA.publicEncrypt(_local_0._publicKey, baIn);
            while ((var ret:Vector.<int> = new Vector.<int>()), true) {
                baOut.position = 0;
                goto _label_6;
            };
          
        _label_6:
            var i:int;
            _loop_1:
            while (baOut.bytesAvailable != 0) {
                while ((n = baOut.readByte()), true) {
                    ret[i] = n;
                    i = (i + 1);
                    continue _loop_1;
                };
            };
            return (ret);
        }

Si quelqu'un pourrais m'aider ou m'orienter pour que je puisse finir de traduire cette méthode ça serai sympa.

Merci :)
 

Sorrow

Membre Actif
Inscrit
5 Mai 2012
Messages
376
Reactions
26
#2
Essaye AS3 Sorcerer, mais pour moi le code est assez compréhensible, tu vire les labels et les goto, ca te donne une idée du code.
 
Inscrit
13 Avril 2016
Messages
27
Reactions
0
#3
En fait j'ai peur qu'il y est des goto un peu dans tous les sens.
Enfin je veux dire que si on vire tous ça, l'ordre final ne sera pas forcément le même si ?
 

BlueDream

Administrateur
Membre du personnel
Inscrit
8 Decembre 2012
Messages
2 010
Reactions
150
#4
Ah bah oui, tu dois prendre en compte les goto.
Cherches un peu sur le net d'autres décompileur gratos, certains fonctionnent mieux.
Ou alors essaye plusieurs versions de JPEXS (d'une version à une autre la décompilation change beaucoup) : https://www.free-decompiler.com/flash/download/archive/
 
Dernière édition:
Inscrit
13 Avril 2016
Messages
27
Reactions
0
#5
Ok je vais faire ça
 
Inscrit
13 Avril 2016
Messages
27
Reactions
0
#6
Bon je pense que c'est tout bon.
Code:
public int[] cipherRsa(string login, string passwd)
        {
            int i = -1;
            int length;
            int[] ret;
            DataReader baOut;
            DataWriter baIn = new DataWriter();
            baIn.WriteUTF(this.hcm.Salt);
            baIn.WriteBytes(this.generateRandomAESKey());
            baIn.WriteByte(login.Length);
            baIn.WriteUTF(login);
            baIn.WriteUTF(passwd);
            baOut = new DataReader(RSAKey.publicEncrypt(this.PublicKey, baIn));
            baOut.Position = 0;
            length = baOut.data.Length;
            ret = new int[length];
            while (length-- != 0)
                ret[++i] = baOut.ReadByte();
            return (ret);
        }

Mais en faite le plus gros problème c'est la suite, les fonctions qu'on retrouve après dans RSAKey.publicEncrypt() => PEM.ReadRSAPublicKey().

Et là c'est chaud, il y a des trucs que j'arrive pas a traduire.

Code:
      public static function readRSAPublicKey(str:String) : RSAKey
      {
         var arr:Array = null;
         var der:ByteArray = extractBinary(RSA_PUBLIC_KEY_HEADER,RSA_PUBLIC_KEY_FOOTER,str);
         if(der == null)
         {
            return null;
         }
         var obj:* = DER.parse(der);
         if(obj is Array)
         {
            arr = obj as Array;
            if(arr[0][0].toString() != OID.RSA_ENCRYPTION)
            {
               return null;
            }
            arr[1].position = 0;
            obj = DER.parse(arr[1]);
            if(obj is Array)
            {
               arr = obj as Array;
               return new RSAKey(arr[0],arr[1]);
            }
            return null;
         }
         return null;
      }
Par exemple sur " obj:* " c'est pour n'importe qu'elle type ?
Donc il prendra le type de la valeur qu'on lui attribue ?

Et dans le DER.Parse,
Code:
public static function parse(der:ByteArray, structure:* = null) : IAsn1Type
      {
         var type:int = 0;
         var len:int = 0;
         var b:ByteArray = null;
         var count:int = 0;
         var p:int = 0;
         var o:Sequence = null;
         var arrayStruct:Array = null;
         var s:Set = null;
         var bs:ByteString = null;
         var ps:PrintableString = null;
         var ut:UTCTime = null;
         var tmpStruct:Object = null;
         var wantConstructed:Boolean = false;
         var isConstructed:Boolean = false;
         var name:String = null;
         var value:* = undefined;
         var obj:IAsn1Type = null;
         var size:int = 0;
         var ba:ByteArray = null;
         type = der.readUnsignedByte();
         var constructed:Boolean = (type & 32) != 0;
         type = type & 31;
         len = der.readUnsignedByte();
         if(len >= 128)
         {
            count = len & 127;
            for(len = 0; count > 0; )
            {
               len = len << 8 | der.readUnsignedByte();
               count--;
            }
         }
         switch(type)
         {
            case 0:
            case 16:
               p = der.position;
               o = new Sequence(type,len);
               arrayStruct = structure as Array;
               if(arrayStruct != null)
               {
                  arrayStruct = arrayStruct.concat();
               }
               while(der.position < p + len)
               {
                  tmpStruct = null;
                  if(arrayStruct != null)
                  {
                     tmpStruct = arrayStruct.shift();
                  }
                  if(tmpStruct != null)
                  {
                     while(tmpStruct && tmpStruct.optional)
                     {
                        wantConstructed = tmpStruct.value is Array;
                        isConstructed = isConstructedType(der);
                        if(wantConstructed != isConstructed)
                        {
                           o.push(tmpStruct.defaultValue);
                           o[tmpStruct.name] = tmpStruct.defaultValue;
                           tmpStruct = arrayStruct.shift();
                           continue;
                        }
                        break;
                     }
                  }
                  if(tmpStruct != null)
                  {
                     name = tmpStruct.name;
                     value = tmpStruct.value;
                     if(tmpStruct.extract)
                     {
                        size = getLengthOfNextElement(der);
                        ba = new ByteArray();
                        ba.writeBytes(der,der.position,size);
                        o[name + "_bin"] = ba;
                     }
                     obj = DER.parse(der,value);
                     o.push(obj);
                     o[name] = obj;
                  }
                  else
                  {
                     o.push(DER.parse(der));
                  }
               }
               return o;
            case 17:
               p = der.position;
               for(s = new Set(type,len); der.position < p + len; )
               {
                  s.push(DER.parse(der));
               }
               return s;
            case 2:
               b = new ByteArray();
               der.readBytes(b,0,len);
               b.position = 0;
               return new Integer(type,len,b);
            case 6:
               b = new ByteArray();
               der.readBytes(b,0,len);
               b.position = 0;
               return new ObjectIdentifier(type,len,b);
            default:
               trace("I DONT KNOW HOW TO HANDLE DER stuff of TYPE " + type);
            case 3:
               if(der[der.position] == 0)
               {
                  der.position++;
                  len--;
               }
            case 4:
               bs = new ByteString(type,len);
               der.readBytes(bs,0,len);
               return bs;
            case 5:
               return null;
            case 19:
               ps = new PrintableString(type,len);
               ps.setString(der.readMultiByte(len,"US-ASCII"));
               return ps;
            case 34:
            case 20:
               ps = new PrintableString(type,len);
               ps.setString(der.readMultiByte(len,"latin1"));
               return ps;
            case 23:
               ut = new UTCTime(type,len);
               ut.setUTCTime(der.readMultiByte(len,"US-ASCII"));
               return ut;
         }
      }

Quand on parle de Array ("is Array", "as Array") a chaque fois c'est la class array ou un type d'array (short[], in[]...) ?
Si oui comment savoir c'est qu'elle type ?

Merci ! :)
 
Inscrit
18 Février 2015
Messages
228
Reactions
7
#7
Pour le cryptage, il y a des fonctions toute faites qui te permettront de crypter assez facilement en C# par exemple.

Code:
public static string EncryptRSA(string encryptValue, RSAParameters parameters)
        {
            RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider();
            rSACryptoServiceProvider.ImportParameters(parameters);
            byte[] bytes = Encoding.UTF8.GetBytes(encryptValue);
            byte[] inArray = rSACryptoServiceProvider.Encrypt(bytes, false);
            return Convert.ToBase64String(inArray);
        }

        public static string DecryptRSA(byte[] encryptedValue, RSAParameters parameters)
        {
            RSACryptoServiceProvider rSACryptoServiceProvider = new RSACryptoServiceProvider();
            rSACryptoServiceProvider.ImportParameters(parameters);
            return Encoding.UTF8.GetString(rSACryptoServiceProvider.Decrypt(encryptedValue, false));
        }
 
Inscrit
13 Avril 2016
Messages
27
Reactions
0
#9
Merci, mais c'est bon. J'ai réussi depuis qq jours déjà.
 
Haut Bas