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

shellsafe returns unsafe chars in 0.0.11 #19

Merged
merged 2 commits into from
Dec 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions lib/trocla/formats/x509.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def format(plain_password,options={})
else
raise "You need to pass \"subject\" or \"CN\" as an option to use this format"
end
hash = options['hash'] || 'sha2'
sign_with = options['ca'] || nil
keysize = options['keysize'] || 2048
serial = options['serial'] || 1
Expand All @@ -42,14 +43,14 @@ def format(plain_password,options={})
begin
subj = OpenSSL::X509::Name.parse(subject)
request = mkreq(subj, key.public_key)
request.sign(key, OpenSSL::Digest::SHA1.new)
request.sign(key, signature(hash))
rescue Exception => e
raise "Certificate request #{subject} creation failed: #{e.message}"
end

begin
csr_cert = mkcert(caserial, request.subject, ca, request.public_key, days, altnames)
csr_cert.sign(cakey, OpenSSL::Digest::SHA1.new)
csr_cert.sign(cakey, signature(hash))
setserial(sign_with, caserial)
rescue Exception => e
raise "Certificate #{subject} signing failed: #{e.message}"
Expand All @@ -60,7 +61,7 @@ def format(plain_password,options={})
begin
subj = OpenSSL::X509::Name.parse(subject)
cert = mkcert(serial, subj, nil, key.public_key, days, altnames)
cert.sign(key, OpenSSL::Digest::SHA1.new)
cert.sign(key, signature(hash))
rescue Exception => e
raise "Self-signed certificate #{subject} creation failed: #{e.message}"
end
Expand All @@ -72,6 +73,22 @@ def format(plain_password,options={})

# nice help: https://gist.github.com/mitfik/1922961

def signature(hash = 'sha2')
if hash == 'sha1'
OpenSSL::Digest::SHA1.new
elsif hash == 'sha224'
OpenSSL::Digest::SHA224.new
elsif hash == 'sha2' || hash == 'sha256'
OpenSSL::Digest::SHA256.new
elsif hash == 'sha384'
OpenSSL::Digest::SHA384.new
elsif hash == 'sha512'
OpenSSL::Digest::SHA512.new
else
raise "Unrecognized hash: #{hash}"
end
end

def mkkey(len)
OpenSSL::PKey::RSA.generate(len)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/trocla/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def chars
@chars ||= shellsafe + special_chars
end
def shellsafe
@chars ||= alphanumeric + shellsafe_chars
@shellsafe ||= alphanumeric + shellsafe_chars
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bleh, good catch!

end
def alphanumeric
@alphanumeric ||= ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
Expand Down