38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/chef/knife/windows_cert_install.rb', line 38
def run
STDOUT.sync = STDERR.sync = true
if Chef::Platform.windows?
if @name_args.empty?
ui.error "Please specify the certificate path. e.g- 'knife windows cert install <path>"
exit 1
end
file_path = @name_args.first
config[:cert_passphrase] = get_cert_passphrase unless config[:cert_passphrase]
begin
ui.info "Adding certificate to the Windows Certificate Store..."
result = `powershell.exe -Command " '#{config[:cert_passphrase]}' | certutil -importPFX '#{file_path}' AT_KEYEXCHANGE"`
if $?.exitstatus == 0
ui.info "Certificate added to Certificate Store"
else
ui.info "Error adding the certificate. Use -VV option for details"
end
Chef::Log.debug "#{result}"
rescue => e
puts "ERROR: + #{e}"
end
else
ui.error "Certificate can be installed on Windows system only"
exit 1
end
end
|