-
Notifications
You must be signed in to change notification settings - Fork 379
Add Certificate Management support over Azure IoT Hub #1223
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
Open
ewertons
wants to merge
24
commits into
feature/iot-csr-preview
Choose a base branch
from
ewertons/iot-csr-preview
base: feature/iot-csr-preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8359207
Partial work for CSR over IoT Hub
ewertons 3c65f26
Fix documentation
f4f2115
Implement async version of send_certificate_signing_request
bbbea0c
Delete CSR sample for DPS-only, under azure-iot-device
8aab8d4
Several little fixes
3b89ed9
Partial changes to implement CSR/IoT
f13c63b
Add stages, ops, events for CertificateSigningRequest
8cdb873
Complete CSR functionality
c5876b6
Update code documentation for CSR
526fd2c
Cleanup certificate_issuance.py (#1)
861ccd4
Add reconnection to certificate_issuance.py, cleanup
340d97a
Update CSR sample and its documentation
e63dc1d
Fix use of iothub_csr_data variable
76cea5c
Add cert mgmt pipeline yaml
ewertons 401577b
Rename certificate_management.md -> readme.md
ewertons 07179fa
Address CR comments (change env var name)
ewertons 7b7b5f3
Add credentialPolicyName on enrollment creation requests
ewertons 158ee6e
Remove previous ClientCertificateIssuancePolicy construct
ewertons e1beadc
Add env var generation cmdlet, re-enable build and tests
ewertons f831984
Pass private key password only if defined as a non-empty string
ewertons 7da5ed4
Adjust Dps service API version for cert mgmt (2021-10-01)
ewertons b578023
Adjust Dps service API version for cert mgmt (try 2025-07-01-preview)
ewertons a171acb
Add e2e tests for certificate signing request
ewertons bde4ea9
device_client.send_certificate_signing_request to take args directly
ewertons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
azure-iot-device/azure/iot/device/iothub/models/certificate_signing_request.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # ------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| """This module contains a class representing messages that are sent or received. | ||
| """ | ||
|
|
||
|
|
||
| class CertificateSigningRequest(object): | ||
| """Represents a Certificate Signing Request message to Azure IoT Hub | ||
|
|
||
| :ivar csr: The base64-encoded certificate signing request. | ||
| :ivar replace: Replace any active credential operation for this device. | ||
| """ | ||
|
|
||
| def __init__(self, csr, replace): | ||
| """ | ||
| Initializer for CertificateSigningRequest | ||
|
|
||
| :param str csr: The base64-encoded certificate signing request. | ||
| :param str replace: Replace any active credential operation for this device. | ||
| """ | ||
| self.id = None # The device id, filled internally by the pipeline configuration. | ||
| self.csr = csr | ||
| self.replace = replace | ||
|
|
||
| def __str__(self): | ||
| return str(self.csr) | ||
|
|
||
| def to_dict(obj): | ||
| data = obj.__dict__.copy() | ||
ewertons marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return data | ||
|
|
||
|
|
||
| class CertificateSigningResponse(object): | ||
| """Represents a Certificate Signing Response message from Azure IoT Hub | ||
|
|
||
| :ivar status_code: The result code for the certificate signing request. | ||
| :ivar certificates: An array with the base64-encoded issued certificate chain (leaf, intermediate and root, in this order). | ||
| """ | ||
|
|
||
| def __init__(self, status_code, certificates): | ||
| """ | ||
| Initializer for CertificateSigningResponse | ||
|
|
||
| :param status_code: The result code for the certificate signing request. | ||
| :param certificates: An array with the base64-encoded issued certificate chain (leaf, intermediate and root, in this order). | ||
| """ | ||
| self.status_code = status_code | ||
| self.certificates = certificates | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| # Feature names | ||
| C2D_MSG = "c2d" | ||
| CSR = "csr" | ||
| INPUT_MSG = "input" | ||
| METHODS = "methods" | ||
| TWIN = "twin" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,71 @@ def is_method_topic(topic): | |
| return False | ||
|
|
||
|
|
||
| def get_certificate_signing_response_topic_for_subscribe(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style nit: this module is organized by subscribe/publish/is_x, not by feature grouping, so these functions should be interspersed as per the existing pattern. |
||
| """ | ||
| :return: The topic for Certificate Signing Response messages. It is of the format | ||
| "$iothub/credentials/res/#" | ||
| """ | ||
| return "$iothub/credentials/res/#" | ||
|
|
||
|
|
||
| def get_certificate_signing_request_topic_for_publish(request_id): | ||
| """ | ||
| :return: The topic for Certificate Signing Request messages. It is of the format | ||
| "$iothub/credentials/POST/issueCertificate/?$rid={request_id}" | ||
| """ | ||
| return "$iothub/credentials/POST/issueCertificate/?$rid={request_id}".format( | ||
| request_id=request_id | ||
| ) | ||
|
|
||
|
|
||
| def is_certificate_signing_response_topic(topic): | ||
| """ | ||
| Topics for certificate signing responses are of the following format: | ||
| "$iothub/credentials/res/{status}/?$rid={request_id}" | ||
|
|
||
| :param str topic: The topic string. | ||
| """ | ||
| return topic.startswith("$iothub/credentials/res/") | ||
|
|
||
|
|
||
| def get_certificate_signing_response_request_id_from_topic(topic): | ||
| """ | ||
| Extract the request id from the certificate signing response topic. | ||
| Topics for certificate signing responses are of the following format: | ||
| "$iothub/credentials/res/{status}/?$rid={request_id}" | ||
|
|
||
| :param str topic: The topic string | ||
| """ | ||
| if is_certificate_signing_response_topic(topic): | ||
| parts = topic.split("/") | ||
| if len(parts) == 5: | ||
| properties = _extract_properties(topic.split("?")[1]) | ||
| return properties["rid"] | ||
| else: | ||
| raise ValueError("topic has incorrect format") | ||
| else: | ||
| raise ValueError("topic has incorrect format") | ||
|
|
||
|
|
||
| def get_certificate_signing_response_status_code_from_topic(topic): | ||
| """ | ||
| Extract the status-code from the certificate signing response topic. | ||
| Topics for certificate signing responses are of the following format: | ||
| "$iothub/credentials/res/{status-code}/?$rid={request_id}" | ||
|
|
||
| :param str topic: The topic string | ||
| """ | ||
| if is_certificate_signing_response_topic(topic): | ||
| parts = topic.split("/") | ||
| if len(parts) == 5: | ||
| return urllib.parse.unquote(parts[3]) | ||
| else: | ||
| raise ValueError("topic has incorrect format") | ||
| else: | ||
| raise ValueError("topic has incorrect format") | ||
|
|
||
|
|
||
| def is_twin_response_topic(topic): | ||
| """Topics for twin responses are of the following format: | ||
| $iothub/twin/res/{status}/?$rid={rid} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the string really the request? And I don't quite get what
replaceis. These parameters are much less explicit in name and documentation than any other API.