Azure / iot-identity-service

Source of the Azure IoT Identity Service and related services.
MIT License
37 stars 46 forks source link

[certd] Fix panic when truncating certificate CN #472

Closed onalante-msft closed 1 year ago

onalante-msft commented 1 year ago

String::truncate panics when the truncation point is not at a valid UTF-8 character boundary. To fix this, take at most 64 characters from the parsed CN string before setting the X509 CN field.

onalante-msft commented 1 year ago

I wonder if it'd be more appropriate to split at graphemes (unicode-segmentation) instead of codepoints.

The specification says the length is measured in "characters", but I assume this means code points: see the bottom of page 124 here. This is not a particularly performance-sensitive code path, so I will just do a .chars().take(64).collect::<String>().