Source

sks-keyserver-patches / KeyExpirationTime

# HG changeset patch
# Parent f11212b6e1657e41211139f1169a3680361c6b3b

diff -r f11212b6e165 common.ml
--- a/common.ml	Sun Oct 07 22:12:46 2012 +0200
+++ b/common.ml	Sun Oct 21 00:43:03 2012 +0200
@@ -44,7 +44,7 @@
 let enforced_filters = ["yminsky.dedup"]
 
 let version_tuple = (__VERSION__)
-let version_suffix = "" (* + for development branch *)
+let version_suffix = "+" (* + for development branch *)
 let compatible_version_tuple = (0,1,5)
 let version =
   let (maj_version,min_version,release) = version_tuple in
diff -r f11212b6e165 mRindex.ml
--- a/mRindex.ml	Sun Oct 07 22:12:46 2012 +0200
+++ b/mRindex.ml	Sun Oct 21 00:43:03 2012 +0200
@@ -94,6 +94,26 @@
   sprintf "uid:%s:%s:%s:"
     uid_string (time_to_string ctime) (time_to_string exptime)
 
+let get_key_expiration_from_uid keyid sigs = 
+  let sigs = get_self_sigs keyid sigs in
+  let times = List.map ~f:ParsePGP.get_key_exptimes sigs in
+  let (ctime,exptime) =
+    List.fold_left ~init:(None,None) ~f:(fun (cmax,emax) (cr,ex) -> if cr > cmax then (cr, ex) else (cmax, emax)) times in
+  (ctime,exptime)
+   
+let key_expiration_from_uids keyid pk_ctime uids =
+ let expir = List.map ~f:(fun (uid,sigs) ->
+      match uid.packet_type with
+          User_ID_Packet -> get_key_expiration_from_uid keyid sigs
+        | _ -> (None, None)
+      ) uids in
+  let (ctime, exptime) = 
+     List.fold_left ~init:(None,None) ~f:(fun (cmax,emax) (cr,ex) -> if cr > cmax then (cr, ex) else (cmax, emax)) expir
+  in
+  match exptime with 
+   | Some x -> x
+   | None -> Int64.zero
+
 (** number of seconds in a day *)
 let daysecs = Int64.of_int (60 * 60 * 24)
 
@@ -104,18 +124,22 @@
   let key_packet = pkey.KeyMerge.key in
   let pki = ParsePGP.parse_pubkey_info key_packet in
   let uids = pkey.KeyMerge.uids in
-  let exp_string = match pki.pk_expiration with
+  (*let exp_string = match pki.pk_expiration with
     | None -> ""
     | Some 0 -> "-"
     | Some days -> sprintf "%Ld"
         (Int64.add pki.pk_ctime (Int64.mul daysecs (Int64.of_int days)))
+  in*)
+  let key_expiry = key_expiration_from_uids full_keyid pki.pk_ctime uids 
+  in
+   let key_expiry_string = sprintf "%Ld" key_expiry (* This has to be updated to reflect possible expiry in direct key expir *)
   in
   let key_line = sprintf "pub:%s:%d:%d:%Ld:%s:%s"
                    keyid
                    pki.pk_alg
                    pki.pk_keylen
                    pki.pk_ctime
-                   exp_string
+                   key_expiry_string
                    (if (Index.is_revoked key) then "r" else "")
   in
   let uid_lines =
diff -r f11212b6e165 parsePGP.ml
--- a/parsePGP.ml	Sun Oct 07 22:12:46 2012 +0200
+++ b/parsePGP.ml	Sun Oct 21 00:43:03 2012 +0200
@@ -308,6 +308,7 @@
 
 let ssp_ctime_id = 2
 let ssp_exptime_id = 3
+let ssp_keyexptime_id = 9
 
 let int32_of_string s =
   let cin = new Channel.string_in_channel s 0 in
@@ -317,6 +318,28 @@
   let cin = new Channel.string_in_channel s 0 in
   cin#read_int64_size (String.length s)
 
+let get_key_exptimes sign = match sign with
+  | V3sig sign ->
+      (Some sign.v3s_ctime, None)
+  | V4sig sign ->
+      let hashed_subpackets = sign.v4s_hashed_subpackets in
+      let (ctime,exptime_delta) =
+        List.fold_left hashed_subpackets ~init:(None,None)
+          ~f:(fun (ctime,exptime) ssp ->
+                if ssp.ssp_type = ssp_ctime_id && ssp.ssp_length = 4 then
+                  (Some (int64_of_string ssp.ssp_body),exptime)
+                else if ssp.ssp_type = ssp_keyexptime_id && ssp.ssp_length = 4 then
+                  (ctime,Some (int64_of_string ssp.ssp_body))
+                else
+                  (ctime,exptime)
+             )
+      in
+      match (ctime,exptime_delta) with
+        | (Some x,None) -> (Some x,None)
+        | (None,_) -> (None,None)
+        | (Some x,Some y) -> (Some x,Some y)
+
+
 let get_times sign = match sign with
   | V3sig sign ->
       (Some sign.v3s_ctime, None)