Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for smartcard identities #1181

Conversation

thiagohmcruz
Copy link
Contributor

@thiagohmcruz thiagohmcruz commented Jun 1, 2021

Resolves #1180

So signed builds are possible when using CryptoTokenKit based solutions to store signing identities (e.g. Signing Manager). When storing identities that way security find-identity won't be able to find them.

The proposal in this PR is to append to the current list of SHA1 the values for the smartcard identities found on the system. Please see detailed explanation in the linked issue #1180 for why system_profiler SPSmartCardsDataType -xml is possibly a good solution here.

I'm also 100% open to changing the approach if you spot any issues with this implementation!

Note that the behaviour triggered by setting the --ios_signing_cert_name flag continues to exist: try to find a signing identity by name and return it's SHA1 or return all SHA1 found if the flag is not provided.

@google-cla
Copy link

google-cla bot commented Jun 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Jun 1, 2021
@thiagohmcruz thiagohmcruz force-pushed the thiago/read-smartcard-identities branch from 25830b6 to aade1ea Compare June 1, 2021 19:42
@google-cla
Copy link

google-cla bot commented Jun 1, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@thiagohmcruz thiagohmcruz force-pushed the thiago/read-smartcard-identities branch from aade1ea to 6cfb372 Compare June 3, 2021 15:14
@google-cla
Copy link

google-cla bot commented Jun 3, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@brentleyjones
Copy link
Collaborator

Just an FYI, we can't really review the change until the CLA is signed

@thiagohmcruz
Copy link
Contributor Author

Just an FYI, we can't really review the change until the CLA is signed

Yep! Dealing with this internally, I believe the setup is done I might have to re-open the PR though (not 100% sure I'll ask). Working on making this reviewable as we speak.

@thiagohmcruz
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Jun 3, 2021
@thiagohmcruz thiagohmcruz marked this pull request as ready for review June 3, 2021 16:24
@timsutton
Copy link
Contributor

One thing we probably will want to establish is if this constrains macOS versions that could be supported. Do we care about supporting anything older than Mojave (10.14) or Catalina (10.15), for example? That might help inform the logic in what's being searched for in the system_profiler output.

@thiagohmcruz
Copy link
Contributor Author

One thing we probably will want to establish is if this constrains macOS versions that could be supported. Do we care about supporting anything older than Mojave (10.14) or Catalina (10.15), for example? That might help inform the logic in what's being searched for in the system_profiler output.

@timsutton wouldn't be enough to fallback to empty array when searching for AVAIL_SMARTCARDS_TOKEN and AVAIL_SMARTCARDS_KEYCHAIN?

Not sure how I would go about checking what is available in each OS version, is there an easy way to do that that I'm not aware of?

@timsutton
Copy link
Contributor

timsutton commented Jun 3, 2021

@timsutton wouldn't be enough to fallback to empty array when searching for AVAIL_SMARTCARDS_TOKEN and AVAIL_SMARTCARDS_KEYCHAIN?

Yes, that seems like just a good defense anyway. I did just check a 10.14 system and these two keys are there as well (full output here.) The code works there as well, just returning an empty [] as expected on a vanilla system.

Another bit of context I'd forgotten to add in this PR is that persistent tokens (as would be used in Signing Manager or other apps providing a token via an app extension) only showed up in 10.15.4. Prior to then it could have only been possible using physically-insertable smartcards, or that's my understanding anyway.

@thiagohmcruz thiagohmcruz force-pushed the thiago/read-smartcard-identities branch from 122d201 to 2b78ab2 Compare June 4, 2021 03:27
@thiagohmcruz
Copy link
Contributor Author

@brentleyjones sorry about the direct ping! Just wanted to check if you know who I should bug to get some reviews?

Copy link
Contributor

@segiddins segiddins left a comment

Choose a reason for hiding this comment

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

It would be awesome to add some test coverage for the xml parsing being done, because some of it gets a bit complicated, but since there's no coverage for this tool at all yet 😶

], inputstr=cert, raise_on_failure=True)
subject = subject.strip().split('/')
cert_cn = [f for f in subject if "CN=" in f][0]
cert_cn = cert_cn.replace("CN=", "")
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible this could be None ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess we should assume it's possible. I'll add the check instead of accessing [0] here and make it return None. Tested locally and is all good since at the call site the comparison is if identity == common_name:

if len(tokens) == 0:
return []

tokens = tokens[0].get("_items", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

is only checking the first match an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the output it's not an issue, all tokens will be located under _items

xml = plistlib.loads(str.encode(xml))
if len(xml) == 0:
return []
xml = xml[0].get("_items", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to consider all entries in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the top level _items that contains all the info we need. I think it's safe to ignore the rest for the purpose of this function

@thiagohmcruz thiagohmcruz force-pushed the thiago/read-smartcard-identities branch from 2b78ab2 to 7458aaa Compare June 4, 2021 20:02
@thiagohmcruz
Copy link
Contributor Author

@segiddins should be good to :shipit:?

@thiagohmcruz
Copy link
Contributor Author

@brentleyjones, @keith mind taking a look? Let me know if there's anything else you think I should be addressing here 🙏

Copy link
Contributor

@jerrymarino jerrymarino left a comment

Choose a reason for hiding this comment

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

A few inline for now, but overall really excited to see smartcard support in Bazel - this has been a long time coming 👍 One alternative to start using this could be to have a different codesigning tool in rules_ios

tools/codesigningtool/codesigningtool.py Outdated Show resolved Hide resolved
tools/codesigningtool/codesigningtool.py Outdated Show resolved Hide resolved
@thiagohmcruz thiagohmcruz force-pushed the thiago/read-smartcard-identities branch from 7458aaa to 79798c4 Compare June 8, 2021 18:21
@thiagohmcruz
Copy link
Contributor Author

A few inline for now, but overall really excited to see smartcard support in Bazel - this has been a long time coming 👍 One alternative to start using this could be to have a different codesigning tool in rules_ios

@jerrymarino will work on bumping rules_ios next, we might be able to use it as is. Just needing to rebase you rules_swift fork I think. Still not sure what changes will be necessary but will look into it next.

@brentleyjones brentleyjones merged commit fe15e1c into bazelbuild:master Jun 8, 2021
@brentleyjones
Copy link
Collaborator

Thanks @thiagohmcruz!

@thiagohmcruz
Copy link
Contributor Author

Thx you all for the feedback here!

@jerrymarino
Copy link
Contributor

@thiagohmcruz ok that sounds good to me. If we're blocked on the rules_swift PRs I'll ready a PR to get rid of the fork.

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

Successfully merging this pull request may close these issues.

Support for smartcard signing identities
5 participants