Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEYCLOAK-7560 Refactor token signature SPI PR
Also incorporates: KEYCLOAK-6770 ES256/384/512 providers KEYCLOAK-4622 Use HS256 for refresh tokens KEYCLOAK-4623 Use HS256 for client reg tokens
- Loading branch information
Showing
190 changed files
with
3,231 additions
and
2,067 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.keycloak; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
public interface Token { | ||
|
||
@JsonIgnore | ||
TokenCategory getCategory(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.keycloak; | ||
|
||
public enum TokenCategory { | ||
INTERNAL, | ||
ACCESS, | ||
ID, | ||
ADMIN, | ||
USERINFO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/main/java/org/keycloak/crypto/AsymmetricSignatureSignerContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.keycloak.crypto; | ||
|
||
import java.security.PrivateKey; | ||
import java.security.Signature; | ||
|
||
public class AsymmetricSignatureSignerContext implements SignatureSignerContext { | ||
|
||
private final KeyWrapper key; | ||
|
||
public AsymmetricSignatureSignerContext(KeyWrapper key) throws SignatureException { | ||
this.key = key; | ||
} | ||
|
||
@Override | ||
public String getKid() { | ||
return key.getKid(); | ||
} | ||
|
||
@Override | ||
public String getAlgorithm() { | ||
return key.getAlgorithm(); | ||
} | ||
|
||
@Override | ||
public byte[] sign(byte[] data) throws SignatureException { | ||
try { | ||
Signature signature = Signature.getInstance(JavaAlgorithm.getJavaAlgorithm(key.getAlgorithm())); | ||
signature.initSign((PrivateKey) key.getSignKey()); | ||
signature.update(data); | ||
return signature.sign(); | ||
} catch (Exception e) { | ||
throw new SignatureException("Signing failed", e); | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
core/src/main/java/org/keycloak/crypto/AsymmetricSignatureVerifierContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2016 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.keycloak.crypto; | ||
|
||
import org.keycloak.common.VerificationException; | ||
|
||
import java.security.PublicKey; | ||
import java.security.Signature; | ||
|
||
public class AsymmetricSignatureVerifierContext implements SignatureVerifierContext { | ||
|
||
private final KeyWrapper key; | ||
|
||
public AsymmetricSignatureVerifierContext(KeyWrapper key) { | ||
this.key = key; | ||
} | ||
|
||
@Override | ||
public String getKid() { | ||
return key.getKid(); | ||
} | ||
|
||
@Override | ||
public String getAlgorithm() { | ||
return key.getAlgorithm(); | ||
} | ||
|
||
@Override | ||
public boolean verify(byte[] data, byte[] signature) throws VerificationException { | ||
try { | ||
Signature verifier = Signature.getInstance(JavaAlgorithm.getJavaAlgorithm(key.getAlgorithm())); | ||
verifier.initVerify((PublicKey) key.getVerifyKey()); | ||
verifier.update(data); | ||
return verifier.verify(signature); | ||
} catch (Exception e) { | ||
throw new VerificationException("Signing failed", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.