@@ -18,6 +18,7 @@ import java.io.ByteArrayInputStream
18
18
import java.nio.file.Files
19
19
import java.nio.file.Path
20
20
21
+
21
22
class GPGVerifier (
22
23
private val context : CoderToolboxContext ,
23
24
) {
@@ -48,23 +49,29 @@ class GPGVerifier(
48
49
}
49
50
50
51
private fun getCoderPublicKeyRing (): PGPPublicKeyRing {
51
- return try {
52
- getDefaultCoderPublicKeyRing()
52
+ try {
53
+ val coderPublicKey = javaClass.getResourceAsStream(" /META-INF/trusted-keys/pgp-public.key" )
54
+ ?.readAllBytes() ? : throw IllegalStateException (" Trusted public key not found" )
55
+ return loadPublicKeyRing(coderPublicKey)
53
56
} catch (e: Exception ) {
54
57
throw PGPException (" Failed to load Coder public GPG key" , e)
55
58
}
56
59
}
57
60
58
- private fun getDefaultCoderPublicKeyRing (): PGPPublicKeyRing {
59
- val coderPublicKey = """
60
- -----BEGIN PGP PUBLIC KEY BLOCK-----
61
-
62
- # Replace this with Coder's actual public key
63
-
64
- -----END PGP PUBLIC KEY BLOCK-----
65
- """ .trimIndent()
66
-
67
- return loadPublicKeyRing(coderPublicKey.toByteArray())
61
+ /* *
62
+ * Load public key ring from bytes
63
+ */
64
+ fun loadPublicKeyRing (publicKeyBytes : ByteArray ): PGPPublicKeyRing {
65
+ return try {
66
+ val keyInputStream = ArmoredInputStream (ByteArrayInputStream (publicKeyBytes))
67
+ val keyRingCollection = PGPPublicKeyRingCollection (
68
+ PGPUtil .getDecoderStream(keyInputStream),
69
+ JcaKeyFingerprintCalculator ()
70
+ )
71
+ keyRingCollection.keyRings.next()
72
+ } catch (e: Exception ) {
73
+ throw PGPException (" Failed to load public key ring" , e)
74
+ }
68
75
}
69
76
70
77
/* *
@@ -103,20 +110,4 @@ class GPGVerifier(
103
110
return Failed (e)
104
111
}
105
112
}
106
-
107
- /* *
108
- * Load public key ring from bytes
109
- */
110
- fun loadPublicKeyRing (publicKeyBytes : ByteArray ): PGPPublicKeyRing {
111
- return try {
112
- val keyInputStream = ArmoredInputStream (ByteArrayInputStream (publicKeyBytes))
113
- val keyRingCollection = PGPPublicKeyRingCollection (
114
- PGPUtil .getDecoderStream(keyInputStream),
115
- JcaKeyFingerprintCalculator ()
116
- )
117
- keyRingCollection.keyRings.next()
118
- } catch (e: Exception ) {
119
- throw PGPException (" Failed to load public key ring" , e)
120
- }
121
- }
122
113
}
0 commit comments