-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extends authentication by adding options to sources and commands to specify client certificate and its password, as well as implementing new IClientCertificateProvider from choco/nuget-chocolatey to lookup those options based on the Uri requested. These options are complimentary and can be used in addition to username/password assuming the server implements it. + unit tests fix to use lowercased %ComSpec% when looking for cmd.exe
- Loading branch information
1 parent
d79e897
commit 6f79d85
Showing
13 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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
71 changes: 71 additions & 0 deletions
71
src/chocolatey/infrastructure.app/nuget/ChocolateyClientCertificateProvider.cs
This file contains 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,71 @@ | ||
// Copyright © 2011 - Present RealDimensions Software, LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.infrastructure.app.nuget | ||
{ | ||
using configuration; | ||
using NuGet; | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
class ChocolateyClientCertificateProvider : IClientCertificateProvider | ||
{ | ||
ChocolateyConfiguration _configuration; | ||
|
||
public ChocolateyClientCertificateProvider(ChocolateyConfiguration configuration) | ||
{ | ||
if (configuration == null) | ||
throw new ArgumentNullException("configuration"); | ||
_configuration = configuration; | ||
} | ||
|
||
public X509Certificate GetCertificate(Uri uri) | ||
{ | ||
if (uri.OriginalString.StartsWith(_configuration.Sources.TrimEnd('/').ToLower(),StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(_configuration.SourceCommand.Certificate)) | ||
{ | ||
this.Log().Debug("Using passed in certificate"); | ||
|
||
return new X509Certificate2(_configuration.SourceCommand.Certificate, _configuration.SourceCommand.CertificatePassword); | ||
} | ||
} | ||
|
||
return _configuration.MachineSources.Where(s => | ||
{ | ||
var sourceUri = s.Key.TrimEnd('/').ToLower(); | ||
return uri.OriginalString.ToLower().StartsWith(sourceUri) | ||
&& !string.IsNullOrWhiteSpace(s.Certificate); | ||
}) | ||
.Select(s => | ||
{ | ||
this.Log().Debug("Using machine source certificate"); | ||
try { | ||
var decrypted = string.IsNullOrEmpty(s.EncryptedCertificatePassword) | ||
? string.Empty | ||
: NugetEncryptionUtility.DecryptString(s.EncryptedCertificatePassword); | ||
return new X509Certificate2(s.Certificate, decrypted); | ||
} catch(Exception x) | ||
{ | ||
this.Log().Error("Unable to load the certificate: {0}", x); | ||
return null; | ||
} | ||
}) | ||
.FirstOrDefault(); | ||
} | ||
} | ||
} |
This file contains 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 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