Created
September 29, 2021 02:09
-
-
Save kawakami-o3/56881a6f3613867e63765579002a0af5 to your computer and use it in GitHub Desktop.
Jenkins credentials.xml decryptor
This file contains hidden or 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
import static hudson.util.Secret.decrypt | |
void printEntry(credential, attr) { | |
def text = credential."${attr.toLowerCase()}".text() | |
println("${attr}: ${text}") | |
} | |
def text = new File('/var/lib/jenkins/credentials.xml').text | |
def list = new XmlParser().parseText(text).domainCredentialsMap.entry.'java.util.concurrent.CopyOnWriteArrayList'.'*' | |
for (i in list) { | |
switch (i.name()) { | |
case 'com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey': | |
println("[SSH Private Key]") | |
printEntry(i, 'Scope') | |
printEntry(i, 'ID') | |
printEntry(i, 'Description') | |
printEntry(i, 'Username') // TODO encypted case | |
println('Private key:') | |
println(decrypt(i.privateKeySource.privateKey.text())) | |
break | |
case 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl': | |
println("[Username & Password]") | |
printEntry(i, 'Scope') | |
printEntry(i, 'ID') | |
printEntry(i, 'Description') | |
printEntry(i, 'Username') | |
println("Password: ${decrypt(i.password.text())}") | |
break | |
case 'org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl': | |
println("[Secret text]") | |
printEntry(i, 'Scope') | |
printEntry(i, 'ID') | |
printEntry(i, 'Description') | |
println("Secret: ${decrypt(i.secret.text())}") | |
break | |
default: | |
println("[Not implemented yet]") | |
println(i) | |
} | |
println() | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment