• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Exception doesn't fit source  RSS feed

 
Ranch Hand
Posts: 136
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I was playing around a bit with BouncyCastle - and got an Exception wich shouldn't happen according to source.

What I tried:

When checking privateKey.getClass().getName() I get com.sun.crypto.provider.DHPrivateKey. But last line throws this Stacktrace:

So I dug through the code - here is what gets called in order:

org.bouncycastle.openssl.jcajce.JcaPEMWriter.writeObject


org.bouncycastle.openssl.jcajce.JcaPEMWriter.writeObject


org.bouncycastle.util.io.pem.PemWriter.writeObject


org.bouncycastle.openssl.MiscPEMGenerator.generate


org.bouncycastle.openssl.MiscPEMGenerator.createPemObject


As far as I understand this whole if-mess in createPemObject the Exception throw should only happen if the passed Object is instanceof org.bouncycastle.asn1.pkcs.PrivateKeyInfo - wich com.sun.crypto.provider.DHPrivateKey obviously isn't. Am I don't getting the right path and get trolled by indentation?
So, I re-indented the code with the missing parenthesis after each else - this is what I came up with:

Is this the real truth table - or am I mis-understanding "else if" and this should better be placed in beginners forum?

As far as I understand blocks with optional parenthesis:



As the last statement line is also another if - it cascades down to:


Am I right with this - or is it here why I think the line "unknown object passed - can't encode." should be thrown? Or did someone at BouncyCastle missed some parenthesis somewhere so the flow is different from what the dev might thought it would be?

Also: THAT'S the reason why one should never omit parenthesis even if it's allowed.

I just don't understand how the flow ends in "Cannot identify private key" when, as far as I understand it, to end up there Object needs to be instanceof PrivateKeyInfo.

I also had it run through de-compiler - here's the output:

So, to get to the Exception "Cannot identify private key" Object indeed has to be instanceof PrivateKeyInfo - wich com.sun.crypto.provider.DHPrivateKey neither is nor could - I'm not seeing it ...
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!