This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 380688d
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.gradle | ||
.idea | ||
build | ||
*.iml | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apply plugin: 'groovy' | ||
|
||
dependencies { | ||
compile gradleApi() | ||
compile localGroovy() | ||
} | ||
|
||
|
64 changes: 64 additions & 0 deletions
64
src/main/groovy/org/whispersystems/witness/WitnessPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.whispersystems.witness | ||
|
||
import org.gradle.api.InvalidUserDataException | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.ResolvedArtifact | ||
|
||
import java.security.MessageDigest | ||
|
||
class WitnessPluginExtension { | ||
List verify | ||
} | ||
|
||
class WitnessPlugin implements Plugin<Project> { | ||
|
||
static String calculateSha256(file) { | ||
MessageDigest md = MessageDigest.getInstance("SHA-256"); | ||
file.eachByte 4096, {bytes, size -> | ||
md.update(bytes, 0, size); | ||
} | ||
return md.digest().collect {String.format "%02x", it}.join(); | ||
} | ||
|
||
void apply(Project project) { | ||
project.extensions.create("dependencyVerification", WitnessPluginExtension) | ||
project.afterEvaluate { | ||
project.dependencyVerification.verify.each { | ||
assertion -> | ||
List parts = assertion.tokenize(":") | ||
String group = parts.get(0) | ||
String name = parts.get(1) | ||
String hash = parts.get(2) | ||
|
||
ResolvedArtifact dependency = project.configurations.compile.resolvedConfiguration.resolvedArtifacts.find { | ||
return it.name.equals(name) && it.resolvedDependency.moduleGroup.equals(group) | ||
} | ||
|
||
println "Verifying " + group + ":" + name | ||
|
||
if (dependency == null) { | ||
throw new InvalidUserDataException("No dependency for integrity assertion found: " + group + ":" + name) | ||
} | ||
|
||
if (!hash.equals(calculateSha256(dependency.file))) { | ||
throw new InvalidUserDataException("Checksum failed for " + assertion) | ||
} | ||
} | ||
} | ||
|
||
project.task('calculateChecksums') << { | ||
println "dependencyVerification {" | ||
println " verify = [" | ||
|
||
project.configurations.compile.resolvedConfiguration.resolvedArtifacts.each { | ||
dep -> | ||
println " '" + dep.resolvedDependency.moduleGroup+ ":" + dep.name + ":" + calculateSha256(dep.file) + "'," | ||
} | ||
|
||
println " ]" | ||
println "}" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
implementation-class=org.whispersystems.witness.WitnessPlugin |