Class ExplicitKeySignedJWTTrustEngineTest
- java.lang.Object
-
- net.shibboleth.oidc.security.impl.ExplicitKeySignedJWTTrustEngineTest
-
public class ExplicitKeySignedJWTTrustEngineTest extends Object
Tests for theExplicitKeySignedJWTTrustEngine.Note, there is not explicit test for the 'none' algorithm as Nimbus will not created a SignedJWT (as required by the trust engine) if the 'none' algorithm is used.
We can not test a JWT with an in-line symmetric key (oct type) JWK as Nimbus will not (correctly) parse it. Hence we assume the trust engine could never be passed such an invalid JWT.
-
-
Field Summary
Fields Modifier and Type Field Description private static StringCLIENT_SECRETThe client_secret.private static StringCLIENT_SECRET_512The client_secret.private MockFunctionalCredentialResolvercredResolverprivate CriteriaSetcriteriaThe criteria set to use.private StringCVE_2016_10555_SIGNING_CERT_PUBLIC_KEYprivate net.shibboleth.oidc.security.impl.ExplicitKeySignedJWTTrustEngineengineprivate JOSEObjectCredentialResolverjoseObjectCredResolverprivate StringJWT_WITH_INLINE_SHARED_SECRET_JWKThis is a forged JWT that contains a 'secret' inside the JWK header.private com.nimbusds.jose.jwk.ECKeykeyprivate net.shibboleth.oidc.security.jose.SignatureValidationParametersparamsSignature params.
-
Constructor Summary
Constructors Constructor Description ExplicitKeySignedJWTTrustEngineTest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static com.nimbusds.jwt.JWTClaimsSetbuildStandardClaims(String issuer, String audience)Build a basic claims set using the audience and issuer provided.protected static com.nimbusds.jwt.SignedJWTcreateECSignedJWT(com.nimbusds.jose.jwk.ECKey key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience)Create a EC signed JWS without a JKU or inline JWK.protected static com.nimbusds.jwt.SignedJWTcreateECSignedJWTWithDifferentInlineJWK(com.nimbusds.jose.jwk.ECKey key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, com.nimbusds.jose.jwk.ECKey signingKey, String issuer, String audience)Create a JWS using a a key that is different to that in the JOSE header.protected static com.nimbusds.jwt.SignedJWTcreateECSignedJWTWithInlineJWK(com.nimbusds.jose.jwk.ECKey key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience)Create an EC signed JWS with an inline (in JOSE headers) JWK.protected static com.nimbusds.jwt.SignedJWTcreateECSignedJWTWithJKU(com.nimbusds.jose.jwk.ECKey key, String keyId, URI jku, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience)Create an EC signed JWS with a JKU URL.protected static com.nimbusds.jwt.SignedJWTcreateMACSignedJWT(String key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience)Create a JWS using a MAC without a JKU or inline JWK.voidsetup()voidtestInvalid_CVE_2016_10555()Test for CVE-2016-10555.voidtestInvalid_InlineJWKInvalidSignature()voidtestInvalid_InlineJWKWrongKid()voidtestInvalid_WithInlineSharedSecretJWK()A shared secret would never come via a JWK, but test in case of forgery.voidtestInvalid_WithUntrustedInlineJWK_CVE_2018_0114()voidtestValid_WithInlineJKU()voidtestValid_WithInlineJWK()voidtestValid_WithSymmetricKeyCredential()voidtestValid_WithSymmetricKeyCredential_Filtered()Test symmetric key using a mock filtering resolver.voidtestValid_WithSymmetricKeyCredential_Filtered_WrongKeySize()Test symmetric key using a mock filtering resolver.voidtestValid_WithSymmetricKeyCredential_JWSAlgorithm_Excluded()voidtestValid_WithSymmetricKeyCredential_JWSAlgorithm_NotIncluded()voidtestValid_WithTrustedCredential()
-
-
-
Field Detail
-
engine
private net.shibboleth.oidc.security.impl.ExplicitKeySignedJWTTrustEngine engine
-
key
private com.nimbusds.jose.jwk.ECKey key
-
credResolver
private MockFunctionalCredentialResolver credResolver
-
joseObjectCredResolver
private JOSEObjectCredentialResolver joseObjectCredResolver
-
CVE_2016_10555_SIGNING_CERT_PUBLIC_KEY
private final String CVE_2016_10555_SIGNING_CERT_PUBLIC_KEY
- See Also:
- Constant Field Values
-
JWT_WITH_INLINE_SHARED_SECRET_JWK
private final String JWT_WITH_INLINE_SHARED_SECRET_JWK
This is a forged JWT that contains a 'secret' inside the JWK header. This should never happen, but we want to test that we can not create a SignedJWT from it.- See Also:
- Constant Field Values
-
CLIENT_SECRET
private static final String CLIENT_SECRET
The client_secret. 256 bit- See Also:
- Constant Field Values
-
CLIENT_SECRET_512
private static final String CLIENT_SECRET_512
The client_secret. 256 bit- See Also:
- Constant Field Values
-
params
private net.shibboleth.oidc.security.jose.SignatureValidationParameters params
Signature params.
-
criteria
private CriteriaSet criteria
The criteria set to use.
-
-
Method Detail
-
setup
@BeforeMethod public void setup() throws com.nimbusds.jose.JOSEException- Throws:
com.nimbusds.jose.JOSEException
-
testValid_WithTrustedCredential
public void testValid_WithTrustedCredential() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testValid_WithSymmetricKeyCredential
public void testValid_WithSymmetricKeyCredential() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testValid_WithSymmetricKeyCredential_Filtered
public void testValid_WithSymmetricKeyCredential_Filtered() throws com.nimbusds.jose.JOSEException, SecurityExceptionTest symmetric key using a mock filtering resolver.- Throws:
com.nimbusds.jose.JOSEException- on errorSecurityException- on error
-
testValid_WithSymmetricKeyCredential_Filtered_WrongKeySize
public void testValid_WithSymmetricKeyCredential_Filtered_WrongKeySize() throws com.nimbusds.jose.JOSEException, SecurityExceptionTest symmetric key using a mock filtering resolver. The key length is too small for the HS512 MAC algorithm used and so no credentials should be supplied for validation.- Throws:
com.nimbusds.jose.JOSEException- on errorSecurityException- on error
-
testValid_WithSymmetricKeyCredential_JWSAlgorithm_Excluded
public void testValid_WithSymmetricKeyCredential_JWSAlgorithm_Excluded() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testValid_WithSymmetricKeyCredential_JWSAlgorithm_NotIncluded
public void testValid_WithSymmetricKeyCredential_JWSAlgorithm_NotIncluded() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testInvalid_CVE_2016_10555
public void testInvalid_CVE_2016_10555() throws ExceptionTest for CVE-2016-10555. That is, can a malicious user choose which algorithm to verify the token with. If so, they could create a MAC for the JWT with the servers public key as a secret, change the algorithm to HS256 (a MAC version) and have the server (if vulnerable) validate it against the public key it has locally - so the server assumes it always needs to use the public key to verify signatures, and passes it in as a secret to the MAC verifier.This is only likely in cases where the implementation only expects to verify using a public key and has a generic method that accepts the public key, but can actually use a MAC verification method - with the public key. So a fairly unusual case!.
- Throws:
Exception- on error.
-
testValid_WithInlineJWK
public void testValid_WithInlineJWK() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testInvalid_WithInlineSharedSecretJWK
public void testInvalid_WithInlineSharedSecretJWK() throws ExceptionA shared secret would never come via a JWK, but test in case of forgery. We should not support shared secrets in JWKs. Nimbus should not parse such a header. Add a smoke test to ensure this is always the case.- Throws:
Exception- on error.
-
testInvalid_WithUntrustedInlineJWK_CVE_2018_0114
public void testInvalid_WithUntrustedInlineJWK_CVE_2018_0114() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testValid_WithInlineJKU
public void testValid_WithInlineJKU() throws com.nimbusds.jose.JOSEException, SecurityException, URISyntaxException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityExceptionURISyntaxException
-
testInvalid_InlineJWKWrongKid
public void testInvalid_InlineJWKWrongKid() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
testInvalid_InlineJWKInvalidSignature
public void testInvalid_InlineJWKInvalidSignature() throws com.nimbusds.jose.JOSEException, SecurityException- Throws:
com.nimbusds.jose.JOSEExceptionSecurityException
-
buildStandardClaims
protected static com.nimbusds.jwt.JWTClaimsSet buildStandardClaims(String issuer, String audience)
Build a basic claims set using the audience and issuer provided.- Parameters:
issuer- the issueraudience- the audience- Returns:
- the constructed claims set
-
createECSignedJWT
protected static com.nimbusds.jwt.SignedJWT createECSignedJWT(com.nimbusds.jose.jwk.ECKey key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience) throws com.nimbusds.jose.JOSEExceptionCreate a EC signed JWS without a JKU or inline JWK.- Parameters:
key- the key to sign the JWT.keyId- the keyId to describe the key to use in the header.algo- the key algorithm.issuer- the issuer.audience- the audience.- Returns:
- the signed JWT
- Throws:
com.nimbusds.jose.JOSEException- on error.
-
createMACSignedJWT
protected static com.nimbusds.jwt.SignedJWT createMACSignedJWT(String key, @Nullable String keyId, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience) throws com.nimbusds.jose.JOSEException
Create a JWS using a MAC without a JKU or inline JWK.- Parameters:
key- the shared key to sign the JWT.keyId- the keyId to describe the key to use in the header. If null, will not be addedalgo- the key algorithm.issuer- the issuer.audience- the audience.- Returns:
- the signed JWT
- Throws:
com.nimbusds.jose.JOSEException- on error.
-
createECSignedJWTWithJKU
protected static com.nimbusds.jwt.SignedJWT createECSignedJWTWithJKU(com.nimbusds.jose.jwk.ECKey key, String keyId, URI jku, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience) throws com.nimbusds.jose.JOSEException, URISyntaxExceptionCreate an EC signed JWS with a JKU URL.- Parameters:
key- the key to sign the JWT.keyId- the keyId to describe the key to use in the header.jku- the JKU.algo- the key algorithm.issuer- the issuer.audience- the audience.- Returns:
- the signed JWT
- Throws:
com.nimbusds.jose.JOSEException- on error.URISyntaxException- on error.
-
createECSignedJWTWithInlineJWK
protected static com.nimbusds.jwt.SignedJWT createECSignedJWTWithInlineJWK(com.nimbusds.jose.jwk.ECKey key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, String issuer, String audience) throws com.nimbusds.jose.JOSEExceptionCreate an EC signed JWS with an inline (in JOSE headers) JWK.- Parameters:
key- the key to sign the JWT.keyId- the keyId to describe the key to use in the header.algo- the key algorithm.issuer- the issuer.audience- the audience.- Returns:
- the signed JWT
- Throws:
com.nimbusds.jose.JOSEException- on error.
-
createECSignedJWTWithDifferentInlineJWK
protected static com.nimbusds.jwt.SignedJWT createECSignedJWTWithDifferentInlineJWK(com.nimbusds.jose.jwk.ECKey key, String keyId, com.nimbusds.jose.JWSAlgorithm algo, com.nimbusds.jose.jwk.ECKey signingKey, String issuer, String audience) throws com.nimbusds.jose.JOSEExceptionCreate a JWS using a a key that is different to that in the JOSE header.- Parameters:
key- the key to described in the JWK header.keyId- the keyId to describe the key to use in the header.algo- the key algorithm.signingKey- the key used to sign the JWS, which could be different than the key described in the JWK.issuer- the issuer.audience- the audience.- Returns:
- the signed JWT
- Throws:
com.nimbusds.jose.JOSEException- on error.
-
-