-
Notifications
You must be signed in to change notification settings - Fork 61
Enable Certificate download (.cer & .pfx) #648
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
Draft
nchapagain001
wants to merge
22
commits into
main
Choose a base branch
from
users/nchapagain/EnableCertDownload
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b94ec7c
main changes
6fb81c4
Minor fix
02a029a
Allowing cert to be exported even after loading.
39bf1f0
Adding doc
b5a8e35
Adding ut
50aff11
Adding comments
3db2a7d
Addressing PR comments
989f114
UT fix
f991c10
Merge branch 'main' into users/nchapagain/EnableCertDownload
nchapagain001 c3a9d24
main changes
032fb2b
Minor fix
18ccb60
Allowing cert to be exported even after loading.
340cfc6
Adding doc
fa57893
Adding ut
51a4e62
Adding comments
cb9d335
Addressing PR comments
08a9050
UT fix
e8e3ced
public -> protected
9ae2ef0
foo
7c004c1
Merge branch 'main' into users/nchapagain/EnableCertDownload
nchapagain001 2236a50
Merge branch 'main' into users/nchapagain/EnableCertDownload
nchapagain001 3e24550
Fixing profile
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
39 changes: 39 additions & 0 deletions
39
src/VirtualClient/VirtualClient.Core/Identity/CertificateLoaderHelper.cs
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,39 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| namespace VirtualClient.Identity | ||
| { | ||
| using System.Security.Cryptography.X509Certificates; | ||
|
|
||
| /// <summary> | ||
| /// Certificate Loader to cleanly handle differences in .NET versions for loading certificates from byte arrays. | ||
| /// </summary> | ||
| internal static class CertificateLoaderHelper | ||
| { | ||
| internal static X509Certificate2 LoadPublic(byte[] cerBytes) | ||
| { | ||
| #if NET9_0_OR_GREATER | ||
| return X509CertificateLoader.LoadCertificate(cerBytes); | ||
| #else | ||
| return new X509Certificate2(cerBytes); | ||
| #endif | ||
| } | ||
|
|
||
| internal static X509Certificate2 LoadPkcs12( | ||
| byte[] pfxBytes, | ||
| string password, | ||
| X509KeyStorageFlags flags) | ||
| { | ||
| #if NET9_0_OR_GREATER | ||
| return X509CertificateLoader.LoadPkcs12( | ||
| pfxBytes, | ||
| password, | ||
| flags); | ||
| #else | ||
| return new X509Certificate2( | ||
| pfxBytes, | ||
| password, | ||
| flags); | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
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.
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.
I don't think we will need this class. This source code should just be located in the Component that is using it. If it is used in more than 1 Component, we should just use extension methods. The source code location/folder is fine. Maybe a CertificateManagerExtensions class.