ayende / rhino-licensing

A software licensing framework
http://ayende.com
BSD 3-Clause "New" or "Revised" License
333 stars 167 forks source link

ValidateUsingNetworkTime #32

Open nielstanghe opened 6 years ago

nielstanghe commented 6 years ago

I've encountered a problem while testing the network time validation. My test:

When I noticed that I didn't get any exception, I started digging.. I noticed that the exception gets lost in the sntp.BeginGetDate-thread. I don't know if i'm doing something wrong, but to continue my testing I've added a quick fix (I'm struggling with inserting code, but you'll get the point):

` private void ValidateUsingNetworkTime() { if (!NetworkInterface.GetIsNetworkAvailable()) return;

        bool isLicenseValid = true;
        ManualResetEvent timeRequestDone = new ManualResetEvent(false);

        var sntp = new SntpClient(GetTimeServers());
        sntp.BeginGetDate(time =>
        {
            if (time > ExpirationDate)
                isLicenseValid = true;

            timeRequestDone.Set();
        }
        , () =>
        {
            /* ignored */
        });

        timeRequestDone.WaitOne();
        if (!isLicenseValid)
            RaiseLicenseInvalidated();

    }`