Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvanes committed Jan 14, 2025
1 parent cd767c6 commit 7d0142b
Show file tree
Hide file tree
Showing 21 changed files with 346 additions and 88 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: mrvanes, michellewilliamsgeant
Tags: inacademia, student validation, student discount, student, discount
Requires at least: 6.0
Tested up to: 6.6
Stable tag: 1.0
Tested up to: 6.7
Stable tag: 1.0.1
Requires PHP: 8.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -60,6 +60,11 @@ Copyright (c) 2023-2024 GÉANT Association on behalf of the GN5-1 project
[https://github.com/InAcademia/student-discount-for-woocommerce/blob/main/COPYRIGHT](https://github.com/InAcademia/student-discount-for-woocommerce/blob/main/COPYRIGHT)

== Changelog ==
= 1.0.1 =
- Provides human-friendly error descriptions when cart discount cannot be applied
- Tested against WordPress 6.7.1
- Tested against WooCommerce 9.5.2

= 1.0 =
* First release

Expand All @@ -82,8 +87,8 @@ Dependency paragonie/random_compat-v9.99.100
- Licensed: MIT
- Copyright 2015 Paragon Initiative Enterprises

Dependency phpseclib-3.0.42
- Version: 3.0.42
Dependency phpseclib-3.0.43
- Version: 3.0.43
- URL: [https://github.com/phpseclib](https://github.com/phpseclib)
- Licensed: MIT
- Copyright 2011-2019 TerraFrost and other contributors
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
*** Student Discount for WooCommerce Changelog ***
2025-01-14 - 1.0.1
* Provides human-friendly error descriptions when cart discount cannot be applied
* Tested against WordPress 6.7.1
* Tested against WooCommerce 9.5.2

2024-08-14 - version 1.0
* First release.
16 changes: 15 additions & 1 deletion inacademia.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function inacademia_validate() {
$validated = false;

try {
// throw new ErrorException('error');
if ( ! $claims ) {
$oidc->authenticate();
$claims = $oidc->getVerifiedClaims();
Expand All @@ -106,7 +107,7 @@ function inacademia_validate() {
}
}
} catch ( Exception $e ) {
$_SESSION['inacademia_error'] = $e->getMessage();
$_SESSION['inacademia_error'] = tr($e->getMessage());
error_log( json_encode( $e->getMessage(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
}

Expand All @@ -118,3 +119,16 @@ function inacademia_validate() {
header( 'Location: ' . $location, true );
}
}

/*
* Translate known error messages
*/
function tr($s) {
$translations = [
'Error: access_denied Description: no affiliation available for this user' => 'We were unable to process your student validation because the SAML response from your institution does not confirm your student affiliation. As a result, the cart discount cannot be applied.',
'Error: access_denied Description: affiliation does not match requested validation' => 'We were unable to process your student validation because the SAML response from your institution does not confirm your student affiliation. As a result, the cart discount cannot be applied.',
'Error: access_denied Description: authentication failed' => 'We were unable to process your student validation because the SAML response from your institution does not confirm your student affiliation. As a result, the cart discount cannot be applied.',
];

return $translations[$s] ?? $s;
}
14 changes: 7 additions & 7 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@
},
{
"name": "phpseclib/phpseclib",
"version": "3.0.42",
"version_normalized": "3.0.42.0",
"version": "3.0.43",
"version_normalized": "3.0.43.0",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "db92f1b1987b12b13f248fe76c3a52cadb67bb98"
"reference": "709ec107af3cb2f385b9617be72af8cf62441d02"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/db92f1b1987b12b13f248fe76c3a52cadb67bb98",
"reference": "db92f1b1987b12b13f248fe76c3a52cadb67bb98",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/709ec107af3cb2f385b9617be72af8cf62441d02",
"reference": "709ec107af3cb2f385b9617be72af8cf62441d02",
"shasum": ""
},
"require": {
Expand All @@ -198,7 +198,7 @@
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"time": "2024-09-16T03:06:04+00:00",
"time": "2024-12-14T21:12:59+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
Expand Down Expand Up @@ -263,7 +263,7 @@
],
"support": {
"issues": "https://github.com/phpseclib/phpseclib/issues",
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.42"
"source": "https://github.com/phpseclib/phpseclib/tree/3.0.43"
},
"funding": [
{
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'martin/wc-inacademia',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'a08a2b1e419a2b0d1ddbcd3cd756fc4c53dd9327',
'reference' => 'ead678205321b364310dc19adab60f16318941c1',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -22,7 +22,7 @@
'martin/wc-inacademia' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => 'a08a2b1e419a2b0d1ddbcd3cd756fc4c53dd9327',
'reference' => 'ead678205321b364310dc19adab60f16318941c1',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -47,9 +47,9 @@
'dev_requirement' => false,
),
'phpseclib/phpseclib' => array(
'pretty_version' => '3.0.42',
'version' => '3.0.42.0',
'reference' => 'db92f1b1987b12b13f248fe76c3a52cadb67bb98',
'pretty_version' => '3.0.43',
'version' => '3.0.43.0',
'reference' => '709ec107af3cb2f385b9617be72af8cf62441d02',
'type' => 'library',
'install_path' => __DIR__ . '/../phpseclib/phpseclib',
'aliases' => array(),
Expand Down
3 changes: 2 additions & 1 deletion vendor/phpseclib/phpseclib/BACKERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ phpseclib ongoing development is made possible by [Tidelift](https://tidelift.co
- [cjhaas](https://github.com/cjhaas)
- [istiak-tridip](https://github.com/istiak-tridip)
- [Anna Filina](https://github.com/afilina)
- [blakemckeeby](https://github.com/blakemckeeby)
- [blakemckeeby](https://github.com/blakemckeeby)
- [ssddanbrown](https://github.com/ssddanbrown)
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ abstract class PKCS8 extends PKCS
*/
private static $oidsLoaded = false;

/**
* Binary key flag
*
* @var bool
*/
private static $binary = false;

/**
* Sets the default encryption algorithm
*
Expand Down Expand Up @@ -513,6 +520,18 @@ protected static function load($key, $password = '')
throw new \RuntimeException('Unable to parse using either OneAsymmetricKey or PublicKeyInfo ASN1 maps');
}

/**
* Toggle between binary (DER) and printable (PEM) keys
*
* Printable keys are what are generated by default.
*
* @param bool $enabled
*/
public static function setBinaryOutput($enabled)
{
self::$binary = $enabled;
}

/**
* Wrap a private key appropriately
*
Expand Down Expand Up @@ -616,11 +635,19 @@ protected static function wrapPrivateKey($key, $attr, $params, $password, $oid =

$key = ASN1::encodeDER($key, Maps\EncryptedPrivateKeyInfo::MAP);

if (isset($options['binary']) ? $options['binary'] : self::$binary) {
return $key;
}

return "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END ENCRYPTED PRIVATE KEY-----";
}

if (isset($options['binary']) ? $options['binary'] : self::$binary) {
return $key;
}

return "-----BEGIN PRIVATE KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END PRIVATE KEY-----";
Expand All @@ -634,7 +661,7 @@ protected static function wrapPrivateKey($key, $attr, $params, $password, $oid =
* @param string $oid
* @return string
*/
protected static function wrapPublicKey($key, $params, $oid = null)
protected static function wrapPublicKey($key, $params, $oid = null, array $options = [])
{
self::initialize_static_variables();

Expand All @@ -651,6 +678,10 @@ protected static function wrapPublicKey($key, $params, $oid = null)

$key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP);

if (isset($options['binary']) ? $options['binary'] : self::$binary) {
return $key;
}

return "-----BEGIN PUBLIC KEY-----\r\n" .
chunk_split(Strings::base64_encode($key), 64) .
"-----END PUBLIC KEY-----";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ public static function savePublicKey(BigInteger $prime, BigInteger $base, BigInt
$params = ASN1::encodeDER($params, Maps\DHParameter::MAP);
$params = new ASN1\Element($params);
$key = ASN1::encodeDER($publicKey, ['type' => ASN1::TYPE_INTEGER]);
return self::wrapPublicKey($key, $params);
return self::wrapPublicKey($key, $params, null, $options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g
$params = ASN1::encodeDER($params, Maps\DSAParams::MAP);
$params = new ASN1\Element($params);
$key = ASN1::encodeDER($y, Maps\DSAPublicKey::MAP);
return self::wrapPublicKey($key, $params);
return self::wrapPublicKey($key, $params, null, $options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private function doubleAndAddPoint(array $p, array $q, PrimeInteger $x1)
public function multiplyPoint(array $p, BigInteger $d)
{
$p1 = [$this->one, $this->zero];
$alreadyInternal = isset($x[1]);
$alreadyInternal = isset($p[1]);
$p2 = $this->convertToInternal($p);
$x = $p[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ public static function savePublicKey(BaseCurve $curve, array $publicKey, array $
return self::wrapPublicKey(
$curve->encodePoint($publicKey),
null,
$curve instanceof Ed25519 ? 'id-Ed25519' : 'id-Ed448'
$curve instanceof Ed25519 ? 'id-Ed25519' : 'id-Ed448',
$options
);
}

$params = new ASN1\Element(self::encodeParameters($curve, false, $options));

$key = "\4" . $publicKey[0]->toBytes() . $publicKey[1]->toBytes();

return self::wrapPublicKey($key, $params, 'id-ecPublicKey');
return self::wrapPublicKey($key, $params, 'id-ecPublicKey', $options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ public static function savePublicKey(BigInteger $n, BigInteger $e, array $option
{
$key = PKCS1::savePublicKey($n, $e);
$key = ASN1::extractBER($key);
return self::wrapPublicKey($key, null);
return self::wrapPublicKey($key, null, null, $options);
}
}
4 changes: 3 additions & 1 deletion vendor/phpseclib/phpseclib/phpseclib/Crypt/Salsa20.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private function crypt($text, $mode)
foreach ($blocks as &$block) {
$block ^= static::salsa20($this->p1 . pack('V', $i++) . $this->p2);
}

unset($block);
return implode('', $blocks);
}

Expand Down Expand Up @@ -366,6 +366,7 @@ private function crypt($text, $mode)
foreach ($blocks as &$block) {
$block ^= static::salsa20($this->p1 . pack('V', $buffer['counter']++) . $this->p2);
}
unset($block);
}
$encrypted = implode('', $blocks);
$temp = static::salsa20($this->p1 . pack('V', $buffer['counter']++) . $this->p2);
Expand All @@ -388,6 +389,7 @@ private function crypt($text, $mode)
foreach ($blocks as &$block) {
$block ^= static::salsa20($this->p1 . pack('V', $buffer['counter']++) . $this->p2);
}
unset($block);
$ciphertext .= implode('', $blocks);
}
}
Expand Down
Loading

0 comments on commit 7d0142b

Please sign in to comment.