ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Identity.php
Go to the documentation of this file.
1 <?php
17 
19 
34 class Identity
35 {
43  var $key;
44 
52  var $key_blob;
53 
61  var $fsock;
62 
70  function __construct($fsock)
71  {
72  $this->fsock = $fsock;
73  }
74 
83  function setPublicKey($key)
84  {
85  $this->key = $key;
86  $this->key->setPublicKey();
87  }
88 
98  function setPublicKeyBlob($key_blob)
99  {
100  $this->key_blob = $key_blob;
101  }
102 
112  function getPublicKey($format = null)
113  {
114  return !isset($format) ? $this->key->getPublicKey() : $this->key->getPublicKey($format);
115  }
116 
126  function setSignatureMode($mode)
127  {
128  }
129 
139  function sign($message)
140  {
141  // the last parameter (currently 0) is for flags and ssh-agent only defines one flag (for ssh-dss): SSH_AGENT_OLD_SIGNATURE
142  $packet = pack('CNa*Na*N', Agent::SSH_AGENTC_SIGN_REQUEST, strlen($this->key_blob), $this->key_blob, strlen($message), $message, 0);
143  $packet = pack('Na*', strlen($packet), $packet);
144  if (strlen($packet) != fputs($this->fsock, $packet)) {
145  user_error('Connection closed during signing');
146  }
147 
148  $length = current(unpack('N', fread($this->fsock, 4)));
149  $type = ord(fread($this->fsock, 1));
151  user_error('Unable to retreive signature');
152  }
153 
154  $signature_blob = fread($this->fsock, $length - 1);
155  // the only other signature format defined - ssh-dss - is the same length as ssh-rsa
156  // the + 12 is for the other various SSH added length fields
157  return substr($signature_blob, strlen('ssh-rsa') + 12);
158  }
159 }
setPublicKey($key)
Set Public Key.
Definition: Identity.php:83
$format
Definition: metadata.php:141
__construct($fsock)
Default Constructor.
Definition: Identity.php:70
$type
setPublicKeyBlob($key_blob)
Set Public Key.
Definition: Identity.php:98
catch(Exception $e) $message
setSignatureMode($mode)
Set Signature Mode.
Definition: Identity.php:126
getPublicKey($format=null)
Get Public Key.
Definition: Identity.php:112
sign($message)
Create a signature.
Definition: Identity.php:139