Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: nil is not a string when trying to write smime. #4585

Closed
mungler opened this issue May 2, 2017 · 4 comments
Closed

TypeError: nil is not a string when trying to write smime. #4585

mungler opened this issue May 2, 2017 · 4 comments

Comments

@mungler
Copy link

mungler commented May 2, 2017

Environment

Re: https://twitter.com/headius/status/859532672611356672

macOS Sierra 10.12.3 on iMac 27'' 5K

Darwin Eddie.mungler.home 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

jruby 9.1.8.0 (2.3.1) 2017-03-06 90fc7ab Java HotSpot(TM) 64-Bit Server VM 25.40-b23 on 1.8.0_40-ea-b20 +jit [darwin-x86_64]
JRUBY_OPTS=-J-Xmn512m -J-Xms4096m -J-Xmx4096m -J-server

Gems included by the bundle:

  • activesupport (3.0.0)
  • asw-cache (0.2.0)
  • asw-services (0.0.55 399297c)
  • asw_database (1.0.1)
  • asw_models (0.2.10 5f042c2)
  • bond (0.5.1)
  • bundler (1.14.6)
  • chronic (0.10.2)
  • commander (4.4.3)
  • concurrent-ruby (1.0.5)
  • diff-lcs (1.3)
  • dry-configurable (0.7.0)
  • dry-container (0.6.0)
  • dry-core (0.2.4)
  • dry-equalizer (0.2.0)
  • dry-logic (0.4.1)
  • dry-struct (0.2.1)
  • dry-types (0.10.2)
  • faraday (0.12.1)
  • fotc (0.2.1)
  • gcm (0.1.1)
  • grocer (0.7.1)
  • highline (1.7.8)
  • httparty (0.14.0)
  • ice_nine (0.11.2)
  • inflecto (0.0.2)
  • jdbc-mysql (5.1.40)
  • jedis_rb (2.7.2)
  • jruby-openssl (0.9.20)
  • json (2.1.0)
  • msgpack (1.1.0)
  • multi_xml (0.6.0)
  • multipart-post (2.0.0)
  • nelson-rpc (0.0.24)
  • passbook (0.4.4)
  • puma (3.8.2)
  • rack (1.6.5)
  • rack-test (0.6.3)
  • rake (10.5.0)
  • require_all (1.4.0)
  • ripl (0.7.1)
  • ripl-color_error (0.1.1)
  • ripl-color_streams (0.1.2)
  • ripl-ripper (0.1.0)
  • rspec (3.5.0)
  • rspec-core (3.5.4)
  • rspec-expectations (3.5.0)
  • rspec-mocks (3.5.0)
  • rspec-support (3.5.0)
  • rubyzip (1.2.1)
  • sequel (4.46.0)
  • sequel_polymorphic_asw (0.2.3)
  • terminal-table (1.7.3)
  • unicode-display_width (1.1.3)
  • whenever (0.9.7)
>> p12 = OpenSSL::PKCS12.new File.read(certificate), password
=> #<OpenSSL::PKCS12:0x2e62e227 @key=#<OpenSSL::PKey::RSA:0x5ebe903a>, @ca_certs=[], @der="0\x82\x19\x18\x02\x01\x030\x82\x18\xDF\x06\t*\x86H\x86\xF7\r\x01\a\x01\xA0\x82\x18\xD0\x04\x82\x18\xCC0\x82\x18\xC80\x82\r\xFF\x06\t*\x86H\x86\xF7\r\x01\a\x06\xA0\x82\r\xF00\x82\r\xEC\x02\x01\x000\x82\r\xE5\x06\t..... etc etc 
>> p12.key.to_s
=> "-----BEGIN RSA PRIVATE KEY-----\nMIIEdqpn1xRuIJyx\n6oklTnT4y8pDPhlnqX8BBJmURik8VUSF\ntFeKzfLRIh8GxoO6Yfdki2ESffh6ynxmv+c8PuMrhHd3zKow6eeSgXmFqjCIQu3okiVUkB8owBvJr9r/QZkKa3ZGlQiZz/XVTdzpaUSh7YzeZuzlI9ipj9lElrtsb\n0n7RFED50uW0SxTFtxTFGv4Y/uSxvvd6/uPw5TfxINfr5JDDsqQ9zqg8KxBZxHJsaqKN5RtmzhmYu6wXKk/TT4B8sMr\npGss6A...... snip ......9kZahyvHVKd/5bahPiwGuBXEcbfaGNL8sjPr3eRP3KDJf\n-----END RSA PRIVATE KEY-----\n"
>> p12.certificate.to_s
=> "-----BEGIN CERTIFICATE-----\nMIYxCzAJBgNV\nBAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3Js\nZHdpZGUgRGV2ZWxvcGVyIFJlbGF0aW9uczFEMEIGA1UEAww7QXBwbGUgV29ybGR3\na..... snip .....EmZD1K5TM=\n-----END CERTIFICATE-----\n"
>> 
>> wwdc  = OpenSSL::X509::Certificate.new File.read(wwdc)
=> #<OpenSSL::X509::Certificate:0x5d2e65bd subject=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority, issuer=/C=US/O=Apple Inc./OU=Apple Certification Authority/CN=Apple Root CA, serial=134752589830791184, not_before=2013-02-07 21:48:47 UTC, not_after=2023-02-07 21:48:47 UTC>

>> data = 'foobarbaz'
=> "foobarbaz"
>> key_hash = {}
=> {}
>> key_hash[:cert] = p12.certificate
=> #<OpenSSL::X509::Certificate:0x75663443 subject=/userId=pass.com.asmallworld.events.ticket/CN=Pass Type ID: pass.com.asmallworld.events.ticket/OU=QY8279AAHT/O=aSmallworld.net/C=US, issuer=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority, serial=534939252856400662, not_before=2017-04-26 12:37:42 UTC, not_after=2018-04-26 12:37:42 UTC>
>> key_hash[:key] = p12.key
=> #<OpenSSL::PKey::RSA:0x7cbe3a05>
>>
>> pk7   = OpenSSL::PKCS7.sign key_hash[:cert], key_hash[:key], data.to_s, [wwdc], OpenSSL::PKCS7::BINARY | OpenSSL::PKCS7::DETACHED
=> #<OpenSSL::PKCS7:0x7aa63f50 @data="foobarbaz">

>> data  = OpenSSL::PKCS7.write_smime pk7
TypeError: nil is not a string
    org/jruby/ext/openssl/PKCS7.java:197:in `write_smime'
    (ripl):28:in `<eval>'
    org/jruby/RubyKernel.java:1000:in `eval'
>> 

Sorry, had to throw this together quickly as its late, but wanted to get it logged asap.

@mungler
Copy link
Author

mungler commented May 3, 2017

@headius FYI :)

@kares
Copy link
Member

kares commented May 3, 2017

seems like a JRuby-OpenSSL issue ... preferably move it to https://github.com/jruby/jruby-openssl/issues

@kares
Copy link
Member

kares commented May 3, 2017

also if we're to have a small reproducable (self-contained) script it would sure help resolve the issue faster.

@mungler
Copy link
Author

mungler commented May 3, 2017

@kares ok thanks, will move it. Will try to put together something to reproduce.

@mungler mungler closed this as completed May 3, 2017
@enebo enebo added this to the Invalid or Duplicate milestone May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants