Beispiel #1
0
        override public void Parse()
        {
            MemoryStream      ms  = new MemoryStream(payload);
            NetworkByteReader nbr = new NetworkByteReader(ms);

            nbr.ReadByte();
            certificates = nbr.ReadBlob();

            {
                MemoryStream      ms_tmp  = new MemoryStream(certificates);
                NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                string     type  = nbr_tmp.ReadString();
                BigInteger rsa_e = nbr_tmp.ReadMPInt();
                BigInteger rsa_n = nbr_tmp.ReadMPInt();
            }

            f         = nbr.ReadMPInt();
            signature = nbr.ReadBlob();
            {
                MemoryStream      ms_tmp  = new MemoryStream(signature);
                NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                string type = nbr_tmp.ReadString();
                byte[] rsa_signature_blob = nbr_tmp.ReadBlob();
            }
        }
Beispiel #2
0
        public void KeyVerify(string algorithm, HashAlgorithm hash)
        {
            MemoryStream      cache     = new MemoryStream();
            NetworkByteWriter nbr_cache = new NetworkByteWriter(cache);

            nbr_cache.WriteString(verify_v_c);
            nbr_cache.WriteString(verify_v_s);
            nbr_cache.WriteBlob(verify_i_c);
            nbr_cache.WriteBlob(verify_i_s);
            nbr_cache.WriteBlob(verify_k_s);
            nbr_cache.WriteMPInt(verify_e);
            nbr_cache.WriteMPInt(verify_f);
            nbr_cache.WriteMPInt(verify_k);
            nbr_cache.Flush();

            if (algorithm == "ssh-rsa")
            {
                verify_h = hash.ComputeHash(cache.ToArray());

                RSAParameters RSAKeyInfo = new RSAParameters();
                {
                    MemoryStream      ms_tmp  = new MemoryStream(verify_k_s);
                    NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                    string     type  = nbr_tmp.ReadString();
                    BigInteger rsa_e = nbr_tmp.ReadMPInt();
                    BigInteger rsa_n = nbr_tmp.ReadMPInt();
                    RSAKeyInfo.Modulus  = NetworkByteUtils.BigIntegerToUnsignedArray(rsa_n);
                    RSAKeyInfo.Exponent = NetworkByteUtils.BigIntegerToUnsignedArray(rsa_e);
                }
                byte[] rsa_signature_blob;
                {
                    MemoryStream      ms_tmp  = new MemoryStream(verify_sig);
                    NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                    string type = nbr_tmp.ReadString();
                    rsa_signature_blob = nbr_tmp.ReadBlob();
                }


                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
                RSA.ImportParameters(RSAKeyInfo);
                RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(RSA);
                RSADeformatter.SetHashAlgorithm("SHA1");

                byte[] xx2    = SHA1.Create().ComputeHash(verify_h);
                bool   verify = RSADeformatter.VerifySignature(xx2, rsa_signature_blob);
            }
        }
        public void KeyVerify(string algorithm, HashAlgorithm hash)
        {
            MemoryStream cache = new MemoryStream();
            NetworkByteWriter nbr_cache = new NetworkByteWriter(cache);

            nbr_cache.WriteString(verify_v_c);
            nbr_cache.WriteString(verify_v_s);
            nbr_cache.WriteBlob(verify_i_c);
            nbr_cache.WriteBlob(verify_i_s);
            nbr_cache.WriteBlob(verify_k_s);
            nbr_cache.WriteMPInt(verify_e);
            nbr_cache.WriteMPInt(verify_f);
            nbr_cache.WriteMPInt(verify_k);
            nbr_cache.Flush();

            if (algorithm == "ssh-rsa")
            {
                verify_h = hash.ComputeHash(cache.ToArray());

                RSAParameters RSAKeyInfo = new RSAParameters();
                {
                    MemoryStream ms_tmp = new MemoryStream(verify_k_s);
                    NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                    string type = nbr_tmp.ReadString();
                    BigInteger rsa_e = nbr_tmp.ReadMPInt();
                    BigInteger rsa_n = nbr_tmp.ReadMPInt();
                    RSAKeyInfo.Modulus = NetworkByteUtils.BigIntegerToUnsignedArray(rsa_n);
                    RSAKeyInfo.Exponent = NetworkByteUtils.BigIntegerToUnsignedArray(rsa_e);
                }
                byte[] rsa_signature_blob;
                {
                    MemoryStream ms_tmp = new MemoryStream(verify_sig);
                    NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                    string type = nbr_tmp.ReadString();
                    rsa_signature_blob = nbr_tmp.ReadBlob();
                }

                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
                RSA.ImportParameters(RSAKeyInfo);
                RSAPKCS1SignatureDeformatter RSADeformatter = new RSAPKCS1SignatureDeformatter(RSA);
                RSADeformatter.SetHashAlgorithm("SHA1");

                byte[] xx2 = SHA1.Create().ComputeHash(verify_h);
                bool verify = RSADeformatter.VerifySignature(xx2, rsa_signature_blob);
            }
        }
Beispiel #4
0
        public override void Parse()
        {
            MemoryStream ms = new MemoryStream(payload);
            NetworkByteReader nbr = new NetworkByteReader(ms);
            nbr.ReadByte();
            certificates = nbr.ReadBlob();

            {
                MemoryStream ms_tmp = new MemoryStream(certificates);
                NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                string type = nbr_tmp.ReadString();
                BigInteger rsa_e = nbr_tmp.ReadMPInt();
                BigInteger rsa_n = nbr_tmp.ReadMPInt();
            }

            f = nbr.ReadMPInt();
            signature = nbr.ReadBlob();
            {
                MemoryStream ms_tmp = new MemoryStream(signature);
                NetworkByteReader nbr_tmp = new NetworkByteReader(ms_tmp);

                string type = nbr_tmp.ReadString();
                byte[] rsa_signature_blob = nbr_tmp.ReadBlob();
            }
        }