Updates to 3rd party libraries
Add Dockerfile and specific docker-php.ini
This commit is contained in:
44
inc/vendor/pacificsec/cpe/src/Common/LogicalValue.php
vendored
Normal file
44
inc/vendor/pacificsec/cpe/src/Common/LogicalValue.php
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace PacificSec\CPE\Common;
|
||||
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* This class represents a Logical Value. It is based on Java version
|
||||
* implemented by JKRAUNELIS <jkraunelis@mitre.org>.
|
||||
*
|
||||
* @see <a href="http://cpe.mitre.org">cpe.mitre.org</a> for more information.
|
||||
* @author Antonio Franco
|
||||
* @email antonio.franco@pacificsec.com
|
||||
*/
|
||||
class LogicalValue {
|
||||
|
||||
private $any = false;
|
||||
private $na = false;
|
||||
|
||||
// Object must be constructed with the string "ANY" or "NA".
|
||||
public function __construct($type) {
|
||||
if ($type == "ANY") {
|
||||
$this->any = true;
|
||||
} else if ($type == "NA") {
|
||||
$this->na = true;
|
||||
} else {
|
||||
throw new Exception("LogicalValue must be ANY or NA");
|
||||
}
|
||||
}
|
||||
|
||||
public function isANY(){
|
||||
return $this->any;
|
||||
}
|
||||
|
||||
public function isNA(){
|
||||
return $this->na;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
if ($this->any){
|
||||
return "ANY";
|
||||
}
|
||||
return "NA";
|
||||
}
|
||||
}
|
166
inc/vendor/pacificsec/cpe/src/Common/Utilities.php
vendored
Normal file
166
inc/vendor/pacificsec/cpe/src/Common/Utilities.php
vendored
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
namespace PacificSec\CPE\Common;
|
||||
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* A collection of utility functions for use with the matching and
|
||||
* naming namespaces. It is based on Java version implemented by
|
||||
* Joshua Kraunelis <jkraunelis@mitre.org>.
|
||||
*
|
||||
* @see <a href="http://cpe.mitre.org">cpe.mitre.org</a> for more information.
|
||||
* @author Antonio Franco
|
||||
* @email antonio.franco@pacificsec.com
|
||||
*/
|
||||
class Utilities {
|
||||
|
||||
/**
|
||||
* Searches string for special characters * and ?
|
||||
* @param string $string to be searched
|
||||
* @return bool true if string contains wildcard, false otherwise
|
||||
*/
|
||||
public static function containsWildcards($string) {
|
||||
if (strpos($string, "*") !== false || strpos($string, "?") !== false) {
|
||||
if (!(strpos($string, "\\") !== false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given number is even or not
|
||||
* @param int $num number to check
|
||||
* @return bool true if number is even, false if not
|
||||
*/
|
||||
public static function isEvenNumber($num) {
|
||||
return (is_int($num) && $num % 2 == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of escape characters in the string beginning and ending
|
||||
* at the given indices
|
||||
* @param string $str string to search
|
||||
* @param int $start beginning index
|
||||
* @param int $end ending index
|
||||
* @return number of escape characters in string
|
||||
* @todo fix the use of $str. The Java version is also not using this variable.
|
||||
*/
|
||||
public static function countEscapeCharacters($str, $start, $end) {
|
||||
$result = 0;
|
||||
$active = false;
|
||||
$i = 0;
|
||||
while ($i < $end) {
|
||||
if ($active && ($i >= $start)) {
|
||||
$result = $result + 1;
|
||||
}
|
||||
$i = $i + 1;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches a string for the first unescaped colon and returns the index of
|
||||
* that colon
|
||||
* @param string $str string to search
|
||||
* @return int index of first unescaped colon, or 0 if not found
|
||||
*/
|
||||
public static function getUnescapedColonIndex($str) {
|
||||
$found = false;
|
||||
$colon_idx = 0;
|
||||
$start_idx = 0;
|
||||
// Find the first non-escaped colon.
|
||||
while (!$found) {
|
||||
$colon_idx = strpos($str, ":", $start_idx + 1);
|
||||
// If no colon is found, return 0.
|
||||
if ($colon_idx === false) {
|
||||
return 0;
|
||||
}
|
||||
// Peek at character before colon.
|
||||
if (substr($str, $colon_idx-1, 1) == "\\") {
|
||||
// If colon is escaped, keep looking.
|
||||
$start_idx = $colon_idx;
|
||||
} else {
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
return $colon_idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the string contains only
|
||||
* alphanumeric characters or the underscore character,
|
||||
* false otherwise.
|
||||
* @param string $c the string in question
|
||||
* @return bool true if $c is alphanumeric or underscore, false if not
|
||||
*/
|
||||
public static function isAlphanum($c) {
|
||||
return (preg_match("/^[a-zA-Z0-9\_]+$/", $c) ? true : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is not part of the reference implementation pseudo code
|
||||
* found in the CPE 2.3 specification. It enforces two rules in the
|
||||
* specification:
|
||||
* URI must start with the characters "cpe:/"
|
||||
* A URI may not contain more than 7 components
|
||||
* If either rule is violated, a Exception is thrown.
|
||||
* @param $in string with URI to be validated
|
||||
*/
|
||||
public static function validateURI($in) {
|
||||
// make sure uri starts with cpe:/
|
||||
if (strpos(strtolower($in), "cpe:/") !== 0) {
|
||||
throw new Exception("Error: URI must start with 'cpe:/'. Given: " . $in, 0);
|
||||
}
|
||||
// make sure uri doesn't contain more than 7 colons
|
||||
$count = sizeof(explode(":", $in));
|
||||
if ($count > 8) {
|
||||
throw new Exception("Error parsing URI. Found " . ($count - 8) . " extra components in: " . $in, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is not part of the reference implementation pseudo code
|
||||
* found in the CPE 2.3 specification. It enforces three rules found in the
|
||||
* specification:
|
||||
* Formatted string must start with the characters "cpe:2.3:"
|
||||
* A formatted string must contain 11 components
|
||||
* A formatted string must not contain empty components
|
||||
* If any rule is violated, a ParseException is thrown.
|
||||
* @param $in string with FS to be validated
|
||||
*/
|
||||
public static function validateFS($in) {
|
||||
if (strpos(strtolower($in), "cpe:2.3:") !== 0) {
|
||||
throw new Exception("Error: Formatted String must start with \"cpe:2.3\". Given: " . $in, 0);
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
for ($i = 0; $i != strlen($in); $i++){
|
||||
if (substr($in, $i, 1) == ":"){
|
||||
if (substr($in, $i - 1, 1) != "\\"){
|
||||
$count++;
|
||||
}
|
||||
if (($i+1) < strlen($in) && substr($in, $i+1, 1) == ":"){
|
||||
throw new Exception("Error parsing formatted string. Found empty component", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($count > 12){
|
||||
$extra = $count - 12;
|
||||
$s = "Error parsing formatted string. Found " . $extra . " extra component";
|
||||
if ($extra > 1){
|
||||
$s = $s . "s";
|
||||
}
|
||||
$s = $s . " in: " . $in;
|
||||
throw new Exception($s, 0);
|
||||
}
|
||||
if ($count < 12){
|
||||
$missing = 12 - $count;
|
||||
$s = "Error parsing formatted string. Missing " . $missing . " component";
|
||||
if ($missing > 1){
|
||||
$s = $s . "s";
|
||||
}
|
||||
throw new Exception($s, 0);
|
||||
}
|
||||
}
|
||||
}
|
210
inc/vendor/pacificsec/cpe/src/Common/WellFormedName.php
vendored
Normal file
210
inc/vendor/pacificsec/cpe/src/Common/WellFormedName.php
vendored
Normal file
@ -0,0 +1,210 @@
|
||||
<?php
|
||||
namespace PacificSec\CPE\Common;
|
||||
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* The WellFormedName class represents a Well Formed Name, as defined
|
||||
* in the CPE Specification version 2.3. It is based on Java version
|
||||
* implemented by jkraunelis <jkraunelis@mitre.org>.
|
||||
*
|
||||
* @see <a href="http://cpe.mitre.org">cpe.mitre.org</a> for details.
|
||||
* @author Antonio Franco
|
||||
* @email antonio.franco@pacificsec.com
|
||||
*/
|
||||
class WellFormedName {
|
||||
|
||||
// Underlying wfn representation.
|
||||
private $wfn = null;
|
||||
// All permissible WFN attributes as defined by specification.
|
||||
private $attributes = array("part", "vendor", "product", "version",
|
||||
"update", "edition", "language", "sw_edition", "target_sw",
|
||||
"target_hw", "other");
|
||||
|
||||
/**
|
||||
* Constructs a new WellFormedName object, setting each component to the
|
||||
* given parameter value. If a parameter is null, the component is set to
|
||||
* the default value "ANY".
|
||||
* @param $part string representing the part component
|
||||
* @param $vendor string representing the vendor component
|
||||
* @param $product string representing the product component
|
||||
* @param $version string representing the version component
|
||||
* @param $update string representing the update component
|
||||
* @param $edition string representing the edition component
|
||||
* @param $language string representing the language component
|
||||
* @param $sw_edition string representing the sw_edition component
|
||||
* @param $target_sw string representing the target_sw component
|
||||
* @param $target_hw string representing the target_hw component
|
||||
* @param $other string representing the other component
|
||||
*/
|
||||
public function __construct($part = null, $vendor = null, $product = null, $version = null,
|
||||
$update = null, $edition = null, $language = null, $sw_edition = null, $target_sw = null,
|
||||
$target_hw = null, $other = null) {
|
||||
|
||||
$this->wfn = array();
|
||||
|
||||
// Constructs a new WellFormedName object, with all components set to the default value "ANY".
|
||||
if ($part === null && $vendor === null && $product === null && $version === null &&
|
||||
$update === null && $edition === null && $language === null && $sw_edition === null && $target_sw === null &&
|
||||
$target_hw === null && $other === null){
|
||||
foreach ($this->attributes as $a){
|
||||
if ($a != "part"){
|
||||
$this->set($a, new LogicalValue("ANY"));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set("part", $part);
|
||||
$this->set("vendor", $vendor);
|
||||
$this->set("product", $product);
|
||||
$this->set("version", $version);
|
||||
$this->set("update", $update);
|
||||
$this->set("edition", $edition);
|
||||
$this->set("language", $language);
|
||||
$this->set("sw_edition", $sw_edition);
|
||||
$this->set("target_sw", $target_sw);
|
||||
$this->set("target_hw", $target_hw);
|
||||
$this->set("other", $other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $attribute string representing the component value to get
|
||||
* @return string the string value of the given component, or default value "ANY"
|
||||
* if the component does not exist
|
||||
*/
|
||||
public function get($attribute){
|
||||
if (array_key_exists($attribute, $this->wfn))
|
||||
return $this->wfn[$attribute];
|
||||
else
|
||||
return new LogicalValue("ANY");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given attribute to value, if the attribute is in the list of
|
||||
* permissible components
|
||||
* @param $attribute string representing the component to set
|
||||
* @param $value object or string representing the value of the given component
|
||||
*/
|
||||
public final function set($attribute, $value){
|
||||
// Iterate over permissible attributes.
|
||||
foreach ($this->attributes as $a){
|
||||
// If the argument is a valid attribute, set that attribute's value.
|
||||
if ($attribute == $a) {
|
||||
// check to see if we're setting a LogicalValue ANY or NA
|
||||
if ($value instanceof LogicalValue){
|
||||
// don't allow logical values in part component
|
||||
if ($attribute == "part"){
|
||||
var_dump($value); echo "<br>\n";
|
||||
var_dump($a); echo "<br>\n";
|
||||
var_dump($attribute); echo "<br>\n";
|
||||
throw new Exception("Error! part component cannot be a logical value");
|
||||
}
|
||||
// put the Object in the ht and break
|
||||
$this->wfn[$attribute] = $value;
|
||||
break;
|
||||
}
|
||||
if ($value == null || $value == ""){
|
||||
// if value is null or blank, set attribute to default logical ANY
|
||||
$this->wfn[$attribute] = new LogicalValue("ANY");
|
||||
break;
|
||||
}
|
||||
$svalue = $value;
|
||||
// Reg exs
|
||||
// check for printable characters - no control characters
|
||||
if (!preg_match("/^[[:print:]]*$/", $svalue)){
|
||||
throw new Exception("Error! encountered non printable character in: " . $svalue, 0);
|
||||
}
|
||||
// svalue has whitespace
|
||||
if (preg_match("/^.*\\s+.*$/", $svalue)){
|
||||
throw new Exception("Error! component cannot contain whitespace: " . $svalue, 0);
|
||||
}
|
||||
// svalue has more than one unquoted star
|
||||
if (preg_match("/^\\*{2,}.*$/", $svalue) || preg_match("/^.*\\*{2,}$/", $svalue)){
|
||||
throw new Exception("Error! component cannot contain more than one * in sequence: " . $svalue, 0);
|
||||
}
|
||||
// svalue has unquoted punctuation embedded
|
||||
if (preg_match("/^.*(?<!\\\\)[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\+\\,\\.\\/\\:\\;\\<\\=\\>\\@\\[\\]\\^\\`\\{\\|\\}\\~\\-].*$/", $svalue)) {
|
||||
throw new Exception("Error! component cannot contain unquoted punctuation: " . $svalue, 0);
|
||||
}
|
||||
// svalue has an unquoted *
|
||||
if (preg_match("/^.+(?<!\\\\)[\\*].+$/", $svalue)) {
|
||||
throw new Exception("Error! component cannot contain embedded *: " . $svalue, 0);
|
||||
}
|
||||
// svalue has embedded unquoted ?
|
||||
// this will catch a single unquoted ?, so make sure we deal with that
|
||||
if (strpos($svalue, "?") !== false) {
|
||||
if ($svalue == "?") {
|
||||
// single ? is valid
|
||||
$this->wfn[$attribute] = $svalue;
|
||||
break;
|
||||
}
|
||||
// remove leading and trailing ?s
|
||||
$v = $svalue;
|
||||
while (strpos($v, "?") === 0) {
|
||||
// remove all leading ?'s
|
||||
$v = substr($v, 1);
|
||||
}
|
||||
$v = strrev($v);
|
||||
while (strpos($v, "?") === 0) {
|
||||
// remove all trailing ?'s (string has been reversed)
|
||||
$v = substr($v, 1);
|
||||
}
|
||||
// back to normal
|
||||
$v = strrev($v);
|
||||
// after leading and trailing ?s are removed, check if value
|
||||
// contains unquoted ?s
|
||||
if (preg_match("/^.+(?<!\\\\)[\\?].+$/", $v)) {
|
||||
throw new Exception("Error! component cannot contain embedded ?: " . $svalue, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// single asterisk is not allowed
|
||||
if ($svalue == "*") {
|
||||
throw new Exception("Error! component cannot be a single *: " . $svalue, 0);
|
||||
}
|
||||
// quoted hyphen not allowed by itself
|
||||
if ($svalue == "-") {
|
||||
throw new Exception("Error! component cannot be quoted hyphen: " . $svalue, 0);
|
||||
}
|
||||
// part must be a, o, or h
|
||||
if ($attribute == "part") {
|
||||
if ($svalue != "a" && $svalue != "o" && $svalue != "h") {
|
||||
throw new Exception("Error! part component must be one of the following: 'a', 'o', 'h': " . $svalue, 0);
|
||||
}
|
||||
}
|
||||
// should be good to go
|
||||
$this->wfn[$attribute] = $svalue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string representation of the WellFormedName
|
||||
*/
|
||||
public function __toString() {
|
||||
$str = "wfn:[";
|
||||
foreach ($this->attributes as $attr) {
|
||||
$str = $str . $attr;
|
||||
$str = $str . "=";
|
||||
|
||||
$o = $this->wfn[$attr];
|
||||
if ($o instanceof LogicalValue) {
|
||||
$str = $str . $o;
|
||||
$str = $str . ", ";
|
||||
} else {
|
||||
$str = $str . "\"";
|
||||
$str = $str . $o;
|
||||
$str = $str . "\", ";
|
||||
}
|
||||
}
|
||||
$str = substr($str, 0, strlen($str)-1);
|
||||
$str = substr($str, 0, strlen($str)-1);
|
||||
$str = $str . "]";
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user