Skip to content

Conversation

godrei
Copy link
Contributor

@godrei godrei commented Sep 12, 2025

No description provided.

@bitrise-ip-bot
Copy link
Contributor

bitrise-ip-bot commented Sep 12, 2025

Summary

This PR migrates utility packages from v1 to v2 module structure, consolidating certificateutil, profileutil, export, exportoptions, and plistutil packages into the main repository. The migration includes updating import paths across the codebase and replacing external dependencies like howett.net/plist with github.com/bitrise-io/go-plist.

Walkthrough

File Summary
certificateutil/, profileutil/, export/, exportoptions/, plistutil/* Added new utility packages migrated from v1
artifacts/, autocodesign/, codesign/, exportoptionsgenerator/, metaparser/, xcarchive/ Updated import paths from v1 to v2 packages
go.mod, go.sum Updated dependencies, removed pkg/errors, added go-plist
_test.go, mocks/ Updated test files and mocks for new package structure

Copy link
Contributor

@bitrise-ip-bot bitrise-ip-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review. Please review it carefully.

Actionable comments posted: 5

Comment on lines +91 to +95
for _, certificate := range certificates {
if certificate != nil {
infos = append(infos, NewCertificateInfo(*certificate, nil))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Potential nil pointer dereference: The code checks if certificate != nil but then immediately dereferences it with *certificate. If the certificate pointer becomes nil between the check and dereference due to concurrent access, this could cause a panic.

🔄 Suggestion:

Suggested change
for _, certificate := range certificates {
if certificate != nil {
infos = append(infos, NewCertificateInfo(*certificate, nil))
}
}
for _, certificate := range certificates {
if certificate != nil {
cert := *certificate
infos = append(infos, NewCertificateInfo(cert, nil))
}
}

Comment on lines +108 to +112
for _, certificate := range certificates {
if certificate != nil {
infos = append(infos, NewCertificateInfo(*certificate, nil))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Potential nil pointer dereference: The code checks if certificate != nil but then immediately dereferences it with *certificate. If the certificate pointer becomes nil between the check and dereference due to concurrent access, this could cause a panic.

🔄 Suggestion:

Suggested change
for _, certificate := range certificates {
if certificate != nil {
infos = append(infos, NewCertificateInfo(*certificate, nil))
}
}
for _, certificate := range certificates {
if certificate != nil {
cert := *certificate
infos = append(infos, NewCertificateInfo(cert, nil))
}
}

Comment on lines +29 to +31
if len(certificates) != len(privateKeys) {
return nil, errors.New("pkcs12: different number of certificates and private keys found")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Inconsistent error handling: The function checks the length of certificates and privateKeys slices without first validating that both slices are non-nil, which could cause a panic if either slice is nil.

🔄 Suggestion:

Suggested change
if len(certificates) != len(privateKeys) {
return nil, errors.New("pkcs12: different number of certificates and private keys found")
}
if certificates == nil || privateKeys == nil {
return nil, errors.New("pkcs12: certificates or private keys slice is nil")
}
if len(certificates) != len(privateKeys) {
return nil, errors.New("pkcs12: different number of certificates and private keys found")
}

Comment on lines +117 to +118
pattern := `(?s)(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)`
matches := regexp.MustCompile(pattern).FindAllString(out, -1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Regex compilation inefficiency: The regex pattern is compiled inside the function on every call. For better performance and to avoid potential regex compilation errors at runtime, this should be compiled once as a package-level variable.

🔄 Suggestion:

Suggested change
pattern := `(?s)(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)`
matches := regexp.MustCompile(pattern).FindAllString(out, -1)
var certificatePattern = regexp.MustCompile(`(?s)(-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----)`)
func normalizeFindCertificateOut(out string) ([]string, error) {
certificateContents := []string{}
matches := certificatePattern.FindAllString(out, -1)

missingEntitlements := []string{}

for key := range targetEntitlements {
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Potential nil pointer dereference: The code accesses profileutil.KnownProfileCapabilitiesMap[profileType][key] without checking if profileutil.KnownProfileCapabilitiesMap[profileType] exists first. This will cause a panic if an unsupported profileType (like ProfileTypeTvOs) is passed.

🔄 Suggestion:

Suggested change
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key]
profileCapabilities, exists := profileutil.KnownProfileCapabilitiesMap[profileType]
if !exists {
continue
}
_, known := profileCapabilities[key]

Copy link
Contributor

@bitrise-ip-bot bitrise-ip-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review. Please review it carefully.

Actionable comments posted: 3

}

func installedCodesigningCertificateNamesFromOutput(out string) ([]string, error) {
pettern := `^[0-9]+\) (?P<hash>.*) "(?P<name>.*)"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Variable name typo: 'pettern' should be 'pattern'. This will cause a compilation error as the variable is used on the next line but never declared correctly.

🔄 Suggestion:

Suggested change
pettern := `^[0-9]+\) (?P<hash>.*) "(?P<name>.*)"`
pattern := `^[0-9]+\) (?P<hash>.*) "(?P<name>.*)"`

missingEntitlements := []string{}

for key := range targetEntitlements {
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Potential map access panic when profileType doesn't exist as a key in KnownProfileCapabilitiesMap. If an unsupported profile type (like ProfileTypeTvOs) is passed, this will cause a runtime panic when trying to access the nested map.

🔄 Suggestion:

Suggested change
_, known := profileutil.KnownProfileCapabilitiesMap[profileType][key]
capabilitiesMap, exists := profileutil.KnownProfileCapabilitiesMap[profileType]
if !exists {
continue
}
_, known := capabilitiesMap[key]

return nil, err
}

pattern := filepath.Join(pathutil.EscapeGlobPath(absProvProfileDirPath), "*"+ext)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Bug

Function pathutil.EscapeGlobPath does not exist in the github.com/bitrise-io/go-utils/pathutil package. This will cause a compilation error when the code is built.

🔄 Suggestion:

Suggested change
pattern := filepath.Join(pathutil.EscapeGlobPath(absProvProfileDirPath), "*"+ext)
pattern := filepath.Join(absProvProfileDirPath, "*"+ext)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants