From 6d7371ba1a201af729cc255b5d6bf808f4cc9bf2 Mon Sep 17 00:00:00 2001 From: Justin Richer Date: Tue, 14 Feb 2012 12:31:51 -0500 Subject: [PATCH] added spring aspect to project, tweaked configuration to point to keystore file correctly, added JWK endpoint views --- server/.project | 6 +++ .../openid/connect/view/JwkKeyListView.java | 43 +++++++++++++++--- .../connect/web/JsonWebKeyEndpoint.java | 4 +- .../spring/appServlet/servlet-context.xml | 2 + .../WEB-INF/spring/application-context.xml | 2 +- .../main/webapp/WEB-INF/spring/keystore.jks | Bin 1318 -> 1393 bytes 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/server/.project b/server/.project index 4c7c87524..f0808e7fa 100644 --- a/server/.project +++ b/server/.project @@ -31,8 +31,14 @@ + + org.springframework.ide.eclipse.core.springbuilder + + + + org.springframework.ide.eclipse.core.springnature org.eclipse.jem.workbench.JavaEMFNature org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.jdt.core.javanature diff --git a/server/src/main/java/org/mitre/openid/connect/view/JwkKeyListView.java b/server/src/main/java/org/mitre/openid/connect/view/JwkKeyListView.java index 175e63a34..ecbf2e57d 100644 --- a/server/src/main/java/org/mitre/openid/connect/view/JwkKeyListView.java +++ b/server/src/main/java/org/mitre/openid/connect/view/JwkKeyListView.java @@ -5,12 +5,17 @@ package org.mitre.openid.connect.view; import java.io.Writer; import java.lang.reflect.Type; +import java.math.BigInteger; +import java.security.PublicKey; +import java.security.interfaces.DSAPublicKey; +import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.codec.binary.Base64; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.web.servlet.view.AbstractView; @@ -49,21 +54,47 @@ public class JwkKeyListView extends AbstractView { } }) - .registerTypeAdapter(RSAPublicKey.class, new JsonSerializer() { + .registerTypeHierarchyAdapter(PublicKey.class, new JsonSerializer() { @Override - public JsonElement serialize(RSAPublicKey src, Type typeOfSrc, JsonSerializationContext context) { + public JsonElement serialize(PublicKey src, Type typeOfSrc, JsonSerializationContext context) { + if (src instanceof RSAPublicKey) { - JsonObject o = new JsonObject(); - o.addProperty("mod", src.getModulus().toString()); + RSAPublicKey rsa = (RSAPublicKey)src; + + + BigInteger mod = rsa.getModulus(); + BigInteger exp = rsa.getPublicExponent(); + + String m64 = Base64.encodeBase64URLSafeString(mod.toByteArray()); + String e64 = Base64.encodeBase64URLSafeString(exp.toByteArray()); + + JsonObject o = new JsonObject(); + + o.addProperty("mod", m64); + o.addProperty("exp", e64); + + return o; + } else if (src instanceof ECPublicKey) { + + ECPublicKey ec = (ECPublicKey)src; + + // TODO: serialize the EC + + return null; + + } else { + + // skip this class ... we shouldn't have any keys in here that aren't encodable by this serializer + return null; + } - return o; } - }) + }) .create(); diff --git a/server/src/main/java/org/mitre/openid/connect/web/JsonWebKeyEndpoint.java b/server/src/main/java/org/mitre/openid/connect/web/JsonWebKeyEndpoint.java index 582b42d29..e1a9abb0a 100644 --- a/server/src/main/java/org/mitre/openid/connect/web/JsonWebKeyEndpoint.java +++ b/server/src/main/java/org/mitre/openid/connect/web/JsonWebKeyEndpoint.java @@ -22,9 +22,9 @@ public class JsonWebKeyEndpoint { List keys = jwtService.getAllPublicKeys(); - // TODO: check if keys are empty, return a 404 here? + // TODO: check if keys are empty, return a 404 here or just an empty list? - return new ModelAndView("jwkKeyList", "keys", keys); // TODO: make a view + return new ModelAndView("jwkKeyList", "entity", keys); } } diff --git a/server/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/server/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml index edd1ff712..264f8641b 100644 --- a/server/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml +++ b/server/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml @@ -34,6 +34,8 @@ + + diff --git a/server/src/main/webapp/WEB-INF/spring/application-context.xml b/server/src/main/webapp/WEB-INF/spring/application-context.xml index f65789929..9d08351bf 100644 --- a/server/src/main/webapp/WEB-INF/spring/application-context.xml +++ b/server/src/main/webapp/WEB-INF/spring/application-context.xml @@ -73,7 +73,7 @@ - + diff --git a/server/src/main/webapp/WEB-INF/spring/keystore.jks b/server/src/main/webapp/WEB-INF/spring/keystore.jks index c2f6182ca301eded4f8b24a7ab6a2709b242b463..eeb6002e74e3080bc148f6692a2e44253cb7976f 100644 GIT binary patch literal 1393 zcmezO_TO6u1_mY|W&~rFlGNf7Ajh=kp~Fm|#BPHortJoNY+TxGj4X^=OoEJztPCto zOp84-&++ZI-rxDo^0ntv_JA+@)qjOQNvT;cnEl4&>64H9bh#y!4K7XCyTpa7P&%WAKJD7+hV&8&7L^h|8YdgwH%c)g`0K)TvzS3MZfddsddVTtJzQR zd8Y05Gmp!QPL-*#9Evh7uI>6a*Lds0>|>TJf>ufinx+aq@qbVGek`_M5EHXdza^tR z?CdhtwD$`Pnq*uIEu;-PBHIof-&r?9^iI6^e&)V}(Q1Xi%{~U3{fwtY_V5}#eC=WNt)I6utGjtFLzAM9 zWRtCz#MJYZLiygQ^Z%XiI>8}v`e}N=yF-&anpb)^Z~wwO`~0fk-2u#sY{yehU3}Bw zq_>q*R#U?3@bS5>_F3-zIiCLmx6Zm!cXV56QvmbtLnr>uv73BJWY^*RfP&Q*qC@t` zwrSpVH{iQC@l%UXoA5-1z2@-~Ud`=sXaBe`_th@e##R|GL0e6R!!KN>IG+1-YQeg? zx0@wQHg;^~@W21jJfwFC_m)@eJV$Pxc+9E!c3qjk%iB3Te{;k7-#&C*)bnLC>%P-+ z^LUi|Kd=;Ew)j!IUPIRH>Pe-SD{np69j(6hv_eST#9-C^-^$7-GBrI&oz9i9cqikw z(>qP7X056`|8;WsLVXXmhYX&~#@(N`J_s#K5YrWH?E0|E5S*Y{BlJuSEP*Mx5SWs4 z4VoCQEnsG1WMX3Rx0-&}fR~L^tIebBJ1;Oo!{k?wLY41jR-MBw&ANv#opU1at&M4zPDZKrPcuJ1&<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