Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle support #33

Closed
dmodoomsirius opened this issue Feb 4, 2017 · 16 comments
Closed

Gradle support #33

dmodoomsirius opened this issue Feb 4, 2017 · 16 comments

Comments

@dmodoomsirius
Copy link

Have you thought about making a plugin for gradle to use jsign without haivng to rework the ant task to work with gradle?

@ebourg
Copy link
Owner

ebourg commented Feb 4, 2017

Integrating an Ant task with Gradle is quite easy and for now I don't plan to implement a Gradle plugin. But if someone wants to write one I'd be happy to merge it.

@nedtwigg
Copy link

nedtwigg commented Feb 4, 2017

I'm not sure a gradle plugin could be much simpler than just calling out to PESigner directly. Here's how I do it:

task sign {
    doLast {
        PESigner signer = new PESigner(INSTALLER_FILE)
        signer.setArg('name', 'MyApp')
        signer.setArg('url', 'https://myapp.com')
        ...
        signer.sign()
    }
}

@dmodoomsirius
Copy link
Author

is the installer file the actual jsign file? just getting back to this now. thanks for the info.

@nedtwigg
Copy link

nedtwigg commented Feb 6, 2017

INSTALLER_FILE is the file you want to sign. In my case, it's an .exe. Not sure what a jsign file is.

@dmodoomsirius
Copy link
Author

http://search.maven.org/#artifactdetails%7Cnet.jsign%7Cjsign%7C1.3%7Cjar this file is what i was referencing.

@nedtwigg
Copy link

nedtwigg commented Feb 6, 2017

Gotcha. You add that to your buildscript by putting this at the top of your buildscript:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "net.jsign:jsign:1.3"
    }
}

import net.jsign.PESigner

@dmodoomsirius
Copy link
Author

:launcher-bootstrap:signexe FAILED

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\Myahm\Desktop\coding\git\MC\github\oblivion\Launcher\launcher-bootstrap\build.gradle' line: 71

* What went wrong:
Execution failed for task ':launcher-bootstrap:signexe'.
> Could not find matching constructor for: net.jsign.PESigner(java.lang.String)

I am dealing with a multi project setup when i run that it fails due to that.

@nedtwigg
Copy link

nedtwigg commented Feb 6, 2017

Whoops, sorry. Looks like we actually have a little in-house code.

import net.jsign.PESignerCLI;

public class PESigner {
	private final File fileToSign;
	private final Map<String, String> stringProps = Maps.newHashMap();

	public PESigner(File fileToSign) {
		this.fileToSign = fileToSign;
	}

	public void setArg(String key, String value) {
		stringProps.put(key, value);
	}

	public void sign() {
		List<String> args = Lists.newArrayList();
		for (Map.Entry<String, String> entry : stringProps.entrySet()) {
			args.add("--" + entry.getKey());
			args.add(entry.getValue());
		}
		args.add(fileToSign.getAbsolutePath());
		PESignerCLI.main(args.toArray(new String[args.size()]));
	}
}

@dmodoomsirius
Copy link
Author

dmodoomsirius commented Feb 6, 2017

https://gist.github.com/dmodoomsirius/ba96f9c98283bf63fa94bb79acc2801a

^ my build.gradle for the project that has the exe i am trying to sign.

:launcher-bootstrap:signexe FAILED

FAILURE: Build failed with an exception.

* Where:
Build file '%userprofile%\Desktop\coding\git\MC\github\oblivion\Launcher\launcher-bootstrap\build.gradle' line: 95

* What went wrong:
Execution failed for task ':launcher-bootstrap:signexe'.
> Could not find matching constructor for: PESigner(java.lang.String)

@nedtwigg
Copy link

nedtwigg commented Feb 6, 2017

If you know how to use buildSrc, then put the PESigner I copy-pasted above into it. If you don't, try something like this:

import net.jsign.PESignerCLI;

task sign {
    doLast {
        args = ['--arg', 'argValue', 'C:\PathToFileToSign']
        PESignerCLI.main(args.toArray(new String[args.size()]));
    }
}

@dmodoomsirius
Copy link
Author

I don't atm. I am looking into it right now.

@ebourg
Copy link
Owner

ebourg commented Feb 7, 2017

This looks fairly complex, and I don't think a build script is the right place to write code, it's sad that Gradle encourages this. Using the Ant task should be easier:

configurations {
    jsign
}

dependencies {
    jsign group: 'net.jsign', name: 'jsign', version: '1.3'
}

task jsign << {
    ant.taskdef(name: 'jsign', classname: 'net.jsign.PESignerTask', classpath: configurations.jsign.asPath)
    ant.jsign(file: 'application.exe',
              name: 'My Application',
              url:  'http://www.example.com',
              keystore: 'keystore.p12',
              alias: 'test',
              storepass: 'secret',
              tsaurl: 'http://timestamp.comodoca.com/authenticode')
}

@dmodoomsirius
Copy link
Author

Now I have can't read private key even tho I converted a PuttyGEN Key into a pvk using this tool. not sure what I am doing wrong.

@dmodoomsirius
Copy link
Author

dmodoomsirius commented Feb 10, 2017

Edit: moved issue to another issue. #34

ebourg added a commit that referenced this issue Feb 22, 2017
@ebourg
Copy link
Owner

ebourg commented Feb 22, 2017

I added a native Gradle plugin, please give it a try. Here is a usage example:

buildscript {
    repositories {
        mavenLocal()
    }

    dependencies {
        classpath 'net.jsign:jsign-gradle-plugin:1.4-SNAPSHOT'
    }
}

apply plugin: 'net.jsign'

task sign << {
    signexe(file      : 'application.exe',
            name      : 'My Application',
            url       : 'http://www.example.com',
            keystore  : 'keystore.p12',
            alias     : 'test',
            storepass : 'secret',
            tsaurl    : 'http://timestamp.comodoca.com/authenticode')
}

I plan to upload the plugin to the Gradle Plugin Portal once the next version is released. The usage will then be easier :

plugins {
    id "net.jsign" version "1.4"
}

task sign << {
    signexe(file      : 'application.exe',
            name      : 'My Application',
            url       : 'http://www.example.com',
            keystore  : 'keystore.p12',
            alias     : 'test',
            storepass : 'secret',
            tsaurl    : 'http://timestamp.comodoca.com/authenticode')
}

@dmodoomsirius
Copy link
Author

ohh thank you. I will sure to give this a try when i get home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants