Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/#35816 mi2 mysql keyword error #25

Merged
merged 23 commits into from
Nov 9, 2023
30 changes: 15 additions & 15 deletions classes/cryptography/mumie_cryptographic_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,26 @@ class mumie_cryptographic_key {
/**
* @var string
*/
private string $key;
private string $keyvalue;

/**
* Create a new instance
* @param string $name
* @param string $key
* @param string $keyvalue
*/
public function __construct(string $name, string $key) {
public function __construct(string $name, string $keyvalue) {
$this->name = $name;
$this->key = $key;
$this->keyvalue = $keyvalue;
}

/**
* Insert a new key into the database
* Insert a new keyvalue into the database
* @return void
* @throws dml_exception
*/
public function create() {
global $DB;
$DB->insert_record(self::MUMIE_CRYPTOGRAPHIC_KEY_TABLE, ["name" => $this->name, "key" => $this->key]);
$DB->insert_record(self::MUMIE_CRYPTOGRAPHIC_KEY_TABLE, ["name" => $this->name, "keyvalue" => $this->keyvalue]);
}

/**
Expand All @@ -76,7 +76,7 @@ public function create() {
*/
public function update() {
global $DB;
$DB->update_record(self::MUMIE_CRYPTOGRAPHIC_KEY_TABLE, ["name" => $this->name, "key" => $this->key, "id" => $this->id]);
$DB->update_record(self::MUMIE_CRYPTOGRAPHIC_KEY_TABLE, ["name" => $this->name, "keyvalue" => $this->keyvalue, "id" => $this->id]);
}

/**
Expand All @@ -100,7 +100,7 @@ private static function from_record($record) : ?mumie_cryptographic_key {
if (!$record) {
return null;
}
$cryptokey = new mumie_cryptographic_key($record->name, $record->key);
$cryptokey = new mumie_cryptographic_key($record->name, $record->keyvalue);
$cryptokey->set_id($record->id);
return $cryptokey;
}
Expand Down Expand Up @@ -138,18 +138,18 @@ public function set_name(string $name) : void {
}

/**
* Get the key
* Get the keyvalue
* @return string
*/
public function get_key() : string {
return $this->key;
public function get_keyvalue() : string {
return $this->keyvalue;
}

/**
* Set a new key
* @param string $key
* Set a new keyvalue
* @param string $keyvalue
*/
public function set_key(string $key) : void {
$this->key = $key;
public function set_keyvalue(string $keyvalue) : void {
$this->keyvalue = $keyvalue;
}
}
4 changes: 2 additions & 2 deletions classes/cryptography/mumie_cryptography_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static function ensure_key_pair_exist() : void {
*/
public static function sign_data(string ...$data) : string {
self::ensure_key_pair_exist();
openssl_sign(implode("", $data), $signeddata, self::get_private_key()->get_key(), OPENSSL_ALGO_SHA512);
openssl_sign(implode("", $data), $signeddata, self::get_private_key()->get_keyvalue(), OPENSSL_ALGO_SHA512);
return base64_encode($signeddata);
}

Expand Down Expand Up @@ -143,7 +143,7 @@ private static function upsert_private_key(string $key) : void {
private static function upsert_key(string $name, string $key) : void {
$cryptographickey = mumie_cryptographic_key::get_by_name($name);
if (!is_null($cryptographickey)) {
$cryptographickey->set_key($key);
$cryptographickey->set_keyvalue($key);
$cryptographickey->update();
} else {
$cryptographickey = new mumie_cryptographic_key($name, $key);
Expand Down
2 changes: 1 addition & 1 deletion classes/sso/user/mumie_user.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function load() : bool {
* @return string
*/
public function get_sync_id() : string {
return "gsso_" . $this->org . "_" . $this->mumieid;
return "GSSO_" . $this->org . "_" . $this->mumieid;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="name" TYPE="char" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="key" TYPE="text" LENGTH="160" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="keyvalue" TYPE="text" LENGTH="160" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
10 changes: 10 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,15 @@ function xmldb_auth_mumie_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2023062000, 'auth', 'mumie');
}

if ($oldversion < 2023110800) {
$table = new xmldb_table('auth_mumie_cryptographic_key');
$field = new xmldb_field('key');
if ($dbman->field_exists($table, $field)) {
$field->set_attributes(XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
dung238 marked this conversation as resolved.
Show resolved Hide resolved
$dbman->rename_field($table, $field, 'keyvalue');
}
upgrade_plugin_savepoint(true, 2023110800, 'auth', 'mumie');
}

return true;
}
2 changes: 1 addition & 1 deletion publicKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
http_response_code(404);
return;
}
echo $publickey->get_key();
echo $publickey->get_keyvalue();
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023103100;
$plugin->version = 2023110800;
$plugin->component = 'auth_mumie';
$plugin->requires = 2022041900;
$plugin->release = "v1.5.0";
Expand Down
Loading