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.RESOLVER_GPG_KEY;
33 import static org.eclipse.aether.generator.gnupg.GnupgConfigurationKeys.RESOLVER_GPG_KEY_FINGERPRINT;
34 import static org.eclipse.aether.generator.gnupg.GnupgConfigurationKeys.RESOLVER_GPG_KEY_PASS;
35
36
37
38
39 @Singleton
40 @Named(GpgEnvLoader.NAME)
41 @Priority(30)
42 public final class GpgEnvLoader implements GnupgSignatureArtifactGeneratorFactory.Loader {
43 public static final String NAME = "env";
44
45 @Override
46 public byte[] loadKeyRingMaterial(RepositorySystemSession session) {
47 String keyMaterial = ConfigUtils.getString(session, null, "env." + RESOLVER_GPG_KEY);
48 if (keyMaterial != null) {
49 return keyMaterial.getBytes(StandardCharsets.UTF_8);
50 }
51 return null;
52 }
53
54 @Override
55 public byte[] loadKeyFingerprint(RepositorySystemSession session) {
56 String keyFingerprint = ConfigUtils.getString(session, null, "env." + RESOLVER_GPG_KEY_FINGERPRINT);
57 if (keyFingerprint != null) {
58 if (keyFingerprint.trim().length() == 40) {
59 return Hex.decode(keyFingerprint);
60 } else {
61 throw new IllegalArgumentException(
62 "Key fingerprint configuration is wrong (hex encoded, 40 characters)");
63 }
64 }
65 return null;
66 }
67
68 @Override
69 public char[] loadPassword(RepositorySystemSession session, byte[] fingerprint) {
70 String keyPassword = ConfigUtils.getString(session, null, "env." + RESOLVER_GPG_KEY_PASS);
71 if (keyPassword != null) {
72 return keyPassword.toCharArray();
73 }
74 return null;
75 }
76 }