File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\security\ConfidentialKey.java.html

1 package jenkins.security;
2
3 import hudson.scm.SCM;
4 import hudson.tasks.Builder;
5 import hudson.util.Secret;
6 import jenkins.slaves.JnlpSlaveAgentProtocol;
7
8 import javax.annotation.CheckForNull;
9 import java.io.IOException;
10
11 /**
12 * Confidential information that gets stored as a singleton in Jenkins, mostly some random token value.
13 *
14 * <p>
15 * The actual value is persisted via {@link ConfidentialStore}, but each use case that requires
16 * a secret like this should use a separate {@link ConfidentialKey} instance so that one compromised
17 * {@link ConfidentialKey} (say through incorrect usage and failure to protect it) shouldn't compromise
18 * all the others.
19 *
20 * <p>
21 * {@link ConfidentialKey} is ultimately a sequence of bytes,
22 * but for convenience, a family of subclasses are provided to represent the secret in different formats.
23 * See {@link HexStringConfidentialKey} and {@link HMACConfidentialKey} for example. In addition to the programming
24 * ease, these use case specific subtypes make it harder for vulnerability to creep in by making it harder
25 * for the secret to leak.
26 *
27 * <p>
28 * The {@link ConfidentialKey} subtypes are expected to be used as a singleton, like {@link JnlpSlaveAgentProtocol#SLAVE_SECRET}.
29 * For code that relies on XStream for persistence (such as {@link Builder}s, {@link SCM}s, and other fragment objects
30 * around builds and jobs), {@link Secret} provides more convenient way of storing secrets.
31 *
32 * @author Kohsuke Kawaguchi
33 * @see Secret
34 * @since 1.498
35 */
36 public abstract class ConfidentialKey {
37 /**
38 * Name of the key. This is used as the file name.
39 */
40 private final String id;
41
42 protected ConfidentialKey(String id) {
43 this.id = id;
44 }
45
46 protected @CheckForNull byte[] load() throws IOException {
47 return ConfidentialStore.get().load(this);
48 }
49
50 protected void store(byte[] payload) throws IOException {
51 ConfidentialStore.get().store(this,payload);
52 }
53
54 public String getId() {
55 return id;
56 }
57 }
58