Exemplo n.º 1
0
 public Hpkp(RequestDelegate next, ulong maxAge, ICollection <PublicKeyPin> keys, bool includeSubDomains = false, string reportUri = "", bool reportOnly = false)
 {
     if (maxAge < 1)
     {
         throw new ArgumentOutOfRangeException(nameof(maxAge));
     }
     if (keys == null)
     {
         throw new ArgumentNullException(nameof(keys));
     }
     if (keys.Count < 2)
     {
         throw new ArgumentException(" The current specification requires including a second pin for a backup key which isn't yet used in production. This allows for changing the server's public key without breaking accessibility for clients that have already noted the pins. This is important for example when the former key gets compromised.", nameof(keys));
     }
     _header         = HpKpHeaderBuilder.Build(maxAge, keys, includeSubDomains, reportUri);
     _next           = next;
     this.reportOnly = reportOnly;
 }
Exemplo n.º 2
0
        public void ThrowsExceptions()
        {
            Assert.Throws <ArgumentOutOfRangeException>(() =>
            {
                HpKpHeaderBuilder.Build(0, null);
            });
            Assert.Throws <ArgumentNullException>(() =>
            {
                HpKpHeaderBuilder.Build(2, null);
            });
            Assert.Throws <ArgumentException>(() =>
            {
                HpKpHeaderBuilder.Build(2, new List <PublicKeyPin>());
            });

            var results = HpKpHeaderBuilder.Build(2, new List <PublicKeyPin>()
            {
                new PublicKeyPin("yo", HpKpCrypto.sha256),
                new PublicKeyPin("dawg", HpKpCrypto.sha256)
            }, true, "/awesome");

            Assert.Equal <string>("pin-sha256=\"yo\"; pin-sha256=\"dawg\"; max-age=2; includeSubDomains; report-uri=\"/awesome\"", results);
        }