-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
122 additions
and
137 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
48 changes: 48 additions & 0 deletions
48
src/VaultSharp/V1/AuthMethods/CloudFoundry/CloudFoundrySignatureProvider.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,48 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using Org.BouncyCastle.Asn1; | ||
using Org.BouncyCastle.Asn1.Pkcs; | ||
using Org.BouncyCastle.Crypto.Digests; | ||
using Org.BouncyCastle.Crypto.Engines; | ||
using Org.BouncyCastle.Crypto.Parameters; | ||
using Org.BouncyCastle.Crypto.Signers; | ||
using Org.BouncyCastle.Utilities.IO.Pem; | ||
|
||
namespace VaultSharp.V1.AuthMethods.CloudFoundry.Signature | ||
{ | ||
public class CloudFoundrySignatureProvider | ||
{ | ||
public static string GetSignature(DateTime dateTime, string cfInstanceCertContent, string roleName, string cfInstanceKeyContent) | ||
{ | ||
var formattedSigningTime = GetFormattedSigningTime(dateTime); | ||
var stringToSign = $"{formattedSigningTime}{cfInstanceCertContent}{roleName}"; | ||
|
||
var data = Encoding.UTF8.GetBytes(stringToSign); | ||
|
||
byte[] keyBytes; | ||
|
||
using (var reader = new StringReader(cfInstanceKeyContent)) | ||
{ | ||
var pemReader = new PemReader(reader); | ||
var pemObject = pemReader.ReadPemObject(); | ||
keyBytes = pemObject.Content; | ||
} | ||
|
||
var seq = (Asn1Sequence)Asn1Object.FromByteArray(keyBytes); | ||
var rsa = RsaPrivateKeyStructure.GetInstance(seq); | ||
|
||
var signer = new PssSigner(new RsaEngine(), new Sha256Digest(), 222); | ||
signer.Init(true, new RsaKeyParameters(true, rsa.Modulus, rsa.PrivateExponent)); | ||
signer.BlockUpdate(data, 0, data.Length); | ||
var signature = signer.GenerateSignature(); | ||
|
||
return $"v1:{Convert.ToBase64String(signature)}"; | ||
} | ||
|
||
public static string GetFormattedSigningTime(DateTime signingTime) | ||
{ | ||
return signingTime.ToString("yyyy-MM-ddTHH:mm:ssZ"); | ||
} | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
src/VaultSharp/V1/AuthMethods/CloudFoundry/Signature/CloudFoundrySignature.cs
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
src/VaultSharp/V1/AuthMethods/CloudFoundry/Signature/CloudFoundrySignatureProvider.cs
This file was deleted.
Oops, something went wrong.
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