Permalink
Browse files

Throw an exception if the certificate is no longer or not yet valid

  • Loading branch information...
PinpointTownes committed Jul 11, 2017
1 parent f17d9a4 commit 583be00898f09ff3a4ca8d7540e8d963fe56b8fd
@@ -98,9 +98,19 @@ public static class OpenIdConnectServerExtensions
throw new ArgumentNullException(nameof(certificate));
}
if (certificate.NotBefore > DateTime.Now)
{
throw new InvalidOperationException("The specified certificate is not yet valid.");
}
if (certificate.NotAfter < DateTime.Now)
{
throw new InvalidOperationException("The specified certificate is no longer valid.");
}
if (!certificate.HasPrivateKey)
{
throw new InvalidOperationException("The certificate doesn't contain the required private key.");
throw new InvalidOperationException("The specified certificate doesn't contain the required private key.");
}
return credentials.AddKey(new X509SecurityKey(certificate));
@@ -143,7 +153,7 @@ public static class OpenIdConnectServerExtensions
{
if (stream == null)
{
throw new InvalidOperationException("The certificate was not found in the given assembly.");
throw new InvalidOperationException("The certificate was not found in the specified assembly.");
}
return credentials.AddCertificate(stream, password);
@@ -226,7 +236,7 @@ public static class OpenIdConnectServerExtensions
if (certificate == null)
{
throw new InvalidOperationException("The certificate corresponding to the given thumbprint was not found.");
throw new InvalidOperationException("The certificate corresponding to the specified thumbprint was not found.");
}
return credentials.AddCertificate(certificate);
@@ -258,7 +268,7 @@ public static class OpenIdConnectServerExtensions
var certificate = OpenIdConnectServerHelpers.GetCertificate(name, location, thumbprint);
if (certificate == null)
{
throw new InvalidOperationException("The certificate corresponding to the given thumbprint was not found.");
throw new InvalidOperationException("The certificate corresponding to the specified thumbprint was not found.");
}
return credentials.AddCertificate(certificate);
@@ -99,9 +99,19 @@ public static class OpenIdConnectServerExtensions
throw new ArgumentNullException(nameof(certificate));
}
if (certificate.NotBefore > DateTime.Now)
{
throw new InvalidOperationException("The specified certificate is not yet valid.");
}
if (certificate.NotAfter < DateTime.Now)
{
throw new InvalidOperationException("The specified certificate is no longer valid.");
}
if (!certificate.HasPrivateKey)
{
throw new InvalidOperationException("The certificate doesn't contain the required private key.");
throw new InvalidOperationException("The specified certificate doesn't contain the required private key.");
}
var identifier = new SecurityKeyIdentifier
@@ -159,7 +169,7 @@ public static class OpenIdConnectServerExtensions
{
if (stream == null)
{
throw new InvalidOperationException("The certificate was not found in the given assembly.");
throw new InvalidOperationException("The certificate was not found in the specified assembly.");
}
return credentials.AddCertificate(stream, password);
@@ -241,7 +251,7 @@ public static class OpenIdConnectServerExtensions
if (certificate == null)
{
throw new InvalidOperationException("The certificate corresponding to the given thumbprint was not found.");
throw new InvalidOperationException("The certificate corresponding to the specified thumbprint was not found.");
}
return credentials.AddCertificate(certificate);
@@ -273,7 +283,7 @@ public static class OpenIdConnectServerExtensions
var certificate = OpenIdConnectServerHelpers.GetCertificate(name, location, thumbprint);
if (certificate == null)
{
throw new InvalidOperationException("The certificate corresponding to the given thumbprint was not found.");
throw new InvalidOperationException("The certificate corresponding to the specified thumbprint was not found.");
}
return credentials.AddCertificate(certificate);
@@ -199,7 +199,7 @@ public void AddCertificate_ThrowsAnExceptionForInvalidResource()
credentials.AddCertificate(assembly, "resource", "password");
});
Assert.Equal("The certificate was not found in the given assembly.", exception.Message);
Assert.Equal("The certificate was not found in the specified assembly.", exception.Message);
}
[Fact]
@@ -214,7 +214,7 @@ public void AddCertificate_ThrowsAnExceptionForInvalidThumbprint()
credentials.AddCertificate("thumbprint", StoreName.Root, StoreLocation.LocalMachine);
});
Assert.Equal("The certificate corresponding to the given thumbprint was not found.", exception.Message);
Assert.Equal("The certificate corresponding to the specified thumbprint was not found.", exception.Message);
}
[Fact]
@@ -240,7 +240,7 @@ public void AddCertificate_ThrowsAnExceptionForCertificateWithNoPrivateKey()
credentials.AddCertificate(certificate);
});
Assert.Equal("The certificate doesn't contain the required private key.", exception.Message);
Assert.Equal("The specified certificate doesn't contain the required private key.", exception.Message);
}
[Fact]
@@ -193,7 +193,7 @@ public void AddCertificate_ThrowsAnExceptionForInvalidResource()
credentials.AddCertificate(assembly, "resource", "password");
});
Assert.Equal("The certificate was not found in the given assembly.", exception.Message);
Assert.Equal("The certificate was not found in the specified assembly.", exception.Message);
}
[Fact]
@@ -208,7 +208,7 @@ public void AddCertificate_ThrowsAnExceptionForInvalidThumbprint()
credentials.AddCertificate("thumbprint", StoreName.Root, StoreLocation.LocalMachine);
});
Assert.Equal("The certificate corresponding to the given thumbprint was not found.", exception.Message);
Assert.Equal("The certificate corresponding to the specified thumbprint was not found.", exception.Message);
}
[Fact]
@@ -234,7 +234,7 @@ public void AddCertificate_ThrowsAnExceptionForCertificateWithNoPrivateKey()
credentials.AddCertificate(certificate);
});
Assert.Equal("The certificate doesn't contain the required private key.", exception.Message);
Assert.Equal("The specified certificate doesn't contain the required private key.", exception.Message);
}
[Fact]

0 comments on commit 583be00

Please sign in to comment.