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