1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.generator.gnupg.loaders;
20
21 import javax.inject.Named;
22 import javax.inject.Singleton;
23
24 import java.nio.charset.StandardCharsets;
25
26 import org.bouncycastle.util.encoders.Hex;
27 import org.eclipse.aether.RepositorySystemSession;
28 import org.eclipse.aether.generator.gnupg.GnupgSignatureArtifactGeneratorFactory;
29 import org.eclipse.aether.util.ConfigUtils;
30 import org.eclipse.sisu.Priority;
31
32 import static org.eclipse.aether.generator.gnupg.GnupgConfigurationKeys.*;
33
34
35
36
37 @Singleton
38 @Named(GpgEnvLoader.NAME)
39 @Priority(30)
40 @SuppressWarnings("checkstyle:magicnumber")
41 public final class GpgEnvLoader implements GnupgSignatureArtifactGeneratorFactory.Loader {
42 public static final String NAME = "env";
43
44 @Override
45 public byte[] loadKeyRingMaterial(RepositorySystemSession session) {
46 String keyMaterial = ConfigUtils.getString(session, null, "env." + RESOLVER_GPG_KEY);
47 if (keyMaterial != null) {
48 return keyMaterial.getBytes(StandardCharsets.UTF_8);
49 }
50 return null;
51 }
52
53 @Override
54 public byte[] loadKeyFingerprint(RepositorySystemSession session) {
55 String keyFingerprint = ConfigUtils.getString(session, null, "env." + RESOLVER_GPG_KEY_FINGERPRINT);
56 if (keyFingerprint != null) {
57 if (keyFingerprint.trim().length() == 40) {
58 return Hex.decode(keyFingerprint);
59 } else {
60 throw new IllegalArgumentException(
61 "Key fingerprint configuration is wrong (hex encoded, 40 characters)");
62 }
63 }
64 return null;
65 }
66
67 @Override
68 public char[] loadPassword(RepositorySystemSession session, byte[] fingerprint) {
69 String keyPassword = ConfigUtils.getString(session, null, "env." + RESOLVER_GPG_KEY_PASS);
70 if (keyPassword != null) {
71 return keyPassword.toCharArray();
72 }
73 return null;
74 }
75 }