-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d21069
commit 9fcd2de
Showing
5 changed files
with
54 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export { decode, encode } from "https://deno.land/[email protected]/encoding/utf8.ts"; | ||
export { format as byteFormat } from "https://deno.land/x/[email protected]/mod.ts"; | ||
export { replaceParams } from "https://deno.land/x/[email protected]/util.ts"; | ||
export { Hash } from "https://deno.land/x/[email protected]/mod.ts"; | ||
export { sha256 } from "https://denopkg.com/chiefbiiko/[email protected]/mod.ts"; | ||
|
||
export { | ||
deferred, | ||
Deferred, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { encode, Hash, sha256 } from "../deps.ts"; | ||
|
||
function xor(a: Uint8Array, b: Uint8Array): Uint8Array { | ||
return a.map((byte, index) => { | ||
return byte ^ b[index]; | ||
}); | ||
} | ||
|
||
function mysqlNativePassword(password: string, seed: Uint8Array): Uint8Array { | ||
const hash = new Hash("sha1"); | ||
const pwd1 = hash.digest(encode(password)).data; | ||
const pwd2 = hash.digest(pwd1).data; | ||
|
||
let seedAndPwd2 = new Uint8Array(seed.length + pwd2.length); | ||
seedAndPwd2.set(seed); | ||
seedAndPwd2.set(pwd2, seed.length); | ||
seedAndPwd2 = hash.digest(seedAndPwd2).data; | ||
|
||
return xor(seedAndPwd2, pwd1); | ||
} | ||
|
||
function cachingSha2Password(password: string, seed: Uint8Array): Uint8Array { | ||
const stage1 = sha256(password, "utf8") as Uint8Array; | ||
const stage2 = sha256(stage1) as Uint8Array; | ||
const stage3 = sha256(Uint8Array.from([...stage2, ...seed])) as Uint8Array; | ||
return xor(stage1, stage3); | ||
} | ||
|
||
export default function auth( | ||
authPluginName: string, | ||
password: string, | ||
seed: Uint8Array | ||
) { | ||
switch (authPluginName) { | ||
case "mysql_native_password": | ||
return mysqlNativePassword(password, seed); | ||
|
||
case "caching_sha2_password": | ||
// TODO | ||
// return cachingSha2Password(password, seed); | ||
|
||
default: | ||
throw new Error("Not supported"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters