diff --git a/Gopkg.lock b/Gopkg.lock index 9a4e93b5..b3f4a957 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -13,7 +13,10 @@ "pathutil", "pkcs12", "pkcs12/internal/rc2", - "progress" + "progress", + "retry", + "sliceutil", + "urlutil" ] revision = "b33f6bcef9b50045d7e62364b354584afc3ee329" @@ -53,7 +56,7 @@ "utility", "xcarchive" ] - revision = "c23fa74e7b04374fbff484fd12ba87cf64cd89e1" + revision = "2ebe49789dd410cae7f6dc54f0d2f5893e4fd1a0" [[projects]] name = "github.com/davecgh/go-spew" @@ -136,6 +139,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "7c54a878fc17fec1c7e02c05175685a10bb47d854beae409eadfb296ff7b3ded" + inputs-digest = "20ccef654feb813d75e196eb0c9135641e33c9d3168f3ec23d216fd126dec967" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/archive.go b/cmd/archive.go new file mode 100644 index 00000000..8595302e --- /dev/null +++ b/cmd/archive.go @@ -0,0 +1,14 @@ +package cmd + +import ( + "github.com/bitrise-tools/go-xcode/plistutil" + "github.com/bitrise-tools/go-xcode/profileutil" +) + +// Archive ... +type Archive interface { + BundleIDEntitlementsMap() map[string]plistutil.PlistData + IsXcodeManaged() bool + SigningIdentity() string + BundleIDProfileInfoMap() map[string]profileutil.ProvisioningProfileInfoModel +} diff --git a/cmd/common.go b/cmd/common.go index 3c62b4e0..a8ef3368 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -50,76 +50,6 @@ func initExportOutputDir() (string, error) { return absExportOutputDirPath, nil } -func analyzeArchive(archive xcarchive.IosArchive, installedCertificates []certificateutil.CertificateInfoModel) (export.IosCodeSignGroup, error) { - signingIdentity := archive.SigningIdentity() - bundleIDProfileInfoMap := archive.BundleIDProfileInfoMap() - - if signingIdentity == "" { - return export.IosCodeSignGroup{}, fmt.Errorf("no signing identity found") - } - - certificate, err := findCertificate(signingIdentity, installedCertificates) - if err != nil { - return export.IosCodeSignGroup{}, err - } - - return export.IosCodeSignGroup{ - Certificate: certificate, - BundleIDProfileMap: bundleIDProfileInfoMap, - }, nil -} - -func collectIpaExportSelectableCodeSignGroups(archive xcarchive.IosArchive, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel) []export.SelectableCodeSignGroup { - bundleIDEntitlemenstMap := archive.BundleIDEntitlementsMap() - - fmt.Println() - fmt.Println() - log.Infof("Targets to sign:") - fmt.Println() - for bundleID, entitlements := range bundleIDEntitlemenstMap { - fmt.Printf("- %s with %d capabilities\n", bundleID, len(entitlements)) - } - fmt.Println() - - bundleIDs := []string{} - for bundleID := range bundleIDEntitlemenstMap { - bundleIDs = append(bundleIDs, bundleID) - } - codeSignGroups := export.CreateSelectableCodeSignGroups(installedCertificates, installedProfiles, bundleIDs) - - log.Debugf("Codesign Groups:") - for _, group := range codeSignGroups { - log.Debugf(group.String()) - } - - if len(codeSignGroups) == 0 { - return []export.SelectableCodeSignGroup{} - } - - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, - export.CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlemenstMap), - ) - - // Handle if archive used NON xcode managed profile - if len(codeSignGroups) > 0 && !archive.IsXcodeManaged() { - log.Warnf("App was signed with NON xcode managed profile when archiving,") - log.Warnf("only NOT xcode managed profiles are allowed to sign when exporting the archive.") - log.Warnf("Removing xcode managed CodeSignInfo groups") - - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, - export.CreateNotXcodeManagedSelectableCodeSignGroupFilter(), - ) - } - - log.Debugf("\n") - log.Debugf("Filtered Codesign Groups:") - for _, group := range codeSignGroups { - log.Debugf(group.String()) - } - - return codeSignGroups -} - func filterLatestProfiles(profiles []profileutil.ProvisioningProfileInfoModel) []profileutil.ProvisioningProfileInfoModel { profilesByBundleIDAndName := map[string][]profileutil.ProvisioningProfileInfoModel{} for _, profile := range profiles { @@ -147,8 +77,9 @@ func filterLatestProfiles(profiles []profileutil.ProvisioningProfileInfoModel) [ return filteredProfiles } -func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel) ([]export.IosCodeSignGroup, error) { - iosCodeSignGroups := []export.IosCodeSignGroup{} +func collectIpaExportCodeSignGroups(tool Tool, archive Archive, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel) ([]export.CodeSignGroup, error) { + collectedCodeSignGroups := []export.CodeSignGroup{} + _, isMacArchive := archive.(xcarchive.MacosArchive) codeSignGroups := collectIpaExportSelectableCodeSignGroups(archive, installedCertificates, installedProfiles) if len(codeSignGroups) == 0 { @@ -280,18 +211,45 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins return nil, fmt.Errorf("failed to find Provisioning Profiles for ipa export") } - iosCodeSignGroup := export.IosCodeSignGroup{ - Certificate: *selectedCertificate, - BundleIDProfileMap: selectedBundleIDProfileMap, + var collectedCodeSignGroup export.CodeSignGroup + if isMacArchive { + installedInstallerCertificates := []certificateutil.CertificateInfoModel{} + + var selectedInstallerCetrificate certificateutil.CertificateInfoModel + if selectedExportMethod == string(exportoptions.MethodAppStore) { + installedInstallerCertificates, err = certificateutil.InstalledInstallerCertificateInfos() + if err != nil { + log.Errorf("Failed to read installed Installer certificates, error: %s", err) + } + + installedInstallerCertificates = certificateutil.FilterValidCertificateInfos(installedInstallerCertificates) + + log.Debugf("\n") + log.Debugf("Installed installer certificates:") + for _, certInfo := range installedInstallerCertificates { + log.Debugf(certInfo.String()) + } + + for _, installerCetrificate := range installedInstallerCertificates { + if installerCetrificate.TeamID == selectedCertificate.TeamID { + selectedInstallerCetrificate = installerCetrificate + break + } + } + } + + collectedCodeSignGroup = export.NewMacGroup(*selectedCertificate, &selectedInstallerCetrificate, selectedBundleIDProfileMap) + } else { + collectedCodeSignGroup = export.NewIOSGroup(*selectedCertificate, selectedBundleIDProfileMap) } fmt.Println() fmt.Println() - log.Infof("Codesign settings will be used for %s ipa export:", exportMethod(iosCodeSignGroup)) + log.Infof("Codesign settings will be used for %s .ipa/.app export:", exportMethod(collectedCodeSignGroup)) fmt.Println() - printCodesignGroup(iosCodeSignGroup) + printCodesignGroup(collectedCodeSignGroup) - iosCodeSignGroups = append(iosCodeSignGroups, iosCodeSignGroup) + collectedCodeSignGroups = append(collectedCodeSignGroups, collectedCodeSignGroup) fmt.Println() fmt.Println() @@ -306,7 +264,7 @@ func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, ins } } - return iosCodeSignGroups, nil + return collectedCodeSignGroups, nil } func collectIpaExportCertificate(tool Tool, archiveCertificate certificateutil.CertificateInfoModel, installedCertificates []certificateutil.CertificateInfoModel) (certificateutil.CertificateInfoModel, error) { @@ -528,11 +486,17 @@ func provProfileExportFileName(info profileutil.ProvisioningProfileInfoModel, pa } func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error { + macOS, err := xcarchive.IsMacOS(archivePath) + if err != nil { + return err + } + // archive code sign settings - installedCertificates, err := certificateutil.InstalledCodesigningCertificateInfos() + installedCertificates, err := certificateutil.InstalledCodesigningCertificateInfos(macOS) if err != nil { return fmt.Errorf("failed to list installed code signing identities, error: %s", err) } + installedCertificates = certificateutil.FilterValidCertificateInfos(installedCertificates) log.Debugf("Installed certificates:") @@ -540,7 +504,12 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error { log.Debugf(installedCertificate.String()) } - installedProfiles, err := profileutil.InstalledProvisioningProfileInfos(profileutil.ProfileTypeIos) + profileType := profileutil.ProfileTypeIos + if macOS { + profileType = profileutil.ProfileTypeMacOs + } + + installedProfiles, err := profileutil.InstalledProvisioningProfileInfos(profileType) if err != nil { return fmt.Errorf("failed to list installed provisioning profiles, error: %s", err) } @@ -550,52 +519,16 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error { log.Debugf(profileInfo.String(installedCertificates...)) } - archive, err := xcarchive.NewIosArchive(archivePath) - if err != nil { - return fmt.Errorf("failed to analyze archive, error: %s", err) - } - - archiveCodeSignGroup, err := analyzeArchive(archive, installedCertificates) + certificatesToExport, profilesToExport, err := getFilesToExport(archivePath, installedCertificates, installedProfiles, tool) if err != nil { - return fmt.Errorf("failed to analyze the archive, error: %s", err) + return err } - fmt.Println() - log.Infof("Codesign settings used for archive:") - fmt.Println() - printCodesignGroup(archiveCodeSignGroup) - // ipa export code sign settings fmt.Println() fmt.Println() log.Printf("🔦 Analyzing the archive, to get ipa export code signing settings...") - certificatesToExport := []certificateutil.CertificateInfoModel{} - profilesToExport := []profileutil.ProvisioningProfileInfoModel{} - - if certificatesOnly { - ipaExportCertificate, err := collectIpaExportCertificate(tool, archiveCodeSignGroup.Certificate, installedCertificates) - if err != nil { - return err - } - - certificatesToExport = append(certificatesToExport, archiveCodeSignGroup.Certificate, ipaExportCertificate) - } else { - ipaExportCodeSignGroups, err := collectIpaExportCodeSignGroups(tool, archive, installedCertificates, installedProfiles) - if err != nil { - return err - } - - if len(ipaExportCodeSignGroups) == 0 { - return errors.New("no ipa export code sign groups collected") - } - - codeSignGroups := append(ipaExportCodeSignGroups, archiveCodeSignGroup) - certificates, profiles := extractCertificatesAndProfiles(codeSignGroups...) - certificatesToExport = append(certificatesToExport, certificates...) - profilesToExport = append(profilesToExport, profiles...) - } - if err := collectAndExportIdentities(certificatesToExport, outputDirPath); err != nil { return err } @@ -632,7 +565,7 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error { bitriseClient.SetSelectedAppSlug(selectedAppSlug) - provProfilesUploaded, err = uploadExportedProvProfiles(bitriseClient, profilesToExport, outputDirPath) + provProfilesUploaded, err = uploadExportedProvProfiles(bitriseClient, profilesToExport, outputDirPath, macOS) if err != nil { return err } @@ -657,6 +590,89 @@ func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error { return nil } +func getFilesToExport(archivePath string, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel, tool Tool) ([]certificateutil.CertificateInfoModel, []profileutil.ProvisioningProfileInfoModel, error) { + macOS, err := xcarchive.IsMacOS(archivePath) + if err != nil { + return nil, nil, err + } + + var certificate certificateutil.CertificateInfoModel + var archive Archive + var achiveCodeSignGroup export.CodeSignGroup + + if macOS { + archive, achiveCodeSignGroup, err = getMacOSCodeSignGroup(archivePath, installedCertificates) + if err != nil { + return nil, nil, err + } + certificate = achiveCodeSignGroup.Certificate() + } else { + archive, achiveCodeSignGroup, err = getIOSCodeSignGroup(archivePath, installedCertificates) + if err != nil { + return nil, nil, err + } + certificate = achiveCodeSignGroup.Certificate() + } + + certificatesToExport := []certificateutil.CertificateInfoModel{} + profilesToExport := []profileutil.ProvisioningProfileInfoModel{} + + if certificatesOnly { + ipaExportCertificate, err := collectIpaExportCertificate(tool, certificate, installedCertificates) + if err != nil { + return nil, nil, err + } + + certificatesToExport = append(certificatesToExport, certificate, ipaExportCertificate) + } else { + certificatesToExport, profilesToExport, err = collectCertificatesAndProfiles(archive, tool, certificate, installedCertificates, installedProfiles, certificatesToExport, profilesToExport, achiveCodeSignGroup) + if err != nil { + return nil, nil, err + } + } + + return certificatesToExport, profilesToExport, nil +} + +func collectCertificatesAndProfiles(archive Archive, tool Tool, certificate certificateutil.CertificateInfoModel, + installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel, + certificatesToExport []certificateutil.CertificateInfoModel, profilesToExport []profileutil.ProvisioningProfileInfoModel, + achiveCodeSignGroup export.CodeSignGroup) ([]certificateutil.CertificateInfoModel, []profileutil.ProvisioningProfileInfoModel, error) { + + _, macOS := archive.(xcarchive.MacosArchive) + + groups, err := collectIpaExportCodeSignGroups(tool, archive, installedCertificates, installedProfiles) + if err != nil { + return nil, nil, err + } + + var exportCodeSignGroups []export.CodeSignGroup + for _, group := range groups { + if macOS { + exportCodeSignGroup, ok := group.(*export.MacCodeSignGroup) + if ok { + exportCodeSignGroups = append(exportCodeSignGroups, exportCodeSignGroup) + } + } else { + exportCodeSignGroup, ok := group.(*export.IosCodeSignGroup) + if ok { + exportCodeSignGroups = append(exportCodeSignGroups, exportCodeSignGroup) + } + } + } + + if len(exportCodeSignGroups) == 0 { + return nil, nil, errors.New("no ipa export code sign groups collected") + } + + codeSignGroups := append(exportCodeSignGroups, achiveCodeSignGroup) + certificates, profiles := extractCertificatesAndProfiles(codeSignGroups...) + certificatesToExport = append(certificatesToExport, certificates...) + profilesToExport = append(profilesToExport, profiles...) + + return certificatesToExport, profilesToExport, nil +} + func getAccessToken() (string, error) { accessToken, err := askAccessToken() if err != nil { @@ -666,7 +682,7 @@ func getAccessToken() (string, error) { return accessToken, nil } -func uploadExportedProvProfiles(bitriseClient *bitriseclient.BitriseClient, profilesToExport []profileutil.ProvisioningProfileInfoModel, outputDirPath string) (bool, error) { +func uploadExportedProvProfiles(bitriseClient *bitriseclient.BitriseClient, profilesToExport []profileutil.ProvisioningProfileInfoModel, outputDirPath string, isMacOS bool) (bool, error) { fmt.Println() log.Infof("Uploading provisioning profiles...") @@ -676,7 +692,7 @@ func uploadExportedProvProfiles(bitriseClient *bitriseclient.BitriseClient, prof } if len(profilesToUpload) > 0 { - if err := uploadProvisioningProfiles(bitriseClient, profilesToUpload, outputDirPath); err != nil { + if err := uploadProvisioningProfiles(bitriseClient, profilesToUpload, outputDirPath, isMacOS); err != nil { return false, err } } else { @@ -794,10 +810,14 @@ func shouldUploadCertificates(client *bitriseclient.BitriseClient, certificatesT // ---------------------------------------------------------------- // --- Upload methods -func uploadProvisioningProfiles(bitriseClient *bitriseclient.BitriseClient, profilesToUpload []profileutil.ProvisioningProfileInfoModel, outputDirPath string) error { +func uploadProvisioningProfiles(bitriseClient *bitriseclient.BitriseClient, profilesToUpload []profileutil.ProvisioningProfileInfoModel, outputDirPath string, isMacOS bool) error { for _, profile := range profilesToUpload { exportFileName := provProfileExportFileName(profile, outputDirPath) + if isMacOS { + exportFileName = strings.Replace(exportFileName, ".mobileprovision", ".provisionprofile", -1) + } + provProfile, err := os.Open(outputDirPath + "/" + exportFileName) if err != nil { return err diff --git a/cmd/print.go b/cmd/print.go index 1c9fb7c0..cf363c9a 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -19,11 +19,11 @@ func printFinished(provProfilesUploaded bool, certsUploaded bool) { } } -func printCodesignGroup(group export.IosCodeSignGroup) { - fmt.Printf("%s %s (%s)\n", colorstring.Green("development team:"), group.Certificate.TeamName, group.Certificate.TeamID) - fmt.Printf("%s %s [%s]\n", colorstring.Green("codesign identity:"), group.Certificate.CommonName, group.Certificate.Serial) +func printCodesignGroup(group export.CodeSignGroup) { + fmt.Printf("%s %s (%s)\n", colorstring.Green("development team:"), group.Certificate().TeamName, group.Certificate().TeamID) + fmt.Printf("%s %s [%s]\n", colorstring.Green("codesign identity:"), group.Certificate().CommonName, group.Certificate().Serial) idx := -1 - for bundleID, profile := range group.BundleIDProfileMap { + for bundleID, profile := range group.BundleIDProfileMap() { idx++ if idx == 0 { fmt.Printf("%s %s -> %s\n", colorstring.Greenf("provisioning profiles:"), profile.Name, bundleID) diff --git a/cmd/utils.go b/cmd/utils.go index ed26b9e4..1b3a3e3a 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -4,21 +4,23 @@ import ( "fmt" "strings" + "github.com/bitrise-io/go-utils/log" "github.com/bitrise-tools/go-xcode/certificateutil" "github.com/bitrise-tools/go-xcode/export" "github.com/bitrise-tools/go-xcode/profileutil" + "github.com/bitrise-tools/go-xcode/xcarchive" "github.com/pkg/errors" ) -func extractCertificatesAndProfiles(codeSignGroups ...export.IosCodeSignGroup) ([]certificateutil.CertificateInfoModel, []profileutil.ProvisioningProfileInfoModel) { +func extractCertificatesAndProfiles(codeSignGroups ...export.CodeSignGroup) ([]certificateutil.CertificateInfoModel, []profileutil.ProvisioningProfileInfoModel) { certificateMap := map[string]certificateutil.CertificateInfoModel{} profilesMap := map[string]profileutil.ProvisioningProfileInfoModel{} for _, group := range codeSignGroups { - certificate := group.Certificate + certificate := group.Certificate() certificateMap[certificate.Serial] = certificate - for _, profile := range group.BundleIDProfileMap { + for _, profile := range group.BundleIDProfileMap() { profilesMap[profile.UUID] = profile } } @@ -34,8 +36,8 @@ func extractCertificatesAndProfiles(codeSignGroups ...export.IosCodeSignGroup) ( return certificates, profiles } -func exportMethod(group export.IosCodeSignGroup) string { - for _, profile := range group.BundleIDProfileMap { +func exportMethod(group export.CodeSignGroup) string { + for _, profile := range group.BundleIDProfileMap() { return string(profile.ExportType) } return "" @@ -70,3 +72,124 @@ func mapCertificatesByTeam(certificates []certificateutil.CertificateInfoModel) } return certificatesByTeam } + +func getIOSCodeSignGroup(archivePath string, installedCertificates []certificateutil.CertificateInfoModel) (xcarchive.IosArchive, *export.IosCodeSignGroup, error) { + archive, err := xcarchive.NewIosArchive(archivePath) + if err != nil { + return xcarchive.IosArchive{}, &export.IosCodeSignGroup{}, fmt.Errorf("failed to analyze archive, error: %s", err) + } + + codeSignGroup, err := getCodeSignGroup(archive, installedCertificates, false) + if err != nil { + return xcarchive.IosArchive{}, &export.IosCodeSignGroup{}, fmt.Errorf("failed to analyze archive, error: %s", err) + } + + archiveCodeSignGroup, ok := codeSignGroup.(*export.IosCodeSignGroup) + if !ok { + return xcarchive.IosArchive{}, &export.IosCodeSignGroup{}, fmt.Errorf("failed to analyze archive, error: %s", err) + } + + return archive, archiveCodeSignGroup, nil +} + +func getMacOSCodeSignGroup(archivePath string, installedCertificates []certificateutil.CertificateInfoModel) (xcarchive.MacosArchive, *export.MacCodeSignGroup, error) { + archive, err := xcarchive.NewMacosArchive(archivePath) + if err != nil { + return xcarchive.MacosArchive{}, &export.MacCodeSignGroup{}, fmt.Errorf("failed to analyze archive, error: %s", err) + } + + codeSignGroup, err := getCodeSignGroup(archive, installedCertificates, true) + if err != nil { + return xcarchive.MacosArchive{}, &export.MacCodeSignGroup{}, fmt.Errorf("failed to analyze archive, error: %s", err) + } + + archiveCodeSignGroup, ok := codeSignGroup.(*export.MacCodeSignGroup) + if !ok { + return xcarchive.MacosArchive{}, &export.MacCodeSignGroup{}, fmt.Errorf("failed to analyze archive, error: %s", err) + } + + return archive, archiveCodeSignGroup, nil +} + +func getCodeSignGroup(archive Archive, installedCertificates []certificateutil.CertificateInfoModel, isMacArchive bool) (export.CodeSignGroup, error) { + if archive.SigningIdentity() == "" { + return nil, fmt.Errorf("no signing identity found") + } + + certificate, err := findCertificate(archive.SigningIdentity(), installedCertificates) + if err != nil { + return nil, err + } + + var archiveCodeSignGroup export.CodeSignGroup + if isMacArchive { + archiveCodeSignGroup = export.NewMacGroup(certificate, nil, archive.BundleIDProfileInfoMap()) + if err != nil { + return &export.MacCodeSignGroup{}, fmt.Errorf("failed to analyze the archive, error: %s", err) + } + + } else { + archiveCodeSignGroup = export.NewIOSGroup(certificate, archive.BundleIDProfileInfoMap()) + if err != nil { + return &export.IosCodeSignGroup{}, fmt.Errorf("failed to analyze the archive, error: %s", err) + } + } + + fmt.Println() + log.Infof("Codesign settings used for archive:") + fmt.Println() + printCodesignGroup(archiveCodeSignGroup) + + return archiveCodeSignGroup, nil +} + +func collectIpaExportSelectableCodeSignGroups(archive Archive, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel) []export.SelectableCodeSignGroup { + bundleIDEntitlemenstMap := archive.BundleIDEntitlementsMap() + + fmt.Println() + fmt.Println() + log.Infof("Targets to sign:") + fmt.Println() + for bundleID, entitlements := range bundleIDEntitlemenstMap { + fmt.Printf("- %s with %d capabilities\n", bundleID, len(entitlements)) + } + fmt.Println() + + bundleIDs := []string{} + for bundleID := range bundleIDEntitlemenstMap { + bundleIDs = append(bundleIDs, bundleID) + } + codeSignGroups := export.CreateSelectableCodeSignGroups(installedCertificates, installedProfiles, bundleIDs) + + log.Debugf("Codesign Groups:") + for _, group := range codeSignGroups { + log.Debugf(group.String()) + } + + if len(codeSignGroups) == 0 { + return []export.SelectableCodeSignGroup{} + } + + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, + export.CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlemenstMap), + ) + + // Handle if archive used NON xcode managed profile + if len(codeSignGroups) > 0 && !archive.IsXcodeManaged() { + log.Warnf("App was signed with NON xcode managed profile when archiving,") + log.Warnf("only NOT xcode managed profiles are allowed to sign when exporting the archive.") + log.Warnf("Removing xcode managed CodeSignInfo groups") + + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, + export.CreateNotXcodeManagedSelectableCodeSignGroupFilter(), + ) + } + + log.Debugf("\n") + log.Debugf("Filtered Codesign Groups:") + for _, group := range codeSignGroups { + log.Debugf(group.String()) + } + + return codeSignGroups +} diff --git a/vendor/github.com/bitrise-tools/go-xcode/certificateutil/info_model.go b/vendor/github.com/bitrise-tools/go-xcode/certificateutil/info_model.go index 941bb488..da47f6d6 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/certificateutil/info_model.go +++ b/vendor/github.com/bitrise-tools/go-xcode/certificateutil/info_model.go @@ -107,8 +107,16 @@ func NewCertificateInfosFromPKCS12(pkcs12Pth, password string) ([]CertificateInf } // InstalledCodesigningCertificateInfos ... -func InstalledCodesigningCertificateInfos() ([]CertificateInfoModel, error) { - certificates, err := InstalledCodesigningCertificates() +func InstalledCodesigningCertificateInfos(isMacOS bool) ([]CertificateInfoModel, error) { + if isMacOS { + certificates, err := InstalledMacAppStoreCertificates() + if err != nil { + return nil, err + } + return CertificateInfos(certificates), nil + } + + certificates, err := InstalledIOSCodesigningCertificates() if err != nil { return nil, err } diff --git a/vendor/github.com/bitrise-tools/go-xcode/certificateutil/util.go b/vendor/github.com/bitrise-tools/go-xcode/certificateutil/util.go index 3e450849..90973da8 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/certificateutil/util.go +++ b/vendor/github.com/bitrise-tools/go-xcode/certificateutil/util.go @@ -117,8 +117,8 @@ func normalizeFindCertificateOut(out string) ([]string, error) { return certificateContents, nil } -// InstalledCodesigningCertificates ... -func InstalledCodesigningCertificates() ([]*x509.Certificate, error) { +// InstalledIOSCodesigningCertificates ... +func InstalledIOSCodesigningCertificates() ([]*x509.Certificate, error) { certificateNames, err := InstalledCodesigningCertificateNames() if err != nil { return nil, err diff --git a/vendor/github.com/bitrise-tools/go-xcode/export/codesing_group.go b/vendor/github.com/bitrise-tools/go-xcode/export/codesing_group.go new file mode 100644 index 00000000..fa292dd1 --- /dev/null +++ b/vendor/github.com/bitrise-tools/go-xcode/export/codesing_group.go @@ -0,0 +1,13 @@ +package export + +import ( + "github.com/bitrise-tools/go-xcode/certificateutil" + "github.com/bitrise-tools/go-xcode/profileutil" +) + +// CodeSignGroup ... +type CodeSignGroup interface { + Certificate() certificateutil.CertificateInfoModel + InstallerCertificate() *certificateutil.CertificateInfoModel + BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel +} diff --git a/vendor/github.com/bitrise-tools/go-xcode/export/ios.go b/vendor/github.com/bitrise-tools/go-xcode/export/ios.go index 11305e8a..eab999e7 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/export/ios.go +++ b/vendor/github.com/bitrise-tools/go-xcode/export/ios.go @@ -10,8 +10,31 @@ import ( // IosCodeSignGroup ... type IosCodeSignGroup struct { - Certificate certificateutil.CertificateInfoModel - BundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel + certificate certificateutil.CertificateInfoModel + bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel +} + +// Certificate ... +func (signGroup *IosCodeSignGroup) Certificate() certificateutil.CertificateInfoModel { + return signGroup.certificate +} + +// InstallerCertificate ... +func (signGroup *IosCodeSignGroup) InstallerCertificate() *certificateutil.CertificateInfoModel { + return nil +} + +// BundleIDProfileMap ... +func (signGroup *IosCodeSignGroup) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { + return signGroup.bundleIDProfileMap +} + +// NewIOSGroup ... +func NewIOSGroup(certificate certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *IosCodeSignGroup { + return &IosCodeSignGroup{ + certificate: certificate, + bundleIDProfileMap: bundleIDProfileMap, + } } func createSingleWildcardGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { @@ -46,8 +69,8 @@ func createSingleWildcardGroups(group SelectableCodeSignGroup, alreadyUsedProfil } group := IosCodeSignGroup{ - Certificate: certificate, - BundleIDProfileMap: bundleIDProfileMap, + certificate: certificate, + bundleIDProfileMap: bundleIDProfileMap, } groups = append(groups, group) @@ -130,8 +153,8 @@ func createXcodeManagedGroups(group SelectableCodeSignGroup, alreadyUsedProfileU } group := IosCodeSignGroup{ - Certificate: certificate, - BundleIDProfileMap: bundleIDMannagedProfileMap, + certificate: certificate, + bundleIDProfileMap: bundleIDMannagedProfileMap, } groups = append(groups, group) } @@ -213,8 +236,8 @@ func createNotXcodeManagedGroups(group SelectableCodeSignGroup, alreadyUsedProfi } codeSignGroup := IosCodeSignGroup{ - Certificate: certificate, - BundleIDProfileMap: bundleIDNotMannagedProfileMap, + certificate: certificate, + bundleIDProfileMap: bundleIDNotMannagedProfileMap, } groups = append(groups, codeSignGroup) } @@ -255,8 +278,8 @@ func createRemainingGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUID if len(bundleIDProfileMap) == len(bundleIDs) { group := IosCodeSignGroup{ - Certificate: certificate, - BundleIDProfileMap: bundleIDProfileMap, + certificate: certificate, + bundleIDProfileMap: bundleIDProfileMap, } groups = append(groups, group) } diff --git a/vendor/github.com/bitrise-tools/go-xcode/export/mac.go b/vendor/github.com/bitrise-tools/go-xcode/export/mac.go index 2176eeed..b7b096cc 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/export/mac.go +++ b/vendor/github.com/bitrise-tools/go-xcode/export/mac.go @@ -8,9 +8,33 @@ import ( // MacCodeSignGroup ... type MacCodeSignGroup struct { - Certificate certificateutil.CertificateInfoModel - InstallerCertificate *certificateutil.CertificateInfoModel - BundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel + certificate certificateutil.CertificateInfoModel + installerCertificate *certificateutil.CertificateInfoModel + bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel +} + +// Certificate ... +func (signGroup *MacCodeSignGroup) Certificate() certificateutil.CertificateInfoModel { + return signGroup.certificate +} + +// InstallerCertificate ... +func (signGroup *MacCodeSignGroup) InstallerCertificate() *certificateutil.CertificateInfoModel { + return signGroup.installerCertificate +} + +// BundleIDProfileMap ... +func (signGroup *MacCodeSignGroup) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { + return signGroup.bundleIDProfileMap +} + +// NewMacGroup ... +func NewMacGroup(certificate certificateutil.CertificateInfoModel, installerCertificate *certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *MacCodeSignGroup { + return &MacCodeSignGroup{ + certificate: certificate, + installerCertificate: installerCertificate, + bundleIDProfileMap: bundleIDProfileMap, + } } // CreateMacCodeSignGroup ... @@ -24,7 +48,7 @@ func CreateMacCodeSignGroup(selectableGroups []SelectableCodeSignGroup, installe installerCertificates := []certificateutil.CertificateInfoModel{} for _, installerCertificate := range installedInstallerCertificates { - if installerCertificate.TeamID == group.Certificate.TeamID { + if installerCertificate.TeamID == group.certificate.TeamID { installerCertificates = append(installerCertificates, installerCertificate) } } @@ -32,15 +56,15 @@ func CreateMacCodeSignGroup(selectableGroups []SelectableCodeSignGroup, installe if len(installerCertificates) > 0 { installerCertificate := installerCertificates[0] macosCodeSignGroups = append(macosCodeSignGroups, MacCodeSignGroup{ - Certificate: group.Certificate, - InstallerCertificate: &installerCertificate, - BundleIDProfileMap: group.BundleIDProfileMap, + certificate: group.certificate, + installerCertificate: &installerCertificate, + bundleIDProfileMap: group.bundleIDProfileMap, }) } } else { macosCodeSignGroups = append(macosCodeSignGroups, MacCodeSignGroup{ - Certificate: group.Certificate, - BundleIDProfileMap: group.BundleIDProfileMap, + certificate: group.certificate, + bundleIDProfileMap: group.bundleIDProfileMap, }) } } diff --git a/vendor/github.com/bitrise-tools/go-xcode/exportoptions/exportoptions_test.go b/vendor/github.com/bitrise-tools/go-xcode/exportoptions/exportoptions_test.go index 95eac67a..bb7b3a67 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/exportoptions/exportoptions_test.go +++ b/vendor/github.com/bitrise-tools/go-xcode/exportoptions/exportoptions_test.go @@ -206,9 +206,9 @@ func TestAppStoreOptionsWriteToFile(t *testing.T) { teamID 123 uploadBitcode - + uploadSymbols - + ` require.Equal(t, desired, content) @@ -376,9 +376,9 @@ func TestNonAppStoreOptionsWriteToFile(t *testing.T) { compileBitcode - + embedOnDemandResourcesAssetPacksInBundle - + iCloudContainerEnvironment Production manifest diff --git a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go index 92a0da12..7907149a 100644 --- a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go +++ b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/macos.go @@ -60,15 +60,13 @@ func newMacosBaseApplication(path string) (macosBaseApplication, error) { entitlementsPath := filepath.Join(path, "Contents/Resources/archived-expanded-entitlements.xcent") if exist, err := pathutil.IsPathExists(entitlementsPath); err != nil { return macosBaseApplication{}, fmt.Errorf("failed to check if entitlements exists at: %s, error: %s", entitlementsPath, err) - } else if !exist { - return macosBaseApplication{}, fmt.Errorf("entitlements not exists at: %s", entitlementsPath) - } - - plist, err := plistutil.NewPlistDataFromFile(entitlementsPath) - if err != nil { - return macosBaseApplication{}, err + } else if exist { + plist, err := plistutil.NewPlistDataFromFile(entitlementsPath) + if err != nil { + return macosBaseApplication{}, err + } + entitlements = plist } - entitlements = plist } return macosBaseApplication{ diff --git a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/xcarchive.go b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/xcarchive.go new file mode 100644 index 00000000..c297a2f6 --- /dev/null +++ b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/xcarchive.go @@ -0,0 +1,41 @@ +package xcarchive + +import ( + "path/filepath" + + "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-tools/go-xcode/plistutil" +) + +// IsMacOS try to find the Contents dir under the .app/. +// If its finds it the archive is MacOs. If it does not the archive is iOS. +func IsMacOS(archPath string) (bool, error) { + log.Debugf("Checking archive is MacOS or iOS") + infoPlistPath := filepath.Join(archPath, "Info.plist") + + plist, err := plistutil.NewPlistDataFromFile(infoPlistPath) + if err != nil { + return false, err + } + + appProperties, found := plist.GetMapStringInterface("ApplicationProperties") + if !found { + return false, err + } + + applicationPath, found := appProperties.GetString("ApplicationPath") + if !found { + return false, err + } + + applicationPath = filepath.Join(archPath, "Products", applicationPath) + contentsPath := filepath.Join(applicationPath, "Contents") + + exist, err := pathutil.IsDirExists(contentsPath) + if err != nil { + return false, err + } + + return exist, nil +} diff --git a/vendor/github.com/bitrise-tools/go-xcode/xcarchive/xcarchive_test.go b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/xcarchive_test.go new file mode 100644 index 00000000..63f4231c --- /dev/null +++ b/vendor/github.com/bitrise-tools/go-xcode/xcarchive/xcarchive_test.go @@ -0,0 +1,40 @@ +package xcarchive + +import ( + "path/filepath" + "testing" +) + +func TestIsMacOS(t *testing.T) { + tests := []struct { + name string + archPath string + want bool + wantErr bool + }{ + { + name: "macOS", + archPath: filepath.Join(sampleRepoPath(t), "archives/macos.xcarchive"), + want: true, + wantErr: false, + }, + { + name: "iOS", + archPath: filepath.Join(sampleRepoPath(t), "archives/ios.xcarchive"), + want: false, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := IsMacOS(tt.archPath) + if (err != nil) != tt.wantErr { + t.Errorf("IsMacOS() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("IsMacOS() = %v, want %v", got, tt.want) + } + }) + } +}