Code

Fixed parameter expansion
[gosa.git] / include / class_certificate.inc
old mode 100755 (executable)
new mode 100644 (file)
index 5c9facf..f7e784d
@@ -19,14 +19,14 @@ class certificate
     $this->data= "";
     $this->type= false;
     $this->error="";  
+    $this->info = array();
   } 
 
   /* Reads specified Certfile/string and convert it to PEM*/
   function import($data,$type=false)
   {
     /* if is file read from file, else use string as it is*/
-    if(is_file($data))
-    {
+    if(is_file($data))  {
       $fp = fopen($data,"r+");
       $str = "";
 
@@ -81,22 +81,98 @@ class certificate
       /* Reset*/
       return(false);
     }
+
+    $this->info(false);
+
     /* Loaded a readable cert */
     return(true);
   }
 
   /* Returns Array with all containing data */
-  function info()
+  function info($ret = true)
   {
     if($this->type != PEM){
       $this->error = _("The Format must be PEM, to output certificate informations");
       return(false);
     } else {
-    /* return an array with all given information */
-    return(openssl_x509_parse($this->data));
+      /* return an array with all given information */
+      $this->info=openssl_x509_parse($this->data);
+
+      if($ret)
+        return($this->info);
+    }
+  }
+
+  /* Return Functions */
+  function getvalidto_date()
+  {
+    if(isset($this->info['validTo_time_t'])){
+      return($this->info['validTo_time_t']);
+    }else{
+      return(false);
+    }
+  } 
+
+  function getvalidfrom_date()
+  {
+    if(isset($this->info['validFrom_time_t'])){
+      return($this->info['validFrom_time_t']);
+    }else{
+      return(false);
+    }
+
+  }
+
+  function getname()
+  {
+    if(isset($this->info['name'])){
+      return($this->info['name']);
+    }else{
+      return(false);
+    }
+  }
+
+  function getCN()
+  {
+    if(isset($this->info['subject']['CN'])){
+      return($this->info['subject']['CN']);
+    }else{
+      return(false);
+    }
+  }
+
+  function getO()
+  {
+    if(isset($this->info['subject']['O'])){
+      return($this->info['subject']['O']);
+    }else{
+      return(false);
+    }
+  }
+
+  function getOU()
+  {
+    if(isset($this->info['subject']['OU'])){
+      return($this->info['subject']['OU']);
+    }else{
+      return(false);
     }
   }
 
+  function getSerialNumber()
+  {
+    if(isset($this->info['serialNumber'])){
+      return($this->info['serialNumber']);
+    }else{
+      return(false);
+    }
+  }
+
+  function isvalid()
+  {
+    return (($this->type != false)&&(count($this->info)>1));
+  }
+  
 
   /* Export Certificate to specified file, with specified method*/
   function export($type,$filename="temp")
@@ -131,8 +207,7 @@ class certificate
   function derTOpem()
   {
     /* if type is DER start convert */
-    if($this->type == DER)
-    {
+    if($this->type == DER)    {
       /* converting */
       $this->type= PEM; 
       $str = base64_encode($this->data);
@@ -140,8 +215,7 @@ class certificate
 
       $end = "";
 
-      while($len > 0 )
-      {
+      while($len > 0 )      {
         $len = $len - 64;
         $str1 = substr($str,0,64)."\n";
         $str  = substr($str,64,$len);
@@ -160,8 +234,7 @@ class certificate
   /*Convert pem to der Certificate */
   function pemTOder()
   {
-    if($this->type == PEM)
-    {
+    if($this->type == PEM)    {
       $this->type= DER;
 
       $str = $this->data;
@@ -178,8 +251,6 @@ class certificate
   }
 
 }
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
-
-
-