String REALM = System.getenv("REALM");
String PUBLIC_KEY = System.getenv("PUBLIC_KEY");
String AUTH_SERVER_URL = System.getenv("AUTH_SERVER_URL");
String RESOURCE = System.getenv("RESOURCE");
String CREDENTIALS = System.getenv("CREDENTIALS");
// Configure the AuthHandler to process JWToken
JWTAuthHandler jwtHandler = JWTAuthHandler.create(
JWTAuth.create(vertx,new JsonObject(
"{\n" +
" \"realm\": " + "\"" + REALM + "\"" + ",\n" +
" \"public-key\": " + "\"" + PUBLIC_KEY + "\"" + ",\n" +
" \"auth-server-url\": " + "\"" + AUTH_SERVER_URL + "\"" + ",\n" +
" \"ssl-required\": \"external\",\n" +
" \"resource\": " + "\"" + RESOURCE + "\"" + ",\n" +
" \"credentials\": {\n" +
" \"secret\": " + "\"" + CREDENTIALS + "\"" + "\n" +
" }\n" +
"}"
))
);
router.route("/greeting").handler(jwtHandler);
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=105, too big. at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:205) at java.security.KeyFactory.generatePublic(KeyFactory.java:334) at io.vertx.ext.auth.jwt.impl.JWT.<init>(JWT.java:108) at io.vertx.ext.auth.jwt.impl.JWTAuthProviderImpl.<init>(JWTAuthProviderImpl.java:73) at io.vertx.ext.auth.jwt.JWTAuth.create(JWTAuth.java:41) at org.obsidiantoaster.quickstart.RestApplication.start(RestApplication.java:50) at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:434) at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:316) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) at java.lang.Thread.run(Thread.java:745)Caused by: java.security.InvalidKeyException: IOException: DerInputStream.getLength(): lengthTag=105, too big. at sun.security.x509.X509Key.decode(X509Key.java:398) at sun.security.x509.X509Key.decode(X509Key.java:403) at sun.security.rsa.RSAPublicKeyImpl.<init>(RSAPublicKeyImpl.java:84) at sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:298) at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:201) ... 12 more
try {
X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.getDecoder().decode(publicKey));
KeyFactory kf = KeyFactory.getInstance("RSA");
tmp.put("RS256", new CryptoPublicKey("SHA256withRSA", kf.generatePublic(spec)));
} catch (InvalidKeySpecException | NoSuchAlgorithmException | RuntimeException e) {
e.printStackTrace();
log.warn("RS256 not supported");
}
X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.getDecoder().decode(publicKey));
KeyFactory kf = KeyFactory.getInstance("RSA");
This means that the key is invalid/corrupted. Or the JDK does not have the required crypto extensions installed. In this case I say it is corrupted since its what the JDK is reporting:
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: ObjectIdentifier() -- data isn't an object ID (tag = 2)
{
"realm": "master",
"realm-public-key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqMIufM8dSnqH/EceTUOepwKEH1TjZT7Hg9S3GlgRY+Z28AciQF0EGP4u7WcVt3/ViuOqZvX6A5FO/TcKNjKqSOTVXeVGenIokAU0pN41MSs2tDU37r2o325gMbwn0+iONNec09ohthHwWgy8xLdadoXnO1En/3g0WJIpU45+wq8sjGzN4RyJU9+56OgpLX1MZLPib0cre07z8FHJTYHh31jJl6qR4lDe9auvleRevyR5RItf73zu0qMuFWZm2CWFxqm3ZB8BGUKGwoDTqfjFyCOO0NTWpIP5BtNmLbdtkTYDUoW0kboZ5ayPwV/qS7hkG1gKB09YgGjoufzXuRh3EQIDAQAB",
"auth-server-url": "http://localhost:8080/auth",
"ssl-required": "external",
"resource": "test",
"public-client": true
}
Pick the public key and run the code to check:
String key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqMIufM8dSnqH/EceTUOepwKEH1TjZT7Hg9S3GlgRY+Z28AciQF0EGP4u7WcVt3/ViuOqZvX6A5FO/TcKNjKqSOTVXeVGenIokAU0pN41MSs2tDU37r2o325gMbwn0+iONNec09ohthHwWgy8xLdadoXnO1En/3g0WJIpU45+wq8sjGzN4RyJU9+56OgpLX1MZLPib0cre07z8FHJTYHh31jJl6qR4lDe9auvleRevyR5RItf73zu0qMuFWZm2CWFxqm3ZB8BGUKGwoDTqfjFyCOO0NTWpIP5BtNmLbdtkTYDUoW0kboZ5ayPwV/qS7hkG1gKB09YgGjoufzXuRh3EQIDAQAB";
X509EncodedKeySpec spec = new X509EncodedKeySpec(Base64.getDecoder().decode(key));
KeyFactory kf = KeyFactory.getInstance("RSA");
kf.generatePublic(spec);
Works!
Now note that the key provided in this report is way longer than the one I've just generated.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/6626be64-390d-425b-bfc2-ae62385757cd%40googlegroups.com.--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/x6JDQ2lDmh0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.