packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/includes/functions.php
changeset 4 2212b2ded8bf
parent 3 a044870a9d3d
child 8 f68fdcc18df9
equal deleted inserted replaced
3:a044870a9d3d 4:2212b2ded8bf
    22 }
    22 }
    23 
    23 
    24 function smarty_function_get_next_uid()
    24 function smarty_function_get_next_uid()
    25 {
    25 {
    26 	return get_next_available_uid();
    26 	return get_next_available_uid();
       
    27 }
       
    28 
       
    29 function smarty_function_json_encode($params)
       
    30 {
       
    31 	return json_encode($params['value']);
    27 }
    32 }
    28 
    33 
    29 function load_credentials()
    34 function load_credentials()
    30 {
    35 {
    31 	$config = yaml_parse_file("/usr/local/etc/ssoinabox/webcreds.yml");
    36 	$config = yaml_parse_file("/usr/local/etc/ssoinabox/webcreds.yml");
    85 			$uniq .= $str{$i};
    90 			$uniq .= $str{$i};
    86 	}
    91 	}
    87 	
    92 	
    88 	return strlen($uniq);
    93 	return strlen($uniq);
    89 }
    94 }
       
    95 
       
    96 $ssh_key_lengths = array(
       
    97 		// pubkey len => key bits
       
    98 		'ecdsa-sha2-nistp521' => array('name' => 'ECDSA', 172 => 521)
       
    99 		, 'ecdsa-sha2-nistp384' => array('name' => 'ECDSA', 136 => 384)
       
   100 		, 'ecdsa-sha2-nistp256' => array('name' => 'ECDSA', 104 => 256)
       
   101 		, 'ssh-dss' => array(
       
   102 				'name' => 'DSA'
       
   103 				, 432 => 1024
       
   104 				, 433 => 1024
       
   105 				, 434 => 1024
       
   106 				, 435 => 1024
       
   107 			)
       
   108 		, 'ssh-rsa' => array(
       
   109 				'name' => 'RSA'
       
   110 				, 119 => 768
       
   111 				, 151 => 1024
       
   112 				, 215 => 1536
       
   113 				, 277 => 2048
       
   114 				, 279 => 2048
       
   115 				, 407 => 3072
       
   116 				, 535 => 4096
       
   117 			)
       
   118 	);
       
   119 
       
   120 function smarty_function_decode_ssh_key($params, $smarty)
       
   121 {
       
   122 	global $ssh_key_lengths;
       
   123 	
       
   124 	if ( !isset($params['key']) )
       
   125 		throw new SmartyException("No key provided");
       
   126 	
       
   127 	if ( !isset($params['out']) )
       
   128 		throw new SmartyException("No output var provided");
       
   129 	
       
   130 	list($type, $key_b64) = preg_split('/\s+/', $params['key']);
       
   131 	
       
   132 	$key = base64_decode($key_b64);
       
   133 	$bits = isset($ssh_key_lengths[$type][strlen($key)]) ? $ssh_key_lengths[$type][strlen($key)] : 0;
       
   134 	
       
   135 	$smarty->assign($params['out'], array(
       
   136 			'fingerprint' => implode(':', str_split(md5($key), 2))
       
   137 			, 'type' => $ssh_key_lengths[$type]['name']
       
   138 			, 'bits' => $bits
       
   139 		));
       
   140 }