Yubikey One-Time Password Authentication
Listing 3. Typo: Account-Specific Yubikey Configuration Options HTML
filename: app/views/admin/users/_form.html.erb: ... <li> <label class="float" for="user_notify_on_new_articles"><%= _("Send notification messages when new articles are posted")%>? </label> <%= check_box 'user', 'notify_on_new_articles' %> </li> <!-- new options for Yubikey authentication - start --> <li> <label class="float" for="user_yubikey_required"><%= _("Yubikey Required")%>? </label> <%= check_box 'user', 'yubikey_required' %> </li> <li> <label class="float" for="user_yubikey_id"><%= _("Yubikey ID")%>: </label> <%= text_field 'user', 'yubikey_id' %> </li> <!-- new options for Yubikey authentication - end --> </ul> </fieldset> <!--[eoform:user]-->
Listing 4. Typo: Yubikey Settings Database Migration
filename: db/migrate/071_add_yubikey_columns_to_user.rb: class AddYubikeyColumnsToUser < ActiveRecord::Migration def self.up add_column :users, :yubikey_id, :string, :null => false, :default => '' add_column :users, :yubikey_required, :boolean, :null => false, :default => false end def self.down remove_column :users, :yubikey_id remove_column :users, :yubikey_required end end
Now that we have the setup all taken care of, we can focus on the actual authentication during login. First, let's add a Yubikey OTP input field to the login screen provided that Yubikey authentication is enabled for the whole blog. I have done this by modifying the partial template that renders the login form in Listing 5. Notice that we always have to show the Yubikey OTP field during login, because until users supply their user names, we don't know whether Yubikey authentication is required for a particular user. Figure 8 shows the modified login screen.
When the login form is submitted, Rails routes it to the login method of the AccountsController class (Listing 6). This is where we add the logic to check whether we need to handle Yubikey authentication. After the existing code has verified the regular login and password, we now have an instantiated user object that can tell us whether Yubikey authentication is required for this user. If so, we invoke the static method authenticate_yubikey of the user object. Looking at Listing 7, we check that neither the Yubikey OTP from the login form nor the user's public Yubikey ID are blank. Moreover, by definition, the first 12 characters of the OTP have to match the public ID associated with the account. If everything is in order, we instantiate a Yubico object, which will handle the Web service authentication request for us. The method simply returns a boolean. True means the user was authenticated successfully. Conversely, false implies an invalid OTP or an attempt by an unauthorized user—possibly an attempt to hack into the account.
Listing 5. Typo: Modified Login Form HTML
filename: app/views/shared/_loginform.html.erb: <% form_tag :action=> "login" do %> <ul> <li> <label for="user_login"><%= _('Username')%>:</label> <input type="text" name="user_login" id="user_login" value=""/> </li> <li> <label for="user_password"><%= _('Password') %>:</label> <input type="password" name="user_password" id="user_password" /> </li> <!-- Yubikey authentication - start --> <% if this_blog.yubikey_required %> <li> <label for="yubikey_otp"><%= _('Yubikey OTP') %>:</label> <input type="text" name="yubikey_otp" id="yubikey_otp" /> </li> <% end %> <!-- Yubikey authentication - end --> <li class="r"><input type="submit" name="login" value= "<%= _('Login') %> »" class="primary" id="submit" /> </li> </ul> <p><%= link_to "« " + _('Back to ') + this_blog.blog_name, this_blog.base_url %></p> <% end %>
Listing 6. Typo: Yubikey Authentication Part 1
filename: app/controllers/accounts_controller.rb: ... def login case request.method when :post self.current_user = User.authenticate(params[:user_login], params[:user_password]) # check whether Yubikey authentication is required and perform # authentication if logged_in? && (!this_blog.yubikey_required || !self.current_user.yubikey_required || self.current_user.authenticate_yubikey( this_blog, self.current_user.yubikey_id, params[:yubikey_otp])) session[:user_id] = self.current_user.id flash[:notice] = _("Login successful") redirect_back_or_default :controller => "admin/dashboard", :action => "index" else flash.now[:notice] = _("Login unsuccessful") @login = params[:user_login] end end end ...
Practical Task Scheduling Deployment
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.View Now!
|The Firebird Project's Firebird Relational Database||Jul 29, 2016|
|Stunnel Security for Oracle||Jul 28, 2016|
|SUSE LLC's SUSE Manager||Jul 21, 2016|
|My +1 Sword of Productivity||Jul 20, 2016|
|Non-Linux FOSS: Caffeine!||Jul 19, 2016|
|Murat Yener and Onur Dundar's Expert Android Studio (Wrox)||Jul 18, 2016|
- The Firebird Project's Firebird Relational Database
- Stunnel Security for Oracle
- My +1 Sword of Productivity
- Managing Linux Using Puppet
- SUSE LLC's SUSE Manager
- Non-Linux FOSS: Caffeine!
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Google's SwiftShader Released
- Doing for User Space What We Did for Kernel Space
- Parsing an RSS News Feed with a Bash Script