Skip to content

Commit 4fad9fd

Browse files
BirmacherAkosgodrei
authored andcommitted
Mac os fix (#83)
* export methods for MacOS (+1 squashed commit) Squashed commits: [2489af1] MacOS fix (+1 squashed commit) Squashed commits: [b1229e9] - * Installer certs * installer cert clean (+2 squashed commits) Squashed commits: [caa3bab] removed some IPA [3eeebc2] exportCerts: MacOS - The installer certificate export option only available after the app-store certificate export. * typo fix
1 parent 94eac53 commit 4fad9fd

File tree

13 files changed

+581
-191
lines changed

13 files changed

+581
-191
lines changed

Gopkg.lock

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/scan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (e ArchiveError) Error() string {
5050
------------------------------` + `
5151
First of all ` + colorstring.Red("please make sure that you can Archive your app from "+e.tool+".") + `
5252
codesigndoc only works if you can archive your app from ` + string(e.tool) + `.
53-
If you can, and you get a valid IPA file if you export from ` + string(e.tool) + `,
53+
If you can, and you get a valid .ipa/.app file if you export from ` + string(e.tool) + `,
5454
` + colorstring.Red("please create an issue") + ` on GitHub at: https://github.com/bitrise-tools/codesigndoc/issues
5555
with as many details & logs as you can share!
5656
------------------------------

codesigndoc/archive.go

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
package codesigndoc
22

33
import (
4-
"fmt"
5-
6-
"github.com/bitrise-tools/go-xcode/certificateutil"
7-
"github.com/bitrise-tools/go-xcode/export"
8-
"github.com/bitrise-tools/go-xcode/xcarchive"
4+
"github.com/bitrise-tools/go-xcode/plistutil"
5+
"github.com/bitrise-tools/go-xcode/profileutil"
96
)
107

11-
// analyzeArchive opens the generated archive and returns a codesign group, which holds the archive signing options
12-
func analyzeArchive(archive xcarchive.IosArchive, installedCertificates []certificateutil.CertificateInfoModel) (export.IosCodeSignGroup, error) {
13-
signingIdentity := archive.SigningIdentity()
14-
bundleIDProfileInfoMap := archive.BundleIDProfileInfoMap()
15-
16-
if signingIdentity == "" {
17-
return export.IosCodeSignGroup{}, fmt.Errorf("no signing identity found")
18-
}
19-
20-
certificate, err := findCertificate(signingIdentity, installedCertificates)
21-
if err != nil {
22-
return export.IosCodeSignGroup{}, err
23-
}
24-
25-
return export.IosCodeSignGroup{
26-
Certificate: certificate,
27-
BundleIDProfileMap: bundleIDProfileInfoMap,
28-
}, nil
8+
// Archive ...
9+
type Archive interface {
10+
BundleIDEntitlementsMap() map[string]plistutil.PlistData
11+
IsXcodeManaged() bool
12+
SigningIdentity() string
13+
BundleIDProfileInfoMap() map[string]profileutil.ProvisioningProfileInfoModel
2914
}

codesigndoc/certificates.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ func isDistributionCertificate(cert certificateutil.CertificateInfoModel) bool {
8181
return false
8282
}
8383

84+
// isInstallerCertificate returns true if the given certificate
85+
// is an installer certificate
86+
func isInstallerCertificate(cert certificateutil.CertificateInfoModel) bool {
87+
if strings.Contains(strings.ToLower(cert.CommonName), strings.ToLower("installer")) {
88+
return true
89+
}
90+
91+
return false
92+
}
93+
8494
// mapCertificatesByTeam returns a certificate list mapped by the certificate's team (in teamdID - teamName format)
8595
func mapCertificatesByTeam(certificates []certificateutil.CertificateInfoModel) map[string][]certificateutil.CertificateInfoModel {
8696
certificatesByTeam := map[string][]certificateutil.CertificateInfoModel{}

codesigndoc/codesigndoc.go

Lines changed: 122 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package codesigndoc
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67

7-
"github.com/bitrise-io/go-utils/colorstring"
8-
98
"github.com/bitrise-io/go-utils/command"
109
"github.com/bitrise-io/go-utils/log"
1110
"github.com/bitrise-io/goinp/goinp"
1211
"github.com/bitrise-tools/codesigndoc/bitriseio"
1312
"github.com/bitrise-tools/go-xcode/certificateutil"
13+
"github.com/bitrise-tools/go-xcode/export"
1414
"github.com/bitrise-tools/go-xcode/profileutil"
1515
"github.com/bitrise-tools/go-xcode/xcarchive"
1616
)
@@ -19,72 +19,63 @@ const collectCodesigningFilesInfo = `To collect available code sign files, we se
1919
- which has installed Codesign Identity in your Keychain"
2020
- which can provision your application target's bundle ids"
2121
- which has the project defined Capabilities set"
22-
- which matches to the selected ipa export method"
22+
- which matches to the selected export method"
2323
`
2424

2525
// ExportCodesignFiles exports the codesigning files required to create an xcode archive
2626
// and exports the codesigning files for the specified export method
2727
func ExportCodesignFiles(archivePath, outputDirPath string, certificatesOnly bool, askForPassword bool) (bool, bool, error) {
28-
certificates, err := installedCertificates(IOSCertificate)
28+
// Find out the XcArchive type
29+
isMacOs, err := xcarchive.IsMacOS(archivePath)
2930
if err != nil {
30-
return false, false, fmt.Errorf("failed to list installed code signing identities, error: %s", err)
31+
return false, false, err
3132
}
3233

33-
profiles, err := profileutil.InstalledProvisioningProfileInfos(profileutil.ProfileTypeIos)
34-
if err != nil {
35-
return false, false, fmt.Errorf("failed to list installed provisioning profiles, error: %s", err)
34+
// Set up the XcArchive type for certs and profiles.
35+
certificateType := IOSCertificate
36+
profileType := profileutil.ProfileTypeIos
37+
if isMacOs {
38+
certificateType = MacOSCertificate
39+
profileType = profileutil.ProfileTypeMacOs
3640
}
3741

38-
// archive code sign settings
39-
archive, err := xcarchive.NewIosArchive(archivePath)
42+
// Certificates
43+
certificates, err := installedCertificates(certificateType)
4044
if err != nil {
41-
return false, false, fmt.Errorf("failed to analyze archive, error: %s", err)
45+
return false, false, fmt.Errorf("failed to list installed code signing identities, error: %s", err)
4246
}
4347

44-
archiveCodeSignGroup, err := analyzeArchive(archive, certificates)
48+
installerCertificates, err := certificateutil.InstalledInstallerCertificateInfos()
4549
if err != nil {
46-
return false, false, fmt.Errorf("failed to analyze the archive, error: %s", err)
50+
return false, false, fmt.Errorf("failed to list installed code signing identities, error: %s", err)
4751
}
4852

49-
fmt.Println()
50-
log.Infof("Codesign settings used for archive:")
51-
fmt.Println()
52-
printCodesignGroup(archiveCodeSignGroup)
53-
54-
// ipa export code sign settings
55-
fmt.Println()
56-
fmt.Println()
57-
log.Printf("🔦 Analyzing the archive, to get ipa export code signing settings...")
58-
59-
certificatesToExport := []certificateutil.CertificateInfoModel{}
60-
profilesToExport := []profileutil.ProvisioningProfileInfoModel{}
61-
62-
if certificatesOnly {
63-
ipaExportCertificate, err := collectIpaExportCertificate(archiveCodeSignGroup.Certificate, certificates)
64-
if err != nil {
65-
return false, false, err
66-
}
53+
log.Debugf("Installed certificates:")
54+
for _, installedCertificate := range certificates {
55+
log.Debugf(installedCertificate.String())
56+
}
6757

68-
certificatesToExport = append(certificatesToExport, archiveCodeSignGroup.Certificate, ipaExportCertificate)
69-
} else {
70-
ipaExportCodeSignGroups, err := collectIpaExportCodeSignGroups(archive, certificates, profiles)
71-
if err != nil {
72-
return false, false, err
73-
}
58+
// Profiles
59+
profiles, err := profileutil.InstalledProvisioningProfileInfos(profileType)
60+
if err != nil {
61+
return false, false, fmt.Errorf("failed to list installed provisioning profiles, error: %s", err)
62+
}
7463

75-
if len(ipaExportCodeSignGroups) == 0 {
76-
errorString := "\n🚨 " + colorstring.Red("Failed to collect codesigning files for the selected distribution type.\n") +
77-
colorstring.Yellow("Export an ipa with the same export method which code signing files you want to collect (e.g app-store if you want to collect the code signing files for app-store distribution) in your local xcode and run codesigndoc again.\n") +
78-
colorstring.Yellow("If the tool fails please report the issue with the codesigndoc log and the local ipa exportOptions.plist")
79-
return false, false, fmt.Errorf(errorString)
80-
}
64+
log.Debugf("Installed profiles:")
65+
for _, profileInfo := range profiles {
66+
log.Debugf(profileInfo.String(certificates...))
67+
}
8168

82-
codeSignGroups := append(ipaExportCodeSignGroups, archiveCodeSignGroup)
83-
certificates, profiles := extractCertificatesAndProfiles(codeSignGroups...)
84-
certificatesToExport = append(certificatesToExport, certificates...)
85-
profilesToExport = append(profilesToExport, profiles...)
69+
certificatesToExport, profilesToExport, err := getFilesToExport(archivePath, certificates, installerCertificates, profiles, certificatesOnly)
70+
if err != nil {
71+
return false, false, err
8672
}
8773

74+
// export code sign settings
75+
fmt.Println()
76+
fmt.Println()
77+
log.Printf("🔦 Analyzing the archive, to get export code signing settings...")
78+
8879
if err := collectAndExportIdentities(certificatesToExport, outputDirPath, askForPassword); err != nil {
8980
return false, false, err
9081
}
@@ -122,3 +113,87 @@ func ExportCodesignFiles(archivePath, outputDirPath string, certificatesOnly boo
122113

123114
return certsUploaded, provProfilesUploaded, nil
124115
}
116+
117+
func getFilesToExport(archivePath string, installedCertificates []certificateutil.CertificateInfoModel, installedInstallerCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel, certificatesOnly bool) ([]certificateutil.CertificateInfoModel, []profileutil.ProvisioningProfileInfoModel, error) {
118+
macOS, err := xcarchive.IsMacOS(archivePath)
119+
if err != nil {
120+
return nil, nil, err
121+
}
122+
123+
var certificate certificateutil.CertificateInfoModel
124+
var archive Archive
125+
var achiveCodeSignGroup export.CodeSignGroup
126+
127+
if macOS {
128+
archive, achiveCodeSignGroup, err = getMacOSCodeSignGroup(archivePath, installedCertificates)
129+
if err != nil {
130+
return nil, nil, err
131+
}
132+
certificate = achiveCodeSignGroup.Certificate()
133+
} else {
134+
archive, achiveCodeSignGroup, err = getIOSCodeSignGroup(archivePath, installedCertificates)
135+
if err != nil {
136+
return nil, nil, err
137+
}
138+
certificate = achiveCodeSignGroup.Certificate()
139+
}
140+
141+
certificatesToExport := []certificateutil.CertificateInfoModel{}
142+
profilesToExport := []profileutil.ProvisioningProfileInfoModel{}
143+
144+
if certificatesOnly {
145+
exportCertificate, err := collectExportCertificate(macOS, certificate, installedCertificates, installedInstallerCertificates)
146+
if err != nil {
147+
return nil, nil, err
148+
}
149+
150+
certificatesToExport = append(certificatesToExport, certificate)
151+
certificatesToExport = append(certificatesToExport, exportCertificate...)
152+
} else {
153+
certificatesToExport, profilesToExport, err = collectCertificatesAndProfiles(archive, certificate, installedCertificates, installedProfiles, certificatesToExport, profilesToExport, achiveCodeSignGroup)
154+
if err != nil {
155+
return nil, nil, err
156+
}
157+
}
158+
159+
return certificatesToExport, profilesToExport, nil
160+
}
161+
162+
func collectCertificatesAndProfiles(archive Archive, certificate certificateutil.CertificateInfoModel,
163+
installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel,
164+
certificatesToExport []certificateutil.CertificateInfoModel, profilesToExport []profileutil.ProvisioningProfileInfoModel,
165+
achiveCodeSignGroup export.CodeSignGroup) ([]certificateutil.CertificateInfoModel, []profileutil.ProvisioningProfileInfoModel, error) {
166+
167+
_, macOS := archive.(xcarchive.MacosArchive)
168+
169+
groups, err := collectExportCodeSignGroups(archive, installedCertificates, installedProfiles)
170+
if err != nil {
171+
return nil, nil, err
172+
}
173+
174+
var exportCodeSignGroups []export.CodeSignGroup
175+
for _, group := range groups {
176+
if macOS {
177+
exportCodeSignGroup, ok := group.(*export.MacCodeSignGroup)
178+
if ok {
179+
exportCodeSignGroups = append(exportCodeSignGroups, exportCodeSignGroup)
180+
}
181+
} else {
182+
exportCodeSignGroup, ok := group.(*export.IosCodeSignGroup)
183+
if ok {
184+
exportCodeSignGroups = append(exportCodeSignGroups, exportCodeSignGroup)
185+
}
186+
}
187+
}
188+
189+
if len(exportCodeSignGroups) == 0 {
190+
return nil, nil, errors.New("no export code sign groups collected")
191+
}
192+
193+
codeSignGroups := append(exportCodeSignGroups, achiveCodeSignGroup)
194+
certificates, profiles := extractCertificatesAndProfiles(codeSignGroups...)
195+
certificatesToExport = append(certificatesToExport, certificates...)
196+
profilesToExport = append(profilesToExport, profiles...)
197+
198+
return certificatesToExport, profilesToExport, nil
199+
}

0 commit comments

Comments
 (0)