Files
Dj GilcreaseandClaude Fable 5.1 62f72a6783 feat(msix): default publisher from the signing certificate or vendor (#1135)
* chore(deps): bump go-msix to v1.0.1 and go-pkcs12 to v0.7.3

go-msix v1.0.1 carries the Authenticode signing fixes needed for packages
signed on Linux to validate on Windows; go-pkcs12 becomes a direct
dependency for the signing tests.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Hnro326ZTAu2EqUTGGkCB

* feat(msix): default publisher from the signing certificate or vendor

`msix.publisher` is no longer required. When signing is configured it
defaults to the certificate subject, which Windows requires to byte-match
on signed packages; otherwise it becomes a CN= distinguished name built
from the root vendor, falling back to the maintainer name (with RFC 2253
escaping). `publisher_display_name` prefers vendor/maintainer over the
package name, `$NFPM_PASSPHRASE` now also feeds the MSIX signer, and the
root `scripts` block is reported as ignored instead of silently dropped.

The vendor/maintainer fallback lives in internal/maintainer so the MSI
packager can share it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Hnro326ZTAu2EqUTGGkCB

* ci: validate nfpm-signed MSIX on real Windows

Build and Authenticode-sign the MSIX on Linux with nfpm's pure-Go signer
and a throwaway openssl certificate, then validate the signature with the
real Windows trust stack (Get-AuthenticodeSignature, signtool verify) and
deploy it with Add-AppxPackage on a Windows runner. The existing
signtool-signed job remains as the control, and the install script now
also runs the installed executable.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Hnro326ZTAu2EqUTGGkCB

* ci: integrate MSIX signature validation with merge queue checks

* fix(msix): derive publishers using Windows DN syntax

* fix: preserve address-only maintainer fallback

* fix(msix): Preserve signing errors without publisher defaults

Return the PFX loading failure before publisher validation when no vendor or maintainer fallback exists. Cover corrupt and missing PFX files and incorrect passphrases with and without fallback metadata.

* test(msix): Remove duplicate publisher display name test

* fix(msix): Validate publisher defaults and isolate signing attempts

Reject unsupported certificate subjects and invalid publisher metadata. Keep derived identities local to each packaging attempt, load signing credentials once, and reject explicit certificate mismatches. Honor explicitly empty MSIX passphrases in the standard environment parsers.

Cover signing retries, successful Info reuse, metadata boundaries, passwordless PFX files, and Windows SDK validation with signed positive and negative controls.

* test(msix): Cover parser entry points and invalid certificate subjects

* fix(msix): Match Windows T61 decoding and validate derived DNs

Preserve certificate ASN.1 value tags and apply Windows UTF-8-first decoding for T.61 strings, with the existing 8-bit fallback. Pass vendor values through only when the complete value is a valid Windows DN; otherwise quote them as CN values.

Cover raw T.61 subjects in native comparisons and signed packaging with derived and explicit publishers. Isolate the global-passphrase test from empty and nonempty ambient MSIX overrides.

* fix(msix): Fall back for invalid derived display names

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-12 01:15:55 +00:00

116 lines
4.2 KiB
Go

package msix
import (
"encoding/asn1"
"fmt"
"strings"
"unicode/utf8"
)
type certificateAttribute struct {
Type asn1.ObjectIdentifier
Value asn1.RawValue
}
// The SET suffix tells encoding/asn1 to decode each RDN as a SET, preserving
// the value's original tag instead of decoding every string into Go text.
type certificateRDNSET []certificateAttribute
// certificatePublisher follows CertNameToStrW with CERT_X500_NAME_STR and
// CERT_NAME_STR_REVERSE_FLAG, as used by Windows MSIX signature validation.
// Decode RawSubject so repeated attributes retain their encoded order.
// Multi-valued RDNs cannot satisfy both the manifest schema and Windows'
// certificate comparison, so reject them instead of flattening them.
func certificatePublisher(rawSubject []byte) (string, error) {
var rdns []certificateRDNSET
rest, err := asn1.Unmarshal(rawSubject, &rdns)
if err != nil {
return "", err
}
if len(rest) != 0 || len(rdns) == 0 {
return "", fmt.Errorf("invalid certificate subject")
}
parts := make([]string, 0, len(rdns))
for i := len(rdns) - 1; i >= 0; i-- {
if len(rdns[i]) == 0 {
return "", fmt.Errorf("empty certificate subject RDN")
}
if len(rdns[i]) != 1 {
return "", fmt.Errorf("multi-valued RDN is not supported by MSIX; use a signing certificate with one attribute per RDN")
}
attribute := rdns[i][0]
var decoded any
if _, err := asn1.Unmarshal(attribute.Value.FullBytes, &decoded); err != nil {
return "", err
}
value, ok := decoded.(string)
if !ok {
return "", fmt.Errorf("unsupported certificate subject value for %s", attribute.Type)
}
// CertNameToStrW tries UTF-8 for T.61 before falling back to 8-bit
// characters. encoding/asn1 always decodes T.61 as Latin-1.
if attribute.Value.Class == asn1.ClassUniversal && attribute.Value.Tag == asn1.TagT61String && utf8.Valid(attribute.Value.Bytes) {
value = string(attribute.Value.Bytes)
}
parts = append(parts, windowsDNKey(attribute.Type)+"="+quoteDNValue(value))
}
publisher := strings.Join(parts, ", ")
if err := validatePublisher(publisher); err != nil {
return "", err
}
return publisher, nil
}
func validatePublisher(publisher string) error {
if !validXMLText(publisher) || utf8.RuneCountInString(publisher) > 8192 || strings.TrimSpace(publisher) != publisher || !publisherPattern.MatchString(publisher) {
return fmt.Errorf("package msix.publisher must be a Windows distinguished name of at most 8192 characters, with comma-space separators and quoted reserved characters")
}
return nil
}
// encoding/xml replaces invalid characters, which would change the signed
// publisher identity. Reject them before encoding instead.
func validXMLText(value string) bool {
return utf8.ValidString(value) && !strings.ContainsFunc(value, func(r rune) bool {
return (r < 0x20 && r != '\t' && r != '\n' && r != '\r') || r == 0xfffe || r == 0xffff
})
}
// Windows doubles embedded quotes and quotes reserved characters and values
// with leading/trailing whitespace; backslashes are literal, not RFC 2253 escapes.
func quoteDNValue(value string) string {
if value == "" || strings.TrimSpace(value) != value || strings.ContainsAny(value, ",+=\"\\<>#;\n\r") {
return `"` + strings.ReplaceAll(value, `"`, `""`) + `"`
}
return value
}
func windowsDNKey(oid asn1.ObjectIdentifier) string {
keys := map[string]string{
"2.5.4.3": "CN",
"2.5.4.4": "SN",
"2.5.4.5": "SERIALNUMBER",
"2.5.4.6": "C",
"2.5.4.7": "L",
"2.5.4.8": "S",
"2.5.4.9": "STREET",
"2.5.4.10": "O",
"2.5.4.11": "OU",
"2.5.4.12": "T",
"2.5.4.13": "Description",
"2.5.4.17": "PostalCode",
"2.5.4.18": "POBox",
"2.5.4.20": "Phone",
"2.5.4.24": "X21Address",
"2.5.4.42": "G",
"2.5.4.43": "I",
"2.5.4.46": "dnQualifier",
"1.2.840.113549.1.9.1": "E",
"0.9.2342.19200300.100.1.25": "DC",
}
if key, ok := keys[oid.String()]; ok {
return key
}
return "OID." + oid.String()
}