You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then I added the following 4 lines in front of the key.pem:
Bag Attributes
localKeyID: 01 00 00 00
friendlyName: lp-016f02aa-9b45-4295-baef-2ffc4768178e
Microsoft CSP Name: Microsoft Strong Cryptographic Provider
because I saw such a file format in the wild.
I think, that these "Bag Attributes" are sometimes generated when converting pkcs12 files (.pfx) into .pem files, like this:
Problem is, that MRI reads it in two ways, while JRuby only in one way:
rvm ruby-2.3.0 do ruby -e "require 'openssl' ; puts OpenSSL::PKey::RSA.new(File.read('key.pem'), 'demo').class"
=> OpenSSL::PKey::RSA
rvm ruby-2.3.0 do ruby -e "require 'openssl' ; puts OpenSSL::PKey.read(File.read('key.pem'), 'demo').class"
=> OpenSSL::PKey::RSA
rvm jruby-9.1.5.0 do ruby -e "require 'openssl' ; puts OpenSSL::PKey::RSA.new(File.read('key.pem'), 'demo').class"
=> OpenSSL::PKey::RSA
rvm jruby-9.1.5.0 do ruby -e "require 'openssl' ; puts OpenSSL::PKey.read(File.read('key.pem'), 'demo').class"
Unhandled Java exception: java.lang.ClassCastException: org.bouncycastle.asn1.DERApplicationSpecific cannot be cast to org.bouncycastle.asn1.ASN1Sequence
java.lang.ClassCastException: org.bouncycastle.asn1.DERApplicationSpecific cannot be cast to org.bouncycastle.asn1.ASN1Sequence
readRSAPrivateKey at org/jruby/ext/openssl/impl/PKey.java:173
readRSAPrivateKey at org/jruby/ext/openssl/impl/PKey.java:168
readPrivateKey at org/jruby/ext/openssl/impl/PKey.java:124
read at org/jruby/ext/openssl/PKey.java:120
call at org/jruby/ext/openssl/PKey$PKeyModule$INVOKER$s$0$1$read.gen:-1
call at org/jruby/internal/runtime/methods/JavaMethod.java:724
call at org/jruby/internal/runtime/methods/DynamicMethod.java:205
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:358
call at org/jruby/runtime/callsite/CachingCallSite.java:195
invokeOther5:read at -e:1
<main> at -e:1
invokeWithArguments at java/lang/invoke/MethodHandle.java:627
load at org/jruby/ir/Compiler.java:111
runScript at org/jruby/Ruby.java:834
runNormally at org/jruby/Ruby.java:749
runNormally at org/jruby/Ruby.java:767
runFromMain at org/jruby/Ruby.java:580
doRunFromMain at org/jruby/Main.java:425
internalRun at org/jruby/Main.java:313
run at org/jruby/Main.java:242
main at org/jruby/Main.java:204
When the 4 first lines, the "Bag Attributes", are removed from the .pem file, it also works with the JRuby:
I found this style of reading the private key file in the HTTPI gem; the commit that introduced it is here: savonrb/httpi#118
---
Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37898323-bag-attributes-in-a-private_key-pem-file-throws-a-classcastexception-while-it-works-in-mri?utm_campaign=plugin&utm_content=tracker%2F136995&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F136995&utm_medium=issues&utm_source=github).
The text was updated successfully, but these errors were encountered:
I created the following key.pem with the password demo using the following command:
Then I added the following 4 lines in front of the key.pem:
because I saw such a file format in the wild.
I think, that these "Bag Attributes" are sometimes generated when converting pkcs12 files (.pfx) into .pem files, like this:
Anyway, let's assume, that we've now this complete key.pem file:
Problem is, that MRI reads it in two ways, while JRuby only in one way:
When the 4 first lines, the "Bag Attributes", are removed from the .pem file, it also works with the JRuby:
I found this style of reading the private key file in the HTTPI gem; the commit that introduced it is here: savonrb/httpi#118
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37898323-bag-attributes-in-a-private_key-pem-file-throws-a-classcastexception-while-it-works-in-mri?utm_campaign=plugin&utm_content=tracker%2F136995&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F136995&utm_medium=issues&utm_source=github).The text was updated successfully, but these errors were encountered: