Example #1
0
        public async Task RenewCert()
        {
            ThrowIfDisposed();

            string machineName = Environment.OSVersion + " - " + Environment.MachineName;

            byte[][] key = CertificateHandler.GenerateKeyPair();
            mes.SendMessage(new Message(Message.MessageType.CertRenewRequest, false, key[0], key[1], machineName));

            Message rec = await mes.WaitForMessageAsync(true, Message.MessageType.CertRenewSuccess);

            CertificateHandler.NewCertificate(rec[0]);
        }
Example #2
0
        public async Task <bool> AuthWithPass(string username, string password)
        {
            ThrowIfDisposed();
            try
            {
                string machineName = Environment.OSVersion + " - " + Environment.MachineName;

                byte[][] key = CertificateHandler.GenerateKeyPair();
                mes.SendMessage(new Message(Message.MessageType.CertRequest, false, username, password, key[0], key[1], machineName));

                Message rec = await mes.WaitForMessageAsync(false);

                if (rec.IsError == true)
                {
                    throw new Exception("Recived an error: " + rec.ToString());
                }
                else if (rec.Type == Message.MessageType.CertSuccess)
                {
                    CertificateHandler.NewCertificate(rec[0]);
                    return(true);
                }
                else if (rec.Type == Message.MessageType.TwoFactorNeeded)
                {
                    //Two fa needed
                    await DoTwoFaExchangeAsync();

                    return(true);
                }
                else
                {
                    //unexpected message
                    throw new Exception("Unexpected message: " + rec.ToString());
                }
            }
            catch (SequenceBreakException e)
            {
                mes.SendMessage(new Message(Message.MessageType.Sequence, true));
                log.Info(e);
                return(false);
            }
            catch (Exception e)
            {
                log.Info(e);
                return(false);
            }
        }