Skip to content

Commit

Permalink
fix bug #74
Browse files Browse the repository at this point in the history
  • Loading branch information
YehudaKremer committed Feb 5, 2022
1 parent 72379b5 commit ee81ce4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.8.14

- fix [#74](https://github.com/YehudaKremer/msix/issues/74)

## 2.8.13

- fix log bug
Expand Down
3 changes: 2 additions & 1 deletion lib/src/appxManifest.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:convert' show HtmlEscape;
import 'capabilities.dart';
import 'configuration.dart';
import 'extensions.dart';
Expand Down Expand Up @@ -38,7 +39,7 @@ class AppxManifest {
xmlns:com3="http://schemas.microsoft.com/appx/manifest/com/windows10/3"
IgnorableNamespaces="uap3 desktop">
<Identity Name="${_config.identityName}" Version="${_config.msixVersion}"
Publisher="${_config.publisher!.replaceAll(' = ', '=')}" ProcessorArchitecture="${_config.architecture}" />
Publisher="${HtmlEscape().convert(_config.publisher!.replaceAll(' = ', '='))}" ProcessorArchitecture="${_config.architecture}" />

This comment has been minimized.

Copy link
@YehudaKremer

YehudaKremer Feb 5, 2022

Author Owner

using HtmlEscape.convert to fix the "ampersand problem" #74

<Properties>
<DisplayName>${_config.displayName}</DisplayName>
<PublisherDisplayName>${_config.publisherName}</PublisherDisplayName>
Expand Down
50 changes: 27 additions & 23 deletions lib/src/signTool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:msix/src/extensions.dart';
import 'package:path/path.dart';
import 'configuration.dart';
import 'log.dart';
import 'extensions.dart';

var _publisherRegex = RegExp(
'(CN|L|O|OU|E|C|S|STREET|T|G|I|SN|DC|SERIALNUMBER|(OID\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))+))=(([^,+="<>#;])+|".*")(, ((CN|L|O|OU|E|C|S|STREET|T|G|I|SN|DC|SERIALNUMBER|(OID\.(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))+))=(([^,+="<>#;])+|".*")))*');
Expand All @@ -25,30 +26,25 @@ class SignTool {
"(Get-PfxData -FilePath \"${_config.certificatePath}\" -Password \$(ConvertTo-SecureString -String \"${_config.certificatePassword}\" -AsPlainText -Force)).EndEntityCertificates[0] | Format-List -Property Subject"
]);

if (certificateDetails.stderr.toString().length > 0) {
if (certificateDetails.stderr.toString().contains('password')) {
_log.errorAndExit(GeneralException(
'Fail to read the certificate details, check if the certificate password is correct'));
}
_log.error(certificateDetails.stdout);
_log.errorAndExit(GeneralException(certificateDetails.stderr));
} else if (certificateDetails.exitCode != 0) {
_log.errorAndExit(GeneralException(certificateDetails.stdout));
if (certificateDetails.exitCode != 0) {
throw certificateDetails.stderr;
}

var subjectRow = certificateDetails.stdout.toString();

if (!_publisherRegex.hasMatch(subjectRow)) {
throw 'Invalid certificate subject: $subjectRow';
}

if (withLogs)
_log.info('Certificate Details: ${certificateDetails.stdout}');

try {
var subjectRow = certificateDetails.stdout
.toString()
.split('\n')
.lastWhere((row) => _publisherRegex.hasMatch(row));
if (withLogs) _log.info('subjectRow: $subjectRow');
_config.publisher = subjectRow
.substring(subjectRow.indexOf(':') + 1, subjectRow.length)
.replaceAll("\"", "&quot;")
.trim();

if (withLogs) _log.info('config.publisher: ${_config.publisher}');
} catch (err, stackTrace) {
if (!withLogs) await getCertificatePublisher(true);
Expand All @@ -69,15 +65,23 @@ class SignTool {
/// Use the certutil.exe tool to install the certificate on the local machine
/// this helps to avoid the need to install the certificate by hand
Future<void> installCertificate() async {
const taskName = 'installing certificate';
_log.startingTask(taskName);
var getInstalledCertificate = await Process.run('powershell.exe', [

This comment has been minimized.

Copy link
@YehudaKremer

YehudaKremer Feb 5, 2022

Author Owner

switch certutil with PowerShell also here

'-NoProfile',
'-NonInteractive',
"dir Cert:\\CurrentUser\\Root | Where-Object { \$_.Subject -eq '${_config.publisher}'}"
]);

if (getInstalledCertificate.exitCode != 0) {
throw getInstalledCertificate.stderr;
}

var installedCertificatesList =
await Process.run('certutil', ['-store', 'root']);
var isCertificateNotInstalled =
getInstalledCertificate.stdout.toString().isNullOrEmpty;

if (isCertificateNotInstalled) {
const taskName = 'installing certificate';
_log.startingTask(taskName);

if (!installedCertificatesList.stdout
.toString()
.contains(_config.publisher!)) {
var isAdminCheck = await Process.run('net', ['session']);

if (isAdminCheck.stderr.toString().contains('Access is denied')) {
Expand All @@ -101,9 +105,9 @@ class SignTool {
} else if (result.exitCode != 0) {
_log.errorAndExit(GeneralException(result.stdout));
}
}

_log.taskCompleted(taskName);
_log.taskCompleted(taskName);
}
}

/// Sign the created msix installer with the certificate
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: msix
description: A command-line tool that create Msix installer from your flutter windows-build files.
version: 2.8.13
version: 2.8.14
maintainer: Yehuda Kremer ([email protected])
homepage: https://github.com/YehudaKremer/msix

Expand Down

0 comments on commit ee81ce4

Please sign in to comment.