Class: Acmesmith::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/acmesmith/command.rb

Instance Method Summary collapse

Instance Method Details

#add_san(name, *add_sans) ⇒ Object



176
177
178
# File 'lib/acmesmith/command.rb', line 176

def add_san(name, *add_sans)
  client.add_san(name, *add_sans)
end

#authorize(*domains) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/acmesmith/command.rb', line 20

def authorize(*domains)
  warn "! WARNING: 'acmesmith authorize' is not available"
  warn "!"
  warn "! TL;DR: Go ahead; Just run 'acmesmith order'."
  warn "!"
  warn "! Pre-authorization have not implemented yet in acme-client.gem (v2) library."
  warn "! But, required domain authorizations will be performed automatically when ordering a certificate."
  warn "!"
  warn "! Pro Tips: Let's encrypt doesn't provide pre-authorization as of May 18, 2018."
  warn "!"
  # client.authorize(*domains)
end

#autorenew(*names) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/acmesmith/command.rb', line 161

def autorenew(*names)
  remaining_life = case options[:remaining_life]
                   when %r{\A\d+/\d+\z}
                     Rational(options[:remaining_life])
                   when %r{\A([\d.]+)%\z}
                     Rational($1.to_f, 100)
                   when nil
                     nil
                   else
                     raise ArgumentError, "invalid format for --remaining-life: it must be in '..%' or '../..'"
                   end
  client.autorenew(days: options[:days], remaining_life: remaining_life, names: names.empty? ? nil : names)
end

#current(name) ⇒ Object



80
81
82
# File 'lib/acmesmith/command.rb', line 80

def current(name)
  puts client.current(name)
end

#list(name = nil) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/acmesmith/command.rb', line 71

def list(name = nil)
  if name
    puts client.certificate_versions(name)
  else
    puts client.certificates_list
  end
end

#list_profilesObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/acmesmith/command.rb', line 58

def list_profiles
  profiles = client.list_profiles
  if profiles.nil? || profiles.empty?
    puts "No profiles available from this ACME directory"
    return
  end
  profiles.each do |name, description|
    puts "#{name}: #{description}"
  end
end

#new_account(contact) ⇒ Object



12
13
14
15
16
17
# File 'lib/acmesmith/command.rb', line 12

def (contact)
  puts "=> Creating an account ..."
  key = client.(contact)
  puts "=> Public Key:"
  puts "\n#{key.private_key.public_key.to_pem}"
end

#order(name, *sans) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/acmesmith/command.rb', line 38

def order(name, *sans)
  cert = client.order(
    name, *sans,
    key_type: options[:key_type],
    rsa_key_size: options[:rsa_key_size],
    elliptic_curve: options[:elliptic_curve],
  )
  if options[:show_certificate]
    puts cert.certificate.to_text
    puts cert.certificate.to_pem
  end
end

#post_issue_hooks(name) ⇒ Object



52
53
54
# File 'lib/acmesmith/command.rb', line 52

def post_issue_hooks(name)
  client.post_issue_hooks(name)
end

#register(contact) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/acmesmith/command.rb', line 181

def register(contact)
  warn "!"
  warn "! DEPRECATION WARNING: Use 'acmesmith new-account' command"
  warn "! There is no user-facing breaking changes. It takes the same arguments with 'acmesmith register'."
  warn "!"
  warn "! This is due to change in semantics of ACME v2. ACME v2 defines 'new-account' instead of 'register' in v1."
  warn "!"
  (contact)
end

#request(name, *sans) ⇒ Object



193
194
195
196
197
198
199
200
201
# File 'lib/acmesmith/command.rb', line 193

def request(name, *sans)
  warn "!"
  warn "! DEPRECATION WARNING: Use 'acmesmith order' command"
  warn "! There is no user-facing breaking changes. It takes the same arguments with 'acmesmith request'."
  warn "!"
  warn "! This is due to change in semantics of ACME v2. ACME v2 defines 'order' instead of 'request' in v1."
  warn "!"
  order(name, *sans)
end

#save(name) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/acmesmith/command.rb', line 127

def save(name)
  client.save(
    name,
    version: options[:version],
    key_mode: options[:key_mode],
    certificate_mode: options[:certificate_mode],
    version_file: options[:version_file],
    key_file: options[:key_file],
    fullchain_file: options[:fullchain_file],
    chain_file: options[:chain_file],
    certificate_file: options[:certificate_file],
    atomic: options[:atomic],
    verbose: true,
  )
end

#save_certificate(name) ⇒ Object



98
99
100
# File 'lib/acmesmith/command.rb', line 98

def save_certificate(name)
  client.save_certificate(name, version: options[:version], mode: options[:mode], output: options[:output], type: options[:type])
end

#save_pkcs12(name) ⇒ Object

Raises:



147
148
149
150
151
152
153
154
155
156
# File 'lib/acmesmith/command.rb', line 147

def save_pkcs12(name)
  print 'Passphrase: '
  passphrase = $stdin.noecho { $stdin.gets }.chomp
  print "\nPassphrase (confirm): "
  passphrase2 = $stdin.noecho { $stdin.gets }.chomp
  puts

  raise ArgumentError, "Passphrase doesn't match" if passphrase != passphrase2
  client.save_pkcs12(name, version: options[:version], mode: options[:mode], output: options[:output], passphrase: passphrase)
end

#save_private_key(name) ⇒ Object



113
114
115
# File 'lib/acmesmith/command.rb', line 113

def save_private_key(name)
  client.save_private_key(name, version: options[:version], mode: options[:mode], output: options[:output])
end

#show_certificate(name) ⇒ Object



87
88
89
90
# File 'lib/acmesmith/command.rb', line 87

def show_certificate(name)
  certs = client.get_certificate(name, version: options[:version], type: options[:type])
  puts certs
end

#show_private_key(name) ⇒ Object



104
105
106
# File 'lib/acmesmith/command.rb', line 104

def show_private_key(name)
  puts client.get_private_key(name, version: options[:version])
end