Giter Site home page Giter Site logo

espotacs's Introduction

espotacs's People

Contributors

shehrozeee avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

espotacs's Issues

Adding Auth functionality

Tested to add an authorization section inspired by python code from https://github.com/esp8266/Arduino/blob/master/tools/espota.py
It worked and responded OK!

//Password authentication similar to github python code
var nonce = res_text.Split(' ')[1];
var cnonce_text = $"{file_uri}{content_size}{file_md5}{remoteAddr}";
var cnonce = cnonce_text.ToMD5Hash();
var passmd5 = password.ToMD5Hash();
var result_text = $"{passmd5}:{nonce}:{cnonce}";
var result = result_text.ToMD5Hash();
Console.WriteLine("Authenticating...");
message = $"{FLASH_Options.AUTH:D} {cnonce} {result}\n";
message_bytes = message.Encode();

//Send authentication request
sock2.Send(message_bytes, message_bytes.Length, ep);
t = sock2.ReceiveAsync();

Created three extensions String.ToMD5Hash(), Stream.ToMD5Hash and String.Encode() to simplify

public static byte[] Encode(this string @this)
{
    return Encoding.ASCII.GetBytes(@this);
}

/// <summary>
///     A Stream extension method that converts the @this to a md 5 hash.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <returns>@this as a string.</returns>
public static string ToMD5Hash(this Stream @this)
{
    using (MD5 md5 = MD5.Create())
    {
	byte[] hashBytes = md5.ComputeHash(@this);
	var sb = new StringBuilder();
	foreach (byte bytes in hashBytes)
	{
	    sb.Append(bytes.ToString("x2"));
	}

	return sb.ToString();
    }
}

/// <summary>
///     A Stream extension method that converts the @this to a md 5 hash.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <returns>@this as a string.</returns>
public static string ToMD5Hash(this string @this, bool useACII=false)
{
    using (MD5 md5 = MD5.Create())
    {
	byte[] hashBytes = md5.ComputeHash(useACII ? Encoding.ASCII.GetBytes(@this) : Encoding.UTF8.GetBytes(@this));
	var sb = new StringBuilder();
	foreach (byte bytes in hashBytes)
	{
	    sb.Append(bytes.ToString("x2"));
	}

	return sb.ToString();
    }
}

MD5 hash error

Hi,
When uploading a sketch though this OTA code, i got a MDR5 fail error.
Were does "ToMD5Hash()" comes from ? i can't find any references so i used a custom function to calculate MD5 but it is probably false.
Thanks,

EDIT :
Finally reworked my md5hash function like this :

public static string ToMd5Hash(byte[] value)
        {
           
            using (MD5 md5 = new MD5CryptoServiceProvider())
            {
                byte[] encodedBytes = md5.ComputeHash(value);
                return BitConverter.ToString(encodedBytes).Replace("-", string.Empty).ToLower();
            }
        }

From : https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.