如何编写 Oracle Wallet 更改脚本?

发布于 2024-10-01 16:34:36 字数 155 浏览 11 评论 0原文

我使用 Oracle 钱包来存储我连接的数据库的密码。我们的密码政策要求我们经常更改密码,因此我想编写更改脚本。我有一个批处理文件,可以自行更改数据库密码,但我也想编写对钱包的更改脚本。问题是调用 mkstore 后必须输入钱包密码,并且密码不能作为参数传递。有没有办法在钱包中编写凭据更改脚本?

I use the Oracle wallet to store passwords for the databases I connect to. Our password policy requires us to change our passwords frequently enough that I would like to script the changes. I have a batch file that can change the database passwords themselves, but I would like to script the changes to the wallet as well. The problem is that a wallet password must be entered after calling mkstore and the password can't be passed as a parameter. Is there a way to script credential changes in the wallet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

记忆で 2024-10-08 16:34:36

通过 echo 获取商店的密码,以便您可以编写脚本。

回声“$passwd”|

回声“钱包密码”| mkstore -wrl 。 -listCredential

这将列出输出,同样所有 mkstore、orapki 的命令都将起作用

Get the passwd for the store thru echo, so you can script it.

echo "$passwd" |

echo "WalletPasswd" | mkstore -wrl . -listCredential

This will list the output,likewise commands for all mkstore, orapki will work

静谧 2024-10-08 16:34:36

这是我想出的一个 Powershell 脚本。要求:

  1. 已安装 PowerShell。
  2. 脚本已启用(Set-ExecutionPolicy RemoteSigned 以管理员身份运行)。
  3. 该脚本位于 c:\oracle\WalletCreator 中。
  4. Windows Automation Snapin for PowerShell 中的 Wasp.dll 位于脚本文件夹中。

钱包将在 c:\oracle\Wallets 中创建。这是脚本。

Import-Module c:\oracle\WalletCreator\WASP.dll

$WalletCreated = 0

cls
Write-Host "                                                           " -foregroundcolor White -backgroundcolor DarkRed
Write-Host "   Warning: This script will delete your current wallet.   " -foregroundcolor White -backgroundcolor DarkRed
Write-Host "                                                           " -foregroundcolor White -backgroundcolor DarkRed

do {
    #Get credentials
    Write-Host " " 
    Write-Host " New Wallet Entry                                          " -foregroundcolor White -backgroundcolor DarkGreen
    Write-Host "    To exit press return without entering anything.        " -foregroundcolor White -backgroundcolor DarkGreen
    $DB = Read-Host "Connection Name"
    if ($DB -eq "") {
       Return
    }
    $Username = Read-Host "       Username"
    if ($Username -eq "") {
       Return
    }
    $Password = Read-Host -AsSecureString "       Password" 

    #Convert from SecureString to String.
    $BasicString = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
    $Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BasicString)
    if ($Password -eq "") {
       Return
    }

    if ($WalletCreated -eq 0) {
        #Create folder in case it doesn't exist.
        md c:\oracle\Wallets -Force | Out-Null

        #Delete any wallet in the folder now.
        del c:\oracle\Wallets\*.* | Out-Null

        #Get GUID for wallet password.
        $WalletPassword = [guid]::NewGuid().toString()
        $WalletPassword = $WalletPassword + "`r"

        #Create Wallet.
        Start-Process -FilePath mkstore -ArgumentList "-wrl c:\oracle\Wallets\ -create"
        Start-Sleep -Milliseconds 500
        Select-Window -ProcessName cmd | Select -First 1 | Send-Keys -keys $WalletPassword
        Start-Sleep -Milliseconds 300
        Select-Window -ProcessName cmd | Select -First 1 | Send-Keys -keys $WalletPassword

        $WalletCreated = 1
        Start-Sleep -Milliseconds 1000
    }

    #Create Credential.
    $CC = "-wrl c:\oracle\Wallets\ -createCredential " + $DB + " " 
    $CC = $CC + $Username + " " + $Password
    Start-Process -FilePath mkstore -ArgumentList $CC
    Start-Sleep -Milliseconds 300
    Select-Window -ProcessName cmd | Select -First 1 | Send-Keys -keys $WalletPassword
    Start-Sleep -Milliseconds 1000
} 
until ($DB -eq "")

Here is a Powershell script I came up with. Requirements:

  1. PowerShell is installed.
  2. Scripting is enabled (Set-ExecutionPolicy RemoteSigned run as administrator).
  3. The script is in c:\oracle\WalletCreator.
  4. Wasp.dll from Windows Automation Snapin for PowerShell is located in the script folder.

The wallet will be created in c:\oracle\Wallets. Here is the script.

Import-Module c:\oracle\WalletCreator\WASP.dll

$WalletCreated = 0

cls
Write-Host "                                                           " -foregroundcolor White -backgroundcolor DarkRed
Write-Host "   Warning: This script will delete your current wallet.   " -foregroundcolor White -backgroundcolor DarkRed
Write-Host "                                                           " -foregroundcolor White -backgroundcolor DarkRed

do {
    #Get credentials
    Write-Host " " 
    Write-Host " New Wallet Entry                                          " -foregroundcolor White -backgroundcolor DarkGreen
    Write-Host "    To exit press return without entering anything.        " -foregroundcolor White -backgroundcolor DarkGreen
    $DB = Read-Host "Connection Name"
    if ($DB -eq "") {
       Return
    }
    $Username = Read-Host "       Username"
    if ($Username -eq "") {
       Return
    }
    $Password = Read-Host -AsSecureString "       Password" 

    #Convert from SecureString to String.
    $BasicString = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
    $Password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BasicString)
    if ($Password -eq "") {
       Return
    }

    if ($WalletCreated -eq 0) {
        #Create folder in case it doesn't exist.
        md c:\oracle\Wallets -Force | Out-Null

        #Delete any wallet in the folder now.
        del c:\oracle\Wallets\*.* | Out-Null

        #Get GUID for wallet password.
        $WalletPassword = [guid]::NewGuid().toString()
        $WalletPassword = $WalletPassword + "`r"

        #Create Wallet.
        Start-Process -FilePath mkstore -ArgumentList "-wrl c:\oracle\Wallets\ -create"
        Start-Sleep -Milliseconds 500
        Select-Window -ProcessName cmd | Select -First 1 | Send-Keys -keys $WalletPassword
        Start-Sleep -Milliseconds 300
        Select-Window -ProcessName cmd | Select -First 1 | Send-Keys -keys $WalletPassword

        $WalletCreated = 1
        Start-Sleep -Milliseconds 1000
    }

    #Create Credential.
    $CC = "-wrl c:\oracle\Wallets\ -createCredential " + $DB + " " 
    $CC = $CC + $Username + " " + $Password
    Start-Process -FilePath mkstore -ArgumentList $CC
    Start-Sleep -Milliseconds 300
    Select-Window -ProcessName cmd | Select -First 1 | Send-Keys -keys $WalletPassword
    Start-Sleep -Milliseconds 1000
} 
until ($DB -eq "")
断念 2024-10-08 16:34:36

至少对于 11g:

orapki wallet change_pwd -wallet {wallet directory}  \
              -oldpwd {old password}   -newpwd  {new password}

我还没有测试密码是否在 ps -fe|grep 可见的进程行中被混淆。

With 11g at least:

orapki wallet change_pwd -wallet {wallet directory}  \
              -oldpwd {old password}   -newpwd  {new password}

I have not tested whether the passwords get obfuscated in the process line visible from a ps -fe|grep.

策马西风 2024-10-08 16:34:36

自动热键解决方案:

; CreateWallet.ahk

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1


Macro1:
Random, WalletPassword, 10000000000, 9999999999999999999999999
WalletPassword := WalletPassword "ExtraCharacters"
InputBox, Username, Username, Please enter your database username, , , , , , , , lriffel
InputBox, DatabasePassword, Database Password, Please enter the database password., HIDE
Run, c:\windows\system32\cmd.exe, c:\
Sleep, 500
Send, md c{:}\oracle\Wallet{enter}
Sleep, 200
Send, cd c{:}\oracle\Wallet{enter}
Sleep, 200
Send, del -s c{:}\oracle\Wallet\*.*{enter}
Sleep, 200
Send, Y{enter}
Sleep, 200
Send, mkstore -wrl c:\oracle\Wallet\ -create{enter}
Sleep, 200
Send, %WalletPassword%{enter}
Sleep, 200
Send, %WalletPassword%{enter}
Sleep, 200
Loop, Read, F:\Programs\CreateWallet\dbs.txt
{
    WinHide, ahk_class ConsoleWindowClass
    Sleep, 333
    Send, mkstore -wrl c:\oracle\Wallet\ -createCredential %A_LoopReadLine% %Username% %DatabasePassword%{enter}
    Send, %WalletPassword%{enter}
    Sleep, 200
    Send, cls{enter}
    Sleep, 200
    WinShow, ahk_class ConsoleWindowClass
    Sleep, 550
}
Send, exit{enter}
MsgBox, 64, Wallet Created, Wallet Created
Return

; This script was created using Pulover's Macro Creator
; www.macrocreator.com

AutoHotKey Solution:

; CreateWallet.ahk

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1


Macro1:
Random, WalletPassword, 10000000000, 9999999999999999999999999
WalletPassword := WalletPassword "ExtraCharacters"
InputBox, Username, Username, Please enter your database username, , , , , , , , lriffel
InputBox, DatabasePassword, Database Password, Please enter the database password., HIDE
Run, c:\windows\system32\cmd.exe, c:\
Sleep, 500
Send, md c{:}\oracle\Wallet{enter}
Sleep, 200
Send, cd c{:}\oracle\Wallet{enter}
Sleep, 200
Send, del -s c{:}\oracle\Wallet\*.*{enter}
Sleep, 200
Send, Y{enter}
Sleep, 200
Send, mkstore -wrl c:\oracle\Wallet\ -create{enter}
Sleep, 200
Send, %WalletPassword%{enter}
Sleep, 200
Send, %WalletPassword%{enter}
Sleep, 200
Loop, Read, F:\Programs\CreateWallet\dbs.txt
{
    WinHide, ahk_class ConsoleWindowClass
    Sleep, 333
    Send, mkstore -wrl c:\oracle\Wallet\ -createCredential %A_LoopReadLine% %Username% %DatabasePassword%{enter}
    Send, %WalletPassword%{enter}
    Sleep, 200
    Send, cls{enter}
    Sleep, 200
    WinShow, ahk_class ConsoleWindowClass
    Sleep, 550
}
Send, exit{enter}
MsgBox, 64, Wallet Created, Wallet Created
Return

; This script was created using Pulover's Macro Creator
; www.macrocreator.com
捎一片雪花 2024-10-08 16:34:36

来自文件的 Windows 管道工作正常。
我将钱包密码放在两行单独的行上,这样它就可以用于创建钱包以及 -createCredential:

set PW=\MySecureFolder\MyWalletPasswordOn2Lines.txt
mkstore -wrl . -create < %PW%

当然,该脚本可以最初提示并创建文件,并在完成后删除该文件。将其放在仅限管理员的文件夹中,以防脚本异常终止。

Windows piping from a file works.
I put the wallet password on 2 separate lines so it works for creating the wallet as well as -createCredential:

set PW=\MySecureFolder\MyWalletPasswordOn2Lines.txt
mkstore -wrl . -create < %PW%

The script could, of course, prompt and create the file initially, and delete the file when done. Put it in an admin-only folder, in case the script terminates abnormally.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文