Bug 28460 - Setting Package Signing options within the IDE should store package signing info in a separate .targets file.
Summary: Setting Package Signing options within the IDE should store package signing i...
Status: CONFIRMED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Android Add-in ()
Version: unspecified
Hardware: Macintosh Mac OS
: Normal enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Greg Munn
URL:
: 29236 57598 ()
Depends on:
Blocks:
 
Reported: 2015-03-26 11:36 UTC by Alexandre Rocha Lima e Marcondes
Modified: 2017-07-17 23:14 UTC (History)
8 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 28460 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Alexandre Rocha Lima e Marcondes 2015-03-26 11:36:43 UTC
The project files (.csproj) contains plaintext information on the keystore and key password as well as the keystore file address and alias name. If I need to do versioning control I have to always edit the file before committing so that this information does not go public. There are three alternative ways to go and I think the second one is the best one when thinking of security:

1. Encrypt the data on the .csproj file but insert it there anyway, just not plaintext
2. Use plaintext files but on a different file referenced by the .csproj file so that I could ignore it on git. The IDE could even suggest to put it on .gitignore file or automatically put it there. jarsigner supports passing :file arguments to the storepass and keypass parameters
3. Use plaintext environment variables referenced by the .csproj file. jarsigner supports passing :env arguments to the storepass and keypass parameters


--
[2,3] http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jarsigner.html

storepass[:env | :file] argument
Specifies the password that is required to access the keystore. This is only needed when signing (not verifying) a JAR file. In that case, if a -storepass option is not provided at the command line, then the user is prompted for the password.

If the modifier env or file is not specified, then the password has the value argument. Otherwise, the password is retrieved as follows:

env: Retrieve the password from the environment variable named argument.

file: Retrieve the password from the file named argument.

Note: The password should not be specified on the command line or in a script unless it is for testing purposes, or you are on a secure system.

-keypass [:env | :file] argument
Specifies the password used to protect the private key of the keystore entry addressed by the alias specified on the command line. The password is required when using jarsigner to sign a JAR file. If no password is provided on the command line, and the required password is different from the store password, then the user is prompted for it.

If the modifier env or file is not specified, then the password has the value argument. Otherwise, the password is retrieved as follows:

env: Retrieve the password from the environment variable named argument.

file: Retrieve the password from the file named argument.

Note: The password should not be specified on the command line or in a script unless it is for testing purposes, or you are on a secure system.
Comment 1 Jonathan Pryor 2015-03-26 12:06:59 UTC
> 2. Use plaintext files but on a different file referenced by the .csproj file
> so that I could ignore it on git.

This is already possible through the MSBuild <Import/> element:

https://msdn.microsoft.com/en-us/library/92x05xfs.aspx

You could thus edit your .csproj to add:

    <!-- ...existing .csproj contents... -->
    <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
    <!-- Add: -->
    <Import
            Project="Signing.targets"
            Condition="Exists('Signing.targets')"
    />

Signing.targets could be ignored by git/etc. If not present, it would use the default signing information.
Comment 2 Alexandre Rocha Lima e Marcondes 2015-03-26 14:09:59 UTC
Great, thanks a lot @jonpryor. Is there any chance of this being the default behaviour for the keystore data setup on the preferences?
Comment 3 Alexandre Rocha Lima e Marcondes 2015-03-27 13:17:51 UTC
@jonpryor I'm sorry to start this thread again. I tried to implement what you
suggested but had no success. I really tried all the ways I could see as this
would be possible and registered the tentatives on this github repository:

https://github.com/arlm/Xamarin.Android-SigningImportSample/commits/master

If you have some time, please, can you help me implement your suggestion
manually?
Comment 4 Jonathan Pryor 2015-03-27 13:26:34 UTC
@Alexandre: Move line 67 of Sample.csproj to line 66:

https://github.com/arlm/Xamarin.Android-SigningImportSample/blob/master/Sample/Sample.csproj#L67


    <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
    <Import Project="Signing.targets" Condition="Exists('Signing.targets')" />
  </Project>

Signing.targets also needs to be a valid MSBuild .targets file:

https://github.com/arlm/Xamarin.Android-SigningImportSample/blob/master/Sample/Signing.targets

Should instead be:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AndroidKeyStore>True</AndroidKeyStore>
    <AndroidSigningKeyStore>mykeystore.jks</AndroidSigningKeyStore>
    <AndroidSigningStorePass>keystore-password</AndroidSigningStorePass>
    <AndroidSigningKeyAlias>key-alias</AndroidSigningKeyAlias>
    <AndroidSigningKeyPass>key-alias-password</AndroidSigningKeyPass>
  </PropertyGroup>
</Project>
Comment 5 Alexandre Rocha Lima e Marcondes 2015-03-27 14:02:55 UTC
Thank you very much @jonpryor. Worked flawlessly.

Now @sgmunn has some working code to base the IDE solution on.
Comment 6 Greg Munn 2015-09-16 17:46:54 UTC
*** Bug 29236 has been marked as a duplicate of this bug. ***
Comment 7 Jon Douglas [MSFT] 2017-07-17 23:13:13 UTC
*** Bug 57598 has been marked as a duplicate of this bug. ***
Comment 8 Jon Douglas [MSFT] 2017-07-17 23:14:25 UTC
I'm CONFIRMING this behavior as per findings in duplicate bug https://bugzilla.xamarin.com/show_bug.cgi?id=57598#c2