Created
February 14, 2016 05:43
-
-
Save paranoidjk/73284de7a82da4ed6398 to your computer and use it in GitHub Desktop.
自动更新VPN密码到Keychain
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
<?php | |
error_reporting(0); | |
$key = strtoupper($argv[1]); | |
$lut = array( | |
'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, | |
'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, | |
'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, | |
'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, | |
'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, | |
'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, | |
'Y' => 24, 'Z' => 25, '2' => 26, '3' => 27, | |
'4' => 28, '5' => 29, '6' => 30, '7' => 31, | |
); | |
$binary = ''; | |
for($i = $j = $k = 0; $i < strlen($key); $i++) { | |
$n = $n << 5; | |
$n = $n + $lut[$key[$i]]; | |
$j = $j + 5; | |
if($j >= 8) { | |
$j = $j - 8; | |
$binary .= chr(($n & (0xFF << $j)) >> $j); | |
} | |
} | |
$counter = pack('N*', 0) . pack('N*', floor(microtime(true) / 30)); | |
$hash = hash_hmac('sha1', $counter, $binary, true); | |
$offset = ord($hash[19]) & 0xf; | |
$hash = ( | |
((ord($hash[$offset+0]) & 0x7f) << 24 ) | | |
((ord($hash[$offset+1]) & 0xff) << 16 ) | | |
((ord($hash[$offset+2]) & 0xff) << 8 ) | | |
(ord($hash[$offset+3]) & 0xff) | |
) % pow(10, 6); | |
$otp = str_pad($hash, 6, '0', STR_PAD_LEFT); | |
echo $otp; |
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
#!/bin/bash | |
SYSPASS="" # 电脑密码 | |
MGJUSER="" # 花名拼音 | |
MGJPASS="" # 内网密码 | |
GGACODE="" # Google Auto Code | |
GGAPASS=`php ga.php $GGACODE` | |
NEWPASS=$MGJPASS$GGAPASS | |
SERVICE="Tunnelblick-Auth-online" | |
KEYCHAIN="/Users/$USER/Library/Keychains/login.keychain" | |
security unlock-keychain -p "$SYSPASS" "$KEYCHAIN" | |
security add-generic-password -a "username" -s "$SERVICE" -w "$MGJUSER" -U "$KEYCHAIN" | |
security add-generic-password -a "password" -s "$SERVICE" -w "$NEWPASS" -U "$KEYCHAIN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment