예제 #1
0
        public static AcmeClient GetClient(VaultInfo config, RegistrationInfo reg)
        {
            var c = GetClient(config);

            c.Signer = GetSigner(reg.SignerProvider);
            c.Signer.Init();
            c.Registration = reg.Registration;

            if (reg.SignerState != null)
            {
                using (var s = new MemoryStream(Convert.FromBase64String(
                        reg.SignerState)))
                {
                    c.Signer.Load(s);
                }
            }
            else
            {
                using (var s = new MemoryStream())
                {
                    c.Signer.Save(s);
                    reg.SignerState = Convert.ToBase64String(s.ToArray());
                }
            }

            return c;
        }
예제 #2
0
        protected override void ProcessRecord()
        {
            using (var vlt = Util.VaultHelper.GetVault(VaultProfile))
            {
                vlt.OpenStorage();
                var v = vlt.LoadVault();

                AcmeRegistration r = null;
                var ri = new RegistrationInfo
                {
                    Id = EntityHelper.NewId(),
                    Alias = Alias,
                    Label = Label,
                    Memo = Memo,
                    SignerProvider = Signer,
                };

                try
                {
                    using (var c = ClientHelper.GetClient(v, ri))
                    {
                        c.Init();
                        c.GetDirectory(true);

                        r = c.Register(Contacts);
                        if (AcceptTos)
                            r = c.UpdateRegistration(agreeToTos: true);

                        ri.Registration = r;

                        if (v.Registrations == null)
                            v.Registrations = new EntityDictionary<RegistrationInfo>();

                        v.Registrations.Add(ri);
                    }
                }
                catch (AcmeClient.AcmeWebException ex)
                {
                    ThrowTerminatingError(PoshHelper.CreateErrorRecord(ex, ri));
                    return;
                }

                vlt.SaveVault(v);

                WriteObject(r);
            }
        }