I had another look at the spec, and it says: *The RSA Key blinding operation [Kocher], which is a defense against some timing attacks, requires all of the RSA key values "n", "e", and "d". However, some RSA private key representations do not include the public exponent "e", but only include the modulus "n" and the private exponent "d". This is true, for instance, of the Java RSAPrivateKeySpec API, which does not include the public exponent "e" as a parameter. So as to enable RSA key blinding, such representations should be avoided. For Java, the RSAPrivateCrtKeySpec API can be used instead. Section 8.2.2(i) of the Handbook of Applied Cryptography [HAC] discusses how to compute the remaining RSA private key parameters, if needed, using only "n", "e", and "d".*
As the spec says says representations that do not have the value "e" *should* be avoided, rather than *must* be avoided, I assume CXF should allow such keys to be used. Also: - If such keys must not be used, a more appropriate exception should be thrown rather than NPE. - Conversion of such keys to JWK should also throw an exception (e.g. JwkUtils.fromRSAPrivateKey(privateKey, KeyAlgorithm.RSA_OAEP_256.getJwaName());). Finally, even when using an RSA key representation that has the public exponent, I still get NPE: https://gist.github.com/behrangsa/24dd165b89e5d4f9f2adee3be58b84f6 *modulus* = 27102507821348874474061747806252695386606210812848295717101025913307461778240809083534733891191469145018865639816248733252837576827247175435549777193545888768053361686964454990901200446336943691151514628235056298600936135537037660783549622548075671064684591044507574869537623427209698578437989841895743034200175397772696886525734349460072186949207849401109666798787048520797993921428006137086662997605264234071765713054984904430443036743929412795274188897714817285150199450013226006987717637543011916021796328664254883548256213838131998868607458493473398757429353686722803424274432422170409391202626090616600948989663 *publicExponent* = 65537 *privateExponent* = 3942325816880827934773191355066709570479530763978863894763630926523338467308079908957331250816001271945082108493954547417478685626350722850101408761250483812592164685015062475063874511419962528155811052549930446840147156264012390256642485187768823294621941901937694908697410075706700894887610924558525998215162921484531614258425298089696012354247984119206051727757767298982429571215215449987960925089649481975984322337338887849099264165613555075487653630947284393661041952069813103362730803138798849318518716300774043121939707515705371462787151082369777346954732250838935071409598377040302268071445195912101145921985 *primeP* = 168565645866321463721757359494893586965844048573965891421831251902170360925287024632232504341738302244181735765323813167912402262029828812818816064242449683202965956327874665437958752995615612700850215100753615532960278564880200378844344952016806003712378420741928422029122293440530685345579952819949419356577 *primeQ* = 160783104303721082738621587159947127022228239307230113065333132379355836939142594478872416309748726303605740321007079622289527210126211593675937607269474776250841338770912932330909766189328519015086351662333905791173139568145018928588087790353257183867789540266903768114307418555716349558052766927945686741119 *prime* = 141957598404779196877050096666648867842880582402220508710403443169272114381012885293836708723762460556035191729248392455611659148968526356670218292226822755318951082009369646685869348541038144806526467061977105276334645994672750039049347492129813036252705949274280383121462954049922480211075404062417387935489 *primeExponentQ* = 81069894589567163268043248053778061437806615620297222732867439148508684127347407335617117001932445194358174602250315792888863186575837498100635644478993453792652273367484289010405011271897720537307604722245814072498228436293271747183932145692103447532097980653979202852393131302526004717119393367623864662103 *crtCoefficient* = 86151368106407802820291205880249546532833965618233424046323726735206524540948924688092473064800640463667416566946540308778944233452634631940085093568530052427389357659926776418263520289213498925563444065938357278821039017220419054308970949297813382895576848904365377490953604759526735834556224481913568643218 Exception in thread "main" java.lang.SecurityException: java.lang.SecurityException: java.lang.NullPointerException at org.apache.cxf.rt.security.crypto.CryptoUtils.getRSAPrivateKey(CryptoUtils.java:184) at org.apache.cxf.rs.security.jose.jwk.JwkUtils.toRSAPrivateKey(JwkUtils.java:414) at org.apache.issues.Cxf7005.main(Cxf7005.java:73) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: java.lang.SecurityException: java.lang.NullPointerException at org.apache.cxf.rt.security.crypto.CryptoUtils.decodeSequence(CryptoUtils.java:629) at org.apache.cxf.rt.security.crypto.CryptoUtils.getRSAPrivateKey(CryptoUtils.java:175) ... 7 more Caused by: java.lang.NullPointerException at org.apache.cxf.common.util.Base64Utility.decode(Base64Utility.java:192) at org.apache.cxf.common.util.Base64UrlUtility.decode(Base64UrlUtility.java:41) at org.apache.cxf.rt.security.crypto.CryptoUtils.decodeSequence(CryptoUtils.java:627) ... 8 more On Wed, Aug 10, 2016 at 6:24 PM Behrang Saeedzadeh <[email protected]> wrote: > Hi, > > Am I using the CXF JOSE library in an incorrect way or is this a bug > https://issues.apache.org/jira/browse/CXF-7005? > -- > Best regards, > Behrang Saeedzadeh >
