From eebe08aba43302b080c7b534a746f0f30359f370 Mon Sep 17 00:00:00 2001
From: elijah <elijah@riseup.net>
Date: Wed, 28 Jan 2015 12:32:15 -0800
Subject: client certificates: allow for time units to be specified in
 client_cert_lifespan config option.

---
 app/models/client_certificate.rb | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'app/models')

diff --git a/app/models/client_certificate.rb b/app/models/client_certificate.rb
index 815801e..688d5c0 100644
--- a/app/models/client_certificate.rb
+++ b/app/models/client_certificate.rb
@@ -48,7 +48,7 @@ class ClientCertificate
   end
 
   def expiry
-    @expiry ||= lifespan.months.from_now.utc.at_midnight
+    @expiry ||= lifespan
   end
 
   private
@@ -109,12 +109,14 @@ class ClientCertificate
   # We normalize timestamps at utc and midnight
   # to reduce the fingerprinting possibilities.
   #
-
   def last_month
     1.month.ago.utc.at_midnight
   end
 
   def lifespan
-    APP_CONFIG[:client_cert_lifespan]
+    number, unit = APP_CONFIG[:client_cert_lifespan].split(' ')
+    unit ||= :months
+    Time.now.utc.at_midnight.advance(unit.to_sym => number.to_i)
   end
+
 end
-- 
cgit v1.2.3