Created
November 25, 2015 23:59
-
-
Save drewbug/31af889480fbcd293494 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'openssl' | |
require 'tempfile' | |
OpenSSL::PKey::EC.send :alias_method, :private?, :private_key? | |
key = OpenSSL::PKey::EC.new('secp256k1') | |
key.generate_key | |
File.write 'mykey.pem', key.to_pem | |
cert = OpenSSL::X509::Certificate.new | |
cert.version = 0x2 | |
cert.issuer = OpenSSL::X509::Name.new([["commonName", "Satoshi Nakamoto"]]) | |
cert.not_before = Time.new(2015, 11, 25, 12, 0, 0, "-07:00") | |
cert.not_after = Time.new(2033, 10, 22, 0, 0, 0, "-07:00") | |
cert.subject = cert.issuer | |
cert.public_key = key | |
cert.add_extension OpenSSL::X509::ExtensionFactory.new(cert, cert).create_ext("subjectKeyIdentifier", "hash") | |
cert.sign(key, OpenSSL::Digest::SHA256.new) | |
IO.popen("openssl pkcs12 -export -inkey 'mykey.pem' -out 'mykey.p12' -name 'mykey' -password 'pass:changeit'", 'w').write(cert.to_pem) | |
exec "keytool -srcstoretype 'PKCS12' -importkeystore -srckeystore 'mykey.p12' -destkeystore 'keystore.jks' -srcstorepass 'changeit' -deststorepass 'changeit'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nevermind :( https://code.google.com/p/android/issues/detail?id=189170