JWK display support for key maps, still no key ids

pull/59/head
Justin Richer 2012-03-22 13:48:16 -04:00
parent d5e7000365
commit 6c01134095
4 changed files with 11 additions and 8 deletions

View File

@ -2,17 +2,18 @@ package org.mitre.jwt.signer.service;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.List; import java.util.List;
import java.util.Map;
import org.mitre.jwt.model.Jwt; import org.mitre.jwt.model.Jwt;
public interface JwtSigningAndValidationService { public interface JwtSigningAndValidationService {
/** /**
* Returns all public keys this service is configured with. * Returns all public keys this service is configured with, indexed by key id
* *
* @return * @return
*/ */
public List<PublicKey> getAllPublicKeys(); public Map<String, PublicKey> getAllPublicKeys();
/** /**
* Check to see if this JWT has expired or not * Check to see if this JWT has expired or not

View File

@ -68,7 +68,7 @@ public class JwtSigningAndValidationServiceDefault implements
* () * ()
*/ */
@Override @Override
public List<PublicKey> getAllPublicKeys() { public Map<String, PublicKey> getAllPublicKeys() {
Map<String, PublicKey> map = new HashMap<String, PublicKey>(); Map<String, PublicKey> map = new HashMap<String, PublicKey>();
@ -80,11 +80,13 @@ public class JwtSigningAndValidationServiceDefault implements
publicKey = ((RsaSigner) signer).getPublicKey(); publicKey = ((RsaSigner) signer).getPublicKey();
if (publicKey != null) if (publicKey != null) {
// what's the index of this map for?
map.put(((RSAPublicKey) publicKey).getModulus() map.put(((RSAPublicKey) publicKey).getModulus()
.toString(16).toUpperCase() .toString(16).toUpperCase()
+ ((RSAPublicKey) publicKey).getPublicExponent() + ((RSAPublicKey) publicKey).getPublicExponent()
.toString(16).toUpperCase(), publicKey); .toString(16).toUpperCase(), publicKey);
}
} else if (signer instanceof EcdsaSigner) { } else if (signer instanceof EcdsaSigner) {
@ -92,8 +94,7 @@ public class JwtSigningAndValidationServiceDefault implements
} }
} }
return new ArrayList<PublicKey>(map.values()); return map;
} }
/** /**

View File

@ -76,7 +76,7 @@ public class JwkKeyListView extends AbstractView {
o.addProperty("alg", "RSA"); o.addProperty("alg", "RSA");
o.addProperty("mod", m64); o.addProperty("mod", m64);
o.addProperty("exp", e64); o.addProperty("exp", e64);
// TODO: get the key ID from the map
return o; return o;
} else if (src instanceof ECPublicKey) { } else if (src instanceof ECPublicKey) {

View File

@ -1,6 +1,7 @@
package org.mitre.openid.connect.web; package org.mitre.openid.connect.web;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,7 +21,7 @@ public class JsonWebKeyEndpoint {
@RequestMapping("/jwk") @RequestMapping("/jwk")
public ModelAndView getJwk() { public ModelAndView getJwk() {
List<PublicKey> keys = jwtService.getAllPublicKeys(); Collection<PublicKey> keys = jwtService.getAllPublicKeys().values();
// TODO: check if keys are empty, return a 404 here or just an empty list? // TODO: check if keys are empty, return a 404 here or just an empty list?