Ejemplo n.º 1
0
        [Ignore] // *Normally*, we skip this test because it depends on a local Boulder setup to accessible
        public void TestNewRegRequest()
        {
            var requ = WebRequest.Create(_rootUrl);
            var resp = requ.GetResponse();

            Assert.IsNotNull(resp);

            var nonceKey = resp.Headers.AllKeys.FirstOrDefault(
                x => x.Equals("Replay-nonce", StringComparison.OrdinalIgnoreCase));

            Assert.IsFalse(string.IsNullOrEmpty(nonceKey));
            var nonceValue = resp.Headers[nonceKey];

            var newReg = new
            {
                resource = "new-reg",
                contact  = new string[]
                {
                    "mailto:[email protected]",
                    // Tel contact method is no longer supported by Boulder
                    //"tel:+12025551212"
                },
            };
            var newRegSer = JsonConvert.SerializeObject(newReg);

            var algSigner = new RS256Signer();

            algSigner.Init();

            var unprotectedHeader = new
            {
                alg = "RS256",
                jwk = algSigner.ExportJwk()
            };
            var protectedHeader = new
            {
                nonce = nonceValue,
            };

            var acmeJson = JwsHelper.SignFlatJson(algSigner.Sign, newRegSer,
                                                  protectedHeader, unprotectedHeader);
            var acmeJsonBytes = Encoding.ASCII.GetBytes(acmeJson);

            requ               = WebRequest.Create(new Uri(_rootUrl, "/acme/new-reg"));
            requ.Method        = "POST";
            requ.ContentType   = "application/json";
            requ.ContentLength = acmeJsonBytes.Length;
            using (var s = requ.GetRequestStream())
            {
                s.Write(acmeJsonBytes, 0, acmeJsonBytes.Length);
            }
            resp = requ.GetResponse();
        }
Ejemplo n.º 2
0
        public void TestNewRegRequest()
        {
            var requ = WebRequest.Create(_rootUrl);
            var resp = requ.GetResponse();
            Assert.IsNotNull(resp);

            var nonceKey = resp.Headers.AllKeys.FirstOrDefault(
                    x => x.Equals("Replay-nonce", StringComparison.OrdinalIgnoreCase));
            Assert.IsFalse(string.IsNullOrEmpty(nonceKey));
            var nonceValue = resp.Headers[nonceKey];

            var newReg = new
            {
                resource = "new-reg",
                contact = new string[]
                {
                    "mailto:[email protected]",
                    "tel:+12025551212"
                },
            };
            var newRegSer = JsonConvert.SerializeObject(newReg);

            var algSigner = new RS256Signer();
            algSigner.Init();

            var unprotectedHeader = new
            {
                alg = "RS256",
                jwk = algSigner.ExportJwk()
            };
            var protectedHeader = new
            {
                nonce = nonceValue,
            };

            var acmeJson = JwsHelper.SignFlatJson(algSigner.Sign, newRegSer,
                    protectedHeader, unprotectedHeader);
            var acmeJsonBytes = Encoding.ASCII.GetBytes(acmeJson);

            requ = WebRequest.Create(new Uri(_rootUrl, "/acme/new-reg"));
            requ.Method = "POST";
            requ.ContentType = "application/json";
            requ.ContentLength = acmeJsonBytes.Length;
            using (var s = requ.GetRequestStream())
            {
                s.Write(acmeJsonBytes, 0, acmeJsonBytes.Length);
            }
            resp = requ.GetResponse();
        }