📖
日々の記録 2025-05-31
環境を思い出す
~/Documents/work にリポジトリを clone していた
やりたいこと
web ブラウザで表示するダッシュボードのひな形を検証したい。
作業場所
sandbox というリポジトリがあったので、そこに作る
sandbox/web/sidemenu というフォルダを作成。
最低限の確認できる環境の作成
簡易 web サーバーを起動して http://localhost:8080/ とかでアクセスできれば OK とする。
PowerShell で WSL で 簡易 web サーバーを起動するスクリプトを作成
param (
[string]$port = "8080"
)
# WSL で簡易的な web サーバーを起動
$wslCommand = "wsl python3 -m http.server $port"
# WSL のコマンドを実行
Invoke-Expression $wslCommand
実行したらエラー
> ./run_daemon.ps1
./run_daemon.ps1 : このシステムではスクリプトの実行が無効になっているため、ファイル ..... \work\sandbox\web\sidemenu\run_daemon.ps1 を読み込むことができません。詳細については、「about_Execution_Policies」(https://go.microsoft.com/fwlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ ./run_daemon.ps1
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : セキュリティ エラー: (: ) []、PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
スクリプトに著名が必要みたい
著名しようとしたらエラー
> Set-AuthenticodeSignature -FilePath ".....\work\sandbox\web\sidemenu\run_daemon.ps1" -Certificate (Get-ChildItem Cert:\CurrentUser\My | Select-Object -First 1)
Set-AuthenticodeSignature : コードに署名できません。指定された証明書は、コードの署名に適していません。
発生場所 行:1 文字:1
+ Set-AuthenticodeSignature -FilePath "C:\users\..... ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-AuthenticodeSignature]、PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SetAuthenticodeSignatureCommand
コードを著名する権限がないらしい
コードを著名する権限を追加 (これではうまくいかない)
テスト用になるのかな ?
管理者権限で powershell を起動
New-SelfSignedCertificate -Type CodeSigningCert -Subject "CN=My Code Signing Certificate" -CertStoreLocation Cert:\CurrentUser\My
$cert = Get-ChildItem Cert:\CurrentUser\My | Where-Object {$_.Subject -eq "CN=My Code Signing Certificate"}
Set-AuthenticodeSignature -FilePath "..... \.....\work\sandbox\web\sidemenu\run_daemon.ps1" -Certificate $cert
調査
Get-ChildItem Cert:\CurrentUser\My | Where-Object {$_.Subject -eq "CN=014979b1-c69b-4d98-907b-6bc642b723e2"}
Get-ChildItem Cert:\CurrentUser\My | Where-Object {$_.Subject -eq "CN=My Code Signing Certificate"}
> Get-ChildItem Cert:\CurrentUser\My
PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
Thumbprint Subject
---------- -------
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CN=My Code Signing Certificate
:
> Get-ChildItem Cert:\CurrentUser\My | Format-List
Subject : CN=My Code Signing Certificate
Issuer : CN=My Code Signing Certificate
Thumbprint : ......
:
追加した著名の Subject がいけてないのかな ?
> get-executionpolicy
Restricted
Restricted (スクリプトの実行禁止) だった・・・・
> get-executionpolicy -list
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
何も設定されていないデフォルトの状態。
Discussion